3131 * @requires vm.cds.supports.aot.class.linking
3232 * @comment work around JDK-8345635
3333 * @requires !vm.jvmci.enabled
34- * @library /test/jdk/lib/testlibrary /test/lib
34+ * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes
3535 * @build InitiatingLoaderTester BadOldClassA BadOldClassB
36- * @build BulkLoaderTest
36+ * @build jdk.test.whitebox.WhiteBox BulkLoaderTest SimpleCusty
3737 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar BulkLoaderTestApp.jar BulkLoaderTestApp MyUtil InitiatingLoaderTester
3838 * BadOldClassA BadOldClassB
39+ * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar cust.jar
40+ * SimpleCusty
41+ * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar jdk.test.whitebox.WhiteBox
3942 * @run driver BulkLoaderTest STATIC
4043 */
4144
4447 * @requires vm.cds.supports.aot.class.linking
4548 * @comment work around JDK-8345635
4649 * @requires !vm.jvmci.enabled
47- * @library /test/jdk/lib/testlibrary /test/lib
50+ * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes
4851 * @build InitiatingLoaderTester BadOldClassA BadOldClassB
49- * @build jdk.test.whitebox.WhiteBox BulkLoaderTest
52+ * @build jdk.test.whitebox.WhiteBox BulkLoaderTest SimpleCusty
5053 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar BulkLoaderTestApp.jar BulkLoaderTestApp MyUtil InitiatingLoaderTester
5154 * BadOldClassA BadOldClassB
52- * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
53- * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. BulkLoaderTest DYNAMIC
55+ * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar cust.jar
56+ * SimpleCusty
57+ * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar jdk.test.whitebox.WhiteBox
58+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:WhiteBox.jar BulkLoaderTest DYNAMIC
5459 */
5560
5661/*
5762 * @test id=aot
5863 * @requires vm.cds.supports.aot.class.linking
5964 * @comment work around JDK-8345635
6065 * @requires !vm.jvmci.enabled
61- * @library /test/jdk/lib/testlibrary /test/lib
62- * @build InitiatingLoaderTester BadOldClassA BadOldClassB
63- * @build BulkLoaderTest
66+ * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes
67+ * @build jdk.test.whitebox.WhiteBox InitiatingLoaderTester BadOldClassA BadOldClassB
68+ * @build BulkLoaderTest SimpleCusty
6469 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar BulkLoaderTestApp.jar BulkLoaderTestApp MyUtil InitiatingLoaderTester
6570 * BadOldClassA BadOldClassB
71+ * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar jdk.test.whitebox.WhiteBox
72+ * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar cust.jar
73+ * SimpleCusty
6674 * @run driver BulkLoaderTest AOT
6775 */
6876
6977import java .io .File ;
7078import java .lang .StackWalker .StackFrame ;
79+ import java .net .URL ;
80+ import java .net .URLClassLoader ;
7181import java .util .List ;
7282import java .util .regex .Matcher ;
7383import java .util .regex .Pattern ;
7686import jdk .test .lib .cds .CDSAppTester ;
7787import jdk .test .lib .helpers .ClassFileInstaller ;
7888import jdk .test .lib .process .OutputAnalyzer ;
89+ import jdk .test .whitebox .WhiteBox ;
7990
8091public class BulkLoaderTest {
8192 static final String appJar = ClassFileInstaller .getJarPath ("BulkLoaderTestApp.jar" );
@@ -114,6 +125,7 @@ public static void main(String[] args) throws Exception {
114125 static class Tester extends CDSAppTester {
115126 public Tester () {
116127 super (mainClass );
128+ useWhiteBox (ClassFileInstaller .getJarPath ("WhiteBox.jar" ));
117129 }
118130
119131 @ Override
@@ -124,7 +136,7 @@ public String classpath(RunMode runMode) {
124136 @ Override
125137 public String [] vmArgs (RunMode runMode ) {
126138 return new String [] {
127- "-Xlog:cds,cds+aot+load" ,
139+ "-Xlog:cds,cds+aot+load,cds+class=debug " ,
128140 "-XX:+AOTClassLinking" ,
129141 };
130142 }
@@ -140,6 +152,12 @@ public String[] appCommandLine(RunMode runMode) {
140152 public void checkExecution (OutputAnalyzer out , RunMode runMode ) throws Exception {
141153 if (isAOTWorkflow () && runMode == RunMode .TRAINING ) {
142154 out .shouldContain ("Skipping BadOldClassA: Unlinked class not supported by AOTConfiguration" );
155+ out .shouldContain ("Skipping SimpleCusty: Duplicated unregistered class" );
156+ }
157+
158+ if (isDumping (runMode )) {
159+ // Check that we are archiving classes for custom class loaders.
160+ out .shouldMatch ("cds,class.* SimpleCusty" );
143161 }
144162 }
145163 }
@@ -152,6 +170,7 @@ public static void main(String args[]) throws Exception {
152170 checkClasses ();
153171 checkInitiatingLoader ();
154172 checkOldClasses ();
173+ checkCustomLoader ();
155174 }
156175
157176 // Check the ClassLoader/Module/Package/ProtectionDomain/CodeSource of classes that are aot-linked
@@ -275,6 +294,38 @@ static void checkOldClasses() throws Exception {
275294 System .out .println ("Caught VerifyError for BadOldClassB: " + e );
276295 }
277296 }
297+
298+
299+ static void checkCustomLoader () throws Exception {
300+ WhiteBox wb = WhiteBox .getWhiteBox ();
301+ for (int i = 0 ; i < 2 ; i ++) {
302+ Object o = initFromCustomLoader ();
303+ System .out .println (o );
304+ Class c = o .getClass ();
305+ if (wb .isSharedClass (BulkLoaderTestApp .class )) {
306+ // We are running with BulkLoaderTestApp from the AOT cache (or CDS achive)
307+ if (i == 0 ) {
308+ if (!wb .isSharedClass (c )) {
309+ throw new RuntimeException ("The first loader should load SimpleCusty from AOT cache (or CDS achive)" );
310+ }
311+ } else {
312+ if (wb .isSharedClass (c )) {
313+ throw new RuntimeException ("The second loader should not load SimpleCusty from AOT cache (or CDS achive)" );
314+ }
315+ }
316+ }
317+ }
318+ }
319+
320+ static Object initFromCustomLoader () throws Exception {
321+ String path = "cust.jar" ;
322+ URL url = new File (path ).toURI ().toURL ();
323+ URL [] urls = new URL [] {url };
324+ URLClassLoader urlClassLoader =
325+ new URLClassLoader ("MyLoader" , urls , null );
326+ Class c = Class .forName ("SimpleCusty" , true , urlClassLoader );
327+ return c .newInstance ();
328+ }
278329}
279330
280331class MyUtil {
0 commit comments