mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8328313: Archived module graph should allow identical --module-path to be specified during dump time and run time
Reviewed-by: alanb, dholmes, iklam
This commit is contained in:
parent
9fc1c68442
commit
0bdfe88e4c
19 changed files with 591 additions and 51 deletions
|
@ -1084,5 +1084,8 @@ public class BuiltinClassLoader
|
|||
private void resetArchivedStates() {
|
||||
ucp = null;
|
||||
resourceCache = null;
|
||||
if (!moduleToReader.isEmpty()) {
|
||||
moduleToReader.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -210,13 +210,6 @@ public class ClassLoaders {
|
|||
protected Package defineOrCheckPackage(String pn, Manifest man, URL url) {
|
||||
return super.defineOrCheckPackage(pn, man, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the VM, during -Xshare:dump
|
||||
*/
|
||||
private void resetArchivedStates() {
|
||||
setClassPath(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.lang.module.ModuleFinder;
|
|||
import java.lang.module.ModuleReference;
|
||||
import java.lang.module.ResolvedModule;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -139,7 +140,6 @@ public final class ModuleBootstrap {
|
|||
*/
|
||||
private static boolean canUseArchivedBootLayer() {
|
||||
return getProperty("jdk.module.upgrade.path") == null &&
|
||||
getProperty("jdk.module.path") == null &&
|
||||
getProperty("jdk.module.patch.0") == null && // --patch-module
|
||||
getProperty("jdk.module.addmods.0") == null && // --add-modules
|
||||
getProperty("jdk.module.limitmods") == null && // --limit-modules
|
||||
|
@ -203,7 +203,8 @@ public final class ModuleBootstrap {
|
|||
SystemModules systemModules = null;
|
||||
ModuleFinder systemModuleFinder;
|
||||
|
||||
boolean haveModulePath = (appModulePath != null || upgradeModulePath != null);
|
||||
boolean haveUpgradeModulePath = (upgradeModulePath != null);
|
||||
boolean haveModulePath = (appModulePath != null || haveUpgradeModulePath);
|
||||
boolean needResolution = true;
|
||||
boolean mayContainSplitPackages = true;
|
||||
boolean mayContainIncubatorModules = true;
|
||||
|
@ -463,7 +464,10 @@ public final class ModuleBootstrap {
|
|||
|
||||
// Step 8: CDS dump phase
|
||||
|
||||
if (CDS.isDumpingStaticArchive() && !haveModulePath && addModules.isEmpty()) {
|
||||
if (CDS.isDumpingStaticArchive()
|
||||
&& !haveUpgradeModulePath
|
||||
&& addModules.isEmpty()
|
||||
&& allJrtOrModularJar(cf)) {
|
||||
assert !isPatched;
|
||||
|
||||
// Archive module graph and maybe boot layer
|
||||
|
@ -510,6 +514,29 @@ public final class ModuleBootstrap {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if all modules in the configuration are in the run-time image or
|
||||
* modular JAR files.
|
||||
*/
|
||||
private static boolean allJrtOrModularJar(Configuration cf) {
|
||||
return !cf.modules().stream()
|
||||
.map(m -> m.reference().location().orElseThrow())
|
||||
.anyMatch(uri -> !uri.getScheme().equalsIgnoreCase("jrt")
|
||||
&& !isJarFile(uri));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given URI locates a jar file on the file system.
|
||||
*/
|
||||
private static boolean isJarFile(URI uri) {
|
||||
if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||
Path path = Path.of(uri);
|
||||
return path.toString().endsWith(".jar") && Files.isRegularFile(path);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the configuration contains modules with overlapping packages.
|
||||
*/
|
||||
|
|
|
@ -91,8 +91,19 @@ class ModuleReferences {
|
|||
ModulePatcher patcher,
|
||||
Path file) {
|
||||
URI uri = file.toUri();
|
||||
Supplier<ModuleReader> supplier = () -> new JarModuleReader(file, uri);
|
||||
HashSupplier hasher = (a) -> ModuleHashes.computeHash(supplier, a);
|
||||
String fileString = file.toString();
|
||||
Supplier<ModuleReader> supplier = new Supplier<>() {
|
||||
@Override
|
||||
public ModuleReader get() {
|
||||
return new JarModuleReader(fileString, uri);
|
||||
}
|
||||
};
|
||||
HashSupplier hasher = new HashSupplier() {
|
||||
@Override
|
||||
public byte[] generate(String algorithm) {
|
||||
return ModuleHashes.computeHash(supplier, algorithm);
|
||||
}
|
||||
};
|
||||
return newModule(attrs, uri, supplier, patcher, hasher);
|
||||
}
|
||||
|
||||
|
@ -222,9 +233,9 @@ class ModuleReferences {
|
|||
private final JarFile jf;
|
||||
private final URI uri;
|
||||
|
||||
static JarFile newJarFile(Path path) {
|
||||
static JarFile newJarFile(String path) {
|
||||
try {
|
||||
return new JarFile(new File(path.toString()),
|
||||
return new JarFile(new File(path),
|
||||
true, // verify
|
||||
ZipFile.OPEN_READ,
|
||||
JarFile.runtimeVersion());
|
||||
|
@ -233,7 +244,7 @@ class ModuleReferences {
|
|||
}
|
||||
}
|
||||
|
||||
JarModuleReader(Path path, URI uri) {
|
||||
JarModuleReader(String path, URI uri) {
|
||||
this.jf = newJarFile(path);
|
||||
this.uri = uri;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue