From 0f3881b1084b5f61f9f3205488c5f88183a101dc Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Tue, 6 Jul 2021 14:07:44 +0200 Subject: [PATCH] Initial implementation of heap printing refactoring --- src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 55 ++++++++++----------- src/hotspot/share/gc/g1/g1CollectedHeap.hpp | 17 +++++-- src/hotspot/share/gc/g1/g1FullCollector.cpp | 5 +- src/hotspot/share/gc/g1/g1FullGCScope.cpp | 6 +-- src/hotspot/share/gc/g1/g1FullGCScope.hpp | 2 +- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index 8f7b9dbff5470..c05247502124d 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -980,7 +980,11 @@ class PostCompactionPrinterClosure: public HeapRegionClosure { : _hr_printer(hr_printer) { } }; -void G1CollectedHeap::print_hrm_post_compaction() { +void G1CollectedHeap::print_heap_after_full_collection() { + // Post collection region logging. + // We should do this after we potentially resize the heap so + // that all the COMMIT / UNCOMMIT events are generated before + // the compaction events. if (_hr_printer.is_active()) { PostCompactionPrinterClosure cl(hr_printer()); heap_region_iterate(&cl); @@ -1092,17 +1096,6 @@ void G1CollectedHeap::verify_after_full_collection() { _ref_processor_cm->verify_no_references_recorded(); } -void G1CollectedHeap::print_heap_after_full_collection(G1HeapTransition* heap_transition) { - // Post collection logging. - // We should do this after we potentially resize the heap so - // that all the COMMIT / UNCOMMIT events are generated before - // the compaction events. - print_hrm_post_compaction(); - heap_transition->print(); - print_heap_after_gc(); - print_heap_regions(); -} - bool G1CollectedHeap::do_full_collection(bool explicit_gc, bool clear_all_soft_refs, bool do_maximum_compaction) { @@ -2572,9 +2565,6 @@ void G1CollectedHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_tracer) { void G1CollectedHeap::gc_prologue(bool full) { assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer"); - // This summary needs to be printed before incrementing total collections. - rem_set()->print_periodic_summary_info("Before GC RS summary", total_collections()); - // Update common counters. increment_total_collections(full /* full gc */); if (full || collector_state()->in_concurrent_start_gc()) { @@ -2607,9 +2597,6 @@ void G1CollectedHeap::gc_epilogue(bool full) { increment_old_marking_cycles_completed(false /* concurrent */, true /* liveness_completed */); } - // We are at the end of the GC. Total collections has already been increased. - rem_set()->print_periodic_summary_info("After GC RS summary", total_collections() - 1); - #if COMPILER2_OR_JVMCI assert(DerivedPointerTable::is_empty(), "derived pointer present"); #endif @@ -2623,9 +2610,6 @@ void G1CollectedHeap::gc_epilogue(bool full) { // policy with the new heap occupancy Universe::heap()->update_capacity_and_used_at_gc(); - // Print NUMA statistics. - _numa->print_statistics(); - _collection_pause_end = Ticks::now(); _free_card_set_memory_task->notify_new_stats(&_young_gen_card_set_stats, @@ -2944,6 +2928,25 @@ class G1YoungGCTraceTime { } }; +G1CollectedHeap::G1HeapPrinterMark::G1HeapPrinterMark(G1CollectedHeap* g1h) : _g1h(g1h), _heap_transition(g1h) { + // This summary needs to be printed before incrementing total collections. + _g1h->rem_set()->print_periodic_summary_info("Before GC RS summary", _g1h->total_collections()); + _g1h->print_heap_before_gc(); + _g1h->print_heap_regions(); +} + +G1CollectedHeap::G1HeapPrinterMark::~G1HeapPrinterMark() { + _g1h->policy()->print_age_table(); + _g1h->rem_set()->print_coarsen_stats(); + + _g1h->print_heap_regions(); + _g1h->print_heap_after_gc(); + // We are at the end of the GC. Total collections has already been increased. + _g1h->rem_set()->print_periodic_summary_info("After GC RS summary", _g1h->total_collections() - 1); + // Print NUMA statistics. + _g1h->numa()->print_statistics(); +} + void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_pause_time_ms) { GCIdMark gc_id_mark; @@ -2956,8 +2959,6 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus wait_for_root_region_scanning(); - print_heap_before_gc(); - print_heap_regions(); trace_heap_before_gc(_gc_tracer_stw); _verifier->verify_region_sets_optional(); @@ -3000,7 +3001,7 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus false /* full_gc */, collector_state()->in_mixed_phase() /* all_memory_pools_affected */); - G1HeapTransition heap_transition(this); + G1HeapPrinterMark hpm(this); { IsGCActiveMark x; @@ -3079,7 +3080,6 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus } policy()->print_phases(); - heap_transition.print(); _hrm.verify_optional(); _verifier->verify_region_sets_optional(); @@ -3087,8 +3087,6 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus TASKQUEUE_STATS_ONLY(print_taskqueue_stats()); TASKQUEUE_STATS_ONLY(reset_taskqueue_stats()); - print_heap_after_gc(); - print_heap_regions(); trace_heap_after_gc(_gc_tracer_stw); gc_tracer_report_gc_end(concurrent_operation_is_full_mark, evacuation_info); @@ -3821,9 +3819,6 @@ void G1CollectedHeap::post_evacuate_collection_set(G1EvacuationInfo& evacuation_ evacuation_info.set_collectionset_used_before(collection_set()->bytes_used_before()); evacuation_info.set_bytes_used(_bytes_used_during_gc); - - policy()->print_age_table(); - rem_set()->print_coarsen_stats(); } void G1CollectedHeap::record_obj_copy_mem_stats() { diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp index e435bb4c9a719..63ecff86fd8a5 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -317,10 +317,6 @@ class G1CollectedHeap : public CollectedHeap { // this method will be found dead by the marking cycle). void allocate_dummy_regions() PRODUCT_RETURN; - // If the HR printer is active, dump the state of the regions in the - // heap after a compaction. - void print_hrm_post_compaction(); - // Create a memory mapper for auxiliary data structures of the given size and // translation factor. static G1RegionToSpaceMapper* create_aux_memory_mapper(const char* description, @@ -537,7 +533,7 @@ class G1CollectedHeap : public CollectedHeap { void prepare_heap_for_mutators(); void abort_refinement(); void verify_after_full_collection(); - void print_heap_after_full_collection(G1HeapTransition* heap_transition); + void print_heap_after_full_collection(); // Helper method for satisfy_failed_allocation() HeapWord* satisfy_failed_allocation_helper(size_t word_size, @@ -1476,6 +1472,8 @@ class G1CollectedHeap : public CollectedHeap { void print_regions_on(outputStream* st) const; public: + class G1HeapPrinterMark; + virtual void print_on(outputStream* st) const; virtual void print_extended_on(outputStream* st) const; virtual void print_on_error(outputStream* st) const; @@ -1493,6 +1491,15 @@ class G1CollectedHeap : public CollectedHeap { virtual bool print_location(outputStream* st, void* addr) const; }; +class G1CollectedHeap::G1HeapPrinterMark : public StackObj { + G1CollectedHeap* _g1h; + G1HeapTransition _heap_transition; + +public: + G1HeapPrinterMark(G1CollectedHeap* g1h); + ~G1HeapPrinterMark(); +}; + class G1ParEvacuateFollowersClosure : public VoidClosure { private: double _start_term; diff --git a/src/hotspot/share/gc/g1/g1FullCollector.cpp b/src/hotspot/share/gc/g1/g1FullCollector.cpp index 317224dea790f..9f11b331095d1 100644 --- a/src/hotspot/share/gc/g1/g1FullCollector.cpp +++ b/src/hotspot/share/gc/g1/g1FullCollector.cpp @@ -170,9 +170,6 @@ class PrepareRegionsClosure : public HeapRegionClosure { void G1FullCollector::prepare_collection() { _heap->policy()->record_full_collection_start(); - _heap->print_heap_before_gc(); - _heap->print_heap_regions(); - _heap->abort_concurrent_cycle(); _heap->verify_before_full_collection(scope()->is_explicit_gc()); @@ -221,7 +218,7 @@ void G1FullCollector::complete_collection() { _heap->verify_after_full_collection(); - _heap->print_heap_after_full_collection(scope()->heap_transition()); + _heap->print_heap_after_full_collection(); } void G1FullCollector::before_marking_update_attribute_table(HeapRegion* hr) { diff --git a/src/hotspot/share/gc/g1/g1FullGCScope.cpp b/src/hotspot/share/gc/g1/g1FullGCScope.cpp index a3c469308ae0b..811bdabc6f4b3 100644 --- a/src/hotspot/share/gc/g1/g1FullGCScope.cpp +++ b/src/hotspot/share/gc/g1/g1FullGCScope.cpp @@ -40,7 +40,7 @@ G1FullGCScope::G1FullGCScope(G1MonitoringSupport* monitoring_support, _cpu_time(), _soft_refs(clear_soft, _g1h->soft_ref_policy()), _monitoring_scope(monitoring_support, true /* full_gc */, true /* all_memory_pools_affected */), - _heap_transition(_g1h), + _heap_printer(_g1h), _region_compaction_threshold(do_maximum_compaction ? HeapRegion::GrainWords : (1 - MarkSweepDeadRatio / 100.0) * HeapRegion::GrainWords) { @@ -73,10 +73,6 @@ G1FullGCTracer* G1FullGCScope::tracer() { return &_tracer; } -G1HeapTransition* G1FullGCScope::heap_transition() { - return &_heap_transition; -} - size_t G1FullGCScope::region_compaction_threshold() { return _region_compaction_threshold; } diff --git a/src/hotspot/share/gc/g1/g1FullGCScope.hpp b/src/hotspot/share/gc/g1/g1FullGCScope.hpp index e12f72b950f39..53c1ecdb0842d 100644 --- a/src/hotspot/share/gc/g1/g1FullGCScope.hpp +++ b/src/hotspot/share/gc/g1/g1FullGCScope.hpp @@ -52,7 +52,7 @@ class G1FullGCScope : public StackObj { GCTraceCPUTime _cpu_time; ClearedAllSoftRefs _soft_refs; G1MonitoringScope _monitoring_scope; - G1HeapTransition _heap_transition; + G1CollectedHeap::G1HeapPrinterMark _heap_printer; size_t _region_compaction_threshold; public: