Flattening large atomic objects inside frozen arrays
Brian Goetz
brian.goetz at oracle.com
Sat Apr 8 19:15:18 UTC 2023
> On Apr 7, 2023, at 1:31 PM, Piotr Tarsa <piotr.tarsa at gmail.com> wrote:
>
> Hi,
>
> In thread "B3, default values, and implicit initialization"
> https://mail.openjdk.org/pipermail/valhalla-spec-observers/2023-March/002206.html
> there are following statements about optimizations related to value
> classes:
>
>> Framed this way, the Valhalla performance story simplifies to:
>> - Give up identity, get flattening on the stack;
>> - Further give up explicit initialization, get flattening for small objects on the heap;
>> - Further give up atomicity, get flattening for larger objects on the heap.
>
> The optimizations are all driven by definition site attributes of a
> class (whether it is an identity class, has optional constructor, is
> atomic, etc - according to current terminology at least), so there is
> no flexibility at use site.
This is not entirely true. Giving up explicit initialization requires both a declaration-site opt in (what had been called “primitive classes” in a prior draft) and a use-site opt-in (what had been called X.val in the prior draft.). Both are needed for flattening.
In any case, I think you may be misinterpreting this “simplified decoder chart” as saying “there is no way any flattening can occur if these conditions are not met.” The JVM has many tricks at its disposal, but the goal of Valhalla is to make it practical for users to write code that they can reasonably expect will be routinely flattened.
> There could be a possibility to enable flattening optimizations at use
> site too. "JEP draft: Frozen Arrays (Preview)"
Quite possible (and possibly also final fields.).
More information about the valhalla-spec-comments
mailing list