-
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
Open
lmesnik
wants to merge
5
commits into
openjdk:master
Choose a base branch
from
lmesnik:8365192-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+46
−34
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.