Skip to content

Commit

Permalink
Playing around with heap region printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schatzl committed Jan 18, 2024
1 parent 2662f25 commit 8757040
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
37 changes: 20 additions & 17 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2057,16 +2057,6 @@ bool G1CollectedHeap::supports_concurrent_gc_breakpoints() const {
return true;
}

class PrintRegionClosure: public HeapRegionClosure {
outputStream* _st;
public:
PrintRegionClosure(outputStream* st) : _st(st) {}
bool do_heap_region(HeapRegion* r) {
r->print_on(_st);
return false;
}
};

bool G1CollectedHeap::is_obj_dead_cond(const oop obj,
const HeapRegion* hr,
const VerifyOption vo) const {
Expand All @@ -2088,11 +2078,11 @@ bool G1CollectedHeap::is_obj_dead_cond(const oop obj,
return false; // keep some compilers happy
}

void G1CollectedHeap::print_heap_regions() const {
void G1CollectedHeap::print_heap_regions(bool print_pin_counts) const {
LogTarget(Trace, gc, heap, region) lt;
if (lt.is_enabled()) {
LogStream ls(lt);
print_regions_on(&ls);
print_regions_on(&ls, print_pin_counts);
}
}

Expand Down Expand Up @@ -2126,13 +2116,25 @@ void G1CollectedHeap::print_on(outputStream* st) const {
MetaspaceUtils::print_on(st);
}

void G1CollectedHeap::print_regions_on(outputStream* st) const {

class PrintRegionClosure: public HeapRegionClosure {
outputStream* _st;
const bool _print_pin_counts;
public:
PrintRegionClosure(outputStream* st, bool print_pin_counts) : _st(st), _print_pin_counts(print_pin_counts) {}
bool do_heap_region(HeapRegion* r) {
r->print_on(_st, _print_pin_counts);
return false;
}
};

void G1CollectedHeap::print_regions_on(outputStream* st, bool print_pin_counts) const {
st->print_cr("Heap Regions: E=young(eden), S=young(survivor), O=old, "
"HS=humongous(starts), HC=humongous(continues), "
"CS=collection set, F=free, "
"TAMS=top-at-mark-start, "
"PB=parsable bottom");
PrintRegionClosure blk(st);
PrintRegionClosure blk(st, print_pin_counts);
heap_region_iterate(&blk);
}

Expand All @@ -2141,7 +2143,7 @@ void G1CollectedHeap::print_extended_on(outputStream* st) const {

// Print the per-region information.
st->cr();
print_regions_on(st);
print_regions_on(st, true /* print_pin_counts */);
}

void G1CollectedHeap::print_on_error(outputStream* st) const {
Expand Down Expand Up @@ -2422,7 +2424,8 @@ G1HeapPrinterMark::G1HeapPrinterMark(G1CollectedHeap* g1h) : _g1h(g1h), _heap_tr
_g1h->total_collections(),
true /* show_thread_times */);
_g1h->print_heap_before_gc();
_g1h->print_heap_regions();
// We did not merge in the cached pin counts yet, making the output confusing.
_g1h->print_heap_regions(false /* print_pin_counts */);
}

G1HeapPrinterMark::~G1HeapPrinterMark() {
Expand All @@ -2434,7 +2437,7 @@ G1HeapPrinterMark::~G1HeapPrinterMark() {
false /* show_thread_times */);

_heap_transition.print();
_g1h->print_heap_regions();
_g1h->print_heap_regions(true /* print_pin_counts */);
_g1h->print_heap_after_gc();
// Print NUMA statistics.
_g1h->numa()->print_statistics();
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/g1/g1CollectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,8 +1306,8 @@ class G1CollectedHeap : public CollectedHeap {

// Printing
private:
void print_heap_regions() const;
void print_regions_on(outputStream* st) const;
void print_heap_regions(bool print_pin_counts) const;
void print_regions_on(outputStream* st, bool print_pin_counts) const;

public:
void print_on(outputStream* st) const override;
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/share/gc/g1/heapRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,7 @@ bool HeapRegion::verify_code_roots(VerifyOption vo) const {
return cb_cl.failures();
}

void HeapRegion::print() const { print_on(tty); }

void HeapRegion::print_on(outputStream* st) const {
void HeapRegion::print_on(outputStream* st, bool print_pin_counts) const {
st->print("|%4u", this->_hrm_index);
st->print("|" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT,
p2i(bottom()), p2i(top()), p2i(end()));
Expand All @@ -425,7 +423,7 @@ void HeapRegion::print_on(outputStream* st) const {
st->print("|-");
}
}
st->print("|%3zu", Atomic::load(&_pinned_object_count));
st->print("|%s%3zu", print_pin_counts ? "" : "~", Atomic::load(&_pinned_object_count));
st->print("|%3zu", Atomic::load(&_total_pinned_atomicops));
st->print_cr("");
}
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/gc/g1/heapRegion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ class HeapRegion : public CHeapObj<mtGC> {
bool verify_code_roots(VerifyOption vo) const;
bool verify_liveness_and_remset(VerifyOption vo) const;

void print() const;
void print_on(outputStream* st) const;
void print_on(outputStream* st, bool print_pin_counts) const;

bool verify(VerifyOption vo) const;
};
Expand Down

0 comments on commit 8757040

Please sign in to comment.