Skip to content

Commit cf96b10

Browse files
committed
8354362: Use automatic indentation in CollectedHeap printing
Reviewed-by: stefank, lkorinth, stuefe
1 parent 0537c69 commit cf96b10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+270
-259
lines changed

src/hotspot/share/gc/epsilon/epsilonHeap.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "memory/universe.hpp"
3838
#include "runtime/atomic.hpp"
3939
#include "runtime/globals.hpp"
40+
#include "utilities/ostream.hpp"
4041

4142
jint EpsilonHeap::initialize() {
4243
size_t align = HeapAlignment;
@@ -297,26 +298,18 @@ void EpsilonHeap::object_iterate(ObjectClosure *cl) {
297298
_space->object_iterate(cl);
298299
}
299300

300-
void EpsilonHeap::print_on(outputStream *st) const {
301+
void EpsilonHeap::print_heap_on(outputStream *st) const {
301302
st->print_cr("Epsilon Heap");
302303

304+
StreamAutoIndentor indentor(st, 1);
305+
303306
_virtual_space.print_on(st);
304307

305308
if (_space != nullptr) {
306309
st->print_cr("Allocation space:");
307-
_space->print_on(st);
308-
}
309-
310-
MetaspaceUtils::print_on(st);
311-
}
312-
313-
void EpsilonHeap::print_on_error(outputStream *st) const {
314-
print_on(st);
315-
st->cr();
316310

317-
BarrierSet* bs = BarrierSet::barrier_set();
318-
if (bs != nullptr) {
319-
bs->print_on(st);
311+
StreamAutoIndentor indentor(st, 1);
312+
_space->print_on(st, "");
320313
}
321314
}
322315

src/hotspot/share/gc/epsilon/epsilonHeap.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ class EpsilonHeap : public CollectedHeap {
131131
bool can_load_archived_objects() const override { return true; }
132132
HeapWord* allocate_loaded_archive_space(size_t size) override;
133133

134-
void print_on(outputStream* st) const override;
135-
void print_on_error(outputStream* st) const override;
134+
void print_heap_on(outputStream* st) const override;
135+
void print_gc_on(outputStream* st) const override {}
136136
void print_tracing_info() const override;
137137
bool print_location(outputStream* st, void* addr) const override;
138138

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,16 +2112,18 @@ void G1CollectedHeap::print_heap_regions() const {
21122112
}
21132113
}
21142114

2115-
void G1CollectedHeap::print_on(outputStream* st) const {
2115+
void G1CollectedHeap::print_heap_on(outputStream* st) const {
21162116
size_t heap_used = Heap_lock->owned_by_self() ? used() : used_unlocked();
2117-
st->print(" %-20s", "garbage-first heap");
2117+
st->print("%-20s", "garbage-first heap");
21182118
st->print(" total reserved %zuK, committed %zuK, used %zuK",
21192119
_hrm.reserved().byte_size()/K, capacity()/K, heap_used/K);
21202120
st->print(" [" PTR_FORMAT ", " PTR_FORMAT ")",
21212121
p2i(_hrm.reserved().start()),
21222122
p2i(_hrm.reserved().end()));
21232123
st->cr();
2124-
st->print(" region size %zuK, ", G1HeapRegion::GrainBytes / K);
2124+
2125+
StreamAutoIndentor indentor(st, 1);
2126+
st->print("region size %zuK, ", G1HeapRegion::GrainBytes / K);
21252127
uint young_regions = young_regions_count();
21262128
st->print("%u young (%zuK), ", young_regions,
21272129
(size_t) young_regions * G1HeapRegion::GrainBytes / K);
@@ -2131,15 +2133,14 @@ void G1CollectedHeap::print_on(outputStream* st) const {
21312133
st->cr();
21322134
if (_numa->is_enabled()) {
21332135
uint num_nodes = _numa->num_active_nodes();
2134-
st->print(" remaining free region(s) on each NUMA node: ");
2136+
st->print("remaining free region(s) on each NUMA node: ");
21352137
const uint* node_ids = _numa->node_ids();
21362138
for (uint node_index = 0; node_index < num_nodes; node_index++) {
21372139
uint num_free_regions = _hrm.num_free_regions(node_index);
21382140
st->print("%u=%u ", node_ids[node_index], num_free_regions);
21392141
}
21402142
st->cr();
21412143
}
2142-
MetaspaceUtils::print_on(st);
21432144
}
21442145

21452146
void G1CollectedHeap::print_regions_on(outputStream* st) const {
@@ -2153,15 +2154,16 @@ void G1CollectedHeap::print_regions_on(outputStream* st) const {
21532154
}
21542155

21552156
void G1CollectedHeap::print_extended_on(outputStream* st) const {
2156-
print_on(st);
2157+
print_heap_on(st);
21572158

21582159
// Print the per-region information.
21592160
st->cr();
21602161
print_regions_on(st);
21612162
}
21622163

2163-
void G1CollectedHeap::print_on_error(outputStream* st) const {
2164-
print_extended_on(st);
2164+
void G1CollectedHeap::print_gc_on(outputStream* st) const {
2165+
// Print the per-region information.
2166+
print_regions_on(st);
21652167
st->cr();
21662168

21672169
BarrierSet* bs = BarrierSet::barrier_set();
@@ -2171,7 +2173,7 @@ void G1CollectedHeap::print_on_error(outputStream* st) const {
21712173

21722174
if (_cm != nullptr) {
21732175
st->cr();
2174-
_cm->print_on_error(st);
2176+
_cm->print_on(st);
21752177
}
21762178
}
21772179

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,9 +1312,9 @@ class G1CollectedHeap : public CollectedHeap {
13121312
void print_regions_on(outputStream* st) const;
13131313

13141314
public:
1315-
void print_on(outputStream* st) const override;
1315+
void print_heap_on(outputStream* st) const override;
13161316
void print_extended_on(outputStream* st) const;
1317-
void print_on_error(outputStream* st) const override;
1317+
void print_gc_on(outputStream* st) const override;
13181318

13191319
void gc_threads_do(ThreadClosure* tc) const override;
13201320

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,9 +2126,9 @@ void G1ConcurrentMark::threads_do(ThreadClosure* tc) const {
21262126
_concurrent_workers->threads_do(tc);
21272127
}
21282128

2129-
void G1ConcurrentMark::print_on_error(outputStream* st) const {
2129+
void G1ConcurrentMark::print_on(outputStream* st) const {
21302130
st->print_cr("Marking Bits: (CMBitMap*) " PTR_FORMAT, p2i(mark_bitmap()));
2131-
_mark_bitmap.print_on_error(st, " Bits: ");
2131+
_mark_bitmap.print_on(st, " Bits: ");
21322132
}
21332133

21342134
static ReferenceProcessor* get_cm_oop_closure_ref_processor(G1CollectedHeap* g1h) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, 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
@@ -707,7 +707,7 @@ class G1ConcurrentMark : public CHeapObj<mtGC> {
707707

708708
void threads_do(ThreadClosure* tc) const;
709709

710-
void print_on_error(outputStream* st) const;
710+
void print_on(outputStream* st) const;
711711

712712
// Mark the given object on the marking bitmap if it is below TAMS.
713713
inline bool mark_in_bitmap(uint worker_id, oop const obj);

src/hotspot/share/gc/parallel/mutableNUMASpace.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,17 +608,20 @@ void MutableNUMASpace::print_short_on(outputStream* st) const {
608608
st->print(")");
609609
}
610610

611-
void MutableNUMASpace::print_on(outputStream* st) const {
612-
MutableSpace::print_on(st);
611+
void MutableNUMASpace::print_on(outputStream* st, const char* prefix) const {
612+
MutableSpace::print_on(st, prefix);
613+
614+
StreamAutoIndentor indentor(st, 1);
613615
for (int i = 0; i < lgrp_spaces()->length(); i++) {
614616
LGRPSpace *ls = lgrp_spaces()->at(i);
615-
st->print(" lgrp %u", ls->lgrp_id());
616-
ls->space()->print_on(st);
617+
FormatBuffer<128> lgrp_message("lgrp %u ", ls->lgrp_id());
618+
ls->space()->print_on(st, lgrp_message);
617619
if (NUMAStats) {
620+
StreamAutoIndentor indentor_numa(st, 1);
618621
for (int i = 0; i < lgrp_spaces()->length(); i++) {
619622
lgrp_spaces()->at(i)->accumulate_statistics(page_size());
620623
}
621-
st->print(" local/remote/unbiased/uncommitted: %zuK/"
624+
st->print("local/remote/unbiased/uncommitted: %zuK/"
622625
"%zuK/%zuK/%zuK\n",
623626
ls->space_stats()->_local_space / K,
624627
ls->space_stats()->_remote_space / K,

src/hotspot/share/gc/parallel/mutableNUMASpace.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 2025, 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
@@ -186,7 +186,7 @@ class MutableNUMASpace : public MutableSpace {
186186
virtual HeapWord* cas_allocate(size_t word_size);
187187

188188
// Debugging
189-
virtual void print_on(outputStream* st) const;
189+
virtual void print_on(outputStream* st, const char* prefix) const;
190190
virtual void print_short_on(outputStream* st) const;
191191
virtual void verify();
192192

src/hotspot/share/gc/parallel/mutableSpace.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,13 @@ void MutableSpace::object_iterate(ObjectClosure* cl) {
232232

233233
void MutableSpace::print_short() const { print_short_on(tty); }
234234
void MutableSpace::print_short_on( outputStream* st) const {
235-
st->print(" space %zuK, %d%% used", capacity_in_bytes() / K,
235+
st->print("space %zuK, %d%% used", capacity_in_bytes() / K,
236236
(int) ((double) used_in_bytes() * 100 / capacity_in_bytes()));
237237
}
238238

239-
void MutableSpace::print() const { print_on(tty); }
240-
void MutableSpace::print_on(outputStream* st) const {
239+
void MutableSpace::print() const { print_on(tty, ""); }
240+
void MutableSpace::print_on(outputStream* st, const char* prefix) const {
241+
st->print("%s", prefix);
241242
MutableSpace::print_short_on(st);
242243
st->print_cr(" [" PTR_FORMAT "," PTR_FORMAT "," PTR_FORMAT ")",
243244
p2i(bottom()), p2i(top()), p2i(end()));

src/hotspot/share/gc/parallel/mutableSpace.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, 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
@@ -138,7 +138,7 @@ class MutableSpace: public CHeapObj<mtGC> {
138138

139139
// Debugging
140140
virtual void print() const;
141-
virtual void print_on(outputStream* st) const;
141+
virtual void print_on(outputStream* st, const char* prefix) const;
142142
virtual void print_short() const;
143143
virtual void print_short_on(outputStream* st) const;
144144
virtual void verify();

0 commit comments

Comments
 (0)