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

8336768: Allow captureCallState and critical linker options to be combined #22327

Closed
wants to merge 5 commits into from

Conversation

JornVernee
Copy link
Member

@JornVernee JornVernee commented Nov 22, 2024

Allow captureCallState and critical(true) linker options to be combined. This allows passing a Java array to capture call state.

One caveat is that the linker expects the memory to be aligned, which means that at least an int[] has to be used (i.e. byte[] will no work).

This patch contains two implementations: one for the linkers that use CallingSequenceBuilder. That one is quite straight-forward, as we can just mimic what we already do for other memory segment arguments, but also for the capture state segment. i.e. split it into base and offset, and pass that down to our downcall stub. The stub will then add the offset and oop together, and pass use the resulting address to write to.

The other implementation is for the fallback linker. This handles the capture state a little differently, but essentially currently just passes the native address to the back end for the native code to write the captured state into. I've just added another heap base parameter for that capture state segment to the back end, which is then turned into a native address using JNI's GetPrimitiveArrayCritical, similarly to what we do for other heap segments.

Testing: jdk_foreign test suite.


Progress

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

Issues

  • JDK-8336768: Allow captureCallState and critical linker options to be combined (Enhancement - P3)
  • JDK-8345106: Allow captureCallState and critical linker options to be combined (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22327

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 22, 2024

👋 Welcome back jvernee! 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
Copy link

openjdk bot commented Nov 22, 2024

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

8336768: Allow captureCallState and critical linker options to be combined

Reviewed-by: mcimadamore

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 168 new commits pushed to the master branch:

  • 68b1b94: 8344904: Interned strings in old classes are not stored in CDS archive
  • 1997e89: 8345346: Shenandoah: Description of ShenandoahGCMode still refers to incremental update mode
  • 3a3bcd5: 8344800: Add W3C DTDs and XSDs to the JDK built-in Catalog
  • 940aa7c: 8344397: Remove Security Manager dependencies from java.security and sun.security packages
  • 3d0d0e6: 8345012: os::build_agent_function_name potentially wastes a byte when allocating the buffer
  • 525f33b: 8345324: Update comment in SourceVersion for language evolution history for changes in 24
  • d6a5f1b: 8344768: Consider removing "sun.security.krb5.autodeducerealm" system property
  • 7c944ee: 8345172: x86: Some CPU feature asserts are declared as 32-bit only
  • 67f18cc: 8345142: Remove uses of SecurityManager in Printing related classes
  • 352201d: 8343788: Provide means to alter lib/tzmappings entries on Windows
  • ... and 158 more: https://git.openjdk.org/jdk/compare/82c3612d775840aa4b851a29b8ee3337950d5aeb...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
Copy link

openjdk bot commented Nov 22, 2024

@JornVernee 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 Nov 22, 2024
if (invData.capturedStateMask() != 0) {
capturedState = SharedUtils.checkCaptureSegment((MemorySegment) args[argStart++]);
if (!invData.allowsHeapAccess) {
SharedUtils.checkNative(capturedState);
Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed that this check was missing in the fallback linker, and we were actually crashing when a heap segment was passed as the capture state segment. I've added a new test case that checks that this works as well.

@JornVernee JornVernee marked this pull request as ready for review November 27, 2024 11:26
@JornVernee
Copy link
Member Author

/csr

@openjdk openjdk bot added rfr Pull request is ready for review csr Pull request needs approved CSR before integration labels Nov 27, 2024
@openjdk
Copy link

openjdk bot commented Nov 27, 2024

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

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

@mlbridge
Copy link

mlbridge bot commented Nov 27, 2024

Webrevs

if (methodType.parameterType(0) != long.class) {
throw new AssertionError("Address expected as first param: " + methodType);
}
int checkIdx = 1;
if ((needsReturnBuffer && methodType.parameterType(checkIdx++) != long.class)
|| (savedValueMask != 0 && methodType.parameterType(checkIdx) != long.class)) {
|| (savedValueMask != 0 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this routine is getting too complex and it would be better to split the checks (and add some comments) ? E.g. we need to check that if there's a return buffer, a certain low-level argument is long and, if there's need to capture state, we either have long, or an Object,long pair.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps, even throwing different assertion error might help

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah... I'll split this up a bit to make it more readable.

@@ -195,6 +195,10 @@ public boolean needsTransition() {
return !linkerOptions.isCritical();
}

public boolean usingAddressPairs() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Copyright years

@@ -90,10 +90,11 @@ private static boolean tryLoadLibrary() {
* @see jdk.internal.foreign.abi.CapturableState
*/
static void doDowncall(MemorySegment cif, MemorySegment target, MemorySegment retPtr, MemorySegment argPtrs,
MemorySegment capturedState, int capturedStateMask,
Object captureStateHeapBase, MemorySegment capturedState, int capturedStateMask,
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it a bit weird that this method is receiving both the captured segment base and the segment itself. It almost seems as if the checks we do in FallbackLinker should be done here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see what you mean, and I agree it looks a bit strange. but we also pass the array of heap bases separately here (which is more or less a forced move due to how the libffi API works). So, I think the current code is more inline with that. The LibFallback class is only supposed to be a thin wrapper around the native methods in fallbackLinker.c. The actual logic is all in FallbackLinker.

Copy link
Contributor

@mcimadamore mcimadamore 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 - left some minor comments

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels Dec 2, 2024
@JornVernee
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 3, 2024

Going to push as commit 8cad043.
Since your change was applied there have been 185 commits pushed to the master branch:

  • 63af2f4: 8344414: ZGC: Another division by zero in rule_major_allocation_rate
  • 077b842: 8345074: java.net.InterfaceAddress constructor could be made private
  • ec93cc5: 8343932: Error when parsing qualified generic type test pattern in switch
  • c330b90: 8343780: Add since checker tests to the Tools area modules and add missing @SInCE to jdk.jfr
  • 8dada73: 8345120: A likely bug in StringSupport::chunkedStrlenShort
  • 659f70b: 8343418: Unnecessary Hashtable usage in CSS.htmlAttrToCssAttrMap
  • 5c8cb2e: 8337199: Add jcmd Thread.vthread_scheduler and Thread.vthread_pollers diagnostic commands
  • 3eb5461: 8343791: Socket.connect API should document whether the socket will be closed when hostname resolution fails or another error occurs
  • 4ac2e47: 8343800: Cleanup definition of NULL_WORD
  • a3b58ee: 8339983: [s390x] secondary_super_cache does not scale well: C1 and interpreter
  • ... and 175 more: https://git.openjdk.org/jdk/compare/82c3612d775840aa4b851a29b8ee3337950d5aeb...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 3, 2024

@JornVernee Pushed as commit 8cad043.

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

@JornVernee JornVernee deleted the Critical+Capture branch December 3, 2024 12:32
@dmlloyd
Copy link
Contributor

dmlloyd commented Dec 3, 2024

I've already tested this and it works great. Thanks!

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
Development

Successfully merging this pull request may close these issues.

4 participants