8235913: ThreadStop should be a handshake

Reviewed-by: dholmes, mdoerr
This commit is contained in:
Robbin Ehn 2019-12-19 17:02:11 +01:00
parent e4c96dea46
commit a170a4af4a
4 changed files with 22 additions and 44 deletions

View file

@ -526,9 +526,25 @@ void Thread::start(Thread* thread) {
}
}
class InstallAsyncExceptionClosure : public HandshakeClosure {
Handle _throwable; // The Throwable thrown at the target Thread
public:
InstallAsyncExceptionClosure(Handle throwable) : HandshakeClosure("InstallAsyncException"), _throwable(throwable) {}
void do_thread(Thread* thr) {
JavaThread* target = (JavaThread*)thr;
// Note that this now allows multiple ThreadDeath exceptions to be
// thrown at a thread.
// The target thread has run and has not exited yet.
target->send_thread_stop(_throwable());
}
};
void Thread::send_async_exception(oop java_thread, oop java_throwable) {
VM_ThreadStop vm_stop(java_thread, java_throwable);
VMThread::execute(&vm_stop);
Handle throwable(Thread::current(), java_throwable);
JavaThread* target = java_lang_Thread::thread(java_thread);
InstallAsyncExceptionClosure vm_stop(throwable);
Handshake::execute(&vm_stop, target);
}
@ -2383,9 +2399,8 @@ void JavaThread::handle_special_runtime_exit_condition(bool check_asyncs) {
}
void JavaThread::send_thread_stop(oop java_throwable) {
assert(Thread::current()->is_VM_thread(), "should be in the vm thread");
assert(Threads_lock->is_locked(), "Threads_lock should be locked by safepoint code");
assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
ResourceMark rm;
assert(Thread::current()->is_VM_thread() || Thread::current() == this, "should be in the vm thread");
// Do not throw asynchronous exceptions against the compiler thread
// (the compiler thread should not be a Java thread -- fix in 1.4.2)