Search in sources :

Example 1 with HostedMethod

use of com.oracle.svm.hosted.meta.HostedMethod in project graal by oracle.

the class GraalObjectReplacer method createMethod.

public SubstrateMethod createMethod(ResolvedJavaMethod original) {
    AnalysisMethod aMethod;
    if (original instanceof AnalysisMethod) {
        aMethod = (AnalysisMethod) original;
    } else if (original instanceof HostedMethod) {
        aMethod = ((HostedMethod) original).wrapped;
    } else {
        aMethod = aUniverse.lookup(original);
    }
    SubstrateMethod sMethod = methods.get(aMethod);
    if (sMethod == null) {
        assert !(original instanceof HostedMethod) : "too late to create new method";
        sMethod = new SubstrateMethod(aMethod, stringTable);
        methods.put(aMethod, sMethod);
        /*
             * The links to other meta objects must be set after adding to the methods to avoid
             * infinite recursion.
             */
        sMethod.setLinks(createSignature(aMethod.getSignature()), createType(aMethod.getDeclaringClass()));
        /*
             * Annotations are updated in every analysis iteration, but this is a starting point. It
             * also ensures that all types used by annotations are created eagerly.
             */
        sMethod.setAnnotationsEncoding(Inflation.encodeAnnotations(aMetaAccess, aMethod.getAnnotations(), null));
    }
    return sMethod;
}
Also used : SubstrateMethod(com.oracle.svm.graal.meta.SubstrateMethod) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod)

Example 2 with HostedMethod

use of com.oracle.svm.hosted.meta.HostedMethod in project graal by oracle.

the class GraalObjectReplacer method updateSubstrateDataAfterHeapLayout.

public void updateSubstrateDataAfterHeapLayout(HostedUniverse hUniverse) {
    for (Map.Entry<AnalysisMethod, SubstrateMethod> entry : methods.entrySet()) {
        AnalysisMethod aMethod = entry.getKey();
        SubstrateMethod sMethod = entry.getValue();
        HostedMethod hMethod = hUniverse.lookup(aMethod);
        int vTableIndex = (hMethod.hasVTableIndex() ? hMethod.getVTableIndex() : -1);
        /*
             * We access the offset of methods in the image code section here. Therefore, this code
             * can only run after the heap and code cache layout was done.
             */
        sMethod.setSubstrateData(vTableIndex, hMethod.isCodeAddressOffsetValid() ? hMethod.getCodeAddressOffset() : 0, hMethod.getDeoptOffsetInImage());
    }
}
Also used : SubstrateMethod(com.oracle.svm.graal.meta.SubstrateMethod) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with HostedMethod

use of com.oracle.svm.hosted.meta.HostedMethod in project graal by oracle.

the class CompileQueue method tryInlineTrivial.

private static boolean tryInlineTrivial(StructuredGraph graph, Invoke invoke, boolean firstInline) {
    if (invoke.getInvokeKind().isDirect()) {
        HostedMethod singleCallee = (HostedMethod) invoke.callTarget().targetMethod();
        if (makeInlineDecision(invoke, singleCallee) && InliningUtilities.recursionDepth(invoke, singleCallee) == 0) {
            if (firstInline) {
                graph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph, "Before inlining");
            }
            InliningUtil.inline(invoke, singleCallee.compilationInfo.getGraph(), true, singleCallee);
            graph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph, "After inlining %s with trivial callee %s", invoke, singleCallee.format("%H.%n(%p)"));
            return true;
        }
    }
    return false;
}
Also used : HostedMethod(com.oracle.svm.hosted.meta.HostedMethod)

Example 4 with HostedMethod

use of com.oracle.svm.hosted.meta.HostedMethod in project graal by oracle.

the class CompileQueue method defaultParseFunction.

@SuppressWarnings("try")
private void defaultParseFunction(DebugContext debug, HostedMethod method, CompileReason reason, RuntimeConfiguration config) {
    if (method.getAnnotation(Fold.class) != null || method.getAnnotation(NodeIntrinsic.class) != null) {
        throw VMError.shouldNotReachHere("Parsing method annotated with @Fold or @NodeIntrinsic: " + method.format("%H.%n(%p)"));
    }
    HostedProviders providers = (HostedProviders) config.lookupBackend(method).getProviders();
    boolean needParsing = false;
    OptionValues options = HostedOptionValues.singleton();
    StructuredGraph graph = method.buildGraph(debug, method, providers, Purpose.AOT_COMPILATION);
    if (graph == null) {
        InvocationPlugin plugin = providers.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method);
        if (plugin != null && !plugin.inlineOnly()) {
            Bytecode code = new ResolvedJavaMethodBytecode(method);
            // DebugContext debug = new DebugContext(options, providers.getSnippetReflection());
            graph = new SubstrateIntrinsicGraphBuilder(debug.getOptions(), debug, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), code).buildGraph(plugin);
        }
    }
    if (graph == null && method.isNative() && NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
        graph = DeletedMethod.buildGraph(debug, method, providers, DeletedMethod.NATIVE_MESSAGE);
    }
    if (graph == null) {
        needParsing = true;
        if (!method.compilationInfo.isDeoptTarget()) {
            /*
                 * Disabling liveness analysis preserves the values of local variables beyond the
                 * bytecode-liveness. This greatly helps debugging. When local variable numbers are
                 * reused by javac, local variables can still get illegal values. Since we cannot
                 * "restore" such illegal values during deoptimization, we must do liveness analysis
                 * for deoptimization target methods.
                 */
            options = new OptionValues(options, GraalOptions.OptClearNonLiveLocals, false);
        }
        graph = new StructuredGraph.Builder(options, debug).method(method).build();
    }
    try (DebugContext.Scope s = debug.scope("Parsing", graph, method, this)) {
        try {
            if (needParsing) {
                GraphBuilderConfiguration gbConf = createHostedGraphBuilderConfiguration(providers, method);
                new HostedGraphBuilderPhase(providers.getMetaAccess(), providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), gbConf, optimisticOpts, null, providers.getWordTypes()).apply(graph);
            } else {
                graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
            }
            new DeadStoreRemovalPhase().apply(graph);
            new DevirtualizeCallsPhase().apply(graph);
            new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
            /*
                 * The StrengthenStampsPhase may not insert type check nodes for specialized
                 * methods, because we would get type state mismatches regarding Const<Type> !=
                 * <Type>
                 */
            /*
                 * cwimmer: the old, commented out, condition always disabled checking of static
                 * analysis results. Therefore, the checks are broken right now.
                 */
            // new StrengthenStampsPhase(BootImageOptions.CheckStaticAnalysisResults.getValue()
            // && method.compilationInfo.deoptTarget != null &&
            // !method.compilationInfo.isDeoptTarget).apply(graph);
            new StrengthenStampsPhase(false).apply(graph);
            new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
            /* Check that graph is in good shape after parsing. */
            assert GraphOrder.assertSchedulableGraph(graph);
            method.compilationInfo.graph = graph;
            for (Invoke invoke : graph.getInvokes()) {
                if (!canBeUsedForInlining(invoke)) {
                    invoke.setUseForInlining(false);
                }
                if (invoke.callTarget() instanceof MethodCallTargetNode) {
                    MethodCallTargetNode targetNode = (MethodCallTargetNode) invoke.callTarget();
                    HostedMethod invokeTarget = (HostedMethod) targetNode.targetMethod();
                    if (targetNode.invokeKind().isDirect()) {
                        if (invokeTarget.wrapped.isImplementationInvoked()) {
                            handleSpecialization(method, targetNode, invokeTarget, invokeTarget);
                            ensureParsed(invokeTarget, new DirectCallReason(method, reason));
                        }
                    } else {
                        for (HostedMethod invokeImplementation : invokeTarget.getImplementations()) {
                            handleSpecialization(method, targetNode, invokeTarget, invokeImplementation);
                            ensureParsed(invokeImplementation, new VirtualCallReason(method, invokeImplementation, reason));
                        }
                    }
                }
            }
        } catch (Throwable ex) {
            GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
            error.addContext("method: " + method.format("%r %H.%n(%p)"));
            throw error;
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) SubstrateIntrinsicGraphBuilder(com.oracle.graal.pointsto.phases.SubstrateIntrinsicGraphBuilder) HostedGraphBuilderPhase(com.oracle.svm.hosted.phases.HostedGraphBuilderPhase) DeadStoreRemovalPhase(com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Invoke(org.graalvm.compiler.nodes.Invoke) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) DevirtualizeCallsPhase(com.oracle.svm.hosted.phases.DevirtualizeCallsPhase) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) StrengthenStampsPhase(com.oracle.svm.hosted.phases.StrengthenStampsPhase)

Example 5 with HostedMethod

use of com.oracle.svm.hosted.meta.HostedMethod in project graal by oracle.

the class MustNotSynchronizeAnnotationChecker method synchronizesIndirectly.

/**
 * Does this method call a method that synchronizes?
 */
protected boolean synchronizesIndirectly(HostedMethod methodImpl) throws WarningException {
    boolean result = false;
    final StructuredGraph graph = methodImpl.compilationInfo.getGraph();
    if (graph != null) {
        for (Invoke invoke : graph.getInvokes()) {
            final HostedMethod callee = (HostedMethod) invoke.callTarget().targetMethod();
            if (invoke.callTarget().invokeKind().isDirect()) {
                result |= checkMethod(callee, callee);
                if (result) {
                    return result;
                }
            } else {
                for (HostedMethod calleeImpl : callee.getImplementations()) {
                    result |= checkMethod(callee, calleeImpl);
                    /* One violation is too many. */
                    if (result) {
                        return result;
                    }
                }
            }
        }
    }
    return result;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) Invoke(org.graalvm.compiler.nodes.Invoke)

Aggregations

HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)32 DebugContext (org.graalvm.compiler.debug.DebugContext)10 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)10 CompilationResult (org.graalvm.compiler.code.CompilationResult)8 Invoke (org.graalvm.compiler.nodes.Invoke)8 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)7 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)7 Infopoint (jdk.vm.ci.code.site.Infopoint)7 Indent (org.graalvm.compiler.debug.Indent)6 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)5 HostedOptionValues (com.oracle.svm.core.option.HostedOptionValues)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Call (jdk.vm.ci.code.site.Call)5 GraalError (org.graalvm.compiler.debug.GraalError)5 OptionValues (org.graalvm.compiler.options.OptionValues)5 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)4 SubstrateIntrinsicGraphBuilder (com.oracle.graal.pointsto.phases.SubstrateIntrinsicGraphBuilder)4 Timer (com.oracle.graal.pointsto.util.Timer)4