Skip to content

Commit 9cbda49

Browse files
committed
Worker threads interruption cleanup
1 parent bed803d commit 9cbda49

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ abstract class TruffleObjectMergedFields<O extends TruffleObject> {
9393

9494

9595
private int objectsCount() { return objects.getObjectsCount(); }
96-
private Iterator<O> objectsIterator() { return objects.getObjectsIterator(); }
96+
private Iterator<O> objectsIterator() { return new InterruptibleIterator(objects.getObjectsIterator()); }
9797

9898
private HeapViewerNode createObjectNode(O object) {
9999
return (HeapViewerNode)getLanguage().createObjectNode(object, object.getType(heap));
100100
}
101101

102102

103103
HeapViewerNode[] getNodes(HeapViewerNode parent, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
104-
final Set<FieldDescriptor> fields = getAllObjectsFields(objects, progress);
104+
final Set<FieldDescriptor> fields = getAllObjectsFields(progress);
105105
NodesComputer<FieldDescriptor> computer = new NodesComputer<FieldDescriptor>(fields.size(), UIThresholds.MAX_INSTANCE_FIELDS) {
106106
protected boolean sorts(DataType dataType) {
107107
return true;
@@ -127,20 +127,16 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
127127
}
128128

129129

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

133133
Set<FieldDescriptor> allFields = new HashSet();
134-
Iterator<O> objectsI = objects.getObjectsIterator();
135-
136-
Thread worker = Thread.currentThread();
134+
Iterator<O> objectsI = objectsIterator();
137135

138136
progress.setupKnownSteps(objects.getObjectsCount());
139137

140138
try {
141139
while (objectsI.hasNext()) {
142-
if (worker.isInterrupted()) throw new InterruptedException();
143-
144140
progress.step();
145141

146142
Collection<FieldValue> fields = getFields(objectsI.next());
@@ -153,6 +149,7 @@ private Set<FieldDescriptor> getAllObjectsFields(TruffleObjectsWrapper<O> object
153149
}
154150
}
155151
}
152+
if (Thread.currentThread().isInterrupted()) throw new InterruptedException();
156153
} finally {
157154
progress.finish();
158155
}
@@ -208,19 +205,16 @@ protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapV
208205

209206
progress.setupKnownSteps(objectsCount());
210207

211-
Thread worker = Thread.currentThread();
212-
213208
Iterator<O> objects = objectsIterator();
214209
try {
215210
while (objects.hasNext()) {
216-
if (worker.isInterrupted()) throw new InterruptedException();
217-
218211
O o = objects.next();
219212
progress.step();
220213
FieldValue value = getValueOfField(o, fieldName);
221214
if (value instanceof ObjectFieldValue)
222215
values.count(((ObjectFieldValue)value).getInstance());
223216
}
217+
if (Thread.currentThread().isInterrupted()) throw new InterruptedException();
224218
} finally {
225219
progress.finish();
226220
}
@@ -275,13 +269,9 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
275269

276270
progress.setupKnownSteps(objectsCount());
277271

278-
Thread worker = Thread.currentThread();
279-
280272
Iterator<O> objects = objectsIterator();
281273
try {
282274
while (objects.hasNext()) {
283-
if (worker.isInterrupted()) throw new InterruptedException();
284-
285275
O o = objects.next();
286276
progress.step();
287277
FieldValue value = getValueOfField(o, fieldName);
@@ -292,6 +282,7 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
292282
values.put(val, ++count);
293283
}
294284
}
285+
if (Thread.currentThread().isInterrupted()) throw new InterruptedException();
295286
} finally {
296287
progress.finish();
297288
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ abstract class TruffleObjectMergedReferences<O extends TruffleObject> {
8787

8888

8989
private int objectsCount() { return objects.getObjectsCount(); }
90-
private Iterator<O> objectsIterator() { return objects.getObjectsIterator(); }
90+
private Iterator<O> objectsIterator() { return new InterruptibleIterator(objects.getObjectsIterator()); }
9191

9292
private HeapViewerNode createObjectNode(O object) {
9393
return (HeapViewerNode)getLanguage().createObjectNode(object, object.getType(heap));
@@ -99,15 +99,11 @@ protected HeapViewerNode[] getNodes(HeapViewerNode parent, String viewID, HeapVi
9999
final Map<Long, Integer> values = new HashMap();
100100
FieldValue refFV = null;
101101

102-
Thread worker = Thread.currentThread();
103-
104102
Iterator<O> objectsI = objectsIterator();
105103

106104
progress.setupKnownSteps(objectsCount());
107105
try {
108106
while (objectsI.hasNext()) {
109-
if (worker.isInterrupted()) throw new InterruptedException();
110-
111107
O object = objectsI.next();
112108
progress.step();
113109
Collection<FieldValue> references = getReferences(object);
@@ -124,6 +120,7 @@ protected HeapViewerNode[] getNodes(HeapViewerNode parent, String viewID, HeapVi
124120
values.put(refererID, ++count);
125121
}
126122
}
123+
if (Thread.currentThread().isInterrupted()) throw new InterruptedException();
127124
} catch (OutOfMemoryError e) {
128125
return new HeapViewerNode[] { new TextNode(Bundle.TruffleObjectPropertyProvider_OOMEWarning()) };
129126
} finally {

0 commit comments

Comments
 (0)