diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/G1CollectedHeap.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/G1CollectedHeap.java index 3870d2642bf..e04b2381da9 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/G1CollectedHeap.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/G1CollectedHeap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2023, 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 @@ -122,6 +122,17 @@ public class G1CollectedHeap extends CollectedHeap { } } + public HeapRegion heapRegionForAddress(Address addr) { + Iterator iter = heapRegionIterator(); + while (iter.hasNext()) { + HeapRegion hr = iter.next(); + if (hr.isInRegion(addr)) { + return hr; + } + } + return null; + } + public CollectedHeapName kind() { return CollectedHeapName.G1; } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/HeapRegion.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/HeapRegion.java index 580a4b1c397..3abc3f75cd8 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/HeapRegion.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/HeapRegion.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2023, 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 @@ -140,6 +140,10 @@ public class HeapRegion extends ContiguousSpace implements LiveRegionsProvider { return pointerSize; } + public boolean isInRegion(Address addr) { + return (addr.greaterThanOrEqual(bottom()) && addr.lessThan(end())); + } + public void printOn(PrintStream tty) { tty.print("Region: " + bottom() + "," + top() + "," + end()); tty.println(":" + type.typeAnnotation() + (isPinned() ? " Pinned" : "")); diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerFinder.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerFinder.java index 65121c4cca9..0ae61b06fe7 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerFinder.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerFinder.java @@ -27,6 +27,7 @@ package sun.jvm.hotspot.utilities; import sun.jvm.hotspot.code.*; import sun.jvm.hotspot.debugger.*; import sun.jvm.hotspot.debugger.cdbg.*; +import sun.jvm.hotspot.gc.g1.*; import sun.jvm.hotspot.gc.serial.*; import sun.jvm.hotspot.gc.shared.*; import sun.jvm.hotspot.interpreter.*; @@ -104,8 +105,7 @@ public class PointerFinder { // If we are using the SerialHeap, find out which generation the address is in if (heap instanceof SerialHeap) { - SerialHeap sh = (SerialHeap) heap; - loc.heap = heap; + SerialHeap sh = (SerialHeap)heap; for (int i = 0; i < sh.nGens(); i++) { Generation g = sh.getGen(i); if (g.isIn(a)) { @@ -119,6 +119,18 @@ public class PointerFinder { } } + // If we are using the G1CollectedHeap, find out which region the address is in + if (heap instanceof G1CollectedHeap) { + G1CollectedHeap g1 = (G1CollectedHeap)heap; + loc.hr = g1.heapRegionForAddress(a); + // We don't assert that loc.hr is not null like we do for the SerialHeap. This is + // because heap.isIn(a) can return true if the address is anywhere in G1's mapped + // memory, even if that area of memory is not in use by a G1 HeapRegion. So there + // may in fact be no HeapRegion for the address even though it is in the heap. + // Leaving loc.hr == null in this case will result in PointerFinder saying that + // the address is "In unknown section of Java the heap", which is what we want. + } + return loc; } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerLocation.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerLocation.java index 72bcdf1aba3..c4ff1697575 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerLocation.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerLocation.java @@ -28,6 +28,7 @@ import java.io.*; import sun.jvm.hotspot.code.*; import sun.jvm.hotspot.debugger.*; import sun.jvm.hotspot.debugger.cdbg.*; +import sun.jvm.hotspot.gc.g1.*; import sun.jvm.hotspot.gc.serial.*; import sun.jvm.hotspot.gc.shared.*; import sun.jvm.hotspot.interpreter.*; @@ -57,7 +58,8 @@ public class PointerLocation { ClosestSymbol nativeSymbol; CollectedHeap heap; - Generation gen; + Generation gen; // Serial heap generation + HeapRegion hr; // G1 heap region // If UseTLAB was enabled and the pointer was found in a // currently-active TLAB, these will be set @@ -123,7 +125,11 @@ public class PointerLocation { } public Generation getGeneration() { - return gen; + return gen; // SerialHeap generation + } + + public HeapRegion getHeapRegion() { + return hr; // G1 heap region } /** This may be true if isInNewGen is also true */ @@ -278,18 +284,36 @@ public class PointerLocation { } else { tty.format("\"%s\" %s\n", thread.getThreadName(), thread); } - } else { - if (isInNewGen()) { - tty.print("In new generation "); - } else if (isInOldGen()) { - tty.print("In old generation "); - } else { - tty.print("In unknown section of Java heap"); - } + } + // This section provides details about where in the heap the address is located, + // but we only want to do that if it is not in a TLAB or if verbose requested. + if (!isInTLAB() || verbose) { if (getGeneration() != null) { - getGeneration().printOn(tty); // does not include "\n" + // Address is in SerialGC heap + if (isInNewGen()) { + tty.print("In new generation of SerialGC heap"); + } else if (isInOldGen()) { + tty.print("In old generation of SerialGC heap"); + } else { + tty.print("In unknown generation of SerialGC heap"); + } + if (verbose) { + tty.print(":"); + getGeneration().printOn(tty); // does not include "\n" + } + tty.println(); + } else if (getHeapRegion() != null) { + // Address is in the G1 heap + if (verbose) { + tty.print("In G1 heap "); + getHeapRegion().printOn(tty); // includes "\n" + } else { + tty.println("In G1 heap region"); + } + } else { + // Address is some other heap type that we haven't special cased yet. + tty.println("In unknown section of the Java heap"); } - tty.println(); } } else if (isInInterpreter()) { tty.print("In interpreter codelet: ");