--- old/src/share/vm/memory/metaspace.cpp 2016-11-18 20:55:17.853405215 -0500 +++ new/src/share/vm/memory/metaspace.cpp 2016-11-18 20:55:16.285316342 -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 --- old/test/runtime/SharedArchiveFile/LargeSharedSpace.java 2016-11-18 20:55:22.861689062 -0500 +++ new/test/runtime/SharedArchiveFile/LargeSharedSpace.java 2016-11-18 20:55:21.041585907 -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,19 @@ 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[] = {"Loading classes to share", + "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) { + output.shouldContain("Unable to allocate memory for shared space"); + } + } } }