src/share/vm/services/management.cpp

Sat, 20 Apr 2013 19:02:11 +0200

author
mgronlun
date
Sat, 20 Apr 2013 19:02:11 +0200
changeset 4966
a527ddd44e07
parent 4542
db9981fd3124
child 5047
31a4e55f8c9d
permissions
-rw-r--r--

6729929: I18N - Taking Heap Dump failed if project path contains multibyte characters
Reviewed-by: dholmes, rbackman
Contributed-by: peter.allwin@oracle.com

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

mercurial