# HG changeset patch # User rehn # Date 1574762548 -3600 # Tue Nov 26 11:02:28 2019 +0100 # Node ID f7e0cf4773e7912476c40b44179c101e451c88f9 # Parent 6ba3d8d4113522fb2951066f5d512ceab3c6f2c4 imported patch 8234796 diff --git a/src/hotspot/share/gc/z/zHeap.cpp b/src/hotspot/share/gc/z/zHeap.cpp --- a/src/hotspot/share/gc/z/zHeap.cpp +++ b/src/hotspot/share/gc/z/zHeap.cpp @@ -326,9 +326,10 @@ _reference_processor.set_soft_reference_policy(clear); } -class ZRendezvousClosure : public ThreadClosure { +class ZRendezvousClosure : public HandshakeOperation { public: - virtual void do_thread(Thread* thread) {} + ZRendezvousClosure() : HandshakeOperation("ZRendezvous") {} + void do_thread(JavaThread* thread) {} }; void ZHeap::process_non_strong_references() { @@ -349,8 +350,8 @@ // this point the mutator could see the unblocked state and pass // this invalid oop through the normal barrier path, which would // incorrectly try to mark the oop. - ZRendezvousClosure cl; - Handshake::execute(&cl); + ZRendezvousClosure zr_hs; + Handshake::execute(&zr_hs); // Purge stale metadata and nmethods that were unlinked _unload.purge(); diff --git a/src/hotspot/share/gc/z/zMark.cpp b/src/hotspot/share/gc/z/zMark.cpp --- a/src/hotspot/share/gc/z/zMark.cpp +++ b/src/hotspot/share/gc/z/zMark.cpp @@ -435,12 +435,23 @@ } }; +class ZMarkFlushAndFreeStacksHandshake : public HandshakeOperation { + ZMarkFlushAndFreeStacksClosure* _cl; +public: + ZMarkFlushAndFreeStacksHandshake(ZMarkFlushAndFreeStacksClosure* cl) + : HandshakeOperation("ZMarkFlushAndFreeStacks"), _cl(cl) {} + void do_thread(JavaThread* jt) { + _cl->do_thread(jt); + } +}; + bool ZMark::flush(bool at_safepoint) { ZMarkFlushAndFreeStacksClosure cl(this); if (at_safepoint) { Threads::threads_do(&cl); } else { - Handshake::execute(&cl); + ZMarkFlushAndFreeStacksHandshake zmf_hs(&cl); + Handshake::execute(&zmf_hs); } // Returns true if more work is available diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -1995,12 +1995,11 @@ #endif // INCLUDE_CDS WB_ENTRY(jint, WB_HandshakeWalkStack(JNIEnv* env, jobject wb, jobject thread_handle, jboolean all_threads)) - class TraceSelfClosure : public ThreadClosure { + class TraceSelfHandshake : public HandshakeOperation { jint _num_threads_completed; - void do_thread(Thread* th) { - assert(th->is_Java_thread(), "sanity"); - JavaThread* jt = (JavaThread*)th; + public: + void do_thread(JavaThread* jt) { ResourceMark rm; jt->print_on(tty); @@ -2009,23 +2008,22 @@ Atomic::inc(&_num_threads_completed); } - public: - TraceSelfClosure() : _num_threads_completed(0) {} + TraceSelfHandshake() : HandshakeOperation("WB_TraceSelf"), _num_threads_completed(0) {} jint num_threads_completed() const { return _num_threads_completed; } }; - TraceSelfClosure tsc; + TraceSelfHandshake ts_hs; if (all_threads) { - Handshake::execute(&tsc); + Handshake::execute(&ts_hs); } else { oop thread_oop = JNIHandles::resolve(thread_handle); if (thread_oop != NULL) { JavaThread* target = java_lang_Thread::thread(thread_oop); - Handshake::execute(&tsc, target); + Handshake::execute(&ts_hs, target); } } - return tsc.num_threads_completed(); + return ts_hs.num_threads_completed(); WB_END //Some convenience methods to deal with objects from java diff --git a/src/hotspot/share/runtime/biasedLocking.cpp b/src/hotspot/share/runtime/biasedLocking.cpp --- a/src/hotspot/share/runtime/biasedLocking.cpp +++ b/src/hotspot/share/runtime/biasedLocking.cpp @@ -504,7 +504,7 @@ }; -class RevokeOneBias : public ThreadClosure { +class RevokeOneBias : public HandshakeOperation { protected: Handle _obj; JavaThread* _requesting_thread; @@ -514,13 +514,14 @@ public: RevokeOneBias(Handle obj, JavaThread* requesting_thread, JavaThread* biased_locker) - : _obj(obj) + : HandshakeOperation("RevokeOneBias") + , _obj(obj) , _requesting_thread(requesting_thread) , _biased_locker(biased_locker) , _status_code(BiasedLocking::NOT_BIASED) , _biased_locker_id(0) {} - void do_thread(Thread* target) { + void do_thread(JavaThread* target) { assert(target == _biased_locker, "Wrong thread"); oop o = _obj(); diff --git a/src/hotspot/share/runtime/deoptimization.cpp b/src/hotspot/share/runtime/deoptimization.cpp --- a/src/hotspot/share/runtime/deoptimization.cpp +++ b/src/hotspot/share/runtime/deoptimization.cpp @@ -807,6 +807,15 @@ } }; +class DeoptimizeMarkedHS : public HandshakeOperation { + public: + DeoptimizeMarkedHS() : HandshakeOperation("Deoptimize") {} + void do_thread(JavaThread* jt) { + jt->deoptimize_marked_methods(); + } +}; + + void Deoptimization::deoptimize_all_marked() { ResourceMark rm; DeoptimizationMarker dm; @@ -822,7 +831,7 @@ MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); CodeCache::make_marked_nmethods_not_entrant(); } - DeoptimizeMarkedTC deopt; + DeoptimizeMarkedHS deopt; Handshake::execute(&deopt); } } diff --git a/src/hotspot/share/runtime/handshake.cpp b/src/hotspot/share/runtime/handshake.cpp --- a/src/hotspot/share/runtime/handshake.cpp +++ b/src/hotspot/share/runtime/handshake.cpp @@ -38,29 +38,7 @@ #include "utilities/formatBuffer.hpp" #include "utilities/preserveException.hpp" -class HandshakeOperation: public StackObj { -public: - virtual void do_handshake(JavaThread* thread) = 0; -}; - -class HandshakeThreadsOperation: public HandshakeOperation { - static Semaphore _done; - ThreadClosure* _thread_cl; - bool _executed; -public: - HandshakeThreadsOperation(ThreadClosure* cl) : _thread_cl(cl), _executed(false) {} - void do_handshake(JavaThread* thread); - bool thread_has_completed() { return _done.trywait(); } - bool executed() const { return _executed; } - -#ifdef ASSERT - void check_state() { - assert(!_done.trywait(), "Must be zero"); - } -#endif -}; - -Semaphore HandshakeThreadsOperation::_done(0); +Semaphore HandshakeOperation::_done(0); class VM_Handshake: public VM_Operation { const jlong _handshake_timeout; @@ -70,9 +48,9 @@ bool evaluate_concurrently() const { return false; } protected: - HandshakeThreadsOperation* const _op; + HandshakeOperation* const _op; - VM_Handshake(HandshakeThreadsOperation* op) : + VM_Handshake(HandshakeOperation* op) : _handshake_timeout(TimeHelper::millis_to_counter(HandshakeTimeout)), _op(op) {} void set_handshake(JavaThread* target) { @@ -111,7 +89,7 @@ class VM_HandshakeOneThread: public VM_Handshake { JavaThread* _target; public: - VM_HandshakeOneThread(HandshakeThreadsOperation* op, JavaThread* target) : + VM_HandshakeOneThread(HandshakeOperation* op, JavaThread* target) : VM_Handshake(op), _target(target) {} void doit() { @@ -151,7 +129,7 @@ class VM_HandshakeAllThreads: public VM_Handshake { public: - VM_HandshakeAllThreads(HandshakeThreadsOperation* op) : VM_Handshake(op) {} + VM_HandshakeAllThreads(HandshakeOperation* op) : VM_Handshake(op) {} void doit() { DEBUG_ONLY(_op->check_state();) @@ -208,15 +186,15 @@ }; class VM_HandshakeFallbackOperation : public VM_Operation { - ThreadClosure* _thread_cl; + HandshakeOperation* _hs_op; Thread* _target_thread; bool _all_threads; bool _executed; public: - VM_HandshakeFallbackOperation(ThreadClosure* cl) : - _thread_cl(cl), _target_thread(NULL), _all_threads(true), _executed(false) {} - VM_HandshakeFallbackOperation(ThreadClosure* cl, Thread* target) : - _thread_cl(cl), _target_thread(target), _all_threads(false), _executed(false) {} + VM_HandshakeFallbackOperation(HandshakeOperation* hs_op) : + _hs_op(hs_op), _target_thread(NULL), _all_threads(true), _executed(false) {} + VM_HandshakeFallbackOperation(HandshakeOperation* hs_op, Thread* target) : + _hs_op(hs_op), _target_thread(target), _all_threads(false), _executed(false) {} void doit() { log_trace(handshake)("VMThread executing VM_HandshakeFallbackOperation"); @@ -225,7 +203,7 @@ if (t == _target_thread) { _executed = true; } - _thread_cl->do_thread(t); + _hs_op->do_thread(t); } } } @@ -234,7 +212,7 @@ bool executed() const { return _executed; } }; -void HandshakeThreadsOperation::do_handshake(JavaThread* thread) { +void HandshakeOperation::do_handshake(JavaThread* thread) { ResourceMark rm; FormatBufferResource message("Operation for thread " PTR_FORMAT ", is_vm_thread: %s", p2i(thread), BOOL_TO_STR(Thread::current()->is_VM_thread())); @@ -242,7 +220,7 @@ // Only actually execute the operation for non terminated threads. if (!thread->is_terminated()) { - _thread_cl->do_thread(thread); + do_thread(thread); _executed = true; } @@ -250,25 +228,23 @@ _done.signal(); } -void Handshake::execute(ThreadClosure* thread_cl) { +void Handshake::execute(HandshakeOperation* hs_op) { if (ThreadLocalHandshakes) { - HandshakeThreadsOperation cto(thread_cl); - VM_HandshakeAllThreads handshake(&cto); + VM_HandshakeAllThreads handshake(hs_op); VMThread::execute(&handshake); } else { - VM_HandshakeFallbackOperation op(thread_cl); + VM_HandshakeFallbackOperation op(hs_op); VMThread::execute(&op); } } -bool Handshake::execute(ThreadClosure* thread_cl, JavaThread* target) { +bool Handshake::execute(HandshakeOperation* hs_op, JavaThread* target) { if (ThreadLocalHandshakes) { - HandshakeThreadsOperation cto(thread_cl); - VM_HandshakeOneThread handshake(&cto, target); + VM_HandshakeOneThread handshake(hs_op, target); VMThread::execute(&handshake); return handshake.executed(); } else { - VM_HandshakeFallbackOperation op(thread_cl, target); + VM_HandshakeFallbackOperation op(hs_op, target); VMThread::execute(&op); return op.executed(); } diff --git a/src/hotspot/share/runtime/handshake.hpp b/src/hotspot/share/runtime/handshake.hpp --- a/src/hotspot/share/runtime/handshake.hpp +++ b/src/hotspot/share/runtime/handshake.hpp @@ -29,7 +29,6 @@ #include "runtime/flags/flagSetting.hpp" #include "runtime/semaphore.hpp" -class ThreadClosure; class JavaThread; // A handshake operation is a callback that is executed for each JavaThread @@ -37,15 +36,35 @@ // either by the thread itself or by the VM thread while keeping the thread // in a blocked state. A handshake can be performed with a single // JavaThread as well. +class HandshakeOperation: public StackObj { + static Semaphore _done; + const char* _name; + bool _executed; +public: + HandshakeOperation(const char* name) : _name(name), _executed(false) {} + + void do_handshake(JavaThread* thread); + bool thread_has_completed() { return _done.trywait(); } + bool executed() const { return _executed; } + const char* name() { return _name; }; + +#ifdef ASSERT + void check_state() { + assert(!_done.trywait(), "Must be zero"); + } +#endif + + // Impl + virtual void do_thread(JavaThread* thread) = 0; +}; + class Handshake : public AllStatic { public: // Execution of handshake operation - static void execute(ThreadClosure* thread_cl); - static bool execute(ThreadClosure* thread_cl, JavaThread* target); + static void execute(HandshakeOperation* hs_op); + static bool execute(HandshakeOperation* hs_op, JavaThread* target); }; -class HandshakeOperation; - // The HandshakeState keep tracks of an ongoing handshake for one JavaThread. // VM thread and JavaThread are serialized with the semaphore making sure // the operation is only done by either VM thread on behalf of the JavaThread diff --git a/src/hotspot/share/runtime/sweeper.cpp b/src/hotspot/share/runtime/sweeper.cpp --- a/src/hotspot/share/runtime/sweeper.cpp +++ b/src/hotspot/share/runtime/sweeper.cpp @@ -311,6 +311,15 @@ return &set_hotness_closure; } +class NMethodMarkingHandshake : public HandshakeOperation { + NMethodMarkingThreadClosure* _cl; + public: + NMethodMarkingHandshake(NMethodMarkingThreadClosure* cl) : HandshakeOperation("NMethodMarking"), _cl(cl) {} + void do_thread(JavaThread* jt) { + _cl->do_thread(jt); + } +}; + /** * This function triggers a VM operation that does stack scanning of active * methods. Stack scanning is mandatory for the sweeper to make progress. @@ -326,7 +335,8 @@ } if (code_cl != NULL) { NMethodMarkingThreadClosure tcl(code_cl); - Handshake::execute(&tcl); + NMethodMarkingHandshake nm_hs(&tcl); + Handshake::execute(&nm_hs); } } else { VM_MarkActiveNMethods op; diff --git a/src/hotspot/share/runtime/vmThread.cpp b/src/hotspot/share/runtime/vmThread.cpp --- a/src/hotspot/share/runtime/vmThread.cpp +++ b/src/hotspot/share/runtime/vmThread.cpp @@ -429,12 +429,11 @@ static VM_None safepointALot_op("SafepointALot"); static VM_Cleanup cleanup_op; -class HandshakeALotTC : public ThreadClosure { +class HandshakeALotHS : public HandshakeOperation { public: - virtual void do_thread(Thread* thread) { + HandshakeALotHS() : HandshakeOperation("HandshakeALot") {} + void do_thread(JavaThread* jt) { #ifdef ASSERT - assert(thread->is_Java_thread(), "must be"); - JavaThread* jt = (JavaThread*)thread; jt->verify_states_for_handshake(); #endif } @@ -443,8 +442,8 @@ VM_Operation* VMThread::no_op_safepoint() { // Check for handshakes first since we may need to return a VMop. if (HandshakeALot) { - HandshakeALotTC haltc; - Handshake::execute(&haltc); + HandshakeALotHS halhs; + Handshake::execute(&halhs); } // Check for a cleanup before SafepointALot to keep stats correct. long interval_ms = SafepointTracing::time_since_last_safepoint_ms();