From 2c358c59edd2c9dd6c8942ef650adf1564c96fa6 Mon Sep 17 00:00:00 2001 From: Albert Yang Date: Mon, 16 Jun 2025 17:26:47 +0200 Subject: [PATCH 1/2] g1-expand-time --- src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 15 +++++---------- src/hotspot/share/gc/g1/g1CollectedHeap.hpp | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index c83414eac82ee..873d6bddf87b0 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -1001,7 +1001,7 @@ HeapWord* G1CollectedHeap::expand_and_allocate(size_t word_size) { return nullptr; } -bool G1CollectedHeap::expand(size_t expand_bytes, WorkerThreads* pretouch_workers, double* expand_time_ms) { +bool G1CollectedHeap::expand(size_t expand_bytes, WorkerThreads* pretouch_workers) { size_t aligned_expand_bytes = os::align_up_vm_page_size(expand_bytes); aligned_expand_bytes = align_up(aligned_expand_bytes, G1HeapRegion::GrainBytes); @@ -1013,15 +1013,10 @@ bool G1CollectedHeap::expand(size_t expand_bytes, WorkerThreads* pretouch_worker return false; } - double expand_heap_start_time_sec = os::elapsedTime(); uint regions_to_expand = (uint)(aligned_expand_bytes / G1HeapRegion::GrainBytes); assert(regions_to_expand > 0, "Must expand by at least one region"); uint expanded_by = _hrm.expand_by(regions_to_expand, pretouch_workers); - if (expand_time_ms != nullptr) { - *expand_time_ms = (os::elapsedTime() - expand_heap_start_time_sec) * MILLIUNITS; - } - assert(expanded_by > 0, "must have failed during commit."); size_t actual_expand_bytes = expanded_by * G1HeapRegion::GrainBytes; @@ -2397,11 +2392,11 @@ void G1CollectedHeap::expand_heap_after_young_collection(){ if (expand_bytes > 0) { // No need for an ergo logging here, // expansion_amount() does this when it returns a value > 0. - double expand_ms = 0.0; - if (!expand(expand_bytes, _workers, &expand_ms)) { - // We failed to expand the heap. Cannot do anything about it. + Ticks expand_start_instant = Ticks::now(); + if (expand(expand_bytes, _workers)) { + double expand_ms = (Ticks::now() - expand_start_instant).seconds() * MILLIUNITS; + phase_times()->record_expand_heap_time(expand_ms); } - phase_times()->record_expand_heap_time(expand_ms); } } diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp index 838e3b000e0bd..ad440577f2d86 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -572,7 +572,7 @@ class G1CollectedHeap : public CollectedHeap { // Returns true if the heap was expanded by the requested amount; // false otherwise. // (Rounds up to a G1HeapRegion boundary.) - bool expand(size_t expand_bytes, WorkerThreads* pretouch_workers, double* expand_time_ms = nullptr); + bool expand(size_t expand_bytes, WorkerThreads* pretouch_workers); bool expand_single_region(uint node_index); // Returns the PLAB statistics for a given destination. From 3f96dedba0c7d29132ef947e597cf1613bbe2a6f Mon Sep 17 00:00:00 2001 From: Albert Yang Date: Tue, 17 Jun 2025 09:56:24 +0200 Subject: [PATCH 2/2] review --- src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index 873d6bddf87b0..b6c18420b82fc 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -2392,9 +2392,9 @@ void G1CollectedHeap::expand_heap_after_young_collection(){ if (expand_bytes > 0) { // No need for an ergo logging here, // expansion_amount() does this when it returns a value > 0. - Ticks expand_start_instant = Ticks::now(); + Ticks expand_start = Ticks::now(); if (expand(expand_bytes, _workers)) { - double expand_ms = (Ticks::now() - expand_start_instant).seconds() * MILLIUNITS; + double expand_ms = (Ticks::now() - expand_start).seconds() * MILLIUNITS; phase_times()->record_expand_heap_time(expand_ms); } }