-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8335392: C2 MergeStores: enhanced pointer parsing #19970
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
Conversation
|
👋 Welcome back epeter! A progress list of the required criteria for merging this PR into |
|
@eme64 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: 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 32 new commits pushed to the
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 |
|
@eme64 this pull request can not be integrated into git checkout JDK-8335392-MemPointer
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
Co-authored-by: Christian Hagedorn <[email protected]>
chhagedorn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some final last mostly minor comments but otherwise, it looks good to me now! I like the summaries and how you worked out the proofs. They are now easy to understand.
test/hotspot/jtreg/compiler/c2/TestMergeStoresMemorySegment.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Christian Hagedorn <[email protected]>
Co-authored-by: Christian Hagedorn <[email protected]>
|
/contributor add chhagedorn You spent enough time on this already ;) |
|
@eme64 Syntax:
User names can only be used for users in the census associated with this repository. For other contributors you need to supply the full name and email address. |
|
/contributor add @chhagedorn |
|
@eme64 |
Thanks Emanuel, I highly appreciate that :-) |
|
@chhagedorn I filed https://bugs.openjdk.org/browse/JDK-8343536 to track the cases in |
|
@chhagedorn I addressed all your review suggestions. Thank you very much for the in-depth review :) |
chhagedorn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good, thanks for the patience to work through all the suggestions and also for the offline discussions!
|
@vnkozlov Would you like to re-review? If I don't hear anything then I'll integrate tomorrow. |
vnkozlov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update is good.
|
Thanks @chhagedorn for the extensive reviews and collaboration on improving the proofs 😊 I did an offline merge and testing (to avoid requiring a re-approval) - all looks good. /integrate |
|
Going to push as commit f3671be.
Your commit was automatically rebased without conflicts. |
|
@eme64 How do I use the TraceMergeStores option? It worked before, but now it gives an error. build/macosx-aarch64-server-fastdebug/jdk/bin/java -Dtest=appendNullLatin1 -XX:+TraceMergeStoresoutput |
|
@wenshao Ah, good question! I changed it from a "global" flag to a "compile option". You can now filter the methods! And you can enable different tags - so you can regulate how verbose it is. Example: And to see all available tags: You might have to play around a little to see what is helpful to you. And I'm always open to feedback :) |
|
Currently, TraceMergeStores can only be used in fastdebug images. Are you planning to support it in release images? |
I generally don't support it in release builds, only debug - or rather Does that make sense? |
|
If it is not provided in the release image, users need to find the source code of the current version of JDK to build the fastdebug image to analyze whether the MergeStore optimization of a certain code works. I can understand that MergeStore may still need to be improved, so it cannot be used as a product feature, but this is a useful optimization and I hope it can be provided in the product eventually. I hope that TraceMergeStore can eventually be used in the release image like |
|
@wenshao I suppose we could consider making |
Background
I am introducing the
MemPointer, for enhanced pointer parsing. For now, it replaces the much more limitedArrayPointerinMergeStores(see #16245), but eventually it is supposed to be used widely in optimizations for pointer analysis: adjacency, aliasing, etc. I also plan to refactor theVPointerfrom auto-vectorization with it, and unlock more pointer patterns that way - possibly including scatter/gather.Details
The
MemPointerdecomposes a pointer into the formpointer = con + sum_i(scale_i * variable_i)- a linear form with a sum of variables and scale-coefficients, plus some constant offset.This form allows us to perform aliasing checks - basically we can check if two pointers are always at a constant offset. This allows us to answer many questions, including if two pointers are adjacent.
MergeStoresneeds to know if two stores are adjacent, so that we can safely merge them.More details can be found in the description in
mempointer.hpp. Please read them when reviewing!MemPointeris more powerful than the previousArrayPointer: the latter only allows arrays, the former also allows native memory accesses,UnsafeandMemorySegement.What this change enables
Before this change, we only allowed merging stores to arrays, where the store had to have the same type as the array element (
StoreBonbyte[],StoreIonint[]).Now we can do:
Unsafestores to array. Including "mismatched size": e.g.putChartobyte[].Unsafestores to native memory.MemorySegment: with array, native, ByteBuffer backing types.MemorySegmentintroducecheckIndexL, the long-variant of the RangeCheck. Normal array accesses only use the equivalent ofcheckIndex, the int-variant that we already optimize away much better.Dealing with Overflows
We have to be very careful with overflows when dealing with pointers. For this, I introduced a
NoOverflowInt. It allows us to do "normal" int operations on it, and tracks if there was ever an overflow. This way, we can do all overflow checks implicitly, and do not clutter the code with overflow-checks or - God forbid - forget overflow-checks.Benchmarks
I added a few new benchmarks, to show the merging of
Unsafeandnativestores. We an see that 8 byte stores are now merged, and have the same performance as a long store. The same for 4 char stores that are merged into a single long store.And here the whole
MergeStoresbenchmark,masterand withpatch:All old benchmarks remain in the level of noise. A few have heavy errors - the benchmark ran on my laptop and maybe something slowed down for a bit. We can see the significant speedup with all the
unsafebenchmarks at the bottom.This is great, now we can perform
putChareven onbyte[]. This was an issue we discovered in this PR #19626.Progress
Issue
Reviewers
Contributors
<[email protected]>Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19970/head:pull/19970$ git checkout pull/19970Update a local copy of the PR:
$ git checkout pull/19970$ git pull https://git.openjdk.org/jdk.git pull/19970/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19970View PR using the GUI difftool:
$ git pr show -t 19970Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19970.diff
Using Webrev
Link to Webrev Comment