On Tue, 26 May 2026 23:38:23 GMT, Phil Race <[email protected]> wrote:
>> I think for each postEvent we should call getSystemEventQueueImplPP at some
>> point to have a queue to post events?
>
> No postEvent() did not do this.
> Hndreds of tests failed without this being added.
> There appear to be many code paths where only the appcontext initialization
> caused the EQ to be initialized. Some of them looked almost accidental like a
> call to insertTargetMapping(..) from XSelection triggered the app context
> creation which started the EQ. Quite a few tests failed on Linux when that
> call to insertTargetMapping(..) was removed.
> Overall this is why this ended up being the last change.
>
> So this is the simplest necessary change.
AFAICS, we can get into a situation where a posted event is silently ignored if
the event EQ has not been initialized by that point.
Previously, we always had AppContext initialized when `postEvent()` was called,
correct me if I am wrong.
> In postEvent() itself was the only other option that worked but then it is
> checked every time an event is posted.
We can make the check relatively cheap in `postEvent()`, for example:
PostEventQueue eq = postEventQueue; // volatile read
if (eq == null) {
initEQ(); // call synchronized method only when necessary
eq = postEventQueue;
}
eq.postEvent(event);
---
Regardless of whether we implement this change in `postEvent()`, we can apply
the same optimization in `getSystemEventQueueImplPP()` to avoid calling a
synchronized method every time:
public static EventQueue getSystemEventQueueImplPP() {
EventQueue eq = currentEventQueue;
if (eq == null) {
initEQ();
eq = currentEventQueue;
}
return eq;
}
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/31262#discussion_r3307983695