< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page
rev 49294 : imported patch 8199813


2375   // by the time we return from SR_lock()->wait(). The thread
2376   // that requested the suspension may already be trying to walk our
2377   // stack and if we return now, we can change the stack out from under
2378   // it. This would be a "bad thing (TM)" and cause the stack walker
2379   // to crash. We stay self-suspended until there are no more pending
2380   // external suspend requests.
2381   while (is_external_suspend()) {
2382     ret++;
2383     this->set_ext_suspended();
2384 
2385     // _ext_suspended flag is cleared by java_resume()
2386     while (is_ext_suspended()) {
2387       this->SR_lock()->wait(Mutex::_no_safepoint_check_flag);
2388     }
2389   }
2390 
2391   return ret;
2392 }
2393 
2394 #ifdef ASSERT
2395 // verify the JavaThread has not yet been published in the Threads::list, and
2396 // hence doesn't need protection from concurrent access at this stage
2397 void JavaThread::verify_not_published() {
2398   ThreadsListHandle tlh;
2399   assert(!tlh.includes(this), "JavaThread shouldn't have been published yet!");


2400 }
2401 #endif
2402 
2403 // Slow path when the native==>VM/Java barriers detect a safepoint is in
2404 // progress or when _suspend_flags is non-zero.
2405 // Current thread needs to self-suspend if there is a suspend request and/or
2406 // block if a safepoint is in progress.
2407 // Async exception ISN'T checked.
2408 // Note only the ThreadInVMfromNative transition can call this function
2409 // directly and when thread state is _thread_in_native_trans
2410 void JavaThread::check_safepoint_and_suspend_for_native_trans(JavaThread *thread) {
2411   assert(thread->thread_state() == _thread_in_native_trans, "wrong state");
2412 
2413   JavaThread *curJT = JavaThread::current();
2414   bool do_self_suspend = thread->is_external_suspend();
2415 
2416   assert(!curJT->has_last_Java_frame() || curJT->frame_anchor()->walkable(), "Unwalkable stack in native->vm transition");
2417 
2418   // If JNIEnv proxies are allowed, don't self-suspend if the target
2419   // thread is not the current thread. In older versions of jdbx, jdbx


4237   before_exit(thread);
4238 
4239   thread->exit(true);
4240 
4241   // Stop VM thread.
4242   {
4243     // 4945125 The vm thread comes to a safepoint during exit.
4244     // GC vm_operations can get caught at the safepoint, and the
4245     // heap is unparseable if they are caught. Grab the Heap_lock
4246     // to prevent this. The GC vm_operations will not be able to
4247     // queue until after the vm thread is dead. After this point,
4248     // we'll never emerge out of the safepoint before the VM exits.
4249 
4250     MutexLocker ml(Heap_lock);
4251 
4252     VMThread::wait_for_vm_thread_exit();
4253     assert(SafepointSynchronize::is_at_safepoint(), "VM thread should exit at Safepoint");
4254     VMThread::destroy();
4255   }
4256 
4257   // clean up ideal graph printers






4258 #if defined(COMPILER2) && !defined(PRODUCT)
4259   IdealGraphPrinter::clean_up();
4260 #endif
4261 
4262   // Now, all Java threads are gone except daemon threads. Daemon threads
4263   // running Java code or in VM are stopped by the Safepoint. However,
4264   // daemon threads executing native code are still running.  But they
4265   // will be stopped at native=>Java/VM barriers. Note that we can't
4266   // simply kill or suspend them, as it is inherently deadlock-prone.
4267 
4268   VM_Exit::set_vm_exited();
4269 
4270   notify_vm_shutdown();
4271 
4272   // We are after VM_Exit::set_vm_exited() so we can't call
4273   // thread->smr_delete() or we will block on the Threads_lock.
4274   // Deleting the shutdown thread here is safe because another
4275   // JavaThread cannot have an active ThreadsListHandle for
4276   // this JavaThread.
4277   delete thread;




2375   // by the time we return from SR_lock()->wait(). The thread
2376   // that requested the suspension may already be trying to walk our
2377   // stack and if we return now, we can change the stack out from under
2378   // it. This would be a "bad thing (TM)" and cause the stack walker
2379   // to crash. We stay self-suspended until there are no more pending
2380   // external suspend requests.
2381   while (is_external_suspend()) {
2382     ret++;
2383     this->set_ext_suspended();
2384 
2385     // _ext_suspended flag is cleared by java_resume()
2386     while (is_ext_suspended()) {
2387       this->SR_lock()->wait(Mutex::_no_safepoint_check_flag);
2388     }
2389   }
2390 
2391   return ret;
2392 }
2393 
2394 #ifdef ASSERT
2395 // Verify the JavaThread has not yet been published in the Threads::list, and
2396 // hence doesn't need protection from concurrent access at this stage.
2397 void JavaThread::verify_not_published() {
2398   // Cannot create a ThreadsListHandle here and check !tlh.includes(this)
2399   // since an unpublished JavaThread doesn't participate in the
2400   // Thread-SMR protocol for keeping a ThreadsList alive.
2401   assert(!on_thread_list(), "JavaThread shouldn't have been published yet!");
2402 }
2403 #endif
2404 
2405 // Slow path when the native==>VM/Java barriers detect a safepoint is in
2406 // progress or when _suspend_flags is non-zero.
2407 // Current thread needs to self-suspend if there is a suspend request and/or
2408 // block if a safepoint is in progress.
2409 // Async exception ISN'T checked.
2410 // Note only the ThreadInVMfromNative transition can call this function
2411 // directly and when thread state is _thread_in_native_trans
2412 void JavaThread::check_safepoint_and_suspend_for_native_trans(JavaThread *thread) {
2413   assert(thread->thread_state() == _thread_in_native_trans, "wrong state");
2414 
2415   JavaThread *curJT = JavaThread::current();
2416   bool do_self_suspend = thread->is_external_suspend();
2417 
2418   assert(!curJT->has_last_Java_frame() || curJT->frame_anchor()->walkable(), "Unwalkable stack in native->vm transition");
2419 
2420   // If JNIEnv proxies are allowed, don't self-suspend if the target
2421   // thread is not the current thread. In older versions of jdbx, jdbx


4239   before_exit(thread);
4240 
4241   thread->exit(true);
4242 
4243   // Stop VM thread.
4244   {
4245     // 4945125 The vm thread comes to a safepoint during exit.
4246     // GC vm_operations can get caught at the safepoint, and the
4247     // heap is unparseable if they are caught. Grab the Heap_lock
4248     // to prevent this. The GC vm_operations will not be able to
4249     // queue until after the vm thread is dead. After this point,
4250     // we'll never emerge out of the safepoint before the VM exits.
4251 
4252     MutexLocker ml(Heap_lock);
4253 
4254     VMThread::wait_for_vm_thread_exit();
4255     assert(SafepointSynchronize::is_at_safepoint(), "VM thread should exit at Safepoint");
4256     VMThread::destroy();
4257   }
4258 
4259   // Remember the Thread that is shutting down the VM because it needs
4260   // to be immune to some of the sanity checks and policies that have
4261   // to happen at VM shutdown time.
4262   VM_Exit::set_shutdown_thread(thread);
4263 
4264   // Clean up ideal graph printers after the VMThread has started
4265   // the final safepoint which will block all the Compiler threads.
4266 #if defined(COMPILER2) && !defined(PRODUCT)
4267   IdealGraphPrinter::clean_up();
4268 #endif
4269 
4270   // Now, all Java threads are gone except daemon threads. Daemon threads
4271   // running Java code or in VM are stopped by the Safepoint. However,
4272   // daemon threads executing native code are still running.  But they
4273   // will be stopped at native=>Java/VM barriers. Note that we can't
4274   // simply kill or suspend them, as it is inherently deadlock-prone.
4275 
4276   VM_Exit::set_vm_exited();
4277 
4278   notify_vm_shutdown();
4279 
4280   // We are after VM_Exit::set_vm_exited() so we can't call
4281   // thread->smr_delete() or we will block on the Threads_lock.
4282   // Deleting the shutdown thread here is safe because another
4283   // JavaThread cannot have an active ThreadsListHandle for
4284   // this JavaThread.
4285   delete thread;


< prev index next >