Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8353559: Restructure CollectedHeap error printing #24387

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/hotspot/share/gc/epsilon/epsilonHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ void EpsilonHeap::print_on(outputStream *st) const {
MetaspaceUtils::print_on(st);
}

void EpsilonHeap::print_on_error(outputStream *st) const {
print_on(st);
st->cr();

BarrierSet* bs = BarrierSet::barrier_set();
if (bs != nullptr) {
bs->print_on(st);
}
}

bool EpsilonHeap::print_location(outputStream* st, void* addr) const {
return BlockLocationPrinter<EpsilonHeap>::print_location(st, addr);
}
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/gc/epsilon/epsilonHeap.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022, Red Hat, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -132,6 +132,7 @@ class EpsilonHeap : public CollectedHeap {
HeapWord* allocate_loaded_archive_space(size_t size) override;

void print_on(outputStream* st) const override;
void print_on_error(outputStream* st) const override;
void print_tracing_info() const override;
bool print_location(outputStream* st, void* addr) const override;

Expand Down
8 changes: 7 additions & 1 deletion src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,13 @@ void G1CollectedHeap::print_extended_on(outputStream* st) const {
}

void G1CollectedHeap::print_on_error(outputStream* st) const {
this->CollectedHeap::print_on_error(st);
print_extended_on(st);
st->cr();

BarrierSet* bs = BarrierSet::barrier_set();
if (bs != nullptr) {
bs->print_on(st);
}

if (_cm != nullptr) {
st->cr();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1CollectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ class G1CollectedHeap : public CollectedHeap {

public:
void print_on(outputStream* st) const override;
void print_extended_on(outputStream* st) const override;
void print_extended_on(outputStream* st) const;
void print_on_error(outputStream* st) const override;

void gc_threads_do(ThreadClosure* tc) const override;
Expand Down
8 changes: 7 additions & 1 deletion src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,13 @@ void ParallelScavengeHeap::print_on(outputStream* st) const {
}

void ParallelScavengeHeap::print_on_error(outputStream* st) const {
this->CollectedHeap::print_on_error(st);
print_on(st);
st->cr();

BarrierSet* bs = BarrierSet::barrier_set();
if (bs != nullptr) {
bs->print_on(st);
}

st->cr();
PSParallelCompact::print_on_error(st);
Expand Down
10 changes: 10 additions & 0 deletions src/hotspot/share/gc/serial/serialHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,16 @@ void SerialHeap::print_on(outputStream* st) const {
MetaspaceUtils::print_on(st);
}

void SerialHeap::print_on_error(outputStream* st) const {
print_on(st);
st->cr();

BarrierSet* bs = BarrierSet::barrier_set();
if (bs != nullptr) {
bs->print_on(st);
}
}

void SerialHeap::gc_threads_do(ThreadClosure* tc) const {
}

Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/gc/serial/serialHeap.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, 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
Expand Down Expand Up @@ -207,6 +207,7 @@ class SerialHeap : public CollectedHeap {
void verify(VerifyOption option) override;

void print_on(outputStream* st) const override;
void print_on_error(outputStream* st) const override;
void gc_threads_do(ThreadClosure* tc) const override;
void print_tracing_info() const override;

Expand Down
11 changes: 0 additions & 11 deletions src/hotspot/share/gc/shared/collectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,6 @@ void CollectedHeap::print_heap_after_gc() {

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

void CollectedHeap::print_on_error(outputStream* st) const {
st->print_cr("Heap:");
print_extended_on(st);
st->cr();

BarrierSet* bs = BarrierSet::barrier_set();
if (bs != nullptr) {
bs->print_on(st);
}
}

void CollectedHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_tracer) {
const GCHeapSummary& heap_summary = create_heap_summary();
gc_tracer->report_gc_heap_summary(when, heap_summary);
Expand Down
12 changes: 2 additions & 10 deletions src/hotspot/share/gc/shared/collectedHeap.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, 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
Expand Down Expand Up @@ -440,15 +440,7 @@ class CollectedHeap : public CHeapObj<mtGC> {
// The default behavior is to call print_on() on tty.
virtual void print() const;

// Print more detailed heap information on the given
// outputStream. The default behavior is to call print_on(). It is
// up to each subclass to override it and add any additional output
// it needs.
virtual void print_extended_on(outputStream* st) const {
print_on(st);
}

virtual void print_on_error(outputStream* st) const;
virtual void print_on_error(outputStream* st) const = 0;

// Used to print information about locations in the hs_err file.
virtual bool print_location(outputStream* st, void* addr) const = 0;
Expand Down
12 changes: 6 additions & 6 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,12 @@ void ShenandoahHeap::print_on(outputStream* st) const {
}
}

void ShenandoahHeap::print_on_error(outputStream* st) const {
print_on(st);
st->cr();
print_heap_regions_on(st);
}

class ShenandoahInitWorkerGCLABClosure : public ThreadClosure {
public:
void do_thread(Thread* thread) {
Expand Down Expand Up @@ -2582,12 +2588,6 @@ void ShenandoahHeap::rebuild_free_set(bool concurrent) {
}
}

void ShenandoahHeap::print_extended_on(outputStream *st) const {
print_on(st);
st->cr();
print_heap_regions_on(st);
}

bool ShenandoahHeap::is_bitmap_slice_committed(ShenandoahHeapRegion* r, bool skip_self) {
size_t slice = r->index() / _bitmap_regions_per_slice;

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved.
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
Expand Down Expand Up @@ -203,7 +203,7 @@ class ShenandoahHeap : public CollectedHeap {
void initialize_serviceability() override;

void print_on(outputStream* st) const override;
void print_extended_on(outputStream *st) const override;
void print_on_error(outputStream *st) const override;
void print_tracing_info() const override;
void print_heap_regions_on(outputStream* st) const;

Expand Down
28 changes: 1 addition & 27 deletions src/hotspot/share/gc/z/zCollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,33 +359,7 @@ void ZCollectedHeap::print_on(outputStream* st) const {
}

void ZCollectedHeap::print_on_error(outputStream* st) const {
st->print_cr("ZGC Globals:");
st->print_cr(" Young Collection: %s/%u", ZGeneration::young()->phase_to_string(), ZGeneration::young()->seqnum());
st->print_cr(" Old Collection: %s/%u", ZGeneration::old()->phase_to_string(), ZGeneration::old()->seqnum());
st->print_cr(" Offset Max: " EXACTFMT " (" PTR_FORMAT ")", EXACTFMTARGS(ZAddressOffsetMax), ZAddressOffsetMax);
st->print_cr(" Page Size Small: %zuM", ZPageSizeSmall / M);
st->print_cr(" Page Size Medium: %zuM", ZPageSizeMedium / M);
st->cr();
st->print_cr("ZGC Metadata Bits:");
st->print_cr(" LoadGood: " PTR_FORMAT, ZPointerLoadGoodMask);
st->print_cr(" LoadBad: " PTR_FORMAT, ZPointerLoadBadMask);
st->print_cr(" MarkGood: " PTR_FORMAT, ZPointerMarkGoodMask);
st->print_cr(" MarkBad: " PTR_FORMAT, ZPointerMarkBadMask);
st->print_cr(" StoreGood: " PTR_FORMAT, ZPointerStoreGoodMask);
st->print_cr(" StoreBad: " PTR_FORMAT, ZPointerStoreBadMask);
st->print_cr(" ------------------- ");
st->print_cr(" Remapped: " PTR_FORMAT, ZPointerRemapped);
st->print_cr(" RemappedYoung: " PTR_FORMAT, ZPointerRemappedYoungMask);
st->print_cr(" RemappedOld: " PTR_FORMAT, ZPointerRemappedOldMask);
st->print_cr(" MarkedYoung: " PTR_FORMAT, ZPointerMarkedYoung);
st->print_cr(" MarkedOld: " PTR_FORMAT, ZPointerMarkedOld);
st->print_cr(" Remembered: " PTR_FORMAT, ZPointerRemembered);
st->cr();
CollectedHeap::print_on_error(st);
}

void ZCollectedHeap::print_extended_on(outputStream* st) const {
_heap.print_extended_on(st);
_heap.print_on_error(st);
}

void ZCollectedHeap::print_tracing_info() const {
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/gc/z/zCollectedHeap.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, 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
Expand Down Expand Up @@ -117,7 +117,6 @@ class ZCollectedHeap : public CollectedHeap {

void print_on(outputStream* st) const override;
void print_on_error(outputStream* st) const override;
void print_extended_on(outputStream* st) const override;
void print_tracing_info() const override;
bool print_location(outputStream* st, void* addr) const override;

Expand Down
33 changes: 32 additions & 1 deletion src/hotspot/share/gc/z/zHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,41 @@ void ZHeap::print_on(outputStream* st) const {
MetaspaceUtils::print_on(st);
}

void ZHeap::print_extended_on(outputStream* st) const {
void ZHeap::print_on_error(outputStream* st) const {
print_on(st);
st->cr();

print_globals_on(st);
st->cr();

print_page_table_on(st);
}

void ZHeap::print_globals_on(outputStream* st) const {
st->print_cr("ZGC Globals:");
st->print_cr(" Young Collection: %s/%u", ZGeneration::young()->phase_to_string(), ZGeneration::young()->seqnum());
st->print_cr(" Old Collection: %s/%u", ZGeneration::old()->phase_to_string(), ZGeneration::old()->seqnum());
st->print_cr(" Offset Max: " EXACTFMT " (" PTR_FORMAT ")", EXACTFMTARGS(ZAddressOffsetMax), ZAddressOffsetMax);
st->print_cr(" Page Size Small: %zuM", ZPageSizeSmall / M);
st->print_cr(" Page Size Medium: %zuM", ZPageSizeMedium / M);
st->cr();
st->print_cr("ZGC Metadata Bits:");
st->print_cr(" LoadGood: " PTR_FORMAT, ZPointerLoadGoodMask);
st->print_cr(" LoadBad: " PTR_FORMAT, ZPointerLoadBadMask);
st->print_cr(" MarkGood: " PTR_FORMAT, ZPointerMarkGoodMask);
st->print_cr(" MarkBad: " PTR_FORMAT, ZPointerMarkBadMask);
st->print_cr(" StoreGood: " PTR_FORMAT, ZPointerStoreGoodMask);
st->print_cr(" StoreBad: " PTR_FORMAT, ZPointerStoreBadMask);
st->print_cr(" ------------------- ");
st->print_cr(" Remapped: " PTR_FORMAT, ZPointerRemapped);
st->print_cr(" RemappedYoung: " PTR_FORMAT, ZPointerRemappedYoungMask);
st->print_cr(" RemappedOld: " PTR_FORMAT, ZPointerRemappedOldMask);
st->print_cr(" MarkedYoung: " PTR_FORMAT, ZPointerMarkedYoung);
st->print_cr(" MarkedOld: " PTR_FORMAT, ZPointerMarkedOld);
st->print_cr(" Remembered: " PTR_FORMAT, ZPointerRemembered);
}

void ZHeap::print_page_table_on(outputStream* st) const {
// Do not allow pages to be deleted
_page_allocator.enable_safe_destroy();

Expand Down
6 changes: 4 additions & 2 deletions src/hotspot/share/gc/z/zHeap.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, 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
Expand Down Expand Up @@ -132,7 +132,9 @@ class ZHeap {

// Printing
void print_on(outputStream* st) const;
void print_extended_on(outputStream* st) const;
void print_on_error(outputStream* st) const;
void print_globals_on(outputStream* st) const;
void print_page_table_on(outputStream* st) const;
bool print_location(outputStream* st, uintptr_t addr) const;
bool print_location(outputStream* st, zaddress addr) const;
bool print_location(outputStream* st, zpointer ptr) const;
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/utilities/vmError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ void VMError::report(outputStream* st, bool _verbose) {
GCLogPrecious::print_on_error(st);

if (Universe::heap() != nullptr) {
st->print_cr("Heap:");
Universe::heap()->print_on_error(st);
st->cr();
}
Expand Down Expand Up @@ -1374,6 +1375,7 @@ void VMError::print_vm_info(outputStream* st) {
if (Universe::is_fully_initialized()) {
MutexLocker hl(Heap_lock);
GCLogPrecious::print_on_error(st);
st->print_cr("Heap:");
Universe::heap()->print_on_error(st);
st->cr();
st->print_cr("Polling page: " PTR_FORMAT, p2i(SafepointMechanism::get_polling_page()));
Expand Down