< prev index next >
src/hotspot/share/runtime/handshake.cpp
Print this page
rev 57079 : imported patch 8234796
*** 36,80 ****
#include "runtime/thread.hpp"
#include "runtime/vmThread.hpp"
#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);
class VM_Handshake: public VM_Operation {
const jlong _handshake_timeout;
public:
bool evaluate_at_safepoint() const { return false; }
bool evaluate_concurrently() const { return false; }
protected:
! HandshakeThreadsOperation* const _op;
! VM_Handshake(HandshakeThreadsOperation* op) :
_handshake_timeout(TimeHelper::millis_to_counter(HandshakeTimeout)), _op(op) {}
void set_handshake(JavaThread* target) {
target->set_handshake_operation(_op);
}
--- 36,58 ----
#include "runtime/thread.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/formatBuffer.hpp"
#include "utilities/preserveException.hpp"
! Semaphore HandshakeOperation::_done(0);
class VM_Handshake: public VM_Operation {
const jlong _handshake_timeout;
public:
bool evaluate_at_safepoint() const { return false; }
bool evaluate_concurrently() const { return false; }
protected:
! HandshakeOperation* const _op;
! VM_Handshake(HandshakeOperation* op) :
_handshake_timeout(TimeHelper::millis_to_counter(HandshakeTimeout)), _op(op) {}
void set_handshake(JavaThread* target) {
target->set_handshake_operation(_op);
}
*** 109,119 ****
}
class VM_HandshakeOneThread: public VM_Handshake {
JavaThread* _target;
public:
! VM_HandshakeOneThread(HandshakeThreadsOperation* op, JavaThread* target) :
VM_Handshake(op), _target(target) {}
void doit() {
DEBUG_ONLY(_op->check_state();)
TraceTime timer("Finished executing single-target operation (VM_HandshakeOneThread::doit)", TRACETIME_LOG(Info, handshake));
--- 87,97 ----
}
class VM_HandshakeOneThread: public VM_Handshake {
JavaThread* _target;
public:
! VM_HandshakeOneThread(HandshakeOperation* op, JavaThread* target) :
VM_Handshake(op), _target(target) {}
void doit() {
DEBUG_ONLY(_op->check_state();)
TraceTime timer("Finished executing single-target operation (VM_HandshakeOneThread::doit)", TRACETIME_LOG(Info, handshake));
*** 149,159 ****
bool executed() const { return _op->executed(); }
};
class VM_HandshakeAllThreads: public VM_Handshake {
public:
! VM_HandshakeAllThreads(HandshakeThreadsOperation* op) : VM_Handshake(op) {}
void doit() {
DEBUG_ONLY(_op->check_state();)
TraceTime timer("Finished executing multi-target operation (VM_HandshakeAllThreads::doit)", TRACETIME_LOG(Info, handshake));
--- 127,137 ----
bool executed() const { return _op->executed(); }
};
class VM_HandshakeAllThreads: public VM_Handshake {
public:
! VM_HandshakeAllThreads(HandshakeOperation* op) : VM_Handshake(op) {}
void doit() {
DEBUG_ONLY(_op->check_state();)
TraceTime timer("Finished executing multi-target operation (VM_HandshakeAllThreads::doit)", TRACETIME_LOG(Info, handshake));
*** 206,276 ****
VMOp_Type type() const { return VMOp_HandshakeAllThreads; }
};
class VM_HandshakeFallbackOperation : public VM_Operation {
! ThreadClosure* _thread_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) {}
void doit() {
log_trace(handshake)("VMThread executing VM_HandshakeFallbackOperation");
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
if (_all_threads || t == _target_thread) {
if (t == _target_thread) {
_executed = true;
}
! _thread_cl->do_thread(t);
}
}
}
VMOp_Type type() const { return VMOp_HandshakeFallback; }
bool executed() const { return _executed; }
};
! void HandshakeThreadsOperation::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()));
TraceTime timer(message, TRACETIME_LOG(Debug, handshake, task));
// Only actually execute the operation for non terminated threads.
if (!thread->is_terminated()) {
! _thread_cl->do_thread(thread);
_executed = true;
}
// Use the semaphore to inform the VM thread that we have completed the operation
_done.signal();
}
! void Handshake::execute(ThreadClosure* thread_cl) {
if (ThreadLocalHandshakes) {
! HandshakeThreadsOperation cto(thread_cl);
! VM_HandshakeAllThreads handshake(&cto);
VMThread::execute(&handshake);
} else {
! VM_HandshakeFallbackOperation op(thread_cl);
VMThread::execute(&op);
}
}
! bool Handshake::execute(ThreadClosure* thread_cl, JavaThread* target) {
if (ThreadLocalHandshakes) {
! HandshakeThreadsOperation cto(thread_cl);
! VM_HandshakeOneThread handshake(&cto, target);
VMThread::execute(&handshake);
return handshake.executed();
} else {
! VM_HandshakeFallbackOperation op(thread_cl, target);
VMThread::execute(&op);
return op.executed();
}
}
--- 184,252 ----
VMOp_Type type() const { return VMOp_HandshakeAllThreads; }
};
class VM_HandshakeFallbackOperation : public VM_Operation {
! HandshakeOperation* _hs_op;
Thread* _target_thread;
bool _all_threads;
bool _executed;
public:
! 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");
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
if (_all_threads || t == _target_thread) {
if (t == _target_thread) {
_executed = true;
}
! _hs_op->do_thread(t);
}
}
}
VMOp_Type type() const { return VMOp_HandshakeFallback; }
bool executed() const { return _executed; }
};
! 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()));
TraceTime timer(message, TRACETIME_LOG(Debug, handshake, task));
// Only actually execute the operation for non terminated threads.
if (!thread->is_terminated()) {
! do_thread(thread);
_executed = true;
}
// Use the semaphore to inform the VM thread that we have completed the operation
_done.signal();
}
! void Handshake::execute(HandshakeOperation* hs_op) {
if (ThreadLocalHandshakes) {
! VM_HandshakeAllThreads handshake(hs_op);
VMThread::execute(&handshake);
} else {
! VM_HandshakeFallbackOperation op(hs_op);
VMThread::execute(&op);
}
}
! bool Handshake::execute(HandshakeOperation* hs_op, JavaThread* target) {
if (ThreadLocalHandshakes) {
! VM_HandshakeOneThread handshake(hs_op, target);
VMThread::execute(&handshake);
return handshake.executed();
} else {
! VM_HandshakeFallbackOperation op(hs_op, target);
VMThread::execute(&op);
return op.executed();
}
}
< prev index next >