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

Print this page

        

*** 21,30 **** --- 21,31 ---- * 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,50 **** --- 42,53 ---- 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,91 **** * </ul> * * @author Mandy Chung */ public class BootAnalyzer { ! public static void main(String[] args) throws Exception { String jdkhome = null; String config = null; String output = "."; boolean printClassList = false; // process arguments int i = 0; while (i < args.length) { --- 80,95 ---- * </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,103 **** --- 98,109 ---- 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,127 **** } else { usage(); } } - - if (jdkhome == null || config == null) { usage(); } File jre = new File(jdkhome, "jre"); if (jre.exists()) { ! ClassPath.setJDKHome(jdkhome); } else { File classes = new File(jdkhome, "classes"); if (classes.exists()) { ! ClassPath.setClassPath(classes.getCanonicalPath()); } else { throw new RuntimeException("Invalid jdkhome: " + jdkhome); } } --- 111,131 ---- } else { usage(); } } if (jdkhome == null || config == null) { usage(); } File jre = new File(jdkhome, "jre"); if (jre.exists()) { ! cpaths = ClassPaths.newJDKClassPaths(jdkhome); } else { File classes = new File(jdkhome, "classes"); if (classes.exists()) { ! cpaths = ClassPaths.newInstance(classes.getCanonicalPath()); } else { throw new RuntimeException("Invalid jdkhome: " + jdkhome); } }
*** 141,163 **** 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)); for (Klass k : Klass.getAllClasses()) { module.addKlass(k); } ! module.fixupDependencies(); if (printClassList) { ! module.printClassListTo(resolve(dir, bootmodule, "classlist")); ! module.printSummaryTo(resolve(dir, bootmodule, "summary")); } } // 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); --- 145,198 ---- String bootmodule = "boot"; String bootconfig = resolve(dir, bootmodule, "config"); printBootConfig(bootconfig, bootmodule); ! 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); } ! builder.run(); if (printClassList) { ! 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,346 **** } } synchronized ClassFileParser getClassFileParser() throws IOException { if (parser == null) { ! parser = ClassPath.parserForClass(classname); if (parser != null) { parseClassFile(); List<String> descriptors = parse(new MethodDescriptor(classname + ".<clinit>", "()V", false)); } } --- 371,381 ---- } } synchronized ClassFileParser getClassFileParser() throws IOException { if (parser == null) { ! parser = cpaths.parserForClass(classname); if (parser != null) { parseClassFile(); List<String> descriptors = parse(new MethodDescriptor(classname + ".<clinit>", "()V", false)); } }
*** 802,819 **** 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>"); --- 837,847 ----