how passing value types will work?

Chen Liang liangchenblue at gmail.com
Mon Oct 20 04:11:30 UTC 2025


Good question. The latest valhalla spec is as non-invasive as possible: we
are still passing a value representing the reference pointer to an
immutable value object, which is identical to a copy of the values. This
will be the case for JEP 401, Value Objects.

Ideally, we want the reference to where the values are in memory to be
usable, given this is the most memory-efficient representation. This is
largely equivalent to a copy of the values given value objects are
immutable, except they are different when a value object is stored in a
mutable field in an identity object. In such cases, we may observe a "tear"
when we read the reference to the memory location, meaning we can observe a
value object that was composed from the result of different writes due to
instruction reordering and CPU caches.

We currently prototype to allow such inconsistency to happen by declaring a
value object as "loosely consistent", so all value object instance in the
cartesian product of all legal individual field values are all legal and
expected by programs.


On Sun, Oct 19, 2025 at 7:51 PM david Grajales <david.1993grajales at gmail.com>
wrote:

> Java always passes by value. When someone passes a primitive to a method
> it passes a copy of the value of the primitive, when one pass a reference
> type what is really being passed it's a copy of the "value" of the object
> (just happens to be the value of an object is its reference)
>
> When a value object (let's say a value record) is being passed to a
> method, does it pass a copy of the values or a reference to where the
> values are in memory?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20251019/238fb145/attachment.htm>


More information about the valhalla-dev mailing list