1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /* 26 * @test 27 * @summary Test archived system module sub-graph and verify objects are archived. 28 * @requires vm.cds.archived.java.heap 29 * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/appcds 30 * @modules java.base/jdk.internal.misc 31 * java.management 32 * jdk.jartool/sun.tools.jar 33 * @build sun.hotspot.WhiteBox 34 * @compile CheckArchivedModuleApp.java 35 * @run driver ClassFileInstaller -jar app.jar CheckArchivedModuleApp 36 * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox 37 * @run main ArchivedModuleComboTest 38 */ 39 40 import java.io.File; 41 import java.nio.file.Files; 42 import java.nio.file.Path; 43 import java.nio.file.Paths; 44 import jdk.test.lib.process.OutputAnalyzer; 45 import jdk.test.lib.process.ProcessTools; 46 import sun.hotspot.WhiteBox; 47 48 public class ArchivedModuleComboTest { 49 public static void main(String[] args) throws Exception { 50 String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar"); 51 String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar; 52 String appJar = ClassFileInstaller.getJarPath("app.jar"); 53 54 Path userDir = Paths.get(System.getProperty("user.dir")); 55 Path moduleDir = Files.createTempDirectory(userDir, "mods"); 56 57 // Dump without --module-path 58 OutputAnalyzer output = TestCommon.dump(appJar, 59 TestCommon.list("CheckArchivedModuleApp"), 60 use_whitebox_jar); 61 TestCommon.checkDump(output); 62 63 // Test case 1) 64 // - Dump without --module-path 65 // - Run from -cp only, archived boot layer module ModuleDescriptors 66 // should be used. 67 System.out.println("----------------------- Test case 1 ----------------------"); 68 output = TestCommon.exec(appJar, use_whitebox_jar, 69 "-XX:+UnlockDiagnosticVMOptions", 70 "-XX:+WhiteBoxAPI", 71 "CheckArchivedModuleApp", 72 "yes"); 73 TestCommon.checkExec(output); 74 75 // Test case 2) 76 // - Dump without --module-path 77 // - Run from -cp only, archived boot layer module ModuleDescriptors 78 // should be used with --show-module-resolution (requires resolution). 79 System.out.println("----------------------- Test case 2 ----------------------"); 80 output = TestCommon.exec(appJar, use_whitebox_jar, 81 "--show-module-resolution", 82 "-XX:+UnlockDiagnosticVMOptions", 83 "-XX:+WhiteBoxAPI", 84 "CheckArchivedModuleApp", 85 "yes"); 86 TestCommon.checkExec(output); 87 88 // Test case 3) 89 // - Dump without --module-path 90 // - Run with --module-path, archived boot layer module ModuleDescriptors 91 // should be disabled. 92 System.out.println("----------------------- Test case 3 ----------------------"); 93 output = TestCommon.exec(appJar, use_whitebox_jar, 94 "--module-path", 95 moduleDir.toString(), 96 "-XX:+UnlockDiagnosticVMOptions", 97 "-XX:+WhiteBoxAPI", 98 "CheckArchivedModuleApp", 99 "no"); 100 TestCommon.checkExec(output); 101 102 // Dump with --module-path specified (test case 4, 5). Use an 103 // empty directory as it's simple and still triggers the case 104 // where system module objects are not archived. 105 output = TestCommon.dump(appJar, 106 TestCommon.list("CheckArchivedModuleApp"), 107 "--module-path", 108 moduleDir.toString(), 109 use_whitebox_jar); 110 TestCommon.checkDump(output); 111 112 // Test case 4) 113 // - Dump with --module-path 114 // - Run from -cp only, no archived boot layer module ModuleDescriptors 115 // should be found. 116 System.out.println("----------------------- Test case 4 ----------------------"); 117 output = TestCommon.exec(appJar, use_whitebox_jar, 118 "-XX:+UnlockDiagnosticVMOptions", 119 "-XX:+WhiteBoxAPI", 120 "CheckArchivedModuleApp", 121 "no"); 122 TestCommon.checkExec(output); 123 124 // Test case 5) 125 // - Dump with --module-path 126 // - Run with --module-path, no archived boot layer module ModuleDescriptors 127 // should be found. 128 System.out.println("----------------------- Test case 5 ----------------------"); 129 output = TestCommon.exec(appJar, use_whitebox_jar, 130 "--module-path", 131 moduleDir.toString(), 132 "-XX:+UnlockDiagnosticVMOptions", 133 "-XX:+WhiteBoxAPI", 134 "CheckArchivedModuleApp", 135 "no"); 136 TestCommon.checkExec(output); 137 } 138 }