8234796: Refactor Handshake::execute to take a more complex type than ThreadClosure

Reviewed-by: dholmes, pliden, coleenp
This commit is contained in:
Robbin Ehn 2019-12-03 15:32:41 +01:00
parent 095d77acf0
commit 21e03e71aa
36 changed files with 95 additions and 50 deletions

View File

@ -55,6 +55,7 @@
#include "include/jvm.h"
#include "logging/log.hpp"
#include "memory/allocation.hpp"
#include "memory/iterator.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "oops/access.inline.hpp"

View File

@ -45,6 +45,7 @@ class G1ConcurrentMark;
class G1OldTracer;
class G1RegionToSpaceMapper;
class G1SurvivorRegions;
class ThreadClosure;
PRAGMA_DIAG_PUSH
// warning C4522: multiple assignment operators specified

View File

@ -29,6 +29,7 @@
#include "gc/g1/g1DirtyCardQueue.hpp"
#include "logging/log.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/iterator.hpp"
#include "runtime/java.hpp"
#include "runtime/thread.hpp"
#include "utilities/debug.hpp"

View File

@ -34,6 +34,7 @@
#include "gc/g1/heapRegionRemSet.hpp"
#include "gc/shared/suspendibleThreadSet.hpp"
#include "gc/shared/workgroup.hpp"
#include "memory/iterator.hpp"
#include "runtime/flags/flagSetting.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/orderAccess.hpp"

View File

@ -34,6 +34,7 @@
#include "gc/g1/heapRegion.hpp"
#include "gc/g1/heapRegionRemSet.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/iterator.hpp"
#include "runtime/thread.inline.hpp"
void G1RemSetSummary::update() {

View File

@ -44,6 +44,7 @@
#include "gc/shared/locationPrinter.inline.hpp"
#include "gc/shared/scavengableNMethods.hpp"
#include "logging/log.hpp"
#include "memory/iterator.hpp"
#include "memory/metaspaceCounters.hpp"
#include "memory/universe.hpp"
#include "oops/oop.inline.hpp"

View File

@ -52,6 +52,7 @@
#include "gc/shared/weakProcessor.hpp"
#include "gc/shared/workerPolicy.hpp"
#include "gc/shared/workgroup.hpp"
#include "memory/iterator.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "logging/log.hpp"

View File

@ -55,6 +55,7 @@
#include "gc/shared/weakProcessor.hpp"
#include "gc/shared/workgroup.hpp"
#include "memory/filemap.hpp"
#include "memory/iterator.hpp"
#include "memory/metaspaceCounters.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"

View File

@ -27,6 +27,7 @@
#include "gc/shared/stringdedup/stringDedupQueue.hpp"
#include "gc/shared/stringdedup/stringDedupTable.hpp"
#include "gc/shared/stringdedup/stringDedupThread.hpp"
#include "memory/iterator.hpp"
bool StringDedup::_enabled = false;

View File

@ -69,6 +69,8 @@
#include "memory/allocation.hpp"
#include "runtime/thread.hpp"
class ThreadClosure;
//
// Main interface for interacting with string deduplication.
//

View File

@ -28,6 +28,7 @@
#include "gc/shared/workerManager.hpp"
#include "memory/allocation.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/iterator.hpp"
#include "runtime/atomic.hpp"
#include "runtime/os.hpp"
#include "runtime/semaphore.hpp"

View File

@ -50,6 +50,7 @@
class AbstractGangWorker;
class Semaphore;
class ThreadClosure;
class WorkGang;
// An abstract task to be worked on by a gang.

View File

@ -158,8 +158,9 @@ void ShenandoahUnload::purge() {
CodeCache::purge_exception_caches();
}
class ShenandoahUnloadRendezvousClosure : public ThreadClosure {
class ShenandoahUnloadRendezvousClosure : public HandshakeClosure {
public:
ShenandoahUnloadRendezvousClosure() : HandshakeClosure("ShenandoahUnloadRendezvous") {}
void do_thread(Thread* thread) {}
};

View File

@ -33,6 +33,7 @@
#include "gc/z/zServiceability.hpp"
#include "gc/z/zStat.hpp"
#include "gc/z/zUtils.inline.hpp"
#include "memory/iterator.hpp"
#include "memory/universe.hpp"
#include "runtime/mutexLocker.hpp"
#include "utilities/align.hpp"

View File

@ -326,9 +326,12 @@ void ZHeap::set_soft_reference_policy(bool clear) {
_reference_processor.set_soft_reference_policy(clear);
}
class ZRendezvousClosure : public ThreadClosure {
class ZRendezvousClosure : public HandshakeClosure {
public:
virtual void do_thread(Thread* thread) {}
ZRendezvousClosure() :
HandshakeClosure("ZRendezvous") {}
void do_thread(Thread* thread) {}
};
void ZHeap::process_non_strong_references() {

View File

@ -39,6 +39,8 @@
#include "gc/z/zUnload.hpp"
#include "gc/z/zWorkers.hpp"
class ThreadClosure;
class ZHeap {
friend class VMStructs;

View File

@ -413,13 +413,14 @@ void ZMark::idle() const {
os::naked_short_sleep(1);
}
class ZMarkFlushAndFreeStacksClosure : public ThreadClosure {
class ZMarkFlushAndFreeStacksClosure : public HandshakeClosure {
private:
ZMark* const _mark;
bool _flushed;
public:
ZMarkFlushAndFreeStacksClosure(ZMark* mark) :
HandshakeClosure("ZMarkFlushAndFreeStacks"),
_mark(mark),
_flushed(false) {}

View File

@ -39,6 +39,7 @@
#include "gc/z/zRootsIterator.hpp"
#include "gc/z/zStat.hpp"
#include "gc/z/zThreadLocalData.hpp"
#include "memory/iterator.hpp"
#include "memory/resourceArea.hpp"
#include "memory/universe.hpp"
#include "prims/jvmtiExport.hpp"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,8 @@
#include "gc/shared/workgroup.hpp"
class ThreadClosure;
class ZRuntimeWorkers {
private:
WorkGang _workers;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,6 +27,7 @@
#include "gc/shared/workgroup.hpp"
#include "memory/allocation.hpp"
class ThreadClosure;
class ZTask;
class ZWorkers {

View File

@ -42,6 +42,7 @@
#include "jfr/utilities/jfrTypes.hpp"
#include "jfr/writers/jfrJavaEventWriter.hpp"
#include "logging/log.hpp"
#include "memory/iterator.hpp"
#include "memory/resourceArea.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/mutex.hpp"

View File

@ -40,6 +40,7 @@
#include "jfr/support/jfrThreadLocal.hpp"
#include "jfr/writers/jfrJavaEventWriter.hpp"
#include "jfr/utilities/jfrThreadIterator.hpp"
#include "memory/iterator.hpp"
#include "memory/metaspaceGCThresholdUpdater.hpp"
#include "memory/referenceType.hpp"
#include "memory/universe.hpp"

View File

@ -32,6 +32,7 @@
#include "jfr/support/jfrThreadId.hpp"
#include "jfr/utilities/jfrTypes.hpp"
#include "jfr/writers/jfrJavaEventWriter.hpp"
#include "memory/iterator.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/fieldDescriptor.inline.hpp"

View File

@ -37,11 +37,18 @@ class KlassClosure;
class ClassLoaderData;
class Symbol;
class Metadata;
class Thread;
// The following classes are C++ `closures` for iterating over objects, roots and spaces
class Closure : public StackObj { };
// Thread iterator
class ThreadClosure: public Closure {
public:
virtual void do_thread(Thread* thread) = 0;
};
// OopClosure is used for iterating through references to Java objects.
class OopClosure : public Closure {
public:

View File

@ -27,6 +27,7 @@
#include "classfile/moduleEntry.hpp"
#include "classfile/systemDictionary.hpp"
#include "jvmtifiles/jvmtiEnv.hpp"
#include "memory/iterator.hpp"
#include "memory/resourceArea.hpp"
#include "oops/objArrayKlass.hpp"
#include "oops/objArrayOop.hpp"

View File

@ -2011,7 +2011,7 @@ WB_END
#endif // INCLUDE_CDS
WB_ENTRY(jint, WB_HandshakeWalkStack(JNIEnv* env, jobject wb, jobject thread_handle, jboolean all_threads))
class TraceSelfClosure : public ThreadClosure {
class TraceSelfClosure : public HandshakeClosure {
jint _num_threads_completed;
void do_thread(Thread* th) {
@ -2026,7 +2026,7 @@ WB_ENTRY(jint, WB_HandshakeWalkStack(JNIEnv* env, jobject wb, jobject thread_han
}
public:
TraceSelfClosure() : _num_threads_completed(0) {}
TraceSelfClosure() : HandshakeClosure("WB_TraceSelf"), _num_threads_completed(0) {}
jint num_threads_completed() const { return _num_threads_completed; }
};

View File

@ -35,6 +35,7 @@
#include "runtime/basicLock.hpp"
#include "runtime/biasedLocking.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/handshake.hpp"
#include "runtime/task.hpp"
#include "runtime/threadSMR.hpp"
#include "runtime/vframe.hpp"
@ -500,7 +501,7 @@ public:
};
class RevokeOneBias : public ThreadClosure {
class RevokeOneBias : public HandshakeClosure {
protected:
Handle _obj;
JavaThread* _requesting_thread;
@ -510,7 +511,8 @@ protected:
public:
RevokeOneBias(Handle obj, JavaThread* requesting_thread, JavaThread* biased_locker)
: _obj(obj)
: HandshakeClosure("RevokeOneBias")
, _obj(obj)
, _requesting_thread(requesting_thread)
, _biased_locker(biased_locker)
, _status_code(BiasedLocking::NOT_BIASED)

View File

@ -805,10 +805,10 @@ JRT_LEAF(BasicType, Deoptimization::unpack_frames(JavaThread* thread, int exec_m
return bt;
JRT_END
class DeoptimizeMarkedTC : public ThreadClosure {
class DeoptimizeMarkedClosure : public HandshakeClosure {
public:
virtual void do_thread(Thread* thread) {
assert(thread->is_Java_thread(), "must be");
DeoptimizeMarkedClosure() : HandshakeClosure("Deoptimize") {}
void do_thread(Thread* thread) {
JavaThread* jt = (JavaThread*)thread;
jt->deoptimize_marked_methods();
}
@ -819,7 +819,7 @@ void Deoptimization::deoptimize_all_marked() {
DeoptimizationMarker dm;
if (SafepointSynchronize::is_at_safepoint()) {
DeoptimizeMarkedTC deopt;
DeoptimizeMarkedClosure deopt;
// Make the dependent methods not entrant
CodeCache::make_marked_nmethods_not_entrant();
Threads::java_threads_do(&deopt);
@ -829,7 +829,7 @@ void Deoptimization::deoptimize_all_marked() {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
CodeCache::make_marked_nmethods_not_entrant();
}
DeoptimizeMarkedTC deopt;
DeoptimizeMarkedClosure deopt;
Handshake::execute(&deopt);
}
}

View File

@ -45,10 +45,10 @@ public:
class HandshakeThreadsOperation: public HandshakeOperation {
static Semaphore _done;
ThreadClosure* _thread_cl;
HandshakeClosure* _handshake_cl;
bool _executed;
public:
HandshakeThreadsOperation(ThreadClosure* cl) : _thread_cl(cl), _executed(false) {}
HandshakeThreadsOperation(HandshakeClosure* cl) : _handshake_cl(cl), _executed(false) {}
void do_handshake(JavaThread* thread);
bool thread_has_completed() { return _done.trywait(); }
bool executed() const { return _executed; }
@ -206,15 +206,15 @@ class VM_HandshakeAllThreads: public VM_Handshake {
};
class VM_HandshakeFallbackOperation : public VM_Operation {
ThreadClosure* _thread_cl;
HandshakeClosure* _handshake_cl;
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(HandshakeClosure* cl) :
_handshake_cl(cl), _target_thread(NULL), _all_threads(true), _executed(false) {}
VM_HandshakeFallbackOperation(HandshakeClosure* cl, Thread* target) :
_handshake_cl(cl), _target_thread(target), _all_threads(false), _executed(false) {}
void doit() {
log_trace(handshake)("VMThread executing VM_HandshakeFallbackOperation");
@ -223,7 +223,7 @@ public:
if (t == _target_thread) {
_executed = true;
}
_thread_cl->do_thread(t);
_handshake_cl->do_thread(t);
}
}
}
@ -240,7 +240,7 @@ void HandshakeThreadsOperation::do_handshake(JavaThread* thread) {
// Only actually execute the operation for non terminated threads.
if (!thread->is_terminated()) {
_thread_cl->do_thread(thread);
_handshake_cl->do_thread(thread);
_executed = true;
}
@ -248,7 +248,7 @@ void HandshakeThreadsOperation::do_handshake(JavaThread* thread) {
_done.signal();
}
void Handshake::execute(ThreadClosure* thread_cl) {
void Handshake::execute(HandshakeClosure* thread_cl) {
if (ThreadLocalHandshakes) {
HandshakeThreadsOperation cto(thread_cl);
VM_HandshakeAllThreads handshake(&cto);
@ -259,7 +259,7 @@ void Handshake::execute(ThreadClosure* thread_cl) {
}
}
bool Handshake::execute(ThreadClosure* thread_cl, JavaThread* target) {
bool Handshake::execute(HandshakeClosure* thread_cl, JavaThread* target) {
if (ThreadLocalHandshakes) {
HandshakeThreadsOperation cto(thread_cl);
VM_HandshakeOneThread handshake(&cto, target);

View File

@ -26,22 +26,32 @@
#define SHARE_RUNTIME_HANDSHAKE_HPP
#include "memory/allocation.hpp"
#include "memory/iterator.hpp"
#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
// A handshake closure is a callback that is executed for each JavaThread
// while that thread is in a safepoint safe state. The callback is executed
// 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 HandshakeClosure : public ThreadClosure {
const char* const _name;
public:
HandshakeClosure(const char* name) : _name(name) {}
const char* name() const {
return _name;
}
virtual void do_thread(Thread* 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(HandshakeClosure* hs_cl);
static bool execute(HandshakeClosure* hs_cl, JavaThread* target);
};
class HandshakeOperation;

View File

@ -197,11 +197,11 @@ bool NMethodSweeper::wait_for_stack_scanning() {
return _current.end();
}
class NMethodMarkingThreadClosure : public ThreadClosure {
class NMethodMarkingClosure : public HandshakeClosure {
private:
CodeBlobClosure* _cl;
public:
NMethodMarkingThreadClosure(CodeBlobClosure* cl) : _cl(cl) {}
NMethodMarkingClosure(CodeBlobClosure* cl) : HandshakeClosure("NMethodMarking"), _cl(cl) {}
void do_thread(Thread* thread) {
if (thread->is_Java_thread() && ! thread->is_Code_cache_sweeper_thread()) {
JavaThread* jt = (JavaThread*) thread;
@ -212,9 +212,9 @@ public:
class NMethodMarkingTask : public AbstractGangTask {
private:
NMethodMarkingThreadClosure* _cl;
NMethodMarkingClosure* _cl;
public:
NMethodMarkingTask(NMethodMarkingThreadClosure* cl) :
NMethodMarkingTask(NMethodMarkingClosure* cl) :
AbstractGangTask("Parallel NMethod Marking"),
_cl(cl) {
Threads::change_thread_claim_token();
@ -239,7 +239,7 @@ void NMethodSweeper::mark_active_nmethods() {
if (cl != NULL) {
WorkGang* workers = Universe::heap()->get_safepoint_workers();
if (workers != NULL) {
NMethodMarkingThreadClosure tcl(cl);
NMethodMarkingClosure tcl(cl);
NMethodMarkingTask task(&tcl);
workers->run_task(&task);
} else {
@ -324,8 +324,8 @@ void NMethodSweeper::do_stack_scanning() {
code_cl = prepare_mark_active_nmethods();
}
if (code_cl != NULL) {
NMethodMarkingThreadClosure tcl(code_cl);
Handshake::execute(&tcl);
NMethodMarkingClosure nm_cl(code_cl);
Handshake::execute(&nm_cl);
}
} else {
VM_MarkActiveNMethods op;

View File

@ -47,6 +47,7 @@
#include "logging/logConfiguration.hpp"
#include "logging/logStream.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/iterator.hpp"
#include "memory/metaspaceShared.hpp"
#include "memory/oopFactory.hpp"
#include "memory/resourceArea.hpp"

View File

@ -2286,13 +2286,6 @@ class Threads: AllStatic {
struct Test; // For private gtest access.
};
// Thread iterator
class ThreadClosure: public StackObj {
public:
virtual void do_thread(Thread* thread) = 0;
};
class SignalHandlerMark: public StackObj {
private:
Thread* _thread;

View File

@ -26,6 +26,7 @@
#define SHARE_RUNTIME_THREADSMR_INLINE_HPP
#include "runtime/atomic.hpp"
#include "memory/iterator.hpp"
#include "runtime/prefetch.inline.hpp"
#include "runtime/thread.inline.hpp"
#include "runtime/threadSMR.hpp"

View File

@ -413,9 +413,10 @@ void VMThread::evaluate_operation(VM_Operation* op) {
static VM_None safepointALot_op("SafepointALot");
static VM_Cleanup cleanup_op;
class HandshakeALotTC : public ThreadClosure {
class HandshakeALotClosure : public HandshakeClosure {
public:
virtual void do_thread(Thread* thread) {
HandshakeALotClosure() : HandshakeClosure("HandshakeALot") {}
void do_thread(Thread* thread) {
#ifdef ASSERT
assert(thread->is_Java_thread(), "must be");
JavaThread* jt = (JavaThread*)thread;
@ -432,8 +433,8 @@ void VMThread::check_for_forced_cleanup() {
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);
HandshakeALotClosure hal_cl;
Handshake::execute(&hal_cl);
}
// Check for a cleanup before SafepointALot to keep stats correct.
long interval_ms = SafepointTracing::time_since_last_safepoint_ms();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,11 +23,12 @@
*/
#include "precompiled.hpp"
#include "utilities/globalCounter.hpp"
#include "memory/iterator.hpp"
#include "runtime/atomic.hpp"
#include "runtime/thread.hpp"
#include "runtime/threadSMR.inline.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/globalCounter.hpp"
#include "utilities/spinYield.hpp"
GlobalCounter::PaddedCounter GlobalCounter::_global_counter;