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

The session/scope fixes on the downcall handler in multithreading #15749

Conversation

ChengJin01
Copy link
Contributor

The changes aim to resolve the issues specific to session/scope
detected in jtreg tests to ensure the session/scopes are kept
alive for the owner thread in the native invocation in the
multithreading environment.

Signed-off-by: Cheng Jin jincheng@ca.ibm.com

@ChengJin01
Copy link
Contributor Author

ChengJin01 commented Aug 18, 2022

The fixes include the following changes with a little polished code in modification to resolve the session/scope specific
issues detected in jtreg tests:
[1] added the code with sessionOrScopeSet to ensure the session/scope of each memory related argument is kept
alive for the current thread for the same downcall handler in the multithreading environment (SafeFunctionAccessTest.java)
[2] modified the code specific to the downcall function address as well as the returned struct MemorySegment to ensure
they are only owned by the currrent thread for the same downcall handler in the multithreading environment in JDK17/18/19+ (LibraryLookupTest.java & TestUpcallAsync.java).

The following failing jtreg tests in JDK17/18/19 passed with this PR and no other issue was detected:
https://github.com/ibmruntimes/openj9-openjdk-jdk19/blob/openj9/test/jdk/java/foreign/LibraryLookupTest.java
https://github.com/ibmruntimes/openj9-openjdk-jdk19/blob/openj9/test/jdk/java/foreign/TestUpcallAsync.java
https://github.com/ibmruntimes/openj9-openjdk-jdk19/blob/openj9/test/jdk/java/foreign/SafeFunctionAccessTest.java (excluding VaList tests)
https://github.com/ibmruntimes/openj9-openjdk-jdk18/blob/openj9/test/jdk/java/foreign/SafeFunctionAccessTest.java (excluding VaList tests)
https://github.com/ibmruntimes/openj9-openjdk-jdk17/blob/openj9/test/jdk/java/foreign/SafeFunctionAccessTest.java (no VaList related test)

@ChengJin01
Copy link
Contributor Author

Reviewer: @tajila
FYI: @gacholio, @pshipton, @DanHeidinga

@ChengJin01 ChengJin01 force-pushed the fix_ffi_downcall_handler_session_jtreg_tests branch from b506b82 to 5caee06 Compare August 18, 2022 18:34
@ChengJin01 ChengJin01 requested a review from tajila August 18, 2022 18:34
@ChengJin01
Copy link
Contributor Author

@tajila, any comment on this PR?

@@ -43,6 +43,7 @@ public class DowncallLinker {
* @return a method handle bound to the native method
*/
public static MethodHandle getBoundMethodHandle(MethodType functionMethodType, FunctionDescriptor funcDesc) {
return InternalDowncallHandler.getBoundMethodHandle(functionMethodType, funcDesc);
InternalDowncallHandler internalDowncallHandler = new InternalDowncallHandler(functionMethodType, funcDesc);
Copy link
Contributor

Choose a reason for hiding this comment

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

can this just be return new InternalDowncallHandler(functionMethodType, funcDesc).getBoundMethodHandle(); ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed and updated here plus the same in ProgrammableInvoker.java as suggested above.

The changes aim to resolve the issues specific to session/scope
detected in jtreg tests to ensure the session/scopes are kept
alive for the owner thread in the native invocation in the
multithreading environment.

Signed-off-by: Cheng Jin <jincheng@ca.ibm.com>
@ChengJin01 ChengJin01 force-pushed the fix_ffi_downcall_handler_session_jtreg_tests branch from 5caee06 to 683a3a1 Compare September 21, 2022 15:20
@tajila
Copy link
Contributor

tajila commented Sep 21, 2022

jenkins test sanity zlinux jdk19

@tajila tajila merged commit b00315b into eclipse-openj9:master Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants