changeset 49847:f22c0b4caad7

8201850: [AOT] vm crash when run test compiler/aot/fingerprint/SelfChangedCDS.java Summary: set AOT specific compressed oop shift value before CDS archive load Reviewed-by: iklam, jiangli
author kvn
date Fri, 20 Apr 2018 14:30:57 -0700
parents a24f067a02dc
children fcd5df7aa235
files src/hotspot/share/aot/aotLoader.cpp src/hotspot/share/aot/aotLoader.hpp src/hotspot/share/memory/universe.cpp test/hotspot/jtreg/compiler/aot/fingerprint/CDSDumper.java test/hotspot/jtreg/compiler/aot/fingerprint/SelfChangedCDS.java
diffstat 5 files changed, 59 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/aot/aotLoader.cpp	Fri Apr 20 21:54:36 2018 +0200
+++ b/src/hotspot/share/aot/aotLoader.cpp	Fri Apr 20 14:30:57 2018 -0700
@@ -183,28 +183,21 @@
     // Shifts are static values which initialized by 0 until java heap initialization.
     // AOT libs are loaded before heap initialized so shift values are not set.
     // It is okay since ObjectAlignmentInBytes flag which defines shifts value is set before AOT libs are loaded.
-    // Set shifts value based on first AOT library config.
+    // AOT sets shift values during heap and metaspace initialization.
+    // Check shifts value to make sure thay did not change.
     if (UseCompressedOops && AOTLib::narrow_oop_shift_initialized()) {
       int oop_shift = Universe::narrow_oop_shift();
-      if (oop_shift == 0) {
-        Universe::set_narrow_oop_shift(AOTLib::narrow_oop_shift());
-      } else {
-        FOR_ALL_AOT_LIBRARIES(lib) {
-          (*lib)->verify_flag(AOTLib::narrow_oop_shift(), oop_shift, "Universe::narrow_oop_shift");
-        }
+      FOR_ALL_AOT_LIBRARIES(lib) {
+        (*lib)->verify_flag((*lib)->config()->_narrowOopShift, oop_shift, "Universe::narrow_oop_shift");
       }
       if (UseCompressedClassPointers) { // It is set only if UseCompressedOops is set
         int klass_shift = Universe::narrow_klass_shift();
-        if (klass_shift == 0) {
-          Universe::set_narrow_klass_shift(AOTLib::narrow_klass_shift());
-        } else {
-          FOR_ALL_AOT_LIBRARIES(lib) {
-            (*lib)->verify_flag(AOTLib::narrow_klass_shift(), klass_shift, "Universe::narrow_klass_shift");
-          }
+        FOR_ALL_AOT_LIBRARIES(lib) {
+          (*lib)->verify_flag((*lib)->config()->_narrowKlassShift, klass_shift, "Universe::narrow_klass_shift");
         }
       }
     }
-    // Create heaps for all the libraries
+    // Create heaps for all valid libraries
     FOR_ALL_AOT_LIBRARIES(lib) {
       if ((*lib)->is_valid()) {
         AOTCodeHeap* heap = new AOTCodeHeap(*lib);
@@ -213,6 +206,9 @@
           add_heap(heap);
           CodeCache::add_heap(heap);
         }
+      } else {
+        // Unload invalid libraries
+        os::dll_unload((*lib)->dl_handle());
       }
     }
   }
@@ -223,20 +219,29 @@
   }
 }
 
+// Set shift value for compressed oops and classes based on first AOT library config.
+// AOTLoader::universe_init(), which is called later, will check the shift value again to make sure nobody change it.
+// This code is not executed during CDS dump because it runs in Interpreter mode and AOT is disabled in this mode.
+
+void AOTLoader::set_narrow_oop_shift() {
+  // This method is called from Universe::initialize_heap().
+  if (UseAOT && libraries_count() > 0 &&
+      UseCompressedOops && AOTLib::narrow_oop_shift_initialized()) {
+    if (Universe::narrow_oop_shift() == 0) {
+      // 0 is valid shift value for small heap but we can safely increase it
+      // at this point when nobody used it yet.
+      Universe::set_narrow_oop_shift(AOTLib::narrow_oop_shift());
+    }
+  }
+}
+
 void AOTLoader::set_narrow_klass_shift() {
-  // This method could be called from Metaspace::set_narrow_klass_base_and_shift().
-  // In case it is not called (during dump CDS, for example) the corresponding code in
-  // AOTLoader::universe_init(), which is called later, will set the shift value.
+  // This method is called from Metaspace::set_narrow_klass_base_and_shift().
   if (UseAOT && libraries_count() > 0 &&
       UseCompressedOops && AOTLib::narrow_oop_shift_initialized() &&
       UseCompressedClassPointers) {
-    int klass_shift = Universe::narrow_klass_shift();
-    if (klass_shift == 0) {
+    if (Universe::narrow_klass_shift() == 0) {
       Universe::set_narrow_klass_shift(AOTLib::narrow_klass_shift());
-    } else {
-      FOR_ALL_AOT_LIBRARIES(lib) {
-        (*lib)->verify_flag(AOTLib::narrow_klass_shift(), klass_shift, "Universe::narrow_klass_shift");
-      }
     }
   }
 }
--- a/src/hotspot/share/aot/aotLoader.hpp	Fri Apr 20 21:54:36 2018 +0200
+++ b/src/hotspot/share/aot/aotLoader.hpp	Fri Apr 20 14:30:57 2018 -0700
@@ -57,6 +57,7 @@
   static void initialize() NOT_AOT({ FLAG_SET_ERGO(bool, UseAOT, false); });
 
   static void universe_init() NOT_AOT_RETURN;
+  static void set_narrow_oop_shift() NOT_AOT_RETURN;
   static void set_narrow_klass_shift() NOT_AOT_RETURN;
   static bool contains(address p) NOT_AOT({ return false; });
   static void load_for_klass(InstanceKlass* ik, Thread* thread) NOT_AOT_RETURN;
--- a/src/hotspot/share/memory/universe.cpp	Fri Apr 20 21:54:36 2018 +0200
+++ b/src/hotspot/share/memory/universe.cpp	Fri Apr 20 14:30:57 2018 -0700
@@ -786,6 +786,7 @@
       // Did reserve heap below 32Gb. Can use base == 0;
       Universe::set_narrow_oop_base(0);
     }
+    AOTLoader::set_narrow_oop_shift();
 
     Universe::set_narrow_ptrs_base(Universe::narrow_oop_base());
 
--- a/test/hotspot/jtreg/compiler/aot/fingerprint/CDSDumper.java	Fri Apr 20 21:54:36 2018 +0200
+++ b/test/hotspot/jtreg/compiler/aot/fingerprint/CDSDumper.java	Fri Apr 20 14:30:57 2018 -0700
@@ -31,18 +31,19 @@
 import jdk.test.lib.process.ProcessTools;
 
 // Usage:
-// java CDSDumper <classpath> <classlist> <archive> <class1> <class2> ...
+// java CDSDumper <classpath> <classlist> <archive> <heapsize> <class1> <class2> ...
 public class CDSDumper {
     public static void main(String[] args) throws Exception {
         String classpath = args[0];
         String classlist = args[1];
         String archive = args[2];
+        String heapsize = args[3];
 
         // Prepare the classlist
         FileOutputStream fos = new FileOutputStream(classlist);
         PrintStream ps = new PrintStream(fos);
 
-        for (int i=3; i<args.length; i++) {
+        for (int i=4; i<args.length; i++) {
             ps.println(args[i].replace('.', '/'));
         }
         ps.close();
@@ -50,6 +51,7 @@
 
         // Dump the archive
         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            heapsize,
             "-XX:+IgnoreUnrecognizedVMOptions",
             "-XX:+UnlockCommercialFeatures",
             "-XX:+UseAppCDS",
@@ -58,9 +60,12 @@
             "-XX:ExtraSharedClassListFile=" + classlist,
             "-XX:SharedArchiveFile=" + archive,
             "-Xshare:dump",
+            "-Xlog:gc+heap+coops",
             "-Xlog:cds");
 
         OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        System.out.println("[stdout = " + output.getStdout() + "]");
+        System.out.println("[stderr = " + output.getStderr() + "]");
         output.shouldContain("Loading classes to share");
         output.shouldHaveExitValue(0);
     }
--- a/test/hotspot/jtreg/compiler/aot/fingerprint/SelfChangedCDS.java	Fri Apr 20 21:54:36 2018 +0200
+++ b/test/hotspot/jtreg/compiler/aot/fingerprint/SelfChangedCDS.java	Fri Apr 20 14:30:57 2018 -0700
@@ -36,7 +36,7 @@
  *      -class compiler.aot.fingerprint.Blah
  *
  * @run driver ClassFileInstaller -jar SelfChangedCDS.jar compiler.aot.fingerprint.Blah
- * @run main compiler.aot.fingerprint.CDSDumper SelfChangedCDS.jar SelfChangedCDS.classlist SelfChangedCDS.jsa
+ * @run main compiler.aot.fingerprint.CDSDumper SelfChangedCDS.jar SelfChangedCDS.classlist SelfChangedCDS.jsa -showversion
  *      compiler.aot.fingerprint.Blah
  *
  * @run main compiler.aot.fingerprint.CDSRunner -cp SelfChangedCDS.jar
@@ -46,6 +46,7 @@
  *      -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=SelfChangedCDS.jsa
  *      -XX:+IgnoreUnrecognizedVMOptions
  *      -Xshare:auto -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -showversion
+ *      -Xlog:cds -Xlog:gc+heap+coops
  *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
  *      compiler.aot.fingerprint.Blah TEST-UNMODIFIED
  *
@@ -61,6 +62,26 @@
  *      -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=SelfChangedCDS.jsa
  *      -XX:+IgnoreUnrecognizedVMOptions
  *      -Xshare:auto -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -showversion
+ *      -Xlog:cds -Xlog:gc+heap+coops
  *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
  *      compiler.aot.fingerprint.Blah TEST-MODIFIED
+ *
+ *
+ * @run driver compiler.aot.AotCompiler -libname libSelfChanged.so
+ *      -class compiler.aot.fingerprint.Blah
+ *      -extraopt -Xmx512m
+ *
+ * @run main compiler.aot.fingerprint.CDSDumper SelfChangedCDS.jar SelfChangedCDS.classlist SelfChangedCDS.jsa -Xmx512m
+ *      compiler.aot.fingerprint.Blah
+ *
+ * @run main compiler.aot.fingerprint.CDSRunner -Xmx512m -cp SelfChangedCDS.jar
+ *      compiler.aot.fingerprint.Blah TEST-UNMODIFIED
+ * @run main compiler.aot.fingerprint.CDSRunner -Xmx512m -cp SelfChangedCDS.jar
+ *      -XX:+UseAOT -XX:+PrintAOT -XX:AOTLibrary=./libSelfChanged.so
+ *      -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=SelfChangedCDS.jsa
+ *      -XX:+IgnoreUnrecognizedVMOptions
+ *      -Xshare:auto -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -showversion
+ *      -Xlog:cds -Xlog:gc+heap+coops
+ *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
+ *      compiler.aot.fingerprint.Blah TEST-UNMODIFIED
  */