< prev index next >

src/hotspot/share/runtime/serviceThread.cpp

Print this page




  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/protectionDomainCache.hpp"
  27 #include "classfile/stringTable.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "memory/universe.hpp"
  31 #include "runtime/handles.inline.hpp"
  32 #include "runtime/interfaceSupport.inline.hpp"
  33 #include "runtime/javaCalls.hpp"
  34 #include "runtime/jniHandles.hpp"
  35 #include "runtime/serviceThread.hpp"
  36 #include "runtime/mutexLocker.hpp"
  37 #include "runtime/os.hpp"
  38 #include "prims/jvmtiImpl.hpp"
  39 #include "prims/resolvedMethodTable.hpp"
  40 #include "services/diagnosticArgument.hpp"
  41 #include "services/diagnosticFramework.hpp"
  42 #include "services/gcNotifier.hpp"
  43 #include "services/lowMemoryDetector.hpp"

  44 
  45 ServiceThread* ServiceThread::_instance = NULL;
  46 
  47 void ServiceThread::initialize() {
  48   EXCEPTION_MARK;
  49 
  50   const char* name = "Service Thread";
  51   Handle string = java_lang_String::create_from_str(name, CHECK);
  52 
  53   // Initialize thread_oop to put it into the system threadGroup
  54   Handle thread_group (THREAD, Universe::system_thread_group());
  55   Handle thread_oop = JavaCalls::construct_new_instance(
  56                           SystemDictionary::Thread_klass(),
  57                           vmSymbols::threadgroup_string_void_signature(),
  58                           thread_group,
  59                           string,
  60                           CHECK);
  61 
  62   {
  63     MutexLocker mu(Threads_lock);


  90 }
  91 
  92 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
  93   OopStorage* const oopstorages[] = {
  94     JNIHandles::global_handles(),
  95     JNIHandles::weak_global_handles(),
  96     StringTable::weak_storage(),
  97     SystemDictionary::vm_global_oop_storage(),
  98     SystemDictionary::vm_weak_oop_storage()
  99   };
 100   const size_t oopstorage_count = ARRAY_SIZE(oopstorages);
 101 
 102   while (true) {
 103     bool sensors_changed = false;
 104     bool has_jvmti_events = false;
 105     bool has_gc_notification_event = false;
 106     bool has_dcmd_notification_event = false;
 107     bool stringtable_work = false;
 108     bool symboltable_work = false;
 109     bool resolved_method_table_work = false;

 110     bool protection_domain_table_work = false;
 111     bool oopstorage_work = false;
 112     JvmtiDeferredEvent jvmti_event;
 113     {
 114       // Need state transition ThreadBlockInVM so that this thread
 115       // will be handled by safepoint correctly when this thread is
 116       // notified at a safepoint.
 117 
 118       // This ThreadBlockInVM object is not also considered to be
 119       // suspend-equivalent because ServiceThread is not visible to
 120       // external suspension.
 121 
 122       ThreadBlockInVM tbivm(jt);
 123 
 124       MonitorLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
 125       // Process all available work on each (outer) iteration, rather than
 126       // only the first recognized bit of work, to avoid frequently true early
 127       // tests from potentially starving later work.  Hence the use of
 128       // arithmetic-or to combine results; we don't want short-circuiting.
 129       while (((sensors_changed = LowMemoryDetector::has_pending_requests()) |
 130               (has_jvmti_events = JvmtiDeferredEventQueue::has_events()) |
 131               (has_gc_notification_event = GCNotifier::has_event()) |
 132               (has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) |
 133               (stringtable_work = StringTable::has_work()) |
 134               (symboltable_work = SymbolTable::has_work()) |
 135               (resolved_method_table_work = ResolvedMethodTable::has_work()) |

 136               (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) |
 137               (oopstorage_work = OopStorage::has_cleanup_work_and_reset()))
 138              == 0) {
 139         // Wait until notified that there is some work to do.
 140         ml.wait();
 141       }
 142 
 143       if (has_jvmti_events) {
 144         jvmti_event = JvmtiDeferredEventQueue::dequeue();
 145       }
 146     }
 147 
 148     if (stringtable_work) {
 149       StringTable::do_concurrent_work(jt);
 150     }
 151 
 152     if (symboltable_work) {
 153       SymbolTable::do_concurrent_work(jt);
 154     }
 155 
 156     if (has_jvmti_events) {
 157       jvmti_event.post();
 158     }
 159 
 160     if (sensors_changed) {
 161       LowMemoryDetector::process_sensor_changes(jt);
 162     }
 163 
 164     if(has_gc_notification_event) {
 165       GCNotifier::sendNotification(CHECK);
 166     }
 167 
 168     if(has_dcmd_notification_event) {
 169       DCmdFactory::send_notification(CHECK);
 170     }
 171 
 172     if (resolved_method_table_work) {
 173       ResolvedMethodTable::do_concurrent_work(jt);
 174     }
 175 




 176     if (protection_domain_table_work) {
 177       SystemDictionary::pd_cache_table()->unlink();
 178     }
 179 
 180     if (oopstorage_work) {
 181       cleanup_oopstorages(oopstorages, oopstorage_count);
 182     }
 183   }
 184 }
 185 
 186 bool ServiceThread::is_service_thread(Thread* thread) {
 187   return thread == _instance;
 188 }


  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/protectionDomainCache.hpp"
  27 #include "classfile/stringTable.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "memory/universe.hpp"
  31 #include "runtime/handles.inline.hpp"
  32 #include "runtime/interfaceSupport.inline.hpp"
  33 #include "runtime/javaCalls.hpp"
  34 #include "runtime/jniHandles.hpp"
  35 #include "runtime/serviceThread.hpp"
  36 #include "runtime/mutexLocker.hpp"
  37 #include "runtime/os.hpp"
  38 #include "prims/jvmtiImpl.hpp"
  39 #include "prims/resolvedMethodTable.hpp"
  40 #include "services/diagnosticArgument.hpp"
  41 #include "services/diagnosticFramework.hpp"
  42 #include "services/gcNotifier.hpp"
  43 #include "services/lowMemoryDetector.hpp"
  44 #include "services/threadTable.hpp"
  45 
  46 ServiceThread* ServiceThread::_instance = NULL;
  47 
  48 void ServiceThread::initialize() {
  49   EXCEPTION_MARK;
  50 
  51   const char* name = "Service Thread";
  52   Handle string = java_lang_String::create_from_str(name, CHECK);
  53 
  54   // Initialize thread_oop to put it into the system threadGroup
  55   Handle thread_group (THREAD, Universe::system_thread_group());
  56   Handle thread_oop = JavaCalls::construct_new_instance(
  57                           SystemDictionary::Thread_klass(),
  58                           vmSymbols::threadgroup_string_void_signature(),
  59                           thread_group,
  60                           string,
  61                           CHECK);
  62 
  63   {
  64     MutexLocker mu(Threads_lock);


  91 }
  92 
  93 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
  94   OopStorage* const oopstorages[] = {
  95     JNIHandles::global_handles(),
  96     JNIHandles::weak_global_handles(),
  97     StringTable::weak_storage(),
  98     SystemDictionary::vm_global_oop_storage(),
  99     SystemDictionary::vm_weak_oop_storage()
 100   };
 101   const size_t oopstorage_count = ARRAY_SIZE(oopstorages);
 102 
 103   while (true) {
 104     bool sensors_changed = false;
 105     bool has_jvmti_events = false;
 106     bool has_gc_notification_event = false;
 107     bool has_dcmd_notification_event = false;
 108     bool stringtable_work = false;
 109     bool symboltable_work = false;
 110     bool resolved_method_table_work = false;
 111     bool thread_table_work = false;
 112     bool protection_domain_table_work = false;
 113     bool oopstorage_work = false;
 114     JvmtiDeferredEvent jvmti_event;
 115     {
 116       // Need state transition ThreadBlockInVM so that this thread
 117       // will be handled by safepoint correctly when this thread is
 118       // notified at a safepoint.
 119 
 120       // This ThreadBlockInVM object is not also considered to be
 121       // suspend-equivalent because ServiceThread is not visible to
 122       // external suspension.
 123 
 124       ThreadBlockInVM tbivm(jt);
 125 
 126       MonitorLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
 127       // Process all available work on each (outer) iteration, rather than
 128       // only the first recognized bit of work, to avoid frequently true early
 129       // tests from potentially starving later work.  Hence the use of
 130       // arithmetic-or to combine results; we don't want short-circuiting.
 131       while (((sensors_changed = LowMemoryDetector::has_pending_requests()) |
 132               (has_jvmti_events = JvmtiDeferredEventQueue::has_events()) |
 133               (has_gc_notification_event = GCNotifier::has_event()) |
 134               (has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) |
 135               (stringtable_work = StringTable::has_work()) |
 136               (symboltable_work = SymbolTable::has_work()) |
 137               (resolved_method_table_work = ResolvedMethodTable::has_work()) |
 138               (thread_table_work = ThreadTable::has_work()) |
 139               (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) |
 140               (oopstorage_work = OopStorage::has_cleanup_work_and_reset()))
 141              == 0) {
 142         // Wait until notified that there is some work to do.
 143         ml.wait();
 144       }
 145 
 146       if (has_jvmti_events) {
 147         jvmti_event = JvmtiDeferredEventQueue::dequeue();
 148       }
 149     }
 150 
 151     if (stringtable_work) {
 152       StringTable::do_concurrent_work(jt);
 153     }
 154 
 155     if (symboltable_work) {
 156       SymbolTable::do_concurrent_work(jt);
 157     }
 158 
 159     if (has_jvmti_events) {
 160       jvmti_event.post();
 161     }
 162 
 163     if (sensors_changed) {
 164       LowMemoryDetector::process_sensor_changes(jt);
 165     }
 166 
 167     if(has_gc_notification_event) {
 168       GCNotifier::sendNotification(CHECK);
 169     }
 170 
 171     if(has_dcmd_notification_event) {
 172       DCmdFactory::send_notification(CHECK);
 173     }
 174 
 175     if (resolved_method_table_work) {
 176       ResolvedMethodTable::do_concurrent_work(jt);
 177     }
 178 
 179     if (thread_table_work) {
 180        ThreadTable::do_concurrent_work(jt);
 181     }
 182 
 183     if (protection_domain_table_work) {
 184       SystemDictionary::pd_cache_table()->unlink();
 185     }
 186 
 187     if (oopstorage_work) {
 188       cleanup_oopstorages(oopstorages, oopstorage_count);
 189     }
 190   }
 191 }
 192 
 193 bool ServiceThread::is_service_thread(Thread* thread) {
 194   return thread == _instance;
 195 }
< prev index next >