super constructor of abstract value classes

Remi Forax forax at univ-mlv.fr
Tue Aug 22 13:41:47 UTC 2023


----- Original Message -----
> From: "Daniel Schmid" <daniel at wwwmaster.at>
> To: "valhalla-dev" <valhalla-dev at openjdk.org>
> Sent: Tuesday, August 22, 2023 10:57:30 AM
> Subject: super constructor of abstract value classes

> Hi,

Hi Daniel,

> 
> When reading the recent article that explains how Q-descriptors and
> v-bytecodes are not needed
> (https://cr.openjdk.org/~jrose/values/larval-values.html), I came across
> 
> > To avoid such ambiguities, we forbid calling the superclass <init>
> method.
> 
> This seems like a pretty strong restriction though I understand why it's
> in place.
> Nevertheless, it raises a question when I am reading this:
> If it is possible to create abstract value classes (i.e. abstract
> classes where all subclasses are value classes), is this restriction
> really necessary for that case?

It is possible if the super class is marked as "value only" with ACC_VALUE but in that case it has no field (and its superclasses must have no field too).

> Since the superclass would "know" its subclasses are value classes,
> can't the object be copied, modified in the super constructor (the one
> of the abstract value class) before all fields are copied back when
> continuing with the constructor of the concrete value class?
> Or are there just no "abstract value classes" or do you want to keep the
> same restrictions on all kind of abstract classes for consistency?

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

The current idea is that we do not need to change the actual verifier rules attached to invokespecial (see page 305 of https://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.

If an invokespecial to the super class can occurs inside a value class constructor, then we have to change the verifier rules after the call to super(), the current rules allow to leak "this", but this is something we do not want for a value class given that the instance is still in larval state. 

As Brian said, it may be possible to relax the verifier rules but the gain is small compare to the complexity of modifying those rules. The verifier rules have bitten several of us in the past so we know that tweaking them will requires many engeneering cycles and we have better things to do.

> 
> Yours,
> Daniel

regards,
Rémi



More information about the valhalla-dev mailing list