author | chegar |
Fri, 09 Mar 2018 17:59:11 +0000 | |
branch | http-client-branch |
changeset 56272 | 7394452786ba |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
42102
3e0a2861efe1
8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents:
36511
diff
changeset
|
2 |
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.management; |
|
27 |
||
34953
67245e3259bf
8146736: Move sun.misc performance counters to jdk.internal.perf
chegar
parents:
25859
diff
changeset
|
28 |
import jdk.internal.perf.Perf; |
2 | 29 |
import sun.management.counter.*; |
30 |
import sun.management.counter.perf.*; |
|
31 |
import java.nio.ByteBuffer; |
|
32 |
import java.io.IOException; |
|
33 |
import java.net.InetAddress; |
|
34 |
import java.net.UnknownHostException; |
|
35 |
import java.util.List; |
|
36 |
import java.util.Arrays; |
|
37 |
import java.util.Collections; |
|
38 |
import java.security.AccessController; |
|
39 |
import java.security.PrivilegedAction; |
|
40 |
||
41 |
/** |
|
42 |
* Implementation of VMManagement interface that accesses the management |
|
43 |
* attributes and operations locally within the same Java virtual |
|
44 |
* machine. |
|
45 |
*/ |
|
46 |
class VMManagementImpl implements VMManagement { |
|
47 |
||
48 |
private static String version; |
|
49 |
||
50 |
private static boolean compTimeMonitoringSupport; |
|
51 |
private static boolean threadContentionMonitoringSupport; |
|
52 |
private static boolean currentThreadCpuTimeSupport; |
|
53 |
private static boolean otherThreadCpuTimeSupport; |
|
54 |
private static boolean objectMonitorUsageSupport; |
|
55 |
private static boolean synchronizerUsageSupport; |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
56 |
private static boolean threadAllocatedMemorySupport; |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
57 |
private static boolean gcNotificationSupport; |
17954 | 58 |
private static boolean remoteDiagnosticCommandsSupport; |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
59 |
|
2 | 60 |
|
61 |
static { |
|
62 |
version = getVersion0(); |
|
63 |
if (version == null) { |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
64 |
throw new AssertionError("Invalid Management Version"); |
2 | 65 |
} |
66 |
initOptionalSupportFields(); |
|
67 |
} |
|
68 |
private native static String getVersion0(); |
|
69 |
private native static void initOptionalSupportFields(); |
|
70 |
||
71 |
// Optional supports |
|
72 |
public boolean isCompilationTimeMonitoringSupported() { |
|
73 |
return compTimeMonitoringSupport; |
|
74 |
} |
|
75 |
||
76 |
public boolean isThreadContentionMonitoringSupported() { |
|
77 |
return threadContentionMonitoringSupport; |
|
78 |
} |
|
79 |
||
80 |
public boolean isCurrentThreadCpuTimeSupported() { |
|
81 |
return currentThreadCpuTimeSupport; |
|
82 |
} |
|
83 |
||
84 |
public boolean isOtherThreadCpuTimeSupported() { |
|
85 |
return otherThreadCpuTimeSupport; |
|
86 |
} |
|
87 |
||
88 |
public boolean isBootClassPathSupported() { |
|
36511 | 89 |
return false; |
2 | 90 |
} |
91 |
||
92 |
public boolean isObjectMonitorUsageSupported() { |
|
93 |
return objectMonitorUsageSupport; |
|
94 |
} |
|
95 |
||
96 |
public boolean isSynchronizerUsageSupported() { |
|
97 |
return synchronizerUsageSupport; |
|
98 |
} |
|
99 |
||
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
100 |
public boolean isThreadAllocatedMemorySupported() { |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
101 |
return threadAllocatedMemorySupport; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
102 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
103 |
|
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
104 |
public boolean isGcNotificationSupported() { |
42102
3e0a2861efe1
8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents:
36511
diff
changeset
|
105 |
boolean isSupported = true; |
3e0a2861efe1
8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents:
36511
diff
changeset
|
106 |
try { |
3e0a2861efe1
8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents:
36511
diff
changeset
|
107 |
Class.forName("com.sun.management.GarbageCollectorMXBean"); |
3e0a2861efe1
8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents:
36511
diff
changeset
|
108 |
} catch (ClassNotFoundException x) { |
3e0a2861efe1
8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents:
36511
diff
changeset
|
109 |
isSupported = false; |
3e0a2861efe1
8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents:
36511
diff
changeset
|
110 |
} |
3e0a2861efe1
8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents:
36511
diff
changeset
|
111 |
return isSupported; |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
112 |
} |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
113 |
|
17954 | 114 |
public boolean isRemoteDiagnosticCommandsSupported() { |
115 |
return remoteDiagnosticCommandsSupport; |
|
116 |
} |
|
117 |
||
2 | 118 |
public native boolean isThreadContentionMonitoringEnabled(); |
119 |
public native boolean isThreadCpuTimeEnabled(); |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
120 |
public native boolean isThreadAllocatedMemoryEnabled(); |
2 | 121 |
|
122 |
// Class Loading Subsystem |
|
123 |
public int getLoadedClassCount() { |
|
124 |
long count = getTotalClassCount() - getUnloadedClassCount(); |
|
125 |
return (int) count; |
|
126 |
} |
|
127 |
public native long getTotalClassCount(); |
|
128 |
public native long getUnloadedClassCount(); |
|
129 |
||
130 |
public native boolean getVerboseClass(); |
|
131 |
||
132 |
// Memory Subsystem |
|
133 |
public native boolean getVerboseGC(); |
|
134 |
||
135 |
// Runtime Subsystem |
|
136 |
public String getManagementVersion() { |
|
137 |
return version; |
|
138 |
} |
|
139 |
||
140 |
public String getVmId() { |
|
141 |
int pid = getProcessId(); |
|
142 |
String hostname = "localhost"; |
|
143 |
try { |
|
144 |
hostname = InetAddress.getLocalHost().getHostName(); |
|
145 |
} catch (UnknownHostException e) { |
|
146 |
// ignore |
|
147 |
} |
|
148 |
||
149 |
return pid + "@" + hostname; |
|
150 |
} |
|
151 |
private native int getProcessId(); |
|
152 |
||
153 |
public String getVmName() { |
|
154 |
return System.getProperty("java.vm.name"); |
|
155 |
} |
|
156 |
||
157 |
public String getVmVendor() { |
|
158 |
return System.getProperty("java.vm.vendor"); |
|
159 |
} |
|
160 |
public String getVmVersion() { |
|
161 |
return System.getProperty("java.vm.version"); |
|
162 |
} |
|
163 |
public String getVmSpecName() { |
|
164 |
return System.getProperty("java.vm.specification.name"); |
|
165 |
} |
|
166 |
public String getVmSpecVendor() { |
|
167 |
return System.getProperty("java.vm.specification.vendor"); |
|
168 |
} |
|
169 |
public String getVmSpecVersion() { |
|
170 |
return System.getProperty("java.vm.specification.version"); |
|
171 |
} |
|
172 |
public String getClassPath() { |
|
173 |
return System.getProperty("java.class.path"); |
|
174 |
} |
|
175 |
public String getLibraryPath() { |
|
176 |
return System.getProperty("java.library.path"); |
|
177 |
} |
|
178 |
||
179 |
public String getBootClassPath( ) { |
|
36511 | 180 |
throw new UnsupportedOperationException( |
181 |
"Boot class path mechanism is not supported"); |
|
2 | 182 |
} |
183 |
||
21640
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
184 |
public long getUptime() { |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
185 |
return getUptime0(); |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
186 |
} |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
187 |
|
2 | 188 |
private List<String> vmArgs = null; |
189 |
public synchronized List<String> getVmArguments() { |
|
190 |
if (vmArgs == null) { |
|
191 |
String[] args = getVmArguments0(); |
|
192 |
List<String> l = ((args != null && args.length != 0) ? Arrays.asList(args) : |
|
193 |
Collections.<String>emptyList()); |
|
194 |
vmArgs = Collections.unmodifiableList(l); |
|
195 |
} |
|
196 |
return vmArgs; |
|
197 |
} |
|
198 |
public native String[] getVmArguments0(); |
|
199 |
||
200 |
public native long getStartupTime(); |
|
21640
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
201 |
private native long getUptime0(); |
2 | 202 |
public native int getAvailableProcessors(); |
203 |
||
204 |
// Compilation Subsystem |
|
205 |
public String getCompilerName() { |
|
206 |
String name = AccessController.doPrivileged( |
|
207 |
new PrivilegedAction<String>() { |
|
208 |
public String run() { |
|
209 |
return System.getProperty("sun.management.compiler"); |
|
210 |
} |
|
211 |
}); |
|
212 |
return name; |
|
213 |
} |
|
214 |
public native long getTotalCompileTime(); |
|
215 |
||
216 |
// Thread Subsystem |
|
217 |
public native long getTotalThreadCount(); |
|
218 |
public native int getLiveThreadCount(); |
|
219 |
public native int getPeakThreadCount(); |
|
220 |
public native int getDaemonThreadCount(); |
|
221 |
||
222 |
// Operating System |
|
223 |
public String getOsName() { |
|
224 |
return System.getProperty("os.name"); |
|
225 |
} |
|
226 |
public String getOsArch() { |
|
227 |
return System.getProperty("os.arch"); |
|
228 |
} |
|
229 |
public String getOsVersion() { |
|
230 |
return System.getProperty("os.version"); |
|
231 |
} |
|
232 |
||
233 |
// Hotspot-specific runtime support |
|
234 |
public native long getSafepointCount(); |
|
235 |
public native long getTotalSafepointTime(); |
|
236 |
public native long getSafepointSyncTime(); |
|
237 |
public native long getTotalApplicationNonStoppedTime(); |
|
238 |
||
239 |
public native long getLoadedClassSize(); |
|
240 |
public native long getUnloadedClassSize(); |
|
241 |
public native long getClassLoadingTime(); |
|
242 |
public native long getMethodDataSize(); |
|
243 |
public native long getInitializedClassCount(); |
|
244 |
public native long getClassInitializationTime(); |
|
245 |
public native long getClassVerificationTime(); |
|
246 |
||
247 |
// Performance Counter Support |
|
248 |
private PerfInstrumentation perfInstr = null; |
|
249 |
private boolean noPerfData = false; |
|
250 |
||
251 |
private synchronized PerfInstrumentation getPerfInstrumentation() { |
|
252 |
if (noPerfData || perfInstr != null) { |
|
253 |
return perfInstr; |
|
254 |
} |
|
255 |
||
256 |
// construct PerfInstrumentation object |
|
257 |
Perf perf = AccessController.doPrivileged(new Perf.GetPerfAction()); |
|
258 |
try { |
|
259 |
ByteBuffer bb = perf.attach(0, "r"); |
|
260 |
if (bb.capacity() == 0) { |
|
261 |
noPerfData = true; |
|
262 |
return null; |
|
263 |
} |
|
264 |
perfInstr = new PerfInstrumentation(bb); |
|
265 |
} catch (IllegalArgumentException e) { |
|
266 |
// If the shared memory doesn't exist e.g. if -XX:-UsePerfData |
|
267 |
// was set |
|
268 |
noPerfData = true; |
|
269 |
} catch (IOException e) { |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
270 |
throw new AssertionError(e); |
2 | 271 |
} |
272 |
return perfInstr; |
|
273 |
} |
|
274 |
||
275 |
public List<Counter> getInternalCounters(String pattern) { |
|
276 |
PerfInstrumentation perf = getPerfInstrumentation(); |
|
277 |
if (perf != null) { |
|
278 |
return perf.findByPattern(pattern); |
|
279 |
} else { |
|
280 |
return Collections.emptyList(); |
|
281 |
} |
|
282 |
} |
|
283 |
} |