mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module
Support system module archiving with unnamed initial module at dump time. Co-authored-by: Alan Bateman <alan.bateman@oracle.com> Reviewed-by: erikj, coleenp, mchung, iklam, ccheung
This commit is contained in:
parent
4d93f17fe1
commit
9ba5bab865
25 changed files with 1473 additions and 32 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -413,4 +413,15 @@ public class VM {
|
|||
initialize();
|
||||
}
|
||||
private static native void initialize();
|
||||
|
||||
/**
|
||||
* Initialize archived static fields in the given Class using archived
|
||||
* values from CDS dump time. Also initialize the classes of objects in
|
||||
* the archived graph referenced by those fields.
|
||||
*
|
||||
* Those static fields remain as uninitialized if there is no mapped CDS
|
||||
* java heap data or there is any error during initialization of the
|
||||
* object class in the archived graph.
|
||||
*/
|
||||
public static native void initializeFromArchive(Class<?> c);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.internal.module;
|
||||
|
||||
import java.lang.module.ModuleFinder;
|
||||
import java.util.Objects;
|
||||
import jdk.internal.misc.VM;
|
||||
|
||||
/**
|
||||
* Used by ModuleBootstrap to obtain the archived system modules and finder.
|
||||
*/
|
||||
final class ArchivedModuleGraph {
|
||||
private static String archivedMainModule;
|
||||
private static SystemModules archivedSystemModules;
|
||||
private static ModuleFinder archivedModuleFinder;
|
||||
|
||||
private final SystemModules systemModules;
|
||||
private final ModuleFinder finder;
|
||||
|
||||
private ArchivedModuleGraph(SystemModules modules, ModuleFinder finder) {
|
||||
this.systemModules = modules;
|
||||
this.finder = finder;
|
||||
}
|
||||
|
||||
SystemModules systemModules() {
|
||||
return systemModules;
|
||||
}
|
||||
|
||||
ModuleFinder finder() {
|
||||
return finder;
|
||||
}
|
||||
|
||||
// A factory method that ModuleBootstrap can use to obtain the
|
||||
// ArchivedModuleGraph.
|
||||
static ArchivedModuleGraph get(String mainModule) {
|
||||
if (Objects.equals(mainModule, archivedMainModule)
|
||||
&& archivedSystemModules != null
|
||||
&& archivedModuleFinder != null) {
|
||||
return new ArchivedModuleGraph(archivedSystemModules,
|
||||
archivedModuleFinder);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Used at CDS dump time
|
||||
static void archive(String mainModule, SystemModules systemModules,
|
||||
ModuleFinder finder) {
|
||||
if (archivedMainModule != null)
|
||||
throw new UnsupportedOperationException();
|
||||
archivedMainModule = mainModule;
|
||||
archivedSystemModules = systemModules;
|
||||
archivedModuleFinder = finder;
|
||||
}
|
||||
|
||||
static {
|
||||
VM.initializeFromArchive(ArchivedModuleGraph.class);
|
||||
}
|
||||
}
|
|
@ -54,6 +54,7 @@ import jdk.internal.loader.BuiltinClassLoader;
|
|||
import jdk.internal.misc.JavaLangAccess;
|
||||
import jdk.internal.misc.JavaLangModuleAccess;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.misc.VM;
|
||||
import jdk.internal.perf.PerfCounter;
|
||||
|
||||
/**
|
||||
|
@ -172,23 +173,45 @@ public final class ModuleBootstrap {
|
|||
boolean haveModulePath = (appModulePath != null || upgradeModulePath != null);
|
||||
boolean needResolution = true;
|
||||
|
||||
if (!haveModulePath && addModules.isEmpty() && limitModules.isEmpty()) {
|
||||
systemModules = SystemModuleFinders.systemModules(mainModule);
|
||||
if (systemModules != null && !isPatched && (traceOutput == null)) {
|
||||
needResolution = false;
|
||||
}
|
||||
}
|
||||
if (systemModules == null) {
|
||||
// all system modules are observable
|
||||
systemModules = SystemModuleFinders.allSystemModules();
|
||||
}
|
||||
if (systemModules != null) {
|
||||
// images build
|
||||
systemModuleFinder = SystemModuleFinders.of(systemModules);
|
||||
// If the java heap was archived at CDS dump time and the environment
|
||||
// at dump time matches the current environment then use the archived
|
||||
// system modules and finder.
|
||||
ArchivedModuleGraph archivedModuleGraph = ArchivedModuleGraph.get(mainModule);
|
||||
if (archivedModuleGraph != null
|
||||
&& !haveModulePath
|
||||
&& addModules.isEmpty()
|
||||
&& limitModules.isEmpty()
|
||||
&& !isPatched) {
|
||||
systemModules = archivedModuleGraph.systemModules();
|
||||
systemModuleFinder = archivedModuleGraph.finder();
|
||||
needResolution = (traceOutput != null);
|
||||
} else {
|
||||
// exploded build or testing
|
||||
systemModules = new ExplodedSystemModules();
|
||||
systemModuleFinder = SystemModuleFinders.ofSystem();
|
||||
boolean canArchive = false;
|
||||
if (!haveModulePath && addModules.isEmpty() && limitModules.isEmpty()) {
|
||||
systemModules = SystemModuleFinders.systemModules(mainModule);
|
||||
if (systemModules != null && !isPatched) {
|
||||
needResolution = (traceOutput != null);
|
||||
canArchive = true;
|
||||
}
|
||||
}
|
||||
if (systemModules == null) {
|
||||
// all system modules are observable
|
||||
systemModules = SystemModuleFinders.allSystemModules();
|
||||
}
|
||||
if (systemModules != null) {
|
||||
// images build
|
||||
systemModuleFinder = SystemModuleFinders.of(systemModules);
|
||||
} else {
|
||||
// exploded build or testing
|
||||
systemModules = new ExplodedSystemModules();
|
||||
systemModuleFinder = SystemModuleFinders.ofSystem();
|
||||
}
|
||||
|
||||
// Module graph can be archived at CDS dump time. Only allow the
|
||||
// unnamed module case for now.
|
||||
if (canArchive && (mainModule == null)) {
|
||||
ArchivedModuleGraph.archive(mainModule, systemModules, systemModuleFinder);
|
||||
}
|
||||
}
|
||||
|
||||
Counters.add("jdk.module.boot.1.systemModulesTime", t1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue