Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ GCRoot getGCRoot(Long instanceId) {
heap.getGCRoots();
roots = new HashMap<>();
for (GCRoot r : getGCRoots()) {
roots.put(r.getInstance().getInstanceId(), r);
Instance instance = r.getInstance();
if (instance != null) {
roots.put(instance.getInstanceId(), r);
}
}
gcRoots = roots;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.netbeans.lib.profiler.heap.HeapUtils.HprofGenerator;

Expand All @@ -45,6 +46,29 @@ public void singleObjectMultipleSegments() throws IOException {
singleObject(true);
}

@Test
public void unresolvedStickyClassRootDoesNotBreakGCRootLookup() throws IOException {
File mydump = File.createTempFile("mydump", ".hprof");
try (HprofGenerator gen = new HprofGenerator(new FileOutputStream(mydump))) {
gen.writeHeapSegment(new HprofGenerator.Generator<HprofGenerator.HeapSegment>() {
@Override
public void generate(HprofGenerator.HeapSegment seg) throws IOException {
seg.newClass("com.oracle.svm.core.heap.heapImpl.DiscoverableReference")
.addField("rawReferent", Object.class)
.dumpClass();
HprofGenerator.ClassInstance clazz = seg.newClass("text.HelloWorld").dumpClass();
seg.dumpStickyClassRoot(clazz);
seg.dumpInstance(clazz);
}
}, true);
}

Heap heap = HeapFactory.createHeap(mydump);
assertEquals("One unresolved sticky class root", 1, heap.getGCRoots().size());
Instance instance = (Instance) heap.getJavaClassByName("text.HelloWorld").getInstances().iterator().next();
assertNull("Non-root instance", heap.getGCRoot(instance));
}

private static void singleObject(boolean flush) throws IOException {
File mydump = File.createTempFile("mydump", ".hprof");
Heap heap = generateSampleDump(mydump, flush);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public int dumpPrimitive(Object obj) throws IOException {
return instanceId;
}

public void dumpStickyClassRoot(ClassInstance clazz) throws IOException {
heap.writeByte(0x05);
heap.writeInt(clazz.id);
}

public final class ThreadBuilder {

private String groupName;
Expand Down