25
25
26
26
package com .sun .tools .visualvm .sampler .memory ;
27
27
28
+ import com .sun .tools .visualvm .application .Application ;
28
29
import com .sun .tools .visualvm .application .jvm .HeapHistogram ;
29
30
import com .sun .tools .visualvm .application .jvm .Jvm ;
30
31
import com .sun .tools .visualvm .core .options .GlobalPreferences ;
54
55
*/
55
56
public abstract class MemorySamplerSupport extends AbstractSamplerSupport {
56
57
58
+ private final Application application ;
59
+
57
60
private final Jvm jvm ;
58
61
private final MemoryMXBean memoryBean ;
59
62
private final ThreadsMemory threadsMemory ;
@@ -77,7 +80,9 @@ public abstract class MemorySamplerSupport extends AbstractSamplerSupport {
77
80
78
81
private DataViewComponent .DetailsView [] detailsViews ;
79
82
80
- public MemorySamplerSupport (Jvm jvm , boolean hasPermGen , ThreadsMemory mem , MemoryMXBean memoryBean , SnapshotDumper snapshotDumper , HeapDumper heapDumper ) {
83
+ public MemorySamplerSupport (Application application , Jvm jvm , boolean hasPermGen , ThreadsMemory mem , MemoryMXBean memoryBean , SnapshotDumper snapshotDumper , HeapDumper heapDumper ) {
84
+ this .application = application ;
85
+
81
86
this .jvm = jvm ;
82
87
hasPermGenHisto = hasPermGen ;
83
88
threadsMemory = mem ;
@@ -94,12 +99,22 @@ public DataViewComponent.DetailsView[] getDetailsView() {
94
99
}
95
100
heapView .initSession ();
96
101
if (permgenView != null ) permgenView .initSession ();
102
+ if (threadAllocView != null ) threadAllocView .initSession ();
97
103
return detailsViews .clone ();
98
104
}
99
105
100
106
public boolean startSampling (ProfilingSettings settings , int samplingRate , int refreshRate ) {
101
107
// heapTimer.start();
102
108
// permgenTimer.start();
109
+
110
+ SwingUtilities .invokeLater (new Runnable () {
111
+ public void run () {
112
+ if (heapView != null ) heapView .starting ();
113
+ if (permgenView != null ) permgenView .starting ();
114
+ if (threadAllocView != null ) threadAllocView .starting ();
115
+ }
116
+ });
117
+
103
118
heapRefresher .setRefreshRate (samplingRate );
104
119
if (permgenRefresher != null )
105
120
permgenRefresher .setRefreshRate (samplingRate );
@@ -113,6 +128,14 @@ public boolean startSampling(ProfilingSettings settings, int samplingRate, int r
113
128
}
114
129
115
130
public synchronized void stopSampling () {
131
+ SwingUtilities .invokeLater (new Runnable () {
132
+ public void run () {
133
+ if (heapView != null ) heapView .stopping ();
134
+ if (permgenView != null ) permgenView .stopping ();
135
+ if (threadAllocView != null ) threadAllocView .stopping ();
136
+ }
137
+ });
138
+
116
139
heapTimer .stop ();
117
140
if (permgenTimer != null ) {
118
141
permgenTimer .stop ();
@@ -126,8 +149,13 @@ public synchronized void stopSampling() {
126
149
}
127
150
128
151
public synchronized void terminate () {
129
- if (heapView != null ) heapView .terminate ();
130
- if (permgenView != null ) permgenView .terminate ();
152
+ SwingUtilities .invokeLater (new Runnable () {
153
+ public void run () {
154
+ if (heapView != null ) heapView .terminated ();
155
+ if (permgenView != null ) permgenView .terminated ();
156
+ if (threadAllocView != null ) threadAllocView .terminated ();
157
+ }
158
+ });
131
159
}
132
160
133
161
@@ -224,12 +252,12 @@ private DataViewComponent.DetailsView[] createViews() {
224
252
if (threadAllocRefresher != null ) detailsCount ++;
225
253
DataViewComponent .DetailsView [] details = new DataViewComponent .DetailsView [detailsCount ];
226
254
227
- heapView = new MemoryView (heapRefresher , MemoryView .MODE_HEAP , memoryBean , snapshotDumper , heapDumper );
255
+ heapView = new MemoryView (application , heapRefresher , MemoryView .MODE_HEAP , memoryBean , snapshotDumper , heapDumper );
228
256
details [detailIndex ++] = new DataViewComponent .DetailsView (
229
257
NbBundle .getMessage (MemorySamplerSupport .class , "LBL_Heap_histogram" ), // NOI18N
230
258
null , 10 , heapView , null );
231
259
if (hasPermGenHisto ) {
232
- permgenView = new MemoryView (permgenRefresher , MemoryView .MODE_PERMGEN , memoryBean , null , heapDumper );
260
+ permgenView = new MemoryView (application , permgenRefresher , MemoryView .MODE_PERMGEN , memoryBean , null , heapDumper );
233
261
details [detailIndex ++] = new DataViewComponent .DetailsView (
234
262
NbBundle .getMessage (MemorySamplerSupport .class , "LBL_PermGen_histogram" ), // NOI18N
235
263
null , 20 , permgenView , null );
0 commit comments