src/share/vm/services/attachListener.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/services

src/share/vm/services/attachListener.cpp

Print this page




 434 
 435       // check for platform dependent attach operation
 436       if (info == NULL) {
 437         info = AttachListener::pd_find_operation(op->name());
 438       }
 439 
 440       if (info != NULL) {
 441         // dispatch to the function that implements this operation
 442         res = (info->func)(op, &st);
 443       } else {
 444         st.print("Operation %s not recognized!", op->name());
 445         res = JNI_ERR;
 446       }
 447     }
 448 
 449     // operation complete - send result and output to client
 450     op->complete(res, &st);
 451   }
 452 }
 453 














 454 // Starts the Attach Listener thread
 455 void AttachListener::init() {
 456   EXCEPTION_MARK;
 457   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK);




 458   instanceKlassHandle klass (THREAD, k);
 459   instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);



 460 
 461   const char thread_name[] = "Attach Listener";
 462   Handle string = java_lang_String::create_from_str(thread_name, CHECK);



 463 
 464   // Initialize thread_oop to put it into the system threadGroup
 465   Handle thread_group (THREAD, Universe::system_thread_group());
 466   JavaValue result(T_VOID);
 467   JavaCalls::call_special(&result, thread_oop,
 468                        klass,
 469                        vmSymbols::object_initializer_name(),
 470                        vmSymbols::threadgroup_string_void_signature(),
 471                        thread_group,
 472                        string,
 473                        THREAD);
 474 
 475   if (HAS_PENDING_EXCEPTION) {
 476     tty->print_cr("Exception in VM (AttachListener::init) : ");
 477     java_lang_Throwable::print(PENDING_EXCEPTION, tty);
 478     tty->cr();
 479 
 480     CLEAR_PENDING_EXCEPTION;
 481 
 482     return;
 483   }
 484 
 485   KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass());
 486   JavaCalls::call_special(&result,
 487                         thread_group,
 488                         group,
 489                         vmSymbols::add_method_name(),
 490                         vmSymbols::thread_void_signature(),
 491                         thread_oop,             // ARG 1
 492                         THREAD);
 493 
 494   if (HAS_PENDING_EXCEPTION) {
 495     tty->print_cr("Exception in VM (AttachListener::init) : ");
 496     java_lang_Throwable::print(PENDING_EXCEPTION, tty);
 497     tty->cr();
 498 
 499     CLEAR_PENDING_EXCEPTION;
 500 
 501     return;
 502   }
 503 
 504   { MutexLocker mu(Threads_lock);
 505     JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry);
 506 
 507     // Check that thread and osthread were created
 508     if (listener_thread == NULL || listener_thread->osthread() == NULL) {
 509       vm_exit_during_initialization("java.lang.OutOfMemoryError",
 510                                     "unable to create new native thread");
 511     }
 512 
 513     java_lang_Thread::set_thread(thread_oop(), listener_thread);
 514     java_lang_Thread::set_daemon(thread_oop());
 515 
 516     listener_thread->set_threadObj(thread_oop());
 517     Threads::add(listener_thread);
 518     Thread::start(listener_thread);
 519   }
 520 }


 434 
 435       // check for platform dependent attach operation
 436       if (info == NULL) {
 437         info = AttachListener::pd_find_operation(op->name());
 438       }
 439 
 440       if (info != NULL) {
 441         // dispatch to the function that implements this operation
 442         res = (info->func)(op, &st);
 443       } else {
 444         st.print("Operation %s not recognized!", op->name());
 445         res = JNI_ERR;
 446       }
 447     }
 448 
 449     // operation complete - send result and output to client
 450     op->complete(res, &st);
 451   }
 452 }
 453 
 454 bool AttachListener::init_error(TRAPS) { 
 455   if (HAS_PENDING_EXCEPTION) {
 456     tty->print_cr("Exception in VM (AttachListener::init) : ");
 457     java_lang_Throwable::print(PENDING_EXCEPTION, tty);
 458     tty->cr();
 459 
 460     CLEAR_PENDING_EXCEPTION;
 461 
 462     return true;
 463   } else {
 464     return false;
 465   }
 466 }
 467 
 468 // Starts the Attach Listener thread
 469 void AttachListener::init() {
 470   EXCEPTION_MARK;
 471   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, THREAD);
 472   if (init_error(THREAD)) {
 473     return;
 474   }
 475 
 476   instanceKlassHandle klass (THREAD, k);
 477   instanceHandle thread_oop = klass->allocate_instance_handle(THREAD);
 478   if (init_error(THREAD)) {
 479     return;
 480   }
 481 
 482   const char thread_name[] = "Attach Listener";
 483   Handle string = java_lang_String::create_from_str(thread_name, THREAD);
 484   if (init_error(THREAD)) {
 485     return;
 486   }
 487 
 488   // Initialize thread_oop to put it into the system threadGroup
 489   Handle thread_group (THREAD, Universe::system_thread_group());
 490   JavaValue result(T_VOID);
 491   JavaCalls::call_special(&result, thread_oop,
 492                        klass,
 493                        vmSymbols::object_initializer_name(),
 494                        vmSymbols::threadgroup_string_void_signature(),
 495                        thread_group,
 496                        string,
 497                        THREAD);
 498 
 499   if (init_error(THREAD)) {






 500     return;
 501   }
 502 
 503   KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass());
 504   JavaCalls::call_special(&result,
 505                         thread_group,
 506                         group,
 507                         vmSymbols::add_method_name(),
 508                         vmSymbols::thread_void_signature(),
 509                         thread_oop,             // ARG 1
 510                         THREAD);
 511   if (init_error(THREAD)) {







 512     return;
 513   }
 514 
 515   { MutexLocker mu(Threads_lock);
 516     JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry);
 517 
 518     // Check that thread and osthread were created
 519     if (listener_thread == NULL || listener_thread->osthread() == NULL) {
 520       vm_exit_during_initialization("java.lang.OutOfMemoryError",
 521                                     "unable to create new native thread");
 522     }
 523 
 524     java_lang_Thread::set_thread(thread_oop(), listener_thread);
 525     java_lang_Thread::set_daemon(thread_oop());
 526 
 527     listener_thread->set_threadObj(thread_oop());
 528     Threads::add(listener_thread);
 529     Thread::start(listener_thread);
 530   }
 531 }
src/share/vm/services/attachListener.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File