Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.jconsole/share/classes/sun/tools/jconsole/SummaryTab.java
40948 views
1
/*
2
* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.tools.jconsole;
27
28
import java.awt.*;
29
import java.io.*;
30
import java.lang.management.*;
31
import java.lang.reflect.*;
32
import java.text.*;
33
import java.util.*;
34
import java.util.concurrent.*;
35
import java.util.function.LongSupplier;
36
37
import javax.swing.*;
38
39
40
import static sun.tools.jconsole.Formatter.*;
41
import static sun.tools.jconsole.Utilities.*;
42
43
@SuppressWarnings("serial")
44
class SummaryTab extends Tab {
45
private static final String cpuUsageKey = "cpu";
46
47
private static final String newDivider = "<tr><td colspan=4><font size =-1><hr>";
48
private static final String newTable = "<tr><td colspan=4 align=left><table cellpadding=1>";
49
private static final String newLeftTable = "<tr><td colspan=2 align=left><table cellpadding=1>";
50
private static final String newRightTable = "<td colspan=2 align=left><table cellpadding=1>";
51
private static final String endTable = "</table>";
52
53
private static final int CPU_DECIMALS = 1;
54
55
private CPUOverviewPanel overviewPanel;
56
private DateFormat headerDateTimeFormat;
57
private String pathSeparator = null;
58
HTMLPane info;
59
60
private static class Result {
61
long upTime = -1L;
62
long processCpuTime = -1L;
63
long timeStamp;
64
int nCPUs;
65
String summary;
66
}
67
68
public static String getTabName() {
69
return Messages.SUMMARY_TAB_TAB_NAME;
70
}
71
72
public SummaryTab(VMPanel vmPanel) {
73
super(vmPanel, getTabName());
74
75
setLayout(new BorderLayout());
76
77
info = new HTMLPane();
78
setAccessibleName(info, getTabName());
79
add(new JScrollPane(info));
80
81
headerDateTimeFormat =
82
Formatter.getDateTimeFormat(Messages.SUMMARY_TAB_HEADER_DATE_TIME_FORMAT);
83
}
84
85
public SwingWorker<?, ?> newSwingWorker() {
86
return new SwingWorker<Result, Object>() {
87
public Result doInBackground() {
88
return formatSummary();
89
}
90
91
92
protected void done() {
93
try {
94
Result result = get();
95
if (result != null) {
96
info.setText(result.summary);
97
if (overviewPanel != null &&
98
result.upTime > 0L &&
99
result.processCpuTime >= 0L) {
100
101
overviewPanel.updateCPUInfo(result);
102
}
103
}
104
} catch (InterruptedException ex) {
105
} catch (ExecutionException ex) {
106
if (JConsole.isDebug()) {
107
ex.printStackTrace();
108
}
109
}
110
}
111
};
112
}
113
114
StringBuilder buf;
115
116
synchronized Result formatSummary() {
117
Result result = new Result();
118
ProxyClient proxyClient = vmPanel.getProxyClient();
119
if (proxyClient.isDead()) {
120
return null;
121
}
122
123
buf = new StringBuilder();
124
append("<table cellpadding=1>");
125
126
try {
127
RuntimeMXBean rmBean = proxyClient.getRuntimeMXBean();
128
CompilationMXBean cmpMBean = proxyClient.getCompilationMXBean();
129
ThreadMXBean tmBean = proxyClient.getThreadMXBean();
130
MemoryMXBean memoryBean = proxyClient.getMemoryMXBean();
131
ClassLoadingMXBean clMBean = proxyClient.getClassLoadingMXBean();
132
OperatingSystemMXBean osMBean = proxyClient.getOperatingSystemMXBean();
133
com.sun.management.OperatingSystemMXBean sunOSMBean =
134
proxyClient.getSunOperatingSystemMXBean();
135
136
append("<tr><td colspan=4>");
137
append("<center><b>" + Messages.SUMMARY_TAB_TAB_NAME + "</b></center>");
138
String dateTime =
139
headerDateTimeFormat.format(System.currentTimeMillis());
140
append("<center>" + dateTime + "</center>");
141
142
append(newDivider);
143
144
{ // VM info
145
append(newLeftTable);
146
append(Messages.CONNECTION_NAME, vmPanel.getDisplayName());
147
append(Messages.VIRTUAL_MACHINE,
148
Resources.format(Messages.SUMMARY_TAB_VM_VERSION,
149
rmBean.getVmName(), rmBean.getVmVersion()));
150
append(Messages.VENDOR, rmBean.getVmVendor());
151
append(Messages.NAME, rmBean.getName());
152
append(endTable);
153
154
append(newRightTable);
155
result.upTime = rmBean.getUptime();
156
append(Messages.UPTIME, formatTime(result.upTime));
157
if (sunOSMBean != null) {
158
result.processCpuTime = sunOSMBean.getProcessCpuTime();
159
append(Messages.PROCESS_CPU_TIME, formatNanoTime(result.processCpuTime));
160
}
161
162
if (cmpMBean != null) {
163
append(Messages.JIT_COMPILER, cmpMBean.getName());
164
append(Messages.TOTAL_COMPILE_TIME,
165
cmpMBean.isCompilationTimeMonitoringSupported()
166
? formatTime(cmpMBean.getTotalCompilationTime())
167
: Messages.UNAVAILABLE);
168
} else {
169
append(Messages.JIT_COMPILER, Messages.UNAVAILABLE);
170
}
171
append(endTable);
172
}
173
174
append(newDivider);
175
176
{ // Threads and Classes
177
append(newLeftTable);
178
int tlCount = tmBean.getThreadCount();
179
int tdCount = tmBean.getDaemonThreadCount();
180
int tpCount = tmBean.getPeakThreadCount();
181
long ttCount = tmBean.getTotalStartedThreadCount();
182
String[] strings1 = formatLongs(tlCount, tpCount,
183
tdCount, ttCount);
184
append(Messages.LIVE_THREADS, strings1[0]);
185
append(Messages.PEAK, strings1[1]);
186
append(Messages.DAEMON_THREADS, strings1[2]);
187
append(Messages.TOTAL_THREADS_STARTED, strings1[3]);
188
append(endTable);
189
190
append(newRightTable);
191
long clCount = clMBean.getLoadedClassCount();
192
long cuCount = clMBean.getUnloadedClassCount();
193
long ctCount = clMBean.getTotalLoadedClassCount();
194
String[] strings2 = formatLongs(clCount, cuCount, ctCount);
195
append(Messages.CURRENT_CLASSES_LOADED, strings2[0]);
196
append(Messages.TOTAL_CLASSES_LOADED, strings2[2]);
197
append(Messages.TOTAL_CLASSES_UNLOADED, strings2[1]);
198
append(null, "");
199
append(endTable);
200
}
201
202
append(newDivider);
203
204
{ // Memory
205
MemoryUsage u = memoryBean.getHeapMemoryUsage();
206
207
append(newLeftTable);
208
String[] strings1 = formatKByteStrings(u.getUsed(), u.getMax());
209
append(Messages.CURRENT_HEAP_SIZE, strings1[0]);
210
append(Messages.MAXIMUM_HEAP_SIZE, strings1[1]);
211
append(endTable);
212
213
append(newRightTable);
214
String[] strings2 = formatKByteStrings(u.getCommitted());
215
append(Messages.COMMITTED_MEMORY, strings2[0]);
216
append(Messages.SUMMARY_TAB_PENDING_FINALIZATION_LABEL,
217
Resources.format(Messages.SUMMARY_TAB_PENDING_FINALIZATION_VALUE,
218
memoryBean.getObjectPendingFinalizationCount()));
219
append(endTable);
220
221
append(newTable);
222
Collection<GarbageCollectorMXBean> garbageCollectors =
223
proxyClient.getGarbageCollectorMXBeans();
224
for (GarbageCollectorMXBean garbageCollectorMBean : garbageCollectors) {
225
String gcName = garbageCollectorMBean.getName();
226
long gcCount = garbageCollectorMBean.getCollectionCount();
227
long gcTime = garbageCollectorMBean.getCollectionTime();
228
229
append(Messages.GARBAGE_COLLECTOR,
230
Resources.format(Messages.GC_INFO, gcName, gcCount,
231
(gcTime >= 0) ? formatTime(gcTime)
232
: Messages.UNAVAILABLE),
233
4);
234
}
235
append(endTable);
236
}
237
238
append(newDivider);
239
240
{ // Operating System info
241
append(newLeftTable);
242
String osName = osMBean.getName();
243
String osVersion = osMBean.getVersion();
244
String osArch = osMBean.getArch();
245
result.nCPUs = osMBean.getAvailableProcessors();
246
append(Messages.OPERATING_SYSTEM, osName + " " + osVersion);
247
append(Messages.ARCHITECTURE, osArch);
248
append(Messages.NUMBER_OF_PROCESSORS, result.nCPUs+"");
249
250
if (pathSeparator == null) {
251
// Must use separator of remote OS, not File.pathSeparator
252
// from this local VM. In the future, consider using
253
// RuntimeMXBean to get the remote system property.
254
pathSeparator = osName.startsWith("Windows ") ? ";" : ":";
255
}
256
257
if (sunOSMBean != null) {
258
String[] kbStrings1 =
259
formatKByteStrings(sunOSMBean.getCommittedVirtualMemorySize());
260
261
// getTotalPhysicalMemorySize and getFreePhysicalMemorySize are deprecated,
262
// but we want be able to get the data for old target VMs (see JDK-8255934).
263
@SuppressWarnings("deprecation")
264
String[] kbStrings2 =
265
formatKByteStrings(tryToGet(sunOSMBean::getTotalMemorySize,
266
sunOSMBean::getTotalPhysicalMemorySize),
267
tryToGet(sunOSMBean::getFreeMemorySize,
268
sunOSMBean::getFreePhysicalMemorySize),
269
sunOSMBean.getTotalSwapSpaceSize(),
270
sunOSMBean.getFreeSwapSpaceSize());
271
272
append(Messages.COMMITTED_VIRTUAL_MEMORY, kbStrings1[0]);
273
append(endTable);
274
275
append(newRightTable);
276
append(Messages.TOTAL_PHYSICAL_MEMORY, kbStrings2[0]);
277
append(Messages.FREE_PHYSICAL_MEMORY, kbStrings2[1]);
278
append(Messages.TOTAL_SWAP_SPACE, kbStrings2[2]);
279
append(Messages.FREE_SWAP_SPACE, kbStrings2[3]);
280
}
281
282
append(endTable);
283
}
284
285
append(newDivider);
286
287
{ // VM arguments and paths
288
append(newTable);
289
String args = "";
290
java.util.List<String> inputArguments = rmBean.getInputArguments();
291
for (String arg : inputArguments) {
292
args += arg + " ";
293
}
294
append(Messages.VM_ARGUMENTS, args, 4);
295
append(Messages.CLASS_PATH, rmBean.getClassPath(), 4);
296
append(Messages.LIBRARY_PATH, rmBean.getLibraryPath(), 4);
297
append(Messages.BOOT_CLASS_PATH,
298
rmBean.isBootClassPathSupported()
299
? rmBean.getBootClassPath()
300
: Messages.UNAVAILABLE,
301
4);
302
append(endTable);
303
}
304
} catch (IOException e) {
305
if (JConsole.isDebug()) {
306
e.printStackTrace();
307
}
308
proxyClient.markAsDead();
309
return null;
310
} catch (UndeclaredThrowableException e) {
311
if (JConsole.isDebug()) {
312
e.printStackTrace();
313
}
314
proxyClient.markAsDead();
315
return null;
316
}
317
318
append("</table>");
319
320
result.timeStamp = System.currentTimeMillis();
321
result.summary = buf.toString();
322
323
return result;
324
}
325
326
/**
327
* Tries to get the specified value from the list of suppliers.
328
* Returns -1 if all suppliers fail.
329
*/
330
private long tryToGet(LongSupplier ... getters) {
331
for (LongSupplier getter : getters) {
332
try {
333
return getter.getAsLong();
334
} catch (UndeclaredThrowableException e) {
335
}
336
}
337
return -1;
338
}
339
340
private synchronized void append(String str) {
341
buf.append(str);
342
}
343
344
void append(String label, String value) {
345
append(newRow(label, value));
346
}
347
348
private void append(String label, String value, int columnPerRow) {
349
if (columnPerRow == 4 && pathSeparator != null) {
350
value = value.replace(pathSeparator,
351
"<b></b>" + pathSeparator);
352
}
353
append(newRow(label, value, columnPerRow));
354
}
355
356
OverviewPanel[] getOverviewPanels() {
357
if (overviewPanel == null) {
358
overviewPanel = new CPUOverviewPanel();
359
}
360
return new OverviewPanel[] { overviewPanel };
361
}
362
363
private static class CPUOverviewPanel extends OverviewPanel {
364
private long prevUpTime, prevProcessCpuTime;
365
366
CPUOverviewPanel() {
367
super(Messages.CPU_USAGE, cpuUsageKey, Messages.CPU_USAGE, Plotter.Unit.PERCENT);
368
getPlotter().setDecimals(CPU_DECIMALS);
369
}
370
371
public void updateCPUInfo(Result result) {
372
if (prevUpTime > 0L && result.upTime > prevUpTime) {
373
// elapsedCpu is in ns and elapsedTime is in ms.
374
long elapsedCpu = result.processCpuTime - prevProcessCpuTime;
375
long elapsedTime = result.upTime - prevUpTime;
376
// cpuUsage could go higher than 100% because elapsedTime
377
// and elapsedCpu are not fetched simultaneously. Limit to
378
// 99% to avoid Plotter showing a scale from 0% to 200%.
379
float cpuUsage =
380
Math.min(99F,
381
elapsedCpu / (elapsedTime * 10000F * result.nCPUs));
382
383
cpuUsage = Math.max(0F, cpuUsage);
384
385
getPlotter().addValues(result.timeStamp,
386
Math.round(cpuUsage * Math.pow(10.0, CPU_DECIMALS)));
387
getInfoLabel().setText(Resources.format(Messages.CPU_USAGE_FORMAT,
388
String.format("%."+CPU_DECIMALS+"f", cpuUsage)));
389
}
390
this.prevUpTime = result.upTime;
391
this.prevProcessCpuTime = result.processCpuTime;
392
}
393
}
394
}
395
396