ArrayStoreException: bug or expected behavior?

Tobias Hartmann tobias.hartmann at oracle.com
Fri Jul 26 11:54:45 UTC 2019


On 26.07.19 13:32, Michael Hoffer wrote:
> A follow-up question: the following code automatically translates Point2D into Point2D?. Is this
> assumption correct?

It does not translate Point2D to Point2D? but simply allocates the inline type on the Java heap and
stores a reference to it in the interface array.

> Does this mean that the reduction in required memory and the cache optimal
> layout are lost in this case?

If you are referring to the memory layout of a flattened array Point2D[] then yes, these are not
available with your interface array.

In memory terms, this creates an array of pointers:

>         Point2DI[] points = new Point2DI[n];

And the following loop stores pointers to Point2D into that array:

>         for(int i = 0; i < points.length;i++) {
>             points[i] = new Point2D(i, i);
>         }

Other than memory layout, one of the biggest optimization opportunities for inline types is that
they can always be scalarized by the just in time compiler (i.e. passed in registers or on the stack).

Hope that helps.

Best regards,
Tobias


More information about the valhalla-dev mailing list