[foreign-memaccess+abi] RFR: Prevent maxAlign virtual calls for polluted accesses [v2]

Radoslaw Smogura duke at openjdk.org
Mon Aug 8 16:14:27 UTC 2022


On Mon, 8 Aug 2022 09:27:37 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Radoslaw Smogura has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Previous version created performance drop for `LoopOverNonConstantHeap` benchamrk, this fixes this and keeps same results for tests with vectors.
>
> src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java line 326:
> 
>> 324:     // Helper methods
>> 325: 
>> 326:     @ForceInline
> 
> When adding `maxAlign` I have played with something similar as what you have done. My recollection is that doing this doesn't 100% solve the issue, as it's possible to have polluted profile for `maxAlignMask` (e.g. the JVM will bias the method implementation towards the 1-2 layouts that seem to be more common, and put everything else in an uncommon branch). Maybe what you see is that, since the virtual call is gone, there is still a net gain.
> 
> Does the problem only manifest with bulk copy? Or also with plain memory access? If the former, perhaps some other inlining issue with bulk copy (which is a big method) could be at play.

I just checked it with vector operations only, there's check in `ScopedMemoryAccess` `loadFromMemorySegment` which checks max align in case of polluted access this will create polymorphic call.

- However when I look right now I think there's second option. Instead of changing `maxAlign`, the check in `loadFromMemorySegment`, could be replaced by checking if segment instance is native or `Bytes`.?

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

PR: https://git.openjdk.org/panama-foreign/pull/700


More information about the panama-dev mailing list