8331401: G1: Make G1HRPrinter AllStatic

Reviewed-by: iwalulya, ayang, gli
This commit is contained in:
Thomas Schatzl 2024-05-03 12:03:28 +00:00
parent 1f6d38f7a6
commit 8ed319023e
10 changed files with 46 additions and 61 deletions

View File

@ -31,6 +31,7 @@
#include "gc/g1/g1HeapRegion.inline.hpp"
#include "gc/g1/g1HeapRegionSet.inline.hpp"
#include "gc/g1/g1HeapRegionType.hpp"
#include "gc/g1/g1HRPrinter.hpp"
#include "gc/g1/g1NUMA.hpp"
#include "gc/g1/g1Policy.hpp"
#include "gc/shared/tlab_globals.hpp"
@ -118,7 +119,7 @@ void G1Allocator::reuse_retained_old_region(G1EvacInfo* evacuation_info,
// it's retired again.
_g1h->old_set_remove(retained_region);
old->set(retained_region);
_g1h->hr_printer()->reuse(retained_region);
G1HRPrinter::reuse(retained_region);
evacuation_info->set_alloc_regions_used_before(retained_region->used());
}
}

View File

@ -52,6 +52,7 @@
#include "gc/g1/g1HeapSizingPolicy.hpp"
#include "gc/g1/g1HeapTransition.hpp"
#include "gc/g1/g1HeapVerifier.hpp"
#include "gc/g1/g1HRPrinter.hpp"
#include "gc/g1/g1InitLogger.hpp"
#include "gc/g1/g1MemoryPool.hpp"
#include "gc/g1/g1MonotonicArenaFreeMemoryTask.hpp"
@ -325,7 +326,7 @@ G1CollectedHeap::humongous_obj_allocate_initialize_regions(HeapRegion* first_hr,
for (uint i = first; i <= last; ++i) {
HeapRegion *hr = region_at(i);
_humongous_set.add(hr);
_hr_printer.alloc(hr);
G1HRPrinter::alloc(hr);
}
return new_obj;
@ -524,7 +525,7 @@ HeapWord* G1CollectedHeap::alloc_archive_region(size_t word_size, HeapWord* pref
r->set_top(top);
r->set_old();
_hr_printer.alloc(r);
G1HRPrinter::alloc(r);
_old_set.add(r);
};
@ -710,17 +711,12 @@ HeapWord* G1CollectedHeap::attempt_allocation_at_safepoint(size_t word_size,
}
class PostCompactionPrinterClosure: public HeapRegionClosure {
private:
G1HRPrinter* _hr_printer;
public:
bool do_heap_region(HeapRegion* hr) {
assert(!hr->is_young(), "not expecting to find young regions");
_hr_printer->post_compaction(hr);
G1HRPrinter::post_compaction(hr);
return false;
}
PostCompactionPrinterClosure(G1HRPrinter* hr_printer)
: _hr_printer(hr_printer) { }
};
void G1CollectedHeap::print_heap_after_full_collection() {
@ -728,8 +724,8 @@ void G1CollectedHeap::print_heap_after_full_collection() {
// 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());
if (G1HRPrinter::is_active()) {
PostCompactionPrinterClosure cl;
heap_region_iterate(&cl);
}
}
@ -1152,7 +1148,6 @@ G1CollectedHeap::G1CollectedHeap() :
_monitoring_support(nullptr),
_num_humongous_objects(0),
_num_humongous_reclaim_candidates(0),
_hr_printer(),
_collector_state(),
_old_marking_cycles_started(0),
_old_marking_cycles_completed(0),
@ -2862,7 +2857,7 @@ HeapRegion* G1CollectedHeap::new_mutator_alloc_region(size_t word_size,
node_index);
if (new_alloc_region != nullptr) {
set_region_short_lived_locked(new_alloc_region);
_hr_printer.alloc(new_alloc_region, !should_allocate);
G1HRPrinter::alloc(new_alloc_region, !should_allocate);
_policy->remset_tracker()->update_at_allocate(new_alloc_region);
return new_alloc_region;
}
@ -2878,7 +2873,7 @@ void G1CollectedHeap::retire_mutator_alloc_region(HeapRegion* alloc_region,
collection_set()->add_eden_region(alloc_region);
increase_used(allocated_bytes);
_eden.add_used_bytes(allocated_bytes);
_hr_printer.retire(alloc_region);
G1HRPrinter::retire(alloc_region);
// We update the eden sizes here, when the region is retired,
// instead of when it's allocated, since this is the point that its
@ -2925,7 +2920,7 @@ HeapRegion* G1CollectedHeap::new_gc_alloc_region(size_t word_size, G1HeapRegionA
}
_policy->remset_tracker()->update_at_allocate(new_alloc_region);
register_region_with_region_attr(new_alloc_region);
_hr_printer.alloc(new_alloc_region);
G1HRPrinter::alloc(new_alloc_region);
return new_alloc_region;
}
return nullptr;
@ -2946,7 +2941,7 @@ void G1CollectedHeap::retire_gc_alloc_region(HeapRegion* alloc_region,
if (during_im && allocated_bytes > 0) {
_cm->add_root_region(alloc_region);
}
_hr_printer.retire(alloc_region);
G1HRPrinter::retire(alloc_region);
}
HeapRegion* G1CollectedHeap::alloc_highest_free_region() {

View File

@ -40,7 +40,6 @@
#include "gc/g1/g1HeapRegionSet.hpp"
#include "gc/g1/g1HeapTransition.hpp"
#include "gc/g1/g1HeapVerifier.hpp"
#include "gc/g1/g1HRPrinter.hpp"
#include "gc/g1/g1MonitoringSupport.hpp"
#include "gc/g1/g1MonotonicArenaFreeMemoryTask.hpp"
#include "gc/g1/g1MonotonicArenaFreePool.hpp"
@ -265,8 +264,6 @@ public:
void update_parallel_gc_threads_cpu_time();
private:
G1HRPrinter _hr_printer;
// Return true if an explicit GC should start a concurrent cycle instead
// of doing a STW full GC. A concurrent cycle should be started if:
// (a) cause == _g1_humongous_allocation,
@ -669,8 +666,6 @@ public:
return _old_marking_cycles_completed;
}
G1HRPrinter* hr_printer() { return &_hr_printer; }
// Allocates a new heap region instance.
HeapRegion* new_heap_region(uint hrs_index, MemRegion mr);

View File

@ -40,6 +40,7 @@
#include "gc/g1/g1HeapRegionRemSet.inline.hpp"
#include "gc/g1/g1HeapRegionSet.inline.hpp"
#include "gc/g1/g1HeapVerifier.hpp"
#include "gc/g1/g1HRPrinter.hpp"
#include "gc/g1/g1OopClosures.inline.hpp"
#include "gc/g1/g1Policy.hpp"
#include "gc/g1/g1RegionMarkStatsCache.inline.hpp"
@ -1317,7 +1318,7 @@ public:
if (!_cleanup_list.is_empty()) {
log_debug(gc)("Reclaimed %u empty regions", _cleanup_list.length());
// Now print the empty regions list.
_g1h->hr_printer()->mark_reclaim(&_cleanup_list);
G1HRPrinter::mark_reclaim(&_cleanup_list);
// And actually make them available.
_g1h->prepend_to_freelist(&_cleanup_list);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,10 +27,11 @@
#include "gc/g1/g1HeapRegion.hpp"
#include "logging/log.hpp"
#include "memory/allStatic.hpp"
class FreeRegionList;
class G1HRPrinter {
class G1HRPrinter : public AllStatic {
private:
@ -40,7 +41,7 @@ private:
action, hr->get_type_str(), p2i(hr->bottom()), p2i(hr->top()), p2i(hr->end()));
}
void mark_reclaim(HeapRegion* hr) {
static void mark_reclaim(HeapRegion* hr) {
print("MARK-RECLAIM", hr);
}
@ -48,79 +49,79 @@ public:
// In some places we iterate over a list in order to generate output
// for the list's elements. By exposing this we can avoid this
// iteration if the printer is not active.
bool is_active() { return log_is_enabled(Trace, gc, region); }
static bool is_active() { return log_is_enabled(Trace, gc, region); }
// The methods below are convenient wrappers for the print() method.
void alloc(HeapRegion* hr, bool force = false) {
static void alloc(HeapRegion* hr, bool force = false) {
if (is_active()) {
print((force) ? "ALLOC-FORCE" : "ALLOC", hr);
}
}
void retire(HeapRegion* hr) {
static void retire(HeapRegion* hr) {
if (is_active()) {
print("RETIRE", hr);
}
}
void reuse(HeapRegion* hr) {
static void reuse(HeapRegion* hr) {
if (is_active()) {
print("REUSE", hr);
}
}
void cset(HeapRegion* hr) {
static void cset(HeapRegion* hr) {
if (is_active()) {
print("CSET", hr);
}
}
void evac_failure(HeapRegion* hr) {
static void evac_failure(HeapRegion* hr) {
if (is_active()) {
print("EVAC-FAILURE", hr);
}
}
void mark_reclaim(FreeRegionList* free_list);
static void mark_reclaim(FreeRegionList* free_list);
void eager_reclaim(HeapRegion* hr) {
static void eager_reclaim(HeapRegion* hr) {
if (is_active()) {
print("EAGER-RECLAIM", hr);
}
}
void evac_reclaim(HeapRegion* hr) {
static void evac_reclaim(HeapRegion* hr) {
if (is_active()) {
print("EVAC-RECLAIM", hr);
}
}
void post_compaction(HeapRegion* hr) {
static void post_compaction(HeapRegion* hr) {
if (is_active()) {
print("POST-COMPACTION", hr);
}
}
void commit(HeapRegion* hr) {
static void commit(HeapRegion* hr) {
if (is_active()) {
print("COMMIT", hr);
}
}
void active(HeapRegion* hr) {
static void active(HeapRegion* hr) {
if (is_active()) {
print("ACTIVE", hr);
}
}
void inactive(HeapRegion* hr) {
static void inactive(HeapRegion* hr) {
if (is_active()) {
print("INACTIVE", hr);
}
}
void uncommit(HeapRegion* hr) {
static void uncommit(HeapRegion* hr) {
if (is_active()) {
print("UNCOMMIT", hr);
}

View File

@ -30,6 +30,7 @@
#include "gc/g1/g1HeapRegion.hpp"
#include "gc/g1/g1HeapRegionManager.inline.hpp"
#include "gc/g1/g1HeapRegionSet.inline.hpp"
#include "gc/g1/g1HRPrinter.hpp"
#include "gc/g1/g1NUMAStats.hpp"
#include "jfr/jfrEvents.hpp"
#include "logging/logStream.hpp"
@ -170,7 +171,7 @@ void HeapRegionManager::expand(uint start, uint num_regions, WorkerThreads* pret
_regions.set_by_index(i, hr);
_allocated_heapregions_length = MAX2(_allocated_heapregions_length, i + 1);
}
G1CollectedHeap::heap()->hr_printer()->commit(hr);
G1HRPrinter::commit(hr);
}
activate_regions(start, num_regions);
}
@ -193,13 +194,12 @@ void HeapRegionManager::uncommit_regions(uint start, uint num_regions) {
guarantee(num_regions > 0, "No point in calling this for zero regions");
uint end = start + num_regions;
G1HRPrinter* printer = G1CollectedHeap::heap()->hr_printer();
if (printer->is_active()) {
if (G1HRPrinter::is_active()) {
for (uint i = start; i < end; i++) {
// Can't use at() here since region is no longer marked available.
HeapRegion* hr = _regions.get_by_index(i);
assert(hr != nullptr, "Region should still be present");
printer->uncommit(hr);
G1HRPrinter::uncommit(hr);
}
}
@ -223,7 +223,7 @@ void HeapRegionManager::initialize_regions(uint start, uint num_regions) {
hr->initialize();
hr->set_node_index(G1NUMA::numa()->index_for_region(hr));
insert_into_free_list(hr);
G1CollectedHeap::heap()->hr_printer()->active(hr);
G1HRPrinter::active(hr);
}
}
@ -250,7 +250,7 @@ void HeapRegionManager::deactivate_regions(uint start, uint num_regions) {
for (uint i = start; i < end; i++) {
HeapRegion* hr = at(i);
hr->set_node_index(G1NUMA::UnknownNodeIndex);
G1CollectedHeap::heap()->hr_printer()->inactive(hr);
G1HRPrinter::inactive(hr);
}
_committed_map.deactivate(start, end);

View File

@ -27,6 +27,7 @@
#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1CollectionSet.hpp"
#include "gc/g1/g1EvacFailureRegions.inline.hpp"
#include "gc/g1/g1HRPrinter.hpp"
#include "gc/g1/g1OopClosures.inline.hpp"
#include "gc/g1/g1ParScanThreadState.inline.hpp"
#include "gc/g1/g1RootClosures.hpp"
@ -642,7 +643,7 @@ oop G1ParScanThreadState::handle_evacuation_failure_par(oop old, markWord m, siz
HeapRegion* r = _g1h->heap_region_containing(old);
if (_evac_failure_regions->record(_worker_id, r->hrm_index(), cause_pinned)) {
_g1h->hr_printer()->evac_failure(r);
G1HRPrinter::evac_failure(r);
}
// Mark the failing object in the marking bitmap and later use the bitmap to handle

View File

@ -216,10 +216,6 @@ G1GCPhaseTimes* G1YoungCollector::phase_times() const {
return _g1h->phase_times();
}
G1HRPrinter* G1YoungCollector::hr_printer() const {
return _g1h->hr_printer();
}
G1MonitoringSupport* G1YoungCollector::monitoring_support() const {
return _g1h->monitoring_support();
}
@ -264,13 +260,9 @@ void G1YoungCollector::wait_for_root_region_scanning() {
}
class G1PrintCollectionSetClosure : public HeapRegionClosure {
private:
G1HRPrinter* _hr_printer;
public:
G1PrintCollectionSetClosure(G1HRPrinter* hr_printer) : HeapRegionClosure(), _hr_printer(hr_printer) { }
virtual bool do_heap_region(HeapRegion* r) {
_hr_printer->cset(r);
G1HRPrinter::cset(r);
return false;
}
};
@ -286,8 +278,8 @@ void G1YoungCollector::calculate_collection_set(G1EvacInfo* evacuation_info, dou
concurrent_mark()->verify_no_collection_set_oops();
if (hr_printer()->is_active()) {
G1PrintCollectionSetClosure cl(hr_printer());
if (G1HRPrinter::is_active()) {
G1PrintCollectionSetClosure cl;
collection_set()->iterate(&cl);
collection_set()->iterate_optional(&cl);
}

View File

@ -40,7 +40,6 @@ class G1ConcurrentMark;
class G1EvacFailureRegions;
class G1EvacInfo;
class G1GCPhaseTimes;
class G1HRPrinter;
class G1MonitoringSupport;
class G1MonotonicArenaMemoryStats;
class G1NewTracer;
@ -69,7 +68,6 @@ class G1YoungCollector {
STWGCTimer* gc_timer_stw() const;
G1NewTracer* gc_tracer_stw() const;
G1HRPrinter* hr_printer() const;
G1MonitoringSupport* monitoring_support() const;
G1GCPhaseTimes* phase_times() const;
G1Policy* policy() const;

View File

@ -36,6 +36,7 @@
#include "gc/g1/g1EvacStats.inline.hpp"
#include "gc/g1/g1HeapRegion.inline.hpp"
#include "gc/g1/g1HeapRegionRemSet.inline.hpp"
#include "gc/g1/g1HRPrinter.hpp"
#include "gc/g1/g1OopClosures.inline.hpp"
#include "gc/g1/g1ParScanThreadState.hpp"
#include "gc/g1/g1RemSet.hpp"
@ -412,7 +413,7 @@ public:
r->set_containing_set(nullptr);
_humongous_regions_reclaimed++;
_g1h->free_humongous_region(r, nullptr);
_g1h->hr_printer()->eager_reclaim(r);
G1HRPrinter::eager_reclaim(r);
};
_g1h->humongous_obj_regions_iterate(r, free_humongous_region);
@ -760,7 +761,7 @@ class FreeCSetClosure : public HeapRegionClosure {
// Free the region and its remembered set.
_g1h->free_region(r, nullptr);
_g1h->hr_printer()->evac_reclaim(r);
G1HRPrinter::evac_reclaim(r);
}
void handle_failed_region(HeapRegion* r) {