Skip to content

Commit

Permalink
8287281: adjust guarantee in Handshake::execute for the case of targe…
Browse files Browse the repository at this point in the history
…t thread being current

Reviewed-by: rehn, pchilanomate, dholmes, dcubed
  • Loading branch information
jdksjolen authored and David Holmes committed Jun 24, 2022
1 parent 64782a7 commit 9dc9a64
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
9 changes: 2 additions & 7 deletions src/hotspot/share/prims/jvmtiEnvThreadState.cpp
Expand Up @@ -396,13 +396,8 @@ void JvmtiEnvThreadState::reset_current_location(jvmtiEvent event_type, bool ena
// The java thread stack may not be walkable for a running thread
// so get current location with direct handshake.
GetCurrentLocationClosure op;
Thread *current = Thread::current();
if (thread->is_handshake_safe_for(current)) {
op.do_thread(thread);
} else {
Handshake::execute(&op, thread);
guarantee(op.completed(), "Handshake failed. Target thread is not alive?");
}
Handshake::execute(&op, thread);
guarantee(op.completed(), "Handshake failed. Target thread is not alive?");
op.get_current_location(&method_id, &bci);
set_current_location(method_id, bci);
}
Expand Down
12 changes: 3 additions & 9 deletions src/hotspot/share/prims/jvmtiEventController.cpp
Expand Up @@ -353,12 +353,11 @@ void VM_ChangeSingleStep::doit() {


void JvmtiEventControllerPrivate::enter_interp_only_mode(JvmtiThreadState *state) {
assert(state != NULL, "sanity check");
EC_TRACE(("[%s] # Entering interpreter only mode",
JvmtiTrace::safe_get_thread_name(state->get_thread_or_saved())));
JavaThread *target = state->get_thread();
Thread *current = Thread::current();

assert(state != NULL, "sanity check");
if (state->is_pending_interp_only_mode()) {
return; // An EnterInterpOnlyModeClosure handshake is already pending for execution.
}
Expand All @@ -368,13 +367,8 @@ void JvmtiEventControllerPrivate::enter_interp_only_mode(JvmtiThreadState *state
return; // EnterInterpOnlyModeClosure will be executed right after mount.
}
EnterInterpOnlyModeClosure hs;
if (target->is_handshake_safe_for(current)) {
hs.do_thread(target);
} else {
assert(state->get_thread() != NULL, "sanity check");
Handshake::execute(&hs, target);
guarantee(hs.completed(), "Handshake failed: Target thread is not alive?");
}
Handshake::execute(&hs, target);
guarantee(hs.completed(), "Handshake failed: Target thread is not alive?");
}


Expand Down
17 changes: 11 additions & 6 deletions src/hotspot/share/runtime/handshake.cpp
Expand Up @@ -351,12 +351,17 @@ void Handshake::execute(HandshakeClosure* hs_cl, JavaThread* target) {
}

void Handshake::execute(HandshakeClosure* hs_cl, ThreadsListHandle* tlh, JavaThread* target) {
JavaThread* self = JavaThread::current();
HandshakeOperation op(hs_cl, target, Thread::current());
guarantee(target != nullptr, "must be");

jlong start_time_ns = os::javaTimeNanos();
JavaThread* current = JavaThread::current();
if (target == current) {
hs_cl->do_thread(target);
return;
}

guarantee(target != nullptr, "must be");
HandshakeOperation op(hs_cl, target, current);

jlong start_time_ns = os::javaTimeNanos();
if (tlh == nullptr) {
guarantee(Thread::is_JavaThread_protected_by_TLH(target),
"missing ThreadsListHandle in calling context.");
Expand Down Expand Up @@ -389,9 +394,9 @@ void Handshake::execute(HandshakeClosure* hs_cl, ThreadsListHandle* tlh, JavaThr
hsy.add_result(pr);
// Check for pending handshakes to avoid possible deadlocks where our
// target is trying to handshake us.
if (SafepointMechanism::should_process(self)) {
if (SafepointMechanism::should_process(current)) {
// Will not suspend here.
ThreadBlockInVM tbivm(self);
ThreadBlockInVM tbivm(current);
}
hsy.process();
}
Expand Down

1 comment on commit 9dc9a64

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.