Skip to content
Permalink
Browse files
8238761: Asynchronous handshakes
Reviewed-by: pchilanomate, dcubed, dholmes, coleenp, sspitsyn
  • Loading branch information
robehn committed Sep 29, 2020
1 parent 6d19fe6 commit 6bddeb709d1d263d0d753909cabce7e755e7e27d
Showing 24 changed files with 975 additions and 375 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,7 @@ class Thread;
class Closure : public StackObj { };

// Thread iterator
class ThreadClosure: public Closure {
class ThreadClosure {
public:
virtual void do_thread(Thread* thread) = 0;
};
@@ -1213,8 +1213,8 @@ JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count
} else {
// get owned monitors info with handshake
GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
bool executed = Handshake::execute_direct(&op, java_thread);
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
Handshake::execute(&op, java_thread);
err = op.result();
}
jint owned_monitor_count = owned_monitors_list->length();
if (err == JVMTI_ERROR_NONE) {
@@ -1258,8 +1258,8 @@ JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_i
} else {
// get owned monitors info with handshake
GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
bool executed = Handshake::execute_direct(&op, java_thread);
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
Handshake::execute(&op, java_thread);
err = op.result();
}

jint owned_monitor_count = owned_monitors_list->length();
@@ -1302,8 +1302,8 @@ JvmtiEnv::GetCurrentContendedMonitor(JavaThread* java_thread, jobject* monitor_p
} else {
// get contended monitor information with handshake
GetCurrentContendedMonitorClosure op(calling_thread, this, monitor_ptr);
bool executed = Handshake::execute_direct(&op, java_thread);
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
Handshake::execute(&op, java_thread);
err = op.result();
}
return err;
} /* end GetCurrentContendedMonitor */
@@ -1540,8 +1540,8 @@ JvmtiEnv::GetStackTrace(JavaThread* java_thread, jint start_depth, jint max_fram
} else {
// Get stack trace with handshake.
GetStackTraceClosure op(this, start_depth, max_frame_count, frame_buffer, count_ptr);
bool executed = Handshake::execute_direct(&op, java_thread);
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
Handshake::execute(&op, java_thread);
err = op.result();
}

return err;
@@ -1585,8 +1585,8 @@ JvmtiEnv::GetThreadListStackTraces(jint thread_count, const jthread* thread_list
}

GetSingleStackTraceClosure op(this, current_thread, *thread_list, max_frame_count);
bool executed = Handshake::execute_direct(&op, java_thread);
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
Handshake::execute(&op, java_thread);
err = op.result();
if (err == JVMTI_ERROR_NONE) {
*stack_info_ptr = op.stack_info();
}
@@ -1623,8 +1623,8 @@ JvmtiEnv::GetFrameCount(JavaThread* java_thread, jint* count_ptr) {
} else {
// get java stack frame count with handshake.
GetFrameCountClosure op(this, state, count_ptr);
bool executed = Handshake::execute_direct(&op, java_thread);
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
Handshake::execute(&op, java_thread);
err = op.result();
}
return err;
} /* end GetFrameCount */
@@ -1721,10 +1721,9 @@ JvmtiEnv::PopFrame(JavaThread* java_thread) {
state->update_for_pop_top_frame();
} else {
UpdateForPopTopFrameClosure op(state);
bool executed = Handshake::execute_direct(&op, java_thread);
jvmtiError err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
if (err != JVMTI_ERROR_NONE) {
return err;
Handshake::execute(&op, java_thread);
if (op.result() != JVMTI_ERROR_NONE) {
return op.result();
}
}
}
@@ -1756,8 +1755,8 @@ JvmtiEnv::GetFrameLocation(JavaThread* java_thread, jint depth, jmethodID* metho
} else {
// JVMTI get java stack frame location via direct handshake.
GetFrameLocationClosure op(this, depth, method_ptr, location_ptr);
bool executed = Handshake::execute_direct(&op, java_thread);
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
Handshake::execute(&op, java_thread);
err = op.result();
}
return err;
} /* end GetFrameLocation */
@@ -1805,8 +1804,8 @@ JvmtiEnv::NotifyFramePop(JavaThread* java_thread, jint depth) {
state->env_thread_state(this)->set_frame_pop(frame_number);
} else {
SetFramePopClosure op(this, state, depth);
bool executed = Handshake::execute_direct(&op, java_thread);
err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
Handshake::execute(&op, java_thread);
err = op.result();
}
return err;
} /* end NotifyFramePop */
@@ -649,10 +649,9 @@ JvmtiEnvBase::count_locked_objects(JavaThread *java_thread, Handle hobj) {

jvmtiError
JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThread *java_thread, jobject *monitor_ptr) {
JavaThread *current_jt = JavaThread::current();
assert(current_jt == java_thread ||
current_jt == java_thread->active_handshaker(),
"call by myself or at direct handshake");
Thread *current_thread = Thread::current();
assert(java_thread->is_handshake_safe_for(current_thread),
"call by myself or at handshake");
oop obj = NULL;
// The ObjectMonitor* can't be async deflated since we are either
// at a safepoint or the calling thread is operating on itself so
@@ -676,8 +675,8 @@ JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThre
if (obj == NULL) {
*monitor_ptr = NULL;
} else {
HandleMark hm(current_jt);
Handle hobj(current_jt, obj);
HandleMark hm(current_thread);
Handle hobj(current_thread, obj);
*monitor_ptr = jni_reference(calling_thread, hobj);
}
return JVMTI_ERROR_NONE;
@@ -687,15 +686,19 @@ JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThre
jvmtiError
JvmtiEnvBase::get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread,
GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list) {
// Note:
// calling_thread is the thread that requested the list of monitors for java_thread.
// java_thread is the thread owning the monitors.
// current_thread is the thread executing this code, can be a non-JavaThread (e.g. VM Thread).
// And they all may be different threads.
jvmtiError err = JVMTI_ERROR_NONE;
JavaThread *current_jt = JavaThread::current();
assert(current_jt == java_thread ||
current_jt == java_thread->active_handshaker(),
"call by myself or at direct handshake");
Thread *current_thread = Thread::current();
assert(java_thread->is_handshake_safe_for(current_thread),
"call by myself or at handshake");

if (java_thread->has_last_Java_frame()) {
ResourceMark rm(current_jt);
HandleMark hm(current_jt);
ResourceMark rm(current_thread);
HandleMark hm(current_thread);
RegisterMap reg_map(java_thread);

int depth = 0;
@@ -819,9 +822,8 @@ JvmtiEnvBase::get_stack_trace(JavaThread *java_thread,
uint32_t debug_bits = 0;
#endif
Thread *current_thread = Thread::current();
assert(current_thread == java_thread ||
SafepointSynchronize::is_at_safepoint() ||
current_thread == java_thread->active_handshaker(),
assert(SafepointSynchronize::is_at_safepoint() ||
java_thread->is_handshake_safe_for(current_thread),
"call by myself / at safepoint / at handshake");
int count = 0;
if (java_thread->has_last_Java_frame()) {
@@ -903,9 +905,8 @@ JvmtiEnvBase::get_frame_location(JavaThread *java_thread, jint depth,
uint32_t debug_bits = 0;
#endif
Thread* current_thread = Thread::current();
assert(current_thread == java_thread ||
current_thread == java_thread->active_handshaker(),
"call by myself or at direct handshake");
assert(java_thread->is_handshake_safe_for(current_thread),
"call by myself or at handshake");
ResourceMark rm(current_thread);

vframe *vf = vframeFor(java_thread, depth);
@@ -1159,9 +1160,8 @@ void
MultipleStackTracesCollector::fill_frames(jthread jt, JavaThread *thr, oop thread_oop) {
#ifdef ASSERT
Thread *current_thread = Thread::current();
assert(current_thread == thr ||
SafepointSynchronize::is_at_safepoint() ||
current_thread == thr->active_handshaker(),
assert(SafepointSynchronize::is_at_safepoint() ||
thr->is_handshake_safe_for(current_thread),
"call by myself / at safepoint / at handshake");
#endif

@@ -1305,7 +1305,7 @@ VM_GetAllStackTraces::doit() {
// HandleMark must be defined in the caller only.
// It is to keep a ret_ob_h handle alive after return to the caller.
jvmtiError
JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
JvmtiEnvBase::check_top_frame(Thread* current_thread, JavaThread* java_thread,
jvalue value, TosState tos, Handle* ret_ob_h) {
ResourceMark rm(current_thread);

@@ -1368,7 +1368,7 @@ JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_threa

jvmtiError
JvmtiEnvBase::force_early_return(JavaThread* java_thread, jvalue value, TosState tos) {
JavaThread* current_thread = JavaThread::current();
Thread* current_thread = Thread::current();
HandleMark hm(current_thread);
uint32_t debug_bits = 0;

1 comment on commit 6bddeb7

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 6bddeb7 Sep 29, 2020

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.