[foreign-memaccess+abi] RFR: Performance improvement to unchecked segment ofNativeRestricted [v3]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Sat Jan 16 15:34:22 UTC 2021
On Sat, 16 Jan 2021 15:11:16 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> Radoslaw Smogura has updated the pull request incrementally with one additional commit since the last revision:
>>
>> JMH Benchmarks for evaluation of `ofNativeRestricted`
>>
>> Original benchmark comparing performance of accessing
>> data using var handles vs ordinal arrays
>>
>> Modified existing benchmark `LoopOverNonConstant` to
>> see differences versus range / temporal checking & and non-checking segments.
>>
>> ```
>> Benchmark Mode Cnt Score Error Units
>> LoopOverNonConstant.BB_get avgt 30 3.885 ? 0.003 ns/op
>> LoopOverNonConstant.BB_loop avgt 30 0.229 ? 0.001 ms/op
>> LoopOverNonConstant.global_segment_get avgt 30 3.663 ? 0.006 ns/op
>> LoopOverNonConstant.global_segment_loop avgt 30 0.374 ? 0.001 ms/op
>> LoopOverNonConstant.segment_get avgt 30 5.514 ? 0.023 ns/op
>> LoopOverNonConstant.segment_loop avgt 30 0.229 ? 0.001 ms/op
>> ```
>> Not optimized `ofNativeRestricted`
>> ```
>> LoopOverNonConstant.global_segment_get avgt 30 4.126 ? 0.006 ns/op
>> LoopOverNonConstant.global_segment_loop avgt 30 0.603 ? 0.001 ms/op
>> ```
>
> test/micro/org/openjdk/bench/jdk/incubator/foreign/LoopOverNonConstant.java line 140:
>
>> 138: int res = 0;
>> 139: for (int i = 0; i < ELEM_SIZE; i ++) {
>> 140: res += (int) VH_int.get(globalRestrictedSegment, segment_addr_idx + i);
>
> This looks wrong. you are passing an absolute address to a "logical index" argument. I see that you are attempting to divide the segment address by the carrier size, and that kind offset things, but still leaves you with suboptimal performances.
If you want to access memory this way, you need a different VarHandle:
VarHandle absolute_int_VH = MemoryHandles.varHandle(int.class, ByteOrder.nativeOrder());
Or use one of the static accessors:
MemoryAccess.getIntAtOffset(globalRestrictedSegment, segment_addr_idx + i);
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/437
More information about the panama-dev
mailing list