src/hotspot/share/services/attachListener.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54786 ebf733a324d4
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    43 #include "services/heapDumper.hpp"
    43 #include "services/heapDumper.hpp"
    44 #include "services/writeableFlags.hpp"
    44 #include "services/writeableFlags.hpp"
    45 #include "utilities/debug.hpp"
    45 #include "utilities/debug.hpp"
    46 #include "utilities/formatBuffer.hpp"
    46 #include "utilities/formatBuffer.hpp"
    47 
    47 
    48 volatile bool AttachListener::_initialized;
    48 volatile AttachListenerState AttachListener::_state = AL_NOT_INITIALIZED;
    49 
    49 
    50 // Implementation of "properties" command.
    50 // Implementation of "properties" command.
    51 //
    51 //
    52 // Invokes VMSupport.serializePropertiesToByteArray to serialize
    52 // Invokes VMSupport.serializePropertiesToByteArray to serialize
    53 // the system properties into a byte array.
    53 // the system properties into a byte array.
   329   const char* name = NULL;
   329   const char* name = NULL;
   330   if ((name = op->arg(0)) == NULL) {
   330   if ((name = op->arg(0)) == NULL) {
   331     out->print_cr("flag name is missing");
   331     out->print_cr("flag name is missing");
   332     return JNI_ERR;
   332     return JNI_ERR;
   333   }
   333   }
   334   JVMFlag* f = JVMFlag::find_flag((char*)name, strlen(name));
   334   JVMFlag* f = JVMFlag::find_flag(name);
   335   if (f) {
   335   if (f) {
   336     f->print_as_flag(out);
   336     f->print_as_flag(out);
   337     out->cr();
   337     out->cr();
   338   } else {
   338   } else {
   339     out->print_cr("no such flag '%s'", name);
   339     out->print_cr("no such flag '%s'", name);
   370   assert(thread == Thread::current(), "Must be");
   370   assert(thread == Thread::current(), "Must be");
   371   assert(thread->stack_base() != NULL && thread->stack_size() > 0,
   371   assert(thread->stack_base() != NULL && thread->stack_size() > 0,
   372          "Should already be setup");
   372          "Should already be setup");
   373 
   373 
   374   if (AttachListener::pd_init() != 0) {
   374   if (AttachListener::pd_init() != 0) {
       
   375     AttachListener::set_state(AL_NOT_INITIALIZED);
   375     return;
   376     return;
   376   }
   377   }
   377   AttachListener::set_initialized();
   378   AttachListener::set_initialized();
   378 
   379 
   379   for (;;) {
   380   for (;;) {
   380     AttachOperation* op = AttachListener::dequeue();
   381     AttachOperation* op = AttachListener::dequeue();
   381     if (op == NULL) {
   382     if (op == NULL) {
       
   383       AttachListener::set_state(AL_NOT_INITIALIZED);
   382       return;   // dequeue failed or shutdown
   384       return;   // dequeue failed or shutdown
   383     }
   385     }
   384 
   386 
   385     ResourceMark rm;
   387     ResourceMark rm;
   386     bufferedStream st;
   388     bufferedStream st;
   420     }
   422     }
   421 
   423 
   422     // operation complete - send result and output to client
   424     // operation complete - send result and output to client
   423     op->complete(res, &st);
   425     op->complete(res, &st);
   424   }
   426   }
       
   427 
       
   428   ShouldNotReachHere();
   425 }
   429 }
   426 
   430 
   427 bool AttachListener::has_init_error(TRAPS) {
   431 bool AttachListener::has_init_error(TRAPS) {
   428   if (HAS_PENDING_EXCEPTION) {
   432   if (HAS_PENDING_EXCEPTION) {
   429     tty->print_cr("Exception in VM (AttachListener::init) : ");
   433     tty->print_cr("Exception in VM (AttachListener::init) : ");
   443   EXCEPTION_MARK;
   447   EXCEPTION_MARK;
   444 
   448 
   445   const char thread_name[] = "Attach Listener";
   449   const char thread_name[] = "Attach Listener";
   446   Handle string = java_lang_String::create_from_str(thread_name, THREAD);
   450   Handle string = java_lang_String::create_from_str(thread_name, THREAD);
   447   if (has_init_error(THREAD)) {
   451   if (has_init_error(THREAD)) {
       
   452     set_state(AL_NOT_INITIALIZED);
   448     return;
   453     return;
   449   }
   454   }
   450 
   455 
   451   // Initialize thread_oop to put it into the system threadGroup
   456   // Initialize thread_oop to put it into the system threadGroup
   452   Handle thread_group (THREAD, Universe::system_thread_group());
   457   Handle thread_group (THREAD, Universe::system_thread_group());
   454                        vmSymbols::threadgroup_string_void_signature(),
   459                        vmSymbols::threadgroup_string_void_signature(),
   455                        thread_group,
   460                        thread_group,
   456                        string,
   461                        string,
   457                        THREAD);
   462                        THREAD);
   458   if (has_init_error(THREAD)) {
   463   if (has_init_error(THREAD)) {
       
   464     set_state(AL_NOT_INITIALIZED);
   459     return;
   465     return;
   460   }
   466   }
   461 
   467 
   462   Klass* group = SystemDictionary::ThreadGroup_klass();
   468   Klass* group = SystemDictionary::ThreadGroup_klass();
   463   JavaValue result(T_VOID);
   469   JavaValue result(T_VOID);
   467                         vmSymbols::add_method_name(),
   473                         vmSymbols::add_method_name(),
   468                         vmSymbols::thread_void_signature(),
   474                         vmSymbols::thread_void_signature(),
   469                         thread_oop,
   475                         thread_oop,
   470                         THREAD);
   476                         THREAD);
   471   if (has_init_error(THREAD)) {
   477   if (has_init_error(THREAD)) {
       
   478     set_state(AL_NOT_INITIALIZED);
   472     return;
   479     return;
   473   }
   480   }
   474 
   481 
   475   { MutexLocker mu(Threads_lock);
   482   { MutexLocker mu(Threads_lock);
   476     JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry);
   483     JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry);