109 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
110 OopStorage* const oopstorages[] = {
111 JNIHandles::global_handles(),
112 JNIHandles::weak_global_handles(),
113 StringTable::weak_storage(),
114 SystemDictionary::vm_weak_oop_storage()
115 };
116 const size_t oopstorage_count = ARRAY_SIZE(oopstorages);
117
118 while (true) {
119 bool sensors_changed = false;
120 bool has_jvmti_events = false;
121 bool has_gc_notification_event = false;
122 bool has_dcmd_notification_event = false;
123 bool stringtable_work = false;
124 bool symboltable_work = false;
125 bool resolved_method_table_work = false;
126 bool protection_domain_table_work = false;
127 bool oopstorage_work = false;
128 bool oopstorages_cleanup[oopstorage_count] = {}; // Zero (false) initialize.
129 JvmtiDeferredEvent jvmti_event;
130 {
131 // Need state transition ThreadBlockInVM so that this thread
132 // will be handled by safepoint correctly when this thread is
133 // notified at a safepoint.
134
135 // This ThreadBlockInVM object is not also considered to be
136 // suspend-equivalent because ServiceThread is not visible to
137 // external suspension.
138
139 ThreadBlockInVM tbivm(jt);
140
141 MonitorLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
142 // Process all available work on each (outer) iteration, rather than
143 // only the first recognized bit of work, to avoid frequently true early
144 // tests from potentially starving later work. Hence the use of
145 // arithmetic-or to combine results; we don't want short-circuiting.
146 while (((sensors_changed = LowMemoryDetector::has_pending_requests()) |
147 (has_jvmti_events = JvmtiDeferredEventQueue::has_events()) |
148 (has_gc_notification_event = GCNotifier::has_event()) |
149 (has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) |
150 (stringtable_work = StringTable::has_work()) |
151 (symboltable_work = SymbolTable::has_work()) |
152 (resolved_method_table_work = ResolvedMethodTable::has_work()) |
153 (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) |
154 (oopstorage_work = needs_oopstorage_cleanup(oopstorages,
155 oopstorages_cleanup,
156 oopstorage_count)))
157
158 == 0) {
159 // Wait until notified that there is some work to do.
160 ml.wait(Mutex::_no_safepoint_check_flag);
161 }
162
163 if (has_jvmti_events) {
164 jvmti_event = JvmtiDeferredEventQueue::dequeue();
165 }
166 }
167
168 if (stringtable_work) {
169 StringTable::do_concurrent_work(jt);
170 }
171
172 if (symboltable_work) {
173 SymbolTable::do_concurrent_work(jt);
174 }
175
176 if (has_jvmti_events) {
177 jvmti_event.post();
178 }
182 }
183
184 if(has_gc_notification_event) {
185 GCNotifier::sendNotification(CHECK);
186 }
187
188 if(has_dcmd_notification_event) {
189 DCmdFactory::send_notification(CHECK);
190 }
191
192 if (resolved_method_table_work) {
193 ResolvedMethodTable::do_concurrent_work(jt);
194 }
195
196 if (protection_domain_table_work) {
197 SystemDictionary::pd_cache_table()->unlink();
198 }
199
200 if (oopstorage_work) {
201 cleanup_oopstorages(oopstorages, oopstorages_cleanup, oopstorage_count);
202 }
203 }
204 }
205
206 bool ServiceThread::is_service_thread(Thread* thread) {
207 return thread == _instance;
208 }
|
109 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
110 OopStorage* const oopstorages[] = {
111 JNIHandles::global_handles(),
112 JNIHandles::weak_global_handles(),
113 StringTable::weak_storage(),
114 SystemDictionary::vm_weak_oop_storage()
115 };
116 const size_t oopstorage_count = ARRAY_SIZE(oopstorages);
117
118 while (true) {
119 bool sensors_changed = false;
120 bool has_jvmti_events = false;
121 bool has_gc_notification_event = false;
122 bool has_dcmd_notification_event = false;
123 bool stringtable_work = false;
124 bool symboltable_work = false;
125 bool resolved_method_table_work = false;
126 bool protection_domain_table_work = false;
127 bool oopstorage_work = false;
128 bool oopstorages_cleanup[oopstorage_count] = {}; // Zero (false) initialize.
129 bool deflate_idle_monitors = false;
130 JvmtiDeferredEvent jvmti_event;
131 {
132 // Need state transition ThreadBlockInVM so that this thread
133 // will be handled by safepoint correctly when this thread is
134 // notified at a safepoint.
135
136 // This ThreadBlockInVM object is not also considered to be
137 // suspend-equivalent because ServiceThread is not visible to
138 // external suspension.
139
140 ThreadBlockInVM tbivm(jt);
141
142 MonitorLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
143 // Process all available work on each (outer) iteration, rather than
144 // only the first recognized bit of work, to avoid frequently true early
145 // tests from potentially starving later work. Hence the use of
146 // arithmetic-or to combine results; we don't want short-circuiting.
147 while (((sensors_changed = LowMemoryDetector::has_pending_requests()) |
148 (has_jvmti_events = JvmtiDeferredEventQueue::has_events()) |
149 (has_gc_notification_event = GCNotifier::has_event()) |
150 (has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) |
151 (stringtable_work = StringTable::has_work()) |
152 (symboltable_work = SymbolTable::has_work()) |
153 (resolved_method_table_work = ResolvedMethodTable::has_work()) |
154 (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) |
155 (oopstorage_work = needs_oopstorage_cleanup(oopstorages,
156 oopstorages_cleanup,
157 oopstorage_count)) |
158 (deflate_idle_monitors = ObjectSynchronizer::gOmShouldDeflateIdleMonitors())
159 ) == 0) {
160 // Wait until notified that there is some work to do.
161 ml.wait(Mutex::_no_safepoint_check_flag);
162 }
163
164 if (has_jvmti_events) {
165 jvmti_event = JvmtiDeferredEventQueue::dequeue();
166 }
167 }
168
169 if (stringtable_work) {
170 StringTable::do_concurrent_work(jt);
171 }
172
173 if (symboltable_work) {
174 SymbolTable::do_concurrent_work(jt);
175 }
176
177 if (has_jvmti_events) {
178 jvmti_event.post();
179 }
183 }
184
185 if(has_gc_notification_event) {
186 GCNotifier::sendNotification(CHECK);
187 }
188
189 if(has_dcmd_notification_event) {
190 DCmdFactory::send_notification(CHECK);
191 }
192
193 if (resolved_method_table_work) {
194 ResolvedMethodTable::do_concurrent_work(jt);
195 }
196
197 if (protection_domain_table_work) {
198 SystemDictionary::pd_cache_table()->unlink();
199 }
200
201 if (oopstorage_work) {
202 cleanup_oopstorages(oopstorages, oopstorages_cleanup, oopstorage_count);
203 }
204
205 if (deflate_idle_monitors) {
206 // Deflate any global idle monitors.
207 // deflate_per_thread_idle_monitors_using_JT() is called by
208 // each JavaThread from ObjectSynchronizer::omAlloc() as needed.
209 ObjectSynchronizer::deflate_global_idle_monitors_using_JT();
210 }
211 }
212 }
213
214 bool ServiceThread::is_service_thread(Thread* thread) {
215 return thread == _instance;
216 }
|