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