29 #include "memory/resourceArea.hpp" 30 #include "oops/oop.inline.hpp" 31 #include "prims/jvmtiExport.hpp" 32 #include "runtime/arguments.hpp" 33 #include "runtime/globals.hpp" 34 #include "runtime/java.hpp" 35 #include "runtime/javaCalls.hpp" 36 #include "runtime/os.hpp" 37 #include "services/attachListener.hpp" 38 #include "services/diagnosticCommand.hpp" 39 #include "services/heapDumper.hpp" 40 #include "services/writeableFlags.hpp" 41 42 volatile bool AttachListener::_initialized; 43 44 // Implementation of "properties" command. 45 // 46 // Invokes VMSupport.serializePropertiesToByteArray to serialize 47 // the system properties into a byte array. 48 49 static Klass* load_and_initialize_klass(Symbol* sh, TRAPS) { 50 Klass* k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL); 51 instanceKlassHandle ik (THREAD, k); 52 if (ik->should_be_initialized()) { 53 ik->initialize(CHECK_NULL); 54 } 55 return ik(); 56 } 57 58 static jint get_properties(AttachOperation* op, outputStream* out, Symbol* serializePropertiesMethod) { 59 Thread* THREAD = Thread::current(); 60 HandleMark hm; 61 62 // load VMSupport 63 Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport(); 64 Klass* k = load_and_initialize_klass(klass, THREAD); 65 if (HAS_PENDING_EXCEPTION) { 66 java_lang_Throwable::print(PENDING_EXCEPTION, out); 67 CLEAR_PENDING_EXCEPTION; 68 return JNI_ERR; 69 } 70 instanceKlassHandle ik(THREAD, k); 71 72 // invoke the serializePropertiesToByteArray method 73 JavaValue result(T_OBJECT); 74 JavaCallArguments args; 75 76 77 Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature(); 78 JavaCalls::call_static(&result, 79 ik, 80 serializePropertiesMethod, 81 signature, 82 &args, 83 THREAD); 84 if (HAS_PENDING_EXCEPTION) { 85 java_lang_Throwable::print(PENDING_EXCEPTION, out); 86 CLEAR_PENDING_EXCEPTION; 87 return JNI_ERR; 88 } 89 90 // The result should be a [B 91 oop res = (oop)result.get_jobject(); 92 assert(res->is_typeArray(), "just checking"); 93 assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking"); 94 95 // copy the bytes to the output stream 96 typeArrayOop ba = typeArrayOop(res); 97 jbyte* addr = typeArrayOop(res)->byte_at_addr(0); 98 out->print_raw((const char*)addr, ba->length()); 99 357 tty->print_cr("Exception in VM (AttachListener::init) : "); 358 java_lang_Throwable::print(PENDING_EXCEPTION, tty); 359 tty->cr(); 360 361 CLEAR_PENDING_EXCEPTION; 362 363 return true; 364 } else { 365 return false; 366 } 367 } 368 369 // Starts the Attach Listener thread 370 void AttachListener::init() { 371 EXCEPTION_MARK; 372 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, THREAD); 373 if (has_init_error(THREAD)) { 374 return; 375 } 376 377 instanceKlassHandle klass (THREAD, k); 378 instanceHandle thread_oop = klass->allocate_instance_handle(THREAD); 379 if (has_init_error(THREAD)) { 380 return; 381 } 382 383 const char thread_name[] = "Attach Listener"; 384 Handle string = java_lang_String::create_from_str(thread_name, THREAD); 385 if (has_init_error(THREAD)) { 386 return; 387 } 388 389 // Initialize thread_oop to put it into the system threadGroup 390 Handle thread_group (THREAD, Universe::system_thread_group()); 391 JavaValue result(T_VOID); 392 JavaCalls::call_special(&result, thread_oop, 393 klass, 394 vmSymbols::object_initializer_name(), 395 vmSymbols::threadgroup_string_void_signature(), 396 thread_group, 397 string, 398 THREAD); 399 400 if (has_init_error(THREAD)) { 401 return; 402 } 403 404 KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass()); 405 JavaCalls::call_special(&result, 406 thread_group, 407 group, 408 vmSymbols::add_method_name(), 409 vmSymbols::thread_void_signature(), 410 thread_oop, // ARG 1 411 THREAD); 412 if (has_init_error(THREAD)) { 413 return; 414 } 415 416 { MutexLocker mu(Threads_lock); 417 JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry); 418 419 // Check that thread and osthread were created 420 if (listener_thread == NULL || listener_thread->osthread() == NULL) { 421 vm_exit_during_initialization("java.lang.OutOfMemoryError", 422 os::native_thread_creation_failed_msg()); 423 } 424 | 29 #include "memory/resourceArea.hpp" 30 #include "oops/oop.inline.hpp" 31 #include "prims/jvmtiExport.hpp" 32 #include "runtime/arguments.hpp" 33 #include "runtime/globals.hpp" 34 #include "runtime/java.hpp" 35 #include "runtime/javaCalls.hpp" 36 #include "runtime/os.hpp" 37 #include "services/attachListener.hpp" 38 #include "services/diagnosticCommand.hpp" 39 #include "services/heapDumper.hpp" 40 #include "services/writeableFlags.hpp" 41 42 volatile bool AttachListener::_initialized; 43 44 // Implementation of "properties" command. 45 // 46 // Invokes VMSupport.serializePropertiesToByteArray to serialize 47 // the system properties into a byte array. 48 49 static InstanceKlass* load_and_initialize_klass(Symbol* sh, TRAPS) { 50 Klass* k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL); 51 InstanceKlass* ik = InstanceKlass::cast(k); 52 if (ik->should_be_initialized()) { 53 ik->initialize(CHECK_NULL); 54 } 55 return ik; 56 } 57 58 static jint get_properties(AttachOperation* op, outputStream* out, Symbol* serializePropertiesMethod) { 59 Thread* THREAD = Thread::current(); 60 HandleMark hm; 61 62 // load VMSupport 63 Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport(); 64 InstanceKlass* k = load_and_initialize_klass(klass, THREAD); 65 if (HAS_PENDING_EXCEPTION) { 66 java_lang_Throwable::print(PENDING_EXCEPTION, out); 67 CLEAR_PENDING_EXCEPTION; 68 return JNI_ERR; 69 } 70 71 // invoke the serializePropertiesToByteArray method 72 JavaValue result(T_OBJECT); 73 JavaCallArguments args; 74 75 76 Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature(); 77 JavaCalls::call_static(&result, 78 k, 79 serializePropertiesMethod, 80 signature, 81 &args, 82 THREAD); 83 if (HAS_PENDING_EXCEPTION) { 84 java_lang_Throwable::print(PENDING_EXCEPTION, out); 85 CLEAR_PENDING_EXCEPTION; 86 return JNI_ERR; 87 } 88 89 // The result should be a [B 90 oop res = (oop)result.get_jobject(); 91 assert(res->is_typeArray(), "just checking"); 92 assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking"); 93 94 // copy the bytes to the output stream 95 typeArrayOop ba = typeArrayOop(res); 96 jbyte* addr = typeArrayOop(res)->byte_at_addr(0); 97 out->print_raw((const char*)addr, ba->length()); 98 356 tty->print_cr("Exception in VM (AttachListener::init) : "); 357 java_lang_Throwable::print(PENDING_EXCEPTION, tty); 358 tty->cr(); 359 360 CLEAR_PENDING_EXCEPTION; 361 362 return true; 363 } else { 364 return false; 365 } 366 } 367 368 // Starts the Attach Listener thread 369 void AttachListener::init() { 370 EXCEPTION_MARK; 371 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, THREAD); 372 if (has_init_error(THREAD)) { 373 return; 374 } 375 376 InstanceKlass* klass = InstanceKlass::cast(k); 377 instanceHandle thread_oop = klass->allocate_instance_handle(THREAD); 378 if (has_init_error(THREAD)) { 379 return; 380 } 381 382 const char thread_name[] = "Attach Listener"; 383 Handle string = java_lang_String::create_from_str(thread_name, THREAD); 384 if (has_init_error(THREAD)) { 385 return; 386 } 387 388 // Initialize thread_oop to put it into the system threadGroup 389 Handle thread_group (THREAD, Universe::system_thread_group()); 390 JavaValue result(T_VOID); 391 JavaCalls::call_special(&result, thread_oop, 392 klass, 393 vmSymbols::object_initializer_name(), 394 vmSymbols::threadgroup_string_void_signature(), 395 thread_group, 396 string, 397 THREAD); 398 399 if (has_init_error(THREAD)) { 400 return; 401 } 402 403 Klass* group = SystemDictionary::ThreadGroup_klass(); 404 JavaCalls::call_special(&result, 405 thread_group, 406 group, 407 vmSymbols::add_method_name(), 408 vmSymbols::thread_void_signature(), 409 thread_oop, // ARG 1 410 THREAD); 411 if (has_init_error(THREAD)) { 412 return; 413 } 414 415 { MutexLocker mu(Threads_lock); 416 JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry); 417 418 // Check that thread and osthread were created 419 if (listener_thread == NULL || listener_thread->osthread() == NULL) { 420 vm_exit_during_initialization("java.lang.OutOfMemoryError", 421 os::native_thread_creation_failed_msg()); 422 } 423 |