Skip to content

Commit be7cc1c

Browse files
committed
8323681: SA PointerFinder code should support G1
Reviewed-by: tschatzl, kevinw
1 parent fbd15b2 commit be7cc1c

File tree

4 files changed

+67
-16
lines changed

4 files changed

+67
-16
lines changed

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/G1CollectedHeap.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, 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
@@ -122,6 +122,17 @@ public void heapRegionIterate(HeapRegionClosure hrcl) {
122122
}
123123
}
124124

125+
public HeapRegion heapRegionForAddress(Address addr) {
126+
Iterator<HeapRegion> iter = heapRegionIterator();
127+
while (iter.hasNext()) {
128+
HeapRegion hr = iter.next();
129+
if (hr.isInRegion(addr)) {
130+
return hr;
131+
}
132+
}
133+
return null;
134+
}
135+
125136
public CollectedHeapName kind() {
126137
return CollectedHeapName.G1;
127138
}

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/HeapRegion.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, 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
@@ -140,6 +140,10 @@ public static long getPointerSize() {
140140
return pointerSize;
141141
}
142142

143+
public boolean isInRegion(Address addr) {
144+
return (addr.greaterThanOrEqual(bottom()) && addr.lessThan(end()));
145+
}
146+
143147
public void printOn(PrintStream tty) {
144148
tty.print("Region: " + bottom() + "," + top() + "," + end());
145149
tty.println(":" + type.typeAnnotation() + (isPinned() ? " Pinned" : ""));

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerFinder.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import sun.jvm.hotspot.code.*;
2828
import sun.jvm.hotspot.debugger.*;
2929
import sun.jvm.hotspot.debugger.cdbg.*;
30+
import sun.jvm.hotspot.gc.g1.*;
3031
import sun.jvm.hotspot.gc.serial.*;
3132
import sun.jvm.hotspot.gc.shared.*;
3233
import sun.jvm.hotspot.interpreter.*;
@@ -104,8 +105,7 @@ public static PointerLocation find(Address a) {
104105

105106
// If we are using the SerialHeap, find out which generation the address is in
106107
if (heap instanceof SerialHeap) {
107-
SerialHeap sh = (SerialHeap) heap;
108-
loc.heap = heap;
108+
SerialHeap sh = (SerialHeap)heap;
109109
for (int i = 0; i < sh.nGens(); i++) {
110110
Generation g = sh.getGen(i);
111111
if (g.isIn(a)) {
@@ -119,6 +119,18 @@ public static PointerLocation find(Address a) {
119119
}
120120
}
121121

122+
// If we are using the G1CollectedHeap, find out which region the address is in
123+
if (heap instanceof G1CollectedHeap) {
124+
G1CollectedHeap g1 = (G1CollectedHeap)heap;
125+
loc.hr = g1.heapRegionForAddress(a);
126+
// We don't assert that loc.hr is not null like we do for the SerialHeap. This is
127+
// because heap.isIn(a) can return true if the address is anywhere in G1's mapped
128+
// memory, even if that area of memory is not in use by a G1 HeapRegion. So there
129+
// may in fact be no HeapRegion for the address even though it is in the heap.
130+
// Leaving loc.hr == null in this case will result in PointerFinder saying that
131+
// the address is "In unknown section of Java the heap", which is what we want.
132+
}
133+
122134
return loc;
123135
}
124136

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerLocation.java

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import sun.jvm.hotspot.code.*;
2929
import sun.jvm.hotspot.debugger.*;
3030
import sun.jvm.hotspot.debugger.cdbg.*;
31+
import sun.jvm.hotspot.gc.g1.*;
3132
import sun.jvm.hotspot.gc.serial.*;
3233
import sun.jvm.hotspot.gc.shared.*;
3334
import sun.jvm.hotspot.interpreter.*;
@@ -57,7 +58,8 @@ public class PointerLocation {
5758
ClosestSymbol nativeSymbol;
5859

5960
CollectedHeap heap;
60-
Generation gen;
61+
Generation gen; // Serial heap generation
62+
HeapRegion hr; // G1 heap region
6163

6264
// If UseTLAB was enabled and the pointer was found in a
6365
// currently-active TLAB, these will be set
@@ -123,7 +125,11 @@ public boolean inOtherGen() {
123125
}
124126

125127
public Generation getGeneration() {
126-
return gen;
128+
return gen; // SerialHeap generation
129+
}
130+
131+
public HeapRegion getHeapRegion() {
132+
return hr; // G1 heap region
127133
}
128134

129135
/** This may be true if isInNewGen is also true */
@@ -278,18 +284,36 @@ public void printOn(PrintStream tty, boolean printAddress, boolean verbose) {
278284
} else {
279285
tty.format("\"%s\" %s\n", thread.getThreadName(), thread);
280286
}
281-
} else {
282-
if (isInNewGen()) {
283-
tty.print("In new generation ");
284-
} else if (isInOldGen()) {
285-
tty.print("In old generation ");
286-
} else {
287-
tty.print("In unknown section of Java heap");
288-
}
287+
}
288+
// This section provides details about where in the heap the address is located,
289+
// but we only want to do that if it is not in a TLAB or if verbose requested.
290+
if (!isInTLAB() || verbose) {
289291
if (getGeneration() != null) {
290-
getGeneration().printOn(tty); // does not include "\n"
292+
// Address is in SerialGC heap
293+
if (isInNewGen()) {
294+
tty.print("In new generation of SerialGC heap");
295+
} else if (isInOldGen()) {
296+
tty.print("In old generation of SerialGC heap");
297+
} else {
298+
tty.print("In unknown generation of SerialGC heap");
299+
}
300+
if (verbose) {
301+
tty.print(":");
302+
getGeneration().printOn(tty); // does not include "\n"
303+
}
304+
tty.println();
305+
} else if (getHeapRegion() != null) {
306+
// Address is in the G1 heap
307+
if (verbose) {
308+
tty.print("In G1 heap ");
309+
getHeapRegion().printOn(tty); // includes "\n"
310+
} else {
311+
tty.println("In G1 heap region");
312+
}
313+
} else {
314+
// Address is some other heap type that we haven't special cased yet.
315+
tty.println("In unknown section of the Java heap");
291316
}
292-
tty.println();
293317
}
294318
} else if (isInInterpreter()) {
295319
tty.print("In interpreter codelet: ");

0 commit comments

Comments
 (0)