use of jdk.vm.ci.meta.JavaType in project graal by oracle.
the class JNIPrimitiveArrayOperationMethod method createSignature.
private JNISignature createSignature(MetaAccessProvider metaAccess) {
ResolvedJavaType objectHandleType = metaAccess.lookupJavaType(JNIObjectHandle.class);
ResolvedJavaType intType = metaAccess.lookupJavaType(int.class);
ResolvedJavaType returnType;
List<JavaType> args = new ArrayList<>();
args.add(metaAccess.lookupJavaType(JNIEnvironment.class));
if (operation == Operation.NEW) {
// jsize length;
args.add(intType);
returnType = objectHandleType;
} else {
// j<PrimitiveType>Array array;
args.add(objectHandleType);
if (operation == Operation.GET_ELEMENTS) {
// jboolean *isCopy;
args.add(metaAccess.lookupJavaType(CIntPointer.class));
returnType = metaAccess.lookupJavaType(WordPointer.class);
} else if (operation == Operation.RELEASE_ELEMENTS) {
// NativeType *elems;
args.add(metaAccess.lookupJavaType(WordPointer.class));
// jint mode;
args.add(intType);
returnType = metaAccess.lookupJavaType(Void.TYPE);
} else if (operation == Operation.GET_REGION || operation == Operation.SET_REGION) {
// jsize start;
args.add(intType);
// jsize len;
args.add(intType);
// NativeType *buf;
args.add(metaAccess.lookupJavaType(WordPointer.class));
returnType = metaAccess.lookupJavaType(Void.TYPE);
} else {
throw VMError.shouldNotReachHere();
}
}
return new JNISignature(args, returnType);
}
use of jdk.vm.ci.meta.JavaType in project graal by oracle.
the class CInterfaceEnumTool method replaceEnumValueInvoke.
boolean replaceEnumValueInvoke(BytecodeParser p, EnumInfo enumInfo, ResolvedJavaMethod method, ValueNode[] args) {
ResolvedJavaMethod valueMethod = getValueMethodForKind(method.getSignature().getReturnKind());
JavaType originalReturnType = method.getSignature().getReturnType(null);
assert args.length == 1;
InvokeNode invoke = invokeEnumValue(p, CallTargetFactory.from(p), p.getFrameStateBuilder(), p.bci(), enumInfo, valueMethod, args[0]);
ValueNode adapted = CInterfaceInvocationPlugin.adaptPrimitiveType(p.getGraph(), invoke, invoke.stamp(NodeView.DEFAULT).getStackKind(), originalReturnType.getJavaKind(), false);
Stamp originalStamp = p.getInvokeReturnStamp(null).getTrustedStamp();
adapted = CInterfaceInvocationPlugin.adaptPrimitiveType(p.getGraph(), adapted, originalReturnType.getJavaKind(), originalStamp.getStackKind(), false);
p.push(CInterfaceInvocationPlugin.pushKind(method), adapted);
return true;
}
use of jdk.vm.ci.meta.JavaType in project graal by oracle.
the class CInterfaceInvocationPlugin method replaceFunctionPointerInvoke.
private boolean replaceFunctionPointerInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, CallingConvention.Type callType) {
if (!functionPointerType.isAssignableFrom(method.getDeclaringClass())) {
throw UserError.abort(new CInterfaceError("function pointer invocation method " + method.format("%H.%n(%p)") + " must be in a type that extends " + CFunctionPointer.class.getSimpleName(), method).getMessage());
}
assert b.getInvokeKind() == InvokeKind.Interface;
JavaType[] parameterTypes = method.getSignature().toParameterTypes(null);
if (callType == SubstrateCallingConventionType.NativeCall) {
Predicate<JavaType> isValid = t -> t.getJavaKind().isPrimitive() || wordTypes.isWord(t);
UserError.guarantee(Stream.of(parameterTypes).allMatch(isValid) && isValid.test(method.getSignature().getReturnType(null)), "C function pointer invocation method must have only primitive types or word types for its parameters and return value: " + method.format("%H.%n(%p)"));
/*
* We currently do not support automatic conversions for @CEnum because it entails
* introducing additional invokes without real BCIs in a BytecodeParser context, which
* does not work too well.
*/
}
// We "discard" the receiver from the signature by pretending we are a static method
assert args.length >= 1;
ValueNode methodAddress = args[0];
ValueNode[] argsWithoutReceiver = Arrays.copyOfRange(args, 1, args.length);
assert argsWithoutReceiver.length == parameterTypes.length;
Stamp returnStamp;
if (wordTypes.isWord(b.getInvokeReturnType())) {
returnStamp = wordTypes.getWordStamp((ResolvedJavaType) b.getInvokeReturnType());
} else {
returnStamp = b.getInvokeReturnStamp(null).getTrustedStamp();
}
CallTargetNode indirectCallTargetNode = b.add(new IndirectCallTargetNode(methodAddress, argsWithoutReceiver, StampPair.createSingle(returnStamp), parameterTypes, method, callType, InvokeKind.Static));
if (callType == SubstrateCallingConventionType.JavaCall) {
b.handleReplacedInvoke(indirectCallTargetNode, b.getInvokeReturnType().getJavaKind());
} else if (callType == SubstrateCallingConventionType.NativeCall) {
// Native code cannot throw exceptions, omit exception edge
InvokeNode invokeNode = new InvokeNode(indirectCallTargetNode, b.bci());
if (pushKind(method) != JavaKind.Void) {
b.addPush(pushKind(method), invokeNode);
} else {
b.add(invokeNode);
}
} else {
throw shouldNotReachHere("Unsupported type of call: " + callType);
}
return true;
}
use of jdk.vm.ci.meta.JavaType in project graal by oracle.
the class MethodFilter method matchesSignature.
private boolean matchesSignature(Signature sig) {
if (signature == null) {
return true;
}
if (sig.getParameterCount(false) != signature.length) {
return false;
}
for (int i = 0; i < signature.length; i++) {
JavaType type = sig.getParameterType(i, null);
String javaName = type.toJavaName();
if (signature[i] != null && !signature[i].matcher(javaName).matches()) {
return false;
}
}
return true;
}
use of jdk.vm.ci.meta.JavaType in project graal by oracle.
the class GraphKit method createInvoke.
/**
* Creates and appends an {@link InvokeNode} for a call to a given method with a given set of
* arguments.
*/
@SuppressWarnings("try")
public InvokeNode createInvoke(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int bci, ValueNode... args) {
try (DebugCloseable context = graph.withNodeSourcePosition(NodeSourcePosition.substitution(graph.currentNodeSourcePosition(), method))) {
assert method.isStatic() == (invokeKind == InvokeKind.Static);
Signature signature = method.getSignature();
JavaType returnType = signature.getReturnType(null);
assert checkArgs(method, args);
StampPair returnStamp = graphBuilderPlugins.getOverridingStamp(this, returnType, false);
if (returnStamp == null) {
returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
}
MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, method, args, returnStamp, bci));
InvokeNode invoke = append(new InvokeNode(callTarget, bci));
if (frameStateBuilder != null) {
if (invoke.getStackKind() != JavaKind.Void) {
frameStateBuilder.push(invoke.getStackKind(), invoke);
}
invoke.setStateAfter(frameStateBuilder.create(bci, invoke));
if (invoke.getStackKind() != JavaKind.Void) {
frameStateBuilder.pop(invoke.getStackKind());
}
}
return invoke;
}
}
Aggregations