src/share/vm/runtime/thread.cpp

Print this page

        

@@ -3474,10 +3474,20 @@
 
   // At this point, the Universe is initialized, but we have not executed
   // any byte code.  Now is a good time (the only time) to dump out the
   // internal state of the JVM for sharing.
   if (DumpSharedSpaces) {
+    // To be able to load and dump the internal state we need the young
+    // generation to be large enough to avoid triggering a GC. By default
+    // the minimal young size will be enough, but if specifying
+    // ObjectAlignmentInBytes > 8 we need to ensure that it is at least 4M.
+    if (ObjectAlignmentInBytes > 8 && NewSize < 4*M) {
+      vm_exit_during_initialization(err_msg("Incompatible NewSize (" SIZE_FORMAT
+            "K) for use with ObjectAlignmentInBytes=" SIZE_FORMAT " and -Xshare:dump,"
+            " it needs to be at least " SIZE_FORMAT"K.",
+            NewSize/K, ObjectAlignmentInBytes, 4*M/K));
+    }
     MetaspaceShared::preload_and_dump(CHECK_0);
     ShouldNotReachHere();
   }
 
   // Always call even when there are not JVMTI environments yet, since environments