use of jdk.vm.ci.meta.Signature in project graal by oracle.
the class CFunctionCallStubMethod method adaptSignatureAndConvertArguments.
private static Signature adaptSignatureAndConvertArguments(ResolvedJavaMethod method, HostedProviders providers, NativeLibraries nativeLibraries, HostedGraphKit kit, Signature signature, List<ValueNode> arguments) {
MetaAccessProvider metaAccess = providers.getMetaAccess();
JavaType returnType = signature.getReturnType(null);
JavaType[] parameterTypes = signature.toParameterTypes(null);
for (int i = 0; i < parameterTypes.length; i++) {
if (!isPrimitiveOrWord(providers, parameterTypes[i])) {
ElementInfo typeInfo = nativeLibraries.findElementInfo(parameterTypes[i]);
if (typeInfo instanceof EnumInfo) {
UserError.guarantee(typeInfo.getChildren().stream().anyMatch(EnumValueInfo.class::isInstance), "Enum class " + returnType.toJavaName() + " needs a method that is annotated with @" + CEnumValue.class.getSimpleName() + " because it is used as a parameter of a method annotated with @" + CFunction.class.getSimpleName() + ": " + method.format("%H.%n(%p)"));
ValueNode argumentValue = arguments.get(i);
IsNullNode isNull = kit.unique(new IsNullNode(argumentValue));
kit.startIf(isNull, BranchProbabilityNode.VERY_SLOW_PATH_PROBABILITY);
kit.thenPart();
ResolvedJavaType enumExceptionType = metaAccess.lookupJavaType(RuntimeException.class);
NewInstanceNode enumException = kit.append(new NewInstanceNode(enumExceptionType, true));
Iterator<ResolvedJavaMethod> enumExceptionCtor = Arrays.stream(enumExceptionType.getDeclaredConstructors()).filter(c -> c.getSignature().getParameterCount(false) == 1 && c.getSignature().getParameterType(0, null).equals(metaAccess.lookupJavaType(String.class))).iterator();
ConstantNode enumExceptionMessage = kit.createConstant(kit.getConstantReflection().forString("null return value cannot be converted to a C enum value"), JavaKind.Object);
kit.createJavaCallWithExceptionAndUnwind(InvokeKind.Special, enumExceptionCtor.next(), enumException, enumExceptionMessage);
assert !enumExceptionCtor.hasNext();
kit.append(new UnwindNode(enumException));
kit.endIf();
CInterfaceEnumTool tool = new CInterfaceEnumTool(metaAccess, providers.getSnippetReflection());
argumentValue = tool.createEnumValueInvoke(kit, (EnumInfo) typeInfo, cEnumKind, argumentValue);
arguments.set(i, argumentValue);
parameterTypes[i] = metaAccess.lookupJavaType(cEnumKind.toJavaClass());
} else {
throw UserError.abort("@" + CFunction.class.getSimpleName() + " parameter types are restricted to primitive types, word types and enumerations (@" + CEnum.class.getSimpleName() + "): " + method.format("%H.%n(%p)"));
}
}
}
if (!isPrimitiveOrWord(providers, returnType)) {
// Assume enum: actual checks and conversion are in adaptReturnValue()
returnType = providers.getWordTypes().getWordImplType();
}
JavaType actualReturnType = returnType;
return new Signature() {
@Override
public int getParameterCount(boolean receiver) {
return parameterTypes.length;
}
@Override
public JavaType getParameterType(int index, ResolvedJavaType accessingClass) {
return parameterTypes[index];
}
@Override
public JavaType getReturnType(ResolvedJavaType accessingClass) {
return actualReturnType;
}
};
}
use of jdk.vm.ci.meta.Signature in project graal by oracle.
the class UniverseBuilder method makeMethod.
private void makeMethod(AnalysisMethod aMethod) {
HostedType holder;
holder = makeType(aMethod.getDeclaringClass());
Signature signature = makeSignature(aMethod.getSignature(), holder);
ConstantPool constantPool = makeConstantPool(aMethod.getConstantPool(), holder);
ExceptionHandler[] aHandlers = aMethod.getExceptionHandlers();
ExceptionHandler[] sHandlers = new ExceptionHandler[aHandlers.length];
for (int i = 0; i < aHandlers.length; i++) {
ExceptionHandler h = aHandlers[i];
ResolvedJavaType catchType = makeType((AnalysisType) h.getCatchType());
sHandlers[i] = new ExceptionHandler(h.getStartBCI(), h.getEndBCI(), h.getHandlerBCI(), h.catchTypeCPI(), catchType);
}
HostedMethod sMethod = new HostedMethod(hUniverse, aMethod, holder, signature, constantPool, sHandlers);
assert !hUniverse.methods.containsKey(aMethod);
hUniverse.methods.put(aMethod, sMethod);
if (aMethod.getAnnotation(CFunction.class) != null) {
if (!aMethod.isNative()) {
unsupportedFeatures.addMessage(aMethod.format("%H.%n(%p)"), aMethod, "Method annotated with @" + CFunction.class.getSimpleName() + " must be declared native");
}
} else if (aMethod.isNative() && !aMethod.isIntrinsicMethod() && aMethod.isImplementationInvoked() && !NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
unsupportedFeatures.addMessage(aMethod.format("%H.%n(%p)"), aMethod, AnnotationSubstitutionProcessor.deleteErrorMessage(aMethod, DeletedMethod.NATIVE_MESSAGE, true));
}
}
use of jdk.vm.ci.meta.Signature in project graal by oracle.
the class BytecodeParser method appendInvoke.
protected Invoke appendInvoke(InvokeKind initialInvokeKind, ResolvedJavaMethod initialTargetMethod, ValueNode[] args) {
ResolvedJavaMethod targetMethod = initialTargetMethod;
InvokeKind invokeKind = initialInvokeKind;
if (initialInvokeKind.isIndirect()) {
ResolvedJavaType contextType = this.frameState.getMethod().getDeclaringClass();
ResolvedJavaMethod specialCallTarget = MethodCallTargetNode.findSpecialCallTarget(initialInvokeKind, args[0], initialTargetMethod, contextType);
if (specialCallTarget != null) {
invokeKind = InvokeKind.Special;
targetMethod = specialCallTarget;
}
}
JavaKind resultType = targetMethod.getSignature().getReturnKind();
if (!parsingIntrinsic() && DeoptALot.getValue(options)) {
append(new DeoptimizeNode(DeoptimizationAction.None, RuntimeConstraint));
frameState.pushReturn(resultType, ConstantNode.defaultForKind(resultType, graph));
return null;
}
JavaType returnType = targetMethod.getSignature().getReturnType(method.getDeclaringClass());
if (graphBuilderConfig.eagerResolving() || parsingIntrinsic()) {
returnType = returnType.resolve(targetMethod.getDeclaringClass());
}
if (invokeKind.hasReceiver()) {
args[0] = emitExplicitExceptions(args[0]);
}
if (initialInvokeKind == InvokeKind.Special && !targetMethod.isConstructor()) {
emitCheckForInvokeSuperSpecial(args);
}
InlineInfo inlineInfo = null;
try {
currentInvoke = new CurrentInvoke(args, invokeKind, returnType);
if (tryNodePluginForInvocation(args, targetMethod)) {
if (TraceParserPlugins.getValue(options)) {
traceWithContext("used node plugin for %s", targetMethod.format("%h.%n(%p)"));
}
return null;
}
if (invokeKind.hasReceiver() && args[0].isNullConstant()) {
append(new DeoptimizeNode(InvalidateRecompile, NullCheckException));
return null;
}
if (!invokeKind.isIndirect() || (UseGuardedIntrinsics.getValue(options) && !GeneratePIC.getValue(options))) {
if (tryInvocationPlugin(invokeKind, args, targetMethod, resultType, returnType)) {
if (TraceParserPlugins.getValue(options)) {
traceWithContext("used invocation plugin for %s", targetMethod.format("%h.%n(%p)"));
}
return null;
}
}
if (invokeKind.isDirect()) {
inlineInfo = tryInline(args, targetMethod);
if (inlineInfo == SUCCESSFULLY_INLINED) {
return null;
}
}
} finally {
currentInvoke = null;
}
int invokeBci = bci();
JavaTypeProfile profile = getProfileForInvoke(invokeKind);
ExceptionEdgeAction edgeAction = getActionForInvokeExceptionEdge(inlineInfo);
boolean partialIntrinsicExit = false;
if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) {
partialIntrinsicExit = true;
ResolvedJavaMethod originalMethod = intrinsicContext.getOriginalMethod();
BytecodeParser intrinsicCallSiteParser = getNonIntrinsicAncestor();
if (intrinsicCallSiteParser != null) {
// When exiting a partial intrinsic, the invoke to the original
// must use the same context as the call to the intrinsic.
invokeBci = intrinsicCallSiteParser.bci();
profile = intrinsicCallSiteParser.getProfileForInvoke(invokeKind);
edgeAction = intrinsicCallSiteParser.getActionForInvokeExceptionEdge(inlineInfo);
} else {
// so the bci must be set to unknown, so that the inliner patches it later.
assert intrinsicContext.isPostParseInlined();
invokeBci = BytecodeFrame.UNKNOWN_BCI;
profile = null;
edgeAction = graph.method().getAnnotation(Snippet.class) == null ? ExceptionEdgeAction.INCLUDE_AND_HANDLE : ExceptionEdgeAction.OMIT;
}
if (originalMethod.isStatic()) {
invokeKind = InvokeKind.Static;
} else {
// The original call to the intrinsic must have been devirtualized
// otherwise we wouldn't be here.
invokeKind = InvokeKind.Special;
}
Signature sig = originalMethod.getSignature();
returnType = sig.getReturnType(method.getDeclaringClass());
resultType = sig.getReturnKind();
assert intrinsicContext.allowPartialIntrinsicArgumentMismatch() || checkPartialIntrinsicExit(intrinsicCallSiteParser == null ? null : intrinsicCallSiteParser.currentInvoke.args, args);
targetMethod = originalMethod;
}
Invoke invoke = createNonInlinedInvoke(edgeAction, invokeBci, args, targetMethod, invokeKind, resultType, returnType, profile);
if (partialIntrinsicExit) {
// This invoke must never be later inlined as it might select the intrinsic graph.
// Until there is a mechanism to guarantee that any late inlining will not select
// the intrinsic graph, prevent this invoke from being inlined.
invoke.setUseForInlining(false);
}
return invoke;
}
use of jdk.vm.ci.meta.Signature in project graal by oracle.
the class FrameStateBuilder method initializeForMethodStart.
public void initializeForMethodStart(Assumptions assumptions, boolean eagerResolve, Plugins plugins) {
int javaIndex = 0;
int index = 0;
ResolvedJavaMethod method = getMethod();
ResolvedJavaType originalType = method.getDeclaringClass();
if (!method.isStatic()) {
// add the receiver
FloatingNode receiver = null;
StampPair receiverStamp = null;
if (plugins != null) {
receiverStamp = plugins.getOverridingStamp(tool, originalType, true);
}
if (receiverStamp == null) {
receiverStamp = StampFactory.forDeclaredType(assumptions, originalType, true);
}
if (plugins != null) {
for (ParameterPlugin plugin : plugins.getParameterPlugins()) {
receiver = plugin.interceptParameter(tool, index, receiverStamp);
if (receiver != null) {
break;
}
}
}
if (receiver == null) {
receiver = new ParameterNode(javaIndex, receiverStamp);
}
locals[javaIndex] = graph.addOrUniqueWithInputs(receiver);
javaIndex = 1;
index = 1;
}
Signature sig = method.getSignature();
int max = sig.getParameterCount(false);
ResolvedJavaType accessingClass = originalType;
for (int i = 0; i < max; i++) {
JavaType type = sig.getParameterType(i, accessingClass);
if (eagerResolve) {
type = type.resolve(accessingClass);
}
JavaKind kind = type.getJavaKind();
StampPair stamp = null;
if (plugins != null) {
stamp = plugins.getOverridingStamp(tool, type, false);
}
if (stamp == null) {
stamp = StampFactory.forDeclaredType(assumptions, type, false);
}
FloatingNode param = null;
if (plugins != null) {
for (ParameterPlugin plugin : plugins.getParameterPlugins()) {
param = plugin.interceptParameter(tool, index, stamp);
if (param != null) {
break;
}
}
}
if (param == null) {
param = new ParameterNode(index, stamp);
}
locals[javaIndex] = graph.addOrUniqueWithInputs(param);
javaIndex++;
if (kind.needsTwoSlots()) {
locals[javaIndex] = TWO_SLOT_MARKER;
javaIndex++;
}
index++;
}
}
use of jdk.vm.ci.meta.Signature in project graal by oracle.
the class GraalObjectReplacer method apply.
@Override
public Object apply(Object source) {
if (source == null) {
return null;
}
Object dest = source;
if (source instanceof RelocatedPointer) {
return dest;
}
if (source instanceof MetaAccessProvider) {
dest = sMetaAccess;
} else if (source instanceof GraalRuntime) {
dest = sGraalRuntime;
} else if (source instanceof AnalysisConstantReflectionProvider) {
dest = sConstantReflectionProvider;
} else if (source instanceof AnalysisConstantFieldProvider) {
dest = sConstantFieldProvider;
} else if (source instanceof ForeignCallsProvider) {
dest = GraalSupport.getRuntimeConfig().getProviders().getForeignCalls();
} else if (source instanceof HostedSnippetReflectionProvider) {
dest = GraalSupport.getRuntimeConfig().getSnippetReflection();
} else if (shouldBeReplaced(source)) {
/*
* The hash maps must be synchronized, because replace() may be called from
* BigBang.finish(), which is multi-threaded.
*/
synchronized (this) {
if (source instanceof ResolvedJavaMethod) {
dest = createMethod((ResolvedJavaMethod) source);
} else if (source instanceof ResolvedJavaField) {
dest = createField((ResolvedJavaField) source);
} else if (source instanceof ResolvedJavaType) {
dest = createType((ResolvedJavaType) source);
} else if (source instanceof Signature) {
dest = createSignature((Signature) source);
} else if (source instanceof FieldLocationIdentity) {
dest = fieldLocationIdentities.get(source);
if (dest == null) {
SubstrateField destField = (SubstrateField) apply(((FieldLocationIdentity) source).getField());
dest = new SubstrateFieldLocationIdentity(destField);
fieldLocationIdentities.put((FieldLocationIdentity) source, (FieldLocationIdentity) dest);
}
}
}
}
assert dest != null;
String className = dest.getClass().getName();
assert !className.contains(".hotspot.") || className.contains(".svm.jtt.hotspot.") : "HotSpot object in image " + className;
assert !className.contains(".analysis.meta.") : "Analysis meta object in image " + className;
assert !className.contains(".hosted.meta.") : "Hosted meta object in image " + className;
return dest;
}
Aggregations