[lworld] RFR: 8351569: [lworld] Revisit atomic access modes in flat var handles

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Mar 20 11:18:27 UTC 2025


On Thu, 20 Mar 2025 11:11:40 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This PR is an attempt to put var handle support for flat values on a more solid footing. Some more notes in a comment below.
>
> src/java.base/share/classes/java/lang/invoke/VarHandles.java line 311:
> 
>> 309:             // do not check for atomicity now -- atomicity will be checked on the accessed array object
>> 310:             // a sharper var handle will be obtained (dynamically) from flatArrayElementHandleFor(Object)
>> 311:             return maybeAdapt(new VarHandleReferences.Array(aoffset, ashift, arrayClass));
> 
> Note: this works because:
> * the reference Array plain access uses array syntax (which works no matter the array passed in)
> * non-plain access modes always delegate to sharper var handles based on the type of the accessed array

Another note: at the language level there's no mechanism to obtain a class mirror for a null-restricted, or atomic array. This means we can't really create an array var handle that works only on one array shape (which would allow us to eliminate the dynamic dispatch completely, at least for some array var handles).

-------------

PR Review Comment: https://git.openjdk.org/valhalla/pull/1402#discussion_r2005370591


More information about the valhalla-dev mailing list