8196121: runtime/appcds/ClassLoaderTest.java fails silently
authoriklam
Sun, 04 Mar 2018 22:24:06 -0800
changeset 49335 3271310a6af7
parent 49334 aefee96e2b90
child 49336 4b7dae855f23
8196121: runtime/appcds/ClassLoaderTest.java fails silently Reviewed-by: mseledtsov, jiangli, ccheung
test/hotspot/jtreg/runtime/appcds/ClassLoaderTest.java
test/hotspot/jtreg/runtime/appcds/test-classes/ForNameTest.java
test/hotspot/jtreg/runtime/appcds/test-classes/HelloWB.java
--- a/test/hotspot/jtreg/runtime/appcds/ClassLoaderTest.java	Sun Mar 04 20:57:46 2018 -0500
+++ b/test/hotspot/jtreg/runtime/appcds/ClassLoaderTest.java	Sun Mar 04 22:24:06 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -62,15 +62,10 @@
 
         TestCommon.dump(appJar, appClasses, bootClassPath);
 
-        OutputAnalyzer runtimeOutput = TestCommon.execCommon(
+        TestCommon.run(
             "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
-            "-cp", appJar, bootClassPath, "-Xlog:class+load", "HelloWB");
-
-        if (!TestCommon.isUnableToMap(runtimeOutput)) {
-            runtimeOutput.shouldNotContain(
-                "[class,load] HelloWB source: shared objects file by jdk/internal/misc/ClassLoaders$AppClassLoader");
-            runtimeOutput.shouldContain("[class,load] HelloWB source: shared objects file");
-        }
+            "-cp", appJar, bootClassPath, "HelloWB")
+          .assertNormalExit(output -> output.shouldContain("HelloWB.class.getClassLoader() = null"));
     }
 
     public void testDefiningLoader() throws Exception {
@@ -84,9 +79,11 @@
         String bootClassPath = "-Xbootclasspath/a:" + helloJar +
             File.pathSeparator + whiteBoxJar;
 
+        // Archive the "Hello" class from the appended bootclasspath
         TestCommon.dump(helloJar, TestCommon.list("Hello"), bootClassPath);
 
-        TestCommon.execCommon("-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
-            "-cp", appJar, bootClassPath, "-XX:+TraceClassPaths", "ForNameTest");
+        TestCommon.run("-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
+            "-cp", appJar, bootClassPath, "-Xlog:class+path=trace", "ForNameTest")
+          .assertNormalExit();
     }
 }
--- a/test/hotspot/jtreg/runtime/appcds/test-classes/ForNameTest.java	Sun Mar 04 20:57:46 2018 -0500
+++ b/test/hotspot/jtreg/runtime/appcds/test-classes/ForNameTest.java	Sun Mar 04 22:24:06 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,7 @@
 public class ForNameTest {
     public static void main(String[] args) throws Throwable {
         // Hello is on the bootclasspath. The defining classloader is
-        // the NULL classloader. See AppCDSClassLoaderTest.
+        // the NULL classloader. See ../ClassLoaderTest.java
         Class c = Class.forName("Hello");
         ClassLoader cl = c.getClassLoader();
         if (cl != null) {
@@ -36,10 +36,10 @@
         }
 
         WhiteBox wb = WhiteBox.getWhiteBox();
-        if (!wb.isSharedClass(c)) {
-            System.out.println("As expected, Hello.class is not in shared space.");
+        if (wb.isSharedClass(c)) {
+            System.out.println("As expected, Hello.class is in shared space.");
         } else {
-            throw new java.lang.RuntimeException("Hello.class shouldn't be in shared space.");
+            throw new java.lang.RuntimeException("Hello.class must be in shared space.");
         }
     }
 }
--- a/test/hotspot/jtreg/runtime/appcds/test-classes/HelloWB.java	Sun Mar 04 20:57:46 2018 -0500
+++ b/test/hotspot/jtreg/runtime/appcds/test-classes/HelloWB.java	Sun Mar 04 22:24:06 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
 
 public class HelloWB {
     public static void main(String[] args) throws Throwable {
+        System.out.println("HelloWB.class.getClassLoader() = " + HelloWB.class.getClassLoader());
 
         WhiteBox wb = WhiteBox.getWhiteBox();
         if (wb.isSharedClass(HelloWB.class)) {