On Fri, 8 May 2026 18:43:52 GMT, Serguei Spitsyn <[email protected]> wrote:
>> On a behavioral level, I wonder how you are deciding which locals are `this` >> variables; like what happens if somebody copies `this` into local slot 3? >> >> It may make more sense to say and implement: >> >>> When preview features are enabled, if the frame's method is a value class >>> constructor >>> and the requested local is a value object, the value_ptr is set to a >>> snapshot of the >>> value object. > >> On a behavioral level, I wonder how you are deciding which locals are this >> variables; like what happens if somebody copies this into local slot 3? > > Good question. There is no check for this corner case now. > >> It may make more sense to say and implement: > > Good suggestion with one correction. We do not want to snapshot any local > value object but only `this` object which is under construction. > > What about this? : > > When preview features are enabled, the frame's method is a value class > constructor and the requested local is a "<code>this</code>" value object, > the > value_ptr is set to a snapshot of the "<code>this</code>" object. I'll let Serguei clarify, but here's what I found. The logic to decide if a snapshot (clone) is needed can be found in this diff (from the PR that implemented this support): https://github.com/openjdk/valhalla/pull/2363/changes#diff-41730062a596d5a0b6b2330022428347b22d71d1a654af76e9959be7a75f65fcR642 My read on this is that if you are in a constructor, accessing local 0 (this), and the current frame's method is for a value class, then the snapshot will be done. That would mean when executing in the Number constructor, this snapshot behavior would apply even if a BigInteger is being constructed. This seems to be consistent with what is done at the language level (not allowing "this" to escape from the Number constructor, even when constructing a BigInteger). Now my question is, what about when executing in the BigInteger constructor? Even though it is not a value type, it appears java does not allow escape of "this", presumably because it extends a value type. If we are going to do the same in JVMTI, we would need to do some extra checks of the inheritance, but I don't think there is actually any harm in JVMTI exposing "this" of BigInteger before the Number constructor is executed since it is actually an identity object. ------------- PR Review Comment: https://git.openjdk.org/valhalla/pull/2412#discussion_r3210686121
