Skip to content

Commit 9dc9a64

Browse files
jdksjolenDavid Holmes
authored and
David Holmes
committed
8287281: adjust guarantee in Handshake::execute for the case of target thread being current
Reviewed-by: rehn, pchilanomate, dholmes, dcubed
1 parent 64782a7 commit 9dc9a64

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

src/hotspot/share/prims/jvmtiEnvThreadState.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,8 @@ void JvmtiEnvThreadState::reset_current_location(jvmtiEvent event_type, bool ena
396396
// The java thread stack may not be walkable for a running thread
397397
// so get current location with direct handshake.
398398
GetCurrentLocationClosure op;
399-
Thread *current = Thread::current();
400-
if (thread->is_handshake_safe_for(current)) {
401-
op.do_thread(thread);
402-
} else {
403-
Handshake::execute(&op, thread);
404-
guarantee(op.completed(), "Handshake failed. Target thread is not alive?");
405-
}
399+
Handshake::execute(&op, thread);
400+
guarantee(op.completed(), "Handshake failed. Target thread is not alive?");
406401
op.get_current_location(&method_id, &bci);
407402
set_current_location(method_id, bci);
408403
}

src/hotspot/share/prims/jvmtiEventController.cpp

+3-9
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,11 @@ void VM_ChangeSingleStep::doit() {
353353

354354

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

361-
assert(state != NULL, "sanity check");
362361
if (state->is_pending_interp_only_mode()) {
363362
return; // An EnterInterpOnlyModeClosure handshake is already pending for execution.
364363
}
@@ -368,13 +367,8 @@ void JvmtiEventControllerPrivate::enter_interp_only_mode(JvmtiThreadState *state
368367
return; // EnterInterpOnlyModeClosure will be executed right after mount.
369368
}
370369
EnterInterpOnlyModeClosure hs;
371-
if (target->is_handshake_safe_for(current)) {
372-
hs.do_thread(target);
373-
} else {
374-
assert(state->get_thread() != NULL, "sanity check");
375-
Handshake::execute(&hs, target);
376-
guarantee(hs.completed(), "Handshake failed: Target thread is not alive?");
377-
}
370+
Handshake::execute(&hs, target);
371+
guarantee(hs.completed(), "Handshake failed: Target thread is not alive?");
378372
}
379373

380374

src/hotspot/share/runtime/handshake.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,17 @@ void Handshake::execute(HandshakeClosure* hs_cl, JavaThread* target) {
351351
}
352352

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

357-
jlong start_time_ns = os::javaTimeNanos();
356+
JavaThread* current = JavaThread::current();
357+
if (target == current) {
358+
hs_cl->do_thread(target);
359+
return;
360+
}
358361

359-
guarantee(target != nullptr, "must be");
362+
HandshakeOperation op(hs_cl, target, current);
363+
364+
jlong start_time_ns = os::javaTimeNanos();
360365
if (tlh == nullptr) {
361366
guarantee(Thread::is_JavaThread_protected_by_TLH(target),
362367
"missing ThreadsListHandle in calling context.");
@@ -389,9 +394,9 @@ void Handshake::execute(HandshakeClosure* hs_cl, ThreadsListHandle* tlh, JavaThr
389394
hsy.add_result(pr);
390395
// Check for pending handshakes to avoid possible deadlocks where our
391396
// target is trying to handshake us.
392-
if (SafepointMechanism::should_process(self)) {
397+
if (SafepointMechanism::should_process(current)) {
393398
// Will not suspend here.
394-
ThreadBlockInVM tbivm(self);
399+
ThreadBlockInVM tbivm(current);
395400
}
396401
hsy.process();
397402
}

0 commit comments

Comments
 (0)