50
50
import org .graalvm .visualvm .heapviewer .ui .HeapViewerRendererWrapper ;
51
51
import org .graalvm .visualvm .heapviewer .ui .UIThresholds ;
52
52
import org .graalvm .visualvm .heapviewer .utils .ExcludingIterator ;
53
+ import org .graalvm .visualvm .heapviewer .utils .InterruptibleIterator ;
53
54
import org .graalvm .visualvm .heapviewer .utils .NodesComputer ;
54
55
import org .graalvm .visualvm .heapviewer .utils .ProgressIterator ;
55
56
import org .graalvm .visualvm .heapviewer .utils .counters .InstanceCounter ;
@@ -99,7 +100,7 @@ private HeapViewerNode createObjectNode(O object) {
99
100
}
100
101
101
102
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 {
103
104
final Set <FieldDescriptor > fields = getAllObjectsFields (objects , progress );
104
105
NodesComputer <FieldDescriptor > computer = new NodesComputer <FieldDescriptor >(fields .size (), UIThresholds .MAX_INSTANCE_FIELDS ) {
105
106
protected boolean sorts (DataType dataType ) {
@@ -126,28 +127,36 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
126
127
}
127
128
128
129
129
- private Set <FieldDescriptor > getAllObjectsFields (TruffleObjectsWrapper <O > objects , Progress progress ) {
130
+ private Set <FieldDescriptor > getAllObjectsFields (TruffleObjectsWrapper <O > objects , Progress progress ) throws InterruptedException {
130
131
boolean filtersProperties = filtersFields ();
131
132
132
- progress .setupKnownSteps (objects .getObjectsCount ());
133
-
134
133
Set <FieldDescriptor > allFields = new HashSet ();
135
134
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
+ }
145
154
}
146
155
}
156
+ } finally {
157
+ progress .finish ();
147
158
}
148
159
149
- progress .finish ();
150
-
151
160
return allFields ;
152
161
}
153
162
@@ -172,8 +181,6 @@ private FieldValue getValueOfField(O object, String name) {
172
181
173
182
private class MergedObjectFieldNode extends HeapViewerNode {
174
183
175
- private volatile boolean computingChildren ;
176
-
177
184
private final String fieldName ;
178
185
private final int fieldType ;
179
186
private int valuesCount = -1 ;
@@ -195,29 +202,29 @@ int getValuesCount() {
195
202
}
196
203
197
204
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 {
199
206
if (fieldType == 0 ) {
200
207
final InstanceCounter values = new InstanceCounter (objectsCount ());
201
208
202
209
progress .setupKnownSteps (objectsCount ());
210
+
211
+ Thread worker = Thread .currentThread ();
203
212
204
213
Iterator <O > objects = objectsIterator ();
205
214
try {
206
- computingChildren = true ;
207
- while (computingChildren && objects .hasNext ()) {
215
+ while (objects .hasNext ()) {
216
+ if (worker .isInterrupted ()) throw new InterruptedException ();
217
+
208
218
O o = objects .next ();
209
219
progress .step ();
210
220
FieldValue value = getValueOfField (o , fieldName );
211
221
if (value instanceof ObjectFieldValue )
212
222
values .count (((ObjectFieldValue )value ).getInstance ());
213
223
}
214
- if (!computingChildren ) return null ;
215
224
} finally {
216
- computingChildren = false ;
225
+ progress . finish () ;
217
226
}
218
227
219
- progress .finish ();
220
-
221
228
valuesCount = values .size ();
222
229
223
230
final TruffleLanguage language = getLanguage ();
@@ -267,11 +274,14 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
267
274
final Map <String , Integer > values = new HashMap ();
268
275
269
276
progress .setupKnownSteps (objectsCount ());
277
+
278
+ Thread worker = Thread .currentThread ();
270
279
271
280
Iterator <O > objects = objectsIterator ();
272
281
try {
273
- computingChildren = true ;
274
- while (computingChildren && objects .hasNext ()) {
282
+ while (objects .hasNext ()) {
283
+ if (worker .isInterrupted ()) throw new InterruptedException ();
284
+
275
285
O o = objects .next ();
276
286
progress .step ();
277
287
FieldValue value = getValueOfField (o , fieldName );
@@ -282,13 +292,10 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
282
292
values .put (val , ++count );
283
293
}
284
294
}
285
- if (!computingChildren ) return null ;
286
295
} finally {
287
- computingChildren = false ;
296
+ progress . finish () ;
288
297
}
289
298
290
- progress .finish ();
291
-
292
299
valuesCount = values .size ();
293
300
294
301
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) {
355
362
}
356
363
357
364
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 {
360
366
final String fieldName = fieldName ();
361
367
NodesComputer <O > computer = new NodesComputer <O >(valuesCount , 20 ) {
362
368
protected boolean sorts (DataType dataType ) {
@@ -368,7 +374,7 @@ protected HeapViewerNode createNode(O object) {
368
374
protected ProgressIterator <O > objectsIterator (int index , Progress progress ) {
369
375
final Instance _instance = HeapViewerNode .getValue (ObjectFieldValueNode .this .getNode (), DataType .INSTANCE , heap );
370
376
progress .setupUnknownSteps ();
371
- Iterator <O > fieldInstanceIterator = new ExcludingIterator <O >(TruffleObjectMergedFields .this .objectsIterator ()) {
377
+ Iterator <O > fieldInstanceIterator = new ExcludingIterator <O >(new InterruptibleIterator ( TruffleObjectMergedFields .this .objectsIterator () )) {
372
378
@ Override
373
379
protected boolean exclude (O object ) {
374
380
progress .step ();
@@ -436,8 +442,7 @@ protected Object getValue(DataType type, Heap heap) {
436
442
}
437
443
438
444
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 {
441
446
final String fieldName = fieldName ();
442
447
NodesComputer <O > computer = new NodesComputer <O >(valuesCount , 20 ) {
443
448
protected boolean sorts (DataType dataType ) {
@@ -448,7 +453,7 @@ protected HeapViewerNode createNode(O object) {
448
453
}
449
454
protected ProgressIterator <O > objectsIterator (int index , Progress progress ) {
450
455
progress .setupUnknownSteps ();
451
- Iterator <O > fieldInstanceIterator = new ExcludingIterator <O >(TruffleObjectMergedFields .this .objectsIterator ()) {
456
+ Iterator <O > fieldInstanceIterator = new ExcludingIterator <O >(new InterruptibleIterator ( TruffleObjectMergedFields .this .objectsIterator () )) {
452
457
@ Override
453
458
protected boolean exclude (O object ) {
454
459
progress .step ();
0 commit comments