make/tools/classanalyzer/src/com/sun/classanalyzer/BootAnalyzer.java

Print this page

        

@@ -21,10 +21,11 @@
  * questions.
  *
  */
 package com.sun.classanalyzer;
 
+import java.util.Collections;
 import java.io.BufferedReader;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;

@@ -41,10 +42,12 @@
 import com.sun.tools.classfile.*;
 import com.sun.tools.classfile.ConstantPool.*;
 import static com.sun.tools.classfile.ConstantPool.*;
 import com.sun.tools.classfile.Instruction.TypeKind;
 import com.sun.tools.classfile.Type.*;
+import com.sun.classanalyzer.ModuleInfo.PackageInfo;
+import static com.sun.classanalyzer.Trace.*;
 
 /**
  * Generate the module config for the boot module with
  * a given set of roots (classes or methods) and exclude list.
  *

@@ -77,15 +80,16 @@
  * </ul>
  *
  * @author Mandy Chung
  */
 public class BootAnalyzer {
-
+    private static ClassPaths cpaths;
     public static void main(String[] args) throws Exception {
         String jdkhome = null;
         String config = null;
         String output = ".";
+        String version = "7-ea";
         boolean printClassList = false;
 
         // process arguments
         int i = 0;
         while (i < args.length) {

@@ -94,10 +98,12 @@
                 if (i < args.length) {
                     jdkhome = args[i++];
                 } else {
                     usage();
                 }
+            } else if (arg.equals("-version")) {
+                version = args[i++];
             } else if (arg.equals("-config")) {
                 config = args[i++];
             } else if (arg.equals("-output")) {
                 output = args[i++];
             } else if (arg.equals("-classlist")) {

@@ -105,23 +111,21 @@
             } else {
                 usage();
             }
         }
 
-
-
         if (jdkhome == null || config == null) {
             usage();
         }
 
         File jre = new File(jdkhome, "jre");
         if (jre.exists()) {
-            ClassPath.setJDKHome(jdkhome);
+            cpaths = ClassPaths.newJDKClassPaths(jdkhome);
         } else {
             File classes = new File(jdkhome, "classes");
             if (classes.exists()) {
-                ClassPath.setClassPath(classes.getCanonicalPath());
+                cpaths = ClassPaths.newInstance(classes.getCanonicalPath());
             } else {
                 throw new RuntimeException("Invalid jdkhome: " + jdkhome);
             }
         }
 

@@ -141,23 +145,54 @@
 
         String bootmodule = "boot";
         String bootconfig = resolve(dir, bootmodule, "config");
         printBootConfig(bootconfig, bootmodule);
 
-        List<ModuleConfig> list = ModuleConfig.readConfigurationFile(bootconfig);
-        Module module = Module.addModule(list.get(0));
+        ModuleBuilder builder =
+                new ModuleBuilder(Collections.singletonList(bootconfig), version);
+
+        assert Module.getAllModules().size() == 1;
+        Module module = null;
+        for (Module m : Module.getAllModules()) {
+            module = m;
+            break;
+        }
         for (Klass k : Klass.getAllClasses()) {
             module.addKlass(k);
         }
-        module.fixupDependencies();
+        builder.run();
 
         if (printClassList) {
-            module.printClassListTo(resolve(dir, bootmodule, "classlist"));
-            module.printSummaryTo(resolve(dir, bootmodule, "summary"));
+            ClassListWriter writer = new ClassListWriter(dir, module);
+            writer.printClassList();
+            writer.printResourceList();
+            printModuleSummary(dir, module);
         }
     }
 
+    private static void printModuleSummary(File dir, Module m) throws IOException {
+        PrintWriter summary =
+                new PrintWriter(Files.resolve(dir, m.name(), "summary"));
+        try {
+            long total = 0L;
+            int count = 0;
+            summary.format("%10s\t%10s\t%s%n", "Bytes", "Classes", "Package name");
+            for (PackageInfo info : m.getModuleInfo().packages()) {
+                if (info.count > 0) {
+                    summary.format("%10d\t%10d\t%s%n",
+                                  info.filesize, info.count, info.pkgName);
+                    total += info.filesize;
+                    count += info.count;
+                }
+            }
+            summary.format("%nTotal: %d bytes (uncompressed) %d classes%n",
+                    total, count);
+        } finally {
+            summary.close();
+        }
+    }
+
     // print boot.config file as an input to the ClassAnalyzer
     private static void printBootConfig(String output, String bootmodule) throws IOException {
 
         File f = new File(output);
         PrintWriter writer = new PrintWriter(f);

@@ -336,11 +371,11 @@
             }
         }
 
         synchronized ClassFileParser getClassFileParser() throws IOException {
             if (parser == null) {
-                parser = ClassPath.parserForClass(classname);
+                parser = cpaths.parserForClass(classname);
                 if (parser != null) {
                     parseClassFile();
                     List<String> descriptors = parse(new MethodDescriptor(classname + ".<clinit>", "()V", false));
                 }
             }

@@ -802,18 +837,11 @@
             public String visitUtf8(CONSTANT_Utf8_info info, Void p) {
                 return null;
             }
         };
     }
-    static boolean traceOn = System.getProperty("classanalyzer.debug") != null;
 
-    private static void trace(String format, Object... args) {
-        if (traceOn) {
-            System.out.format(format, args);
-        }
-    }
-
     private static void usage() {
         System.out.println("Usage: BootAnalyzer <options>");
         System.out.println("Options: ");
         System.out.println("\t-jdkhome <JDK home> where all jars will be parsed");
         System.out.println("\t-config  <roots for the boot module>");