Skip to content
Permalink
Browse files

8235913: ThreadStop should be a handshake

Reviewed-by: dholmes, mdoerr
  • Loading branch information
robehn committed Dec 19, 2019
1 parent e4c96de commit a170a4af4a84461a17aa596384f020a6babd90d8
@@ -37,7 +37,7 @@
#include "runtime/handles.inline.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/thread.hpp"
#include "runtime/thread.inline.hpp"

DEF_STUB_INTERFACE(ICStub);

@@ -165,11 +165,10 @@ void InlineCacheBuffer::refill_ic_stubs() {
if (HAS_PENDING_EXCEPTION) {
oop exception = PENDING_EXCEPTION;
CLEAR_PENDING_EXCEPTION;
Thread::send_async_exception(JavaThread::current()->threadObj(), exception);
JavaThread::current()->set_pending_async_exception(exception);
}
}


void InlineCacheBuffer::update_inline_caches() {
if (buffer()->number_of_stubs() > 0) {
if (TraceICBuffer) {
@@ -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)
@@ -85,18 +85,6 @@ void VM_Operation::print_on_error(outputStream* st) const {
}
}

void VM_ThreadStop::doit() {
assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
ThreadsListHandle tlh;
JavaThread* target = java_lang_Thread::thread(target_thread());
// Note that this now allows multiple ThreadDeath exceptions to be
// thrown at a thread.
if (target != NULL && (!EnableThreadSMRExtraValidityChecks || tlh.includes(target))) {
// The target thread has run and has not exited yet.
target->send_thread_stop(throwable());
}
}

void VM_ClearICs::doit() {
if (_preserve_static_stubs) {
CodeCache::cleanup_inline_caches();
@@ -210,30 +210,6 @@ class VM_Cleanup: public VM_Operation {
void doit() {};
};

class VM_ThreadStop: public VM_Operation {
private:
oop _thread; // The Thread that the Throwable is thrown against
oop _throwable; // The Throwable thrown at the target Thread
public:
// All oops are passed as JNI handles, since there is no guarantee that a GC might happen before the
// VM operation is executed.
VM_ThreadStop(oop thread, oop throwable) {
_thread = thread;
_throwable = throwable;
}
VMOp_Type type() const { return VMOp_ThreadStop; }
oop target_thread() const { return _thread; }
oop throwable() const { return _throwable;}
void doit();
// We deoptimize if top-most frame is compiled - this might require a C2I adapter to be generated
bool allow_nested_vm_operations() const { return true; }

// GC support
void oops_do(OopClosure* f) {
f->do_oop(&_thread); f->do_oop(&_throwable);
}
};

class VM_ClearICs: public VM_Operation {
private:
bool _preserve_static_stubs;

0 comments on commit a170a4a

Please sign in to comment.
You can’t perform that action at this time.