8130681: Kitchensink startup crashes JVM with NMT overlapping ranges
authormockner
Thu, 24 Sep 2015 11:26:30 -0400
changeset 33099 55ad1d5370f6
parent 33098 2668fb702656
child 33101 4dc58e1ac2fb
8130681: Kitchensink startup crashes JVM with NMT overlapping ranges Summary: add_committed_region now handles overlapping commits. Reviewed-by: hseigel, coleenp
hotspot/src/share/vm/services/virtualMemoryTracker.cpp
hotspot/test/runtime/NMT/CommitOverlappingRegions.java
--- a/hotspot/src/share/vm/services/virtualMemoryTracker.cpp	Thu Sep 24 16:19:15 2015 +0200
+++ b/hotspot/src/share/vm/services/virtualMemoryTracker.cpp	Thu Sep 24 11:26:30 2015 -0400
@@ -84,7 +84,10 @@
         return _committed_regions.insert_after(committed_rgn, node) != NULL;
       }
     }
-    assert(rgn->contain_region(addr, size), "Must cover this region");
+    // If we have reached this point, then we are trying to commit a region that overlaps with some existing committed regions.
+    remove_uncommitted_region(addr, size);
+    add_committed_region(committed_rgn);
+
     return true;
   } else {
     // New committed region
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/NMT/CommitOverlappingRegions.java	Thu Sep 24 11:26:30 2015 -0400
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary Test commits of overlapping regions of memory.
+ * @key nmt jcmd
+ * @library /testlibrary /../../test/lib
+ * @modules java.base/sun.misc
+ *          java.management
+ * @build   CommitOverlappingRegions
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail CommitOverlappingRegions
+ */
+
+import jdk.test.lib.*;
+import sun.hotspot.WhiteBox;
+
+public class CommitOverlappingRegions {
+    public static WhiteBox wb = WhiteBox.getWhiteBox();
+    public static void main(String args[]) throws Exception {
+        OutputAnalyzer output;
+        long size = 32 * 1024;
+        long addr;
+
+        String pid = Integer.toString(ProcessTools.getProcessId());
+        ProcessBuilder pb = new ProcessBuilder();
+
+        addr = wb.NMTReserveMemory(8*size);        // [                ]
+        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail"});
+        // Test output before commits
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("(reserved=256KB, committed=0KB)");
+
+        // Commit regions 1 and 2, then test output.
+        wb.NMTCommitMemory(addr + 0*size, 3*size); // [       ]
+        wb.NMTCommitMemory(addr + 4*size, 3*size); //           [      ]
+
+        output = new OutputAnalyzer(pb.start());
+        output.shouldContain("(reserved=256KB, committed=192KB)");
+
+        // Commit the final region which overlaps partially with both regions.
+        wb.NMTCommitMemory(addr + 2*size, 3*size); //     [        ]
+
+        output = new OutputAnalyzer(pb.start());
+        output.getOutput();
+        output.shouldContain("(reserved=256KB, committed=224KB)");
+    }
+}