72 }
73
74 java_lang_Thread::set_thread(thread_oop(), thread);
75 java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
76 java_lang_Thread::set_daemon(thread_oop());
77 thread->set_threadObj(thread_oop());
78 _instance = thread;
79
80 Threads::add(thread);
81 Thread::start(thread);
82 }
83 }
84
85 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
86 while (true) {
87 bool sensors_changed = false;
88 bool has_jvmti_events = false;
89 bool has_gc_notification_event = false;
90 bool has_dcmd_notification_event = false;
91 bool acs_notify = false;
92 JvmtiDeferredEvent jvmti_event;
93 {
94 // Need state transition ThreadBlockInVM so that this thread
95 // will be handled by safepoint correctly when this thread is
96 // notified at a safepoint.
97
98 // This ThreadBlockInVM object is not also considered to be
99 // suspend-equivalent because ServiceThread is not visible to
100 // external suspension.
101
102 ThreadBlockInVM tbivm(jt);
103
104 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
105 while (!(sensors_changed = LowMemoryDetector::has_pending_requests()) &&
106 !(has_jvmti_events = JvmtiDeferredEventQueue::has_events()) &&
107 !(has_gc_notification_event = GCNotifier::has_event()) &&
108 !(has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) &&
109 !(acs_notify = AllocationContextService::should_notify())) {
110 // wait until one of the sensors has pending requests, or there is a
111 // pending JVMTI event or JMX GC notification to post
112 Service_lock->wait(Mutex::_no_safepoint_check_flag);
113 }
114
115 if (has_jvmti_events) {
116 jvmti_event = JvmtiDeferredEventQueue::dequeue();
117 }
118 }
119
120 if (has_jvmti_events) {
121 jvmti_event.post();
122 }
123
124 if (sensors_changed) {
125 LowMemoryDetector::process_sensor_changes(jt);
126 }
127
128 if(has_gc_notification_event) {
129 GCNotifier::sendNotification(CHECK);
130 }
131
132 if(has_dcmd_notification_event) {
133 DCmdFactory::send_notification(CHECK);
134 }
135
136 if (acs_notify) {
137 AllocationContextService::notify(CHECK);
138 }
139 }
140 }
141
142 bool ServiceThread::is_service_thread(Thread* thread) {
143 return thread == _instance;
144 }
|
72 }
73
74 java_lang_Thread::set_thread(thread_oop(), thread);
75 java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
76 java_lang_Thread::set_daemon(thread_oop());
77 thread->set_threadObj(thread_oop());
78 _instance = thread;
79
80 Threads::add(thread);
81 Thread::start(thread);
82 }
83 }
84
85 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
86 while (true) {
87 bool sensors_changed = false;
88 bool has_jvmti_events = false;
89 bool has_gc_notification_event = false;
90 bool has_dcmd_notification_event = false;
91 bool acs_notify = false;
92 bool deflate_idle_monitors = false;
93 JvmtiDeferredEvent jvmti_event;
94 {
95 // Need state transition ThreadBlockInVM so that this thread
96 // will be handled by safepoint correctly when this thread is
97 // notified at a safepoint.
98
99 // This ThreadBlockInVM object is not also considered to be
100 // suspend-equivalent because ServiceThread is not visible to
101 // external suspension.
102
103 ThreadBlockInVM tbivm(jt);
104
105 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
106 while (!(sensors_changed = LowMemoryDetector::has_pending_requests()) &&
107 !(has_jvmti_events = JvmtiDeferredEventQueue::has_events()) &&
108 !(has_gc_notification_event = GCNotifier::has_event()) &&
109 !(has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) &&
110 !(acs_notify = AllocationContextService::should_notify()) &&
111 !(deflate_idle_monitors = ObjectSynchronizer::should_deflate_idle_monitors_conc())) {
112 // wait until one of the sensors has pending requests, or there is a
113 // pending JVMTI event or JMX GC notification to post
114 Service_lock->wait(Mutex::_no_safepoint_check_flag);
115 }
116
117 if (has_jvmti_events) {
118 jvmti_event = JvmtiDeferredEventQueue::dequeue();
119 }
120 }
121
122 if (has_jvmti_events) {
123 jvmti_event.post();
124 }
125
126 if (sensors_changed) {
127 LowMemoryDetector::process_sensor_changes(jt);
128 }
129
130 if(has_gc_notification_event) {
131 GCNotifier::sendNotification(CHECK);
132 }
133
134 if(has_dcmd_notification_event) {
135 DCmdFactory::send_notification(CHECK);
136 }
137
138 if (acs_notify) {
139 AllocationContextService::notify(CHECK);
140 }
141
142 if (deflate_idle_monitors) {
143 ObjectSynchronizer::deflate_idle_monitors_conc();
144 }
145 }
146 }
147
148 bool ServiceThread::is_service_thread(Thread* thread) {
149 return thread == _instance;
150 }
|