|
1 /* |
|
2 * Copyright 2003-2006 Sun Microsystems, Inc. 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. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 #include <jni.h> |
|
27 #include "jvm.h" |
|
28 #include "management.h" |
|
29 #include "sun_management_VMManagementImpl.h" |
|
30 |
|
31 #define MAX_VERSION_LEN 20 |
|
32 |
|
33 JNIEXPORT jstring JNICALL |
|
34 Java_sun_management_VMManagementImpl_getVersion0 |
|
35 (JNIEnv *env, jclass dummy) |
|
36 { |
|
37 char buf[MAX_VERSION_LEN]; |
|
38 jstring version_string = NULL; |
|
39 |
|
40 unsigned int major = ((unsigned int) jmm_version & 0x0FFF0000) >> 16; |
|
41 unsigned int minor = ((unsigned int) jmm_version & 0xFF00) >> 8; |
|
42 |
|
43 // for internal use |
|
44 unsigned int micro = (unsigned int) jmm_version & 0xFF; |
|
45 |
|
46 sprintf(buf, "%d.%d", major, minor); |
|
47 version_string = (*env)->NewStringUTF(env, buf); |
|
48 return version_string; |
|
49 } |
|
50 |
|
51 static void setStaticBooleanField |
|
52 (JNIEnv* env, jclass cls, const char* name, jboolean value) |
|
53 { |
|
54 jfieldID fid; |
|
55 fid = (*env)->GetStaticFieldID(env, cls, name, "Z"); |
|
56 if (fid != 0) { |
|
57 (*env)->SetStaticBooleanField(env, cls, fid, value); |
|
58 } |
|
59 } |
|
60 |
|
61 JNIEXPORT void JNICALL |
|
62 Java_sun_management_VMManagementImpl_initOptionalSupportFields |
|
63 (JNIEnv *env, jclass cls) |
|
64 { |
|
65 jmmOptionalSupport mos; |
|
66 jint ret = jmm_interface->GetOptionalSupport(env, &mos); |
|
67 |
|
68 jboolean value; |
|
69 |
|
70 value = mos.isCompilationTimeMonitoringSupported; |
|
71 setStaticBooleanField(env, cls, "compTimeMonitoringSupport", value); |
|
72 |
|
73 value = mos.isThreadContentionMonitoringSupported; |
|
74 setStaticBooleanField(env, cls, "threadContentionMonitoringSupport", value); |
|
75 |
|
76 value = mos.isCurrentThreadCpuTimeSupported; |
|
77 setStaticBooleanField(env, cls, "currentThreadCpuTimeSupport", value); |
|
78 |
|
79 value = mos.isOtherThreadCpuTimeSupported; |
|
80 setStaticBooleanField(env, cls, "otherThreadCpuTimeSupport", value); |
|
81 |
|
82 value = mos.isBootClassPathSupported; |
|
83 setStaticBooleanField(env, cls, "bootClassPathSupport", value); |
|
84 |
|
85 if (jmm_version >= JMM_VERSION_1_1) { |
|
86 value = mos.isObjectMonitorUsageSupported; |
|
87 setStaticBooleanField(env, cls, "objectMonitorUsageSupport", value); |
|
88 |
|
89 value = mos.isSynchronizerUsageSupported; |
|
90 setStaticBooleanField(env, cls, "synchronizerUsageSupport", value); |
|
91 } else { |
|
92 setStaticBooleanField(env, cls, "objectMonitorUsageSupport", JNI_FALSE); |
|
93 setStaticBooleanField(env, cls, "synchronizerUsageSupport", JNI_FALSE); |
|
94 } |
|
95 } |
|
96 |
|
97 JNIEXPORT jobjectArray JNICALL |
|
98 Java_sun_management_VMManagementImpl_getVmArguments0 |
|
99 (JNIEnv *env, jobject dummy) |
|
100 { |
|
101 return jmm_interface->GetInputArgumentArray(env); |
|
102 } |
|
103 |
|
104 JNIEXPORT jlong JNICALL |
|
105 Java_sun_management_VMManagementImpl_getTotalClassCount |
|
106 (JNIEnv *env, jobject dummy) |
|
107 { |
|
108 /* JMM_CLASS_LOADED_COUNT is the total number of classes loaded */ |
|
109 jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
110 JMM_CLASS_LOADED_COUNT); |
|
111 return count; |
|
112 } |
|
113 |
|
114 JNIEXPORT jlong JNICALL |
|
115 Java_sun_management_VMManagementImpl_getUnloadedClassCount |
|
116 (JNIEnv *env, jobject dummy) |
|
117 { |
|
118 /* JMM_CLASS_UNLOADED_COUNT is the total number of classes unloaded */ |
|
119 jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
120 JMM_CLASS_UNLOADED_COUNT); |
|
121 return count; |
|
122 } |
|
123 |
|
124 JNIEXPORT jboolean JNICALL |
|
125 Java_sun_management_VMManagementImpl_getVerboseGC |
|
126 (JNIEnv *env, jobject dummy) |
|
127 { |
|
128 return jmm_interface->GetBoolAttribute(env, JMM_VERBOSE_GC); |
|
129 } |
|
130 |
|
131 JNIEXPORT jboolean JNICALL |
|
132 Java_sun_management_VMManagementImpl_getVerboseClass |
|
133 (JNIEnv *env, jobject dummy) |
|
134 { |
|
135 return jmm_interface->GetBoolAttribute(env, JMM_VERBOSE_CLASS); |
|
136 } |
|
137 |
|
138 JNIEXPORT jlong JNICALL |
|
139 Java_sun_management_VMManagementImpl_getTotalThreadCount |
|
140 (JNIEnv *env, jobject dummy) |
|
141 { |
|
142 return jmm_interface->GetLongAttribute(env, NULL, |
|
143 JMM_THREAD_TOTAL_COUNT); |
|
144 } |
|
145 |
|
146 JNIEXPORT jint JNICALL |
|
147 Java_sun_management_VMManagementImpl_getLiveThreadCount |
|
148 (JNIEnv *env, jobject dummy) |
|
149 { |
|
150 jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
151 JMM_THREAD_LIVE_COUNT); |
|
152 return (jint) count; |
|
153 } |
|
154 |
|
155 JNIEXPORT jint JNICALL |
|
156 Java_sun_management_VMManagementImpl_getPeakThreadCount |
|
157 (JNIEnv *env, jobject dummy) |
|
158 { |
|
159 jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
160 JMM_THREAD_PEAK_COUNT); |
|
161 return (jint) count; |
|
162 } |
|
163 |
|
164 JNIEXPORT jint JNICALL |
|
165 Java_sun_management_VMManagementImpl_getDaemonThreadCount |
|
166 (JNIEnv *env, jobject dummy) |
|
167 { |
|
168 jlong count = jmm_interface->GetLongAttribute(env, NULL, |
|
169 JMM_THREAD_DAEMON_COUNT); |
|
170 return (jint) count; |
|
171 } |
|
172 |
|
173 JNIEXPORT jlong JNICALL |
|
174 Java_sun_management_VMManagementImpl_getTotalCompileTime |
|
175 (JNIEnv *env, jobject dummy) |
|
176 { |
|
177 return jmm_interface->GetLongAttribute(env, NULL, |
|
178 JMM_COMPILE_TOTAL_TIME_MS); |
|
179 } |
|
180 |
|
181 JNIEXPORT jlong JNICALL |
|
182 Java_sun_management_VMManagementImpl_getStartupTime |
|
183 (JNIEnv *env, jobject dummy) |
|
184 { |
|
185 return jmm_interface->GetLongAttribute(env, NULL, |
|
186 JMM_JVM_INIT_DONE_TIME_MS); |
|
187 } |
|
188 |
|
189 JNIEXPORT jboolean JNICALL |
|
190 Java_sun_management_VMManagementImpl_isThreadContentionMonitoringEnabled |
|
191 (JNIEnv *env, jobject dummy) |
|
192 { |
|
193 return jmm_interface->GetBoolAttribute(env, |
|
194 JMM_THREAD_CONTENTION_MONITORING); |
|
195 } |
|
196 |
|
197 JNIEXPORT jboolean JNICALL |
|
198 Java_sun_management_VMManagementImpl_isThreadCpuTimeEnabled |
|
199 (JNIEnv *env, jobject dummy) |
|
200 { |
|
201 return jmm_interface->GetBoolAttribute(env, JMM_THREAD_CPU_TIME); |
|
202 } |
|
203 |
|
204 JNIEXPORT jint JNICALL |
|
205 Java_sun_management_VMManagementImpl_getProcessId |
|
206 (JNIEnv *env, jobject dummy) |
|
207 { |
|
208 jlong pid = jmm_interface->GetLongAttribute(env, NULL, |
|
209 JMM_OS_PROCESS_ID); |
|
210 return (jint) pid; |
|
211 } |
|
212 |
|
213 JNIEXPORT jint JNICALL |
|
214 Java_sun_management_VMManagementImpl_getAvailableProcessors |
|
215 (JNIEnv *env, jobject dummy) |
|
216 { |
|
217 return JVM_ActiveProcessorCount(); |
|
218 } |
|
219 |
|
220 JNIEXPORT jlong JNICALL |
|
221 Java_sun_management_VMManagementImpl_getSafepointCount |
|
222 (JNIEnv *env, jobject dummy) |
|
223 { |
|
224 return jmm_interface->GetLongAttribute(env, NULL, |
|
225 JMM_SAFEPOINT_COUNT); |
|
226 } |
|
227 |
|
228 JNIEXPORT jlong JNICALL |
|
229 Java_sun_management_VMManagementImpl_getTotalSafepointTime |
|
230 (JNIEnv *env, jobject dummy) |
|
231 { |
|
232 return jmm_interface->GetLongAttribute(env, NULL, |
|
233 JMM_TOTAL_STOPPED_TIME_MS); |
|
234 } |
|
235 |
|
236 JNIEXPORT jlong JNICALL |
|
237 Java_sun_management_VMManagementImpl_getSafepointSyncTime |
|
238 (JNIEnv *env, jobject dummy) |
|
239 { |
|
240 return jmm_interface->GetLongAttribute(env, NULL, |
|
241 JMM_TOTAL_SAFEPOINTSYNC_TIME_MS); |
|
242 } |
|
243 |
|
244 JNIEXPORT jlong JNICALL |
|
245 Java_sun_management_VMManagementImpl_getTotalApplicationNonStoppedTime |
|
246 (JNIEnv *env, jobject dummy) |
|
247 { |
|
248 return jmm_interface->GetLongAttribute(env, NULL, |
|
249 JMM_TOTAL_APP_TIME_MS); |
|
250 } |
|
251 |
|
252 JNIEXPORT jlong JNICALL |
|
253 Java_sun_management_VMManagementImpl_getLoadedClassSize |
|
254 (JNIEnv *env, jobject dummy) |
|
255 { |
|
256 return jmm_interface->GetLongAttribute(env, NULL, |
|
257 JMM_CLASS_LOADED_BYTES); |
|
258 } |
|
259 |
|
260 JNIEXPORT jlong JNICALL |
|
261 Java_sun_management_VMManagementImpl_getUnloadedClassSize |
|
262 (JNIEnv *env, jobject dummy) |
|
263 { |
|
264 return jmm_interface->GetLongAttribute(env, NULL, |
|
265 JMM_CLASS_UNLOADED_BYTES); |
|
266 } |
|
267 JNIEXPORT jlong JNICALL |
|
268 Java_sun_management_VMManagementImpl_getClassLoadingTime |
|
269 (JNIEnv *env, jobject dummy) |
|
270 { |
|
271 return jmm_interface->GetLongAttribute(env, NULL, |
|
272 JMM_TOTAL_CLASSLOAD_TIME_MS); |
|
273 } |
|
274 |
|
275 |
|
276 JNIEXPORT jlong JNICALL |
|
277 Java_sun_management_VMManagementImpl_getMethodDataSize |
|
278 (JNIEnv *env, jobject dummy) |
|
279 { |
|
280 return jmm_interface->GetLongAttribute(env, NULL, |
|
281 JMM_METHOD_DATA_SIZE_BYTES); |
|
282 } |
|
283 |
|
284 JNIEXPORT jlong JNICALL |
|
285 Java_sun_management_VMManagementImpl_getInitializedClassCount |
|
286 (JNIEnv *env, jobject dummy) |
|
287 { |
|
288 return jmm_interface->GetLongAttribute(env, NULL, |
|
289 JMM_CLASS_INIT_TOTAL_COUNT); |
|
290 } |
|
291 |
|
292 JNIEXPORT jlong JNICALL |
|
293 Java_sun_management_VMManagementImpl_getClassInitializationTime |
|
294 (JNIEnv *env, jobject dummy) |
|
295 { |
|
296 return jmm_interface->GetLongAttribute(env, NULL, |
|
297 JMM_CLASS_INIT_TOTAL_TIME_MS); |
|
298 } |
|
299 |
|
300 JNIEXPORT jlong JNICALL |
|
301 Java_sun_management_VMManagementImpl_getClassVerificationTime |
|
302 (JNIEnv *env, jobject dummy) |
|
303 { |
|
304 return jmm_interface->GetLongAttribute(env, NULL, |
|
305 JMM_CLASS_VERIFY_TOTAL_TIME_MS); |
|
306 } |