|
51 | 51 | import org.graalvm.visualvm.heapviewer.java.InstancesWrapper;
|
52 | 52 | import org.graalvm.visualvm.heapviewer.java.JavaHeapFragment;
|
53 | 53 | import org.graalvm.visualvm.heapviewer.model.DataType;
|
| 54 | +import org.graalvm.visualvm.heapviewer.model.ErrorNode; |
54 | 55 | import org.graalvm.visualvm.heapviewer.model.HeapViewerNode;
|
55 | 56 | import org.graalvm.visualvm.heapviewer.model.HeapViewerNodeFilter;
|
56 | 57 | import org.graalvm.visualvm.heapviewer.model.Progress;
|
|
63 | 64 | import org.graalvm.visualvm.heapviewer.ui.TreeTableViewColumn;
|
64 | 65 | import org.graalvm.visualvm.heapviewer.ui.UIThresholds;
|
65 | 66 | import org.graalvm.visualvm.heapviewer.utils.ExcludingIterator;
|
| 67 | +import org.graalvm.visualvm.heapviewer.utils.HeapUtils; |
66 | 68 | import org.graalvm.visualvm.heapviewer.utils.InterruptibleIterator;
|
67 | 69 | import org.graalvm.visualvm.heapviewer.utils.NodesComputer;
|
68 | 70 | import org.graalvm.visualvm.heapviewer.utils.ProgressIterator;
|
|
98 | 100 | "JavaFieldsPlugin_MenuStaticFields=Static Fields",
|
99 | 101 | "JavaFieldsPlugin_MenuFieldsHisto=Fields Histogram",
|
100 | 102 | "JavaFieldsPlugin_ValuesCountHint=({0} values)",
|
101 |
| - "JavaFieldsPlugin_OOMEWarning=<too many instances - increase heap size!>", |
102 | 103 | "JavaFieldsPlugin_FieldHistogramNodesContainer=<values {0}-{1}>"
|
103 | 104 | })
|
104 | 105 | class JavaFieldsPlugin extends HeapViewPlugin {
|
@@ -355,62 +356,60 @@ private String getName() {
|
355 | 356 | abstract InterruptibleIterator<Instance> instancesIterator();
|
356 | 357 |
|
357 | 358 | protected HeapViewerNode[] lazilyComputeChildren(Heap heap, String viewID, HeapViewerNodeFilter viewFilter, List<DataType> dataTypes, List<SortOrder> sortOrders, Progress progress) throws InterruptedException {
|
358 |
| - String fieldTypeName = fieldType.getName(); |
359 |
| - |
360 |
| - if ("object".equals(fieldTypeName)) { // NOI18N |
361 |
| - final InstanceCounter values = new InstanceCounter(instancesCount()); |
362 |
| - |
363 |
| - progress.setupKnownSteps(instancesCount()); |
364 |
| - |
365 |
| - Iterator<Instance> instances = instancesIterator(); |
366 |
| - try { |
367 |
| - while (instances.hasNext()) { |
368 |
| - Instance instance = instances.next(); |
369 |
| - progress.step(); |
370 |
| - FieldValue value = getValueOfField(instance, fieldName); |
371 |
| - if (value instanceof ObjectFieldValue) |
372 |
| - values.count(((ObjectFieldValue)value).getInstance()); |
373 |
| - } |
374 |
| - if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); |
375 |
| - } finally { |
376 |
| - progress.finish(); |
377 |
| - } |
378 |
| - |
379 |
| - valuesCount = values.size(); |
380 |
| - |
381 |
| - NodesComputer<InstanceCounter.Record> computer = new NodesComputer<InstanceCounter.Record>(valuesCount, UIThresholds.MAX_MERGED_OBJECTS) { |
382 |
| - protected boolean sorts(DataType dataType) { |
383 |
| - return true; |
384 |
| - } |
385 |
| - protected HeapViewerNode createNode(InstanceCounter.Record object) { |
386 |
| - return new InstanceFieldValueNode(object.getInstance(heap), object.getCount()) { |
387 |
| - @Override |
388 |
| - String fieldName() { return fieldName; } |
389 |
| - @Override |
390 |
| - InterruptibleIterator<Instance> instancesIterator() { return FieldHistogramNode.this.instancesIterator(); } |
391 |
| - }; |
392 |
| - } |
393 |
| - protected ProgressIterator<InstanceCounter.Record> objectsIterator(int index, Progress progress) { |
394 |
| - Iterator<InstanceCounter.Record> iterator = values.iterator(); |
395 |
| - return new ProgressIterator(iterator, index, true, progress); |
396 |
| - } |
397 |
| - protected String getMoreNodesString(String moreNodesCount) { |
398 |
| - return Bundle.JavaFieldsPlugin_FieldHistogramMoreNodes(moreNodesCount); |
399 |
| - } |
400 |
| - protected String getSamplesContainerString(String objectsCount) { |
401 |
| - return Bundle.JavaFieldsPlugin_FieldHistogramSamplesContainer(objectsCount); |
402 |
| - } |
403 |
| - protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx) { |
404 |
| - return Bundle.JavaFieldsPlugin_FieldHistogramNodesContainer(firstNodeIdx, lastNodeIdx); |
405 |
| - } |
406 |
| - }; |
407 |
| - |
408 |
| - return computer.computeNodes(FieldHistogramNode.this, heap, viewID, null, dataTypes, sortOrders, progress); |
409 |
| - } else { |
| 359 | + try { |
410 | 360 | int instancesCount = instancesCount();
|
411 |
| - |
412 |
| - try { |
413 |
| - |
| 361 | + String fieldTypeName = fieldType.getName(); |
| 362 | + |
| 363 | + if ("object".equals(fieldTypeName)) { // NOI18N |
| 364 | + final InstanceCounter values = new InstanceCounter(instancesCount); |
| 365 | + |
| 366 | + progress.setupKnownSteps(instancesCount); |
| 367 | + |
| 368 | + Iterator<Instance> instances = instancesIterator(); |
| 369 | + try { |
| 370 | + while (instances.hasNext()) { |
| 371 | + Instance instance = instances.next(); |
| 372 | + progress.step(); |
| 373 | + FieldValue value = getValueOfField(instance, fieldName); |
| 374 | + if (value instanceof ObjectFieldValue) |
| 375 | + values.count(((ObjectFieldValue)value).getInstance()); |
| 376 | + } |
| 377 | + if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); |
| 378 | + } finally { |
| 379 | + progress.finish(); |
| 380 | + } |
| 381 | + |
| 382 | + valuesCount = values.size(); |
| 383 | + |
| 384 | + NodesComputer<InstanceCounter.Record> computer = new NodesComputer<InstanceCounter.Record>(valuesCount, UIThresholds.MAX_MERGED_OBJECTS) { |
| 385 | + protected boolean sorts(DataType dataType) { |
| 386 | + return true; |
| 387 | + } |
| 388 | + protected HeapViewerNode createNode(InstanceCounter.Record object) { |
| 389 | + return new InstanceFieldValueNode(object.getInstance(heap), object.getCount()) { |
| 390 | + @Override |
| 391 | + String fieldName() { return fieldName; } |
| 392 | + @Override |
| 393 | + InterruptibleIterator<Instance> instancesIterator() { return FieldHistogramNode.this.instancesIterator(); } |
| 394 | + }; |
| 395 | + } |
| 396 | + protected ProgressIterator<InstanceCounter.Record> objectsIterator(int index, Progress progress) { |
| 397 | + Iterator<InstanceCounter.Record> iterator = values.iterator(); |
| 398 | + return new ProgressIterator(iterator, index, true, progress); |
| 399 | + } |
| 400 | + protected String getMoreNodesString(String moreNodesCount) { |
| 401 | + return Bundle.JavaFieldsPlugin_FieldHistogramMoreNodes(moreNodesCount); |
| 402 | + } |
| 403 | + protected String getSamplesContainerString(String objectsCount) { |
| 404 | + return Bundle.JavaFieldsPlugin_FieldHistogramSamplesContainer(objectsCount); |
| 405 | + } |
| 406 | + protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx) { |
| 407 | + return Bundle.JavaFieldsPlugin_FieldHistogramNodesContainer(firstNodeIdx, lastNodeIdx); |
| 408 | + } |
| 409 | + }; |
| 410 | + |
| 411 | + return computer.computeNodes(FieldHistogramNode.this, heap, viewID, null, dataTypes, sortOrders, progress); |
| 412 | + } else { |
414 | 413 | final PrimitiveCounter counter = PrimitiveCounter.create(fieldTypeName, instancesCount);
|
415 | 414 |
|
416 | 415 | progress.setupKnownSteps(instancesCount);
|
@@ -458,12 +457,11 @@ protected String getNodesContainerString(String firstNodeIdx, String lastNodeIdx
|
458 | 457 | };
|
459 | 458 |
|
460 | 459 | return computer.computeNodes(FieldHistogramNode.this, heap, viewID, null, dataTypes, sortOrders, progress);
|
461 |
| - |
462 |
| - } catch (OutOfMemoryError e) { |
463 |
| - |
464 |
| - return new HeapViewerNode[] { new TextNode(Bundle.JavaFieldsPlugin_OOMEWarning()) }; |
465 |
| - |
466 | 460 | }
|
| 461 | + } catch (OutOfMemoryError e) { |
| 462 | + System.err.println("Out of memory in JavaFieldsPlugin: " + e.getMessage()); // NOI18N |
| 463 | + HeapUtils.handleOOME(e); |
| 464 | + return new HeapViewerNode[] { new ErrorNode.OOME() }; |
467 | 465 | }
|
468 | 466 |
|
469 | 467 | }
|
|
0 commit comments