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