Skip to content

Commit

Permalink
[GR-62082] Remove obsolete BreakpointInterceptor.rectifyCurrentThread.
Browse files Browse the repository at this point in the history
PullRequest: graal/20125
  • Loading branch information
wirthi committed Feb 25, 2025
2 parents 415d221 + 36a8124 commit 63a4415
Showing 1 changed file with 1 addition and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
import com.oracle.svm.jvmtiagentbase.jvmti.JvmtiEventCallbacks;
import com.oracle.svm.jvmtiagentbase.jvmti.JvmtiEventMode;
import com.oracle.svm.jvmtiagentbase.jvmti.JvmtiFrameInfo;
import com.oracle.svm.jvmtiagentbase.jvmti.JvmtiInterface;
import com.oracle.svm.jvmtiagentbase.jvmti.JvmtiLocationFormat;

import jdk.graal.compiler.core.common.NumUtil;
Expand Down Expand Up @@ -1190,14 +1189,9 @@ private static void onBreakpoint(@SuppressWarnings("unused") JvmtiEnv jvmti, JNI
}
recursive.set(true);
try {
JNIObjectHandle rectifiedThread = rectifyCurrentThread(thread);
if (rectifiedThread.equal(nullHandle())) {
return;
}

Breakpoint bp = installedBreakpoints.get(method.rawValue());
InterceptedState state = interceptedStateSupplier.get();
if (bp.specification.handler.dispatch(jni, rectifiedThread, bp, state)) {
if (bp.specification.handler.dispatch(jni, thread, bp, state)) {
guarantee(!testException(jni));
}
} catch (Throwable t) {
Expand All @@ -1207,28 +1201,6 @@ private static void onBreakpoint(@SuppressWarnings("unused") JvmtiEnv jvmti, JNI
}
}

/**
* The JVMTI implementation of JDK 19 can pass the platform thread as current thread for events
* in a virtual thread that happen while temporarily switching to the carrier thread (such as
* scheduling an unpark). It also ignores the frames of a virtual thread when passing
* {@code NULL} to {@code GetLocal*} to refer to the current thread (JDK-8292657). This method
* calls {@code GetCurrentThread}, which seems to always return the virtual thread and can be
* used to properly read the locals in the breakpoint.
*/
private static JNIObjectHandle rectifyCurrentThread(JNIObjectHandle thread) {
if (Support.jvmtiVersion() != JvmtiInterface.JVMTI_VERSION_19) {
return thread;
}

WordPointer threadPtr = StackValue.get(WordPointer.class);
JvmtiError error = jvmtiFunctions().GetCurrentThread().invoke(jvmtiEnv(), threadPtr);
if (error == JvmtiError.JVMTI_ERROR_WRONG_PHASE) {
return nullHandle();
}
check(error);
return threadPtr.read();
}

@CEntryPoint
@CEntryPointOptions(prologue = AgentIsolate.Prologue.class)
private static void onNativeMethodBind(@SuppressWarnings("unused") JvmtiEnv jvmti, JNIEnvironment jni,
Expand Down

0 comments on commit 63a4415

Please sign in to comment.