392 } 393 } 394 395 bool AttachListener::has_init_error(TRAPS) { 396 if (HAS_PENDING_EXCEPTION) { 397 tty->print_cr("Exception in VM (AttachListener::init) : "); 398 java_lang_Throwable::print(PENDING_EXCEPTION, tty); 399 tty->cr(); 400 401 CLEAR_PENDING_EXCEPTION; 402 403 return true; 404 } else { 405 return false; 406 } 407 } 408 409 // Starts the Attach Listener thread 410 void AttachListener::init() { 411 EXCEPTION_MARK; 412 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, THREAD); 413 if (has_init_error(THREAD)) { 414 return; 415 } 416 417 InstanceKlass* klass = InstanceKlass::cast(k); 418 instanceHandle thread_oop = klass->allocate_instance_handle(THREAD); 419 if (has_init_error(THREAD)) { 420 return; 421 } 422 423 const char thread_name[] = "Attach Listener"; 424 Handle string = java_lang_String::create_from_str(thread_name, THREAD); 425 if (has_init_error(THREAD)) { 426 return; 427 } 428 429 // Initialize thread_oop to put it into the system threadGroup 430 Handle thread_group (THREAD, Universe::system_thread_group()); 431 JavaValue result(T_VOID); 432 JavaCalls::call_special(&result, thread_oop, 433 klass, 434 vmSymbols::object_initializer_name(), 435 vmSymbols::threadgroup_string_void_signature(), 436 thread_group, 437 string, 438 THREAD); 439 440 if (has_init_error(THREAD)) { 441 return; 442 } 443 444 Klass* group = SystemDictionary::ThreadGroup_klass(); 445 JavaCalls::call_special(&result, 446 thread_group, 447 group, 448 vmSymbols::add_method_name(), 449 vmSymbols::thread_void_signature(), 450 thread_oop, // ARG 1 451 THREAD); 452 if (has_init_error(THREAD)) { 453 return; 454 } 455 456 { MutexLocker mu(Threads_lock); 457 JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry); 458 459 // Check that thread and osthread were created 460 if (listener_thread == NULL || listener_thread->osthread() == NULL) { 461 vm_exit_during_initialization("java.lang.OutOfMemoryError", 462 os::native_thread_creation_failed_msg()); 463 } 464 465 java_lang_Thread::set_thread(thread_oop(), listener_thread); 466 java_lang_Thread::set_daemon(thread_oop()); 467 468 listener_thread->set_threadObj(thread_oop()); 469 Threads::add(listener_thread); 470 Thread::start(listener_thread); | 392 } 393 } 394 395 bool AttachListener::has_init_error(TRAPS) { 396 if (HAS_PENDING_EXCEPTION) { 397 tty->print_cr("Exception in VM (AttachListener::init) : "); 398 java_lang_Throwable::print(PENDING_EXCEPTION, tty); 399 tty->cr(); 400 401 CLEAR_PENDING_EXCEPTION; 402 403 return true; 404 } else { 405 return false; 406 } 407 } 408 409 // Starts the Attach Listener thread 410 void AttachListener::init() { 411 EXCEPTION_MARK; 412 413 const char thread_name[] = "Attach Listener"; 414 Handle string = java_lang_String::create_from_str(thread_name, THREAD); 415 if (has_init_error(THREAD)) { 416 return; 417 } 418 419 // Initialize thread_oop to put it into the system threadGroup 420 Handle thread_group (THREAD, Universe::system_thread_group()); 421 Handle thread_oop = JavaCalls::construct_new_instance(SystemDictionary::Thread_klass(), 422 vmSymbols::threadgroup_string_void_signature(), 423 thread_group, 424 string, 425 THREAD); 426 if (has_init_error(THREAD)) { 427 return; 428 } 429 430 Klass* group = SystemDictionary::ThreadGroup_klass(); 431 JavaValue result(T_VOID); 432 JavaCalls::call_special(&result, 433 thread_group, 434 group, 435 vmSymbols::add_method_name(), 436 vmSymbols::thread_void_signature(), 437 thread_oop, 438 THREAD); 439 if (has_init_error(THREAD)) { 440 return; 441 } 442 443 { MutexLocker mu(Threads_lock); 444 JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry); 445 446 // Check that thread and osthread were created 447 if (listener_thread == NULL || listener_thread->osthread() == NULL) { 448 vm_exit_during_initialization("java.lang.OutOfMemoryError", 449 os::native_thread_creation_failed_msg()); 450 } 451 452 java_lang_Thread::set_thread(thread_oop(), listener_thread); 453 java_lang_Thread::set_daemon(thread_oop()); 454 455 listener_thread->set_threadObj(thread_oop()); 456 Threads::add(listener_thread); 457 Thread::start(listener_thread); |