Skip to content

Commit

Permalink
@iklam comments
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinccheung committed Oct 1, 2024
1 parent a3eef6c commit 4b6ca61
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/classfile/classLoaderExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ void ClassLoaderExt::setup_module_paths(JavaThread* current) {
}

bool ClassLoaderExt::has_jar_suffix(const char* filename) {
// In jdk.internal.module.ModulePath.readModule(), it checks for the ".jar" suffix.
// Performing the same check here.
const char* dot = strrchr(filename, '.');
if (dot != nullptr && strcmp(dot + 1, "jar") == 0) {
return true;
Expand Down
8 changes: 1 addition & 7 deletions src/hotspot/share/runtime/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,7 @@ bool Arguments::is_internal_module_property(const char* property) {

// Return true if the key matches the --module-path property name ("jdk.module.path").
bool Arguments::is_module_path_property(const char* key) {
if (strncmp(key, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) == 0) {
const char* property_suffix = key + MODULE_PROPERTY_PREFIX_LEN;
if (matches_property_suffix(property_suffix, PATH, PATH_LEN)) {
return true;
}
}
return false;
return (strcmp(key, MODULE_PROPERTY_PREFIX PATH) == 0);
}

// Process java launcher properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,18 +1082,10 @@ private static URL checkURL(URL url) {

// Called from VM only, during -Xshare:dump
private void resetArchivedStates() {
resetArchivedStates(false);
}

// Called from BuiltinClassLoaders.resetArchivedStates() and ClassLoaders.AppClassLoader.resetArchivedStates().
void resetArchivedStates(boolean all) {
ucp = null;
resourceCache = null;
if (all) {
setClassPath(null);
if (!moduleToReader.isEmpty()) {
moduleToReader.clear();
}
if (!moduleToReader.isEmpty()) {
moduleToReader.clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,6 @@ void appendToClassPathForInstrumentation(String path) {
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() {
super.resetArchivedStates(true);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@

import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

public class ModulePathAndFMG {
private static final String JAVA_HOME = System.getProperty("java.home");

private static final Path USER_DIR = Paths.get(CDSTestUtils.getOutputDir());

private static final String TEST_SRC = System.getProperty("test.src");

private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
private static final Path MODS_DIR = Paths.get("mody");
private static final Path JMOD_DIR = Paths.get("jmod_dir");

// the module name of the test module
private static final String MAIN_MODULE = "com.bars";
Expand All @@ -63,12 +66,16 @@ public class ModulePathAndFMG {
private static String DUP_LIBS = "duplibs";
private static Path libsDir = null;
private static Path dupDir = null;
private static Path jmodDir = null;
private static Path mainJar = null;
private static Path testJar = null;
private static Path dupJar = null;
private static Path badJar = null;

private static String CLASS_FOUND_MESSAGE = "com.foos.Test found";
private static String CLASS_NOT_FOUND_MESSAGE = "java.lang.ClassNotFoundException: com.foos.Test";
private static String FIND_EXCEPTION_MESSAGE = "java.lang.module.FindException: Module com.foos not found, required by com.bars";
private static String MODULE_NOT_RECOGNIZED = "Module format not recognized:.*modylibs.*com.bars.JAR";
private static String OPTIMIZE_ENABLED = "] optimized module handling: enabled";
private static String OPTIMIZE_DISABLED = "] optimized module handling: disabled";
private static String FMG_ENABLED = "] full module graph: enabled";
Expand Down Expand Up @@ -111,11 +118,27 @@ public static void buildTestModule() throws Exception {
dupDir = Files.createTempDirectory(USER_DIR, DUP_LIBS);
dupJar = dupDir.resolve(DUP_MODULE + ".jar");
Files.copy(testJar, dupJar, StandardCopyOption.REPLACE_EXISTING);

badJar = libsDir.resolve(MAIN_MODULE + ".JAR");
Files.copy(mainJar, badJar, StandardCopyOption.REPLACE_EXISTING);
}

public static void buildJmod() throws Exception {
Path jmod = Paths.get(JAVA_HOME, "bin", "jmod");
jmodDir = Files.createDirectory(Paths.get(USER_DIR.toString() + File.separator + JMOD_DIR.toString()));
OutputAnalyzer output = ProcessTools.executeProcess(jmod.toString(),
"create",
"--class-path", Paths.get(USER_DIR.toString(), MODS_DIR.toString(), TEST_MODULE).toString(),
"--module-version", "1.0",
"--main-class", TEST_CLASS,
jmodDir.toString() + File.separator + TEST_MODULE + ".jmod");
output.shouldHaveExitValue(0);
}

public static void main(String... args) throws Exception {
runWithModulePath();
runWithExplodedModule();
runWithJmodAndBadJar();
}

private static void tty(String... args) {
Expand All @@ -125,7 +148,7 @@ private static void tty(String... args) {
System.out.print("\n");
}

public static void runWithModulePath(String... extraRuntimeArgs) throws Exception {
public static void runWithModulePath() throws Exception {
// compile the modules and create the modular jar files
buildTestModule();
// create an archive with the classes in the modules built in the
Expand Down Expand Up @@ -281,7 +304,7 @@ public static void runWithModulePath(String... extraRuntimeArgs) throws Exceptio
});
}

public static void runWithExplodedModule(String... extraRuntimeArgs) throws Exception {
public static void runWithExplodedModule() throws Exception {
// create an archive with an exploded module in the module path.
OutputAnalyzer output = TestCommon.createArchive(
null, appClasses,
Expand All @@ -301,4 +324,62 @@ public static void runWithExplodedModule(String... extraRuntimeArgs) throws Exce
.shouldContain(CLASS_FOUND_MESSAGE);
});
}

public static void runWithJmodAndBadJar() throws Exception {
buildJmod();

final String modularJarPath = mainJar.toString() + PATH_SEPARATOR + testJar.toString();
// create an archive with --module-path com.bars.jar:com.foos.jar
OutputAnalyzer output = TestCommon.createArchive(
null, appClasses,
"--module-path",
modularJarPath,
"-m", MAIN_MODULE);
TestCommon.checkDump(output);

String runModulePath = mainJar.toString() + PATH_SEPARATOR +
jmodDir.toString() + TEST_MODULE + ".jmod";
tty("11. run with CDS on, with module path com.bars.jar:com.foos.jmod");
TestCommon.runWithModules(prefix,
null, // --upgrade-module-path
runModulePath, // --module-path
MAIN_MODULE) // -m
.assertAbnormalExit(out -> {
out.shouldContain(OPTIMIZE_DISABLED)
.shouldNotContain(OPTIMIZE_ENABLED)
.shouldContain(FMG_DISABLED)
.shouldNotContain(FMG_ENABLED)
.shouldContain(FIND_EXCEPTION_MESSAGE);
});

runModulePath += PATH_SEPARATOR + testJar.toString();
tty("12. run with CDS on, with module path com.bars.jar:com.foos.jmod:com.foos.jar");
TestCommon.runWithModules(prefix,
null, // --upgrade-module-path
runModulePath, // --module-path
MAIN_MODULE) // -m
.assertNormalExit(out -> {
out.shouldNotContain(OPTIMIZE_DISABLED)
.shouldContain(OPTIMIZE_ENABLED)
.shouldNotContain(FMG_DISABLED)
.shouldContain(FMG_ENABLED)
.shouldMatch(TEST_FROM_CDS)
.shouldMatch(MAIN_FROM_CDS)
.shouldContain(CLASS_FOUND_MESSAGE);
});

runModulePath = badJar.toString() + PATH_SEPARATOR + testJar.toString();
tty("13. run with CDS on, with module path com.bars.JAR:com.foos.jar");
TestCommon.runWithModules(prefix,
null, // --upgrade-module-path
runModulePath, // --module-path
TEST_MODULE) // -m
.assertAbnormalExit(out -> {
out.shouldContain(OPTIMIZE_DISABLED)
.shouldNotContain(OPTIMIZE_ENABLED)
.shouldContain(FMG_DISABLED)
.shouldNotContain(FMG_ENABLED)
.shouldMatch(MODULE_NOT_RECOGNIZED);
});
}
}

0 comments on commit 4b6ca61

Please sign in to comment.