Hello,

Please review fix for JDK9.

Bug: https://bugs.openjdk.java.net/browse/JDK-6980209#comment-13623256
Webrev: http://cr.openjdk.java.net/~alexsch/semyon-sadetsky/6980209/webrev.00/

***The root cause:
There are 2 issues in WaitDispatchSupport:
1. If exit() is called before the secondary loop just silently never ends. That is pointed in the summary. 2. In the same spec it is proposed to call exit() and enter() concurrently but they are not thread-safe. That is an additional issue.

To fix 1: I support Artem's proposal for enter() to return false immidiately in case if disordered exit() detected. To fix 2: WaitDispatchSupport need to be reworked to allow concurrent execution. Unfortunately we cannot synchronize EDT with another thread, so the secondary loop launching cannot be run atomically. And this is very sensitive area because of potential possibility to block EDT. Right testing of the fix is very desirable.

***Solution description:
1. User immediately get false as result of enter() if it is detected that exit() has been run either before or concurrently. For that purpose a new AtomicBoolean field prematureExit is introduced. 2. The exit() and enter() are reworked to be capable to run concurrently and avoid EDT jam in the secondary loop. See comments to the code for details.

***Testing:
Test launches the secondary loop upon a button press action triggered by the Robot and simultaneously call exit() in a separate thread. The Robot sends a big number of events (number is adjustable by ATTEMPTS constant) to cover different concurrent states randomly. Along with that the Robot sends a number of key events to ensure that UI is kept responsive and all events are dispatched by EDT. The number of the sent key events is tested to be equal to the number of processed events. The test is run in different modes to test secondary loop launching from EDT and non-EDT threads.

--Semyon

Reply via email to