Search in sources :

Example 31 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class CompileQueue method defaultCompileFunction.

@SuppressWarnings("try")
private CompilationResult defaultCompileFunction(DebugContext debug, HostedMethod method, CompilationIdentifier compilationIdentifier, CompileReason reason, RuntimeConfiguration config) {
    if (NativeImageOptions.PrintAOTCompilation.getValue()) {
        System.out.println("Compiling " + method.format("%r %H.%n(%p)") + "  [" + reason + "]");
    }
    Backend backend = config.lookupBackend(method);
    StructuredGraph graph = method.compilationInfo.graph;
    assert graph != null : method;
    /* Operate on a copy, to keep the original graph intact for later inlining. */
    graph = graph.copyWithIdentifier(compilationIdentifier, debug);
    /* Check that graph is in good shape before compilation. */
    assert GraphOrder.assertSchedulableGraph(graph);
    try (DebugContext.Scope s = debug.scope("Compiling", graph, method, this)) {
        if (deoptimizeAll && method.compilationInfo.canDeoptForTesting) {
            insertDeoptTests(method, graph);
        }
        method.compilationInfo.numNodesBeforeCompilation = graph.getNodeCount();
        method.compilationInfo.numDeoptEntryPoints = graph.getNodes().filter(DeoptEntryNode.class).count();
        method.compilationInfo.numDuringCallEntryPoints = graph.getNodes(MethodCallTargetNode.TYPE).snapshot().stream().map(MethodCallTargetNode::invoke).filter(invoke -> method.compilationInfo.isDeoptEntry(invoke.bci(), true, false)).count();
        Suites suites = method.compilationInfo.isDeoptTarget() ? deoptTargetSuites : regularSuites;
        LIRSuites lirSuites = method.compilationInfo.isDeoptTarget() ? deoptTargetLIRSuites : regularLIRSuites;
        CompilationResult result = new CompilationResult(compilationIdentifier, method.format("%H.%n(%p)")) {

            @Override
            public void close() {
            /*
                     * Do nothing, we do not want our CompilationResult to be closed because we
                     * aggregate all data items and machine code in the native image heap.
                     */
            }
        };
        try (Indent indent = debug.logAndIndent("compile %s", method)) {
            GraalCompiler.compileGraph(graph, method, backend.getProviders(), backend, null, optimisticOpts, method.getProfilingInfo(), suites, lirSuites, result, new HostedCompilationResultBuilderFactory());
        }
        method.getProfilingInfo().setCompilerIRSize(StructuredGraph.class, method.compilationInfo.graph.getNodeCount());
        method.compilationInfo.numNodesAfterCompilation = graph.getNodeCount();
        if (method.compilationInfo.isDeoptTarget()) {
            assert verifyDeoptTarget(method, result);
        }
        for (Infopoint infopoint : result.getInfopoints()) {
            if (infopoint instanceof Call) {
                Call call = (Call) infopoint;
                HostedMethod callTarget = (HostedMethod) call.target;
                if (call.direct) {
                    ensureCompiled(callTarget, new DirectCallReason(method, reason));
                } else if (callTarget != null && callTarget.getImplementations() != null) {
                    for (HostedMethod impl : callTarget.getImplementations()) {
                        ensureCompiled(impl, new VirtualCallReason(method, callTarget, reason));
                    }
                }
            }
        }
        /* Shrink resulting code array to minimum size, to reduze memory footprint. */
        if (result.getTargetCode().length > result.getTargetCodeSize()) {
            result.setTargetCode(Arrays.copyOf(result.getTargetCode(), result.getTargetCodeSize()), result.getTargetCodeSize());
        }
        return result;
    } catch (Throwable ex) {
        GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
        error.addContext("method: " + method.format("%r %H.%n(%p)") + "  [" + reason + "]");
        throw error;
    }
}
Also used : Call(jdk.vm.ci.code.site.Call) Indent(org.graalvm.compiler.debug.Indent) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint) DebugContext(org.graalvm.compiler.debug.DebugContext) Backend(org.graalvm.compiler.core.target.Backend) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) CompilationResult(org.graalvm.compiler.code.CompilationResult) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 32 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class CompileQueue method doInlineTrivial.

@SuppressWarnings("try")
private void doInlineTrivial(DebugContext debug, final HostedMethod method) {
    /*
         * Make a copy of the graph to avoid concurrency problems. Graph manipulations are not
         * thread safe, and another thread can concurrently inline this method.
         */
    final StructuredGraph graph = (StructuredGraph) method.compilationInfo.getGraph().copy(debug);
    try (DebugContext.Scope s = debug.scope("InlineTrivial", graph, method, this)) {
        try {
            try (Indent in = debug.logAndIndent("do inline trivial in %s", method)) {
                boolean inlined = false;
                for (Invoke invoke : graph.getInvokes()) {
                    if (invoke.useForInlining()) {
                        inlined |= tryInlineTrivial(graph, invoke, !inlined);
                    }
                }
                if (inlined) {
                    Providers providers = runtimeConfig.lookupBackend(method).getProviders();
                    new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
                    /*
                         * Publish the new graph, it can be picked up immediately by other threads
                         * trying to inline this method.
                         */
                    method.compilationInfo.setGraph(graph);
                    checkTrivial(method);
                    inliningProgress = true;
                }
            }
        } 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 : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) Indent(org.graalvm.compiler.debug.Indent) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Providers(org.graalvm.compiler.phases.util.Providers) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 33 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class SPARCBranchBailoutTest method testBailoutOnBranchOverflow.

@SuppressWarnings("try")
@Test
public void testBailoutOnBranchOverflow() throws Throwable {
    Assume.assumeTrue(getBackend().getTarget().arch instanceof SPARC);
    ResolvedJavaMethod m = getResolvedJavaMethod("testBranch");
    DebugContext debug = getDebugContext();
    try {
        try (Scope s = debug.disable()) {
            StructuredGraph graph = parseEager(m, AllowAssumptions.YES, debug);
            compile(m, graph);
        }
    } catch (GraalError e) {
        Assert.assertEquals(PermanentBailoutException.class, e.getCause().getClass());
    }
}
Also used : SPARC(jdk.vm.ci.sparc.SPARC) Scope(org.graalvm.compiler.debug.DebugContext.Scope) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) DebugContext(org.graalvm.compiler.debug.DebugContext) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException) Test(org.junit.Test)

Example 34 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class MatchProcessor method processMatchableNode.

private void processMatchableNode(Element element, TypeElement topDeclaringType, MatchableNode matchable, AnnotationMirror mirror) throws GraalError {
    logMessage("processMatchableNode %s %s %s\n", topDeclaringType, element, matchable);
    String nodeClass;
    String nodePackage;
    TypeMirror nodeClassMirror = null;
    try {
        matchable.nodeClass();
    } catch (MirroredTypeException e) {
        nodeClassMirror = e.getTypeMirror();
    }
    if (nodeClassMirror == null) {
        throw new GraalError("Can't get mirror for node class %s", element);
    }
    if (nodeClassMirror.toString().equals(MatchableNode.class.getName())) {
        nodeClass = topDeclaringType.getQualifiedName().toString();
    } else {
        nodeClass = nodeClassMirror.toString();
    }
    TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(nodeClass);
    if (typeElement == null) {
        errorMessage(element, mirror, "Class \"%s\" cannot be resolved to a type", nodeClass);
        return;
    }
    nodePackage = findPackage(typeElement);
    assert nodeClass.startsWith(nodePackage);
    nodeClass = nodeClass.substring(nodePackage.length() + 1);
    assert nodeClass.endsWith("Node");
    String shortName = nodeClass.substring(0, nodeClass.length() - 4);
    Types typeUtils = processingEnv.getTypeUtils();
    TypeElement nodeClassElement = (TypeElement) typeUtils.asElement(nodeClassMirror);
    for (String input : matchable.inputs()) {
        boolean ok = false;
        TypeElement current = nodeClassElement;
        while (!ok && current != null) {
            for (Element fieldElement : ElementFilter.fieldsIn(current.getEnclosedElements())) {
                if (fieldElement.getSimpleName().toString().equals(input)) {
                    ok = true;
                    break;
                }
            }
            TypeMirror theSuper = current.getSuperclass();
            current = (TypeElement) typeUtils.asElement(theSuper);
        }
        if (!ok) {
            errorMessage(element, mirror, "Input named \"%s\" doesn't exist in %s", input, nodeClassElement.getSimpleName());
        }
    }
    declareType(nodeClassMirror, shortName, nodeClass, nodePackage, matchable.inputs(), matchable.commutative(), matchable.shareable(), element);
}
Also used : MirroredTypeException(javax.lang.model.type.MirroredTypeException) MatchableNode(org.graalvm.compiler.core.match.MatchableNode) SupportedAnnotationTypes(javax.annotation.processing.SupportedAnnotationTypes) Types(javax.lang.model.util.Types) GraalError(org.graalvm.compiler.debug.GraalError) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 35 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class HotSpotGraalConstantFieldProvider method isEmbeddableField.

protected boolean isEmbeddableField(ResolvedJavaField field) {
    if (nonEmbeddableFields == null) {
        synchronized (this) {
            if (nonEmbeddableFields == null) {
                List<ResolvedJavaField> fields = new ArrayList<>();
                try {
                    fields.add(metaAccess.lookupJavaField(Boolean.class.getDeclaredField("TRUE")));
                    fields.add(metaAccess.lookupJavaField(Boolean.class.getDeclaredField("FALSE")));
                    Class<?> characterCacheClass = Character.class.getDeclaredClasses()[0];
                    assert "java.lang.Character$CharacterCache".equals(characterCacheClass.getName());
                    fields.add(metaAccess.lookupJavaField(characterCacheClass.getDeclaredField("cache")));
                    Class<?> byteCacheClass = Byte.class.getDeclaredClasses()[0];
                    assert "java.lang.Byte$ByteCache".equals(byteCacheClass.getName());
                    fields.add(metaAccess.lookupJavaField(byteCacheClass.getDeclaredField("cache")));
                    Class<?> shortCacheClass = Short.class.getDeclaredClasses()[0];
                    assert "java.lang.Short$ShortCache".equals(shortCacheClass.getName());
                    fields.add(metaAccess.lookupJavaField(shortCacheClass.getDeclaredField("cache")));
                    Class<?> integerCacheClass = Integer.class.getDeclaredClasses()[0];
                    assert "java.lang.Integer$IntegerCache".equals(integerCacheClass.getName());
                    fields.add(metaAccess.lookupJavaField(integerCacheClass.getDeclaredField("cache")));
                    Class<?> longCacheClass = Long.class.getDeclaredClasses()[0];
                    assert "java.lang.Long$LongCache".equals(longCacheClass.getName());
                    fields.add(metaAccess.lookupJavaField(longCacheClass.getDeclaredField("cache")));
                    fields.add(metaAccess.lookupJavaField(Throwable.class.getDeclaredField("UNASSIGNED_STACK")));
                    fields.add(metaAccess.lookupJavaField(Throwable.class.getDeclaredField("SUPPRESSED_SENTINEL")));
                } catch (SecurityException | NoSuchFieldException e) {
                    throw new GraalError(e);
                }
                nonEmbeddableFields = fields;
            }
        }
    }
    return !nonEmbeddableFields.contains(field);
}
Also used : ArrayList(java.util.ArrayList) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) GraalError(org.graalvm.compiler.debug.GraalError)

Aggregations

GraalError (org.graalvm.compiler.debug.GraalError)42 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)9 ValueNode (org.graalvm.compiler.nodes.ValueNode)8 DebugContext (org.graalvm.compiler.debug.DebugContext)7 Indent (org.graalvm.compiler.debug.Indent)5 IOException (java.io.IOException)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 Node (org.graalvm.compiler.graph.Node)4 OptionValues (org.graalvm.compiler.options.OptionValues)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 ArrayList (java.util.ArrayList)3 CompilationResult (org.graalvm.compiler.code.CompilationResult)3 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 Invoke (org.graalvm.compiler.nodes.Invoke)3 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)3 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)3 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)2 InstalledCode (jdk.vm.ci.code.InstalledCode)2