1 | /* |
2 | * Copyright (c) 2003, 2016, 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 | #include <jni.h> |
27 | #include <stdlib.h> |
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 | } |
93 | |
94 | value = mos.isThreadAllocatedMemorySupported; |
95 | setStaticBooleanField(env, cls, "threadAllocatedMemorySupport" , value); |
96 | |
97 | value = mos.isRemoteDiagnosticCommandsSupported; |
98 | setStaticBooleanField(env, cls, "remoteDiagnosticCommandsSupport" , value); |
99 | } |
100 | |
101 | JNIEXPORT jobjectArray JNICALL |
102 | Java_sun_management_VMManagementImpl_getVmArguments0 |
103 | (JNIEnv *env, jobject dummy) |
104 | { |
105 | return JVM_GetVmArguments(env); |
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 | |
193 | JNIEXPORT jlong JNICALL |
194 | Java_sun_management_VMManagementImpl_getUptime0 |
195 | (JNIEnv *env, jobject dummy) |
196 | { |
197 | return jmm_interface->GetLongAttribute(env, NULL, JMM_JVM_UPTIME_MS); |
198 | } |
199 | |
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 | |
215 | JNIEXPORT jboolean JNICALL |
216 | Java_sun_management_VMManagementImpl_isThreadAllocatedMemoryEnabled |
217 | (JNIEnv *env, jobject dummy) |
218 | { |
219 | return jmm_interface->GetBoolAttribute(env, JMM_THREAD_ALLOCATED_MEMORY); |
220 | } |
221 | |
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 | } |
325 | |