Recently [JDK-8305511](https://bugs.openjdk.org/browse/JDK-8305511) removed the 
"@ignore 6951287 ", allowing this test to run, which is why this failure mode 
is now turning up.

There is a race condition, leading to the `popFrames()` call being done while a 
native method is in the set of frames to be popped. This results in a 
`NativeMethodException` instead of the frames being popped. The debuggee has:


    public static void waiter() {
        if (waiting) {
            return;
        }
        waiting = true;
        System.out.println(" debuggee: in waiter");
        while (true) {
        }
    }


And the debugger waits for `waiting == true` (checked via JDI calls) before 
suspending and doing the `popFrames()`. The problem is the println() after 
setting `waiting = true`. The debugger side can detect that `waiting == true` 
before the println() is complete, and the println() involves native code. Once 
`waiting` is set true, we need to make sure no other method calls are made so 
we can be sure that only the `waiter()` method is on the stack.

Note there is a lot of interesting history to this CR, including 
[JDK-6417053](https://bugs.openjdk.org/browse/JDK-6417053), which actually 
reproduced this issue long ago (but got closed as CNR), although it failed with 
a different error message (even though it was the same issue), and the 
different error message was itself the result of another bug that was 
inadvertently fixed when virtual threads support was added to JDI. See the CR 
for details if you are interested.

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

Commit messages:
 - Move println to before setting the waiting flag

Changes: https://git.openjdk.org/jdk/pull/13657/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=13657&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8306705
  Stats: 3 lines in 1 file changed: 2 ins; 1 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/13657.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/13657/head:pull/13657

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

Reply via email to