Skip to content

Commit c57fbd7

Browse files
committed
Handle OOME when loading heap dump, handle no supported content.
1 parent 1d0f41a commit c57fbd7

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/HeapViewer.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import java.util.List;
3636
import javax.swing.JComponent;
3737
import javax.swing.SwingUtilities;
38+
import org.graalvm.visualvm.core.ui.components.NotSupportedDisplayer;
39+
import org.graalvm.visualvm.heapviewer.utils.HeapUtils;
3840
import org.netbeans.api.progress.ProgressHandle;
3941
import org.graalvm.visualvm.lib.jfluid.heap.Heap;
4042
import org.graalvm.visualvm.lib.jfluid.heap.HeapFactory;
@@ -47,7 +49,9 @@
4749
* @author Jiri Sedlacek
4850
*/
4951
@NbBundle.Messages({
50-
"HeapViewer_LoadingDumpMsg=Loading Heap Dump..."
52+
"HeapViewer_LoadingDumpMsg=Loading Heap Dump...",
53+
"HeapViewer_HeapDumpEmpty=heap dump (no content)", // Displays 'Not supported for this heap dump (no content)'
54+
"HeapViewer_HeapDumpOOME=heap dump (not enough memory)" // Displays 'Not supported for this heap dump (not enough memory)'
5155
})
5256
public final class HeapViewer {
5357

@@ -56,7 +60,7 @@ public final class HeapViewer {
5660

5761
private final List<HeapFragment> heapFragments;
5862

59-
private HeapViewerComponent component;
63+
private JComponent component;
6064

6165

6266
public HeapViewer(File file) throws IOException {
@@ -84,13 +88,18 @@ public List<HeapFragment> getFragments() {
8488

8589

8690
public JComponent getComponent() {
87-
if (component == null) component = new HeapViewerComponent(this);
91+
if (component == null) {
92+
if (heapFragments == null) component = new NotSupportedDisplayer(Bundle.HeapViewer_HeapDumpOOME());
93+
else if (heapFragments.isEmpty()) component = new NotSupportedDisplayer(Bundle.HeapViewer_HeapDumpEmpty());
94+
else component = new HeapViewerComponent(this);
95+
}
8896
return component;
8997
}
9098

9199

92100
public void closed() {
93-
if (component != null) component.closed();
101+
if (component instanceof HeapViewerComponent)
102+
((HeapViewerComponent)component).closed();
94103
}
95104

96105

@@ -111,12 +120,18 @@ private static Heap createHeap(File heapFile) throws IOException {
111120
heap.getSummary(); // Precompute HeapSummary within the progress
112121

113122
return heap;
123+
} catch (OutOfMemoryError e) {
124+
System.err.println("Out of memory in HeapViewer.createHeap: " + e.getMessage()); // NOI18N
125+
HeapUtils.handleOOME(e);
126+
return null;
114127
} finally {
115128
if (pHandle != null) pHandle.finish();
116129
}
117130
}
118131

119132
private static List<HeapFragment> computeHeapFragments(File heapDumpFile, Lookup.Provider heapDumpProject, Heap heap) throws IOException {
133+
if (heap == null) return null;
134+
120135
Collection<? extends HeapFragment.Provider> providers = Lookup.getDefault().lookupAll(HeapFragment.Provider.class);
121136

122137
List<HeapFragment> fragments = new ArrayList(providers.size());

0 commit comments

Comments
 (0)