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

8318538: Add a way to obtain a strided var handle from a layout #16272

Closed
wants to merge 3 commits into from

Conversation

mcimadamore
Copy link
Contributor

@mcimadamore mcimadamore commented Oct 19, 2023

The 21 iteration of the FFM API used to contain a method, namely ValueLayout::arrayElementVarHandle. This var handle factory was useful when accessing elements in a flat array of variable size.

In 22, this method has been removed because:

  • It was not general enough (it only worked with value layouts)
  • A more useful/general version could be obtained with the following code:
MethodHandles.collectCoordinates(varHandle(elements), 1, scaleHandle());

Given that accessing variable-length array is rather common, and given that combining var handles is perceived as hard, we noticed that developers often tried to workaround by creating a sequence layout of maximal size, and then deriving a var handle from it. This feels suboptimal (as a new layout is created just so that we can select from it, and using this layout for anything else will likely lead to exceptions, because of its size).

For these reasons, we would like to expose this functionality as a new method in the MemoryLayout interface, namely MemoryLayout::arrayElementVarHandle. This method generalizes the old method in the 21 API, and is implemented in the obvious way, using a combinator (see above).

This PR also adds a lot of narrative text to describe how to deal with variable-length arrays, which should clarify the role of the new method.


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-8318539 to be approved

Issues

  • JDK-8318538: Add a way to obtain a strided var handle from a layout (Enhancement - P3)
  • JDK-8318539: Add a way to obtain a strided var handle from a layout (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16272

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 19, 2023

👋 Welcome back mcimadamore! 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 csr Pull request needs approved CSR before integration rfr Pull request is ready for review labels Oct 19, 2023
@openjdk
Copy link

openjdk bot commented Oct 19, 2023

@mcimadamore 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 19, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 19, 2023

Webrevs

* }
* }
*
* Here, the coordinate {@code x} of subsequent point in the array are accessed using the {@code POINT_ARR_X} var
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Here, the coordinate {@code x} of subsequent point in the array are accessed using the {@code POINT_ARR_X} var
* Here, the coordinate {@code x} of subsequent points in the array is accessed using the {@code POINT_ARR_X} var

* index can be created as follows:
*
* {@snippet lang=java:
* MethodHandle scale = ValueLayout.JAVA_INT.scaleHandle(); // (long, long)long
* MethodHandle scale = ValueLayout.JAVA_INT.scaleHandle();
Copy link
Member

Choose a reason for hiding this comment

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

scale seems unused now

@openjdk
Copy link

openjdk bot commented Oct 19, 2023

@mcimadamore 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:

8318538: Add a way to obtain a strided var handle from a layout

Reviewed-by: jvernee, pminborg

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 Oct 19, 2023
@mcimadamore
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Oct 20, 2023

Going to push as commit 848ecc1.

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

openjdk bot commented Oct 20, 2023

@mcimadamore Pushed as commit 848ecc1.

💡 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
3 participants