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

Fix stackwalk related jvmti functions #15872

Merged

Conversation

thallium
Copy link
Contributor

@thallium thallium commented Sep 12, 2022

In some cases the J9VMContinuation cannot be accessed through a j9object so we change the parameter of walkContinuationStackFrames to accept a J9VMContinuation pointer directly.

Adds declaration of J9VMContinuation to the top.

In the old implementation, if a carrier thread has a virtual thread mounted after getVMThread being called, the virtual thread will be walked. We fix this by adding a check for currentContinuation of the carrier thread. If the currentContinuation is not null, the info of the carrier thread has been swapped to the currentContinuation, so the
currentContinuation will be walked instead.

To facilitate other stackwalk-related functions, a generic stackwalk helper is added to walk a platform thread or a virtual thread. A virtual can be mounted or unmounted, if it's mounted, the carrier thread is walked, otherwise the continuation object is walked. For a platform thread, if the currentContinuation is not null, the currentContinuation will be walked, otherwise the thread is walked.

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

In some cases the J9VMContinuation cannot be accessed through a j9object
so we change the parameter of walkContinuationStackFrames to accept
a J9VMContinuation pointer directly.

Adds declaration of J9VMContinuation to the top.

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

@fengxue-IS @babsingh FYI

Copy link
Contributor

@fengxue-IS fengxue-IS left a comment

Choose a reason for hiding this comment

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

LGTM

@fengxue-IS fengxue-IS added the project:loom Used to track Project Loom related work label Sep 12, 2022
@thallium thallium changed the title Change walkContinuationStackFrames to accept J9VMContinuation [WIP] Fix stackwalk related jvmti functions Sep 12, 2022
@thallium thallium force-pushed the walkContinuationStackFrameFix branch 3 times, most recently from 55dff18 to 104f071 Compare September 13, 2022 15:29
@thallium thallium changed the title [WIP] Fix stackwalk related jvmti functions Fix stackwalk related jvmti functions Sep 13, 2022
@thallium thallium requested review from babsingh and fengxue-IS and removed request for babsingh and fengxue-IS September 13, 2022 15:32
@fengxue-IS fengxue-IS self-requested a review September 13, 2022 15:34
Copy link
Contributor

@fengxue-IS fengxue-IS left a comment

Choose a reason for hiding this comment

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

@thallium
Copy link
Contributor Author

Can you confirm that all previous testing on the updated APIs also pass ie. https://github.com/ibmruntimes/openj9-openjdk-jdk19/tree/openj9/test/hotspot/jtreg/serviceability/jvmti/thread/GetStackTrace https://github.com/ibmruntimes/openj9-openjdk-jdk19/tree/openj9/test/hotspot/jtreg/serviceability/jvmti/thread/GetFrameCount/framecnt01

Yes I've run the GetFrameCount, GetFrameLocation, and GetStackTrace tests, all the results stayed the same.

Copy link
Contributor

@babsingh babsingh left a comment

Choose a reason for hiding this comment

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

Minor formatting nitpicks. Plan to launch PR builds after this.

runtime/jvmti/jvmti_internal.h Outdated Show resolved Hide resolved
runtime/jvmti/jvmtiHelpers.c Outdated Show resolved Hide resolved
runtime/oti/vm_api.h Show resolved Hide resolved
@thallium
Copy link
Contributor Author

fixed

runtime/oti/vm_api.h Outdated Show resolved Hide resolved
runtime/jvmti/jvmtiHelpers.c Outdated Show resolved Hide resolved
runtime/oti/vm_api.h Outdated Show resolved Hide resolved
@babsingh
Copy link
Contributor

jenkins test sanity win,xlinux jdk19

@babsingh
Copy link
Contributor

jenkins test sanity amac jdk11

@babsingh
Copy link
Contributor

There are compilation errors in the PR builds. All invocations of jvmtiInternalGetStackTrace have not been correctly updated to take threadObject.

@thallium
Copy link
Contributor Author

Should be fixed now, but not sure if targetThread->threadObject should be passed in GetAllStackTraces.

@babsingh
Copy link
Contributor

Should be fixed now, but not sure if targetThread->threadObject should be passed in GetAllStackTraces.

No. See https://download.java.net/java/early_access/jdk19/docs/specs/jvmti.html#GetAllStackTraces. As per the JVMTI doc, it should "get the stack traces of all live platform threads attached to the VM ... It does not include the stack traces of virtual threads". targetThread->threadObject can point to virtual threads. To only go through platform threads, it should be carrierThreadObject for JDK19+ and threadObject for JDK18-. For reference, see the below changes:

#if JAVA_SPEC_VERSION >= 19
/* carrierThreadObject should always point to a platform thread.
* Thus, all virtual threads should be excluded.
*/
j9object_t threadObject = targetThread->carrierThreadObject;
#else /* JAVA_SPEC_VERSION >= 19 */
j9object_t threadObject = targetThread->threadObject;
#endif /* JAVA_SPEC_VERSION >= 19 */

@babsingh
Copy link
Contributor

jenkins test sanity amac jdk11

@babsingh
Copy link
Contributor

jenkins test sanity win,xlinux jdk19

@babsingh
Copy link
Contributor

jenkins test sanity amac jdk11

@babsingh
Copy link
Contributor

jenkins test sanity win,xlinux jdk19

Copy link
Contributor

@babsingh babsingh left a comment

Choose a reason for hiding this comment

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

This should fix the recent crash. As per the JVMTI doc, the current thread should be used if the input thread is null. See the JVMTI doc for the three impacted functions:

runtime/jvmti/jvmtiStackFrame.c Outdated Show resolved Hide resolved
runtime/jvmti/jvmtiStackFrame.c Outdated Show resolved Hide resolved
runtime/jvmti/jvmtiStackFrame.c Outdated Show resolved Hide resolved
In the old implementation, if a carrier thread has a virtual thread
mounted after getVMThread being called, the virtual thread will be
walked. We fix this by adding a check for currentContinuation of the
carrier thread. If the currentContinuation is not null, the info of the
carrier thread has been swapped to the currentContinuation, so the
currentContinuation will be walked instead.

To facilitate other stackwalk-related functions, a generic stackwalk
helper is added to walk a platform thread or a virtual thread. A
virtual can be mounted or unmounted, if it's mounted, the carrier thread
is walked, otherwise the continuation object is walked. For a platform
thread, if the currentContinuation is not null, the currentContinuation
will be walked, otherwise the thread is walked.

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

Fixed

@babsingh
Copy link
Contributor

jenkins test sanity amac jdk11

@babsingh
Copy link
Contributor

jenkins test sanity win,xlinux jdk19

@babsingh babsingh merged commit 3aa730c into eclipse-openj9:master Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project:loom Used to track Project Loom related work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants