Skip to content
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

Add a walk state flag to skip methods with the JvmtiMountTransition annotation #17758

Closed
wants to merge 1 commit into from

Conversation

thallium
Copy link
Contributor

@thallium thallium commented Jul 7, 2023

Since it's only related to JVMTI, a walk state flag is added to enable the behaviour when doing JVMTI-related stack walk.

Related: #17490

…nnotation

Since it's only related to JVMTI, a walk state flag is added to enable
the behaviour when doing JVMTI-related stack walk.

Related: eclipse-openj9#17490

Signed-off-by: Gengchen Tuo <gengchen.tuo@ibm.com>
@thallium
Copy link
Contributor Author

thallium commented Jul 7, 2023

@babsingh FYI

@babsingh
Copy link
Contributor

babsingh commented Jul 10, 2023

The current title exceeds the allowed character limit. Revised commit message and PR description:

Skip methods with the JvmtiMountTransition annotation in JVMTI

These changes are only related to JVMTI.

A walk state flag is added to skip methods with the
JvmtiMountTransition annotation while walking the stack
in the following JVMTI functions:
- ... list the impacted JVMTI functions ...
- ...
- ...

Related: https://github.com/eclipse-openj9/openj9/issues/17490

Signed-off-by: Gengchen Tuo <gengchen.tuo@ibm.com>

Comment on lines +377 to 379
#define J9_IS_JVMTI_MOUNT_TRANSITION(method) \
((NULL != (method)) && (J9_ARE_ANY_BITS_SET(getExtendedModifiersDataFromROMMethod(J9_ROM_METHOD_FROM_RAM_METHOD(method)), CFR_METHOD_EXT_JVMTIMOUNTTRANSITION_ANNOTATION)))
#if defined(OPENJ9_BUILD)
Copy link
Contributor

@babsingh babsingh Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line and wrap with JAVA_SPEC_VERSION >= 20 to avoid compilation errors since CFR_METHOD_EXT_JVMTIMOUNTTRANSITION_ANNOTATION is only defined in JDK20+.

Suggested change
#define J9_IS_JVMTI_MOUNT_TRANSITION(method) \
((NULL != (method)) && (J9_ARE_ANY_BITS_SET(getExtendedModifiersDataFromROMMethod(J9_ROM_METHOD_FROM_RAM_METHOD(method)), CFR_METHOD_EXT_JVMTIMOUNTTRANSITION_ANNOTATION)))
#if defined(OPENJ9_BUILD)
#if JAVA_SPEC_VERSION >= 20
#define J9_IS_JVMTI_MOUNT_TRANSITION(method) \
((NULL != (method)) && (J9_ARE_ANY_BITS_SET(getExtendedModifiersDataFromROMMethod(J9_ROM_METHOD_FROM_RAM_METHOD(method)), CFR_METHOD_EXT_JVMTIMOUNTTRANSITION_ANNOTATION)))
#endif /* JAVA_SPEC_VERSION >= 20 */
#if defined(OPENJ9_BUILD)

Comment on lines +484 to +489
/* Skip methods with JvmtiMountTransition annotation */
if (J9_ARE_ALL_BITS_SET(walkState->flags, J9_STACKWALK_SKIP_JVMTI_MOUNT_TRANSITION_FRAMES)
&& J9_IS_JVMTI_MOUNT_TRANSITION(walkState->method)
) {
return J9_STACKWALK_KEEP_ITERATING;
}
Copy link
Contributor

@babsingh babsingh Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with #16654, the code changes in this PR should be wrapped with JAVA_SPEC_VERSION >= 20.

Suggested change
/* Skip methods with JvmtiMountTransition annotation */
if (J9_ARE_ALL_BITS_SET(walkState->flags, J9_STACKWALK_SKIP_JVMTI_MOUNT_TRANSITION_FRAMES)
&& J9_IS_JVMTI_MOUNT_TRANSITION(walkState->method)
) {
return J9_STACKWALK_KEEP_ITERATING;
}
#if JAVA_SPEC_VERSION >= 20
/* Skip methods with JvmtiMountTransition annotation. */
if (J9_ARE_ALL_BITS_SET(walkState->flags, J9_STACKWALK_SKIP_JVMTI_MOUNT_TRANSITION_FRAMES)
&& J9_IS_JVMTI_MOUNT_TRANSITION(walkState->method)
) {
return J9_STACKWALK_KEEP_ITERATING;
}
#endif /* JAVA_SPEC_VERSION >= 20 */

@@ -401,6 +401,7 @@ extern "C" {
#define J9_STACKWALK_CACHE_METHODS 0x400
#define J9_STACKWALK_CACHE_MASK 0x700
#define J9_STACKWALK_SKIP_HIDDEN_FRAMES 0x800
#define J9_STACKWALK_SKIP_JVMTI_MOUNT_TRANSITION_FRAMES 0x1000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Macro definitions don't need JAVA_SPEC_VERSION >= 20.

@babsingh
Copy link
Contributor

++ @gacholio for a second set of eyes.

@babsingh babsingh requested a review from gacholio July 10, 2023 18:25
@gacholio
Copy link
Contributor

This stuff really doesn't belong in the stack walker (I know previous hacks for hidden have made it in). Really, it should be handled in the frame iterators, much like we do to hide the old reflect implementation).

@@ -1813,7 +1813,7 @@ UDATA
findDecompileInfo(J9VMThread *currentThread, J9VMThread *targetThread, UDATA depth, J9StackWalkState *walkState)
{
walkState->walkThread = targetThread;
walkState->flags = J9_STACKWALK_ITERATE_FRAMES | J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY | J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET | J9_STACKWALK_MAINTAIN_REGISTER_MAP;
walkState->flags = J9_STACKWALK_ITERATE_FRAMES | J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY | J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET | J9_STACKWALK_MAINTAIN_REGISTER_MAP | J9_STACKWALK_SKIP_JVMTI_MOUNT_TRANSITION_FRAMES;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly a place that should not be changed - this wants the true view of the stack, not a user-facing one.

@gacholio
Copy link
Contributor

The only place using the new flag is using it incorrectly as far as I can see, so we should probably just abandon this PR.

babsingh pushed a commit to babsingh/openj9 that referenced this pull request Jul 26, 2023
Java methods tagged with the JvmtiMountTransition annotation are
involved in transitioning between carrier to virtual threads, and
vice-versa. These methods are not part of the thread's scope. So,
they are skipped during introspection by the following JVMTI
functions:
- ForceEarlyReturn
- NotifyFramePop
- Local Variable (GetOrSetLocal)

This PR allows us to match the RI in jvmti/vthread/MethodExitTest.

Related eclipse-openj9#17490

Closes eclipse-openj9#17758

Co-authored-by: Gengchen Tuo <gengchen.tuo@ibm.com>
Signed-off-by: Babneet Singh <sbabneet@ca.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants