Superclasses with fields
Remi Forax
forax at univ-mlv.fr
Mon Aug 21 18:58:40 UTC 2023
> From: "Brian Goetz" <brian.goetz at oracle.com>
> To: "valhalla-spec-experts" <valhalla-spec-experts at openjdk.java.net>
> Sent: Monday, August 21, 2023 6:39:26 PM
> Subject: Fwd: Superclasses with fields
> The below was received on the valhalla-spec-comments list.
> The topic of further relaxing the restrictions on abstract class supertypes of
> value classes has been discussed by the EG. While it is possible that such
> restrictions could be further relaxed, we are likely facing diminishing
> returns.
> It is certainly possible to define a way that fields and initialization logic
> from an abstract super is "copied" into the value class. But this would still
> come with restrictions we might not like; we would then either have to give up
> putting fields in the value subclass (to eliminate layout polymorphism), or
> give up flattening of the abstract class type (because there is layout
> polymorphism.) And, we would likely end up creating a new category of abstract
> class to support the "pushing down" of fields and initialization, which is new
> language complexity. Overall this seems like something that has a relatively
> weak return-on-complexity and there are many opportunities for much higher
> return right now.
I will add that in case of an enum, it's not clear that a "value enum" make sense in term of performance.
The number of instances of an enum is fixed, and because there are all initialized one after the other, there are all in the same memory page so the actual representation is already very cache friendly.
Rémi
> -------- Forwarded Message --------
> Subject: Superclasses with fields
> Date: Mon, 21 Aug 2023 08:03:58 -0300
> From: Thiago Henrique Hupner [ mailto:thihup at gmail.com | <thihup at gmail.com> ]
> To: [ mailto:valhalla-spec-comments at openjdk.org |
> valhalla-spec-comments at openjdk.org ]
> Now that most of the migration issues from classes to value classes have been
> discovered, would it also be possible to allow maybe a subset of superclasses
> that contains some fields?
> Probably having "value enums" would be great, but also it would enable to have
> subclasses of j.u.AbstractList to also become value classes.
> Probably there are more issues to it than I could remember, but wouldn't it be
> possible to check at load time if the superclass uses some unsupported
> features, like synchronized methods, and throw an error?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-observers/attachments/20230821/64f09d8e/attachment-0003.htm>
More information about the valhalla-spec-observers
mailing list