|
41 | 41 | * <ol> |
42 | 42 | * <li>{@code init()}: captures the current {@link Context} and an {@link ContextContinuation} to |
43 | 43 | * prevent the enclosing context scope from completing early. |
44 | | - * <li>{@code run(Runnable)}: seeds the virtual thread's saved context once and retains its state |
45 | | - * in the continuation frame across park/unpark cycles. |
| 44 | + * <li>On JDK 22 and later, {@code run(Runnable)} seeds the virtual thread's saved context once |
| 45 | + * and retains its state in the continuation frame across park/unpark cycles. |
46 | 46 | * <li>{@code mount()} / {@code unmount()}: rebind and clear carrier-local profiler context. The |
47 | | - * state-backed swap path is retained when context listeners require per-mount notification. |
| 47 | + * state-backed swap path is retained on JDK 21 and when context listeners require per-mount |
| 48 | + * notification. |
48 | 49 | * <li>{@code afterDone()} / {@code afterTerminate()} for early VirtualThread support: cancels the |
49 | 50 | * help continuation, releasing the context scope to be closed. |
50 | 51 | * </ol> |
51 | 52 | * |
52 | | - * <p>{@code run(Runnable)} is the one-shot continuation body and executes after the first mount, |
53 | | - * when the current thread is the virtual thread. Its advice local is preserved with the |
54 | | - * continuation across yields. {@code runContinuation()} cannot serve this purpose because it |
55 | | - * executes once per mount and starts while the carrier is still the current thread. |
| 53 | + * <p>On JDK 22 and later, {@code run(Runnable)} is the one-shot continuation body and executes |
| 54 | + * after the first mount, when the current thread is the virtual thread. Its advice local is |
| 55 | + * preserved with the continuation across yields. {@code runContinuation()} cannot serve this |
| 56 | + * purpose because it executes once per mount and starts while the carrier is still the current |
| 57 | + * thread. JDK 21 retains the per-mount path because this internal ordering differs across its |
| 58 | + * update releases. |
56 | 59 | * |
57 | 60 | * @see VirtualThreadState |
58 | 61 | */ |
@@ -104,9 +107,11 @@ public Map<String, String> contextStore() { |
104 | 107 | @Override |
105 | 108 | public void methodAdvice(MethodTransformer transformer) { |
106 | 109 | transformer.applyAdvice(isConstructor(), getClass().getName() + "$Construct"); |
107 | | - transformer.applyAdvice( |
108 | | - isMethod().and(named("run")).and(takesArguments(Runnable.class)).and(returns(void.class)), |
109 | | - getClass().getName() + "$Run"); |
| 110 | + if (JavaVirtualMachine.isJavaVersionAtLeast(22)) { |
| 111 | + transformer.applyAdvice( |
| 112 | + isMethod().and(named("run")).and(takesArguments(Runnable.class)).and(returns(void.class)), |
| 113 | + getClass().getName() + "$Run"); |
| 114 | + } |
110 | 115 | transformer.applyAdvice(isMethod().and(named("mount")), getClass().getName() + "$Mount"); |
111 | 116 | transformer.applyAdvice(isMethod().and(named("unmount")), getClass().getName() + "$Unmount"); |
112 | 117 | transformer.applyAdvice( |
|
0 commit comments