Skip to content

Commit a170a4a

Browse files
committedDec 19, 2019
8235913: ThreadStop should be a handshake
Reviewed-by: dholmes, mdoerr
1 parent e4c96de commit a170a4a

File tree

4 files changed

+22
-44
lines changed

4 files changed

+22
-44
lines changed
 

‎src/hotspot/share/code/icBuffer.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include "runtime/handles.inline.hpp"
3838
#include "runtime/mutexLocker.hpp"
3939
#include "runtime/stubRoutines.hpp"
40-
#include "runtime/thread.hpp"
40+
#include "runtime/thread.inline.hpp"
4141

4242
DEF_STUB_INTERFACE(ICStub);
4343

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

172-
173172
void InlineCacheBuffer::update_inline_caches() {
174173
if (buffer()->number_of_stubs() > 0) {
175174
if (TraceICBuffer) {

‎src/hotspot/share/runtime/thread.cpp

+20-5
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,25 @@ void Thread::start(Thread* thread) {
526526
}
527527
}
528528

529+
class InstallAsyncExceptionClosure : public HandshakeClosure {
530+
Handle _throwable; // The Throwable thrown at the target Thread
531+
public:
532+
InstallAsyncExceptionClosure(Handle throwable) : HandshakeClosure("InstallAsyncException"), _throwable(throwable) {}
533+
534+
void do_thread(Thread* thr) {
535+
JavaThread* target = (JavaThread*)thr;
536+
// Note that this now allows multiple ThreadDeath exceptions to be
537+
// thrown at a thread.
538+
// The target thread has run and has not exited yet.
539+
target->send_thread_stop(_throwable());
540+
}
541+
};
542+
529543
void Thread::send_async_exception(oop java_thread, oop java_throwable) {
530-
VM_ThreadStop vm_stop(java_thread, java_throwable);
531-
VMThread::execute(&vm_stop);
544+
Handle throwable(Thread::current(), java_throwable);
545+
JavaThread* target = java_lang_Thread::thread(java_thread);
546+
InstallAsyncExceptionClosure vm_stop(throwable);
547+
Handshake::execute(&vm_stop, target);
532548
}
533549

534550

@@ -2383,9 +2399,8 @@ void JavaThread::handle_special_runtime_exit_condition(bool check_asyncs) {
23832399
}
23842400

23852401
void JavaThread::send_thread_stop(oop java_throwable) {
2386-
assert(Thread::current()->is_VM_thread(), "should be in the vm thread");
2387-
assert(Threads_lock->is_locked(), "Threads_lock should be locked by safepoint code");
2388-
assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
2402+
ResourceMark rm;
2403+
assert(Thread::current()->is_VM_thread() || Thread::current() == this, "should be in the vm thread");
23892404

23902405
// Do not throw asynchronous exceptions against the compiler thread
23912406
// (the compiler thread should not be a Java thread -- fix in 1.4.2)

‎src/hotspot/share/runtime/vmOperations.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,6 @@ void VM_Operation::print_on_error(outputStream* st) const {
8585
}
8686
}
8787

88-
void VM_ThreadStop::doit() {
89-
assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
90-
ThreadsListHandle tlh;
91-
JavaThread* target = java_lang_Thread::thread(target_thread());
92-
// Note that this now allows multiple ThreadDeath exceptions to be
93-
// thrown at a thread.
94-
if (target != NULL && (!EnableThreadSMRExtraValidityChecks || tlh.includes(target))) {
95-
// The target thread has run and has not exited yet.
96-
target->send_thread_stop(throwable());
97-
}
98-
}
99-
10088
void VM_ClearICs::doit() {
10189
if (_preserve_static_stubs) {
10290
CodeCache::cleanup_inline_caches();

‎src/hotspot/share/runtime/vmOperations.hpp

-24
Original file line numberDiff line numberDiff line change
@@ -210,30 +210,6 @@ class VM_Cleanup: public VM_Operation {
210210
void doit() {};
211211
};
212212

213-
class VM_ThreadStop: public VM_Operation {
214-
private:
215-
oop _thread; // The Thread that the Throwable is thrown against
216-
oop _throwable; // The Throwable thrown at the target Thread
217-
public:
218-
// All oops are passed as JNI handles, since there is no guarantee that a GC might happen before the
219-
// VM operation is executed.
220-
VM_ThreadStop(oop thread, oop throwable) {
221-
_thread = thread;
222-
_throwable = throwable;
223-
}
224-
VMOp_Type type() const { return VMOp_ThreadStop; }
225-
oop target_thread() const { return _thread; }
226-
oop throwable() const { return _throwable;}
227-
void doit();
228-
// We deoptimize if top-most frame is compiled - this might require a C2I adapter to be generated
229-
bool allow_nested_vm_operations() const { return true; }
230-
231-
// GC support
232-
void oops_do(OopClosure* f) {
233-
f->do_oop(&_thread); f->do_oop(&_throwable);
234-
}
235-
};
236-
237213
class VM_ClearICs: public VM_Operation {
238214
private:
239215
bool _preserve_static_stubs;

0 commit comments

Comments
 (0)
Please sign in to comment.