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_weak_oop_storage()
98 };
99 const size_t oopstorage_count = ARRAY_SIZE(oopstorages);
100
101 while (true) {
102 bool sensors_changed = false;
103 bool has_jvmti_events = false;
104 bool has_gc_notification_event = false;
105 bool has_dcmd_notification_event = false;
106 bool stringtable_work = false;
107 bool symboltable_work = false;
108 bool resolved_method_table_work = false;
109 bool protection_domain_table_work = false;
110 bool oopstorage_work = false;
111 JvmtiDeferredEvent jvmti_event;
112 {
113 // Need state transition ThreadBlockInVM so that this thread
114 // will be handled by safepoint correctly when this thread is
115 // notified at a safepoint.
116
117 // This ThreadBlockInVM object is not also considered to be
118 // suspend-equivalent because ServiceThread is not visible to
119 // external suspension.
120
121 ThreadBlockInVM tbivm(jt);
122
123 MonitorLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
124 // Process all available work on each (outer) iteration, rather than
125 // only the first recognized bit of work, to avoid frequently true early
126 // tests from potentially starving later work. Hence the use of
127 // arithmetic-or to combine results; we don't want short-circuiting.
128 while (((sensors_changed = LowMemoryDetector::has_pending_requests()) |
129 (has_jvmti_events = JvmtiDeferredEventQueue::has_events()) |
130 (has_gc_notification_event = GCNotifier::has_event()) |
131 (has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) |
132 (stringtable_work = StringTable::has_work()) |
133 (symboltable_work = SymbolTable::has_work()) |
134 (resolved_method_table_work = ResolvedMethodTable::has_work()) |
135 (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) |
136 (oopstorage_work = OopStorage::has_cleanup_work_and_reset()))
137 == 0) {
138 // Wait until notified that there is some work to do.
139 ml.wait();
140 }
141
142 if (has_jvmti_events) {
143 jvmti_event = JvmtiDeferredEventQueue::dequeue();
144 }
145 }
146
147 if (stringtable_work) {
148 StringTable::do_concurrent_work(jt);
149 }
150
151 if (symboltable_work) {
152 SymbolTable::do_concurrent_work(jt);
153 }
154
155 if (has_jvmti_events) {
156 jvmti_event.post();
157 }
158
159 if (sensors_changed) {
161 }
162
163 if(has_gc_notification_event) {
164 GCNotifier::sendNotification(CHECK);
165 }
166
167 if(has_dcmd_notification_event) {
168 DCmdFactory::send_notification(CHECK);
169 }
170
171 if (resolved_method_table_work) {
172 ResolvedMethodTable::do_concurrent_work(jt);
173 }
174
175 if (protection_domain_table_work) {
176 SystemDictionary::pd_cache_table()->unlink();
177 }
178
179 if (oopstorage_work) {
180 cleanup_oopstorages(oopstorages, oopstorage_count);
181 }
182 }
183 }
184
185 bool ServiceThread::is_service_thread(Thread* thread) {
186 return thread == _instance;
187 }
|
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_weak_oop_storage()
98 };
99 const size_t oopstorage_count = ARRAY_SIZE(oopstorages);
100
101 while (true) {
102 bool sensors_changed = false;
103 bool has_jvmti_events = false;
104 bool has_gc_notification_event = false;
105 bool has_dcmd_notification_event = false;
106 bool stringtable_work = false;
107 bool symboltable_work = false;
108 bool resolved_method_table_work = false;
109 bool protection_domain_table_work = false;
110 bool oopstorage_work = false;
111 bool deflate_idle_monitors = 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 (deflate_idle_monitors = ObjectSynchronizer::is_async_deflation_needed())
139 ) == 0) {
140 // Wait until notified that there is some work to do.
141 // If AsyncDeflateIdleMonitors, then we wait for
142 // GuaranteedSafepointInterval so that is_async_deflation_needed()
143 // is checked at the same interval.
144 ml.wait(AsyncDeflateIdleMonitors ? GuaranteedSafepointInterval : 0);
145 }
146
147 if (has_jvmti_events) {
148 jvmti_event = JvmtiDeferredEventQueue::dequeue();
149 }
150 }
151
152 if (stringtable_work) {
153 StringTable::do_concurrent_work(jt);
154 }
155
156 if (symboltable_work) {
157 SymbolTable::do_concurrent_work(jt);
158 }
159
160 if (has_jvmti_events) {
161 jvmti_event.post();
162 }
163
164 if (sensors_changed) {
166 }
167
168 if(has_gc_notification_event) {
169 GCNotifier::sendNotification(CHECK);
170 }
171
172 if(has_dcmd_notification_event) {
173 DCmdFactory::send_notification(CHECK);
174 }
175
176 if (resolved_method_table_work) {
177 ResolvedMethodTable::do_concurrent_work(jt);
178 }
179
180 if (protection_domain_table_work) {
181 SystemDictionary::pd_cache_table()->unlink();
182 }
183
184 if (oopstorage_work) {
185 cleanup_oopstorages(oopstorages, oopstorage_count);
186 }
187
188 if (deflate_idle_monitors) {
189 // Deflate any global idle monitors.
190 ObjectSynchronizer::deflate_global_idle_monitors_using_JT();
191
192 // deflate_per_thread_idle_monitors_using_JT() is called by
193 // each JavaThread from ObjectSynchronizer::omAlloc() as needed.
194 int count = 0;
195 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) {
196 if (jt->omInUseCount > 0) {
197 // This JavaThread is using monitors so mark it.
198 jt->omShouldDeflateIdleMonitors = true;
199 count++;
200 }
201 }
202 if (count > 0) {
203 log_debug(monitorinflation)("requesting async deflation of idle monitors for %d thread(s).", count);
204 }
205 // The ServiceThread's async deflation request has been processed.
206 ObjectSynchronizer::set_is_async_deflation_requested(false);
207
208 // The global in-use list was handled above, but the request won't
209 // be complete until the JavaThreads have handled their in-use
210 // lists. This is the nature of an async deflation request.
211 }
212 }
213 }
214
215 bool ServiceThread::is_service_thread(Thread* thread) {
216 return thread == _instance;
217 }
|