Skip to content

Commit 2511797

Browse files
committed
GH-146 show static fields and full name of class
1 parent de10c09 commit 2511797

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/java/InstanceNode.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ public JavaClass getJavaClass() {
9090
public String getName(Heap heap) {
9191
if (name == null) {
9292
if (heap == null) {
93-
return computeName(instance, Collections.EMPTY_LIST);
93+
return computeName(heap, instance, Collections.EMPTY_LIST);
9494
} else {
9595
Collection<GCRoot> gcRoots = heap.getGCRoots(instance);
9696
isGCRoot = gcRoots.isEmpty();
97-
name = computeName(instance, gcRoots);
97+
name = computeName(heap, instance, gcRoots);
9898
}
9999
}
100100
return name;
@@ -133,11 +133,21 @@ boolean isGCRoot() {
133133

134134
static String computeName(Instance instance, Heap heap) {
135135
Collection<GCRoot> gcroots = heap == null ? Collections.EMPTY_LIST : heap.getGCRoots(instance);
136-
return computeName(instance, gcroots);
136+
return computeName(heap, instance, gcroots);
137137
}
138138

139-
private static String computeName(Instance instance, Collection<GCRoot> gcroots) {
140-
String name = instance.getJavaClass().getName() + "#" + instance.getInstanceNumber(); // NOI18N
139+
private static String computeName(Heap heap, Instance instance, Collection<GCRoot> gcroots) {
140+
String name = null;
141+
String className = instance.getJavaClass().getName();
142+
if (heap != null && Class.class.getName().equals(className)) {
143+
JavaClass jcls = heap.getJavaClassByID(instance.getInstanceId());
144+
if (jcls != null) {
145+
name = "class "+jcls.getName(); // NOI18N
146+
}
147+
}
148+
if (name == null) {
149+
name = className + "#" + instance.getInstanceNumber(); // NOI18N
150+
}
141151
if (!gcroots.isEmpty()) {
142152
Set<String> gcKinds = new HashSet();
143153

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,14 @@ public boolean supportsView(Heap heap, String viewID) {
120120
public boolean supportsNode(HeapViewerNode parent, Heap heap, String viewID) {
121121
if (parent instanceof InstanceNode && !InstanceNode.Mode.INCOMING_REFERENCE.equals(((InstanceNode)parent).getMode())) {
122122
Instance instance = ((InstanceNode)parent).getInstance();
123-
return instance != null && !instance.getJavaClass().isArray();
123+
if (instance == null) return false;
124+
JavaClass jcls = instance.getJavaClass();
125+
if (jcls.isArray()) return false;
126+
if (Class.class.getName().equals(jcls.getName())) {
127+
JavaClass jclass = heap.getJavaClassByID(instance.getInstanceId());
128+
return jclass == null;
129+
}
130+
return true;
124131
} else {
125132
return false;
126133
}
@@ -148,7 +155,7 @@ static List<FieldValue> getFields(HeapViewerNode parent, Heap heap, boolean inst
148155

149156
}
150157

151-
// @ServiceProvider(service=HeapViewerNode.Provider.class, position = 250)
158+
@ServiceProvider(service=HeapViewerNode.Provider.class, position = 250)
152159
@NbBundle.Messages({
153160
"ClassFieldsProvider_Name=static fields"
154161
})
@@ -159,21 +166,27 @@ public String getName() {
159166
}
160167

161168
public boolean supportsView(Heap heap, String viewID) {
162-
return viewID.startsWith("java_objects"); // NOI18N
169+
return viewID.startsWith("java_"); // NOI18N
163170
}
164171

165172
public boolean supportsNode(HeapViewerNode parent, Heap heap, String viewID) {
166-
if (parent instanceof ClassNode) {
167-
JavaClass javaClass = ((ClassNode)parent).getJavaClass();
168-
return javaClass != null && !javaClass.isArray();
169-
} else {
170-
return false;
173+
if (parent instanceof InstanceNode && !InstanceNode.Mode.INCOMING_REFERENCE.equals(((InstanceNode)parent).getMode())) {
174+
Instance instance = ((InstanceNode)parent).getInstance();
175+
if (instance == null) return false;
176+
JavaClass jcls = instance.getJavaClass();
177+
if (jcls.isArray()) return false;
178+
if (Class.class.getName().equals(jcls.getName())) {
179+
JavaClass jclass = heap.getJavaClassByID(instance.getInstanceId());
180+
return jclass != null;
181+
}
171182
}
183+
return false;
172184
}
173-
174185

175186
protected List<FieldValue> getFields(HeapViewerNode parent, Heap heap) {
176-
JavaClass jclass = HeapViewerNode.getValue(parent, DataType.CLASS, heap);
187+
Instance instance = HeapViewerNode.getValue(parent, DataType.INSTANCE, heap);
188+
if (instance == null) return null;
189+
JavaClass jclass = heap.getJavaClassByID(instance.getInstanceId());
177190
return jclass == null ? null : jclass.getStaticFieldValues();
178191
}
179192

0 commit comments

Comments
 (0)