[foreign-memaccess+abi] RFR: 8311594: Avoid GlobalSession liveness check
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Jul 10 09:17:22 UTC 2023
On Fri, 7 Jul 2023 18:14:41 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> This patch overrides `checkValidStateRaw` in GlobalSession, to do nothing. The current `checkValidStateRaw` in MemorySessionImpl checks the owner thread, and liveness, which are both not needed for the global session.
>
> Since the state field is mutable, I found that the JIT can not fold away the liveness check. This has a very marginal effect on performance, but since the fix is also very non-intrusive, I think it's okay to do.
>
> I've added 2 new benchmarks that I've used to measure the difference. One measures the performance of MS::copy, and the other measures MS::get. Both use a special `ALL` segment which spans `0` to `Long.MAX_VALUE`, which means that the target address can be used as an offset when doing the accesses. This helps the bounds checks being eliminated, and makes the result of overriding `checkValidStateRaw` in GlobalSession easier to see.
>
> Here are some of the interesting numbers:
>
> Before:
>
>
> Benchmark Mode Cnt Score Error Units
> MemorySegmentCopyALL.panama_ALL_to_ALL avgt 30 7.788 ± 0.029 ns/op
> MemorySegmentCopyALL.unsafe_array_to_addr avgt 30 7.543 ± 0.018 ns/op
>
> Benchmark Mode Cnt Score Error Units
> MemorySegmentGet.segment_ALL_unaligned avgt 30 0.486 ± 0.002 ns/op
> MemorySegmentGet.unsafe avgt 30 0.398 ± 0.003 ns/op
>
>
> After:
>
>
> Benchmark Mode Cnt Score Error Units
> MemorySegmentCopyALL.panama_ALL_to_ALL avgt 30 7.571 ± 0.017 ns/op
> MemorySegmentCopyALL.unsafe_array_to_addr avgt 30 7.550 ± 0.019 ns/op
>
> Benchmark Mode Cnt Score Error Units
> MemorySegmentGet.segment_ALL_unaligned avgt 30 0.409 ± 0.002 ns/op
> MemorySegmentGet.unsafe avgt 30 0.397 ± 0.003 ns/op
src/java.base/share/classes/jdk/internal/foreign/GlobalSession.java line 74:
> 72: @ForceInline
> 73: public void checkValidStateRaw() {
> 74: // do nothing, avoid liveness check
This looks ok, although (see comments on MemorySessionImpl::checkValidStateRaw) sometimes having too many versions of this method can cause profile pollution issues (which is why we consolidated the impl at some point). I suggest trying other benchmarks, such as LoopOverPollutedXYZ
-------------
PR Review Comment: https://git.openjdk.org/panama-foreign/pull/844#discussion_r1257963606
More information about the panama-dev
mailing list