Value objects and inheritance
Toby Reyelts
rreyelts at gmail.com
Mon May 5 19:41:12 UTC 2025
[Apologies if this is the wrong list. I was hoping to find something more
user-focused (e.g. a valhalla-users@), but this seems to be the recommended
place to ask questions. Please LMK if there's somewhere more appropriate].
I've been reading the JEPs and messing around with the early access build,
trying to create a mental model for myself about how JVMs will typically be
able to optimize value classes. It seems like a goal is effectively to be
able to dump object headers:
- no identity (no boxing/unboxing visibility, no gc)
- no synchronization
- restrictions on inheritance
etc
but this seems like it relies on the ability of the JIT to know the
concrete value of the type at runtime. E.G. if I have the method:
public void print(java.lang.Number! n) {
System.out.println(n.toString());
}
It seems that the JVM must require some kind of object header to be able to
determine the appropriate toString to dispatch to. Similarly, if I have:
class X {
Number![] nums = someNums();
}
It seems like every Number in nums must still require an object header,
because the JIT doesn't know the concrete type of said objects. Reading JEP
401 more closely, I see now that scalarization can't be supported for
supertypes:
One limitation of scalarization is that it is not typically applied to a
> variable with a type that is a *supertype* of a value class type.
Is heap flattening in the same category? Are there any optimizations that
end up working with supertypes, or is the general premise that you'll
mostly need to be working with the concrete classes for optimizations to
kick in?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20250505/0126b3f6/attachment-0001.htm>
More information about the valhalla-dev
mailing list