Updated specs for Value Classes

Remi Forax forax at univ-mlv.fr
Tue Sep 30 06:21:49 UTC 2025



----- Original Message -----
> From: "daniel smith" <daniel.smith at oracle.com>
> To: "valhalla-spec-experts" <valhalla-spec-experts at openjdk.java.net>
> Sent: Saturday, September 27, 2025 12:57:53 AM
> Subject: Updated specs for Value Classes

> Please see these spec change documents, revised to align with current plans for
> the Value Classes and Objects JEP.
> 
> https://cr.openjdk.org/~dlsmith/jep401/jep401-20250926/specs/value-objects-jls.html
> https://cr.openjdk.org/~dlsmith/jep401/jep401-20250926/specs/value-objects-jvms.html
> 
> I've also revised the JEP in the last couple of months, which you can view here:
> 
> https://openjdk.org/jeps/401
> 
> Some highlights:
> 
> - Clarified the presentation of how == works, with extensive discussion in the
> JEP
> - Instance fields can be both written and read in early construction

Hello Dan,
this one seems too clever for me.

I find that it make it hard to explain how things work apart from explaining the cleverness.
First, even without this feature, the fact that this.x = x is allowed but not IO.println(this)
is already a challenged to explain correctly.

Now, we can write IO.println(this.x) but still not IO.println(this),
I do not know how to explain that without explaining the trick the compiler does.

Also, the trick starts to break when by example lambdas or inner classes are involved

value class Point {
  private final double x, y;

  Point(double x, double y) {
    this.x = x;
    IO.println(this.x);
    var lambda = (DoubleSupplier) () -> this.x;
    var innerClass = new DoubleSupplier() {
      @Override
      public double getAsDouble() {
        return this.x;   // BTW Point.this.x raises a different error ??
      }
    };
    this.y = y;
    super();
  }
}

For me, we are going a step too far here, yes it's convenient but it makes the semantics is more blurry.


> - Record classes adopt the same early construction behavior as value classes
> - Memory model rules to ensure correct values are read from value and record
> class fields (and, eventually, other strict fields)
> - New verifier rules disallowing acmp/ifnull on uninitialized types
> 
> A linked JVMS document covers the Strict Field Initialization JEP, although I
> still have some work to do to refresh and polish that one.


regards,
Rémi


More information about the valhalla-spec-experts mailing list