[foreign-memaccess+abi] RFR: 8278151: Heap segments should handle alignment constraints in a deterministic fashion [v2]

Radoslaw Smogura duke at openjdk.java.net
Thu Dec 2 18:35:33 UTC 2021


On Thu, 2 Dec 2021 18:11:48 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Hmm...
>> 
>> I wonder a bit if this code can be optimized `if (((address | maxAlignMask) & alignmentMask) != 0) {`
>> 
>> Max `maxAlignMask`, can be 1,2,4 (if I see it correctly) so if `maxAlignMask` `alignmentMask` and will not be correct, than exception will be thrown regardless of address? I wonder if making static check could be more performant as VM move such check before loop, than we could only focus on `address & alignmentMask != 0`. Or something like this.
>
> The max align check is already moved out of the loop (as it only depends on the segment, which is a loop invariant). The problematic check, which is not moved outside the loop is exactly `address & alignmentMask != 0`. That check cannot be hoisted, because `address` is made up of `offset` and the segment base address; the latter is a loop invariant, but the former isn't.
> 
> Of course C2 should be able to detect that offset is a function of the loop variable, and prove that the check can never fail - but this pattern is currently not detected (hence JDK-8277850).

Yes, I was thinking about line 125 `if (((address | maxAlignMask) & alignmentMask) != 0) {` to split into to two
`if ((maxAlignMask & alignmentMask) != 0) throw...` and `if (address & alignmentMask) != 0) throw...` if this could help a bit.

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

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


More information about the panama-dev mailing list