8174101: Bootclasspath append should not invalidate CDS archive
authorccheung
Thu, 30 Nov 2017 14:25:33 -0800
changeset 48171 7ad2d33a0f05
parent 48170 3af0ab7d1d90
child 48172 e26fc5201707
8174101: Bootclasspath append should not invalidate CDS archive Reviewed-by: iklam, jiangli
src/hotspot/share/classfile/sharedPathsMiscInfo.cpp
test/hotspot/jtreg/runtime/SharedArchiveFile/BootAppendTests.java
test/hotspot/jtreg/runtime/appcds/BootClassPathMismatch.java
--- a/src/hotspot/share/classfile/sharedPathsMiscInfo.cpp	Thu Nov 30 16:00:34 2017 -0500
+++ b/src/hotspot/share/classfile/sharedPathsMiscInfo.cpp	Thu Nov 30 14:25:33 2017 -0800
@@ -139,7 +139,8 @@
 bool SharedPathsMiscInfo::check(jint type, const char* path) {
   switch (type) {
   case BOOT:
-    if (os::file_name_strcmp(path, Arguments::get_sysclasspath()) != 0) {
+    // In the future we should perform the check based on the content of the mapped archive.
+    if (UseAppCDS && os::file_name_strcmp(path, Arguments::get_sysclasspath()) != 0) {
       return fail("[BOOT classpath mismatch, actual =", Arguments::get_sysclasspath());
     }
     break;
--- a/test/hotspot/jtreg/runtime/SharedArchiveFile/BootAppendTests.java	Thu Nov 30 16:00:34 2017 -0500
+++ b/test/hotspot/jtreg/runtime/SharedArchiveFile/BootAppendTests.java	Thu Nov 30 14:25:33 2017 -0800
@@ -86,6 +86,9 @@
 
         logTestCase("5");
         testBootAppendClass();
+
+        logTestCase("6");
+        testBootAppendExtraDir();
     }
 
     private static void logTestCase(String msg) {
@@ -241,4 +244,28 @@
             }
         }
     }
+
+    // Test #6: This is similar to Test #5. During runtime, an extra dir
+    //          is appended to the bootclasspath. It should not invalidate
+    //          the shared archive.
+    public static void testBootAppendExtraDir() throws Exception {
+        for (String mode : modes) {
+            CDSOptions opts = (new CDSOptions())
+                .setXShareMode(mode).setUseVersion(false)
+                .addPrefix("-Xbootclasspath/a:" + bootAppendJar + File.pathSeparator + appJar,
+                           "-showversion", "--limit-modules=java.base", "-cp", appJar)
+                .addSuffix("-Xlog:class+load=info",
+                           APP_CLASS, BOOT_APPEND_CLASS_NAME);
+
+            OutputAnalyzer out = CDSTestUtils.runWithArchive(opts);
+            CDSTestUtils.checkExec(out, opts, "[class,load] nonjdk.myPackage.MyClass");
+
+            // If CDS is enabled, the nonjdk.myPackage.MyClass should be loaded
+            // from the shared archive.
+            if (mode.equals("on")) {
+                CDSTestUtils.checkExec(out, opts,
+                    "[class,load] nonjdk.myPackage.MyClass source: shared objects file");
+            }
+        }
+    }
 }
--- a/test/hotspot/jtreg/runtime/appcds/BootClassPathMismatch.java	Thu Nov 30 16:00:34 2017 -0500
+++ b/test/hotspot/jtreg/runtime/appcds/BootClassPathMismatch.java	Thu Nov 30 14:25:33 2017 -0800
@@ -52,6 +52,7 @@
 
         BootClassPathMismatch test = new BootClassPathMismatch();
         test.testBootClassPathMismatch();
+        test.testBootClassPathMismatch2();
         test.testBootClassPathMatch();
     }
 
@@ -78,6 +79,26 @@
         }
     }
 
+    /* Error should be detected if:
+     * dump time: <no bootclasspath specified>
+     * run-time : -Xbootclasspath/a:${testdir}/hello.jar
+     */
+    public void testBootClassPathMismatch2() throws Exception {
+        String appJar = JarBuilder.getOrCreateHelloJar();
+        String appClasses[] = {"Hello"};
+        OutputAnalyzer dumpOutput = TestCommon.dump(appJar, appClasses);
+        OutputAnalyzer execOutput = TestCommon.exec(
+            appJar, "-verbose:class", "-Xbootclasspath/a:" + appJar, "Hello");
+        try {
+            TestCommon.checkExec(execOutput, mismatchMessage);
+        } catch (java.lang.RuntimeException re) {
+          String cause = re.getMessage();
+          if (!mismatchMessage.equals(cause)) {
+              throw re;
+          }
+        }
+    }
+
     /* No error if:
      * dump time: -Xbootclasspath/a:${testdir}/hello.jar
      * run-time : -Xbootclasspath/a:${testdir}/hello.jar