Skip to content

Commit

Permalink
8323681: SA PointerFinder code should support G1
Browse files Browse the repository at this point in the history
Reviewed-by: tschatzl, kevinw
  • Loading branch information
plummercj committed Feb 7, 2024
1 parent fbd15b2 commit be7cc1c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -122,6 +122,17 @@ public void heapRegionIterate(HeapRegionClosure hrcl) {
}
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -140,6 +140,10 @@ public static long getPointerSize() {
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" : ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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.*;
Expand Down Expand Up @@ -104,8 +105,7 @@ public static PointerLocation find(Address a) {

// 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)) {
Expand All @@ -119,6 +119,18 @@ public static PointerLocation find(Address a) {
}
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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.*;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -123,7 +125,11 @@ public boolean inOtherGen() {
}

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 */
Expand Down Expand Up @@ -278,18 +284,36 @@ public void printOn(PrintStream tty, boolean printAddress, boolean verbose) {
} 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: ");
Expand Down

1 comment on commit be7cc1c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.