Mercurial > hg > graal-compiler
annotate src/share/vm/services/management.cpp @ 4715:6c995c08526c
7122880: Extend vendor-specific command interface to include manageable switches
Summary: Add Flag::external_ext()/writable_ext(), both return false.
Reviewed-by: coleenp, zgu
author | phh |
---|---|
date | Mon, 19 Dec 2011 15:50:47 -0500 |
parents | 3b688d6ff3d0 |
children | 4f25538b54c9 |
rev | line source |
---|---|
0 | 1 /* |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1326
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1326
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1326
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | |
27 #include "compiler/compileBroker.hpp" | |
28 #include "memory/iterator.hpp" | |
29 #include "memory/oopFactory.hpp" | |
30 #include "memory/resourceArea.hpp" | |
31 #include "oops/klass.hpp" | |
32 #include "oops/klassOop.hpp" | |
33 #include "oops/objArrayKlass.hpp" | |
34 #include "oops/oop.inline.hpp" | |
35 #include "runtime/arguments.hpp" | |
4715
6c995c08526c
7122880: Extend vendor-specific command interface to include manageable switches
phh
parents:
4133
diff
changeset
|
36 #include "runtime/globals.hpp" |
1972 | 37 #include "runtime/handles.inline.hpp" |
38 #include "runtime/interfaceSupport.hpp" | |
39 #include "runtime/javaCalls.hpp" | |
40 #include "runtime/jniHandles.hpp" | |
41 #include "runtime/os.hpp" | |
2195
bf8517f4e4d0
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
2177
diff
changeset
|
42 #include "runtime/serviceThread.hpp" |
1972 | 43 #include "services/classLoadingService.hpp" |
4133 | 44 #include "services/diagnosticCommand.hpp" |
45 #include "services/diagnosticFramework.hpp" | |
1972 | 46 #include "services/heapDumper.hpp" |
4133 | 47 #include "services/jmm.h" |
1972 | 48 #include "services/lowMemoryDetector.hpp" |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
49 #include "services/gcNotifier.hpp" |
1972 | 50 #include "services/management.hpp" |
51 #include "services/memoryManager.hpp" | |
52 #include "services/memoryPool.hpp" | |
53 #include "services/memoryService.hpp" | |
54 #include "services/runtimeService.hpp" | |
55 #include "services/threadService.hpp" | |
0 | 56 |
57 PerfVariable* Management::_begin_vm_creation_time = NULL; | |
58 PerfVariable* Management::_end_vm_creation_time = NULL; | |
59 PerfVariable* Management::_vm_init_done_time = NULL; | |
60 | |
61 klassOop Management::_sensor_klass = NULL; | |
62 klassOop Management::_threadInfo_klass = NULL; | |
63 klassOop Management::_memoryUsage_klass = NULL; | |
64 klassOop Management::_memoryPoolMXBean_klass = NULL; | |
65 klassOop Management::_memoryManagerMXBean_klass = NULL; | |
66 klassOop Management::_garbageCollectorMXBean_klass = NULL; | |
67 klassOop Management::_managementFactory_klass = NULL; | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
68 klassOop Management::_garbageCollectorImpl_klass = NULL; |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
69 klassOop Management::_gcInfo_klass = NULL; |
0 | 70 |
71 jmmOptionalSupport Management::_optional_support = {0}; | |
72 TimeStamp Management::_stamp; | |
73 | |
74 void management_init() { | |
75 Management::init(); | |
76 ThreadService::init(); | |
77 RuntimeService::init(); | |
78 ClassLoadingService::init(); | |
79 } | |
80 | |
81 void Management::init() { | |
82 EXCEPTION_MARK; | |
83 | |
84 // These counters are for java.lang.management API support. | |
85 // They are created even if -XX:-UsePerfData is set and in | |
86 // that case, they will be allocated on C heap. | |
87 | |
88 _begin_vm_creation_time = | |
89 PerfDataManager::create_variable(SUN_RT, "createVmBeginTime", | |
90 PerfData::U_None, CHECK); | |
91 | |
92 _end_vm_creation_time = | |
93 PerfDataManager::create_variable(SUN_RT, "createVmEndTime", | |
94 PerfData::U_None, CHECK); | |
95 | |
96 _vm_init_done_time = | |
97 PerfDataManager::create_variable(SUN_RT, "vmInitDoneTime", | |
98 PerfData::U_None, CHECK); | |
99 | |
100 // Initialize optional support | |
101 _optional_support.isLowMemoryDetectionSupported = 1; | |
102 _optional_support.isCompilationTimeMonitoringSupported = 1; | |
103 _optional_support.isThreadContentionMonitoringSupported = 1; | |
104 | |
105 if (os::is_thread_cpu_time_supported()) { | |
106 _optional_support.isCurrentThreadCpuTimeSupported = 1; | |
107 _optional_support.isOtherThreadCpuTimeSupported = 1; | |
108 } else { | |
109 _optional_support.isCurrentThreadCpuTimeSupported = 0; | |
110 _optional_support.isOtherThreadCpuTimeSupported = 0; | |
111 } | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
112 |
0 | 113 _optional_support.isBootClassPathSupported = 1; |
114 _optional_support.isObjectMonitorUsageSupported = 1; | |
115 #ifndef SERVICES_KERNEL | |
116 // This depends on the heap inspector | |
117 _optional_support.isSynchronizerUsageSupported = 1; | |
118 #endif // SERVICES_KERNEL | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
119 _optional_support.isThreadAllocatedMemorySupported = 1; |
4133 | 120 |
121 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(true, false)); | |
122 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(true, false)); | |
0 | 123 } |
124 | |
125 void Management::initialize(TRAPS) { | |
2195
bf8517f4e4d0
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
2177
diff
changeset
|
126 // Start the service thread |
bf8517f4e4d0
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
2177
diff
changeset
|
127 ServiceThread::initialize(); |
0 | 128 |
129 if (ManagementServer) { | |
130 ResourceMark rm(THREAD); | |
131 HandleMark hm(THREAD); | |
132 | |
133 // Load and initialize the sun.management.Agent class | |
134 // invoke startAgent method to start the management server | |
135 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
136 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), |
0 | 137 loader, |
138 Handle(), | |
139 true, | |
140 CHECK); | |
141 instanceKlassHandle ik (THREAD, k); | |
142 | |
143 JavaValue result(T_VOID); | |
144 JavaCalls::call_static(&result, | |
145 ik, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
146 vmSymbols::startAgent_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
147 vmSymbols::void_method_signature(), |
0 | 148 CHECK); |
149 } | |
150 } | |
151 | |
152 void Management::get_optional_support(jmmOptionalSupport* support) { | |
153 memcpy(support, &_optional_support, sizeof(jmmOptionalSupport)); | |
154 } | |
155 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
156 klassOop Management::load_and_initialize_klass(Symbol* sh, TRAPS) { |
0 | 157 klassOop k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL); |
158 instanceKlassHandle ik (THREAD, k); | |
159 if (ik->should_be_initialized()) { | |
160 ik->initialize(CHECK_NULL); | |
161 } | |
162 return ik(); | |
163 } | |
164 | |
165 void Management::record_vm_startup_time(jlong begin, jlong duration) { | |
166 // if the performance counter is not initialized, | |
167 // then vm initialization failed; simply return. | |
168 if (_begin_vm_creation_time == NULL) return; | |
169 | |
170 _begin_vm_creation_time->set_value(begin); | |
171 _end_vm_creation_time->set_value(begin + duration); | |
172 PerfMemory::set_accessible(true); | |
173 } | |
174 | |
175 jlong Management::timestamp() { | |
176 TimeStamp t; | |
177 t.update(); | |
178 return t.ticks() - _stamp.ticks(); | |
179 } | |
180 | |
181 void Management::oops_do(OopClosure* f) { | |
182 MemoryService::oops_do(f); | |
183 ThreadService::oops_do(f); | |
184 | |
185 f->do_oop((oop*) &_sensor_klass); | |
186 f->do_oop((oop*) &_threadInfo_klass); | |
187 f->do_oop((oop*) &_memoryUsage_klass); | |
188 f->do_oop((oop*) &_memoryPoolMXBean_klass); | |
189 f->do_oop((oop*) &_memoryManagerMXBean_klass); | |
190 f->do_oop((oop*) &_garbageCollectorMXBean_klass); | |
191 f->do_oop((oop*) &_managementFactory_klass); | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
192 f->do_oop((oop*) &_garbageCollectorImpl_klass); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
193 f->do_oop((oop*) &_gcInfo_klass); |
0 | 194 } |
195 | |
196 klassOop Management::java_lang_management_ThreadInfo_klass(TRAPS) { | |
197 if (_threadInfo_klass == NULL) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
198 _threadInfo_klass = load_and_initialize_klass(vmSymbols::java_lang_management_ThreadInfo(), CHECK_NULL); |
0 | 199 } |
200 return _threadInfo_klass; | |
201 } | |
202 | |
203 klassOop Management::java_lang_management_MemoryUsage_klass(TRAPS) { | |
204 if (_memoryUsage_klass == NULL) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
205 _memoryUsage_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryUsage(), CHECK_NULL); |
0 | 206 } |
207 return _memoryUsage_klass; | |
208 } | |
209 | |
210 klassOop Management::java_lang_management_MemoryPoolMXBean_klass(TRAPS) { | |
211 if (_memoryPoolMXBean_klass == NULL) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
212 _memoryPoolMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryPoolMXBean(), CHECK_NULL); |
0 | 213 } |
214 return _memoryPoolMXBean_klass; | |
215 } | |
216 | |
217 klassOop Management::java_lang_management_MemoryManagerMXBean_klass(TRAPS) { | |
218 if (_memoryManagerMXBean_klass == NULL) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
219 _memoryManagerMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_MemoryManagerMXBean(), CHECK_NULL); |
0 | 220 } |
221 return _memoryManagerMXBean_klass; | |
222 } | |
223 | |
224 klassOop Management::java_lang_management_GarbageCollectorMXBean_klass(TRAPS) { | |
225 if (_garbageCollectorMXBean_klass == NULL) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
226 _garbageCollectorMXBean_klass = load_and_initialize_klass(vmSymbols::java_lang_management_GarbageCollectorMXBean(), CHECK_NULL); |
0 | 227 } |
228 return _garbageCollectorMXBean_klass; | |
229 } | |
230 | |
231 klassOop Management::sun_management_Sensor_klass(TRAPS) { | |
232 if (_sensor_klass == NULL) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
233 _sensor_klass = load_and_initialize_klass(vmSymbols::sun_management_Sensor(), CHECK_NULL); |
0 | 234 } |
235 return _sensor_klass; | |
236 } | |
237 | |
238 klassOop Management::sun_management_ManagementFactory_klass(TRAPS) { | |
239 if (_managementFactory_klass == NULL) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
240 _managementFactory_klass = load_and_initialize_klass(vmSymbols::sun_management_ManagementFactory(), CHECK_NULL); |
0 | 241 } |
242 return _managementFactory_klass; | |
243 } | |
244 | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
245 klassOop Management::sun_management_GarbageCollectorImpl_klass(TRAPS) { |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
246 if (_garbageCollectorImpl_klass == NULL) { |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
247 _garbageCollectorImpl_klass = load_and_initialize_klass(vmSymbols::sun_management_GarbageCollectorImpl(), CHECK_NULL); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
248 } |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
249 return _garbageCollectorImpl_klass; |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
250 } |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
251 |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
252 klassOop Management::com_sun_management_GcInfo_klass(TRAPS) { |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
253 if (_gcInfo_klass == NULL) { |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
254 _gcInfo_klass = load_and_initialize_klass(vmSymbols::com_sun_management_GcInfo(), CHECK_NULL); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
255 } |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
256 return _gcInfo_klass; |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
257 } |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
258 |
0 | 259 static void initialize_ThreadInfo_constructor_arguments(JavaCallArguments* args, ThreadSnapshot* snapshot, TRAPS) { |
260 Handle snapshot_thread(THREAD, snapshot->threadObj()); | |
261 | |
262 jlong contended_time; | |
263 jlong waited_time; | |
264 if (ThreadService::is_thread_monitoring_contention()) { | |
265 contended_time = Management::ticks_to_ms(snapshot->contended_enter_ticks()); | |
266 waited_time = Management::ticks_to_ms(snapshot->monitor_wait_ticks() + snapshot->sleep_ticks()); | |
267 } else { | |
268 // set them to -1 if thread contention monitoring is disabled. | |
269 contended_time = max_julong; | |
270 waited_time = max_julong; | |
271 } | |
272 | |
273 int thread_status = snapshot->thread_status(); | |
274 assert((thread_status & JMM_THREAD_STATE_FLAG_MASK) == 0, "Flags already set in thread_status in Thread object"); | |
275 if (snapshot->is_ext_suspended()) { | |
276 thread_status |= JMM_THREAD_STATE_FLAG_SUSPENDED; | |
277 } | |
278 if (snapshot->is_in_native()) { | |
279 thread_status |= JMM_THREAD_STATE_FLAG_NATIVE; | |
280 } | |
281 | |
282 ThreadStackTrace* st = snapshot->get_stack_trace(); | |
283 Handle stacktrace_h; | |
284 if (st != NULL) { | |
285 stacktrace_h = st->allocate_fill_stack_trace_element_array(CHECK); | |
286 } else { | |
287 stacktrace_h = Handle(); | |
288 } | |
289 | |
290 args->push_oop(snapshot_thread); | |
291 args->push_int(thread_status); | |
292 args->push_oop(Handle(THREAD, snapshot->blocker_object())); | |
293 args->push_oop(Handle(THREAD, snapshot->blocker_object_owner())); | |
294 args->push_long(snapshot->contended_enter_count()); | |
295 args->push_long(contended_time); | |
296 args->push_long(snapshot->monitor_wait_count() + snapshot->sleep_count()); | |
297 args->push_long(waited_time); | |
298 args->push_oop(stacktrace_h); | |
299 } | |
300 | |
301 // Helper function to construct a ThreadInfo object | |
302 instanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot, TRAPS) { | |
303 klassOop k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL); | |
304 instanceKlassHandle ik (THREAD, k); | |
305 | |
306 JavaValue result(T_VOID); | |
307 JavaCallArguments args(14); | |
308 | |
309 // First allocate a ThreadObj object and | |
310 // push the receiver as the first argument | |
311 Handle element = ik->allocate_instance_handle(CHECK_NULL); | |
312 args.push_oop(element); | |
313 | |
314 // initialize the arguments for the ThreadInfo constructor | |
315 initialize_ThreadInfo_constructor_arguments(&args, snapshot, CHECK_NULL); | |
316 | |
317 // Call ThreadInfo constructor with no locked monitors and synchronizers | |
318 JavaCalls::call_special(&result, | |
319 ik, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
320 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
321 vmSymbols::java_lang_management_ThreadInfo_constructor_signature(), |
0 | 322 &args, |
323 CHECK_NULL); | |
324 | |
325 return (instanceOop) element(); | |
326 } | |
327 | |
328 instanceOop Management::create_thread_info_instance(ThreadSnapshot* snapshot, | |
329 objArrayHandle monitors_array, | |
330 typeArrayHandle depths_array, | |
331 objArrayHandle synchronizers_array, | |
332 TRAPS) { | |
333 klassOop k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL); | |
334 instanceKlassHandle ik (THREAD, k); | |
335 | |
336 JavaValue result(T_VOID); | |
337 JavaCallArguments args(17); | |
338 | |
339 // First allocate a ThreadObj object and | |
340 // push the receiver as the first argument | |
341 Handle element = ik->allocate_instance_handle(CHECK_NULL); | |
342 args.push_oop(element); | |
343 | |
344 // initialize the arguments for the ThreadInfo constructor | |
345 initialize_ThreadInfo_constructor_arguments(&args, snapshot, CHECK_NULL); | |
346 | |
347 // push the locked monitors and synchronizers in the arguments | |
348 args.push_oop(monitors_array); | |
349 args.push_oop(depths_array); | |
350 args.push_oop(synchronizers_array); | |
351 | |
352 // Call ThreadInfo constructor with locked monitors and synchronizers | |
353 JavaCalls::call_special(&result, | |
354 ik, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
355 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2100
diff
changeset
|
356 vmSymbols::java_lang_management_ThreadInfo_with_locks_constructor_signature(), |
0 | 357 &args, |
358 CHECK_NULL); | |
359 | |
360 return (instanceOop) element(); | |
361 } | |
362 | |
363 // Helper functions | |
364 static JavaThread* find_java_thread_from_id(jlong thread_id) { | |
365 assert(Threads_lock->owned_by_self(), "Must hold Threads_lock"); | |
366 | |
367 JavaThread* java_thread = NULL; | |
368 // Sequential search for now. Need to do better optimization later. | |
369 for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) { | |
370 oop tobj = thread->threadObj(); | |
371 if (!thread->is_exiting() && | |
372 tobj != NULL && | |
373 thread_id == java_lang_Thread::thread_id(tobj)) { | |
374 java_thread = thread; | |
375 break; | |
376 } | |
377 } | |
378 return java_thread; | |
379 } | |
380 | |
381 static GCMemoryManager* get_gc_memory_manager_from_jobject(jobject mgr, TRAPS) { | |
382 if (mgr == NULL) { | |
383 THROW_(vmSymbols::java_lang_NullPointerException(), NULL); | |
384 } | |
385 oop mgr_obj = JNIHandles::resolve(mgr); | |
386 instanceHandle h(THREAD, (instanceOop) mgr_obj); | |
387 | |
388 klassOop k = Management::java_lang_management_GarbageCollectorMXBean_klass(CHECK_NULL); | |
389 if (!h->is_a(k)) { | |
390 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
391 "the object is not an instance of java.lang.management.GarbageCollectorMXBean class", | |
392 NULL); | |
393 } | |
394 | |
395 MemoryManager* gc = MemoryService::get_memory_manager(h); | |
396 if (gc == NULL || !gc->is_gc_memory_manager()) { | |
397 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
398 "Invalid GC memory manager", | |
399 NULL); | |
400 } | |
401 return (GCMemoryManager*) gc; | |
402 } | |
403 | |
404 static MemoryPool* get_memory_pool_from_jobject(jobject obj, TRAPS) { | |
405 if (obj == NULL) { | |
406 THROW_(vmSymbols::java_lang_NullPointerException(), NULL); | |
407 } | |
408 | |
409 oop pool_obj = JNIHandles::resolve(obj); | |
410 assert(pool_obj->is_instance(), "Should be an instanceOop"); | |
411 instanceHandle ph(THREAD, (instanceOop) pool_obj); | |
412 | |
413 return MemoryService::get_memory_pool(ph); | |
414 } | |
415 | |
416 static void validate_thread_id_array(typeArrayHandle ids_ah, TRAPS) { | |
417 int num_threads = ids_ah->length(); | |
418 | |
419 // Validate input thread IDs | |
420 int i = 0; | |
421 for (i = 0; i < num_threads; i++) { | |
422 jlong tid = ids_ah->long_at(i); | |
423 if (tid <= 0) { | |
424 // throw exception if invalid thread id. | |
425 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
426 "Invalid thread ID entry"); | |
427 } | |
428 } | |
429 } | |
430 | |
431 static void validate_thread_info_array(objArrayHandle infoArray_h, TRAPS) { | |
432 // check if the element of infoArray is of type ThreadInfo class | |
433 klassOop threadinfo_klass = Management::java_lang_management_ThreadInfo_klass(CHECK); | |
434 klassOop element_klass = objArrayKlass::cast(infoArray_h->klass())->element_klass(); | |
435 if (element_klass != threadinfo_klass) { | |
436 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
437 "infoArray element type is not ThreadInfo class"); | |
438 } | |
439 } | |
440 | |
441 | |
442 static MemoryManager* get_memory_manager_from_jobject(jobject obj, TRAPS) { | |
443 if (obj == NULL) { | |
444 THROW_(vmSymbols::java_lang_NullPointerException(), NULL); | |
445 } | |
446 | |
447 oop mgr_obj = JNIHandles::resolve(obj); | |
448 assert(mgr_obj->is_instance(), "Should be an instanceOop"); | |
449 instanceHandle mh(THREAD, (instanceOop) mgr_obj); | |
450 | |
451 return MemoryService::get_memory_manager(mh); | |
452 } | |
453 | |
454 // Returns a version string and sets major and minor version if | |
455 // the input parameters are non-null. | |
456 JVM_LEAF(jint, jmm_GetVersion(JNIEnv *env)) | |
457 return JMM_VERSION; | |
458 JVM_END | |
459 | |
460 // Gets the list of VM monitoring and management optional supports | |
461 // Returns 0 if succeeded; otherwise returns non-zero. | |
462 JVM_LEAF(jint, jmm_GetOptionalSupport(JNIEnv *env, jmmOptionalSupport* support)) | |
463 if (support == NULL) { | |
464 return -1; | |
465 } | |
466 Management::get_optional_support(support); | |
467 return 0; | |
468 JVM_END | |
469 | |
470 // Returns a java.lang.String object containing the input arguments to the VM. | |
471 JVM_ENTRY(jobject, jmm_GetInputArguments(JNIEnv *env)) | |
472 ResourceMark rm(THREAD); | |
473 | |
474 if (Arguments::num_jvm_args() == 0 && Arguments::num_jvm_flags() == 0) { | |
475 return NULL; | |
476 } | |
477 | |
478 char** vm_flags = Arguments::jvm_flags_array(); | |
479 char** vm_args = Arguments::jvm_args_array(); | |
480 int num_flags = Arguments::num_jvm_flags(); | |
481 int num_args = Arguments::num_jvm_args(); | |
482 | |
483 size_t length = 1; // null terminator | |
484 int i; | |
485 for (i = 0; i < num_flags; i++) { | |
486 length += strlen(vm_flags[i]); | |
487 } | |
488 for (i = 0; i < num_args; i++) { | |
489 length += strlen(vm_args[i]); | |
490 } | |
491 // add a space between each argument | |
492 length += num_flags + num_args - 1; | |
493 | |
494 // Return the list of input arguments passed to the VM | |
495 // and preserve the order that the VM processes. | |
496 char* args = NEW_RESOURCE_ARRAY(char, length); | |
497 args[0] = '\0'; | |
498 // concatenate all jvm_flags | |
499 if (num_flags > 0) { | |
500 strcat(args, vm_flags[0]); | |
501 for (i = 1; i < num_flags; i++) { | |
502 strcat(args, " "); | |
503 strcat(args, vm_flags[i]); | |
504 } | |
505 } | |
506 | |
507 if (num_args > 0 && num_flags > 0) { | |
508 // append a space if args already contains one or more jvm_flags | |
509 strcat(args, " "); | |
510 } | |
511 | |
512 // concatenate all jvm_args | |
513 if (num_args > 0) { | |
514 strcat(args, vm_args[0]); | |
515 for (i = 1; i < num_args; i++) { | |
516 strcat(args, " "); | |
517 strcat(args, vm_args[i]); | |
518 } | |
519 } | |
520 | |
521 Handle hargs = java_lang_String::create_from_platform_dependent_str(args, CHECK_NULL); | |
522 return JNIHandles::make_local(env, hargs()); | |
523 JVM_END | |
524 | |
525 // Returns an array of java.lang.String object containing the input arguments to the VM. | |
526 JVM_ENTRY(jobjectArray, jmm_GetInputArgumentArray(JNIEnv *env)) | |
527 ResourceMark rm(THREAD); | |
528 | |
529 if (Arguments::num_jvm_args() == 0 && Arguments::num_jvm_flags() == 0) { | |
530 return NULL; | |
531 } | |
532 | |
533 char** vm_flags = Arguments::jvm_flags_array(); | |
534 char** vm_args = Arguments::jvm_args_array(); | |
535 int num_flags = Arguments::num_jvm_flags(); | |
536 int num_args = Arguments::num_jvm_args(); | |
537 | |
1142 | 538 instanceKlassHandle ik (THREAD, SystemDictionary::String_klass()); |
0 | 539 objArrayOop r = oopFactory::new_objArray(ik(), num_args + num_flags, CHECK_NULL); |
540 objArrayHandle result_h(THREAD, r); | |
541 | |
542 int index = 0; | |
543 for (int j = 0; j < num_flags; j++, index++) { | |
544 Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL); | |
545 result_h->obj_at_put(index, h()); | |
546 } | |
547 for (int i = 0; i < num_args; i++, index++) { | |
548 Handle h = java_lang_String::create_from_platform_dependent_str(vm_args[i], CHECK_NULL); | |
549 result_h->obj_at_put(index, h()); | |
550 } | |
551 return (jobjectArray) JNIHandles::make_local(env, result_h()); | |
552 JVM_END | |
553 | |
554 // Returns an array of java/lang/management/MemoryPoolMXBean object | |
555 // one for each memory pool if obj == null; otherwise returns | |
556 // an array of memory pools for a given memory manager if | |
557 // it is a valid memory manager. | |
558 JVM_ENTRY(jobjectArray, jmm_GetMemoryPools(JNIEnv* env, jobject obj)) | |
559 ResourceMark rm(THREAD); | |
560 | |
561 int num_memory_pools; | |
562 MemoryManager* mgr = NULL; | |
563 if (obj == NULL) { | |
564 num_memory_pools = MemoryService::num_memory_pools(); | |
565 } else { | |
566 mgr = get_memory_manager_from_jobject(obj, CHECK_NULL); | |
567 if (mgr == NULL) { | |
568 return NULL; | |
569 } | |
570 num_memory_pools = mgr->num_memory_pools(); | |
571 } | |
572 | |
573 // Allocate the resulting MemoryPoolMXBean[] object | |
574 klassOop k = Management::java_lang_management_MemoryPoolMXBean_klass(CHECK_NULL); | |
575 instanceKlassHandle ik (THREAD, k); | |
576 objArrayOop r = oopFactory::new_objArray(ik(), num_memory_pools, CHECK_NULL); | |
577 objArrayHandle poolArray(THREAD, r); | |
578 | |
579 if (mgr == NULL) { | |
580 // Get all memory pools | |
581 for (int i = 0; i < num_memory_pools; i++) { | |
582 MemoryPool* pool = MemoryService::get_memory_pool(i); | |
583 instanceOop p = pool->get_memory_pool_instance(CHECK_NULL); | |
584 instanceHandle ph(THREAD, p); | |
585 poolArray->obj_at_put(i, ph()); | |
586 } | |
587 } else { | |
588 // Get memory pools managed by a given memory manager | |
589 for (int i = 0; i < num_memory_pools; i++) { | |
590 MemoryPool* pool = mgr->get_memory_pool(i); | |
591 instanceOop p = pool->get_memory_pool_instance(CHECK_NULL); | |
592 instanceHandle ph(THREAD, p); | |
593 poolArray->obj_at_put(i, ph()); | |
594 } | |
595 } | |
596 return (jobjectArray) JNIHandles::make_local(env, poolArray()); | |
597 JVM_END | |
598 | |
599 // Returns an array of java/lang/management/MemoryManagerMXBean object | |
600 // one for each memory manager if obj == null; otherwise returns | |
601 // an array of memory managers for a given memory pool if | |
602 // it is a valid memory pool. | |
603 JVM_ENTRY(jobjectArray, jmm_GetMemoryManagers(JNIEnv* env, jobject obj)) | |
604 ResourceMark rm(THREAD); | |
605 | |
606 int num_mgrs; | |
607 MemoryPool* pool = NULL; | |
608 if (obj == NULL) { | |
609 num_mgrs = MemoryService::num_memory_managers(); | |
610 } else { | |
611 pool = get_memory_pool_from_jobject(obj, CHECK_NULL); | |
612 if (pool == NULL) { | |
613 return NULL; | |
614 } | |
615 num_mgrs = pool->num_memory_managers(); | |
616 } | |
617 | |
618 // Allocate the resulting MemoryManagerMXBean[] object | |
619 klassOop k = Management::java_lang_management_MemoryManagerMXBean_klass(CHECK_NULL); | |
620 instanceKlassHandle ik (THREAD, k); | |
621 objArrayOop r = oopFactory::new_objArray(ik(), num_mgrs, CHECK_NULL); | |
622 objArrayHandle mgrArray(THREAD, r); | |
623 | |
624 if (pool == NULL) { | |
625 // Get all memory managers | |
626 for (int i = 0; i < num_mgrs; i++) { | |
627 MemoryManager* mgr = MemoryService::get_memory_manager(i); | |
628 instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL); | |
629 instanceHandle ph(THREAD, p); | |
630 mgrArray->obj_at_put(i, ph()); | |
631 } | |
632 } else { | |
633 // Get memory managers for a given memory pool | |
634 for (int i = 0; i < num_mgrs; i++) { | |
635 MemoryManager* mgr = pool->get_memory_manager(i); | |
636 instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL); | |
637 instanceHandle ph(THREAD, p); | |
638 mgrArray->obj_at_put(i, ph()); | |
639 } | |
640 } | |
641 return (jobjectArray) JNIHandles::make_local(env, mgrArray()); | |
642 JVM_END | |
643 | |
644 | |
645 // Returns a java/lang/management/MemoryUsage object containing the memory usage | |
646 // of a given memory pool. | |
647 JVM_ENTRY(jobject, jmm_GetMemoryPoolUsage(JNIEnv* env, jobject obj)) | |
648 ResourceMark rm(THREAD); | |
649 | |
650 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL); | |
651 if (pool != NULL) { | |
652 MemoryUsage usage = pool->get_memory_usage(); | |
653 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL); | |
654 return JNIHandles::make_local(env, h()); | |
655 } else { | |
656 return NULL; | |
657 } | |
658 JVM_END | |
659 | |
660 // Returns a java/lang/management/MemoryUsage object containing the memory usage | |
661 // of a given memory pool. | |
662 JVM_ENTRY(jobject, jmm_GetPeakMemoryPoolUsage(JNIEnv* env, jobject obj)) | |
663 ResourceMark rm(THREAD); | |
664 | |
665 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL); | |
666 if (pool != NULL) { | |
667 MemoryUsage usage = pool->get_peak_memory_usage(); | |
668 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL); | |
669 return JNIHandles::make_local(env, h()); | |
670 } else { | |
671 return NULL; | |
672 } | |
673 JVM_END | |
674 | |
675 // Returns a java/lang/management/MemoryUsage object containing the memory usage | |
676 // of a given memory pool after most recent GC. | |
677 JVM_ENTRY(jobject, jmm_GetPoolCollectionUsage(JNIEnv* env, jobject obj)) | |
678 ResourceMark rm(THREAD); | |
679 | |
680 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL); | |
681 if (pool != NULL && pool->is_collected_pool()) { | |
682 MemoryUsage usage = pool->get_last_collection_usage(); | |
683 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL); | |
684 return JNIHandles::make_local(env, h()); | |
685 } else { | |
686 return NULL; | |
687 } | |
688 JVM_END | |
689 | |
690 // Sets the memory pool sensor for a threshold type | |
691 JVM_ENTRY(void, jmm_SetPoolSensor(JNIEnv* env, jobject obj, jmmThresholdType type, jobject sensorObj)) | |
692 if (obj == NULL || sensorObj == NULL) { | |
693 THROW(vmSymbols::java_lang_NullPointerException()); | |
694 } | |
695 | |
696 klassOop sensor_klass = Management::sun_management_Sensor_klass(CHECK); | |
697 oop s = JNIHandles::resolve(sensorObj); | |
698 assert(s->is_instance(), "Sensor should be an instanceOop"); | |
699 instanceHandle sensor_h(THREAD, (instanceOop) s); | |
700 if (!sensor_h->is_a(sensor_klass)) { | |
701 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
702 "Sensor is not an instance of sun.management.Sensor class"); | |
703 } | |
704 | |
705 MemoryPool* mpool = get_memory_pool_from_jobject(obj, CHECK); | |
706 assert(mpool != NULL, "MemoryPool should exist"); | |
707 | |
708 switch (type) { | |
709 case JMM_USAGE_THRESHOLD_HIGH: | |
710 case JMM_USAGE_THRESHOLD_LOW: | |
711 // have only one sensor for threshold high and low | |
712 mpool->set_usage_sensor_obj(sensor_h); | |
713 break; | |
714 case JMM_COLLECTION_USAGE_THRESHOLD_HIGH: | |
715 case JMM_COLLECTION_USAGE_THRESHOLD_LOW: | |
716 // have only one sensor for threshold high and low | |
717 mpool->set_gc_usage_sensor_obj(sensor_h); | |
718 break; | |
719 default: | |
720 assert(false, "Unrecognized type"); | |
721 } | |
722 | |
723 JVM_END | |
724 | |
725 | |
726 // Sets the threshold of a given memory pool. | |
727 // Returns the previous threshold. | |
728 // | |
729 // Input parameters: | |
730 // pool - the MemoryPoolMXBean object | |
731 // type - threshold type | |
732 // threshold - the new threshold (must not be negative) | |
733 // | |
734 JVM_ENTRY(jlong, jmm_SetPoolThreshold(JNIEnv* env, jobject obj, jmmThresholdType type, jlong threshold)) | |
735 if (threshold < 0) { | |
736 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
737 "Invalid threshold value", | |
738 -1); | |
739 } | |
740 | |
489
2494ab195856
6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents:
350
diff
changeset
|
741 if ((size_t)threshold > max_uintx) { |
2494ab195856
6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents:
350
diff
changeset
|
742 stringStream st; |
2494ab195856
6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents:
350
diff
changeset
|
743 st.print("Invalid valid threshold value. Threshold value (" UINT64_FORMAT ") > max value of size_t (" SIZE_FORMAT ")", (size_t)threshold, max_uintx); |
2494ab195856
6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents:
350
diff
changeset
|
744 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), st.as_string(), -1); |
0 | 745 } |
746 | |
747 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_(0L)); | |
748 assert(pool != NULL, "MemoryPool should exist"); | |
749 | |
750 jlong prev = 0; | |
751 switch (type) { | |
752 case JMM_USAGE_THRESHOLD_HIGH: | |
753 if (!pool->usage_threshold()->is_high_threshold_supported()) { | |
754 return -1; | |
755 } | |
756 prev = pool->usage_threshold()->set_high_threshold((size_t) threshold); | |
757 break; | |
758 | |
759 case JMM_USAGE_THRESHOLD_LOW: | |
760 if (!pool->usage_threshold()->is_low_threshold_supported()) { | |
761 return -1; | |
762 } | |
763 prev = pool->usage_threshold()->set_low_threshold((size_t) threshold); | |
764 break; | |
765 | |
766 case JMM_COLLECTION_USAGE_THRESHOLD_HIGH: | |
767 if (!pool->gc_usage_threshold()->is_high_threshold_supported()) { | |
768 return -1; | |
769 } | |
770 // return and the new threshold is effective for the next GC | |
771 return pool->gc_usage_threshold()->set_high_threshold((size_t) threshold); | |
772 | |
773 case JMM_COLLECTION_USAGE_THRESHOLD_LOW: | |
774 if (!pool->gc_usage_threshold()->is_low_threshold_supported()) { | |
775 return -1; | |
776 } | |
777 // return and the new threshold is effective for the next GC | |
778 return pool->gc_usage_threshold()->set_low_threshold((size_t) threshold); | |
779 | |
780 default: | |
781 assert(false, "Unrecognized type"); | |
782 return -1; | |
783 } | |
784 | |
785 // When the threshold is changed, reevaluate if the low memory | |
786 // detection is enabled. | |
787 if (prev != threshold) { | |
788 LowMemoryDetector::recompute_enabled_for_collected_pools(); | |
789 LowMemoryDetector::detect_low_memory(pool); | |
790 } | |
791 return prev; | |
792 JVM_END | |
793 | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
794 // Gets an array containing the amount of memory allocated on the Java |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
795 // heap for a set of threads (in bytes). Each element of the array is |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
796 // the amount of memory allocated for the thread ID specified in the |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
797 // corresponding entry in the given array of thread IDs; or -1 if the |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
798 // thread does not exist or has terminated. |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
799 JVM_ENTRY(void, jmm_GetThreadAllocatedMemory(JNIEnv *env, jlongArray ids, |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
800 jlongArray sizeArray)) |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
801 // Check if threads is null |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
802 if (ids == NULL || sizeArray == NULL) { |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
803 THROW(vmSymbols::java_lang_NullPointerException()); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
804 } |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
805 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
806 ResourceMark rm(THREAD); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
807 typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids)); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
808 typeArrayHandle ids_ah(THREAD, ta); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
809 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
810 typeArrayOop sa = typeArrayOop(JNIHandles::resolve_non_null(sizeArray)); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
811 typeArrayHandle sizeArray_h(THREAD, sa); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
812 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
813 // validate the thread id array |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
814 validate_thread_id_array(ids_ah, CHECK); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
815 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
816 // sizeArray must be of the same length as the given array of thread IDs |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
817 int num_threads = ids_ah->length(); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
818 if (num_threads != sizeArray_h->length()) { |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
819 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
820 "The length of the given long array does not match the length of " |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
821 "the given array of thread IDs"); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
822 } |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
823 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
824 MutexLockerEx ml(Threads_lock); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
825 for (int i = 0; i < num_threads; i++) { |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
826 JavaThread* java_thread = find_java_thread_from_id(ids_ah->long_at(i)); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
827 if (java_thread != NULL) { |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
828 sizeArray_h->long_at_put(i, java_thread->cooked_allocated_bytes()); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
829 } |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
830 } |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
831 JVM_END |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
832 |
0 | 833 // Returns a java/lang/management/MemoryUsage object representing |
834 // the memory usage for the heap or non-heap memory. | |
835 JVM_ENTRY(jobject, jmm_GetMemoryUsage(JNIEnv* env, jboolean heap)) | |
836 ResourceMark rm(THREAD); | |
837 | |
838 // Calculate the memory usage | |
839 size_t total_init = 0; | |
840 size_t total_used = 0; | |
841 size_t total_committed = 0; | |
842 size_t total_max = 0; | |
843 bool has_undefined_init_size = false; | |
844 bool has_undefined_max_size = false; | |
845 | |
846 for (int i = 0; i < MemoryService::num_memory_pools(); i++) { | |
847 MemoryPool* pool = MemoryService::get_memory_pool(i); | |
848 if ((heap && pool->is_heap()) || (!heap && pool->is_non_heap())) { | |
849 MemoryUsage u = pool->get_memory_usage(); | |
850 total_used += u.used(); | |
851 total_committed += u.committed(); | |
852 | |
853 // if any one of the memory pool has undefined init_size or max_size, | |
854 // set it to -1 | |
855 if (u.init_size() == (size_t)-1) { | |
856 has_undefined_init_size = true; | |
857 } | |
858 if (!has_undefined_init_size) { | |
859 total_init += u.init_size(); | |
860 } | |
861 | |
862 if (u.max_size() == (size_t)-1) { | |
863 has_undefined_max_size = true; | |
864 } | |
865 if (!has_undefined_max_size) { | |
866 total_max += u.max_size(); | |
867 } | |
868 } | |
869 } | |
870 | |
1757
1c63587d925b
6980206: G1: assert(has_undefined_max_size, "Undefined max size");
tonyp
parents:
1703
diff
changeset
|
871 // In our current implementation, we make sure that all non-heap |
1c63587d925b
6980206: G1: assert(has_undefined_max_size, "Undefined max size");
tonyp
parents:
1703
diff
changeset
|
872 // pools have defined init and max sizes. Heap pools do not matter, |
1c63587d925b
6980206: G1: assert(has_undefined_max_size, "Undefined max size");
tonyp
parents:
1703
diff
changeset
|
873 // as we never use total_init and total_max for them. |
1c63587d925b
6980206: G1: assert(has_undefined_max_size, "Undefined max size");
tonyp
parents:
1703
diff
changeset
|
874 assert(heap || !has_undefined_init_size, "Undefined init size"); |
1c63587d925b
6980206: G1: assert(has_undefined_max_size, "Undefined max size");
tonyp
parents:
1703
diff
changeset
|
875 assert(heap || !has_undefined_max_size, "Undefined max size"); |
0 | 876 |
1064 | 877 MemoryUsage usage((heap ? InitialHeapSize : total_init), |
0 | 878 total_used, |
879 total_committed, | |
880 (heap ? Universe::heap()->max_capacity() : total_max)); | |
881 | |
882 Handle obj = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL); | |
883 return JNIHandles::make_local(env, obj()); | |
884 JVM_END | |
885 | |
886 // Returns the boolean value of a given attribute. | |
887 JVM_LEAF(jboolean, jmm_GetBoolAttribute(JNIEnv *env, jmmBoolAttribute att)) | |
888 switch (att) { | |
889 case JMM_VERBOSE_GC: | |
890 return MemoryService::get_verbose(); | |
891 case JMM_VERBOSE_CLASS: | |
892 return ClassLoadingService::get_verbose(); | |
893 case JMM_THREAD_CONTENTION_MONITORING: | |
894 return ThreadService::is_thread_monitoring_contention(); | |
895 case JMM_THREAD_CPU_TIME: | |
896 return ThreadService::is_thread_cpu_time_enabled(); | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
897 case JMM_THREAD_ALLOCATED_MEMORY: |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
898 return ThreadService::is_thread_allocated_memory_enabled(); |
0 | 899 default: |
900 assert(0, "Unrecognized attribute"); | |
901 return false; | |
902 } | |
903 JVM_END | |
904 | |
905 // Sets the given boolean attribute and returns the previous value. | |
906 JVM_ENTRY(jboolean, jmm_SetBoolAttribute(JNIEnv *env, jmmBoolAttribute att, jboolean flag)) | |
907 switch (att) { | |
908 case JMM_VERBOSE_GC: | |
909 return MemoryService::set_verbose(flag != 0); | |
910 case JMM_VERBOSE_CLASS: | |
911 return ClassLoadingService::set_verbose(flag != 0); | |
912 case JMM_THREAD_CONTENTION_MONITORING: | |
913 return ThreadService::set_thread_monitoring_contention(flag != 0); | |
914 case JMM_THREAD_CPU_TIME: | |
915 return ThreadService::set_thread_cpu_time_enabled(flag != 0); | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
916 case JMM_THREAD_ALLOCATED_MEMORY: |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
917 return ThreadService::set_thread_allocated_memory_enabled(flag != 0); |
0 | 918 default: |
919 assert(0, "Unrecognized attribute"); | |
920 return false; | |
921 } | |
922 JVM_END | |
923 | |
924 | |
925 static jlong get_gc_attribute(GCMemoryManager* mgr, jmmLongAttribute att) { | |
926 switch (att) { | |
927 case JMM_GC_TIME_MS: | |
928 return mgr->gc_time_ms(); | |
929 | |
930 case JMM_GC_COUNT: | |
931 return mgr->gc_count(); | |
932 | |
933 case JMM_GC_EXT_ATTRIBUTE_INFO_SIZE: | |
934 // current implementation only has 1 ext attribute | |
935 return 1; | |
936 | |
937 default: | |
938 assert(0, "Unrecognized GC attribute"); | |
939 return -1; | |
940 } | |
941 } | |
942 | |
943 class VmThreadCountClosure: public ThreadClosure { | |
944 private: | |
945 int _count; | |
946 public: | |
947 VmThreadCountClosure() : _count(0) {}; | |
948 void do_thread(Thread* thread); | |
949 int count() { return _count; } | |
950 }; | |
951 | |
952 void VmThreadCountClosure::do_thread(Thread* thread) { | |
953 // exclude externally visible JavaThreads | |
954 if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) { | |
955 return; | |
956 } | |
957 | |
958 _count++; | |
959 } | |
960 | |
961 static jint get_vm_thread_count() { | |
962 VmThreadCountClosure vmtcc; | |
963 { | |
964 MutexLockerEx ml(Threads_lock); | |
965 Threads::threads_do(&vmtcc); | |
966 } | |
967 | |
968 return vmtcc.count(); | |
969 } | |
970 | |
971 static jint get_num_flags() { | |
972 // last flag entry is always NULL, so subtract 1 | |
973 int nFlags = (int) Flag::numFlags - 1; | |
974 int count = 0; | |
975 for (int i = 0; i < nFlags; i++) { | |
976 Flag* flag = &Flag::flags[i]; | |
350 | 977 // Exclude the locked (diagnostic, experimental) flags |
0 | 978 if (flag->is_unlocked() || flag->is_unlocker()) { |
979 count++; | |
980 } | |
981 } | |
982 return count; | |
983 } | |
984 | |
985 static jlong get_long_attribute(jmmLongAttribute att) { | |
986 switch (att) { | |
987 case JMM_CLASS_LOADED_COUNT: | |
988 return ClassLoadingService::loaded_class_count(); | |
989 | |
990 case JMM_CLASS_UNLOADED_COUNT: | |
991 return ClassLoadingService::unloaded_class_count(); | |
992 | |
993 case JMM_THREAD_TOTAL_COUNT: | |
994 return ThreadService::get_total_thread_count(); | |
995 | |
996 case JMM_THREAD_LIVE_COUNT: | |
997 return ThreadService::get_live_thread_count(); | |
998 | |
999 case JMM_THREAD_PEAK_COUNT: | |
1000 return ThreadService::get_peak_thread_count(); | |
1001 | |
1002 case JMM_THREAD_DAEMON_COUNT: | |
1003 return ThreadService::get_daemon_thread_count(); | |
1004 | |
1005 case JMM_JVM_INIT_DONE_TIME_MS: | |
1006 return Management::vm_init_done_time(); | |
1007 | |
1008 case JMM_COMPILE_TOTAL_TIME_MS: | |
1009 return Management::ticks_to_ms(CompileBroker::total_compilation_ticks()); | |
1010 | |
1011 case JMM_OS_PROCESS_ID: | |
1012 return os::current_process_id(); | |
1013 | |
1014 // Hotspot-specific counters | |
1015 case JMM_CLASS_LOADED_BYTES: | |
1016 return ClassLoadingService::loaded_class_bytes(); | |
1017 | |
1018 case JMM_CLASS_UNLOADED_BYTES: | |
1019 return ClassLoadingService::unloaded_class_bytes(); | |
1020 | |
1021 case JMM_SHARED_CLASS_LOADED_COUNT: | |
1022 return ClassLoadingService::loaded_shared_class_count(); | |
1023 | |
1024 case JMM_SHARED_CLASS_UNLOADED_COUNT: | |
1025 return ClassLoadingService::unloaded_shared_class_count(); | |
1026 | |
1027 | |
1028 case JMM_SHARED_CLASS_LOADED_BYTES: | |
1029 return ClassLoadingService::loaded_shared_class_bytes(); | |
1030 | |
1031 case JMM_SHARED_CLASS_UNLOADED_BYTES: | |
1032 return ClassLoadingService::unloaded_shared_class_bytes(); | |
1033 | |
1034 case JMM_TOTAL_CLASSLOAD_TIME_MS: | |
1035 return ClassLoader::classloader_time_ms(); | |
1036 | |
1037 case JMM_VM_GLOBAL_COUNT: | |
1038 return get_num_flags(); | |
1039 | |
1040 case JMM_SAFEPOINT_COUNT: | |
1041 return RuntimeService::safepoint_count(); | |
1042 | |
1043 case JMM_TOTAL_SAFEPOINTSYNC_TIME_MS: | |
1044 return RuntimeService::safepoint_sync_time_ms(); | |
1045 | |
1046 case JMM_TOTAL_STOPPED_TIME_MS: | |
1047 return RuntimeService::safepoint_time_ms(); | |
1048 | |
1049 case JMM_TOTAL_APP_TIME_MS: | |
1050 return RuntimeService::application_time_ms(); | |
1051 | |
1052 case JMM_VM_THREAD_COUNT: | |
1053 return get_vm_thread_count(); | |
1054 | |
1055 case JMM_CLASS_INIT_TOTAL_COUNT: | |
1056 return ClassLoader::class_init_count(); | |
1057 | |
1058 case JMM_CLASS_INIT_TOTAL_TIME_MS: | |
1059 return ClassLoader::class_init_time_ms(); | |
1060 | |
1061 case JMM_CLASS_VERIFY_TOTAL_TIME_MS: | |
1062 return ClassLoader::class_verify_time_ms(); | |
1063 | |
1064 case JMM_METHOD_DATA_SIZE_BYTES: | |
1065 return ClassLoadingService::class_method_data_size(); | |
1066 | |
1067 case JMM_OS_MEM_TOTAL_PHYSICAL_BYTES: | |
1068 return os::physical_memory(); | |
1069 | |
1070 default: | |
1071 return -1; | |
1072 } | |
1073 } | |
1074 | |
1075 | |
1076 // Returns the long value of a given attribute. | |
1077 JVM_ENTRY(jlong, jmm_GetLongAttribute(JNIEnv *env, jobject obj, jmmLongAttribute att)) | |
1078 if (obj == NULL) { | |
1079 return get_long_attribute(att); | |
1080 } else { | |
1081 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK_(0L)); | |
1082 if (mgr != NULL) { | |
1083 return get_gc_attribute(mgr, att); | |
1084 } | |
1085 } | |
1086 return -1; | |
1087 JVM_END | |
1088 | |
1089 // Gets the value of all attributes specified in the given array | |
1090 // and sets the value in the result array. | |
1091 // Returns the number of attributes found. | |
1092 JVM_ENTRY(jint, jmm_GetLongAttributes(JNIEnv *env, | |
1093 jobject obj, | |
1094 jmmLongAttribute* atts, | |
1095 jint count, | |
1096 jlong* result)) | |
1097 | |
1098 int num_atts = 0; | |
1099 if (obj == NULL) { | |
1100 for (int i = 0; i < count; i++) { | |
1101 result[i] = get_long_attribute(atts[i]); | |
1102 if (result[i] != -1) { | |
1103 num_atts++; | |
1104 } | |
1105 } | |
1106 } else { | |
1107 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK_0); | |
1108 for (int i = 0; i < count; i++) { | |
1109 result[i] = get_gc_attribute(mgr, atts[i]); | |
1110 if (result[i] != -1) { | |
1111 num_atts++; | |
1112 } | |
1113 } | |
1114 } | |
1115 return num_atts; | |
1116 JVM_END | |
1117 | |
1118 // Helper function to do thread dump for a specific list of threads | |
1119 static void do_thread_dump(ThreadDumpResult* dump_result, | |
1120 typeArrayHandle ids_ah, // array of thread ID (long[]) | |
1121 int num_threads, | |
1122 int max_depth, | |
1123 bool with_locked_monitors, | |
1124 bool with_locked_synchronizers, | |
1125 TRAPS) { | |
1126 | |
1127 // First get an array of threadObj handles. | |
1128 // A JavaThread may terminate before we get the stack trace. | |
1129 GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads); | |
1130 { | |
1131 MutexLockerEx ml(Threads_lock); | |
1132 for (int i = 0; i < num_threads; i++) { | |
1133 jlong tid = ids_ah->long_at(i); | |
1134 JavaThread* jt = find_java_thread_from_id(tid); | |
1135 oop thread_obj = (jt != NULL ? jt->threadObj() : (oop)NULL); | |
1136 instanceHandle threadObj_h(THREAD, (instanceOop) thread_obj); | |
1137 thread_handle_array->append(threadObj_h); | |
1138 } | |
1139 } | |
1140 | |
1141 // Obtain thread dumps and thread snapshot information | |
1142 VM_ThreadDump op(dump_result, | |
1143 thread_handle_array, | |
1144 num_threads, | |
1145 max_depth, /* stack depth */ | |
1146 with_locked_monitors, | |
1147 with_locked_synchronizers); | |
1148 VMThread::execute(&op); | |
1149 } | |
1150 | |
1151 // Gets an array of ThreadInfo objects. Each element is the ThreadInfo | |
1152 // for the thread ID specified in the corresponding entry in | |
1153 // the given array of thread IDs; or NULL if the thread does not exist | |
1154 // or has terminated. | |
1155 // | |
1156 // Input parameters: | |
1157 // ids - array of thread IDs | |
1158 // maxDepth - the maximum depth of stack traces to be dumped: | |
1159 // maxDepth == -1 requests to dump entire stack trace. | |
1160 // maxDepth == 0 requests no stack trace. | |
1161 // infoArray - array of ThreadInfo objects | |
1162 // | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1163 // QQQ - Why does this method return a value instead of void? |
0 | 1164 JVM_ENTRY(jint, jmm_GetThreadInfo(JNIEnv *env, jlongArray ids, jint maxDepth, jobjectArray infoArray)) |
1165 // Check if threads is null | |
1166 if (ids == NULL || infoArray == NULL) { | |
1167 THROW_(vmSymbols::java_lang_NullPointerException(), -1); | |
1168 } | |
1169 | |
1170 if (maxDepth < -1) { | |
1171 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1172 "Invalid maxDepth", -1); | |
1173 } | |
1174 | |
1175 ResourceMark rm(THREAD); | |
1176 typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids)); | |
1177 typeArrayHandle ids_ah(THREAD, ta); | |
1178 | |
1179 oop infoArray_obj = JNIHandles::resolve_non_null(infoArray); | |
1180 objArrayOop oa = objArrayOop(infoArray_obj); | |
1181 objArrayHandle infoArray_h(THREAD, oa); | |
1182 | |
1183 // validate the thread id array | |
1184 validate_thread_id_array(ids_ah, CHECK_0); | |
1185 | |
1186 // validate the ThreadInfo[] parameters | |
1187 validate_thread_info_array(infoArray_h, CHECK_0); | |
1188 | |
1189 // infoArray must be of the same length as the given array of thread IDs | |
1190 int num_threads = ids_ah->length(); | |
1191 if (num_threads != infoArray_h->length()) { | |
1192 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1193 "The length of the given ThreadInfo array does not match the length of the given array of thread IDs", -1); | |
1194 } | |
1195 | |
1196 if (JDK_Version::is_gte_jdk16x_version()) { | |
1197 // make sure the AbstractOwnableSynchronizer klass is loaded before taking thread snapshots | |
1198 java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(CHECK_0); | |
1199 } | |
1200 | |
1201 // Must use ThreadDumpResult to store the ThreadSnapshot. | |
1202 // GC may occur after the thread snapshots are taken but before | |
1203 // this function returns. The threadObj and other oops kept | |
1204 // in the ThreadSnapshot are marked and adjusted during GC. | |
1205 ThreadDumpResult dump_result(num_threads); | |
1206 | |
1207 if (maxDepth == 0) { | |
1208 // no stack trace dumped - do not need to stop the world | |
1209 { | |
1210 MutexLockerEx ml(Threads_lock); | |
1211 for (int i = 0; i < num_threads; i++) { | |
1212 jlong tid = ids_ah->long_at(i); | |
1213 JavaThread* jt = find_java_thread_from_id(tid); | |
1214 ThreadSnapshot* ts; | |
1215 if (jt == NULL) { | |
1216 // if the thread does not exist or now it is terminated, | |
1217 // create dummy snapshot | |
1218 ts = new ThreadSnapshot(); | |
1219 } else { | |
1220 ts = new ThreadSnapshot(jt); | |
1221 } | |
1222 dump_result.add_thread_snapshot(ts); | |
1223 } | |
1224 } | |
1225 } else { | |
1226 // obtain thread dump with the specific list of threads with stack trace | |
1227 do_thread_dump(&dump_result, | |
1228 ids_ah, | |
1229 num_threads, | |
1230 maxDepth, | |
1231 false, /* no locked monitor */ | |
1232 false, /* no locked synchronizers */ | |
1233 CHECK_0); | |
1234 } | |
1235 | |
1236 int num_snapshots = dump_result.num_snapshots(); | |
1237 assert(num_snapshots == num_threads, "Must match the number of thread snapshots"); | |
1238 int index = 0; | |
1239 for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; index++, ts = ts->next()) { | |
1240 // For each thread, create an java/lang/management/ThreadInfo object | |
1241 // and fill with the thread information | |
1242 | |
1243 if (ts->threadObj() == NULL) { | |
1244 // if the thread does not exist or now it is terminated, set threadinfo to NULL | |
1245 infoArray_h->obj_at_put(index, NULL); | |
1246 continue; | |
1247 } | |
1248 | |
1249 // Create java.lang.management.ThreadInfo object | |
1250 instanceOop info_obj = Management::create_thread_info_instance(ts, CHECK_0); | |
1251 infoArray_h->obj_at_put(index, info_obj); | |
1252 } | |
1253 return 0; | |
1254 JVM_END | |
1255 | |
1256 // Dump thread info for the specified threads. | |
1257 // It returns an array of ThreadInfo objects. Each element is the ThreadInfo | |
1258 // for the thread ID specified in the corresponding entry in | |
1259 // the given array of thread IDs; or NULL if the thread does not exist | |
1260 // or has terminated. | |
1261 // | |
1262 // Input parameter: | |
1263 // ids - array of thread IDs; NULL indicates all live threads | |
1264 // locked_monitors - if true, dump locked object monitors | |
1265 // locked_synchronizers - if true, dump locked JSR-166 synchronizers | |
1266 // | |
1267 JVM_ENTRY(jobjectArray, jmm_DumpThreads(JNIEnv *env, jlongArray thread_ids, jboolean locked_monitors, jboolean locked_synchronizers)) | |
1268 ResourceMark rm(THREAD); | |
1269 | |
1270 if (JDK_Version::is_gte_jdk16x_version()) { | |
1271 // make sure the AbstractOwnableSynchronizer klass is loaded before taking thread snapshots | |
1272 java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(CHECK_NULL); | |
1273 } | |
1274 | |
1275 typeArrayOop ta = typeArrayOop(JNIHandles::resolve(thread_ids)); | |
1276 int num_threads = (ta != NULL ? ta->length() : 0); | |
1277 typeArrayHandle ids_ah(THREAD, ta); | |
1278 | |
1279 ThreadDumpResult dump_result(num_threads); // can safepoint | |
1280 | |
1281 if (ids_ah() != NULL) { | |
1282 | |
1283 // validate the thread id array | |
1284 validate_thread_id_array(ids_ah, CHECK_NULL); | |
1285 | |
1286 // obtain thread dump of a specific list of threads | |
1287 do_thread_dump(&dump_result, | |
1288 ids_ah, | |
1289 num_threads, | |
1290 -1, /* entire stack */ | |
1291 (locked_monitors ? true : false), /* with locked monitors */ | |
1292 (locked_synchronizers ? true : false), /* with locked synchronizers */ | |
1293 CHECK_NULL); | |
1294 } else { | |
1295 // obtain thread dump of all threads | |
1296 VM_ThreadDump op(&dump_result, | |
1297 -1, /* entire stack */ | |
1298 (locked_monitors ? true : false), /* with locked monitors */ | |
1299 (locked_synchronizers ? true : false) /* with locked synchronizers */); | |
1300 VMThread::execute(&op); | |
1301 } | |
1302 | |
1303 int num_snapshots = dump_result.num_snapshots(); | |
1304 | |
1305 // create the result ThreadInfo[] object | |
1306 klassOop k = Management::java_lang_management_ThreadInfo_klass(CHECK_NULL); | |
1307 instanceKlassHandle ik (THREAD, k); | |
1308 objArrayOop r = oopFactory::new_objArray(ik(), num_snapshots, CHECK_NULL); | |
1309 objArrayHandle result_h(THREAD, r); | |
1310 | |
1311 int index = 0; | |
1312 for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; ts = ts->next(), index++) { | |
1313 if (ts->threadObj() == NULL) { | |
1314 // if the thread does not exist or now it is terminated, set threadinfo to NULL | |
1315 result_h->obj_at_put(index, NULL); | |
1316 continue; | |
1317 } | |
1318 | |
1319 ThreadStackTrace* stacktrace = ts->get_stack_trace(); | |
1320 assert(stacktrace != NULL, "Must have a stack trace dumped"); | |
1321 | |
1322 // Create Object[] filled with locked monitors | |
1323 // Create int[] filled with the stack depth where a monitor was locked | |
1324 int num_frames = stacktrace->get_stack_depth(); | |
1325 int num_locked_monitors = stacktrace->num_jni_locked_monitors(); | |
1326 | |
1327 // Count the total number of locked monitors | |
1328 for (int i = 0; i < num_frames; i++) { | |
1329 StackFrameInfo* frame = stacktrace->stack_frame_at(i); | |
1330 num_locked_monitors += frame->num_locked_monitors(); | |
1331 } | |
1332 | |
1333 objArrayHandle monitors_array; | |
1334 typeArrayHandle depths_array; | |
1335 objArrayHandle synchronizers_array; | |
1336 | |
1337 if (locked_monitors) { | |
1338 // Constructs Object[] and int[] to contain the object monitor and the stack depth | |
1339 // where the thread locked it | |
2267
02f78cfa4656
7020992: jmm_DumpThreads should not allocate system object arrays outside the perm gen
stefank
parents:
2231
diff
changeset
|
1340 objArrayOop array = oopFactory::new_objArray(SystemDictionary::Object_klass(), num_locked_monitors, CHECK_NULL); |
0 | 1341 objArrayHandle mh(THREAD, array); |
1342 monitors_array = mh; | |
1343 | |
1344 typeArrayOop tarray = oopFactory::new_typeArray(T_INT, num_locked_monitors, CHECK_NULL); | |
1345 typeArrayHandle dh(THREAD, tarray); | |
1346 depths_array = dh; | |
1347 | |
1348 int count = 0; | |
1349 int j = 0; | |
1350 for (int depth = 0; depth < num_frames; depth++) { | |
1351 StackFrameInfo* frame = stacktrace->stack_frame_at(depth); | |
1352 int len = frame->num_locked_monitors(); | |
1353 GrowableArray<oop>* locked_monitors = frame->locked_monitors(); | |
1354 for (j = 0; j < len; j++) { | |
1355 oop monitor = locked_monitors->at(j); | |
1356 assert(monitor != NULL && monitor->is_instance(), "must be a Java object"); | |
1357 monitors_array->obj_at_put(count, monitor); | |
1358 depths_array->int_at_put(count, depth); | |
1359 count++; | |
1360 } | |
1361 } | |
1362 | |
1363 GrowableArray<oop>* jni_locked_monitors = stacktrace->jni_locked_monitors(); | |
1364 for (j = 0; j < jni_locked_monitors->length(); j++) { | |
1365 oop object = jni_locked_monitors->at(j); | |
1366 assert(object != NULL && object->is_instance(), "must be a Java object"); | |
1367 monitors_array->obj_at_put(count, object); | |
1368 // Monitor locked via JNI MonitorEnter call doesn't have stack depth info | |
1369 depths_array->int_at_put(count, -1); | |
1370 count++; | |
1371 } | |
1372 assert(count == num_locked_monitors, "number of locked monitors doesn't match"); | |
1373 } | |
1374 | |
1375 if (locked_synchronizers) { | |
1376 // Create Object[] filled with locked JSR-166 synchronizers | |
1377 assert(ts->threadObj() != NULL, "Must be a valid JavaThread"); | |
1378 ThreadConcurrentLocks* tcl = ts->get_concurrent_locks(); | |
1379 GrowableArray<instanceOop>* locks = (tcl != NULL ? tcl->owned_locks() : NULL); | |
1380 int num_locked_synchronizers = (locks != NULL ? locks->length() : 0); | |
1381 | |
2267
02f78cfa4656
7020992: jmm_DumpThreads should not allocate system object arrays outside the perm gen
stefank
parents:
2231
diff
changeset
|
1382 objArrayOop array = oopFactory::new_objArray(SystemDictionary::Object_klass(), num_locked_synchronizers, CHECK_NULL); |
0 | 1383 objArrayHandle sh(THREAD, array); |
1384 synchronizers_array = sh; | |
1385 | |
1386 for (int k = 0; k < num_locked_synchronizers; k++) { | |
1387 synchronizers_array->obj_at_put(k, locks->at(k)); | |
1388 } | |
1389 } | |
1390 | |
1391 // Create java.lang.management.ThreadInfo object | |
1392 instanceOop info_obj = Management::create_thread_info_instance(ts, | |
1393 monitors_array, | |
1394 depths_array, | |
1395 synchronizers_array, | |
1396 CHECK_NULL); | |
1397 result_h->obj_at_put(index, info_obj); | |
1398 } | |
1399 | |
1400 return (jobjectArray) JNIHandles::make_local(env, result_h()); | |
1401 JVM_END | |
1402 | |
1403 // Returns an array of Class objects. | |
1404 JVM_ENTRY(jobjectArray, jmm_GetLoadedClasses(JNIEnv *env)) | |
1405 ResourceMark rm(THREAD); | |
1406 | |
1407 LoadedClassesEnumerator lce(THREAD); // Pass current Thread as parameter | |
1408 | |
1409 int num_classes = lce.num_loaded_classes(); | |
1142 | 1410 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), num_classes, CHECK_0); |
0 | 1411 objArrayHandle classes_ah(THREAD, r); |
1412 | |
1413 for (int i = 0; i < num_classes; i++) { | |
1414 KlassHandle kh = lce.get_klass(i); | |
1415 oop mirror = Klass::cast(kh())->java_mirror(); | |
1416 classes_ah->obj_at_put(i, mirror); | |
1417 } | |
1418 | |
1419 return (jobjectArray) JNIHandles::make_local(env, classes_ah()); | |
1420 JVM_END | |
1421 | |
1422 // Reset statistic. Return true if the requested statistic is reset. | |
1423 // Otherwise, return false. | |
1424 // | |
1425 // Input parameters: | |
1426 // obj - specify which instance the statistic associated with to be reset | |
1427 // For PEAK_POOL_USAGE stat, obj is required to be a memory pool object. | |
1428 // For THREAD_CONTENTION_COUNT and TIME stat, obj is required to be a thread ID. | |
1429 // type - the type of statistic to be reset | |
1430 // | |
1431 JVM_ENTRY(jboolean, jmm_ResetStatistic(JNIEnv *env, jvalue obj, jmmStatisticType type)) | |
1432 ResourceMark rm(THREAD); | |
1433 | |
1434 switch (type) { | |
1435 case JMM_STAT_PEAK_THREAD_COUNT: | |
1436 ThreadService::reset_peak_thread_count(); | |
1437 return true; | |
1438 | |
1439 case JMM_STAT_THREAD_CONTENTION_COUNT: | |
1440 case JMM_STAT_THREAD_CONTENTION_TIME: { | |
1441 jlong tid = obj.j; | |
1442 if (tid < 0) { | |
1443 THROW_(vmSymbols::java_lang_IllegalArgumentException(), JNI_FALSE); | |
1444 } | |
1445 | |
1446 // Look for the JavaThread of this given tid | |
1447 MutexLockerEx ml(Threads_lock); | |
1448 if (tid == 0) { | |
1449 // reset contention statistics for all threads if tid == 0 | |
1450 for (JavaThread* java_thread = Threads::first(); java_thread != NULL; java_thread = java_thread->next()) { | |
1451 if (type == JMM_STAT_THREAD_CONTENTION_COUNT) { | |
1452 ThreadService::reset_contention_count_stat(java_thread); | |
1453 } else { | |
1454 ThreadService::reset_contention_time_stat(java_thread); | |
1455 } | |
1456 } | |
1457 } else { | |
1458 // reset contention statistics for a given thread | |
1459 JavaThread* java_thread = find_java_thread_from_id(tid); | |
1460 if (java_thread == NULL) { | |
1461 return false; | |
1462 } | |
1463 | |
1464 if (type == JMM_STAT_THREAD_CONTENTION_COUNT) { | |
1465 ThreadService::reset_contention_count_stat(java_thread); | |
1466 } else { | |
1467 ThreadService::reset_contention_time_stat(java_thread); | |
1468 } | |
1469 } | |
1470 return true; | |
1471 break; | |
1472 } | |
1473 case JMM_STAT_PEAK_POOL_USAGE: { | |
1474 jobject o = obj.l; | |
1475 if (o == NULL) { | |
1476 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE); | |
1477 } | |
1478 | |
1479 oop pool_obj = JNIHandles::resolve(o); | |
1480 assert(pool_obj->is_instance(), "Should be an instanceOop"); | |
1481 instanceHandle ph(THREAD, (instanceOop) pool_obj); | |
1482 | |
1483 MemoryPool* pool = MemoryService::get_memory_pool(ph); | |
1484 if (pool != NULL) { | |
1485 pool->reset_peak_memory_usage(); | |
1486 return true; | |
1487 } | |
1488 break; | |
1489 } | |
1490 case JMM_STAT_GC_STAT: { | |
1491 jobject o = obj.l; | |
1492 if (o == NULL) { | |
1493 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE); | |
1494 } | |
1495 | |
1496 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(o, CHECK_0); | |
1497 if (mgr != NULL) { | |
1498 mgr->reset_gc_stat(); | |
1499 return true; | |
1500 } | |
1501 break; | |
1502 } | |
1503 default: | |
1504 assert(0, "Unknown Statistic Type"); | |
1505 } | |
1506 return false; | |
1507 JVM_END | |
1508 | |
1509 // Returns the fast estimate of CPU time consumed by | |
1510 // a given thread (in nanoseconds). | |
1511 // If thread_id == 0, return CPU time for the current thread. | |
1512 JVM_ENTRY(jlong, jmm_GetThreadCpuTime(JNIEnv *env, jlong thread_id)) | |
1513 if (!os::is_thread_cpu_time_supported()) { | |
1514 return -1; | |
1515 } | |
1516 | |
1517 if (thread_id < 0) { | |
1518 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1519 "Invalid thread ID", -1); | |
1520 } | |
1521 | |
1522 JavaThread* java_thread = NULL; | |
1523 if (thread_id == 0) { | |
1524 // current thread | |
1525 return os::current_thread_cpu_time(); | |
1526 } else { | |
1527 MutexLockerEx ml(Threads_lock); | |
1528 java_thread = find_java_thread_from_id(thread_id); | |
1529 if (java_thread != NULL) { | |
1530 return os::thread_cpu_time((Thread*) java_thread); | |
1531 } | |
1532 } | |
1533 return -1; | |
1534 JVM_END | |
1535 | |
1536 // Returns the CPU time consumed by a given thread (in nanoseconds). | |
1537 // If thread_id == 0, CPU time for the current thread is returned. | |
1538 // If user_sys_cpu_time = true, user level and system CPU time of | |
1539 // a given thread is returned; otherwise, only user level CPU time | |
1540 // is returned. | |
1541 JVM_ENTRY(jlong, jmm_GetThreadCpuTimeWithKind(JNIEnv *env, jlong thread_id, jboolean user_sys_cpu_time)) | |
1542 if (!os::is_thread_cpu_time_supported()) { | |
1543 return -1; | |
1544 } | |
1545 | |
1546 if (thread_id < 0) { | |
1547 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1548 "Invalid thread ID", -1); | |
1549 } | |
1550 | |
1551 JavaThread* java_thread = NULL; | |
1552 if (thread_id == 0) { | |
1553 // current thread | |
1554 return os::current_thread_cpu_time(user_sys_cpu_time != 0); | |
1555 } else { | |
1556 MutexLockerEx ml(Threads_lock); | |
1557 java_thread = find_java_thread_from_id(thread_id); | |
1558 if (java_thread != NULL) { | |
1559 return os::thread_cpu_time((Thread*) java_thread, user_sys_cpu_time != 0); | |
1560 } | |
1561 } | |
1562 return -1; | |
1563 JVM_END | |
1564 | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1565 // Gets an array containing the CPU times consumed by a set of threads |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1566 // (in nanoseconds). Each element of the array is the CPU time for the |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1567 // thread ID specified in the corresponding entry in the given array |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1568 // of thread IDs; or -1 if the thread does not exist or has terminated. |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1569 // If user_sys_cpu_time = true, the sum of user level and system CPU time |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1570 // for the given thread is returned; otherwise, only user level CPU time |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1571 // is returned. |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1572 JVM_ENTRY(void, jmm_GetThreadCpuTimesWithKind(JNIEnv *env, jlongArray ids, |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1573 jlongArray timeArray, |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1574 jboolean user_sys_cpu_time)) |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1575 // Check if threads is null |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1576 if (ids == NULL || timeArray == NULL) { |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1577 THROW(vmSymbols::java_lang_NullPointerException()); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1578 } |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1579 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1580 ResourceMark rm(THREAD); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1581 typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids)); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1582 typeArrayHandle ids_ah(THREAD, ta); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1583 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1584 typeArrayOop tia = typeArrayOop(JNIHandles::resolve_non_null(timeArray)); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1585 typeArrayHandle timeArray_h(THREAD, tia); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1586 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1587 // validate the thread id array |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1588 validate_thread_id_array(ids_ah, CHECK); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1589 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1590 // timeArray must be of the same length as the given array of thread IDs |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1591 int num_threads = ids_ah->length(); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1592 if (num_threads != timeArray_h->length()) { |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1593 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1594 "The length of the given long array does not match the length of " |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1595 "the given array of thread IDs"); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1596 } |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1597 |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1598 MutexLockerEx ml(Threads_lock); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1599 for (int i = 0; i < num_threads; i++) { |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1600 JavaThread* java_thread = find_java_thread_from_id(ids_ah->long_at(i)); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1601 if (java_thread != NULL) { |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1602 timeArray_h->long_at_put(i, os::thread_cpu_time((Thread*)java_thread, |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1603 user_sys_cpu_time != 0)); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1604 } |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1605 } |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1606 JVM_END |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
1607 |
0 | 1608 // Returns a String array of all VM global flag names |
1609 JVM_ENTRY(jobjectArray, jmm_GetVMGlobalNames(JNIEnv *env)) | |
1610 // last flag entry is always NULL, so subtract 1 | |
1611 int nFlags = (int) Flag::numFlags - 1; | |
1612 // allocate a temp array | |
1142 | 1613 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(), |
0 | 1614 nFlags, CHECK_0); |
1615 objArrayHandle flags_ah(THREAD, r); | |
1616 int num_entries = 0; | |
1617 for (int i = 0; i < nFlags; i++) { | |
1618 Flag* flag = &Flag::flags[i]; | |
350 | 1619 // Exclude the locked (experimental, diagnostic) flags |
0 | 1620 if (flag->is_unlocked() || flag->is_unlocker()) { |
1621 Handle s = java_lang_String::create_from_str(flag->name, CHECK_0); | |
1622 flags_ah->obj_at_put(num_entries, s()); | |
1623 num_entries++; | |
1624 } | |
1625 } | |
1626 | |
1627 if (num_entries < nFlags) { | |
1628 // Return array of right length | |
1142 | 1629 objArrayOop res = oopFactory::new_objArray(SystemDictionary::String_klass(), num_entries, CHECK_0); |
0 | 1630 for(int i = 0; i < num_entries; i++) { |
1631 res->obj_at_put(i, flags_ah->obj_at(i)); | |
1632 } | |
1633 return (jobjectArray)JNIHandles::make_local(env, res); | |
1634 } | |
1635 | |
1636 return (jobjectArray)JNIHandles::make_local(env, flags_ah()); | |
1637 JVM_END | |
1638 | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1639 // Utility function used by jmm_GetVMGlobals. Returns false if flag type |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1640 // can't be determined, true otherwise. If false is returned, then *global |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1641 // will be incomplete and invalid. |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1642 bool add_global_entry(JNIEnv* env, Handle name, jmmVMGlobal *global, Flag *flag, TRAPS) { |
0 | 1643 Handle flag_name; |
1644 if (name() == NULL) { | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1645 flag_name = java_lang_String::create_from_str(flag->name, CHECK_false); |
0 | 1646 } else { |
1647 flag_name = name; | |
1648 } | |
1649 global->name = (jstring)JNIHandles::make_local(env, flag_name()); | |
1650 | |
1651 if (flag->is_bool()) { | |
1652 global->value.z = flag->get_bool() ? JNI_TRUE : JNI_FALSE; | |
1653 global->type = JMM_VMGLOBAL_TYPE_JBOOLEAN; | |
1654 } else if (flag->is_intx()) { | |
1655 global->value.j = (jlong)flag->get_intx(); | |
1656 global->type = JMM_VMGLOBAL_TYPE_JLONG; | |
1657 } else if (flag->is_uintx()) { | |
1658 global->value.j = (jlong)flag->get_uintx(); | |
1659 global->type = JMM_VMGLOBAL_TYPE_JLONG; | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1660 } else if (flag->is_uint64_t()) { |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1661 global->value.j = (jlong)flag->get_uint64_t(); |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1662 global->type = JMM_VMGLOBAL_TYPE_JLONG; |
0 | 1663 } else if (flag->is_ccstr()) { |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1664 Handle str = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_false); |
0 | 1665 global->value.l = (jobject)JNIHandles::make_local(env, str()); |
1666 global->type = JMM_VMGLOBAL_TYPE_JSTRING; | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1667 } else { |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1668 global->type = JMM_VMGLOBAL_TYPE_UNKNOWN; |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1669 return false; |
0 | 1670 } |
1671 | |
1672 global->writeable = flag->is_writeable(); | |
1673 global->external = flag->is_external(); | |
1674 switch (flag->origin) { | |
1675 case DEFAULT: | |
1676 global->origin = JMM_VMGLOBAL_ORIGIN_DEFAULT; | |
1677 break; | |
1678 case COMMAND_LINE: | |
1679 global->origin = JMM_VMGLOBAL_ORIGIN_COMMAND_LINE; | |
1680 break; | |
1681 case ENVIRON_VAR: | |
1682 global->origin = JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR; | |
1683 break; | |
1684 case CONFIG_FILE: | |
1685 global->origin = JMM_VMGLOBAL_ORIGIN_CONFIG_FILE; | |
1686 break; | |
1687 case MANAGEMENT: | |
1688 global->origin = JMM_VMGLOBAL_ORIGIN_MANAGEMENT; | |
1689 break; | |
1690 case ERGONOMIC: | |
1691 global->origin = JMM_VMGLOBAL_ORIGIN_ERGONOMIC; | |
1692 break; | |
1693 default: | |
1694 global->origin = JMM_VMGLOBAL_ORIGIN_OTHER; | |
1695 } | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1696 |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1697 return true; |
0 | 1698 } |
1699 | |
1700 // Fill globals array of count length with jmmVMGlobal entries | |
1701 // specified by names. If names == NULL, fill globals array | |
1702 // with all Flags. Return value is number of entries | |
1703 // created in globals. | |
1704 // If a Flag with a given name in an array element does not | |
1705 // exist, globals[i].name will be set to NULL. | |
1706 JVM_ENTRY(jint, jmm_GetVMGlobals(JNIEnv *env, | |
1707 jobjectArray names, | |
1708 jmmVMGlobal *globals, | |
1709 jint count)) | |
1710 | |
1711 | |
1712 if (globals == NULL) { | |
1713 THROW_(vmSymbols::java_lang_NullPointerException(), 0); | |
1714 } | |
1715 | |
1716 ResourceMark rm(THREAD); | |
1717 | |
1718 if (names != NULL) { | |
1719 // return the requested globals | |
1720 objArrayOop ta = objArrayOop(JNIHandles::resolve_non_null(names)); | |
1721 objArrayHandle names_ah(THREAD, ta); | |
1722 // Make sure we have a String array | |
1723 klassOop element_klass = objArrayKlass::cast(names_ah->klass())->element_klass(); | |
1142 | 1724 if (element_klass != SystemDictionary::String_klass()) { |
0 | 1725 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), |
1726 "Array element type is not String class", 0); | |
1727 } | |
1728 | |
1729 int names_length = names_ah->length(); | |
1730 int num_entries = 0; | |
1731 for (int i = 0; i < names_length && i < count; i++) { | |
1732 oop s = names_ah->obj_at(i); | |
1733 if (s == NULL) { | |
1734 THROW_(vmSymbols::java_lang_NullPointerException(), 0); | |
1735 } | |
1736 | |
1737 Handle sh(THREAD, s); | |
1738 char* str = java_lang_String::as_utf8_string(s); | |
1739 Flag* flag = Flag::find_flag(str, strlen(str)); | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1740 if (flag != NULL && |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1741 add_global_entry(env, sh, &globals[i], flag, THREAD)) { |
0 | 1742 num_entries++; |
1743 } else { | |
1744 globals[i].name = NULL; | |
1745 } | |
1746 } | |
1747 return num_entries; | |
1748 } else { | |
1749 // return all globals if names == NULL | |
1750 | |
1751 // last flag entry is always NULL, so subtract 1 | |
1752 int nFlags = (int) Flag::numFlags - 1; | |
1753 Handle null_h; | |
1754 int num_entries = 0; | |
1755 for (int i = 0; i < nFlags && num_entries < count; i++) { | |
1756 Flag* flag = &Flag::flags[i]; | |
350 | 1757 // Exclude the locked (diagnostic, experimental) flags |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1758 if ((flag->is_unlocked() || flag->is_unlocker()) && |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1759 add_global_entry(env, null_h, &globals[num_entries], flag, THREAD)) { |
0 | 1760 num_entries++; |
1761 } | |
1762 } | |
1763 return num_entries; | |
1764 } | |
1765 JVM_END | |
1766 | |
1767 JVM_ENTRY(void, jmm_SetVMGlobal(JNIEnv *env, jstring flag_name, jvalue new_value)) | |
1768 ResourceMark rm(THREAD); | |
1769 | |
1770 oop fn = JNIHandles::resolve_external_guard(flag_name); | |
1771 if (fn == NULL) { | |
1772 THROW_MSG(vmSymbols::java_lang_NullPointerException(), | |
1773 "The flag name cannot be null."); | |
1774 } | |
1775 char* name = java_lang_String::as_utf8_string(fn); | |
1776 Flag* flag = Flag::find_flag(name, strlen(name)); | |
1777 if (flag == NULL) { | |
1778 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
1779 "Flag does not exist."); | |
1780 } | |
1781 if (!flag->is_writeable()) { | |
1782 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
1783 "This flag is not writeable."); | |
1784 } | |
1785 | |
1786 bool succeed; | |
1787 if (flag->is_bool()) { | |
1788 bool bvalue = (new_value.z == JNI_TRUE ? true : false); | |
1789 succeed = CommandLineFlags::boolAtPut(name, &bvalue, MANAGEMENT); | |
1790 } else if (flag->is_intx()) { | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1791 intx ivalue = (intx)new_value.j; |
0 | 1792 succeed = CommandLineFlags::intxAtPut(name, &ivalue, MANAGEMENT); |
1793 } else if (flag->is_uintx()) { | |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1794 uintx uvalue = (uintx)new_value.j; |
0 | 1795 succeed = CommandLineFlags::uintxAtPut(name, &uvalue, MANAGEMENT); |
1067
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1796 } else if (flag->is_uint64_t()) { |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1797 uint64_t uvalue = (uint64_t)new_value.j; |
ba7ea42fc66e
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
1064
diff
changeset
|
1798 succeed = CommandLineFlags::uint64_tAtPut(name, &uvalue, MANAGEMENT); |
0 | 1799 } else if (flag->is_ccstr()) { |
1800 oop str = JNIHandles::resolve_external_guard(new_value.l); | |
1801 if (str == NULL) { | |
1802 THROW(vmSymbols::java_lang_NullPointerException()); | |
1803 } | |
1804 ccstr svalue = java_lang_String::as_utf8_string(str); | |
1805 succeed = CommandLineFlags::ccstrAtPut(name, &svalue, MANAGEMENT); | |
1806 } | |
1807 assert(succeed, "Setting flag should succeed"); | |
1808 JVM_END | |
1809 | |
1810 class ThreadTimesClosure: public ThreadClosure { | |
1811 private: | |
1812 objArrayOop _names; | |
1813 typeArrayOop _times; | |
1814 int _names_len; | |
1815 int _times_len; | |
1816 int _count; | |
1817 | |
1818 public: | |
1819 ThreadTimesClosure(objArrayOop names, typeArrayOop times); | |
1820 virtual void do_thread(Thread* thread); | |
1821 int count() { return _count; } | |
1822 }; | |
1823 | |
1824 ThreadTimesClosure::ThreadTimesClosure(objArrayOop names, | |
1825 typeArrayOop times) { | |
1826 assert(names != NULL, "names was NULL"); | |
1827 assert(times != NULL, "times was NULL"); | |
1828 _names = names; | |
1829 _names_len = names->length(); | |
1830 _times = times; | |
1831 _times_len = times->length(); | |
1832 _count = 0; | |
1833 } | |
1834 | |
1835 void ThreadTimesClosure::do_thread(Thread* thread) { | |
1836 Handle s; | |
1837 assert(thread != NULL, "thread was NULL"); | |
1838 | |
1839 // exclude externally visible JavaThreads | |
1840 if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) { | |
1841 return; | |
1842 } | |
1843 | |
1844 if (_count >= _names_len || _count >= _times_len) { | |
1845 // skip if the result array is not big enough | |
1846 return; | |
1847 } | |
1848 | |
1849 EXCEPTION_MARK; | |
1850 | |
1851 assert(thread->name() != NULL, "All threads should have a name"); | |
1852 s = java_lang_String::create_from_str(thread->name(), CHECK); | |
1853 _names->obj_at_put(_count, s()); | |
1854 | |
1855 _times->long_at_put(_count, os::is_thread_cpu_time_supported() ? | |
1856 os::thread_cpu_time(thread) : -1); | |
1857 _count++; | |
1858 } | |
1859 | |
1860 // Fills names with VM internal thread names and times with the corresponding | |
1861 // CPU times. If names or times is NULL, a NullPointerException is thrown. | |
1862 // If the element type of names is not String, an IllegalArgumentException is | |
1863 // thrown. | |
1864 // If an array is not large enough to hold all the entries, only the entries | |
1865 // that fit will be returned. Return value is the number of VM internal | |
1866 // threads entries. | |
1867 JVM_ENTRY(jint, jmm_GetInternalThreadTimes(JNIEnv *env, | |
1868 jobjectArray names, | |
1869 jlongArray times)) | |
1870 if (names == NULL || times == NULL) { | |
1871 THROW_(vmSymbols::java_lang_NullPointerException(), 0); | |
1872 } | |
1873 objArrayOop na = objArrayOop(JNIHandles::resolve_non_null(names)); | |
1874 objArrayHandle names_ah(THREAD, na); | |
1875 | |
1876 // Make sure we have a String array | |
1877 klassOop element_klass = objArrayKlass::cast(names_ah->klass())->element_klass(); | |
1142 | 1878 if (element_klass != SystemDictionary::String_klass()) { |
0 | 1879 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), |
1880 "Array element type is not String class", 0); | |
1881 } | |
1882 | |
1883 typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(times)); | |
1884 typeArrayHandle times_ah(THREAD, ta); | |
1885 | |
1886 ThreadTimesClosure ttc(names_ah(), times_ah()); | |
1887 { | |
1888 MutexLockerEx ml(Threads_lock); | |
1889 Threads::threads_do(&ttc); | |
1890 } | |
1891 | |
1892 return ttc.count(); | |
1893 JVM_END | |
1894 | |
1895 static Handle find_deadlocks(bool object_monitors_only, TRAPS) { | |
1896 ResourceMark rm(THREAD); | |
1897 | |
1898 VM_FindDeadlocks op(!object_monitors_only /* also check concurrent locks? */); | |
1899 VMThread::execute(&op); | |
1900 | |
1901 DeadlockCycle* deadlocks = op.result(); | |
1902 if (deadlocks == NULL) { | |
1903 // no deadlock found and return | |
1904 return Handle(); | |
1905 } | |
1906 | |
1907 int num_threads = 0; | |
1908 DeadlockCycle* cycle; | |
1909 for (cycle = deadlocks; cycle != NULL; cycle = cycle->next()) { | |
1910 num_threads += cycle->num_threads(); | |
1911 } | |
1912 | |
1142 | 1913 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NH); |
0 | 1914 objArrayHandle threads_ah(THREAD, r); |
1915 | |
1916 int index = 0; | |
1917 for (cycle = deadlocks; cycle != NULL; cycle = cycle->next()) { | |
1918 GrowableArray<JavaThread*>* deadlock_threads = cycle->threads(); | |
1919 int len = deadlock_threads->length(); | |
1920 for (int i = 0; i < len; i++) { | |
1921 threads_ah->obj_at_put(index, deadlock_threads->at(i)->threadObj()); | |
1922 index++; | |
1923 } | |
1924 } | |
1925 return threads_ah; | |
1926 } | |
1927 | |
1928 // Finds cycles of threads that are deadlocked involved in object monitors | |
1929 // and JSR-166 synchronizers. | |
1930 // Returns an array of Thread objects which are in deadlock, if any. | |
1931 // Otherwise, returns NULL. | |
1932 // | |
1933 // Input parameter: | |
1934 // object_monitors_only - if true, only check object monitors | |
1935 // | |
1936 JVM_ENTRY(jobjectArray, jmm_FindDeadlockedThreads(JNIEnv *env, jboolean object_monitors_only)) | |
1937 Handle result = find_deadlocks(object_monitors_only != 0, CHECK_0); | |
1938 return (jobjectArray) JNIHandles::make_local(env, result()); | |
1939 JVM_END | |
1940 | |
1941 // Finds cycles of threads that are deadlocked on monitor locks | |
1942 // Returns an array of Thread objects which are in deadlock, if any. | |
1943 // Otherwise, returns NULL. | |
1944 JVM_ENTRY(jobjectArray, jmm_FindMonitorDeadlockedThreads(JNIEnv *env)) | |
1945 Handle result = find_deadlocks(true, CHECK_0); | |
1946 return (jobjectArray) JNIHandles::make_local(env, result()); | |
1947 JVM_END | |
1948 | |
1949 // Gets the information about GC extension attributes including | |
1950 // the name of the attribute, its type, and a short description. | |
1951 // | |
1952 // Input parameters: | |
1953 // mgr - GC memory manager | |
1954 // info - caller allocated array of jmmExtAttributeInfo | |
1955 // count - number of elements of the info array | |
1956 // | |
1957 // Returns the number of GC extension attributes filled in the info array; or | |
1958 // -1 if info is not big enough | |
1959 // | |
1960 JVM_ENTRY(jint, jmm_GetGCExtAttributeInfo(JNIEnv *env, jobject mgr, jmmExtAttributeInfo* info, jint count)) | |
1961 // All GC memory managers have 1 attribute (number of GC threads) | |
1962 if (count == 0) { | |
1963 return 0; | |
1964 } | |
1965 | |
1966 if (info == NULL) { | |
1967 THROW_(vmSymbols::java_lang_NullPointerException(), 0); | |
1968 } | |
1969 | |
1970 info[0].name = "GcThreadCount"; | |
1971 info[0].type = 'I'; | |
1972 info[0].description = "Number of GC threads"; | |
1973 return 1; | |
1974 JVM_END | |
1975 | |
1976 // verify the given array is an array of java/lang/management/MemoryUsage objects | |
1977 // of a given length and return the objArrayOop | |
1978 static objArrayOop get_memory_usage_objArray(jobjectArray array, int length, TRAPS) { | |
1979 if (array == NULL) { | |
1980 THROW_(vmSymbols::java_lang_NullPointerException(), 0); | |
1981 } | |
1982 | |
1983 objArrayOop oa = objArrayOop(JNIHandles::resolve_non_null(array)); | |
1984 objArrayHandle array_h(THREAD, oa); | |
1985 | |
1986 // array must be of the given length | |
1987 if (length != array_h->length()) { | |
1988 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1989 "The length of the given MemoryUsage array does not match the number of memory pools.", 0); | |
1990 } | |
1991 | |
1992 // check if the element of array is of type MemoryUsage class | |
1993 klassOop usage_klass = Management::java_lang_management_MemoryUsage_klass(CHECK_0); | |
1994 klassOop element_klass = objArrayKlass::cast(array_h->klass())->element_klass(); | |
1995 if (element_klass != usage_klass) { | |
1996 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
1997 "The element type is not MemoryUsage class", 0); | |
1998 } | |
1999 | |
2000 return array_h(); | |
2001 } | |
2002 | |
2003 // Gets the statistics of the last GC of a given GC memory manager. | |
2004 // Input parameters: | |
2005 // obj - GarbageCollectorMXBean object | |
2006 // gc_stat - caller allocated jmmGCStat where: | |
2007 // a. before_gc_usage - array of MemoryUsage objects | |
2008 // b. after_gc_usage - array of MemoryUsage objects | |
2009 // c. gc_ext_attributes_values_size is set to the | |
2010 // gc_ext_attribute_values array allocated | |
2011 // d. gc_ext_attribute_values is a caller allocated array of jvalue. | |
2012 // | |
2013 // On return, | |
2014 // gc_index == 0 indicates no GC statistics available | |
2015 // | |
2016 // before_gc_usage and after_gc_usage - filled with per memory pool | |
2017 // before and after GC usage in the same order as the memory pools | |
2018 // returned by GetMemoryPools for a given GC memory manager. | |
2019 // num_gc_ext_attributes indicates the number of elements in | |
2020 // the gc_ext_attribute_values array is filled; or | |
2021 // -1 if the gc_ext_attributes_values array is not big enough | |
2022 // | |
2023 JVM_ENTRY(void, jmm_GetLastGCStat(JNIEnv *env, jobject obj, jmmGCStat *gc_stat)) | |
2024 ResourceMark rm(THREAD); | |
2025 | |
2026 if (gc_stat->gc_ext_attribute_values_size > 0 && gc_stat->gc_ext_attribute_values == NULL) { | |
2027 THROW(vmSymbols::java_lang_NullPointerException()); | |
2028 } | |
2029 | |
2030 // Get the GCMemoryManager | |
2031 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK); | |
2032 | |
2033 // Make a copy of the last GC statistics | |
2034 // GC may occur while constructing the last GC information | |
2035 int num_pools = MemoryService::num_memory_pools(); | |
2036 GCStatInfo* stat = new GCStatInfo(num_pools); | |
1703
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
2037 if (mgr->get_last_gc_stat(stat) == 0) { |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
2038 gc_stat->gc_index = 0; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
2039 return; |
f6f3eef8a521
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
1552
diff
changeset
|
2040 } |
0 | 2041 |
2042 gc_stat->gc_index = stat->gc_index(); | |
2043 gc_stat->start_time = Management::ticks_to_ms(stat->start_time()); | |
2044 gc_stat->end_time = Management::ticks_to_ms(stat->end_time()); | |
2045 | |
2046 // Current implementation does not have GC extension attributes | |
2047 gc_stat->num_gc_ext_attributes = 0; | |
2048 | |
2049 // Fill the arrays of MemoryUsage objects with before and after GC | |
2050 // per pool memory usage | |
2051 objArrayOop bu = get_memory_usage_objArray(gc_stat->usage_before_gc, | |
2052 num_pools, | |
2053 CHECK); | |
2054 objArrayHandle usage_before_gc_ah(THREAD, bu); | |
2055 | |
2056 objArrayOop au = get_memory_usage_objArray(gc_stat->usage_after_gc, | |
2057 num_pools, | |
2058 CHECK); | |
2059 objArrayHandle usage_after_gc_ah(THREAD, au); | |
2060 | |
2061 for (int i = 0; i < num_pools; i++) { | |
2062 Handle before_usage = MemoryService::create_MemoryUsage_obj(stat->before_gc_usage_for_pool(i), CHECK); | |
2063 Handle after_usage; | |
2064 | |
2065 MemoryUsage u = stat->after_gc_usage_for_pool(i); | |
2066 if (u.max_size() == 0 && u.used() > 0) { | |
2067 // If max size == 0, this pool is a survivor space. | |
2068 // Set max size = -1 since the pools will be swapped after GC. | |
2069 MemoryUsage usage(u.init_size(), u.used(), u.committed(), (size_t)-1); | |
2070 after_usage = MemoryService::create_MemoryUsage_obj(usage, CHECK); | |
2071 } else { | |
2072 after_usage = MemoryService::create_MemoryUsage_obj(stat->after_gc_usage_for_pool(i), CHECK); | |
2073 } | |
2074 usage_before_gc_ah->obj_at_put(i, before_usage()); | |
2075 usage_after_gc_ah->obj_at_put(i, after_usage()); | |
2076 } | |
2077 | |
2078 if (gc_stat->gc_ext_attribute_values_size > 0) { | |
2079 // Current implementation only has 1 attribute (number of GC threads) | |
2080 // The type is 'I' | |
2081 gc_stat->gc_ext_attribute_values[0].i = mgr->num_gc_threads(); | |
2082 } | |
2083 JVM_END | |
2084 | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2085 JVM_ENTRY(void, jmm_SetGCNotificationEnabled(JNIEnv *env, jobject obj, jboolean enabled)) |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2086 ResourceMark rm(THREAD); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2087 // Get the GCMemoryManager |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2088 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2089 mgr->set_notification_enabled(enabled?true:false); |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2090 JVM_END |
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2091 |
0 | 2092 // Dump heap - Returns 0 if succeeds. |
2093 JVM_ENTRY(jint, jmm_DumpHeap0(JNIEnv *env, jstring outputfile, jboolean live)) | |
2094 #ifndef SERVICES_KERNEL | |
2095 ResourceMark rm(THREAD); | |
2096 oop on = JNIHandles::resolve_external_guard(outputfile); | |
2097 if (on == NULL) { | |
2098 THROW_MSG_(vmSymbols::java_lang_NullPointerException(), | |
2099 "Output file name cannot be null.", -1); | |
2100 } | |
2101 char* name = java_lang_String::as_utf8_string(on); | |
2102 if (name == NULL) { | |
2103 THROW_MSG_(vmSymbols::java_lang_NullPointerException(), | |
2104 "Output file name cannot be null.", -1); | |
2105 } | |
2106 HeapDumper dumper(live ? true : false); | |
2107 if (dumper.dump(name) != 0) { | |
2108 const char* errmsg = dumper.error_as_C_string(); | |
2109 THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1); | |
2110 } | |
2111 return 0; | |
2112 #else // SERVICES_KERNEL | |
2113 return -1; | |
2114 #endif // SERVICES_KERNEL | |
2115 JVM_END | |
2116 | |
4133 | 2117 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env)) |
2118 ResourceMark rm(THREAD); | |
2119 GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(); | |
2120 objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(), | |
2121 dcmd_list->length(), CHECK_NULL); | |
2122 objArrayHandle cmd_array(THREAD, cmd_array_oop); | |
2123 for (int i = 0; i < dcmd_list->length(); i++) { | |
2124 oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL); | |
2125 cmd_array->obj_at_put(i, cmd_name); | |
2126 } | |
2127 return (jobjectArray) JNIHandles::make_local(env, cmd_array()); | |
2128 JVM_END | |
2129 | |
2130 JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds, | |
2131 dcmdInfo* infoArray)) | |
2132 if (cmds == NULL || infoArray == NULL) { | |
2133 THROW(vmSymbols::java_lang_NullPointerException()); | |
2134 } | |
2135 | |
2136 ResourceMark rm(THREAD); | |
2137 | |
2138 objArrayOop ca = objArrayOop(JNIHandles::resolve_non_null(cmds)); | |
2139 objArrayHandle cmds_ah(THREAD, ca); | |
2140 | |
2141 // Make sure we have a String array | |
2142 klassOop element_klass = objArrayKlass::cast(cmds_ah->klass())->element_klass(); | |
2143 if (element_klass != SystemDictionary::String_klass()) { | |
2144 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
2145 "Array element type is not String class"); | |
2146 } | |
2147 | |
2148 GrowableArray<DCmdInfo *>* info_list = DCmdFactory::DCmdInfo_list(); | |
2149 | |
2150 int num_cmds = cmds_ah->length(); | |
2151 for (int i = 0; i < num_cmds; i++) { | |
2152 oop cmd = cmds_ah->obj_at(i); | |
2153 if (cmd == NULL) { | |
2154 THROW_MSG(vmSymbols::java_lang_NullPointerException(), | |
2155 "Command name cannot be null."); | |
2156 } | |
2157 char* cmd_name = java_lang_String::as_utf8_string(cmd); | |
2158 if (cmd_name == NULL) { | |
2159 THROW_MSG(vmSymbols::java_lang_NullPointerException(), | |
2160 "Command name cannot be null."); | |
2161 } | |
2162 int pos = info_list->find((void*)cmd_name,DCmdInfo::by_name); | |
2163 if (pos == -1) { | |
2164 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
2165 "Unknown diagnostic command"); | |
2166 } | |
2167 DCmdInfo* info = info_list->at(pos); | |
2168 infoArray[i].name = info->name(); | |
2169 infoArray[i].description = info->description(); | |
2170 infoArray[i].impact = info->impact(); | |
2171 infoArray[i].num_arguments = info->num_arguments(); | |
2172 infoArray[i].enabled = info->is_enabled(); | |
2173 } | |
2174 JVM_END | |
2175 | |
2176 JVM_ENTRY(void, jmm_GetDiagnosticCommandArgumentsInfo(JNIEnv *env, | |
2177 jstring command, dcmdArgInfo* infoArray)) | |
2178 ResourceMark rm(THREAD); | |
2179 oop cmd = JNIHandles::resolve_external_guard(command); | |
2180 if (cmd == NULL) { | |
2181 THROW_MSG(vmSymbols::java_lang_NullPointerException(), | |
2182 "Command line cannot be null."); | |
2183 } | |
2184 char* cmd_name = java_lang_String::as_utf8_string(cmd); | |
2185 if (cmd_name == NULL) { | |
2186 THROW_MSG(vmSymbols::java_lang_NullPointerException(), | |
2187 "Command line content cannot be null."); | |
2188 } | |
2189 DCmd* dcmd = NULL; | |
2190 DCmdFactory*factory = DCmdFactory::factory(cmd_name, strlen(cmd_name)); | |
2191 if (factory != NULL) { | |
2192 dcmd = factory->create_resource_instance(NULL); | |
2193 } | |
2194 if (dcmd == NULL) { | |
2195 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
2196 "Unknown diagnostic command"); | |
2197 } | |
2198 DCmdMark mark(dcmd); | |
2199 GrowableArray<DCmdArgumentInfo*>* array = dcmd->argument_info_array(); | |
2200 if (array->length() == 0) { | |
2201 return; | |
2202 } | |
2203 for (int i = 0; i < array->length(); i++) { | |
2204 infoArray[i].name = array->at(i)->name(); | |
2205 infoArray[i].description = array->at(i)->description(); | |
2206 infoArray[i].type = array->at(i)->type(); | |
2207 infoArray[i].default_string = array->at(i)->default_string(); | |
2208 infoArray[i].mandatory = array->at(i)->is_mandatory(); | |
2209 infoArray[i].option = array->at(i)->is_option(); | |
2210 infoArray[i].position = array->at(i)->position(); | |
2211 } | |
2212 return; | |
2213 JVM_END | |
2214 | |
2215 JVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline)) | |
2216 ResourceMark rm(THREAD); | |
2217 oop cmd = JNIHandles::resolve_external_guard(commandline); | |
2218 if (cmd == NULL) { | |
2219 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), | |
2220 "Command line cannot be null."); | |
2221 } | |
2222 char* cmdline = java_lang_String::as_utf8_string(cmd); | |
2223 if (cmdline == NULL) { | |
2224 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), | |
2225 "Command line content cannot be null."); | |
2226 } | |
2227 bufferedStream output; | |
2228 DCmd::parse_and_execute(&output, cmdline, ' ', CHECK_NULL); | |
2229 oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL); | |
2230 return (jstring) JNIHandles::make_local(env, result); | |
2231 JVM_END | |
2232 | |
0 | 2233 jlong Management::ticks_to_ms(jlong ticks) { |
2234 assert(os::elapsed_frequency() > 0, "Must be non-zero"); | |
2235 return (jlong)(((double)ticks / (double)os::elapsed_frequency()) | |
2236 * (double)1000.0); | |
2237 } | |
2238 | |
2239 const struct jmmInterface_1_ jmm_interface = { | |
2240 NULL, | |
2241 NULL, | |
2242 jmm_GetVersion, | |
2243 jmm_GetOptionalSupport, | |
2244 jmm_GetInputArguments, | |
2245 jmm_GetThreadInfo, | |
2246 jmm_GetInputArgumentArray, | |
2247 jmm_GetMemoryPools, | |
2248 jmm_GetMemoryManagers, | |
2249 jmm_GetMemoryPoolUsage, | |
2250 jmm_GetPeakMemoryPoolUsage, | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
2251 jmm_GetThreadAllocatedMemory, |
0 | 2252 jmm_GetMemoryUsage, |
2253 jmm_GetLongAttribute, | |
2254 jmm_GetBoolAttribute, | |
2255 jmm_SetBoolAttribute, | |
2256 jmm_GetLongAttributes, | |
2257 jmm_FindMonitorDeadlockedThreads, | |
2258 jmm_GetThreadCpuTime, | |
2259 jmm_GetVMGlobalNames, | |
2260 jmm_GetVMGlobals, | |
2261 jmm_GetInternalThreadTimes, | |
2262 jmm_ResetStatistic, | |
2263 jmm_SetPoolSensor, | |
2264 jmm_SetPoolThreshold, | |
2265 jmm_GetPoolCollectionUsage, | |
2266 jmm_GetGCExtAttributeInfo, | |
2267 jmm_GetLastGCStat, | |
2268 jmm_GetThreadCpuTimeWithKind, | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
1972
diff
changeset
|
2269 jmm_GetThreadCpuTimesWithKind, |
0 | 2270 jmm_DumpHeap0, |
2271 jmm_FindDeadlockedThreads, | |
2272 jmm_SetVMGlobal, | |
2273 NULL, | |
3356
78542e2b5e35
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
2267
diff
changeset
|
2274 jmm_DumpThreads, |
4133 | 2275 jmm_SetGCNotificationEnabled, |
2276 jmm_GetDiagnosticCommands, | |
2277 jmm_GetDiagnosticCommandInfo, | |
2278 jmm_GetDiagnosticCommandArgumentsInfo, | |
2279 jmm_ExecuteDiagnosticCommand | |
0 | 2280 }; |
2281 | |
2282 void* Management::get_jmm_interface(int version) { | |
2283 if (version == JMM_VERSION_1_0) { | |
2284 return (void*) &jmm_interface; | |
2285 } | |
2286 return NULL; | |
2287 } |