< prev index next >

src/hotspot/share/services/virtualMemoryTracker.cpp

Print this page

        

@@ -63,17 +63,27 @@
     if (rgn->same_region(addr, size)) {
       return true;
     }
 
     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)) {

@@ -88,11 +98,11 @@
   }
 
     // 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) {
     _all_committed = b;
     if (b) {
< prev index next >