RFR: 8358255: Factor out boilerplate code of EventHandler properties in Scene and Window

Michael Strauß mstrauss at openjdk.org
Tue Jun 3 16:34:57 UTC 2025


On Tue, 3 Jun 2025 16:10:18 GMT, Nir Lisker <nlisker at openjdk.org> wrote:

> I've tried to do something similar for controls by replacing a lot of the anonymous classes with concrete ones. I can't find the issue/discussion right now, but Kevin measured a non-negligible increase in memory usage. I assume it's because constant folding is doable for the constants in the methods of the anonymous class, but not for the final fields in the concrete property (because they are not really final when considering reflection).
> 
> Because an application doesn't have a lot of windows and scenes, it's possible that these changes won't have detrimental effects, but I suggest measuring.

I don't think there's any constant folding here, because methods like `getName()` are not constant expressions. You can always alias a property instance dynamically by referencing, which is why the compiler can't inline the value into the calling expression.

That being said, of course the nominal class stores two additional fields that the anonymous class didn't. But it doesn't store any more than that: the name strings come from literal expressions and are therefore interned, and the event types are references to static instances.

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

PR Comment: https://git.openjdk.org/jfx/pull/1819#issuecomment-2936235353


More information about the openjfx-dev mailing list