src/hotspot/share/services/virtualMemoryTracker.cpp
changeset 48815 d80d521e9cb1
parent 47553 5d20359dd938
child 48818 ec4a84ba2aaf
--- a/src/hotspot/share/services/virtualMemoryTracker.cpp	Mon Jan 29 11:55:40 2018 -0500
+++ b/src/hotspot/share/services/virtualMemoryTracker.cpp	Mon Jan 29 15:11:33 2018 +0100
@@ -65,16 +65,26 @@
     }
 
     if (rgn->adjacent_to(addr, size)) {
-      // special case to expand prior region if there is no next region
-      LinkedListNode<CommittedMemoryRegion>* next = node->next();
-      if (next == NULL && rgn->call_stack()->equals(stack)) {
-        VirtualMemorySummary::record_uncommitted_memory(rgn->size(), flag());
+      if (rgn->call_stack()->equals(stack)) {
         // the two adjacent regions have the same call stack, merge them
         rgn->expand_region(addr, size);
-        VirtualMemorySummary::record_committed_memory(rgn->size(), flag());
+        VirtualMemorySummary::record_committed_memory(size, flag());
+
+        // maybe merge with the next region
+        LinkedListNode<CommittedMemoryRegion>* next_node = node->next();
+        if (next_node != NULL) {
+          CommittedMemoryRegion* next = next_node->data();
+          if (next->call_stack()->equals(stack) && rgn->adjacent_to(next->base(), next->size())) {
+            // the two adjacent regions have the same call stack, merge them
+            rgn->expand_region(next->base(), next->size());
+
+            // the merge next_node needs to be removed from the list
+            _committed_regions.remove(next_node);
+          }
+        }
         return true;
       }
-      }
+    }
 
     if (rgn->overlap_region(addr, size)) {
       // Clear a space for this region in the case it overlaps with any regions.
@@ -87,10 +97,10 @@
     node = node->next();
   }
 
-    // New committed region
-    VirtualMemorySummary::record_committed_memory(size, flag());
-    return add_committed_region(committed_rgn);
-  }
+  // New committed region
+  VirtualMemorySummary::record_committed_memory(size, flag());
+  return add_committed_region(committed_rgn);
+}
 
 void ReservedMemoryRegion::set_all_committed(bool b) {
   if (all_committed() != b) {