35
35
import java .util .List ;
36
36
import javax .swing .JComponent ;
37
37
import javax .swing .SwingUtilities ;
38
+ import org .graalvm .visualvm .core .ui .components .NotSupportedDisplayer ;
39
+ import org .graalvm .visualvm .heapviewer .utils .HeapUtils ;
38
40
import org .netbeans .api .progress .ProgressHandle ;
39
41
import org .graalvm .visualvm .lib .jfluid .heap .Heap ;
40
42
import org .graalvm .visualvm .lib .jfluid .heap .HeapFactory ;
47
49
* @author Jiri Sedlacek
48
50
*/
49
51
@ 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)'
51
55
})
52
56
public final class HeapViewer {
53
57
@@ -56,7 +60,7 @@ public final class HeapViewer {
56
60
57
61
private final List <HeapFragment > heapFragments ;
58
62
59
- private HeapViewerComponent component ;
63
+ private JComponent component ;
60
64
61
65
62
66
public HeapViewer (File file ) throws IOException {
@@ -84,13 +88,18 @@ public List<HeapFragment> getFragments() {
84
88
85
89
86
90
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
+ }
88
96
return component ;
89
97
}
90
98
91
99
92
100
public void closed () {
93
- if (component != null ) component .closed ();
101
+ if (component instanceof HeapViewerComponent )
102
+ ((HeapViewerComponent )component ).closed ();
94
103
}
95
104
96
105
@@ -111,12 +120,18 @@ private static Heap createHeap(File heapFile) throws IOException {
111
120
heap .getSummary (); // Precompute HeapSummary within the progress
112
121
113
122
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 ;
114
127
} finally {
115
128
if (pHandle != null ) pHandle .finish ();
116
129
}
117
130
}
118
131
119
132
private static List <HeapFragment > computeHeapFragments (File heapDumpFile , Lookup .Provider heapDumpProject , Heap heap ) throws IOException {
133
+ if (heap == null ) return null ;
134
+
120
135
Collection <? extends HeapFragment .Provider > providers = Lookup .getDefault ().lookupAll (HeapFragment .Provider .class );
121
136
122
137
List <HeapFragment > fragments = new ArrayList (providers .size ());
0 commit comments