< prev index next > src/java.base/share/classes/jdk/internal/invoke/NativeEntryPoint.java
Print this page
*/
package jdk.internal.invoke;
import java.lang.invoke.MethodType;
+ import java.util.Arrays;
+ import java.util.List;
+ import java.util.Map;
import java.util.Objects;
+ import java.util.concurrent.ConcurrentHashMap;
/**
* This class describes a native call, including arguments/return shuffle moves, PC entry point and
* various other info which are relevant when the call will be intrinsified by C2.
*/
private final boolean needTransition;
private final MethodType methodType; // C2 sees erased version (byte -> int), so need this explicitly
private final String name;
private NativeEntryPoint(int shadowSpace, long[] argMoves, long[] returnMoves,
! boolean needTransition, MethodType methodType, String name) {
this.shadowSpace = shadowSpace;
this.argMoves = Objects.requireNonNull(argMoves);
this.returnMoves = Objects.requireNonNull(returnMoves);
this.needTransition = needTransition;
this.methodType = methodType;
this.name = name;
}
public static NativeEntryPoint make(String name, ABIDescriptorProxy abi,
VMStorageProxy[] argMoves, VMStorageProxy[] returnMoves,
! boolean needTransition, MethodType methodType) {
! if (returnMoves.length > 1) {
! throw new IllegalArgumentException("Multiple register return not supported");
}
! return new NativeEntryPoint(abi.shadowSpaceBytes(), encodeVMStorages(argMoves), encodeVMStorages(returnMoves),
! needTransition, methodType, name);
}
private static long[] encodeVMStorages(VMStorageProxy[] moves) {
long[] out = new long[moves.length];
for (int i = 0; i < moves.length; i++) {
private final boolean needTransition;
private final MethodType methodType; // C2 sees erased version (byte -> int), so need this explicitly
private final String name;
+ private final long invoker;
+
+ private static final Map<CacheKey, Long> INVOKER_CACHE = new ConcurrentHashMap<>();
+ private record CacheKey(MethodType mt, int shadowSpaceBytes,
+ List<VMStorageProxy> argMoves, List<VMStorageProxy> retMoves) {}
+
private NativeEntryPoint(int shadowSpace, long[] argMoves, long[] returnMoves,
! boolean needTransition, MethodType methodType, String name, long invoker) {
this.shadowSpace = shadowSpace;
this.argMoves = Objects.requireNonNull(argMoves);
this.returnMoves = Objects.requireNonNull(returnMoves);
this.needTransition = needTransition;
this.methodType = methodType;
this.name = name;
+ this.invoker = invoker;
}
public static NativeEntryPoint make(String name, ABIDescriptorProxy abi,
VMStorageProxy[] argMoves, VMStorageProxy[] returnMoves,
! boolean needTransition, MethodType methodType, boolean needsReturnBuffer) {
! if (returnMoves.length > 1 != needsReturnBuffer) {
! throw new IllegalArgumentException("Multiple register return, but needsReturnBuffer was false");
}
! assert (methodType.parameterType(0) == long.class) : "Address expected";
! assert (!needsReturnBuffer || methodType.parameterType(1) == long.class) : "IMR address expected";
+
+ int shadowSpaceBytes = abi.shadowSpaceBytes();
+ long[] encArgMoves = encodeVMStorages(argMoves);
+ long[] encRetMoves = encodeVMStorages(returnMoves);
+
+ CacheKey key = new CacheKey(methodType, abi.shadowSpaceBytes(),
+ Arrays.asList(argMoves), Arrays.asList(returnMoves));
+ long invoker = INVOKER_CACHE.computeIfAbsent(key, k ->
+ makeInvoker(methodType, abi, encArgMoves, encRetMoves, needsReturnBuffer));
+
+ return new NativeEntryPoint(shadowSpaceBytes, encArgMoves, encRetMoves,
+ needTransition, methodType, name, invoker);
}
private static long[] encodeVMStorages(VMStorageProxy[] moves) {
long[] out = new long[moves.length];
for (int i = 0; i < moves.length; i++) {
return out;
}
private static native long vmStorageToVMReg(int type, int index);
+ private static native long makeInvoker(MethodType methodType, ABIDescriptorProxy abi, long[] encArgMoves, long[] encRetMoves, boolean needsReturnBuffer);
+
public MethodType type() {
return methodType;
}
private static native void registerNatives();
< prev index next >