JDK-8319111 : Mismatched MemorySegment heap access is not consistently intrinsified
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-10-30
  • Updated: 2024-08-01
  • Resolved: 2023-12-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 22
22 b27Fixed
Related Reports
Blocks :  
Relates :  
Description
The performance of load and store operations from a heap `MemorySegment` backed by various array types varies substantially with the Vector type.

Generally, load and store operations on vector type X are performant if performed on a `MemorySegment` backed by an array of X or a byte array.

Here are some benchmark results from the micro-benchmark class `TestLoadSegmentVarious`.

```
Benchmark                                                   (size)  Mode  Cnt     Score     Error  Units
TestLoadSegmentVarious.byteVectorFromByteBackedSegment        1024  avgt   10   280.008 ?   7.251  ns/op
TestLoadSegmentVarious.byteVectorFromDoubleBackedSegment      1024  avgt   10  1304.008 ?  98.901  ns/op
TestLoadSegmentVarious.byteVectorFromIntBackedSegment         1024  avgt   10  1279.621 ? 100.008  ns/op
TestLoadSegmentVarious.doubleVectorFromByteBackedSegment      1024  avgt   10    37.281 ?   1.360  ns/op
TestLoadSegmentVarious.doubleVectorFromDoubleBackedSegment    1024  avgt   10    36.847 ?   0.130  ns/op
TestLoadSegmentVarious.doubleVectorFromIntBackedSegment       1024  avgt   10   194.195 ?  31.096  ns/op
TestLoadSegmentVarious.intVectorFromByteBackedSegment         1024  avgt   10    72.602 ?   1.768  ns/op
TestLoadSegmentVarious.intVectorFromDoubleBackedSegment       1024  avgt   10   166.851 ?   9.528  ns/op
TestLoadSegmentVarious.intVectorFromIntBackedSegment          1024  avgt   10    71.283 ?   0.507  ns/op
TestLoadSegmentVarious.scalarByteVectorFromByteSegment        1024  avgt   10  4790.084 ?  45.882  ns/op
TestLoadSegmentVarious.scalarByteVectorFromDoubleSegment      1024  avgt   10  4841.273 ? 291.962  ns/op
TestLoadSegmentVarious.scalarByteVectorFromIntSegment         1024  avgt   10  4794.028 ? 101.282  ns/op
TestLoadSegmentVarious.scalarDoubleVectorFromByteSegment      1024  avgt   10  1241.117 ?  11.603  ns/op
TestLoadSegmentVarious.scalarDoubleVectorFromDoubleSegment    1024  avgt   10  1245.752 ?  15.516  ns/op
TestLoadSegmentVarious.scalarDoubleVectorFromIntSegment       1024  avgt   10  1232.216 ?   8.365  ns/op
TestLoadSegmentVarious.scalarIntVectorFromByteSegment         1024  avgt   10  1239.146 ?  14.582  ns/op
TestLoadSegmentVarious.scalarIntVectorFromDoubleSegment       1024  avgt   10  1236.712 ?   8.063  ns/op
TestLoadSegmentVarious.scalarIntVectorFromIntSegment          1024  avgt   10  1228.656 ?   3.329  ns/op
```

A log of methods being/not being intrinsified can be obtained by running the test `IntrinsicHeapTest` and observing the standard output.  Excerpt:

```
  ** not supported: arity=0 op=load vlen=1 etype=long ismask=no
                                      @ 28   jdk.internal.vm.vector.VectorSupport::load (38 bytes)   failed to inline: failed to inline (intrinsic)
                                  @ 3   jdk.internal.misc.Unsafe::loadFence (5 bytes)   (intrinsic)
                                      @ 28   jdk.internal.vm.vector.VectorSupport::load (38 bytes)   (intrinsic)
                                  @ 3   jdk.internal.misc.Unsafe::loadFence (5 bytes)   (intrinsic)
  ** not supported: arity=0 op=load vlen=4 etype=long ismask=no
                                      @ 28   jdk.internal.vm.vector.VectorSupport::load (38 bytes)   failed to inline: failed to inline (intrinsic)
                                  @ 3   jdk.internal.misc.Unsafe::loadFence (5 bytes)   (intrinsic)
  ** not supported: arity=0 op=load vlen=8 etype=long ismask=no
                                      @ 28   jdk.internal.vm.vector.VectorSupport::load (38 bytes)   failed to inline: failed to inline (intrinsic)
                                  @ 3   jdk.internal.misc.Unsafe::loadFence (5 bytes)   (intrinsic)
                                      @ 28   jdk.internal.vm.vector.VectorSupport::load (38 bytes)   (intrinsic)
                                  @ 3   jdk.internal.misc.Unsafe::loadFence (5 bytes)   (intrinsic)
```
Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/16888 Date: 2023-11-29 17:49:45 +0000
01-08-2024

Changeset: 2678e4cd Author: Jatin Bhateja <jbhateja@openjdk.org> Date: 2023-12-06 09:58:06 +0000 URL: https://git.openjdk.org/jdk/commit/2678e4cd9424ca4e33ebb9693c84f9a86bf5504c
06-12-2023

[~thartmann] Thanks for heads up, I am working on this issue.
29-11-2023

[~jbhateja] do you still plan to fix this in JDK 22 or should we defer?
27-11-2023