author | sangheki |
Mon, 04 Jun 2018 21:20:16 -0700 | |
changeset 50396 | 7f48bff40a9a |
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 |
#include <jni.h> |
|
17954 | 27 |
#include <stdlib.h> |
2 | 28 |
#include "jvm.h" |
29 |
#include "management.h" |
|
30 |
#include "sun_management_VMManagementImpl.h" |
|
31 |
||
32 |
#define MAX_VERSION_LEN 20 |
|
33 |
||
34 |
JNIEXPORT jstring JNICALL |
|
35 |
Java_sun_management_VMManagementImpl_getVersion0 |
|
36 |
(JNIEnv *env, jclass dummy) |
|
37 |
{ |
|
38 |
char buf[MAX_VERSION_LEN]; |
|
39 |
jstring version_string = NULL; |
|
40 |
||
41 |
unsigned int major = ((unsigned int) jmm_version & 0x0FFF0000) >> 16; |
|
42 |
unsigned int minor = ((unsigned int) jmm_version & 0xFF00) >> 8; |
|
43 |
||
44 |
// for internal use |
|
45 |
unsigned int micro = (unsigned int) jmm_version & 0xFF; |
|
46 |
||
47 |
sprintf(buf, "%d.%d", major, minor); |
|
48 |
version_string = (*env)->NewStringUTF(env, buf); |
|
49 |
return version_string; |
|
50 |
} |
|
51 |
||
52 |
static void setStaticBooleanField |
|
53 |
(JNIEnv* env, jclass cls, const char* name, jboolean value) |
|
54 |
{ |
|
55 |
jfieldID fid; |
|
56 |
fid = (*env)->GetStaticFieldID(env, cls, name, "Z"); |
|
57 |
if (fid != 0) { |
|
58 |
(*env)->SetStaticBooleanField(env, cls, fid, value); |
|
59 |
} |
|
60 |
} |
|
61 |
||
62 |
JNIEXPORT void JNICALL |
|
63 |
Java_sun_management_VMManagementImpl_initOptionalSupportFields |
|
64 |
(JNIEnv *env, jclass cls) |
|
65 |
{ |
|
66 |
jmmOptionalSupport mos; |
|
67 |
jint ret = jmm_interface->GetOptionalSupport(env, &mos); |
|
68 |
||
69 |
jboolean value; |
|
70 |
||
71 |
value = mos.isCompilationTimeMonitoringSupported; |
|
72 |
setStaticBooleanField(env, cls, "compTimeMonitoringSupport", value); |
|
73 |
||
74 |
value = mos.isThreadContentionMonitoringSupported; |
|
75 |
setStaticBooleanField(env, cls, "threadContentionMonitoringSupport", value); |
|
76 |
||
77 |
value = mos.isCurrentThreadCpuTimeSupported; |
|
78 |
setStaticBooleanField(env, cls, "currentThreadCpuTimeSupport", value); |
|
79 |
||
80 |
value = mos.isOtherThreadCpuTimeSupported; |
|
81 |
setStaticBooleanField(env, cls, "otherThreadCpuTimeSupport", value); |
|
82 |
||
83 |
if (jmm_version >= JMM_VERSION_1_1) { |
|
84 |
value = mos.isObjectMonitorUsageSupported; |
|
85 |
setStaticBooleanField(env, cls, "objectMonitorUsageSupport", value); |
|
86 |
||
87 |
value = mos.isSynchronizerUsageSupported; |
|
88 |
setStaticBooleanField(env, cls, "synchronizerUsageSupport", value); |
|
89 |
} else { |
|
90 |
setStaticBooleanField(env, cls, "objectMonitorUsageSupport", JNI_FALSE); |
|
91 |
setStaticBooleanField(env, cls, "synchronizerUsageSupport", JNI_FALSE); |
|
92 |
} |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
93 |
|
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
94 |
value = mos.isThreadAllocatedMemorySupported; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
95 |
setStaticBooleanField(env, cls, "threadAllocatedMemorySupport", value); |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
96 |
|
17954 | 97 |
value = mos.isRemoteDiagnosticCommandsSupported; |
98 |
setStaticBooleanField(env, cls, "remoteDiagnosticCommandsSupport", value); |
|
2 | 99 |
} |
100 |
||
101 |
JNIEXPORT jobjectArray JNICALL |
|
102 |
Java_sun_management_VMManagementImpl_getVmArguments0 |
|
103 |
(JNIEnv *env, jobject dummy) |
|
104 |
{ |
|
35262
6ffcba13c973
8138677: IllegalAccessException Class sun.usagetracker.UsageTrackerClient$4 (module java.base) can not access a member of class java.lang.management.ManagementFactory (module java.management)
jbachorik
parents:
25859
diff
changeset
|
105 |
return JVM_GetVmArguments(env); |
2 | 106 |
} |
107 |
||
108 |
JNIEXPORT jlong JNICALL |
|
109 |
Java_sun_management_VMManagementImpl_getTotalClassCount |
|
110 |
(JNIEnv *env, jobject dummy) |
|
111 |
{ |
|
112 |
/* JMM_CLASS_LOADED_COUNT is the total number of classes loaded */ |
|
113 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
114 |
JMM_CLASS_LOADED_COUNT); |
|
115 |
return count; |
|
116 |
} |
|
117 |
||
118 |
JNIEXPORT jlong JNICALL |
|
119 |
Java_sun_management_VMManagementImpl_getUnloadedClassCount |
|
120 |
(JNIEnv *env, jobject dummy) |
|
121 |
{ |
|
122 |
/* JMM_CLASS_UNLOADED_COUNT is the total number of classes unloaded */ |
|
123 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
124 |
JMM_CLASS_UNLOADED_COUNT); |
|
125 |
return count; |
|
126 |
} |
|
127 |
||
128 |
JNIEXPORT jboolean JNICALL |
|
129 |
Java_sun_management_VMManagementImpl_getVerboseGC |
|
130 |
(JNIEnv *env, jobject dummy) |
|
131 |
{ |
|
132 |
return jmm_interface->GetBoolAttribute(env, JMM_VERBOSE_GC); |
|
133 |
} |
|
134 |
||
135 |
JNIEXPORT jboolean JNICALL |
|
136 |
Java_sun_management_VMManagementImpl_getVerboseClass |
|
137 |
(JNIEnv *env, jobject dummy) |
|
138 |
{ |
|
139 |
return jmm_interface->GetBoolAttribute(env, JMM_VERBOSE_CLASS); |
|
140 |
} |
|
141 |
||
142 |
JNIEXPORT jlong JNICALL |
|
143 |
Java_sun_management_VMManagementImpl_getTotalThreadCount |
|
144 |
(JNIEnv *env, jobject dummy) |
|
145 |
{ |
|
146 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
147 |
JMM_THREAD_TOTAL_COUNT); |
|
148 |
} |
|
149 |
||
150 |
JNIEXPORT jint JNICALL |
|
151 |
Java_sun_management_VMManagementImpl_getLiveThreadCount |
|
152 |
(JNIEnv *env, jobject dummy) |
|
153 |
{ |
|
154 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
155 |
JMM_THREAD_LIVE_COUNT); |
|
156 |
return (jint) count; |
|
157 |
} |
|
158 |
||
159 |
JNIEXPORT jint JNICALL |
|
160 |
Java_sun_management_VMManagementImpl_getPeakThreadCount |
|
161 |
(JNIEnv *env, jobject dummy) |
|
162 |
{ |
|
163 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
164 |
JMM_THREAD_PEAK_COUNT); |
|
165 |
return (jint) count; |
|
166 |
} |
|
167 |
||
168 |
JNIEXPORT jint JNICALL |
|
169 |
Java_sun_management_VMManagementImpl_getDaemonThreadCount |
|
170 |
(JNIEnv *env, jobject dummy) |
|
171 |
{ |
|
172 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
173 |
JMM_THREAD_DAEMON_COUNT); |
|
174 |
return (jint) count; |
|
175 |
} |
|
176 |
||
177 |
JNIEXPORT jlong JNICALL |
|
178 |
Java_sun_management_VMManagementImpl_getTotalCompileTime |
|
179 |
(JNIEnv *env, jobject dummy) |
|
180 |
{ |
|
181 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
182 |
JMM_COMPILE_TOTAL_TIME_MS); |
|
183 |
} |
|
184 |
||
185 |
JNIEXPORT jlong JNICALL |
|
186 |
Java_sun_management_VMManagementImpl_getStartupTime |
|
187 |
(JNIEnv *env, jobject dummy) |
|
188 |
{ |
|
189 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
190 |
JMM_JVM_INIT_DONE_TIME_MS); |
|
191 |
} |
|
192 |
||
21640
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
193 |
JNIEXPORT jlong JNICALL |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
194 |
Java_sun_management_VMManagementImpl_getUptime0 |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
195 |
(JNIEnv *env, jobject dummy) |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
196 |
{ |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
197 |
return jmm_interface->GetLongAttribute(env, NULL, JMM_JVM_UPTIME_MS); |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
198 |
} |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
199 |
|
2 | 200 |
JNIEXPORT jboolean JNICALL |
201 |
Java_sun_management_VMManagementImpl_isThreadContentionMonitoringEnabled |
|
202 |
(JNIEnv *env, jobject dummy) |
|
203 |
{ |
|
204 |
return jmm_interface->GetBoolAttribute(env, |
|
205 |
JMM_THREAD_CONTENTION_MONITORING); |
|
206 |
} |
|
207 |
||
208 |
JNIEXPORT jboolean JNICALL |
|
209 |
Java_sun_management_VMManagementImpl_isThreadCpuTimeEnabled |
|
210 |
(JNIEnv *env, jobject dummy) |
|
211 |
{ |
|
212 |
return jmm_interface->GetBoolAttribute(env, JMM_THREAD_CPU_TIME); |
|
213 |
} |
|
214 |
||
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
215 |
JNIEXPORT jboolean JNICALL |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
216 |
Java_sun_management_VMManagementImpl_isThreadAllocatedMemoryEnabled |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
217 |
(JNIEnv *env, jobject dummy) |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
218 |
{ |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
219 |
return jmm_interface->GetBoolAttribute(env, JMM_THREAD_ALLOCATED_MEMORY); |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
220 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
221 |
|
2 | 222 |
JNIEXPORT jint JNICALL |
223 |
Java_sun_management_VMManagementImpl_getProcessId |
|
224 |
(JNIEnv *env, jobject dummy) |
|
225 |
{ |
|
226 |
jlong pid = jmm_interface->GetLongAttribute(env, NULL, |
|
227 |
JMM_OS_PROCESS_ID); |
|
228 |
return (jint) pid; |
|
229 |
} |
|
230 |
||
231 |
JNIEXPORT jint JNICALL |
|
232 |
Java_sun_management_VMManagementImpl_getAvailableProcessors |
|
233 |
(JNIEnv *env, jobject dummy) |
|
234 |
{ |
|
235 |
return JVM_ActiveProcessorCount(); |
|
236 |
} |
|
237 |
||
238 |
JNIEXPORT jlong JNICALL |
|
239 |
Java_sun_management_VMManagementImpl_getSafepointCount |
|
240 |
(JNIEnv *env, jobject dummy) |
|
241 |
{ |
|
242 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
243 |
JMM_SAFEPOINT_COUNT); |
|
244 |
} |
|
245 |
||
246 |
JNIEXPORT jlong JNICALL |
|
247 |
Java_sun_management_VMManagementImpl_getTotalSafepointTime |
|
248 |
(JNIEnv *env, jobject dummy) |
|
249 |
{ |
|
250 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
251 |
JMM_TOTAL_STOPPED_TIME_MS); |
|
252 |
} |
|
253 |
||
254 |
JNIEXPORT jlong JNICALL |
|
255 |
Java_sun_management_VMManagementImpl_getSafepointSyncTime |
|
256 |
(JNIEnv *env, jobject dummy) |
|
257 |
{ |
|
258 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
259 |
JMM_TOTAL_SAFEPOINTSYNC_TIME_MS); |
|
260 |
} |
|
261 |
||
262 |
JNIEXPORT jlong JNICALL |
|
263 |
Java_sun_management_VMManagementImpl_getTotalApplicationNonStoppedTime |
|
264 |
(JNIEnv *env, jobject dummy) |
|
265 |
{ |
|
266 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
267 |
JMM_TOTAL_APP_TIME_MS); |
|
268 |
} |
|
269 |
||
270 |
JNIEXPORT jlong JNICALL |
|
271 |
Java_sun_management_VMManagementImpl_getLoadedClassSize |
|
272 |
(JNIEnv *env, jobject dummy) |
|
273 |
{ |
|
274 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
275 |
JMM_CLASS_LOADED_BYTES); |
|
276 |
} |
|
277 |
||
278 |
JNIEXPORT jlong JNICALL |
|
279 |
Java_sun_management_VMManagementImpl_getUnloadedClassSize |
|
280 |
(JNIEnv *env, jobject dummy) |
|
281 |
{ |
|
282 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
283 |
JMM_CLASS_UNLOADED_BYTES); |
|
284 |
} |
|
285 |
JNIEXPORT jlong JNICALL |
|
286 |
Java_sun_management_VMManagementImpl_getClassLoadingTime |
|
287 |
(JNIEnv *env, jobject dummy) |
|
288 |
{ |
|
289 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
290 |
JMM_TOTAL_CLASSLOAD_TIME_MS); |
|
291 |
} |
|
292 |
||
293 |
||
294 |
JNIEXPORT jlong JNICALL |
|
295 |
Java_sun_management_VMManagementImpl_getMethodDataSize |
|
296 |
(JNIEnv *env, jobject dummy) |
|
297 |
{ |
|
298 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
299 |
JMM_METHOD_DATA_SIZE_BYTES); |
|
300 |
} |
|
301 |
||
302 |
JNIEXPORT jlong JNICALL |
|
303 |
Java_sun_management_VMManagementImpl_getInitializedClassCount |
|
304 |
(JNIEnv *env, jobject dummy) |
|
305 |
{ |
|
306 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
307 |
JMM_CLASS_INIT_TOTAL_COUNT); |
|
308 |
} |
|
309 |
||
310 |
JNIEXPORT jlong JNICALL |
|
311 |
Java_sun_management_VMManagementImpl_getClassInitializationTime |
|
312 |
(JNIEnv *env, jobject dummy) |
|
313 |
{ |
|
314 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
315 |
JMM_CLASS_INIT_TOTAL_TIME_MS); |
|
316 |
} |
|
317 |
||
318 |
JNIEXPORT jlong JNICALL |
|
319 |
Java_sun_management_VMManagementImpl_getClassVerificationTime |
|
320 |
(JNIEnv *env, jobject dummy) |
|
321 |
{ |
|
322 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
323 |
JMM_CLASS_VERIFY_TOTAL_TIME_MS); |
|
324 |
} |