Most recent JEP 401 description

Brian Goetz brian.goetz at oracle.com
Sun May 19 00:21:34 UTC 2024


Amazingly, yes, value-capable abstract classes can have fields.  We 
thought for many years this would never be possible; the Great 
Initialization Alignment (eliminating `vnew` and `withfield` in favor of 
the `new` and `putfield` approach) made this possible.

The language imposes no restrictions on the number of fields of value 
types.  The VM reserves the right to flatten, or not, based on its 
whims.  One likely whim is that "large" values are usually not worth 
flattening.  But this is invisible to the user; the semantics are the 
same whether or not the object is flattened.

On 5/18/2024 1:24 PM, John Bossons wrote:
> Thanks for making this so very clear.
>
> Two questions/issues:
> (1) It would be helpful to include more on the properties of abstract 
> value classes (AVCs) -- perhaps a labelled subsection? A specific 
> question not dealt with explicitly in the current version: Can an AVC 
> have an instance field, now that a value class utilizes the 
> Flexible Constructor Bodies JEP? (The alternative is  repetition of 
> that field definition and accessor in every subtype, which is 
> potentially error-prone).
> (2) It would also be helpful to include some commentary on limitations.
> Specifically, although it is clear that the purpose is more 
> efficiently defined SMALL value objects, (a) How big is 'small'? And 
> (b) will the compiler accept value types of any size, no matter how deep?
>
> John
>
>
> Phone:  (416) 450-3584 (cell)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20240518/e87de956/attachment.htm>


More information about the valhalla-dev mailing list