changeset 42584:ab0188378b7c

8169870: CDS: "assert(partition_size <= size()) failed: partition failed" on 32 bit JVM Summary: Exit the VM and report error if the second ReservedSpace() call also fails. Reviewed-by: cjplummer, sspitsyn, iklam
author jiangli
date Mon, 21 Nov 2016 21:07:45 -0500
parents b33957017897
children 570f4b5312af
files hotspot/src/share/vm/memory/metaspace.cpp hotspot/test/runtime/SharedArchiveFile/LargeSharedSpace.java
diffstat 2 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/share/vm/memory/metaspace.cpp	Mon Nov 21 17:38:13 2016 +0000
+++ b/hotspot/src/share/vm/memory/metaspace.cpp	Mon Nov 21 21:07:45 2016 -0500
@@ -489,6 +489,10 @@
       // Get a mmap region anywhere if the SharedBaseAddress fails.
       _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
     }
+    if (!_rs.is_reserved()) {
+      vm_exit_during_initialization("Unable to allocate memory for shared space",
+        err_msg(SIZE_FORMAT " bytes.", bytes));
+    }
     MetaspaceShared::initialize_shared_rs(&_rs);
   } else
 #endif
--- a/hotspot/test/runtime/SharedArchiveFile/LargeSharedSpace.java	Mon Nov 21 17:38:13 2016 +0000
+++ b/hotspot/test/runtime/SharedArchiveFile/LargeSharedSpace.java	Mon Nov 21 21:07:45 2016 -0500
@@ -23,10 +23,10 @@
 
 /*
  * @test LargeSharedSpace
- * @bug 8168790
+ * @bug 8168790 8169870
  * @summary Test CDS dumping with specific space size.
- * The space size used in the test might not be suitable on windows and 32-bit platforms.
- * @requires (sun.arch.data.model != "32") & (os.family != "windows")
+ * The space size used in the test might not be suitable on windows.
+ * @requires (os.family != "windows")
  * @library /test/lib
  * @modules java.base/jdk.internal.misc
  *          java.management
@@ -38,11 +38,24 @@
 
 public class LargeSharedSpace {
     public static void main(String[] args) throws Exception {
-       ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-            "-XX:SharedMiscCodeSize=1066924031", "-XX:+UnlockDiagnosticVMOptions",
-            "-XX:SharedArchiveFile=./LargeSharedSpace.jsa", "-Xshare:dump");
-       OutputAnalyzer output = new OutputAnalyzer(pb.start());
-       output.shouldContain("Loading classes to share");
-       output.shouldHaveExitValue(0);
+       String sizes[] = {"1066924031", "1600386047"};
+       String expectedOutputs[] =
+           {/* can dump using the given size */
+            "Loading classes to share",
+            /* the size is too large, exceeding the limit for compressed klass support */
+            "larger than compressed klass limit"};
+       for (int i = 0; i < sizes.length; i++) {
+           ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+                "-XX:SharedMiscCodeSize="+sizes[i], "-XX:+UnlockDiagnosticVMOptions",
+                "-XX:SharedArchiveFile=./LargeSharedSpace.jsa", "-Xshare:dump");
+           OutputAnalyzer output = new OutputAnalyzer(pb.start());
+           try {
+               output.shouldContain(expectedOutputs[i]);
+           } catch (RuntimeException e) {
+               /* failed to reserve the memory for the required size, might happen
+                  on 32-bit platforms */
+               output.shouldContain("Unable to allocate memory for shared space");
+           }
+       }
     }
 }