Skip to content

Commit bed803d

Browse files
committed
Update HeapViewer-Truffle to the new APIs, to be cleaned up yet
1 parent fbb0738 commit bed803d

15 files changed

+118
-102
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ protected final L getLanguage() {
106106

107107

108108
@Override
109-
public final HeapViewerNode[] getNodes(HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
109+
public final HeapViewerNode[] getNodes(HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
110110
Instance instance = HeapViewerNode.getValue(parent, DataType.INSTANCE, heap);
111111
return instance == null ? null : getNodes(instance, parent, heap, viewID, viewFilter, dataTypes, sortOrders, progress);
112112
}
113113

114-
final HeapViewerNode[] getNodes(Instance instance, HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
114+
final HeapViewerNode[] getNodes(Instance instance, HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
115115
Collection<I> itemsC = null;
116116

117117
if (!displaysProgress) {

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

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.graalvm.visualvm.heapviewer.ui.HeapViewerRendererWrapper;
5151
import org.graalvm.visualvm.heapviewer.ui.UIThresholds;
5252
import org.graalvm.visualvm.heapviewer.utils.ExcludingIterator;
53+
import org.graalvm.visualvm.heapviewer.utils.InterruptibleIterator;
5354
import org.graalvm.visualvm.heapviewer.utils.NodesComputer;
5455
import org.graalvm.visualvm.heapviewer.utils.ProgressIterator;
5556
import org.graalvm.visualvm.heapviewer.utils.counters.InstanceCounter;
@@ -99,7 +100,7 @@ private HeapViewerNode createObjectNode(O object) {
99100
}
100101

101102

102-
HeapViewerNode[] getNodes(HeapViewerNode parent, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
103+
HeapViewerNode[] getNodes(HeapViewerNode parent, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
103104
final Set<FieldDescriptor> fields = getAllObjectsFields(objects, progress);
104105
NodesComputer<FieldDescriptor> computer = new NodesComputer<FieldDescriptor>(fields.size(), UIThresholds.MAX_INSTANCE_FIELDS) {
105106
protected boolean sorts(DataType dataType) {
@@ -126,28 +127,36 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
126127
}
127128

128129

129-
private Set<FieldDescriptor> getAllObjectsFields(TruffleObjectsWrapper<O> objects, Progress progress) {
130+
private Set<FieldDescriptor> getAllObjectsFields(TruffleObjectsWrapper<O> objects, Progress progress) throws InterruptedException {
130131
boolean filtersProperties = filtersFields();
131132

132-
progress.setupKnownSteps(objects.getObjectsCount());
133-
134133
Set<FieldDescriptor> allFields = new HashSet();
135134
Iterator<O> objectsI = objects.getObjectsIterator();
136-
while (objectsI.hasNext()) {
137-
progress.step();
138-
Collection<FieldValue> fields = getFields(objectsI.next());
139-
if (fields != null) for (FieldValue field : fields) {
140-
if (!filtersProperties || includeField(field)) {
141-
Field f = field.getField();
142-
String fname = f.isStatic() ? "static " + f.getName() : f.getName(); // NOI18N
143-
int ftype = field instanceof ObjectFieldValue ? 0 : -1;
144-
allFields.add(new FieldDescriptor(fname, ftype));
135+
136+
Thread worker = Thread.currentThread();
137+
138+
progress.setupKnownSteps(objects.getObjectsCount());
139+
140+
try {
141+
while (objectsI.hasNext()) {
142+
if (worker.isInterrupted()) throw new InterruptedException();
143+
144+
progress.step();
145+
146+
Collection<FieldValue> fields = getFields(objectsI.next());
147+
if (fields != null) for (FieldValue field : fields) {
148+
if (!filtersProperties || includeField(field)) {
149+
Field f = field.getField();
150+
String fname = f.isStatic() ? "static " + f.getName() : f.getName(); // NOI18N
151+
int ftype = field instanceof ObjectFieldValue ? 0 : -1;
152+
allFields.add(new FieldDescriptor(fname, ftype));
153+
}
145154
}
146155
}
156+
} finally {
157+
progress.finish();
147158
}
148159

149-
progress.finish();
150-
151160
return allFields;
152161
}
153162

@@ -172,8 +181,6 @@ private FieldValue getValueOfField(O object, String name) {
172181

173182
private class MergedObjectFieldNode extends HeapViewerNode {
174183

175-
private volatile boolean computingChildren;
176-
177184
private final String fieldName;
178185
private final int fieldType;
179186
private int valuesCount = -1;
@@ -195,29 +202,29 @@ int getValuesCount() {
195202
}
196203

197204

198-
protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
205+
protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
199206
if (fieldType == 0) {
200207
final InstanceCounter values = new InstanceCounter(objectsCount());
201208

202209
progress.setupKnownSteps(objectsCount());
210+
211+
Thread worker = Thread.currentThread();
203212

204213
Iterator<O> objects = objectsIterator();
205214
try {
206-
computingChildren = true;
207-
while (computingChildren && objects.hasNext()) {
215+
while (objects.hasNext()) {
216+
if (worker.isInterrupted()) throw new InterruptedException();
217+
208218
O o = objects.next();
209219
progress.step();
210220
FieldValue value = getValueOfField(o, fieldName);
211221
if (value instanceof ObjectFieldValue)
212222
values.count(((ObjectFieldValue)value).getInstance());
213223
}
214-
if (!computingChildren) return null;
215224
} finally {
216-
computingChildren = false;
225+
progress.finish();
217226
}
218227

219-
progress.finish();
220-
221228
valuesCount = values.size();
222229

223230
final TruffleLanguage language = getLanguage();
@@ -267,11 +274,14 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
267274
final Map<String, Integer> values = new HashMap();
268275

269276
progress.setupKnownSteps(objectsCount());
277+
278+
Thread worker = Thread.currentThread();
270279

271280
Iterator<O> objects = objectsIterator();
272281
try {
273-
computingChildren = true;
274-
while (computingChildren && objects.hasNext()) {
282+
while (objects.hasNext()) {
283+
if (worker.isInterrupted()) throw new InterruptedException();
284+
275285
O o = objects.next();
276286
progress.step();
277287
FieldValue value = getValueOfField(o, fieldName);
@@ -282,13 +292,10 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
282292
values.put(val, ++count);
283293
}
284294
}
285-
if (!computingChildren) return null;
286295
} finally {
287-
computingChildren = false;
296+
progress.finish();
288297
}
289298

290-
progress.finish();
291-
292299
valuesCount = values.size();
293300

294301
NodesComputer<Map.Entry<String, Integer>> computer = new NodesComputer<Map.Entry<String, Integer>>(valuesCount, 20) {
@@ -355,8 +362,7 @@ protected Object getValue(DataType type, Heap heap) {
355362
}
356363

357364

358-
protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
359-
365+
protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
360366
final String fieldName = fieldName();
361367
NodesComputer<O> computer = new NodesComputer<O>(valuesCount, 20) {
362368
protected boolean sorts(DataType dataType) {
@@ -368,7 +374,7 @@ protected HeapViewerNode createNode(O object) {
368374
protected ProgressIterator<O> objectsIterator(int index, Progress progress) {
369375
final Instance _instance = HeapViewerNode.getValue(ObjectFieldValueNode.this.getNode(), DataType.INSTANCE, heap);
370376
progress.setupUnknownSteps();
371-
Iterator<O> fieldInstanceIterator = new ExcludingIterator<O>(TruffleObjectMergedFields.this.objectsIterator()) {
377+
Iterator<O> fieldInstanceIterator = new ExcludingIterator<O>(new InterruptibleIterator(TruffleObjectMergedFields.this.objectsIterator())) {
372378
@Override
373379
protected boolean exclude(O object) {
374380
progress.step();
@@ -436,8 +442,7 @@ protected Object getValue(DataType type, Heap heap) {
436442
}
437443

438444

439-
protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
440-
445+
protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
441446
final String fieldName = fieldName();
442447
NodesComputer<O> computer = new NodesComputer<O>(valuesCount, 20) {
443448
protected boolean sorts(DataType dataType) {
@@ -448,7 +453,7 @@ protected HeapViewerNode createNode(O object) {
448453
}
449454
protected ProgressIterator<O> objectsIterator(int index, Progress progress) {
450455
progress.setupUnknownSteps();
451-
Iterator<O> fieldInstanceIterator = new ExcludingIterator<O>(TruffleObjectMergedFields.this.objectsIterator()) {
456+
Iterator<O> fieldInstanceIterator = new ExcludingIterator<O>(new InterruptibleIterator(TruffleObjectMergedFields.this.objectsIterator())) {
452457
@Override
453458
protected boolean exclude(O object) {
454459
progress.step();

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.graalvm.visualvm.heapviewer.ui.HeapViewerRenderer;
4747
import org.graalvm.visualvm.heapviewer.ui.UIThresholds;
4848
import org.graalvm.visualvm.heapviewer.utils.ExcludingIterator;
49+
import org.graalvm.visualvm.heapviewer.utils.InterruptibleIterator;
4950
import org.graalvm.visualvm.heapviewer.utils.NodesComputer;
5051
import org.graalvm.visualvm.heapviewer.utils.ProgressIterator;
5152
import org.graalvm.visualvm.lib.jfluid.heap.FieldValue;
@@ -92,48 +93,43 @@ private HeapViewerNode createObjectNode(O object) {
9293
return (HeapViewerNode)getLanguage().createObjectNode(object, object.getType(heap));
9394
}
9495

95-
// TODO: set to false or replace by Thread.interrupt() when the TruffleObjectPropertyPlugin selection changes!
96-
private volatile boolean computingChildren;
97-
98-
protected HeapViewerNode[] getNodes(HeapViewerNode parent, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
96+
protected HeapViewerNode[] getNodes(HeapViewerNode parent, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
9997
boolean filtersReferences = filtersReferences();
10098

10199
final Map<Long, Integer> values = new HashMap();
102100
FieldValue refFV = null;
103101

104-
progress.setupKnownSteps(objectsCount());
102+
Thread worker = Thread.currentThread();
105103

106104
Iterator<O> objectsI = objectsIterator();
105+
106+
progress.setupKnownSteps(objectsCount());
107107
try {
108-
computingChildren = true;
109-
while (computingChildren && objectsI.hasNext()) {
108+
while (objectsI.hasNext()) {
109+
if (worker.isInterrupted()) throw new InterruptedException();
110+
110111
O object = objectsI.next();
111112
progress.step();
112113
Collection<FieldValue> references = getReferences(object);
113114
Set<Instance> referers = new HashSet();
114115
for (FieldValue reference : references) {
115-
if (!computingChildren) break;
116116
if (refFV == null) refFV = reference;
117117
if (!filtersReferences || includeReference(reference))
118118
referers.add(reference.getDefiningInstance());
119119
}
120120
for (Instance referer : referers) {
121-
if (!computingChildren) break;
122121
long refererID = referer.getInstanceId();
123122
Integer count = values.get(refererID);
124123
if (count == null) count = 0;
125124
values.put(refererID, ++count);
126125
}
127126
}
128-
if (!computingChildren) return null;
129127
} catch (OutOfMemoryError e) {
130128
return new HeapViewerNode[] { new TextNode(Bundle.TruffleObjectPropertyProvider_OOMEWarning()) };
131129
} finally {
132-
computingChildren = false;
130+
progress.finish();
133131
}
134132

135-
progress.finish();
136-
137133
final TruffleLanguage language = getLanguage();
138134
final FieldValue refFVF = refFV;
139135

@@ -195,7 +191,7 @@ private abstract class MergedObjectReferenceNode extends HeapViewerNodeWrapper {
195191
public abstract int getCount();
196192

197193

198-
protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
194+
protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
199195
NodesComputer<O> computer = new NodesComputer<O>(getCount(), 20) {
200196
protected boolean sorts(DataType dataType) {
201197
return !DataType.COUNT.equals(dataType);
@@ -207,7 +203,7 @@ protected HeapViewerNode createNode(O object) {
207203
protected ProgressIterator<O> objectsIterator(int index, Progress _progress) {
208204
final Instance referer = getInstance();
209205
progress.setupUnknownSteps();
210-
Iterator<O> referencesIt = new ExcludingIterator<O>(TruffleObjectMergedReferences.this.objectsIterator()) {
206+
Iterator<O> referencesIt = new ExcludingIterator<O>(new InterruptibleIterator(TruffleObjectMergedReferences.this.objectsIterator())) {
211207
@Override
212208
protected boolean exclude(O object) {
213209
progress.step();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public TruffleObjectPropertyPlugin(String name, String description, Icon icon, S
100100
new TreeTableViewColumn.ObjectID(heap)
101101
};
102102
objectsView = new TreeTableView(viewID, context, actions, columns) {
103-
protected HeapViewerNode[] computeData(RootNode root, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
103+
protected HeapViewerNode[] computeData(RootNode root, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
104104
HeapViewerNode _selected;
105105
synchronized (objectsView) { _selected = selected; }
106106

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ protected final L getLanguage() {
128128

129129

130130
@Override
131-
public final HeapViewerNode[] getNodes(HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
131+
public final HeapViewerNode[] getNodes(HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
132132
O object = getObject(parent, heap);
133133
return object == null ? null : getNodes(object, parent, heap, viewID, viewFilter, dataTypes, sortOrders, progress);
134134
}
135135

136-
final HeapViewerNode[] getNodes(O object, HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
136+
final HeapViewerNode[] getNodes(O object, HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
137137
Collection<I> itemsC = null;
138138

139139
if (!displaysProgress) {
@@ -176,7 +176,7 @@ protected ProgressIterator<Integer> objectsIterator(int index, Progress progress
176176
return computer.computeNodes(parent, heap, viewID, null, dataTypes, sortOrders, progress);
177177
}
178178

179-
protected HeapViewerNode[] getNodes(TruffleObjectsWrapper<O> objects, HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
179+
protected HeapViewerNode[] getNodes(TruffleObjectsWrapper<O> objects, HeapViewerNode parent, Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
180180
return null;
181181
}
182182

@@ -254,7 +254,7 @@ protected HeapViewerNode createForeignFieldNode(Instance instance, FieldValue fi
254254
}
255255

256256
@Override
257-
protected HeapViewerNode[] getNodes(TruffleObjectsWrapper<O> objects, HeapViewerNode parent, final Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
257+
protected HeapViewerNode[] getNodes(TruffleObjectsWrapper<O> objects, HeapViewerNode parent, final Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
258258
if (!supportsAggregation()) return null;
259259

260260
return new TruffleObjectMergedFields<O>(objects, heap) {
@@ -322,7 +322,7 @@ protected HeapViewerNode createForeignReferenceNode(Instance instance, FieldValu
322322

323323

324324
@Override
325-
protected HeapViewerNode[] getNodes(final TruffleObjectsWrapper<O> objects, HeapViewerNode parent, final Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) {
325+
protected HeapViewerNode[] getNodes(final TruffleObjectsWrapper<O> objects, HeapViewerNode parent, final Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
326326
if (!supportsAggregation()) return null;
327327

328328
return new TruffleObjectMergedReferences<O>(objects, heap) {

0 commit comments

Comments
 (0)