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

Virtual threads support for jvmtiGetFrameCount #15753

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions runtime/jvmti/j9jvmti.tdf
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ TraceAssert=Assert_JVMTI_false noEnv Overhead=1 Level=1 Assert="!(P1)"
TraceAssert=Assert_JVMTI_notNull noEnv Overhead=1 Level=1 Assert="(P1) != NULL"
TraceAssert=Assert_JVMTI_mustHaveVMAccess noEnv overhead=1 Level=1 Assert="(P1)->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS"
TraceAssert=Assert_JVMTI_mustNotHaveVMAccess noEnv overhead=1 Level=1 Assert="0 == ((P1)->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS)"
TraceAssert=Assert_JVMTI_unreachable noEnv Overhead=1 Level=1 Assert="0"
babsingh marked this conversation as resolved.
Show resolved Hide resolved

TraceEntry=Trc_JVMTI_jvmtiHookResourceExhausted_Entry Overhead=1 Level=1 Noenv Template="ResourceExhaustedEvent"
TraceExit=Trc_JVMTI_jvmtiHookResourceExhausted_Exit Overhead=1 Level=1 Noenv Template="ResourceExhaustedEvent"
Expand Down
30 changes: 22 additions & 8 deletions runtime/jvmti/jvmtiStackFrame.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,11 @@ jvmtiGetFrameCount(jvmtiEnv* env,
Trc_JVMTI_jvmtiGetFrameCount_Entry(env);

rc = getCurrentVMThread(vm, &currentThread);
J9InternalVMFunctions* vmFuncs = vm->internalVMFunctions;
thallium marked this conversation as resolved.
Show resolved Hide resolved
if (rc == JVMTI_ERROR_NONE) {
J9VMThread *targetThread = NULL;

vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
vmFuncs->internalEnterVMFromJNI(currentThread);

ENSURE_PHASE_LIVE(env);

Expand All @@ -283,20 +284,33 @@ jvmtiGetFrameCount(jvmtiEnv* env,
rc = getVMThread(currentThread, thread, &targetThread, TRUE, TRUE);
if (rc == JVMTI_ERROR_NONE) {
J9StackWalkState walkState;

vm->internalVMFunctions->haltThreadForInspection(currentThread, targetThread);
thallium marked this conversation as resolved.
Show resolved Hide resolved

walkState.walkThread = targetThread;
walkState.flags = J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY;
walkState.skipCount = 0;
vm->walkStackFrames(currentThread, &walkState);

#if JAVA_SPEC_VERSION >= 19
if (NULL == targetThread) {
j9object_t threadObject = J9_JNI_UNWRAP_REFERENCE(thread);
if (IS_VIRTUAL_THREAD(currentThread, threadObject)) {
thallium marked this conversation as resolved.
Show resolved Hide resolved
j9object_t contObject = (j9object_t)J9VMJAVALANGVIRTUALTHREAD_CONT(currentThread, threadObject);
vmFuncs->walkContinuationStackFrames(currentThread, contObject, &walkState);
} else {
Assert_JVMTI_unreachable();
}
} else
#endif /* JAVA_SPEC_VERSION >= 19 */
{
vmFuncs->haltThreadForInspection(currentThread, targetThread);
walkState.walkThread = targetThread;
vm->walkStackFrames(currentThread, &walkState);
vmFuncs->resumeThreadForInspection(currentThread, targetThread);
}

rv_count = (jint) walkState.framesWalked;

vm->internalVMFunctions->resumeThreadForInspection(currentThread, targetThread);
releaseVMThread(currentThread, targetThread, thread);
}
done:
vm->internalVMFunctions->internalExitVMToJNI(currentThread);
vmFuncs->internalExitVMToJNI(currentThread);
}

if (NULL != count_ptr) {
Expand Down
3 changes: 3 additions & 0 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4900,6 +4900,9 @@ typedef struct J9InternalVMFunctions {
U_8 * (JNICALL *native2InterpJavaUpcallStruct)(struct J9UpcallMetaData *data, void *argsListPointer);
*/
#endif /* JAVA_SPEC_VERSION >= 16 */
#if JAVA_SPEC_VERSION >= 19
UDATA (*walkContinuationStackFrames)(struct J9VMThread *currentThread, j9object_t continuationObject, J9StackWalkState *walkState);
#endif /* JAVA_SPEC_VERSION >= 19 */
} J9InternalVMFunctions;

/* Jazz 99339: define a new structure to replace JavaVM so as to pass J9NativeLibrary to JVMTIEnv */
Expand Down
1 change: 1 addition & 0 deletions runtime/oti/vmconstantpool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti

<fieldref class="java/lang/VirtualThread" name="state" signature="I" versions="19-"/>
<fieldref class="java/lang/VirtualThread" name="carrierThread" signature="Ljava/lang/Thread;" versions="19-"/>
<fieldref class="java/lang/VirtualThread" name="cont" signature="Ljdk/internal/vm/Continuation;" versions="19-"/>

<fieldref class="java/lang/Throwable" name="cause" signature="Ljava/lang/Throwable;"/>
<fieldref class="java/lang/Throwable" name="detailMessage" signature="Ljava/lang/String;"/>
Expand Down
3 changes: 3 additions & 0 deletions runtime/vm/intfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,7 @@ J9InternalVMFunctions J9InternalFunctions = {
native2InterpJavaUpcallStruct,
*/
#endif /* JAVA_SPEC_VERSION >= 16 */
#if JAVA_SPEC_VERSION >= 19
walkContinuationStackFrames,
#endif /* JAVA_SPEC_VERSION >= 19 */
};