89
90 static void cleanup_oopstorages() {
91 OopStorageSet::Iterator it = OopStorageSet::all_iterator();
92 for ( ; !it.is_end(); ++it) {
93 it->delete_empty_blocks();
94 }
95 }
96
97 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
98 while (true) {
99 bool sensors_changed = false;
100 bool has_jvmti_events = false;
101 bool has_gc_notification_event = false;
102 bool has_dcmd_notification_event = false;
103 bool stringtable_work = false;
104 bool symboltable_work = false;
105 bool resolved_method_table_work = false;
106 bool thread_id_table_work = false;
107 bool protection_domain_table_work = false;
108 bool oopstorage_work = false;
109 JvmtiDeferredEvent jvmti_event;
110 {
111 // Need state transition ThreadBlockInVM so that this thread
112 // will be handled by safepoint correctly when this thread is
113 // notified at a safepoint.
114
115 // This ThreadBlockInVM object is not also considered to be
116 // suspend-equivalent because ServiceThread is not visible to
117 // external suspension.
118
119 ThreadBlockInVM tbivm(jt);
120
121 MonitorLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
122 // Process all available work on each (outer) iteration, rather than
123 // only the first recognized bit of work, to avoid frequently true early
124 // tests from potentially starving later work. Hence the use of
125 // arithmetic-or to combine results; we don't want short-circuiting.
126 while (((sensors_changed = (!UseNotificationThread && LowMemoryDetector::has_pending_requests())) |
127 (has_jvmti_events = JvmtiDeferredEventQueue::has_events()) |
128 (has_gc_notification_event = (!UseNotificationThread && GCNotifier::has_event())) |
129 (has_dcmd_notification_event = (!UseNotificationThread && DCmdFactory::has_pending_jmx_notification())) |
130 (stringtable_work = StringTable::has_work()) |
131 (symboltable_work = SymbolTable::has_work()) |
132 (resolved_method_table_work = ResolvedMethodTable::has_work()) |
133 (thread_id_table_work = ThreadIdTable::has_work()) |
134 (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) |
135 (oopstorage_work = OopStorage::has_cleanup_work_and_reset())
136 ) == 0) {
137 // Wait until notified that there is some work to do.
138 ml.wait();
139 }
140
141 if (has_jvmti_events) {
142 // Get the event under the Service_lock
143 jvmti_event = JvmtiDeferredEventQueue::dequeue();
144 _jvmti_event = &jvmti_event;
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 _jvmti_event = NULL; // reset
170 if(has_dcmd_notification_event) {
171 DCmdFactory::send_notification(CHECK);
172 }
173 }
174
175 if (resolved_method_table_work) {
176 ResolvedMethodTable::do_concurrent_work(jt);
177 }
178
179 if (thread_id_table_work) {
180 ThreadIdTable::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();
189 }
190 }
191 }
192
193 void ServiceThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
194 JavaThread::oops_do(f, cf);
195 // The ServiceThread "owns" the JVMTI Deferred events, scan them here
196 // to keep them alive until they are processed.
197 if (cf != NULL) {
198 if (_jvmti_event != NULL) {
199 _jvmti_event->oops_do(f, cf);
200 }
201 MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
202 JvmtiDeferredEventQueue::oops_do(f, cf);
203 }
204 }
205
206 void ServiceThread::nmethods_do(CodeBlobClosure* cf) {
207 JavaThread::nmethods_do(cf);
208 if (cf != NULL) {
209 if (_jvmti_event != NULL) {
|
89
90 static void cleanup_oopstorages() {
91 OopStorageSet::Iterator it = OopStorageSet::all_iterator();
92 for ( ; !it.is_end(); ++it) {
93 it->delete_empty_blocks();
94 }
95 }
96
97 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
98 while (true) {
99 bool sensors_changed = false;
100 bool has_jvmti_events = false;
101 bool has_gc_notification_event = false;
102 bool has_dcmd_notification_event = false;
103 bool stringtable_work = false;
104 bool symboltable_work = false;
105 bool resolved_method_table_work = false;
106 bool thread_id_table_work = false;
107 bool protection_domain_table_work = false;
108 bool oopstorage_work = false;
109 bool deflate_idle_monitors = false;
110 JvmtiDeferredEvent jvmti_event;
111 {
112 // Need state transition ThreadBlockInVM so that this thread
113 // will be handled by safepoint correctly when this thread is
114 // notified at a safepoint.
115
116 // This ThreadBlockInVM object is not also considered to be
117 // suspend-equivalent because ServiceThread is not visible to
118 // external suspension.
119
120 ThreadBlockInVM tbivm(jt);
121
122 MonitorLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
123 // Process all available work on each (outer) iteration, rather than
124 // only the first recognized bit of work, to avoid frequently true early
125 // tests from potentially starving later work. Hence the use of
126 // arithmetic-or to combine results; we don't want short-circuiting.
127 while (((sensors_changed = (!UseNotificationThread && LowMemoryDetector::has_pending_requests())) |
128 (has_jvmti_events = JvmtiDeferredEventQueue::has_events()) |
129 (has_gc_notification_event = (!UseNotificationThread && GCNotifier::has_event())) |
130 (has_dcmd_notification_event = (!UseNotificationThread && DCmdFactory::has_pending_jmx_notification())) |
131 (stringtable_work = StringTable::has_work()) |
132 (symboltable_work = SymbolTable::has_work()) |
133 (resolved_method_table_work = ResolvedMethodTable::has_work()) |
134 (thread_id_table_work = ThreadIdTable::has_work()) |
135 (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) |
136 (oopstorage_work = OopStorage::has_cleanup_work_and_reset()) |
137 (deflate_idle_monitors = ObjectSynchronizer::is_async_deflation_needed())
138 ) == 0) {
139 // Wait until notified that there is some work to do.
140 // If AsyncDeflateIdleMonitors, then we wait for
141 // GuaranteedSafepointInterval so that is_async_deflation_needed()
142 // is checked at the same interval.
143 ml.wait(AsyncDeflateIdleMonitors ? GuaranteedSafepointInterval : 0);
144 }
145
146 if (has_jvmti_events) {
147 // Get the event under the Service_lock
148 jvmti_event = JvmtiDeferredEventQueue::dequeue();
149 _jvmti_event = &jvmti_event;
150 }
151 }
152
153 if (stringtable_work) {
154 StringTable::do_concurrent_work(jt);
155 }
156
157 if (symboltable_work) {
158 SymbolTable::do_concurrent_work(jt);
159 }
160
161 if (has_jvmti_events) {
162 _jvmti_event->post();
163 _jvmti_event = NULL; // reset
175 if(has_dcmd_notification_event) {
176 DCmdFactory::send_notification(CHECK);
177 }
178 }
179
180 if (resolved_method_table_work) {
181 ResolvedMethodTable::do_concurrent_work(jt);
182 }
183
184 if (thread_id_table_work) {
185 ThreadIdTable::do_concurrent_work(jt);
186 }
187
188 if (protection_domain_table_work) {
189 SystemDictionary::pd_cache_table()->unlink();
190 }
191
192 if (oopstorage_work) {
193 cleanup_oopstorages();
194 }
195
196 if (deflate_idle_monitors) {
197 ObjectSynchronizer::deflate_idle_monitors_using_JT();
198 }
199 }
200 }
201
202 void ServiceThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
203 JavaThread::oops_do(f, cf);
204 // The ServiceThread "owns" the JVMTI Deferred events, scan them here
205 // to keep them alive until they are processed.
206 if (cf != NULL) {
207 if (_jvmti_event != NULL) {
208 _jvmti_event->oops_do(f, cf);
209 }
210 MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
211 JvmtiDeferredEventQueue::oops_do(f, cf);
212 }
213 }
214
215 void ServiceThread::nmethods_do(CodeBlobClosure* cf) {
216 JavaThread::nmethods_do(cf);
217 if (cf != NULL) {
218 if (_jvmti_event != NULL) {
|