RFR: 8359131: JShell AbstractStopExecutionTest does not stop reliably

Aleksey Shipilev shade at openjdk.org
Tue Jun 10 16:07:34 UTC 2025


On Tue, 10 Jun 2025 14:24:15 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

> The JShell regression test support class `AbstractStopExecutionTest.java` provides code that starts a JShell evaluation in one thread and then invokes `JShell.stop()` to interrupt that evaluation from another thread.
> 
> This class uses a `boolean` field to synchronize the action between threads. However, this field is not marked `volatile` and so the communication is unreliable. As a result, in rare cases, the test can fail due to a timeout.
> 
> The simple fix is to make the field `volatile`. This has been verified in testing to resolve the problem (see discussion in [JDK-8355323](https://bugs.openjdk.org/browse/JDK-8355323)).

Really confusing how `volatile` helps here. There are three accesses to `isStopped`:
 1. `isStopped = false;` initially in this thread
 2. `isStopped` checks in separate threads.
 3. `isStopped = true;` in this thread

(2) and (3) are done under `synchronized(lock)`. `Thread.start` synchronizes-with the `Thread.run`, so passing `false` (1) to separate threads (2) should work. These two should be enough to maintain correctness.

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

PR Review: https://git.openjdk.org/jdk/pull/25730#pullrequestreview-2914242450


More information about the kulla-dev mailing list