RFR: 8289613: Drop use of Thread.stop in jshell

Jan Lahoda jlahoda at openjdk.org
Mon Sep 5 14:38:19 UTC 2022


On Mon, 5 Sep 2022 12:39:41 GMT, Adam Sotona <asotona at openjdk.org> wrote:

> LocalExecutionControl in jdk.jshell actually uses Thread::stop to cancel execution of (long-running or infinite loops) user code in JShell, however Thread::stop is deprecated and planned for removal.
> 
> Proposed patch instruments all user code to call LocalExecutionControl::stopCheck method before every branch instruction.
> Thread::stop call is replaced by setting global field LocalExecutionControl.allStop to true and stopCheck method then throws ThreadDead when called from the instrumented code.
> 
> Proposed patch requires jdk.jshell access to java.base jdk.internal.org.objectweb.asm package. 
> 
> Please review.
> 
> Thanks,
> Adam

I believe that one instance of JShell will use only once instance of `ExecutionControl` at one time (although if it fails, it may spawn a new one). But there may be multiple instances of JShell at one time, so I suspect the static field on `LocalExecutionControl` won't work. I apologize for not realizing this sooner.

I think one way to resolve this is, for every `LocalExecutionControl` instance, synthesize a class, possibly named `REPL.$Cancel$`, which would hold the `allStop` field and the `stopCheck` method. This would then be load using the `LocalExecutionControl`'s `LoaderDelegate`, and used by the snippet.

A positive side-effect of this would be that we wouldn't need a new method in the public API, which I think would be preferred.

-------------

PR: https://git.openjdk.org/jdk/pull/10166


More information about the core-libs-dev mailing list