Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8318678: Vector access on heap MemorySegments only works for byte[] #16360

Closed
wants to merge 4 commits into from

Conversation

minborg
Copy link
Contributor

@minborg minborg commented Oct 25, 2023

This PR proposes removing the restriction that only heap MemorySegment wrapping a byte array can be accessed by Vectors. Now any array type can be used provided the element alignment constraints are respected.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8318956 to be approved

Issues

  • JDK-8318678: Vector access on heap MemorySegments only works for byte[] (Bug - P3)
  • JDK-8318956: Vector access on heap MemorySegments only works for byte[] (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16360/head:pull/16360
$ git checkout pull/16360

Update a local copy of the PR:
$ git checkout pull/16360
$ git pull https://git.openjdk.org/jdk.git pull/16360/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16360

View PR using the GUI difftool:
$ git pr show -t 16360

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16360.diff

Webrev

Link to Webrev Comment

@minborg
Copy link
Contributor Author

minborg commented Oct 25, 2023

/csr

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 25, 2023

👋 Welcome back pminborg! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added rfr Pull request is ready for review csr Pull request needs approved CSR before integration labels Oct 25, 2023
@openjdk
Copy link

openjdk bot commented Oct 25, 2023

@minborg has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@minborg please create a CSR request for issue JDK-8318678 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@openjdk
Copy link

openjdk bot commented Oct 25, 2023

@minborg The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Oct 25, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 25, 2023

Webrevs

@merykitty
Copy link
Member

Vector loads and stores are always unaligned, so I don't see the value in forcing the alignment of accesses.

Copy link
Member

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcimadamore
Copy link
Contributor

On a second look, I agree with the comments. Logically, the vector API is accessing elements using JAVA_XYZ_UNALIGNED layouts, which should always succeed. E.g. no alignment exception should ever be possible when doing unaligned access, regardless of whether the segment is on/off heap.

@PaulSandoz
Copy link
Member

PaulSandoz commented Oct 26, 2023

We also need to review the intrinsic for load/store found here to ensure, when the hardware supports it, that mixed access is optimized:

https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/vectorIntrinsics.cpp#L967

I recommend writing a simple benchmark with various forms of mixed access and verify the intrinsics kick in (longer term IR tests would be preferable).

@minborg
Copy link
Contributor Author

minborg commented Oct 30, 2023

Here is a test showing there is a need to improve performance for certain combinations of load operations. It is likely, the same is true for store operations.

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

As can be seen, vector performance for IntVector and DoubleVector is good for operations from a byte array or where the array types match.

This work can be made under a separate issue.


import static org.testng.Assert.*;

public class IntrinsicHeapTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this test as part of this PR. It's useful ascertain what is intrinsic or not. We can rethink it as part of the following fix if needed to verify the intrinsics work across all the cross product of array types and vector types.

Copy link
Member

@PaulSandoz PaulSandoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Please remove IntrinsicHeapTest and let's follow up in another issue/PR to fix the mismatched heap access not being intrinsic.

@openjdk
Copy link

openjdk bot commented Nov 6, 2023

@minborg This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8318678: Vector access on heap MemorySegments only works for byte[]

Reviewed-by: chegar, mcimadamore, psandoz

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 170 new commits pushed to the master branch:

  • cdf3373: 8319316: Clarify text around which layouts a linker supports
  • 1696603: 8308453: Convert JKS test keystores in test/jdk/javax/net/ssl/etc to PKCS12
  • b3126b6: 8319455: Test compiler/print/CompileCommandMemLimit.java times out
  • 1c2ea1d: 8319153: Fix: Class is a raw type in ProcessTools
  • 96e6e67: 4365952: Cannot disable JFileChooser
  • 2d4bbf4: 8319465: Typos in javadoc of com.sun.management.OperatingSystemMXBean methods
  • 8fb94fd: 8319379: G1: gc/logging/TestUnifiedLoggingSwitchStress.java crashes after JDK-8318894
  • b5c863b: 8316533: C2 compilation fails with assert(verify(phase)) failed: missing Value() optimization
  • 377138c: 8318959: C2: define MachNode::fill_new_machnode() statically
  • c146685: 8319165: hsdis binutils: warns on empty string as option string
  • ... and 160 more: https://git.openjdk.org/jdk/compare/08f79148c6607bf2fce3710f112313e29c05ea90...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels Nov 6, 2023
@minborg
Copy link
Contributor Author

minborg commented Nov 7, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Nov 7, 2023

Going to push as commit 74f1889.
Since your change was applied there have been 174 commits pushed to the master branch:

  • e1cae72: 8319197: Exclude hb-subset and hb-style from compilation
  • 419ed90: 8319450: New methods java.net.InetXAddress.ofLiteral() miss @SInCE tag
  • 439ed04: 8319233: AArch64: Build failure with clang due to -Wformat-nonliteral warning
  • e4803e0: 8318580: "javax/swing/MultiMonitor/MultimonVImage.java failing with Error. Can't find library: /open/test/jdk/java/awt/regtesthelpers" after JDK-8316053
  • cdf3373: 8319316: Clarify text around which layouts a linker supports
  • 1696603: 8308453: Convert JKS test keystores in test/jdk/javax/net/ssl/etc to PKCS12
  • b3126b6: 8319455: Test compiler/print/CompileCommandMemLimit.java times out
  • 1c2ea1d: 8319153: Fix: Class is a raw type in ProcessTools
  • 96e6e67: 4365952: Cannot disable JFileChooser
  • 2d4bbf4: 8319465: Typos in javadoc of com.sun.management.OperatingSystemMXBean methods
  • ... and 164 more: https://git.openjdk.org/jdk/compare/08f79148c6607bf2fce3710f112313e29c05ea90...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 7, 2023
@openjdk openjdk bot closed this Nov 7, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 7, 2023
@openjdk
Copy link

openjdk bot commented Nov 7, 2023

@minborg Pushed as commit 74f1889.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
5 participants