|
@@ -140,9 +140,9 @@ public static ModuleFinder limitedFinder() { |
|
|
*/ |
|
|
public static ModuleLayer boot() throws Exception { |
|
|
|
|
|
// Step 0: Command line options |
|
|
Counters.start(); |
|
|
|
|
|
long t0 = System.nanoTime(); |
|
|
// Step 0: Command line options |
|
|
|
|
|
ModuleFinder upgradeModulePath = finderFor("jdk.module.upgrade.path"); |
|
|
ModuleFinder appModulePath = finderFor("jdk.module.path"); |
|
@@ -157,15 +157,14 @@ public static ModuleLayer boot() throws Exception { |
|
|
if (trace != null && Boolean.parseBoolean(trace)) |
|
|
traceOutput = System.out; |
|
|
|
|
|
Counters.add("jdk.module.boot.0.commandLineTime"); |
|
|
|
|
|
// Step 1: The observable system modules, either all system modules |
|
|
// or the system modules pre-generated for the initial module (the |
|
|
// initial module may be the unnamed module). If the system modules |
|
|
// are pre-generated for the initial module then resolution can be |
|
|
// skipped. |
|
|
|
|
|
long t1 = System.nanoTime(); |
|
|
|
|
|
SystemModules systemModules = null; |
|
|
ModuleFinder systemModuleFinder; |
|
|
|
|
@@ -215,16 +214,13 @@ public static ModuleLayer boot() throws Exception { |
|
|
archivedModuleGraph = null; |
|
|
} |
|
|
|
|
|
Counters.add("jdk.module.boot.1.systemModulesTime", t1); |
|
|
|
|
|
Counters.add("jdk.module.boot.1.systemModulesTime"); |
|
|
|
|
|
// Step 2: Define and load java.base. This patches all classes loaded |
|
|
// to date so that they are members of java.base. Once java.base is |
|
|
// loaded then resources in java.base are available for error messages |
|
|
// needed from here on. |
|
|
|
|
|
long t2 = System.nanoTime(); |
|
|
|
|
|
ModuleReference base = systemModuleFinder.find(JAVA_BASE).orElse(null); |
|
|
if (base == null) |
|
|
throw new InternalError(JAVA_BASE + " not found"); |
|
@@ -234,9 +230,6 @@ public static ModuleLayer boot() throws Exception { |
|
|
BootLoader.loadModule(base); |
|
|
Modules.defineModule(null, base.descriptor(), baseUri); |
|
|
|
|
|
Counters.add("jdk.module.boot.2.defineBaseTime", t2); |
|
|
|
|
|
|
|
|
// Step 2a: Scan all modules when --validate-modules specified |
|
|
|
|
|
if (getAndRemoveProperty("jdk.module.validation") != null) { |
|
@@ -246,12 +239,11 @@ public static ModuleLayer boot() throws Exception { |
|
|
} |
|
|
} |
|
|
|
|
|
Counters.add("jdk.module.boot.2.defineBaseTime"); |
|
|
|
|
|
// Step 3: If resolution is needed then create the module finder and |
|
|
// the set of root modules to resolve. |
|
|
|
|
|
long t3 = System.nanoTime(); |
|
|
|
|
|
ModuleFinder savedModuleFinder = null; |
|
|
ModuleFinder finder; |
|
|
Set<String> roots; |
|
@@ -341,15 +333,13 @@ public static ModuleLayer boot() throws Exception { |
|
|
roots = null; |
|
|
} |
|
|
|
|
|
Counters.add("jdk.module.boot.3.optionsAndRootsTime", t3); |
|
|
Counters.add("jdk.module.boot.3.optionsAndRootsTime"); |
|
|
|
|
|
// Step 4: Resolve the root modules, with service binding, to create |
|
|
// the configuration for the boot layer. If resolution is not needed |
|
|
// then create the configuration for the boot layer from the |
|
|
// readability graph created at link time. |
|
|
|
|
|
long t4 = System.nanoTime(); |
|
|
|
|
|
Configuration cf; |
|
|
if (needResolution) { |
|
|
cf = Modules.newBootLayerConfiguration(finder, roots, traceOutput); |
|
@@ -370,8 +360,7 @@ public static ModuleLayer boot() throws Exception { |
|
|
.forEach(mn -> warnUnknownModule(PATCH_MODULE, mn)); |
|
|
} |
|
|
|
|
|
Counters.add("jdk.module.boot.4.resolveTime", t4); |
|
|
|
|
|
Counters.add("jdk.module.boot.4.resolveTime"); |
|
|
|
|
|
// Step 5: Map the modules in the configuration to class loaders. |
|
|
// The static configuration provides the mapping of standard and JDK |
|
@@ -380,8 +369,6 @@ public static ModuleLayer boot() throws Exception { |
|
|
// application module path) are defined to the application class |
|
|
// loader. |
|
|
|
|
|
long t5 = System.nanoTime(); |
|
|
|
|
|
// mapping of modules to class loaders |
|
|
Function<String, ClassLoader> clf = ModuleLoaderMap.mappingFunction(cf); |
|
|
|
|
@@ -409,16 +396,12 @@ public static ModuleLayer boot() throws Exception { |
|
|
|
|
|
// load/register the modules with the built-in class loaders |
|
|
loadModules(cf, clf); |
|
|
|
|
|
Counters.add("jdk.module.boot.5.loadModulesTime", t5); |
|
|
|
|
|
Counters.add("jdk.module.boot.5.loadModulesTime"); |
|
|
|
|
|
// Step 6: Define all modules to the VM |
|
|
|
|
|
long t6 = System.nanoTime(); |
|
|
ModuleLayer bootLayer = ModuleLayer.empty().defineModules(cf, clf); |
|
|
Counters.add("jdk.module.boot.6.layerCreateTime", t6); |
|
|
|
|
|
Counters.add("jdk.module.boot.6.layerCreateTime"); |
|
|
|
|
|
// Step 7: Miscellaneous |
|
|
|
|
@@ -428,7 +411,6 @@ public static ModuleLayer boot() throws Exception { |
|
|
} |
|
|
|
|
|
// --add-reads, --add-exports/--add-opens, and --illegal-access |
|
|
long t7 = System.nanoTime(); |
|
|
addExtraReads(bootLayer); |
|
|
boolean extraExportsOrOpens = addExtraExportsAndOpens(bootLayer); |
|
|
|
|
@@ -446,7 +428,7 @@ public static ModuleLayer boot() throws Exception { |
|
|
exportedPackagesToOpen, |
|
|
bootLayer, |
|
|
extraExportsOrOpens); |
|
|
Counters.add("jdk.module.boot.7.adjustModulesTime", t7); |
|
|
Counters.add("jdk.module.boot.7.adjustModulesTime"); |
|
|
|
|
|
// save module finders for later use |
|
|
if (savedModuleFinder != null) { |
|
@@ -468,8 +450,7 @@ public static ModuleLayer boot() throws Exception { |
|
|
} |
|
|
|
|
|
// total time to initialize |
|
|
Counters.add("jdk.module.boot.totalTime", t0); |
|
|
Counters.publish(); |
|
|
Counters.publish("jdk.module.boot.totalTime"); |
|
|
|
|
|
return bootLayer; |
|
|
} |
|
@@ -1030,6 +1011,9 @@ static String option(String prefix) { |
|
|
private static final boolean PUBLISH_COUNTERS; |
|
|
private static final boolean PRINT_COUNTERS; |
|
|
private static Map<String, Long> counters; |
|
|
private static long startTime; |
|
|
private static long previousTime; |
|
|
|
|
|
static { |
|
|
String s = System.getProperty("jdk.module.boot.usePerfData"); |
|
|
if (s == null) { |
|
@@ -1043,27 +1027,44 @@ static String option(String prefix) { |
|
|
} |
|
|
|
|
|
/** |
|
|
* Add a counter |
|
|
* Start counting time. |
|
|
*/ |
|
|
static void start() { |
|
|
if (PUBLISH_COUNTERS) { |
|
|
startTime = previousTime = System.nanoTime(); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Add a counter - storing the time difference between now and the |
|
|
* previous add or the start. |
|
|
*/ |
|
|
static void add(String name, long start) { |
|
|
if (PUBLISH_COUNTERS || PRINT_COUNTERS) { |
|
|
counters.put(name, (System.nanoTime() - start)); |
|
|
static void add(String name) { |
|
|
if (PUBLISH_COUNTERS) { |
|
|
long current = System.nanoTime(); |
|
|
long elapsed = current - previousTime; |
|
|
previousTime = current; |
|
|
counters.put(name, elapsed); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Publish the counters to the instrumentation buffer or stdout. |
|
|
*/ |
|
|
static void publish() { |
|
|
if (PUBLISH_COUNTERS || PRINT_COUNTERS) { |
|
|
static void publish(String totalTimeName) { |
|
|
if (PUBLISH_COUNTERS) { |
|
|
long currentTime = System.nanoTime(); |
|
|
for (Map.Entry<String, Long> e : counters.entrySet()) { |
|
|
String name = e.getKey(); |
|
|
long value = e.getValue(); |
|
|
if (PUBLISH_COUNTERS) |
|
|
PerfCounter.newPerfCounter(name).set(value); |
|
|
PerfCounter.newPerfCounter(name).set(value); |
|
|
if (PRINT_COUNTERS) |
|
|
System.out.println(name + " = " + value); |
|
|
} |
|
|
long elapsedTotal = currentTime - startTime; |
|
|
PerfCounter.newPerfCounter(totalTimeName).set(elapsedTotal); |
|
|
if (PRINT_COUNTERS) |
|
|
System.out.println(totalTimeName + " = " + elapsedTotal); |
|
|
} |
|
|
} |
|
|
} |
|
|