< prev index next > src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64Linker.java
Print this page
import jdk.incubator.foreign.ForeignLinker;
import jdk.incubator.foreign.FunctionDescriptor;
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemoryLayout;
import jdk.incubator.foreign.MemorySegment;
+ import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.UpcallStubs;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
private static final MethodHandle MH_boxVaList;
static {
try {
MethodHandles.Lookup lookup = MethodHandles.lookup();
! MH_unboxVaList = lookup.findStatic(Windowsx64Linker.class, "unboxVaList",
! MethodType.methodType(MemoryAddress.class, CSupport.VaList.class));
! MH_boxVaList = lookup.findStatic(Windowsx64Linker.class, "boxVaList",
MethodType.methodType(VaList.class, MemoryAddress.class));
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
private static final MethodHandle MH_boxVaList;
static {
try {
MethodHandles.Lookup lookup = MethodHandles.lookup();
! MH_unboxVaList = lookup.findVirtual(CSupport.VaList.class, "address",
! MethodType.methodType(MemoryAddress.class));
! MH_boxVaList = lookup.findStatic(Windowsx64Linker.class, "newVaListOfAddress",
MethodType.methodType(VaList.class, MemoryAddress.class));
} catch (ReflectiveOperationException e) {
throw new ExceptionInInitializerError(e);
}
}
WinVaList.Builder builder = WinVaList.builder();
actions.accept(builder);
return builder.build();
}
- private static MethodType convertVaListCarriers(MethodType mt) {
- Class<?>[] params = new Class<?>[mt.parameterCount()];
- for (int i = 0; i < params.length; i++) {
- Class<?> pType = mt.parameterType(i);
- params[i] = ((pType == CSupport.VaList.class) ? WinVaList.CARRIER : pType);
- }
- return MethodType.methodType(mt.returnType(), params);
- }
-
- private static MethodHandle unxboxVaLists(MethodType type, MethodHandle handle) {
- for (int i = 0; i < type.parameterCount(); i++) {
- if (type.parameterType(i) == VaList.class) {
- handle = MethodHandles.filterArguments(handle, i, MH_unboxVaList);
- }
- }
- return handle;
- }
-
@Override
public MethodHandle downcallHandle(MemoryAddress symbol, MethodType type, FunctionDescriptor function) {
! MethodType llMt = convertVaListCarriers(type);
MethodHandle handle = CallArranger.arrangeDowncall(symbol, llMt, function);
! handle = unxboxVaLists(type, handle);
- return handle;
- }
-
- private static MethodHandle boxVaLists(MethodHandle handle) {
- MethodType type = handle.type();
- for (int i = 0; i < type.parameterCount(); i++) {
- if (type.parameterType(i) == VaList.class) {
- handle = MethodHandles.filterArguments(handle, i, MH_boxVaList);
- }
- }
return handle;
}
@Override
public MemorySegment upcallStub(MethodHandle target, FunctionDescriptor function) {
! target = boxVaLists(target);
return UpcallStubs.upcallAddress(CallArranger.arrangeUpcall(target, target.type(), function));
}
@Override
public String name() {
WinVaList.Builder builder = WinVaList.builder();
actions.accept(builder);
return builder.build();
}
@Override
public MethodHandle downcallHandle(MemoryAddress symbol, MethodType type, FunctionDescriptor function) {
! MethodType llMt = SharedUtils.convertVaListCarriers(type, WinVaList.CARRIER);
MethodHandle handle = CallArranger.arrangeDowncall(symbol, llMt, function);
! handle = SharedUtils.unboxVaLists(type, handle, MH_unboxVaList);
return handle;
}
@Override
public MemorySegment upcallStub(MethodHandle target, FunctionDescriptor function) {
! target = SharedUtils.boxVaLists(target, MH_boxVaList);
return UpcallStubs.upcallAddress(CallArranger.arrangeUpcall(target, target.type(), function));
}
@Override
public String name() {
static Win64.ArgumentClass argumentClassFor(MemoryLayout layout) {
return (Win64.ArgumentClass)layout.attribute(Win64.CLASS_ATTRIBUTE_NAME).get();
}
- private static MemoryAddress unboxVaList(CSupport.VaList list) {
- return ((WinVaList) list).getSegment().baseAddress();
- }
-
- private static CSupport.VaList boxVaList(MemoryAddress ma) {
- return WinVaList.ofAddress(ma);
- }
-
public static VaList newVaListOfAddress(MemoryAddress ma) {
return WinVaList.ofAddress(ma);
}
}
static Win64.ArgumentClass argumentClassFor(MemoryLayout layout) {
return (Win64.ArgumentClass)layout.attribute(Win64.CLASS_ATTRIBUTE_NAME).get();
}
public static VaList newVaListOfAddress(MemoryAddress ma) {
return WinVaList.ofAddress(ma);
}
+ public static VaList emptyVaList() {
+ return WinVaList.empty();
+ }
}
< prev index next >