[foreign-memaccess] RFR: 8249879: Split MemorySegment and MemoryAddress [v3]

Henry Jen henryjen at openjdk.java.net
Fri Jul 24 19:22:01 UTC 2020


On Wed, 22 Jul 2020 23:41:25 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/invoke/X-VarHandleMemoryAccess.java.template line 107:
>> 
>>> 106:                 throw MemoryAccessVarHandleBase.newIllegalStateExceptionForMisalignedAccess(address);
>>> 107:             }
>>> 108:         }
>> 
>> Seems a little odd to me, as there is no performance gain with skipOffsetCheck.
>> 
>> The else block check only address but not base and offset separately is not the same, although I think that's correct
>> as it's what matters.
>> However, if this is desired, I don't see why we don't simply check address without the difference.
>
> The final address is the sum of two components - a base B and an offset O. In a hot loop, B is typically constant (e.g.
> the base address of a segment) while O keeps changing. So, if the alignment check is only performed on B, the VM can
> prove that this check can be hoisted outside the loop. Of course that leaves the correctness problem - e.g. what if B
> is aligned but B + O is not? Luckily, by construction, this is not possible - skipOffsetCheck is only set when we
> construct a memory access var handle from a layout - and in that case the layout API make sure that the O part of the
> final address is aligned accordingly.  So, while it "looks" as if there's no performance gain, in reality the gain is
> quite big, because that move allows the alignment check to be moved outside the loop.

Thanks for the explanation

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

PR: https://git.openjdk.java.net/panama-foreign/pull/260


More information about the panama-dev mailing list