74 Path srcJar = moduleDir.resolve(TEST_MODULE1 + ".jar"); 75 destJar = moduleDir2.resolve(TEST_MODULE1 + ".jar"); 76 String classes = MODS_DIR.resolve(TEST_MODULE1).toString(); 77 JarBuilder.createModularJar(srcJar.toString(), classes, MAIN_CLASS); 78 Files.copy(srcJar, destJar); 79 80 } 81 82 public static void main(String... args) throws Exception { 83 // compile the modules and create the modular jar files 84 buildTestModule(); 85 String appClasses[] = {MAIN_CLASS}; 86 // create an archive with both -cp and --module-path in the command line. 87 // Only the class in the modular jar in the --module-path will be archived; 88 // the class in the modular jar in the -cp won't be archived. 89 OutputAnalyzer output = TestCommon.createArchive( 90 destJar.toString(), appClasses, 91 "-Xlog:class+load=trace", "-XX:+PrintSystemDictionaryAtExit", 92 "--module-path", moduleDir.toString(), 93 "-m", TEST_MODULE1); 94 TestCommon.checkExecReturn(output, 0, true, "Loading classes to share"); 95 96 // run with the archive using the same command line as in dump time. 97 // The main class should be loaded from the archive. 98 output = TestCommon.execCommon( "-Xlog:class+load=trace", 99 "-cp", destJar.toString(), 100 "--module-path", moduleDir.toString(), 101 "-m", TEST_MODULE1); 102 TestCommon.checkExecReturn(output, 0, true, 103 "[class,load] com.simple.Main source: shared objects file"); 104 105 // run with the archive with the main class name inserted before the -m. 106 // The main class name will be picked up before the module name. So the 107 // main class should be loaded from the jar in the -cp. 108 output = TestCommon.execCommon( "-Xlog:class+load=trace", 109 "-cp", destJar.toString(), 110 "--module-path", moduleDir.toString(), 111 MAIN_CLASS, "-m", TEST_MODULE1); 112 output.shouldHaveExitValue(0) 113 .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"); 114 115 // run with the archive with exploded module. Since during dump time, we 116 // only archive classes from the modular jar in the --module-path, the 117 // main class should be loaded from the exploded module directory. 118 output = TestCommon.execCommon( "-Xlog:class+load=trace", 119 "-cp", destJar.toString(), 120 "--module-path", MODS_DIR.toString(), 121 "-m", TEST_MODULE1 + "/" + MAIN_CLASS); 122 output.shouldHaveExitValue(0) 123 .shouldMatch(".class.load. com.simple.Main source:.*com.simple") 124 .shouldContain(MODS_DIR.toString()); 125 126 // run with the archive with the --upgrade-module-path option. 127 // CDS will be disabled with this options and the main class will be 128 // loaded from the modular jar. 129 output = TestCommon.execCommon( "-Xlog:class+load=trace", 130 "-cp", destJar.toString(), 131 "--upgrade-module-path", moduleDir.toString(), 132 "--module-path", moduleDir.toString(), 133 "-m", TEST_MODULE1); 134 output.shouldHaveExitValue(0) 135 .shouldMatch("CDS is disabled when the.*option is specified") 136 .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"); 137 // run with the archive with the --limit-modules option. 138 // CDS will be disabled with this options and the main class will be 139 // loaded from the modular jar. 140 output = TestCommon.execCommon( "-Xlog:class+load=trace", 141 "-cp", destJar.toString(), 142 "--limit-modules", "java.base," + TEST_MODULE1, 143 "--module-path", moduleDir.toString(), 144 "-m", TEST_MODULE1); 145 output.shouldHaveExitValue(0) 146 .shouldMatch("CDS is disabled when the.*option is specified") 147 .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"); 148 // run with the archive with the --patch-module option. 149 // CDS will be disabled with this options and the main class will be 150 // loaded from the modular jar. 151 output = TestCommon.execCommon( "-Xlog:class+load=trace", 152 "-cp", destJar.toString(), 153 "--patch-module", TEST_MODULE1 + "=" + MODS_DIR.toString(), 154 "--module-path", moduleDir.toString(), 155 "-m", TEST_MODULE1); 156 output.shouldHaveExitValue(0) 157 .shouldMatch("CDS is disabled when the.*option is specified") 158 .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"); 159 // modify the timestamp of the jar file 160 (new File(destJar.toString())).setLastModified(System.currentTimeMillis() + 2000); 161 // run with the archive and the jar with modified timestamp. 162 // It should fail due to timestamp of the jar doesn't match the one 163 // used during dump time. 164 output = TestCommon.execCommon( "-Xlog:class+load=trace", 165 "-cp", destJar.toString(), 166 "--module-path", moduleDir.toString(), 167 "-m", TEST_MODULE1); 168 TestCommon.checkExecReturn(output, 1, true, 169 "A jar/jimage file is not the one used while building the shared archive file:"); 170 } 171 } | 74 Path srcJar = moduleDir.resolve(TEST_MODULE1 + ".jar"); 75 destJar = moduleDir2.resolve(TEST_MODULE1 + ".jar"); 76 String classes = MODS_DIR.resolve(TEST_MODULE1).toString(); 77 JarBuilder.createModularJar(srcJar.toString(), classes, MAIN_CLASS); 78 Files.copy(srcJar, destJar); 79 80 } 81 82 public static void main(String... args) throws Exception { 83 // compile the modules and create the modular jar files 84 buildTestModule(); 85 String appClasses[] = {MAIN_CLASS}; 86 // create an archive with both -cp and --module-path in the command line. 87 // Only the class in the modular jar in the --module-path will be archived; 88 // the class in the modular jar in the -cp won't be archived. 89 OutputAnalyzer output = TestCommon.createArchive( 90 destJar.toString(), appClasses, 91 "-Xlog:class+load=trace", "-XX:+PrintSystemDictionaryAtExit", 92 "--module-path", moduleDir.toString(), 93 "-m", TEST_MODULE1); 94 TestCommon.checkDump(output); 95 96 // run with the archive using the same command line as in dump time. 97 // The main class should be loaded from the archive. 98 TestCommon.run("-Xlog:class+load=trace", 99 "-cp", destJar.toString(), 100 "--module-path", moduleDir.toString(), 101 "-m", TEST_MODULE1) 102 .assertNormalExit("[class,load] com.simple.Main source: shared objects file"); 103 104 // run with the archive with the main class name inserted before the -m. 105 // The main class name will be picked up before the module name. So the 106 // main class should be loaded from the jar in the -cp. 107 TestCommon.run("-Xlog:class+load=trace", 108 "-cp", destJar.toString(), 109 "--module-path", moduleDir.toString(), 110 MAIN_CLASS, "-m", TEST_MODULE1) 111 .assertNormalExit(out -> 112 out.shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar")); 113 114 // run with the archive with exploded module. Since during dump time, we 115 // only archive classes from the modular jar in the --module-path, the 116 // main class should be loaded from the exploded module directory. 117 TestCommon.run("-Xlog:class+load=trace", 118 "-cp", destJar.toString(), 119 "--module-path", MODS_DIR.toString(), 120 "-m", TEST_MODULE1 + "/" + MAIN_CLASS) 121 .assertNormalExit(out -> { 122 out.shouldMatch(".class.load. com.simple.Main source:.*com.simple") 123 .shouldContain(MODS_DIR.toString()); 124 }); 125 126 // run with the archive with the --upgrade-module-path option. 127 // CDS will be disabled with this options and the main class will be 128 // loaded from the modular jar. 129 TestCommon.run("-Xlog:class+load=trace", 130 "-cp", destJar.toString(), 131 "--upgrade-module-path", moduleDir.toString(), 132 "--module-path", moduleDir.toString(), 133 "-m", TEST_MODULE1) 134 .assertSilentlyDisabledCDS(out -> { 135 out.shouldHaveExitValue(0) 136 .shouldMatch("CDS is disabled when the.*option is specified") 137 .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"); 138 }); 139 // run with the archive with the --limit-modules option. 140 // CDS will be disabled with this options and the main class will be 141 // loaded from the modular jar. 142 TestCommon.run("-Xlog:class+load=trace", 143 "-cp", destJar.toString(), 144 "--limit-modules", "java.base," + TEST_MODULE1, 145 "--module-path", moduleDir.toString(), 146 "-m", TEST_MODULE1) 147 .assertSilentlyDisabledCDS(out -> { 148 out.shouldHaveExitValue(0) 149 .shouldMatch("CDS is disabled when the.*option is specified") 150 .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"); 151 }); 152 // run with the archive with the --patch-module option. 153 // CDS will be disabled with this options and the main class will be 154 // loaded from the modular jar. 155 TestCommon.run("-Xlog:class+load=trace", 156 "-cp", destJar.toString(), 157 "--patch-module", TEST_MODULE1 + "=" + MODS_DIR.toString(), 158 "--module-path", moduleDir.toString(), 159 "-m", TEST_MODULE1) 160 .assertSilentlyDisabledCDS(out -> { 161 out.shouldHaveExitValue(0) 162 .shouldMatch("CDS is disabled when the.*option is specified") 163 .shouldMatch(".class.load. com.simple.Main source:.*com.simple.jar"); 164 }); 165 // modify the timestamp of the jar file 166 (new File(destJar.toString())).setLastModified(System.currentTimeMillis() + 2000); 167 // run with the archive and the jar with modified timestamp. 168 // It should fail due to timestamp of the jar doesn't match the one 169 // used during dump time. 170 TestCommon.run("-Xlog:class+load=trace", 171 "-cp", destJar.toString(), 172 "--module-path", moduleDir.toString(), 173 "-m", TEST_MODULE1) 174 .assertAbnormalExit( 175 "A jar/jimage file is not the one used while building the shared archive file:"); 176 } 177 } |