-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8365192: post_meth_exit should be in vm state when calling get_jvmti_thread_state #27112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
a031b40
c1de44f
77c9c7a
ea2dff0
0bd9c98
118d39e
ea941c2
03c172a
3a16979
85482ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,6 +418,7 @@ JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) { | |
JvmtiThreadState* | ||
JvmtiExport::get_jvmti_thread_state(JavaThread *thread, bool allow_suspend) { | ||
assert(thread == JavaThread::current(), "must be current thread"); | ||
assert(thread->thread_state() == _thread_in_vm, "thread should be in vm"); | ||
if (thread->is_vthread_mounted() && thread->jvmti_thread_state() == nullptr) { | ||
JvmtiEventController::thread_started(thread); | ||
if (allow_suspend && thread->is_suspended()) { | ||
|
@@ -1826,58 +1827,64 @@ void JvmtiExport::post_method_entry(JavaThread *thread, Method* method, frame cu | |
} | ||
|
||
void JvmtiExport::post_method_exit(JavaThread* thread, Method* method, frame current_frame) { | ||
// At this point we only have the address of a "raw result" and | ||
// we just call into the interpreter to convert this into a jvalue. | ||
// The post_method_exit_transition always makes transition to vm and back | ||
// where GC can happen. So it is needed to preserve result and then restore it | ||
// even if events are not actually posted. | ||
// Saving oop_result into value.j is deferred until jvmti state is ready. | ||
HandleMark hm(thread); | ||
methodHandle mh(thread, method); | ||
|
||
JvmtiThreadState *state = get_jvmti_thread_state(thread); | ||
|
||
if (state == nullptr || !state->is_interp_only_mode()) { | ||
// for any thread that actually wants method exit, interp_only_mode is set | ||
return; | ||
} | ||
|
||
Handle result; | ||
oop oop_result; | ||
jvalue value; | ||
value.j = 0L; | ||
|
||
if (state->is_enabled(JVMTI_EVENT_METHOD_EXIT)) { | ||
// At this point we only have the address of a "raw result" and | ||
// we just call into the interpreter to convert this into a jvalue. | ||
oop oop_result; | ||
BasicType type = current_frame.interpreter_frame_result(&oop_result, &value); | ||
assert(type == T_VOID || current_frame.interpreter_frame_expression_stack_size() > 0, | ||
"Stack shouldn't be empty"); | ||
if (is_reference_type(type)) { | ||
result = Handle(thread, oop_result); | ||
value.l = JNIHandles::make_local(thread, result()); | ||
} | ||
BasicType type = current_frame.interpreter_frame_result(&oop_result, &value); | ||
assert(type == T_VOID || current_frame.interpreter_frame_expression_stack_size() > 0, | ||
"Stack shouldn't be empty"); | ||
|
||
if (is_reference_type(type)) { | ||
result = Handle(thread, oop_result); | ||
} | ||
post_method_exit_transition(thread, mh, type, result, value); | ||
if (result.not_null() && !mh->is_native()) { | ||
*(oop*)current_frame.interpreter_frame_tos_address() = result(); | ||
} | ||
} | ||
|
||
// Do not allow NotifyFramePop to add new FramePop event request at | ||
// depth 0 as it is already late in the method exiting dance. | ||
state->set_top_frame_is_exiting(); | ||
|
||
// Deferred transition to VM, so we can stash away the return oop before GC. | ||
void JvmtiExport::post_method_exit_transition(JavaThread* thread, methodHandle mh, | ||
BasicType type, Handle result, jvalue value) { | ||
JvmtiThreadState* state; // should be initialized in vm state only | ||
JavaThread* current = thread; // for JRT_BLOCK | ||
lmesnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
JRT_BLOCK | ||
post_method_exit_inner(thread, mh, state, false /* not exception exit */, current_frame, value); | ||
state = get_jvmti_thread_state(thread); | ||
if (state == nullptr || !state->is_interp_only_mode()) { | ||
// The transition from vm to java | ||
return; | ||
} | ||
|
||
if (state->is_enabled(JVMTI_EVENT_METHOD_EXIT)) { | ||
// Deferred saving Object result into value. | ||
if (is_reference_type(type)) { | ||
value.l = JNIHandles::make_local(thread, result()); | ||
} | ||
} | ||
|
||
// Do not allow NotifyFramePop to add new FramePop event request at | ||
// depth 0 as it is already late in the method exiting dance. | ||
state->set_top_frame_is_exiting(); | ||
|
||
post_method_exit_inner(thread, mh, state, false /* not exception exit */, value); | ||
JRT_BLOCK_END | ||
|
||
// The JRT_BLOCK_END can safepoint in ThreadInVMfromJava desctructor. Now it is safe to allow | ||
// adding FramePop event requests as no safepoint can happen before removing activation. | ||
state->clr_top_frame_is_exiting(); | ||
|
||
if (result.not_null() && !mh->is_native()) { | ||
// We have to restore the oop on the stack for interpreter frames | ||
*(oop*)current_frame.interpreter_frame_tos_address() = result(); | ||
} | ||
} | ||
|
||
void JvmtiExport::post_method_exit_inner(JavaThread* thread, | ||
methodHandle& mh, | ||
JvmtiThreadState *state, | ||
bool exception_exit, | ||
frame current_frame, | ||
jvalue& value) { | ||
if (mh->jvmti_mount_transition() || thread->should_hide_jvmti_events()) { | ||
return; | ||
|
@@ -2107,7 +2114,7 @@ void JvmtiExport::notice_unwind_due_to_exception(JavaThread *thread, Method* met | |
// When these events are enabled code should be in running in interp mode. | ||
jvalue no_value; | ||
no_value.j = 0L; | ||
JvmtiExport::post_method_exit_inner(thread, mh, state, true, thread->last_frame(), no_value); | ||
JvmtiExport::post_method_exit_inner(thread, mh, state, true, no_value); | ||
// The cached cur_stack_depth might have changed from the | ||
// operations of frame pop or method exit. We are not 100% sure | ||
// the cached cur_stack_depth is still valid depth so invalidate | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.