277 HandshakeState::HandshakeState() : _operation(NULL), _semaphore(1), _thread_in_process_handshake(false) {}
278
279 void HandshakeState::set_operation(JavaThread* target, HandshakeOperation* op) {
280 _operation = op;
281 SafepointMechanism::arm_local_poll_release(target);
282 }
283
284 void HandshakeState::clear_handshake(JavaThread* target) {
285 _operation = NULL;
286 SafepointMechanism::disarm_if_needed(target, true /* release */);
287 }
288
289 void HandshakeState::process_self_inner(JavaThread* thread) {
290 assert(Thread::current() == thread, "should call from thread");
291 assert(!thread->is_terminated(), "should not be a terminated thread");
292
293 ThreadInVMForHandshake tivm(thread);
294 if (!_semaphore.trywait()) {
295 _semaphore.wait_with_safepoint_check(thread);
296 }
297 HandshakeOperation* op = OrderAccess::load_acquire(&_operation);
298 if (op != NULL) {
299 HandleMark hm(thread);
300 CautiouslyPreserveExceptionMark pem(thread);
301 // Disarm before execute the operation
302 clear_handshake(thread);
303 op->do_handshake(thread);
304 }
305 _semaphore.signal();
306 }
307
308 bool HandshakeState::vmthread_can_process_handshake(JavaThread* target) {
309 // handshake_safe may only be called with polls armed.
310 // VM thread controls this by first claiming the handshake via claim_handshake_for_vmthread.
311 return SafepointSynchronize::handshake_safe(target);
312 }
313
314 static bool possibly_vmthread_can_process_handshake(JavaThread* target) {
315 // An externally suspended thread cannot be resumed while the
316 // Threads_lock is held so it is safe.
317 // Note that this method is allowed to produce false positives.
|
277 HandshakeState::HandshakeState() : _operation(NULL), _semaphore(1), _thread_in_process_handshake(false) {}
278
279 void HandshakeState::set_operation(JavaThread* target, HandshakeOperation* op) {
280 _operation = op;
281 SafepointMechanism::arm_local_poll_release(target);
282 }
283
284 void HandshakeState::clear_handshake(JavaThread* target) {
285 _operation = NULL;
286 SafepointMechanism::disarm_if_needed(target, true /* release */);
287 }
288
289 void HandshakeState::process_self_inner(JavaThread* thread) {
290 assert(Thread::current() == thread, "should call from thread");
291 assert(!thread->is_terminated(), "should not be a terminated thread");
292
293 ThreadInVMForHandshake tivm(thread);
294 if (!_semaphore.trywait()) {
295 _semaphore.wait_with_safepoint_check(thread);
296 }
297 HandshakeOperation* op = Atomic::load_acquire(&_operation);
298 if (op != NULL) {
299 HandleMark hm(thread);
300 CautiouslyPreserveExceptionMark pem(thread);
301 // Disarm before execute the operation
302 clear_handshake(thread);
303 op->do_handshake(thread);
304 }
305 _semaphore.signal();
306 }
307
308 bool HandshakeState::vmthread_can_process_handshake(JavaThread* target) {
309 // handshake_safe may only be called with polls armed.
310 // VM thread controls this by first claiming the handshake via claim_handshake_for_vmthread.
311 return SafepointSynchronize::handshake_safe(target);
312 }
313
314 static bool possibly_vmthread_can_process_handshake(JavaThread* target) {
315 // An externally suspended thread cannot be resumed while the
316 // Threads_lock is held so it is safe.
317 // Note that this method is allowed to produce false positives.
|