8323681: SA PointerFinder code should support G1

Reviewed-by: tschatzl, kevinw
This commit is contained in:
Chris Plummer 2024-02-07 23:39:34 +00:00
parent fbd15b2087
commit be7cc1c2b0
4 changed files with 67 additions and 16 deletions

View File

@ -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<HeapRegion> iter = heapRegionIterator();
while (iter.hasNext()) {
HeapRegion hr = iter.next();
if (hr.isInRegion(addr)) {
return hr;
}
}
return null;
}
public CollectedHeapName kind() {
return CollectedHeapName.G1;
}

View File

@ -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" : ""));

View File

@ -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;
}

View File

@ -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: ");