From 2fef5d4a334fd67b5e2a8f342cd7a5143830ddf1 Mon Sep 17 00:00:00 2001 From: Chris Plummer Date: Tue, 29 Mar 2022 18:38:42 +0000 Subject: [PATCH] 8281853: serviceability/sa/ClhsdbThreadContext.java failed with NullPointerException: Cannot invoke "sun.jvm.hotspot.gc.shared.GenCollectedHeap.getGen(int)" because "this.heap" is null Reviewed-by: kevinw, sspitsyn --- .../classes/sun/jvm/hotspot/utilities/PointerFinder.java | 1 + .../classes/sun/jvm/hotspot/utilities/PointerLocation.java | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) 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 cd9e8264f28..f0e7b0997e9 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 @@ -87,6 +87,7 @@ public class PointerFinder { if (heap instanceof GenCollectedHeap) { GenCollectedHeap genheap = (GenCollectedHeap) heap; if (genheap.isIn(a)) { + loc.heap = heap; for (int i = 0; i < genheap.nGens(); i++) { Generation g = genheap.getGen(i); if (g.isIn(a)) { 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 a7cfa5de983..d474469c562 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 @@ -107,22 +107,21 @@ public class PointerLocation { } public boolean isInHeap() { - return (heap != null || (gen != null)); + return (heap != null); } public boolean isInNewGen() { - return ((gen != null) && (gen == ((GenCollectedHeap)heap).getGen(0))); + return ((gen != null) && (gen.equals(((GenCollectedHeap)heap).getGen(0)))); } public boolean isInOldGen() { - return ((gen != null) && (gen == ((GenCollectedHeap)heap).getGen(1))); + return ((gen != null) && (gen.equals(((GenCollectedHeap)heap).getGen(1)))); } public boolean inOtherGen() { return (!isInNewGen() && !isInOldGen()); } - /** Only valid if isInHeap() */ public Generation getGeneration() { return gen; }