22 * 23 */ 24 25 /* 26 * @test 27 * @summary Check that during dumping, the classes for BOOT/EXT/APP loaders are segregated from the 28 * custom loader classes. 29 * @requires vm.cds 30 * @requires vm.cds.custom.loaders 31 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds 32 * @modules java.base/jdk.internal.misc 33 * java.management 34 * jdk.jartool/sun.tools.jar 35 * @compile test-classes/LoaderSegregation.java 36 * test-classes/CustomLoadee.java test-classes/CustomLoadee2.java 37 * test-classes/CustomInterface2_ia.java test-classes/CustomInterface2_ib.java 38 * test-classes/CustomLoadee3.java test-classes/CustomLoadee3Child.java 39 * test-classes/OnlyBuiltin.java 40 * test-classes/OnlyUnregistered.java 41 * ../test-classes/Util.java 42 * @build sun.hotspot.WhiteBox 43 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 44 * @run driver LoaderSegregationTest 45 */ 46 47 import jdk.test.lib.process.OutputAnalyzer; 48 import sun.hotspot.WhiteBox; 49 50 /** 51 * See "Handling of the classes in the AppCDS archive" at the top of 52 * systemDicrionatyShared.hpp. 53 * 54 * This test ensure that the 2 types of archived classes (BUILTIN and UNREGISTERED) 55 * are segregated at both dump-time and run time: 56 * 57 * [A] An archived BUILTIN class cannot be a subclass of a non-BUILTIN class. 58 * [B] An archived BUILTIN class cannot implement a non-BUILTIN interface. 59 * [C] BUILTIN and UNREGISTERED classes can be loaded only by their corresponding 60 * type of loaders. 61 * 62 */ 63 public class LoaderSegregationTest { 64 public static void main(String[] args) throws Exception { 65 String wbJar = JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox"); 66 String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar; 67 68 String appJar = JarBuilder.build("LoaderSegregation_app", "LoaderSegregation", 69 "CustomLoadee", "CustomLoadee2", "CustomLoadee3Child", "CustomInterface2_ia", 70 "OnlyBuiltin", "Util"); 71 72 String app2Jar = JarBuilder.build("LoaderSegregation_app2", "CustomLoadee3", "CustomInterface2_ib"); 73 74 String customJarPath = JarBuilder.build("LoaderSegregation_custom", "CustomLoadee", 75 "CustomLoadee2", "CustomInterface2_ia", "CustomInterface2_ib", 76 "CustomLoadee3", "CustomLoadee3Child", 77 "OnlyBuiltin", "OnlyUnregistered"); 78 79 // Dump the archive 80 String classlist[] = new String[] { 81 "LoaderSegregation", 82 "java/lang/Object id: 1", 83 84 // These are the UNREGISTERED classes: they have "source:" 85 // but they don't have "loader:". 86 "CustomLoadee id: 2 super: 1 source: " + customJarPath, 87 88 "CustomInterface2_ia id: 3 super: 1 source: " + customJarPath, 89 "CustomInterface2_ib id: 4 super: 1 source: " + customJarPath, 90 "CustomLoadee2 id: 5 super: 1 interfaces: 3 4 source: " + customJarPath, 91 92 "CustomLoadee3 id: 6 super: 1 source: " + customJarPath, 93 "CustomLoadee3Child id: 7 super: 6 source: " + customJarPath, 94 95 // At dump time, the following BUILTIN classes are loaded after the UNREGISTERED 96 // classes from above. However, at dump time, they cannot use the UNREGISTERED classes are their 97 // super or interface. 98 "CustomLoadee", // can be loaded at dump time 99 "CustomLoadee2", // cannot be loaded at dump time (interface missing) 100 "CustomLoadee3Child", // cannot be loaded at dump time (super missing) 101 102 // Check that BUILTIN and UNREGISTERED classes can be loaded only by their 103 // corresponding type of loaders. 104 "OnlyBuiltin", 105 "OnlyUnregistered id: 9 super: 1 source: " + customJarPath, 106 }; 107 108 OutputAnalyzer output; 109 TestCommon.testDump(appJar, classlist, 110 // command-line arguments ... 111 use_whitebox_jar); 112 113 output = TestCommon.exec(TestCommon.concatPaths(appJar, app2Jar), 114 // command-line arguments ... 115 "--add-opens=java.base/java.lang=ALL-UNNAMED", 116 "--add-opens=java.base/java.security=ALL-UNNAMED", 117 use_whitebox_jar, 118 "-XX:+UnlockDiagnosticVMOptions", 119 "-XX:+WhiteBoxAPI", 120 "LoaderSegregation", customJarPath); 121 TestCommon.checkExec(output); 122 } 123 } | 22 * 23 */ 24 25 /* 26 * @test 27 * @summary Check that during dumping, the classes for BOOT/EXT/APP loaders are segregated from the 28 * custom loader classes. 29 * @requires vm.cds 30 * @requires vm.cds.custom.loaders 31 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds 32 * @modules java.base/jdk.internal.misc 33 * java.management 34 * jdk.jartool/sun.tools.jar 35 * @compile test-classes/LoaderSegregation.java 36 * test-classes/CustomLoadee.java test-classes/CustomLoadee2.java 37 * test-classes/CustomInterface2_ia.java test-classes/CustomInterface2_ib.java 38 * test-classes/CustomLoadee3.java test-classes/CustomLoadee3Child.java 39 * test-classes/OnlyBuiltin.java 40 * test-classes/OnlyUnregistered.java 41 * ../test-classes/Util.java 42 * ../test-classes/Hello.java 43 * @build sun.hotspot.WhiteBox 44 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 45 * @run driver LoaderSegregationTest 46 */ 47 48 import jdk.test.lib.process.OutputAnalyzer; 49 import sun.hotspot.WhiteBox; 50 51 /** 52 * See "Handling of the classes in the AppCDS archive" at the top of 53 * systemDicrionatyShared.hpp. 54 * 55 * This test ensure that the 2 types of archived classes (BUILTIN and UNREGISTERED) 56 * are segregated at both dump-time and run time: 57 * 58 * [A] An archived BUILTIN class cannot be a subclass of a non-BUILTIN class. 59 * [B] An archived BUILTIN class cannot implement a non-BUILTIN interface. 60 * [C] BUILTIN and UNREGISTERED classes can be loaded only by their corresponding 61 * type of loaders. 62 * 63 */ 64 public class LoaderSegregationTest { 65 public static void main(String[] args) throws Exception { 66 String wbJar = JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox"); 67 String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar; 68 69 String appJar = JarBuilder.build("LoaderSegregation_app", "LoaderSegregation", 70 "CustomLoadee", "CustomLoadee2", "CustomLoadee3Child", "CustomInterface2_ia", 71 "OnlyBuiltin", "Util"); 72 73 String app2Jar = JarBuilder.build("LoaderSegregation_app2", "CustomLoadee3", "CustomInterface2_ib"); 74 75 String customJarPath = JarBuilder.build("LoaderSegregation_custom", "CustomLoadee", 76 "CustomLoadee2", "CustomInterface2_ia", "CustomInterface2_ib", 77 "CustomLoadee3", "CustomLoadee3Child", 78 "OnlyBuiltin", "OnlyUnregistered", "Hello"); 79 80 // Dump the archive 81 String classlist[] = new String[] { 82 "LoaderSegregation", 83 "java/lang/Object id: 1", 84 85 // These are the UNREGISTERED classes: they have "source:" 86 // but they don't have "loader:". 87 "CustomLoadee id: 2 super: 1 source: " + customJarPath, 88 89 "CustomInterface2_ia id: 3 super: 1 source: " + customJarPath, 90 "CustomInterface2_ib id: 4 super: 1 source: " + customJarPath, 91 "CustomLoadee2 id: 5 super: 1 interfaces: 3 4 source: " + customJarPath, 92 93 "CustomLoadee3 id: 6 super: 1 source: " + customJarPath, 94 "CustomLoadee3Child id: 7 super: 6 source: " + customJarPath, 95 96 // At dump time, the following BUILTIN classes are loaded after the UNREGISTERED 97 // classes from above. However, at dump time, they cannot use the UNREGISTERED classes are their 98 // super or interface. 99 "CustomLoadee", // can be loaded at dump time 100 "CustomLoadee2", // cannot be loaded at dump time (interface missing) 101 "CustomLoadee3Child", // cannot be loaded at dump time (super missing) 102 103 // Check that BUILTIN and UNREGISTERED classes can be loaded only by their 104 // corresponding type of loaders. 105 "OnlyBuiltin", 106 "OnlyUnregistered id: 9 super: 1 source: " + customJarPath, 107 }; 108 109 OutputAnalyzer output; 110 TestCommon.testDump(appJar, classlist, 111 // command-line arguments ... 112 use_whitebox_jar); 113 114 output = TestCommon.exec(TestCommon.concatPaths(appJar, app2Jar), 115 // command-line arguments ... 116 use_whitebox_jar, 117 "-XX:+UnlockDiagnosticVMOptions", 118 "-XX:+WhiteBoxAPI", 119 "LoaderSegregation", customJarPath); 120 TestCommon.checkExec(output); 121 } 122 } |