Skip to content

Commit c029250

Browse files
committed
Fixed AIOOBE when subsequently opening HeapViewPlugins
- reworked the cleanup code when a HeapViewPlugin is closed
1 parent dbaf561 commit c029250

File tree

14 files changed

+91
-59
lines changed

14 files changed

+91
-59
lines changed

visualvm/heapviewer.truffle/nbproject/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<compile-dependency/>
2222
<run-dependency>
2323
<release-version>2</release-version>
24-
<specification-version>2.0</specification-version>
24+
<specification-version>2.1</specification-version>
2525
</run-dependency>
2626
</dependency>
2727
<dependency>

visualvm/heapviewer.truffle/src/org/graalvm/visualvm/heapviewer/truffle/TruffleObjectPreviewPlugin.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -70,6 +70,11 @@ public TruffleObjectPreviewPlugin(HeapContext context) {
7070
protected abstract Instance getPreviewInstance(HeapViewerNode node);
7171

7272

73+
@Override
74+
protected void closed() {
75+
// TODO: should cancel the preview
76+
}
77+
7378
@Override
7479
protected void nodeSelected(HeapViewerNode node, boolean adjusting) {
7580
component.showInstance(supportsNode(node) ? getPreviewInstance(node) : null);

visualvm/heapviewer.truffle/src/org/graalvm/visualvm/heapviewer/truffle/TruffleObjectPropertyPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -267,6 +267,7 @@ protected JComponent createComponent() {
267267

268268
@Override
269269
protected void closed() {
270+
synchronized (objectsView) { selected = objectsView.getRoot(); }
270271
objectsView.closed();
271272
}
272273

visualvm/heapviewer.truffle/src/org/graalvm/visualvm/heapviewer/truffle/javaext/TruffleJavaViewPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -96,6 +96,7 @@ protected JComponent createComponent() {
9696

9797
@Override
9898
protected void closed() {
99+
synchronized (objectsView) { selected = TruffleViewPlugin.NO_INSTANCE; }
99100
objectsView.closed();
100101
}
101102

visualvm/heapviewer.truffle/src/org/graalvm/visualvm/heapviewer/truffle/javaext/TruffleViewPlugin.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -48,6 +48,7 @@
4848
import org.graalvm.visualvm.heapviewer.ui.HeapViewerActions;
4949
import org.graalvm.visualvm.heapviewer.ui.TreeTableView;
5050
import org.graalvm.visualvm.heapviewer.ui.TreeTableViewColumn;
51+
import org.graalvm.visualvm.lib.jfluid.heap.JavaClass;
5152
import org.openide.util.ImageUtilities;
5253
import org.openide.util.NbBundle;
5354
import org.openide.util.lookup.ServiceProvider;
@@ -63,6 +64,9 @@
6364
})
6465
class TruffleViewPlugin extends HeapViewPlugin {
6566

67+
static final Instance NO_INSTANCE = new FakeInstance();
68+
69+
6670
private final Heap heap;
6771
private Instance selected;
6872

@@ -104,6 +108,7 @@ protected JComponent createComponent() {
104108

105109
@Override
106110
protected void closed() {
111+
synchronized (objectsView) { selected = NO_INSTANCE; }
107112
objectsView.closed();
108113
}
109114

@@ -135,4 +140,23 @@ public HeapViewPlugin createPlugin(HeapContext context, HeapViewerActions action
135140

136141
}
137142

143+
144+
private static class FakeInstance implements Instance {
145+
@Override public List getFieldValues() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
146+
@Override public boolean isGCRoot() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
147+
@Override public long getInstanceId() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
148+
@Override public int getInstanceNumber() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
149+
@Override public JavaClass getJavaClass() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
150+
@Override public Instance getNearestGCRootPointer() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
151+
@Override public long getReachableSize() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
152+
@Override public List getReferences() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
153+
@Override public long getRetainedSize() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
154+
@Override public long getSize() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
155+
@Override public List getStaticFieldValues() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
156+
@Override public Object getValueOfField(String name) { throw new UnsupportedOperationException("Not supported."); } // NOI18N
157+
158+
@Override public boolean equals(Object o) { return o == this; }
159+
@Override public int hashCode() { return -1; }
160+
}
161+
138162
}

visualvm/heapviewer/manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ AutoUpdate-Show-In-Client: false
33
AutoUpdate-Essential-Module: true
44
OpenIDE-Module: org.graalvm.visualvm.heapviewer/2
55
OpenIDE-Module-Localizing-Bundle: org/graalvm/visualvm/heapviewer/Bundle.properties
6-
OpenIDE-Module-Specification-Version: 2.0
6+
OpenIDE-Module-Specification-Version: 2.1
77

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -64,7 +64,8 @@
6464
})
6565
public class ClassHierarchyPlugin extends HeapViewPlugin {
6666

67-
private static final JavaClass EMPTY_CLASS = new EmptyJavaClass();
67+
private static final JavaClass NO_CLASS = new FakeClass();
68+
private static final JavaClass EMPTY_CLASS = new FakeClass();
6869

6970
private final Heap heap;
7071
private JavaClass selected;
@@ -112,7 +113,7 @@ protected HeapViewerNode[] computeData(RootNode root, Heap heap, String viewID,
112113
node.setChildren(HeapViewerNode.NO_NODES);
113114
return new HeapViewerNode[] { firstNode };
114115
}
115-
116+
116117
return new HeapViewerNode[] { new TextNode(Bundle.ClassHierarchyPlugin_NoSelection()) };
117118
}
118119
protected void childrenChanged() {
@@ -124,14 +125,15 @@ protected void childrenChanged() {
124125
}
125126
};
126127
}
127-
128+
128129
protected JComponent createComponent() {
129130
return objectsView.getComponent();
130131
}
131132

132133

133134
@Override
134135
protected void closed() {
136+
synchronized (objectsView) { selected = NO_CLASS; }
135137
objectsView.closed();
136138
}
137139

@@ -169,24 +171,25 @@ public boolean isLeaf() {
169171
}
170172

171173

172-
private static class EmptyJavaClass implements JavaClass {
173-
@Override public Object getValueOfStaticField(String name) { return null; }
174-
@Override public long getAllInstancesSize() { return -1; }
175-
@Override public boolean isArray() { return false; }
176-
@Override public Instance getClassLoader() { return null; }
177-
@Override public List getFields() { return null; }
178-
@Override public int getInstanceSize() { return -1; }
179-
@Override public List getInstances() { return null; }
180-
@Override public Iterator getInstancesIterator() { return null; }
181-
@Override public int getInstancesCount() { return -1; }
182-
@Override public long getRetainedSizeByClass() { return -1; }
183-
@Override public long getJavaClassId() { return -1; }
184-
@Override public String getName() { return null; }
185-
@Override public List getStaticFieldValues() { return null; }
186-
@Override public Collection getSubClasses() { return null; }
187-
@Override public JavaClass getSuperClass() { return null; }
188-
@Override public boolean equals(Object o) { return o == this; }
189-
@Override public int hashCode() { return -1; }
174+
private static class FakeClass implements JavaClass {
175+
@Override public Object getValueOfStaticField(String name) { throw new UnsupportedOperationException("Not supported."); } // NOI18N
176+
@Override public long getAllInstancesSize() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
177+
@Override public boolean isArray() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
178+
@Override public Instance getClassLoader() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
179+
@Override public List getFields() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
180+
@Override public int getInstanceSize() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
181+
@Override public List getInstances() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
182+
@Override public Iterator getInstancesIterator() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
183+
@Override public int getInstancesCount() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
184+
@Override public long getRetainedSizeByClass() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
185+
@Override public long getJavaClassId() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
186+
@Override public String getName() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
187+
@Override public List getStaticFieldValues() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
188+
@Override public Collection getSubClasses() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
189+
@Override public JavaClass getSuperClass() { throw new UnsupportedOperationException("Not supported."); } // NOI18N
190+
191+
@Override public boolean equals(Object o) { return o == this; }
192+
@Override public int hashCode() { return -1; }
190193
}
191194

192195

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -288,6 +288,7 @@ protected JComponent createComponent() {
288288

289289
@Override
290290
protected void closed() {
291+
synchronized (objectsView) { selected = objectsView.getRoot(); }
291292
objectsView.closed();
292293
}
293294

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -307,6 +307,7 @@ protected JComponent createComponent() {
307307

308308
@Override
309309
protected void closed() {
310+
synchronized (objectsView) { selected = objectsView.getRoot(); }
310311
objectsView.closed();
311312
}
312313

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -346,6 +346,7 @@ protected void nodeSelected(final HeapViewerNode node, boolean adjusting) {
346346

347347
@Override
348348
protected void closed() {
349+
synchronized (objectsView) { selected = objectsView.getRoot(); }
349350
objectsView.closed();
350351
}
351352

0 commit comments

Comments
 (0)