223 PerfDataManager::create_counter(SUN_THREADS, "vmOperationTime",
224 PerfData::U_Ticks, CHECK);
225 }
226 }
227
228
229 VMThread::VMThread() : NamedThread() {
230 set_name("VM Thread");
231 }
232
233 void VMThread::destroy() {
234 if (_vm_thread != NULL) {
235 delete _vm_thread;
236 _vm_thread = NULL; // VM thread is gone
237 }
238 }
239
240 void VMThread::run() {
241 assert(this == vm_thread(), "check");
242
243 this->initialize_thread_local_storage();
244 this->initialize_named_thread();
245 this->record_stack_base_and_size();
246 // Notify_lock wait checks on active_handles() to rewait in
247 // case of spurious wakeup, it should wait on the last
248 // value set prior to the notify
249 this->set_active_handles(JNIHandleBlock::allocate_block());
250
251 {
252 MutexLocker ml(Notify_lock);
253 Notify_lock->notify();
254 }
255 // Notify_lock is destroyed by Threads::create_vm()
256
257 int prio = (VMThreadPriority == -1)
258 ? os::java_to_os_priority[NearMaxPriority]
259 : VMThreadPriority;
260 // Note that I cannot call os::set_priority because it expects Java
261 // priorities and I am *explicitly* using OS priorities so that it's
262 // possible to set the VM thread priority higher than any Java thread.
263 os::set_native_priority( this, prio );
290 }
291
292 CompileBroker::set_should_block();
293
294 // wait for threads (compiler threads or daemon threads) in the
295 // _thread_in_native state to block.
296 VM_Exit::wait_for_threads_in_native_to_block();
297
298 // signal other threads that VM process is gone
299 {
300 // Note: we must have the _no_safepoint_check_flag. Mutex::lock() allows
301 // VM thread to enter any lock at Safepoint as long as its _owner is NULL.
302 // If that happens after _terminate_lock->wait() has unset _owner
303 // but before it actually drops the lock and waits, the notification below
304 // may get lost and we will have a hang. To avoid this, we need to use
305 // Mutex::lock_without_safepoint_check().
306 MutexLockerEx ml(_terminate_lock, Mutex::_no_safepoint_check_flag);
307 _terminated = true;
308 _terminate_lock->notify();
309 }
310
311 // Thread destructor usually does this.
312 ThreadLocalStorage::set_thread(NULL);
313
314 // Deletion must be done synchronously by the JNI DestroyJavaVM thread
315 // so that the VMThread deletion completes before the main thread frees
316 // up the CodeHeap.
317
318 }
319
320
321 // Notify the VMThread that the last non-daemon JavaThread has terminated,
322 // and wait until operation is performed.
323 void VMThread::wait_for_vm_thread_exit() {
324 { MutexLocker mu(VMOperationQueue_lock);
325 _should_terminate = true;
326 VMOperationQueue_lock->notify();
327 }
328
329 // Note: VM thread leaves at Safepoint. We are not stopped by Safepoint
330 // because this thread has been removed from the threads list. But anything
331 // that could get blocked by Safepoint should not be used after this point,
332 // otherwise we will hang, since there is no one can end the safepoint.
|
223 PerfDataManager::create_counter(SUN_THREADS, "vmOperationTime",
224 PerfData::U_Ticks, CHECK);
225 }
226 }
227
228
229 VMThread::VMThread() : NamedThread() {
230 set_name("VM Thread");
231 }
232
233 void VMThread::destroy() {
234 if (_vm_thread != NULL) {
235 delete _vm_thread;
236 _vm_thread = NULL; // VM thread is gone
237 }
238 }
239
240 void VMThread::run() {
241 assert(this == vm_thread(), "check");
242
243 this->initialize_named_thread();
244 this->record_stack_base_and_size();
245 // Notify_lock wait checks on active_handles() to rewait in
246 // case of spurious wakeup, it should wait on the last
247 // value set prior to the notify
248 this->set_active_handles(JNIHandleBlock::allocate_block());
249
250 {
251 MutexLocker ml(Notify_lock);
252 Notify_lock->notify();
253 }
254 // Notify_lock is destroyed by Threads::create_vm()
255
256 int prio = (VMThreadPriority == -1)
257 ? os::java_to_os_priority[NearMaxPriority]
258 : VMThreadPriority;
259 // Note that I cannot call os::set_priority because it expects Java
260 // priorities and I am *explicitly* using OS priorities so that it's
261 // possible to set the VM thread priority higher than any Java thread.
262 os::set_native_priority( this, prio );
289 }
290
291 CompileBroker::set_should_block();
292
293 // wait for threads (compiler threads or daemon threads) in the
294 // _thread_in_native state to block.
295 VM_Exit::wait_for_threads_in_native_to_block();
296
297 // signal other threads that VM process is gone
298 {
299 // Note: we must have the _no_safepoint_check_flag. Mutex::lock() allows
300 // VM thread to enter any lock at Safepoint as long as its _owner is NULL.
301 // If that happens after _terminate_lock->wait() has unset _owner
302 // but before it actually drops the lock and waits, the notification below
303 // may get lost and we will have a hang. To avoid this, we need to use
304 // Mutex::lock_without_safepoint_check().
305 MutexLockerEx ml(_terminate_lock, Mutex::_no_safepoint_check_flag);
306 _terminated = true;
307 _terminate_lock->notify();
308 }
309
310 // Deletion must be done synchronously by the JNI DestroyJavaVM thread
311 // so that the VMThread deletion completes before the main thread frees
312 // up the CodeHeap.
313
314 }
315
316
317 // Notify the VMThread that the last non-daemon JavaThread has terminated,
318 // and wait until operation is performed.
319 void VMThread::wait_for_vm_thread_exit() {
320 { MutexLocker mu(VMOperationQueue_lock);
321 _should_terminate = true;
322 VMOperationQueue_lock->notify();
323 }
324
325 // Note: VM thread leaves at Safepoint. We are not stopped by Safepoint
326 // because this thread has been removed from the threads list. But anything
327 // that could get blocked by Safepoint should not be used after this point,
328 // otherwise we will hang, since there is no one can end the safepoint.
|