RFR: 8257837: Performance regression in heap byte buffer views

Maurizio Cimadamore mcimadamore at openjdk.java.net
Thu Dec 10 13:20:47 UTC 2020


As a result of the recent integration of the foreign memory access API, some of the buffer implementations now use `ScopedMemoryAccess` instead of `Unsafe`. While this works generally well, there are situations where profile pollution arises, which result in a considerable slowdown. The profile pollution occurs because the same ScopedMemoryAccess method (e.g. `getIntUnaligned`) is called with two different buffer kinds (e.g. an off heap buffer where base == null, and an on-heap buffer where base == byte[]). Because of that, unsafe access cannot be optimized, since C2 can't guess what the unsafe base access is.

In reality, this problem was already known (and solved) elsewhere: the sun.misc.Unsafe wrapper does basically the same thing that ScopedMemoryAccess does. To make sure that profile pollution does not occur in those cases, argument profiling is enabled for sun.misc.Unsafe as well. This patch adds yet another case for ScopedMemoryAccess.

Here are the benchmark results:

Before:

Benchmark                                            Mode  Cnt  Score   Error  Units
LoopOverPollutedBuffer.direct_byte_buffer_get_float  avgt   30  0.612 ? 0.005  ms/op
LoopOverPollutedBuffer.heap_byte_buffer_get_int      avgt   30  2.740 ? 0.039  ms/op
LoopOverPollutedBuffer.unsafe_get_float              avgt   30  0.504 ? 0.020  ms/op

After

Benchmark                                            Mode  Cnt  Score   Error  Units
LoopOverPollutedBuffer.direct_byte_buffer_get_float  avgt   30  0.613 ? 0.007  ms/op
LoopOverPollutedBuffer.heap_byte_buffer_get_int      avgt   30  0.304 ? 0.002  ms/op
LoopOverPollutedBuffer.unsafe_get_float              avgt   30  0.491 ? 0.004  ms/op

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

Commit messages:
 - Add argument profiling for ScopedMemoryAccess

Changes: https://git.openjdk.java.net/jdk/pull/1733/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=1733&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8257837
  Stats: 121 lines in 3 files changed: 120 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/1733.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/1733/head:pull/1733

PR: https://git.openjdk.java.net/jdk/pull/1733


More information about the core-libs-dev mailing list