src/share/vm/runtime/serviceThread.cpp

Print this page




  53                           string,
  54                           CHECK);
  55 
  56   {
  57     MutexLocker mu(Threads_lock);
  58     ServiceThread* thread =  new ServiceThread(&service_thread_entry);
  59 
  60     // At this point it may be possible that no osthread was created for the
  61     // JavaThread due to lack of memory. We would have to throw an exception
  62     // in that case. However, since this must work and we do not allow
  63     // exceptions anyway, check and abort if this fails.
  64     if (thread == NULL || thread->osthread() == NULL) {
  65       vm_exit_during_initialization("java.lang.OutOfMemoryError",
  66                                     "unable to create new native thread");
  67     }
  68 
  69     java_lang_Thread::set_thread(thread_oop(), thread);
  70     java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
  71     java_lang_Thread::set_daemon(thread_oop());
  72     thread->set_threadObj(thread_oop());

  73 
  74     Threads::add(thread);
  75     Thread::start(thread);
  76 
  77     _instance = thread;
  78   }
  79 }
  80 
  81 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
  82   while (true) {
  83     bool sensors_changed = false;
  84     bool has_jvmti_events = false;
  85     JvmtiDeferredEvent jvmti_event;
  86     {
  87       // Need state transition ThreadBlockInVM so that this thread
  88       // will be handled by safepoint correctly when this thread is
  89       // notified at a safepoint.
  90 
  91       // This ThreadBlockInVM object is not also considered to be
  92       // suspend-equivalent because ServiceThread is not visible to
  93       // external suspension.
  94 
  95       ThreadBlockInVM tbivm(jt);
  96 
  97       MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);




  53                           string,
  54                           CHECK);
  55 
  56   {
  57     MutexLocker mu(Threads_lock);
  58     ServiceThread* thread =  new ServiceThread(&service_thread_entry);
  59 
  60     // At this point it may be possible that no osthread was created for the
  61     // JavaThread due to lack of memory. We would have to throw an exception
  62     // in that case. However, since this must work and we do not allow
  63     // exceptions anyway, check and abort if this fails.
  64     if (thread == NULL || thread->osthread() == NULL) {
  65       vm_exit_during_initialization("java.lang.OutOfMemoryError",
  66                                     "unable to create new native thread");
  67     }
  68 
  69     java_lang_Thread::set_thread(thread_oop(), thread);
  70     java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
  71     java_lang_Thread::set_daemon(thread_oop());
  72     thread->set_threadObj(thread_oop());
  73     _instance = thread;
  74 
  75     Threads::add(thread);
  76     Thread::start(thread);


  77   }
  78 }
  79 
  80 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
  81   while (true) {
  82     bool sensors_changed = false;
  83     bool has_jvmti_events = false;
  84     JvmtiDeferredEvent jvmti_event;
  85     {
  86       // Need state transition ThreadBlockInVM so that this thread
  87       // will be handled by safepoint correctly when this thread is
  88       // notified at a safepoint.
  89 
  90       // This ThreadBlockInVM object is not also considered to be
  91       // suspend-equivalent because ServiceThread is not visible to
  92       // external suspension.
  93 
  94       ThreadBlockInVM tbivm(jt);
  95 
  96       MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);