On Mon, 5 Sep 2022 12:39:41 GMT, Adam Sotona <asot...@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've checked the code, same question as Alan, i believe you can have multiple 
instances of LocalExecutionControl, but `allStop` is a global flag.

Usually, the way to get an instance at runtime is either to use a ClassValue on 
the generated class or to store the instance in a ClassLoader and several one 
class loaders.
The last option is to pass an instance when defining a class, it only works 
with hidden classes, not normal classes but that code can be changed in the JDK.

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

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

Reply via email to