Search in sources :

Example 61 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class CEntryPointCallStubMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    UniverseMetaAccess metaAccess = (UniverseMetaAccess) providers.getMetaAccess();
    NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries();
    HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
    StructuredGraph graph = kit.getGraph();
    JavaType[] parameterTypes = method.toParameterTypes();
    JavaType[] parameterLoadTypes = Arrays.copyOf(parameterTypes, parameterTypes.length);
    EnumInfo[] parameterEnumInfos;
    parameterEnumInfos = adaptParameterTypes(providers, nativeLibraries, kit, parameterTypes, parameterLoadTypes, purpose);
    ValueNode[] args = kit.loadArguments(parameterLoadTypes).toArray(new ValueNode[0]);
    InvokeNode prologueInvoke = generatePrologue(providers, kit, parameterLoadTypes, args);
    adaptArgumentValues(providers, kit, parameterTypes, parameterEnumInfos, args);
    ResolvedJavaMethod unwrappedTargetMethod = targetMethod;
    while (unwrappedTargetMethod instanceof WrappedJavaMethod) {
        unwrappedTargetMethod = ((WrappedJavaMethod) unwrappedTargetMethod).getWrapped();
    }
    ResolvedJavaMethod universeTargetMethod = lookupMethodInUniverse(metaAccess, unwrappedTargetMethod);
    int invokeBci = kit.bci();
    int exceptionEdgeBci = kit.bci();
    // Also support non-static test methods (they are not allowed to use the receiver)
    InvokeKind invokeKind = universeTargetMethod.isStatic() ? InvokeKind.Static : InvokeKind.Special;
    ValueNode[] invokeArgs = args;
    if (invokeKind != InvokeKind.Static) {
        invokeArgs = new ValueNode[args.length + 1];
        invokeArgs[0] = kit.createObject(null);
        System.arraycopy(args, 0, invokeArgs, 1, args.length);
    }
    InvokeWithExceptionNode invoke = kit.startInvokeWithException(universeTargetMethod, invokeKind, kit.getFrameState(), invokeBci, exceptionEdgeBci, invokeArgs);
    kit.exceptionPart();
    ExceptionObjectNode exception = kit.exceptionObject();
    generateExceptionHandler(providers, kit, exception, invoke.getStackKind());
    kit.endInvokeWithException();
    ValueNode returnValue = adaptReturnValue(method, providers, purpose, metaAccess, nativeLibraries, kit, invoke);
    InvokeNode epilogueInvoke = generateEpilogue(providers, kit);
    kit.createReturn(returnValue, returnValue.getStackKind());
    inlinePrologueAndEpilogue(kit, prologueInvoke, epilogueInvoke, invoke.getStackKind());
    assert graph.verify();
    return graph;
}
Also used : HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) UniverseMetaAccess(com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 62 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class CEntryPointCallStubMethod method generateEpilogue.

private InvokeNode generateEpilogue(HostedProviders providers, SubstrateGraphKit kit) {
    Class<?> epilogueClass = entryPointData.getEpilogue();
    if (epilogueClass == NoEpilogue.class) {
        UserError.guarantee(targetMethod.getAnnotation(Uninterruptible.class) != null, CEntryPointOptions.class.getSimpleName() + "." + NoEpilogue.class.getSimpleName() + " is allowed only for methods annotated with @" + Uninterruptible.class.getSimpleName() + ": " + targetMethod.format("%H.%n(%p)"));
        return null;
    }
    ResolvedJavaType epilogue = providers.getMetaAccess().lookupJavaType(epilogueClass);
    ResolvedJavaMethod[] epilogueMethods = epilogue.getDeclaredMethods();
    UserError.guarantee(epilogueMethods.length == 1 && epilogueMethods[0].isStatic() && epilogueMethods[0].getSignature().getParameterCount(false) == 0, "Epilogue class must declare exactly one static method without parameters: " + targetMethod.format("%H.%n(%p)") + " -> " + epilogue.toJavaName());
    return kit.createInvoke(epilogueMethods[0], InvokeKind.Static, kit.getFrameState(), kit.bci());
}
Also used : CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 63 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class CEntryPointCallStubMethod method create.

static CEntryPointCallStubMethod create(AnalysisMethod targetMethod, CEntryPointData entryPointData, AnalysisMetaAccess metaAccess) {
    ResolvedJavaMethod unwrappedMethod = targetMethod.getWrapped();
    MetaAccessProvider unwrappedMetaAccess = metaAccess.getWrapped();
    ResolvedJavaType declaringClass = unwrappedMetaAccess.lookupJavaType(CEntryPointCallStubs.class);
    ConstantPool constantPool = CEntryPointCallStubs.getConstantPool(unwrappedMetaAccess);
    return new CEntryPointCallStubMethod(entryPointData, unwrappedMethod, declaringClass, constantPool);
}
Also used : ConstantPool(jdk.vm.ci.meta.ConstantPool) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 64 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class CGlobalDataFeature method registerInvocationPlugins.

@Override
public void registerInvocationPlugins(Providers providers, SnippetReflectionProvider snippetReflection, InvocationPlugins invocationPlugins, boolean hosted) {
    Registration r = new Registration(invocationPlugins, CGlobalData.class);
    r.register1("get", Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            VMError.guarantee(receiver.get().isConstant(), "Accessed CGlobalData is not a compile-time constant: " + b.getMethod().asStackTraceElement(b.bci()));
            CGlobalDataImpl<?> data = (CGlobalDataImpl<?>) SubstrateObjectConstant.asObject(receiver.get().asConstant());
            CGlobalDataInfo info = CGlobalDataFeature.this.map.get(data);
            b.addPush(targetMethod.getSignature().getReturnKind(), new CGlobalDataLoadAddressNode(info));
            return true;
        }
    });
}
Also used : CGlobalDataImpl(com.oracle.svm.core.c.CGlobalDataImpl) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) CGlobalDataInfo(com.oracle.svm.core.graal.code.CGlobalDataInfo) CGlobalDataLoadAddressNode(com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 65 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class InfoTreeBuilder method accessorValid.

private boolean accessorValid(AccessorInfo accessorInfo) {
    ResolvedJavaMethod method = (ResolvedJavaMethod) accessorInfo.getAnnotatedElement();
    int expectedParamCount = accessorInfo.parameterCount(false);
    int actualParamCount = method.getSignature().getParameterCount(false);
    if (actualParamCount != expectedParamCount) {
        nativeLibs.addError("Wrong number of parameters: expected " + expectedParamCount + "; found " + actualParamCount, method);
        return false;
    }
    if (accessorInfo.isIndexed()) {
        ResolvedJavaType paramType = (ResolvedJavaType) method.getSignature().getParameterType(accessorInfo.indexParameterNumber(false), method.getDeclaringClass());
        if (paramType.getJavaKind() != JavaKind.Int && paramType.getJavaKind() != JavaKind.Long && !nativeLibs.isSigned(paramType)) {
            nativeLibs.addError("Wrong type of index parameter 0: expected int, long, or Signed; found " + paramType.toJavaName(true), method);
            return false;
        }
    }
    if (accessorInfo.hasLocationIdentityParameter() && accessorInfo.hasUniqueLocationIdentity()) {
        nativeLibs.addError("Method cannot have annotation @" + UniqueLocationIdentity.class.getSimpleName() + " and a LocationIdentity parameter", method);
        return false;
    }
    if (accessorInfo.hasLocationIdentityParameter()) {
        ResolvedJavaType paramType = (ResolvedJavaType) method.getSignature().getParameterType(accessorInfo.locationIdentityParameterNumber(false), method.getDeclaringClass());
        if (!nativeLibs.getLocationIdentityType().equals(paramType)) {
            nativeLibs.addError("Wrong type of locationIdentity parameter: expected " + nativeLibs.getLocationIdentityType().toJavaName(true) + "; found " + paramType.toJavaName(true), method);
            return false;
        }
    }
    ResolvedJavaType returnType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
    if (accessorInfo.getAccessorKind() == AccessorKind.ADDRESS) {
        if (!nativeLibs.isPointerBase(returnType) || nativeLibs.isSigned(returnType) || nativeLibs.isUnsigned(returnType)) {
            nativeLibs.addError("Wrong return type: expected a pointer type; found " + returnType.toJavaName(true), method);
            return false;
        }
    }
    if (accessorInfo.getAccessorKind() == AccessorKind.OFFSET) {
        if (!(returnType.getJavaKind().isNumericInteger() || nativeLibs.isUnsigned(returnType))) {
            nativeLibs.addError("Wrong return type: expected an integer numeric type or Unsigned; found " + returnType.toJavaName(true), method);
            return false;
        }
    }
    if (!checkObjectType(returnType, method)) {
        return false;
    }
    for (int i = 0; i < method.getSignature().getParameterCount(false); i++) {
        ResolvedJavaType paramType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
        if (!checkObjectType(paramType, method)) {
            return false;
        }
    }
    return true;
}
Also used : UniqueLocationIdentity(org.graalvm.nativeimage.c.struct.UniqueLocationIdentity) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)331 ValueNode (org.graalvm.compiler.nodes.ValueNode)104 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)92 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)89 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)67 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)66 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 Test (org.junit.Test)54 DebugContext (org.graalvm.compiler.debug.DebugContext)35 OptionValues (org.graalvm.compiler.options.OptionValues)32 InstalledCode (jdk.vm.ci.code.InstalledCode)24 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)23 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)22 JavaKind (jdk.vm.ci.meta.JavaKind)21 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)20 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)19 JavaConstant (jdk.vm.ci.meta.JavaConstant)17 LogicNode (org.graalvm.compiler.nodes.LogicNode)17 ArrayList (java.util.ArrayList)16