Skip to content

Commit

Permalink
Merge pull request #16446 from ChengJin01/ffi_remove_push_special_fra…
Browse files Browse the repository at this point in the history
…me_upcall_dispatcher_v0.36.0

[FFI/0.36] Remove PUSH_OBJECT_IN_SPECIAL_FRAME in the upcall dispatcher
  • Loading branch information
pshipton committed Dec 10, 2022
2 parents 7a33a8b + f2153cd commit c585ea5
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private long getUpcallThunkAddr(MethodHandle target, ResourceScope sessionOrScop
* is only alive for a MemorySession(JDK19)/ResourceScope(JDK17/18) specified in java, which means the upcall handler
* and its UpcallMHMetaData object will be cleaned up automatically once their session/scope is closed.
*/
metaData = new UpcallMHMetaData(target, sessionOrScope);
metaData = new UpcallMHMetaData(target, argLayoutCount, sessionOrScope);
return allocateUpcallStub(metaData, nativeSignatureStrs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ final class UpcallMHMetaData {
* by MethodHandleResolver.upcallLinkCallerMethod().
*/
private Object[] invokeCache;
/* The argument array stores the memory specific argument(struct/pointer) object
* being allocated in native for upcall to stop GC from updating the previously
* allocated argument reference when allocating the next argument.
*/
private Object[] nativeArgArray;

/*[IF JAVA_SPEC_VERSION >= 19]*/
private MemorySession session;
Expand All @@ -68,21 +73,22 @@ final class UpcallMHMetaData {
}

/*[IF JAVA_SPEC_VERSION >= 19]*/
UpcallMHMetaData(MethodHandle targetHandle, MemorySession session)
UpcallMHMetaData(MethodHandle targetHandle, int nativeArgCount, MemorySession session)
/*[ELSE] JAVA_SPEC_VERSION >= 19 */
UpcallMHMetaData(MethodHandle targetHandle, ResourceScope scope)
UpcallMHMetaData(MethodHandle targetHandle, int nativeArgCount, ResourceScope scope)
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
{
calleeMH = targetHandle;
calleeType = targetHandle.type();
nativeArgArray = new Object[nativeArgCount];
/* Only hold the confined session/scope (owned by the current thread)
* will be used to construct a MemorySegment object for argument in
* the native dispatcher in upcall.
* or the shared session/scope will be used to construct a MemorySegment
* object for argument in the native dispatcher in upcall.
*/
/*[IF JAVA_SPEC_VERSION >= 19]*/
this.session = ((session != null) && (session.ownerThread() != null)) ? session : null;
this.session = ((session != null) && (session.ownerThread() != null)) ? session : MemorySession.openShared();
/*[ELSE] JAVA_SPEC_VERSION >= 19 */
this.scope = ((scope != null) && (scope.ownerThread() != null)) ? scope : null;;
this.scope = ((scope != null) && (scope.ownerThread() != null)) ? scope : ResourceScope.newSharedScope();
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
}
}
2 changes: 2 additions & 0 deletions runtime/oti/vmconstantpool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<fieldref class="openj9/internal/foreign/abi/UpcallMHMetaData" name="calleeMH" signature="Ljava/lang/invoke/MethodHandle;" flags="opt_openjdkFfi" versions="16-"/>
<fieldref class="openj9/internal/foreign/abi/UpcallMHMetaData" name="calleeType" signature="Ljava/lang/invoke/MethodType;" flags="opt_openjdkFfi" versions="16-"/>
<fieldref class="openj9/internal/foreign/abi/UpcallMHMetaData" name="invokeCache" signature="[Ljava/lang/Object;" flags="opt_openjdkFfi" versions="16-"/>
<fieldref class="openj9/internal/foreign/abi/UpcallMHMetaData" name="nativeArgArray" signature="[Ljava/lang/Object;" flags="opt_openjdkFfi" versions="16-"/>

<fieldref class="openj9/internal/foreign/abi/UpcallMHMetaData" name="scope" signature="Ljdk/incubator/foreign/ResourceScope;" flags="opt_openjdkFfi" versions="16-18"/>
<fieldref class="openj9/internal/foreign/abi/UpcallMHMetaData" name="session" signature="Ljava/lang/foreign/MemorySession;" flags="opt_openjdkFfi" versions="19-"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ OutOfLineINL_openj9_internal_foreign_abi_UpcallMHMetaData_resolveUpcallDataField
J9JavaVM *vm = currentThread->javaVM;
J9ConstantPool *jclConstantPool = (J9ConstantPool *)vm->jclConstantPool;
#if JAVA_SPEC_VERSION >= 18
const int cpEntryNum = 8;
#else /* JAVA_SPEC_VERSION >= 18 */
const int cpEntryNum = 9;
#else /* JAVA_SPEC_VERSION >= 18 */
const int cpEntryNum = 10;
#endif /* JAVA_SPEC_VERSION >= 18 */
U_16 cpIndex[cpEntryNum] = {
J9VMCONSTANTPOOL_OPENJ9INTERNALFOREIGNABIUPCALLMHMETADATA_CALLEEMH,
J9VMCONSTANTPOOL_OPENJ9INTERNALFOREIGNABIUPCALLMHMETADATA_CALLEETYPE,
J9VMCONSTANTPOOL_OPENJ9INTERNALFOREIGNABIUPCALLMHMETADATA_INVOKECACHE,
J9VMCONSTANTPOOL_OPENJ9INTERNALFOREIGNABIUPCALLMHMETADATA_NATIVEARGARRAY,
#if JAVA_SPEC_VERSION >= 19
J9VMCONSTANTPOOL_OPENJ9INTERNALFOREIGNABIUPCALLMHMETADATA_SESSION,
#else /* JAVA_SPEC_VERSION >= 19 */
Expand Down
Loading

0 comments on commit c585ea5

Please sign in to comment.