Skip to content

Commit b5978a1

Browse files
committed
Merged GC roots: show instances with no GC roots
1 parent e9b4308 commit b5978a1

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/java/impl/PathToGCRootPlugin.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,12 @@ private static Collection<HeapViewerNode> computeInstancesRoots(Iterator<Instanc
295295
while (!current.isInterrupted() && instances.hasNext()) {
296296
Instance instance = instances.next();
297297
Instance gcRoot = getGCRoot(instance, current);
298-
if (gcRoot != null) {
299-
GCRootNode gcRootNode = (GCRootNode)gcRoots.get(gcRoot);
300-
if (gcRootNode == null) {
301-
gcRootNode = new GCRootNode(gcRoot);
302-
gcRoots.put(gcRoot, gcRootNode);
303-
}
304-
gcRootNode.addInstance(instance);
298+
GCRootNode gcRootNode = (GCRootNode)gcRoots.get(gcRoot);
299+
if (gcRootNode == null) {
300+
gcRootNode = new GCRootNode(gcRoot);
301+
gcRoots.put(gcRoot, gcRootNode);
305302
}
303+
gcRootNode.addInstance(instance);
306304
progress.step();
307305
}
308306
if (current.isInterrupted()) throw new InterruptedException();
@@ -336,7 +334,7 @@ private static void storeItem(String itemName, boolean value) {
336334
"GCRootNode_SamplesContainer=<sample {0} instances>",
337335
"GCRootNode_NodesContainer=<instances {0}-{1}>"
338336
})
339-
static class GCRootNode extends InstanceNode {
337+
static class GCRootNode extends InstanceNode.IncludingNull {
340338

341339
// private final int maxNodes = UIThresholds.MAX_MERGED_OBJECTS;
342340

@@ -370,14 +368,17 @@ public int getCount() {
370368
// }
371369

372370
protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
373-
final boolean isArray = getInstance().getJavaClass().isArray();
371+
final Instance gcRoot = getInstance();
372+
final boolean isArray = gcRoot != null && gcRoot.getJavaClass().isArray();
374373
NodesComputer<Instance> computer = new NodesComputer<Instance>(instances.size(), UIThresholds.MAX_MERGED_OBJECTS) {
375374
protected boolean sorts(DataType dataType) {
376375
if (DataType.COUNT.equals(dataType) || (DataType.OWN_SIZE.equals(dataType) && !isArray)) return false;
377376
return true;
378377
}
379378
protected HeapViewerNode createNode(Instance object) {
380-
return GCRootNode.this.createNode(object);
379+
return new GCInstanceNode(object) {
380+
public boolean isLeaf() { return gcRoot == null; }
381+
};
381382
}
382383
protected ProgressIterator<Instance> objectsIterator(int index, Progress progress) {
383384
Iterator<Instance> iterator = instances.listIterator(index);
@@ -396,10 +397,6 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
396397
return computer.computeNodes(GCRootNode.this, heap, viewID, null, dataTypes, sortOrders, progress);
397398
}
398399

399-
private HeapViewerNode createNode(Instance instance) {
400-
return new GCInstanceNode(instance);
401-
}
402-
403400

404401
protected Object getValue(DataType type, Heap heap) {
405402
if (type == DataType.COUNT) return getCount();
@@ -408,6 +405,11 @@ protected Object getValue(DataType type, Heap heap) {
408405
}
409406

410407

408+
public boolean isLeaf() {
409+
return false;
410+
}
411+
412+
411413
static class Renderer extends InstanceNodeRenderer {
412414

413415
private static final ImageIcon ICON = Icons.getImageIcon(ProfilerIcons.NODE_FORWARD);
@@ -416,6 +418,21 @@ static class Renderer extends InstanceNodeRenderer {
416418
super(heap);
417419
}
418420

421+
@Override
422+
public void setValue(Object value, int row) {
423+
if (value != null) {
424+
GCRootNode node = (GCRootNode)value;
425+
if (node.getInstance() == null) {
426+
setNormalValue(Bundle.PathToGCRootPlugin_NoRoot());
427+
setBoldValue(""); // NOI18N
428+
setGrayValue(""); // NOI18N
429+
setIcon(ICON);
430+
return;
431+
}
432+
}
433+
super.setValue(value, row);
434+
}
435+
419436
@Override
420437
protected ImageIcon getIcon(Instance instance, boolean isGCRoot) {
421438
return ICON;

0 commit comments

Comments
 (0)