How to observe a flat array?

Cay Horstmann cay.horstmann at gmail.com
Sat May 25 16:58:48 UTC 2024


I just tried the following after building https://github.com/openjdk/valhalla:

@ImplicitlyConstructible
@LooselyConsistentValue
value record Point(double x, double y) {
    public Point transform() {
       return new Point(x + Math.random() - 0.5, y + Math.random() - 0.5);
    }
}

public class Points {
    static int NPOINTS = 100_000_000;

    public static void main(String[] args) {
       Point[] path = (Point[]) ValueClass.newNullRestrictedArray(Point.class, NPOINTS);
       for (int i = 1; i < path.length; i++) {
          path[i] = path[i - 1].transform();
       }
       System.out.println(path[path.length - 1]);
       
       try {
          Thread.sleep(60_000);
       } catch (Exception e) {
          e.printStackTrace();
       }
    }
}

Running jcmd withvalhalla.Points GC.class_histogram shows

  num     #instances         #bytes  class name (module)
-------------------------------------------------------
    1:     100000000     3200000000  withvalhalla.Point
    2:             1      400000016  [Lwithvalhalla.Point;

That doesn't look like a flattened array, but like an array with NPOINTS references. Do I need to wait for the JIT to kick in? Or is this not yet implemented?

Thanks,

Cay

--

Cay S. Horstmann | https://horstmann.com


More information about the valhalla-spec-observers mailing list