Skip to content

Commit 8ed3190

Browse files
author
Thomas Schatzl
committed
8331401: G1: Make G1HRPrinter AllStatic
Reviewed-by: iwalulya, ayang, gli
1 parent 1f6d38f commit 8ed3190

File tree

10 files changed

+46
-61
lines changed

10 files changed

+46
-61
lines changed

src/hotspot/share/gc/g1/g1Allocator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "gc/g1/g1HeapRegion.inline.hpp"
3232
#include "gc/g1/g1HeapRegionSet.inline.hpp"
3333
#include "gc/g1/g1HeapRegionType.hpp"
34+
#include "gc/g1/g1HRPrinter.hpp"
3435
#include "gc/g1/g1NUMA.hpp"
3536
#include "gc/g1/g1Policy.hpp"
3637
#include "gc/shared/tlab_globals.hpp"
@@ -118,7 +119,7 @@ void G1Allocator::reuse_retained_old_region(G1EvacInfo* evacuation_info,
118119
// it's retired again.
119120
_g1h->old_set_remove(retained_region);
120121
old->set(retained_region);
121-
_g1h->hr_printer()->reuse(retained_region);
122+
G1HRPrinter::reuse(retained_region);
122123
evacuation_info->set_alloc_regions_used_before(retained_region->used());
123124
}
124125
}

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "gc/g1/g1HeapSizingPolicy.hpp"
5353
#include "gc/g1/g1HeapTransition.hpp"
5454
#include "gc/g1/g1HeapVerifier.hpp"
55+
#include "gc/g1/g1HRPrinter.hpp"
5556
#include "gc/g1/g1InitLogger.hpp"
5657
#include "gc/g1/g1MemoryPool.hpp"
5758
#include "gc/g1/g1MonotonicArenaFreeMemoryTask.hpp"
@@ -325,7 +326,7 @@ G1CollectedHeap::humongous_obj_allocate_initialize_regions(HeapRegion* first_hr,
325326
for (uint i = first; i <= last; ++i) {
326327
HeapRegion *hr = region_at(i);
327328
_humongous_set.add(hr);
328-
_hr_printer.alloc(hr);
329+
G1HRPrinter::alloc(hr);
329330
}
330331

331332
return new_obj;
@@ -524,7 +525,7 @@ HeapWord* G1CollectedHeap::alloc_archive_region(size_t word_size, HeapWord* pref
524525
r->set_top(top);
525526

526527
r->set_old();
527-
_hr_printer.alloc(r);
528+
G1HRPrinter::alloc(r);
528529
_old_set.add(r);
529530
};
530531

@@ -710,26 +711,21 @@ HeapWord* G1CollectedHeap::attempt_allocation_at_safepoint(size_t word_size,
710711
}
711712

712713
class PostCompactionPrinterClosure: public HeapRegionClosure {
713-
private:
714-
G1HRPrinter* _hr_printer;
715714
public:
716715
bool do_heap_region(HeapRegion* hr) {
717716
assert(!hr->is_young(), "not expecting to find young regions");
718-
_hr_printer->post_compaction(hr);
717+
G1HRPrinter::post_compaction(hr);
719718
return false;
720719
}
721-
722-
PostCompactionPrinterClosure(G1HRPrinter* hr_printer)
723-
: _hr_printer(hr_printer) { }
724720
};
725721

726722
void G1CollectedHeap::print_heap_after_full_collection() {
727723
// Post collection region logging.
728724
// We should do this after we potentially resize the heap so
729725
// that all the COMMIT / UNCOMMIT events are generated before
730726
// the compaction events.
731-
if (_hr_printer.is_active()) {
732-
PostCompactionPrinterClosure cl(hr_printer());
727+
if (G1HRPrinter::is_active()) {
728+
PostCompactionPrinterClosure cl;
733729
heap_region_iterate(&cl);
734730
}
735731
}
@@ -1152,7 +1148,6 @@ G1CollectedHeap::G1CollectedHeap() :
11521148
_monitoring_support(nullptr),
11531149
_num_humongous_objects(0),
11541150
_num_humongous_reclaim_candidates(0),
1155-
_hr_printer(),
11561151
_collector_state(),
11571152
_old_marking_cycles_started(0),
11581153
_old_marking_cycles_completed(0),
@@ -2862,7 +2857,7 @@ HeapRegion* G1CollectedHeap::new_mutator_alloc_region(size_t word_size,
28622857
node_index);
28632858
if (new_alloc_region != nullptr) {
28642859
set_region_short_lived_locked(new_alloc_region);
2865-
_hr_printer.alloc(new_alloc_region, !should_allocate);
2860+
G1HRPrinter::alloc(new_alloc_region, !should_allocate);
28662861
_policy->remset_tracker()->update_at_allocate(new_alloc_region);
28672862
return new_alloc_region;
28682863
}
@@ -2878,7 +2873,7 @@ void G1CollectedHeap::retire_mutator_alloc_region(HeapRegion* alloc_region,
28782873
collection_set()->add_eden_region(alloc_region);
28792874
increase_used(allocated_bytes);
28802875
_eden.add_used_bytes(allocated_bytes);
2881-
_hr_printer.retire(alloc_region);
2876+
G1HRPrinter::retire(alloc_region);
28822877

28832878
// We update the eden sizes here, when the region is retired,
28842879
// 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
29252920
}
29262921
_policy->remset_tracker()->update_at_allocate(new_alloc_region);
29272922
register_region_with_region_attr(new_alloc_region);
2928-
_hr_printer.alloc(new_alloc_region);
2923+
G1HRPrinter::alloc(new_alloc_region);
29292924
return new_alloc_region;
29302925
}
29312926
return nullptr;
@@ -2946,7 +2941,7 @@ void G1CollectedHeap::retire_gc_alloc_region(HeapRegion* alloc_region,
29462941
if (during_im && allocated_bytes > 0) {
29472942
_cm->add_root_region(alloc_region);
29482943
}
2949-
_hr_printer.retire(alloc_region);
2944+
G1HRPrinter::retire(alloc_region);
29502945
}
29512946

29522947
HeapRegion* G1CollectedHeap::alloc_highest_free_region() {

src/hotspot/share/gc/g1/g1CollectedHeap.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include "gc/g1/g1HeapRegionSet.hpp"
4141
#include "gc/g1/g1HeapTransition.hpp"
4242
#include "gc/g1/g1HeapVerifier.hpp"
43-
#include "gc/g1/g1HRPrinter.hpp"
4443
#include "gc/g1/g1MonitoringSupport.hpp"
4544
#include "gc/g1/g1MonotonicArenaFreeMemoryTask.hpp"
4645
#include "gc/g1/g1MonotonicArenaFreePool.hpp"
@@ -265,8 +264,6 @@ class G1CollectedHeap : public CollectedHeap {
265264
void update_parallel_gc_threads_cpu_time();
266265
private:
267266

268-
G1HRPrinter _hr_printer;
269-
270267
// Return true if an explicit GC should start a concurrent cycle instead
271268
// of doing a STW full GC. A concurrent cycle should be started if:
272269
// (a) cause == _g1_humongous_allocation,
@@ -669,8 +666,6 @@ class G1CollectedHeap : public CollectedHeap {
669666
return _old_marking_cycles_completed;
670667
}
671668

672-
G1HRPrinter* hr_printer() { return &_hr_printer; }
673-
674669
// Allocates a new heap region instance.
675670
HeapRegion* new_heap_region(uint hrs_index, MemRegion mr);
676671

src/hotspot/share/gc/g1/g1ConcurrentMark.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "gc/g1/g1HeapRegionRemSet.inline.hpp"
4141
#include "gc/g1/g1HeapRegionSet.inline.hpp"
4242
#include "gc/g1/g1HeapVerifier.hpp"
43+
#include "gc/g1/g1HRPrinter.hpp"
4344
#include "gc/g1/g1OopClosures.inline.hpp"
4445
#include "gc/g1/g1Policy.hpp"
4546
#include "gc/g1/g1RegionMarkStatsCache.inline.hpp"
@@ -1317,7 +1318,7 @@ class G1UpdateRegionLivenessAndSelectForRebuildTask : public WorkerTask {
13171318
if (!_cleanup_list.is_empty()) {
13181319
log_debug(gc)("Reclaimed %u empty regions", _cleanup_list.length());
13191320
// Now print the empty regions list.
1320-
_g1h->hr_printer()->mark_reclaim(&_cleanup_list);
1321+
G1HRPrinter::mark_reclaim(&_cleanup_list);
13211322
// And actually make them available.
13221323
_g1h->prepend_to_freelist(&_cleanup_list);
13231324
}

src/hotspot/share/gc/g1/g1HRPrinter.hpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,10 +27,11 @@
2727

2828
#include "gc/g1/g1HeapRegion.hpp"
2929
#include "logging/log.hpp"
30+
#include "memory/allStatic.hpp"
3031

3132
class FreeRegionList;
3233

33-
class G1HRPrinter {
34+
class G1HRPrinter : public AllStatic {
3435

3536
private:
3637

@@ -40,87 +41,87 @@ class G1HRPrinter {
4041
action, hr->get_type_str(), p2i(hr->bottom()), p2i(hr->top()), p2i(hr->end()));
4142
}
4243

43-
void mark_reclaim(HeapRegion* hr) {
44+
static void mark_reclaim(HeapRegion* hr) {
4445
print("MARK-RECLAIM", hr);
4546
}
4647

4748
public:
4849
// In some places we iterate over a list in order to generate output
4950
// for the list's elements. By exposing this we can avoid this
5051
// iteration if the printer is not active.
51-
bool is_active() { return log_is_enabled(Trace, gc, region); }
52+
static bool is_active() { return log_is_enabled(Trace, gc, region); }
5253

5354
// The methods below are convenient wrappers for the print() method.
5455

55-
void alloc(HeapRegion* hr, bool force = false) {
56+
static void alloc(HeapRegion* hr, bool force = false) {
5657
if (is_active()) {
5758
print((force) ? "ALLOC-FORCE" : "ALLOC", hr);
5859
}
5960
}
6061

61-
void retire(HeapRegion* hr) {
62+
static void retire(HeapRegion* hr) {
6263
if (is_active()) {
6364
print("RETIRE", hr);
6465
}
6566
}
6667

67-
void reuse(HeapRegion* hr) {
68+
static void reuse(HeapRegion* hr) {
6869
if (is_active()) {
6970
print("REUSE", hr);
7071
}
7172
}
7273

73-
void cset(HeapRegion* hr) {
74+
static void cset(HeapRegion* hr) {
7475
if (is_active()) {
7576
print("CSET", hr);
7677
}
7778
}
7879

79-
void evac_failure(HeapRegion* hr) {
80+
static void evac_failure(HeapRegion* hr) {
8081
if (is_active()) {
8182
print("EVAC-FAILURE", hr);
8283
}
8384
}
8485

85-
void mark_reclaim(FreeRegionList* free_list);
86+
static void mark_reclaim(FreeRegionList* free_list);
8687

87-
void eager_reclaim(HeapRegion* hr) {
88+
static void eager_reclaim(HeapRegion* hr) {
8889
if (is_active()) {
8990
print("EAGER-RECLAIM", hr);
9091
}
9192
}
9293

93-
void evac_reclaim(HeapRegion* hr) {
94+
static void evac_reclaim(HeapRegion* hr) {
9495
if (is_active()) {
9596
print("EVAC-RECLAIM", hr);
9697
}
9798
}
9899

99-
void post_compaction(HeapRegion* hr) {
100+
static void post_compaction(HeapRegion* hr) {
100101
if (is_active()) {
101102
print("POST-COMPACTION", hr);
102103
}
103104
}
104105

105-
void commit(HeapRegion* hr) {
106+
static void commit(HeapRegion* hr) {
106107
if (is_active()) {
107108
print("COMMIT", hr);
108109
}
109110
}
110111

111-
void active(HeapRegion* hr) {
112+
static void active(HeapRegion* hr) {
112113
if (is_active()) {
113114
print("ACTIVE", hr);
114115
}
115116
}
116117

117-
void inactive(HeapRegion* hr) {
118+
static void inactive(HeapRegion* hr) {
118119
if (is_active()) {
119120
print("INACTIVE", hr);
120121
}
121122
}
122123

123-
void uncommit(HeapRegion* hr) {
124+
static void uncommit(HeapRegion* hr) {
124125
if (is_active()) {
125126
print("UNCOMMIT", hr);
126127
}

src/hotspot/share/gc/g1/g1HeapRegionManager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "gc/g1/g1HeapRegion.hpp"
3131
#include "gc/g1/g1HeapRegionManager.inline.hpp"
3232
#include "gc/g1/g1HeapRegionSet.inline.hpp"
33+
#include "gc/g1/g1HRPrinter.hpp"
3334
#include "gc/g1/g1NUMAStats.hpp"
3435
#include "jfr/jfrEvents.hpp"
3536
#include "logging/logStream.hpp"
@@ -170,7 +171,7 @@ void HeapRegionManager::expand(uint start, uint num_regions, WorkerThreads* pret
170171
_regions.set_by_index(i, hr);
171172
_allocated_heapregions_length = MAX2(_allocated_heapregions_length, i + 1);
172173
}
173-
G1CollectedHeap::heap()->hr_printer()->commit(hr);
174+
G1HRPrinter::commit(hr);
174175
}
175176
activate_regions(start, num_regions);
176177
}
@@ -193,13 +194,12 @@ void HeapRegionManager::uncommit_regions(uint start, uint num_regions) {
193194
guarantee(num_regions > 0, "No point in calling this for zero regions");
194195

195196
uint end = start + num_regions;
196-
G1HRPrinter* printer = G1CollectedHeap::heap()->hr_printer();
197-
if (printer->is_active()) {
197+
if (G1HRPrinter::is_active()) {
198198
for (uint i = start; i < end; i++) {
199199
// Can't use at() here since region is no longer marked available.
200200
HeapRegion* hr = _regions.get_by_index(i);
201201
assert(hr != nullptr, "Region should still be present");
202-
printer->uncommit(hr);
202+
G1HRPrinter::uncommit(hr);
203203
}
204204
}
205205

@@ -223,7 +223,7 @@ void HeapRegionManager::initialize_regions(uint start, uint num_regions) {
223223
hr->initialize();
224224
hr->set_node_index(G1NUMA::numa()->index_for_region(hr));
225225
insert_into_free_list(hr);
226-
G1CollectedHeap::heap()->hr_printer()->active(hr);
226+
G1HRPrinter::active(hr);
227227
}
228228
}
229229

@@ -250,7 +250,7 @@ void HeapRegionManager::deactivate_regions(uint start, uint num_regions) {
250250
for (uint i = start; i < end; i++) {
251251
HeapRegion* hr = at(i);
252252
hr->set_node_index(G1NUMA::UnknownNodeIndex);
253-
G1CollectedHeap::heap()->hr_printer()->inactive(hr);
253+
G1HRPrinter::inactive(hr);
254254
}
255255

256256
_committed_map.deactivate(start, end);

src/hotspot/share/gc/g1/g1ParScanThreadState.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "gc/g1/g1CollectedHeap.inline.hpp"
2828
#include "gc/g1/g1CollectionSet.hpp"
2929
#include "gc/g1/g1EvacFailureRegions.inline.hpp"
30+
#include "gc/g1/g1HRPrinter.hpp"
3031
#include "gc/g1/g1OopClosures.inline.hpp"
3132
#include "gc/g1/g1ParScanThreadState.inline.hpp"
3233
#include "gc/g1/g1RootClosures.hpp"
@@ -642,7 +643,7 @@ oop G1ParScanThreadState::handle_evacuation_failure_par(oop old, markWord m, siz
642643
HeapRegion* r = _g1h->heap_region_containing(old);
643644

644645
if (_evac_failure_regions->record(_worker_id, r->hrm_index(), cause_pinned)) {
645-
_g1h->hr_printer()->evac_failure(r);
646+
G1HRPrinter::evac_failure(r);
646647
}
647648

648649
// Mark the failing object in the marking bitmap and later use the bitmap to handle

src/hotspot/share/gc/g1/g1YoungCollector.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ G1GCPhaseTimes* G1YoungCollector::phase_times() const {
216216
return _g1h->phase_times();
217217
}
218218

219-
G1HRPrinter* G1YoungCollector::hr_printer() const {
220-
return _g1h->hr_printer();
221-
}
222-
223219
G1MonitoringSupport* G1YoungCollector::monitoring_support() const {
224220
return _g1h->monitoring_support();
225221
}
@@ -264,13 +260,9 @@ void G1YoungCollector::wait_for_root_region_scanning() {
264260
}
265261

266262
class G1PrintCollectionSetClosure : public HeapRegionClosure {
267-
private:
268-
G1HRPrinter* _hr_printer;
269263
public:
270-
G1PrintCollectionSetClosure(G1HRPrinter* hr_printer) : HeapRegionClosure(), _hr_printer(hr_printer) { }
271-
272264
virtual bool do_heap_region(HeapRegion* r) {
273-
_hr_printer->cset(r);
265+
G1HRPrinter::cset(r);
274266
return false;
275267
}
276268
};
@@ -286,8 +278,8 @@ void G1YoungCollector::calculate_collection_set(G1EvacInfo* evacuation_info, dou
286278

287279
concurrent_mark()->verify_no_collection_set_oops();
288280

289-
if (hr_printer()->is_active()) {
290-
G1PrintCollectionSetClosure cl(hr_printer());
281+
if (G1HRPrinter::is_active()) {
282+
G1PrintCollectionSetClosure cl;
291283
collection_set()->iterate(&cl);
292284
collection_set()->iterate_optional(&cl);
293285
}

0 commit comments

Comments
 (0)