Skip to content

Commit

Permalink
Replace ProgrammableInvoker (downcall) on X86_64 & Aarch64
Browse files Browse the repository at this point in the history
The change is to replace the ProgrammableInvoker in OpenJDK with
the equivalent in OpenJ9 to handle the CLinker downcall to the C
function on X86_64 (Linux & Windows) and Linux/Aarch64.

Note: the change depend on the code in OpenJ9
at eclipse-openj9/openj9#12413

Signed-off-by: Cheng Jin jincheng@ca.ibm.com
  • Loading branch information
Cheng Jin committed May 20, 2021
1 parent b5df00f commit dce003b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
1 change: 1 addition & 0 deletions closed/OpenJ9.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ $(foreach file, \
bcuwhite \
bcvrelationships \
bcvwhite \
clinkerffitests \
gptest \
hooktests \
j9aixbaddep \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2021, 2021 All Rights Reserved
* ===========================================================================
*/

package jdk.internal.foreign.abi.aarch64;

import jdk.incubator.foreign.Addressable;
Expand Down Expand Up @@ -126,15 +133,9 @@ public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, bool
return new Bindings(csb.build(), returnInMemory);
}

/* Replace ProgrammableInvoker in OpenJDK with the implementation of ProgrammableInvoker specific to OpenJ9 */
public static MethodHandle arrangeDowncall(Addressable addr, MethodType mt, FunctionDescriptor cDesc) {
Bindings bindings = getBindings(mt, cDesc, false);

MethodHandle handle = new ProgrammableInvoker(C, addr, bindings.callingSequence).getBoundMethodHandle();

if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc);
}

MethodHandle handle = ProgrammableInvoker.getBoundMethodHandle(addr, mt, cDesc);
return handle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
* questions.
*
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2021, 2021 All Rights Reserved
* ===========================================================================
*/

package jdk.internal.foreign.abi.x64.sysv;

import jdk.incubator.foreign.Addressable;
Expand Down Expand Up @@ -123,16 +130,9 @@ public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, bool
return new Bindings(csb.build(), returnInMemory, argCalc.storageCalculator.nVectorReg);
}

/* Replace ProgrammableInvoker in OpenJDK with the implementation of ProgrammableInvoker specific to OpenJ9 */
public static MethodHandle arrangeDowncall(Addressable addr, MethodType mt, FunctionDescriptor cDesc) {
Bindings bindings = getBindings(mt, cDesc, false);

MethodHandle handle = new ProgrammableInvoker(CSysV, addr, bindings.callingSequence).getBoundMethodHandle();
handle = MethodHandles.insertArguments(handle, handle.type().parameterCount() - 1, bindings.nVectorArgs);

if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc);
}

MethodHandle handle = ProgrammableInvoker.getBoundMethodHandle(addr, mt, cDesc);
return handle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2021, 2021 All Rights Reserved
* ===========================================================================
*/

package jdk.internal.foreign.abi.x64.windows;

import jdk.incubator.foreign.Addressable;
Expand Down Expand Up @@ -124,15 +131,9 @@ void setReturnBindings(Class<?> carrier, MemoryLayout layout) {
return new Bindings(csb.csb.build(), returnInMemory);
}

/* Replace ProgrammableInvoker in OpenJDK with the implementation of ProgrammableInvoker specific to OpenJ9 */
public static MethodHandle arrangeDowncall(Addressable addr, MethodType mt, FunctionDescriptor cDesc) {
Bindings bindings = getBindings(mt, cDesc, false);

MethodHandle handle = new ProgrammableInvoker(CWindows, addr, bindings.callingSequence).getBoundMethodHandle();

if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc);
}

MethodHandle handle = ProgrammableInvoker.getBoundMethodHandle(addr, mt, cDesc);
return handle;
}

Expand Down

0 comments on commit dce003b

Please sign in to comment.