Skip to content

Commit a2030ff

Browse files
committedJun 7, 2024
8332516: Serial: Always sample promoted bytes to avoid getting stuck in Full GCs
Reviewed-by: iwalulya, tschatzl
1 parent bf7f1c4 commit a2030ff

File tree

4 files changed

+15
-25
lines changed

4 files changed

+15
-25
lines changed
 

‎src/hotspot/share/gc/serial/serialHeap.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,10 @@ bool SerialHeap::do_young_collection(bool clear_soft_refs) {
468468

469469
COMPILER2_OR_JVMCI_PRESENT(DerivedPointerTable::update_pointers());
470470

471-
update_gc_stats(_young_gen, false);
471+
// Only update stats for successful young-gc
472+
if (result) {
473+
_old_gen->update_promote_stats();
474+
}
472475

473476
if (should_verify && VerifyAfterGC) {
474477
Universe::verify("After GC");
@@ -761,6 +764,8 @@ void SerialHeap::do_full_collection_no_gc_locker(bool clear_all_soft_refs) {
761764
// Need to clear claim bits for the next mark.
762765
ClassLoaderDataGraph::clear_claimed_marks();
763766

767+
_old_gen->update_promote_stats();
768+
764769
// Resize the metaspace capacity after full collections
765770
MetaspaceGC::compute_new_size();
766771

‎src/hotspot/share/gc/serial/serialHeap.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,6 @@ class SerialHeap : public CollectedHeap {
208208
size_t requested_size,
209209
size_t* actual_size) override;
210210

211-
// Update the gc statistics for each generation.
212-
void update_gc_stats(Generation* current_generation, bool full) {
213-
_old_gen->update_gc_stats(current_generation, full);
214-
}
215-
216211
void prepare_for_verify() override;
217212
void verify(VerifyOption option) override;
218213

‎src/hotspot/share/gc/serial/tenuredGeneration.cpp

+8-18
Original file line numberDiff line numberDiff line change
@@ -357,25 +357,15 @@ void TenuredGeneration::compute_new_size() {
357357
" capacity: " SIZE_FORMAT, used(), used_after_gc, capacity());
358358
}
359359

360-
void TenuredGeneration::update_gc_stats(Generation* current_generation,
361-
bool full) {
362-
// If the young generation has been collected, gather any statistics
363-
// that are of interest at this point.
364-
bool current_is_young = SerialHeap::heap()->is_young_gen(current_generation);
365-
if (!full && current_is_young) {
366-
// Calculate size of data promoted from the young generation
367-
// before doing the collection.
368-
size_t used_before_gc = used();
369-
370-
// If the young gen collection was skipped, then the
371-
// number of promoted bytes will be 0 and adding it to the
372-
// average will incorrectly lessen the average. It is, however,
373-
// also possible that no promotion was needed.
374-
if (used_before_gc >= _used_at_prologue) {
375-
size_t promoted_in_bytes = used_before_gc - _used_at_prologue;
376-
_avg_promoted->sample(promoted_in_bytes);
377-
}
360+
void TenuredGeneration::update_promote_stats() {
361+
size_t used_after_gc = used();
362+
size_t promoted_in_bytes;
363+
if (used_after_gc > _used_at_prologue) {
364+
promoted_in_bytes = used_after_gc - _used_at_prologue;
365+
} else {
366+
promoted_in_bytes = 0;
378367
}
368+
_avg_promoted->sample(promoted_in_bytes);
379369
}
380370

381371
void TenuredGeneration::update_counters() {

‎src/hotspot/share/gc/serial/tenuredGeneration.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class TenuredGeneration: public Generation {
154154

155155
// Statistics
156156

157-
void update_gc_stats(Generation* current_generation, bool full);
157+
void update_promote_stats();
158158

159159
// Returns true if promotions of the specified amount are
160160
// likely to succeed without a promotion failure.

0 commit comments

Comments
 (0)
Please sign in to comment.