author | jbachorik |
Sun, 10 Nov 2013 20:05:03 +0100 | |
changeset 21640 | 6bbdcc430310 |
parent 17954 | 885a02686acb |
permissions | -rw-r--r-- |
2 | 1 |
/* |
17954 | 2 |
* Copyright (c) 2003, 2013, 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 |
value = mos.isBootClassPathSupported; |
|
84 |
setStaticBooleanField(env, cls, "bootClassPathSupport", value); |
|
85 |
||
86 |
if (jmm_version >= JMM_VERSION_1_1) { |
|
87 |
value = mos.isObjectMonitorUsageSupported; |
|
88 |
setStaticBooleanField(env, cls, "objectMonitorUsageSupport", value); |
|
89 |
||
90 |
value = mos.isSynchronizerUsageSupported; |
|
91 |
setStaticBooleanField(env, cls, "synchronizerUsageSupport", value); |
|
92 |
} else { |
|
93 |
setStaticBooleanField(env, cls, "objectMonitorUsageSupport", JNI_FALSE); |
|
94 |
setStaticBooleanField(env, cls, "synchronizerUsageSupport", JNI_FALSE); |
|
95 |
} |
|
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
96 |
|
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
97 |
value = mos.isThreadAllocatedMemorySupported; |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
98 |
setStaticBooleanField(env, cls, "threadAllocatedMemorySupport", value); |
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
99 |
|
17954 | 100 |
value = mos.isRemoteDiagnosticCommandsSupported; |
101 |
setStaticBooleanField(env, cls, "remoteDiagnosticCommandsSupport", value); |
|
102 |
||
9698
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
103 |
if ((jmm_version > JMM_VERSION_1_2) || |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
104 |
(jmm_version == JMM_VERSION_1_2 && ((jmm_version&0xFF) >= 1))) { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
105 |
setStaticBooleanField(env, cls, "gcNotificationSupport", JNI_TRUE); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
106 |
} else { |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
107 |
setStaticBooleanField(env, cls, "gcNotificationSupport", JNI_FALSE); |
8b66cd6c5ebc
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
8001
diff
changeset
|
108 |
} |
2 | 109 |
} |
110 |
||
111 |
JNIEXPORT jobjectArray JNICALL |
|
112 |
Java_sun_management_VMManagementImpl_getVmArguments0 |
|
113 |
(JNIEnv *env, jobject dummy) |
|
114 |
{ |
|
115 |
return jmm_interface->GetInputArgumentArray(env); |
|
116 |
} |
|
117 |
||
118 |
JNIEXPORT jlong JNICALL |
|
119 |
Java_sun_management_VMManagementImpl_getTotalClassCount |
|
120 |
(JNIEnv *env, jobject dummy) |
|
121 |
{ |
|
122 |
/* JMM_CLASS_LOADED_COUNT is the total number of classes loaded */ |
|
123 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
124 |
JMM_CLASS_LOADED_COUNT); |
|
125 |
return count; |
|
126 |
} |
|
127 |
||
128 |
JNIEXPORT jlong JNICALL |
|
129 |
Java_sun_management_VMManagementImpl_getUnloadedClassCount |
|
130 |
(JNIEnv *env, jobject dummy) |
|
131 |
{ |
|
132 |
/* JMM_CLASS_UNLOADED_COUNT is the total number of classes unloaded */ |
|
133 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
134 |
JMM_CLASS_UNLOADED_COUNT); |
|
135 |
return count; |
|
136 |
} |
|
137 |
||
138 |
JNIEXPORT jboolean JNICALL |
|
139 |
Java_sun_management_VMManagementImpl_getVerboseGC |
|
140 |
(JNIEnv *env, jobject dummy) |
|
141 |
{ |
|
142 |
return jmm_interface->GetBoolAttribute(env, JMM_VERBOSE_GC); |
|
143 |
} |
|
144 |
||
145 |
JNIEXPORT jboolean JNICALL |
|
146 |
Java_sun_management_VMManagementImpl_getVerboseClass |
|
147 |
(JNIEnv *env, jobject dummy) |
|
148 |
{ |
|
149 |
return jmm_interface->GetBoolAttribute(env, JMM_VERBOSE_CLASS); |
|
150 |
} |
|
151 |
||
152 |
JNIEXPORT jlong JNICALL |
|
153 |
Java_sun_management_VMManagementImpl_getTotalThreadCount |
|
154 |
(JNIEnv *env, jobject dummy) |
|
155 |
{ |
|
156 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
157 |
JMM_THREAD_TOTAL_COUNT); |
|
158 |
} |
|
159 |
||
160 |
JNIEXPORT jint JNICALL |
|
161 |
Java_sun_management_VMManagementImpl_getLiveThreadCount |
|
162 |
(JNIEnv *env, jobject dummy) |
|
163 |
{ |
|
164 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
165 |
JMM_THREAD_LIVE_COUNT); |
|
166 |
return (jint) count; |
|
167 |
} |
|
168 |
||
169 |
JNIEXPORT jint JNICALL |
|
170 |
Java_sun_management_VMManagementImpl_getPeakThreadCount |
|
171 |
(JNIEnv *env, jobject dummy) |
|
172 |
{ |
|
173 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
174 |
JMM_THREAD_PEAK_COUNT); |
|
175 |
return (jint) count; |
|
176 |
} |
|
177 |
||
178 |
JNIEXPORT jint JNICALL |
|
179 |
Java_sun_management_VMManagementImpl_getDaemonThreadCount |
|
180 |
(JNIEnv *env, jobject dummy) |
|
181 |
{ |
|
182 |
jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
183 |
JMM_THREAD_DAEMON_COUNT); |
|
184 |
return (jint) count; |
|
185 |
} |
|
186 |
||
187 |
JNIEXPORT jlong JNICALL |
|
188 |
Java_sun_management_VMManagementImpl_getTotalCompileTime |
|
189 |
(JNIEnv *env, jobject dummy) |
|
190 |
{ |
|
191 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
192 |
JMM_COMPILE_TOTAL_TIME_MS); |
|
193 |
} |
|
194 |
||
195 |
JNIEXPORT jlong JNICALL |
|
196 |
Java_sun_management_VMManagementImpl_getStartupTime |
|
197 |
(JNIEnv *env, jobject dummy) |
|
198 |
{ |
|
199 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
200 |
JMM_JVM_INIT_DONE_TIME_MS); |
|
201 |
} |
|
202 |
||
21640
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
203 |
JNIEXPORT jlong JNICALL |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
204 |
Java_sun_management_VMManagementImpl_getUptime0 |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
205 |
(JNIEnv *env, jobject dummy) |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
206 |
{ |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
207 |
return jmm_interface->GetLongAttribute(env, NULL, JMM_JVM_UPTIME_MS); |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
208 |
} |
6bbdcc430310
6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents:
17954
diff
changeset
|
209 |
|
2 | 210 |
JNIEXPORT jboolean JNICALL |
211 |
Java_sun_management_VMManagementImpl_isThreadContentionMonitoringEnabled |
|
212 |
(JNIEnv *env, jobject dummy) |
|
213 |
{ |
|
214 |
return jmm_interface->GetBoolAttribute(env, |
|
215 |
JMM_THREAD_CONTENTION_MONITORING); |
|
216 |
} |
|
217 |
||
218 |
JNIEXPORT jboolean JNICALL |
|
219 |
Java_sun_management_VMManagementImpl_isThreadCpuTimeEnabled |
|
220 |
(JNIEnv *env, jobject dummy) |
|
221 |
{ |
|
222 |
return jmm_interface->GetBoolAttribute(env, JMM_THREAD_CPU_TIME); |
|
223 |
} |
|
224 |
||
8001
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
225 |
JNIEXPORT jboolean JNICALL |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
226 |
Java_sun_management_VMManagementImpl_isThreadAllocatedMemoryEnabled |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
227 |
(JNIEnv *env, jobject dummy) |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
228 |
{ |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
229 |
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
|
230 |
} |
192adf3627b7
6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents:
5506
diff
changeset
|
231 |
|
2 | 232 |
JNIEXPORT jint JNICALL |
233 |
Java_sun_management_VMManagementImpl_getProcessId |
|
234 |
(JNIEnv *env, jobject dummy) |
|
235 |
{ |
|
236 |
jlong pid = jmm_interface->GetLongAttribute(env, NULL, |
|
237 |
JMM_OS_PROCESS_ID); |
|
238 |
return (jint) pid; |
|
239 |
} |
|
240 |
||
241 |
JNIEXPORT jint JNICALL |
|
242 |
Java_sun_management_VMManagementImpl_getAvailableProcessors |
|
243 |
(JNIEnv *env, jobject dummy) |
|
244 |
{ |
|
245 |
return JVM_ActiveProcessorCount(); |
|
246 |
} |
|
247 |
||
248 |
JNIEXPORT jlong JNICALL |
|
249 |
Java_sun_management_VMManagementImpl_getSafepointCount |
|
250 |
(JNIEnv *env, jobject dummy) |
|
251 |
{ |
|
252 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
253 |
JMM_SAFEPOINT_COUNT); |
|
254 |
} |
|
255 |
||
256 |
JNIEXPORT jlong JNICALL |
|
257 |
Java_sun_management_VMManagementImpl_getTotalSafepointTime |
|
258 |
(JNIEnv *env, jobject dummy) |
|
259 |
{ |
|
260 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
261 |
JMM_TOTAL_STOPPED_TIME_MS); |
|
262 |
} |
|
263 |
||
264 |
JNIEXPORT jlong JNICALL |
|
265 |
Java_sun_management_VMManagementImpl_getSafepointSyncTime |
|
266 |
(JNIEnv *env, jobject dummy) |
|
267 |
{ |
|
268 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
269 |
JMM_TOTAL_SAFEPOINTSYNC_TIME_MS); |
|
270 |
} |
|
271 |
||
272 |
JNIEXPORT jlong JNICALL |
|
273 |
Java_sun_management_VMManagementImpl_getTotalApplicationNonStoppedTime |
|
274 |
(JNIEnv *env, jobject dummy) |
|
275 |
{ |
|
276 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
277 |
JMM_TOTAL_APP_TIME_MS); |
|
278 |
} |
|
279 |
||
280 |
JNIEXPORT jlong JNICALL |
|
281 |
Java_sun_management_VMManagementImpl_getLoadedClassSize |
|
282 |
(JNIEnv *env, jobject dummy) |
|
283 |
{ |
|
284 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
285 |
JMM_CLASS_LOADED_BYTES); |
|
286 |
} |
|
287 |
||
288 |
JNIEXPORT jlong JNICALL |
|
289 |
Java_sun_management_VMManagementImpl_getUnloadedClassSize |
|
290 |
(JNIEnv *env, jobject dummy) |
|
291 |
{ |
|
292 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
293 |
JMM_CLASS_UNLOADED_BYTES); |
|
294 |
} |
|
295 |
JNIEXPORT jlong JNICALL |
|
296 |
Java_sun_management_VMManagementImpl_getClassLoadingTime |
|
297 |
(JNIEnv *env, jobject dummy) |
|
298 |
{ |
|
299 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
300 |
JMM_TOTAL_CLASSLOAD_TIME_MS); |
|
301 |
} |
|
302 |
||
303 |
||
304 |
JNIEXPORT jlong JNICALL |
|
305 |
Java_sun_management_VMManagementImpl_getMethodDataSize |
|
306 |
(JNIEnv *env, jobject dummy) |
|
307 |
{ |
|
308 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
309 |
JMM_METHOD_DATA_SIZE_BYTES); |
|
310 |
} |
|
311 |
||
312 |
JNIEXPORT jlong JNICALL |
|
313 |
Java_sun_management_VMManagementImpl_getInitializedClassCount |
|
314 |
(JNIEnv *env, jobject dummy) |
|
315 |
{ |
|
316 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
317 |
JMM_CLASS_INIT_TOTAL_COUNT); |
|
318 |
} |
|
319 |
||
320 |
JNIEXPORT jlong JNICALL |
|
321 |
Java_sun_management_VMManagementImpl_getClassInitializationTime |
|
322 |
(JNIEnv *env, jobject dummy) |
|
323 |
{ |
|
324 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
325 |
JMM_CLASS_INIT_TOTAL_TIME_MS); |
|
326 |
} |
|
327 |
||
328 |
JNIEXPORT jlong JNICALL |
|
329 |
Java_sun_management_VMManagementImpl_getClassVerificationTime |
|
330 |
(JNIEnv *env, jobject dummy) |
|
331 |
{ |
|
332 |
return jmm_interface->GetLongAttribute(env, NULL, |
|
333 |
JMM_CLASS_VERIFY_TOTAL_TIME_MS); |
|
334 |
} |