super constructor of abstract value classes

Daniel Schmid daniel at wwwmaster.at
Tue Aug 22 17:57:52 UTC 2023


Hi again,

First of all, thank you very much for your response, Remi. It really 
cleared up a few things for me.

> I'm not sure you have fully understand the restriction about the 
> constructor of a value class.

I made the wrong assumption that this was mainly about having multiple 
copies of the value object in multiple states and not about leaking 
this. Thanks for clearing that up.

> The current idea is that we do not need to change the actual verifier rules attached to invokespecial (see page 305 ofhttps://docs.oracle.com/javase/specs/jvms/se20/jvms20.pdf) because we do not allow an invokespecial to occur inside the constructor of a value class (unlike the constructor of an identity class) so the verifier ensures that the constructor of a value class can not leak "this" for free.
I understand the reasoning to not allow any actions in super 
constructors because that would require changing the verifier rules.
Nevertheless, I think this is a pretty strong restriction.
According to the document, it is required that "the no-argument 
constructor takes no action" in order to receive the "special marking" 
that it can be used as a super constructor of value classes.
I feel like the requirement for that marking could be relaxed a bit by 
saying that "the no-argument constructor is not allowed to use the 
this-reference except for setting fields" (and is also not allowed to 
call other methods) similar to essentially the same restriction required 
for "normal" object before the "super()" call in the constructor.

If I understood that correctly, it would be possible to mark a 
constructor as "trivial" (so that it can be used as a super constructor 
of value classes) in case the same requirements than the ones before the 
super() call of other constructors are met (and maybe also allow setting 
fields of the parent class).

Or is this also too much of an increase of complexity for only a small 
gain? Because I feel like essentially not allowing the constructor to do 
anything is a big loss.

Thank you for listening,
Daniel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4490 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20230822/23102e50/smime.p7s>


More information about the valhalla-dev mailing list