--- old/src/hotspot/share/services/virtualMemoryTracker.cpp 2018-01-26 10:31:36.273197879 +0100 +++ new/src/hotspot/share/services/virtualMemoryTracker.cpp 2018-01-26 10:31:35.973187982 +0100 @@ -65,16 +65,26 @@ } if (rgn->adjacent_to(addr, size)) { - // special case to expand prior region if there is no next region - LinkedListNode* 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* 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) {