8214756: SA should ignore archived java heap objects that are not in use
Summary: Ignore objects, the associated classes of which are unloaded while walking the heap to create a heapdump
Reviewed-by: jiangli, redestad
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java Mon Feb 18 16:17:48 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java Mon Feb 25 13:50:32 2019 +0530
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2019, 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
@@ -938,10 +938,16 @@
}
protected void writeInstance(Instance instance) throws IOException {
+ Klass klass = instance.getKlass();
+ if (klass.getClassLoaderData() == null) {
+ // Ignoring this object since the corresponding Klass is not loaded.
+ // Might be a dormant archive object.
+ return;
+ }
+
out.writeByte((byte) HPROF_GC_INSTANCE_DUMP);
writeObjectID(instance);
out.writeInt(DUMMY_STACK_TRACE_ID);
- Klass klass = instance.getKlass();
writeObjectID(klass.getJavaMirror());
ClassData cd = (ClassData) classDataCache.get(klass);