-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8287788: Implement a better allocator for downcalls #23142
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
8287788: Implement a better allocator for downcalls #23142
Conversation
Hi @mernst-github, welcome to this OpenJDK project and thanks for contributing! We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user mernst-github" as summary for the issue. If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing |
@mernst-github 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 119 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. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@JornVernee, @mcimadamore) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
@mernst-github The following label will be automatically applied to this pull request:
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. |
@mernst-github this pull request can not be integrated into git checkout mernst/cache-segments
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 |
# Conflicts: # src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java
/label remove core-libs |
@mernst-github |
@mernst-github
|
/label core-libs |
@mernst-github |
Should really just protect the CTL handling. alloc/free should happen outside (even if it practically doesn't matter)
no need to recreate these simplifies code and no longer needs @ForceInlining
Careful massaging to get scalar replacement. Triggers fastdebug assertion, though.
The |
I think it's the stress test, the starting Thread sleeps and never gets rescheduled because it's starved out by the others. I can repro. Need to strategically place yields or interrupt the competitors. |
Maybe the number of iterations could be capped? |
Thanks for the fix, I'll submit another CI job |
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.
Tests came back green. I think this is good to go.
Thanks, looks ready to me, too. This is my first contribution - as far as I understand, any further concerns can still be voiced between '/integrate' and '/sponsor', so I'll go ahead 😱 /integrate |
@mernst-github |
/sponsor |
Going to push as commit 8cc1304.
Your commit was automatically rebased without conflicts. |
@JornVernee @mernst-github Pushed as commit 8cc1304. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Thanks a lot for the fine work!! |
Sorry to say, but the implementation seems to have a bug that is causing occasional heap corruption, which is being caught by mac's malloc guards. Since this is failing in tier 1, and the issue seems like it will take some time to investigate and fix, I'm backing out the change for now. |
As to what's causing the issue, I wonder if the stack buffer is being freed while it is still in use, somehow. We reinterpret the segment from the shared arena, maybe the frame should keep that arena alive until it is closed itself (with a |
Thanks for the backout. That's java/foreign/TestBufferStack.java, let me try if I can force anything to repro. |
Tried for a few hours to repro with various approaches, to no avail. |
It should be possible to reproduce on either an x64 or AArch64 mac machine using:
It will take a while to run/fail. The failure seems to be detected by the |
P.S. I have not tried this yet, but some of the malloc debugging flags available on mac may help trigger this faster: https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html |
@mernst-github We have investigated this issue further, and have narrowed it down to an issue with malloc/free. See: https://bugs.openjdk.org/browse/JDK-8350455 At this point, I think it's safe to try and re-integrate this patch, but the Note that we already have an issue to redo this patch: https://bugs.openjdk.org/browse/JDK-8349146 Is that something you'd be interested in taking on? |
Certain signatures for foreign function calls (e.g. HVA return by value) require allocation of an intermediate buffer to adapt the FFM's to the native stub's calling convention. In the current implementation, this buffer is malloced and freed on every FFM invocation, a non-negligible overhead.
Sample stack trace:
To alleviate this, this PR implements a per carrier-thread stacked allocator.
Performance (MBA M3):
-prof gc
also shows that the new call path is fully scalar-replaced vs 160 byte/call before.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23142/head:pull/23142
$ git checkout pull/23142
Update a local copy of the PR:
$ git checkout pull/23142
$ git pull https://git.openjdk.org/jdk.git pull/23142/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 23142
View PR using the GUI difftool:
$ git pr show -t 23142
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23142.diff
Using Webrev
Link to Webrev Comment