The implementation of execute_direct is as follows:
bool Handshake::execute_direct(HandshakeClosure* thread_cl, JavaThread* target) {
JavaThread* self = JavaThread::current();
HandshakeOperation op(thread_cl, /*is_direct*/ true);
jlong start_time_ns = os::javaTimeNanos();
ThreadsListHandle tlh;
if (tlh.includes(target)) {
target->set_handshake_operation(&op);
It needs the ThreadsListHandle to ensure the target thread is alive, and will remain alive, for the duration of the operation.
However, in some cases when dealing with direct handshakes, the higher-level operation already has to have a ThreadsListHandle active to guard the target thread for the same reasons. In such cases the overhead of the TLH in execute_direct is unnecessary.
We should provide an alternative version of execute_direct that allows us to rely on the outer TLH.