Search in sources :

Example 36 with GraalError

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

the class WordOperationPlugin method processWordOperation.

protected void processWordOperation(GraphBuilderContext b, ValueNode[] args, ResolvedJavaMethod wordMethod) throws GraalError {
    JavaKind returnKind = wordMethod.getSignature().getReturnKind();
    WordFactory.FactoryOperation factoryOperation = BridgeMethodUtils.getAnnotation(WordFactory.FactoryOperation.class, wordMethod);
    if (factoryOperation != null) {
        switch(factoryOperation.opcode()) {
            case ZERO:
                assert args.length == 0;
                b.addPush(returnKind, forIntegerKind(wordKind, 0L));
                return;
            case FROM_UNSIGNED:
                assert args.length == 1;
                b.push(returnKind, fromUnsigned(b, args[0]));
                return;
            case FROM_SIGNED:
                assert args.length == 1;
                b.push(returnKind, fromSigned(b, args[0]));
                return;
        }
    }
    Word.Operation operation = BridgeMethodUtils.getAnnotation(Word.Operation.class, wordMethod);
    if (operation == null) {
        throw bailout(b, "Cannot call method on a word value: " + wordMethod.format("%H.%n(%p)"));
    }
    switch(operation.opcode()) {
        case NODE_CLASS:
            assert args.length == 2;
            ValueNode left = args[0];
            ValueNode right = operation.rightOperandIsInt() ? toUnsigned(b, args[1], JavaKind.Int) : fromSigned(b, args[1]);
            b.addPush(returnKind, createBinaryNodeInstance(operation.node(), left, right));
            break;
        case COMPARISON:
            assert args.length == 2;
            b.push(returnKind, comparisonOp(b, operation.condition(), args[0], fromSigned(b, args[1])));
            break;
        case IS_NULL:
            assert args.length == 1;
            b.push(returnKind, comparisonOp(b, Condition.EQ, args[0], ConstantNode.forIntegerKind(wordKind, 0L)));
            break;
        case IS_NON_NULL:
            assert args.length == 1;
            b.push(returnKind, comparisonOp(b, Condition.NE, args[0], ConstantNode.forIntegerKind(wordKind, 0L)));
            break;
        case NOT:
            assert args.length == 1;
            b.addPush(returnKind, new XorNode(args[0], b.add(forIntegerKind(wordKind, -1))));
            break;
        case READ_POINTER:
        case READ_OBJECT:
        case READ_BARRIERED:
            {
                assert args.length == 2 || args.length == 3;
                JavaKind readKind = wordTypes.asKind(wordMethod.getSignature().getReturnType(wordMethod.getDeclaringClass()));
                AddressNode address = makeAddress(b, args[0], args[1]);
                LocationIdentity location;
                if (args.length == 2) {
                    location = any();
                } else {
                    assert args[2].isConstant();
                    location = snippetReflection.asObject(LocationIdentity.class, args[2].asJavaConstant());
                }
                b.push(returnKind, readOp(b, readKind, address, location, operation.opcode()));
                break;
            }
        case READ_HEAP:
            {
                assert args.length == 3;
                JavaKind readKind = wordTypes.asKind(wordMethod.getSignature().getReturnType(wordMethod.getDeclaringClass()));
                AddressNode address = makeAddress(b, args[0], args[1]);
                BarrierType barrierType = snippetReflection.asObject(BarrierType.class, args[2].asJavaConstant());
                b.push(returnKind, readOp(b, readKind, address, any(), barrierType, true));
                break;
            }
        case WRITE_POINTER:
        case WRITE_OBJECT:
        case WRITE_BARRIERED:
        case INITIALIZE:
            {
                assert args.length == 3 || args.length == 4;
                JavaKind writeKind = wordTypes.asKind(wordMethod.getSignature().getParameterType(wordMethod.isStatic() ? 2 : 1, wordMethod.getDeclaringClass()));
                AddressNode address = makeAddress(b, args[0], args[1]);
                LocationIdentity location;
                if (args.length == 3) {
                    location = any();
                } else {
                    assert args[3].isConstant();
                    location = snippetReflection.asObject(LocationIdentity.class, args[3].asJavaConstant());
                }
                writeOp(b, writeKind, address, location, args[2], operation.opcode());
                break;
            }
        case TO_RAW_VALUE:
            assert args.length == 1;
            b.push(returnKind, toUnsigned(b, args[0], JavaKind.Long));
            break;
        case OBJECT_TO_TRACKED:
            assert args.length == 1;
            WordCastNode objectToTracked = b.add(WordCastNode.objectToTrackedPointer(args[0], wordKind));
            b.push(returnKind, objectToTracked);
            break;
        case OBJECT_TO_UNTRACKED:
            assert args.length == 1;
            WordCastNode objectToUntracked = b.add(WordCastNode.objectToUntrackedPointer(args[0], wordKind));
            b.push(returnKind, objectToUntracked);
            break;
        case FROM_ADDRESS:
            assert args.length == 1;
            WordCastNode addressToWord = b.add(WordCastNode.addressToWord(args[0], wordKind));
            b.push(returnKind, addressToWord);
            break;
        case TO_OBJECT:
            assert args.length == 1;
            WordCastNode wordToObject = b.add(WordCastNode.wordToObject(args[0], wordKind));
            b.push(returnKind, wordToObject);
            break;
        case TO_OBJECT_NON_NULL:
            assert args.length == 1;
            WordCastNode wordToObjectNonNull = b.add(WordCastNode.wordToObjectNonNull(args[0], wordKind));
            b.push(returnKind, wordToObjectNonNull);
            break;
        case CAS_POINTER:
            assert args.length == 5;
            AddressNode address = makeAddress(b, args[0], args[1]);
            JavaKind valueKind = wordTypes.asKind(wordMethod.getSignature().getParameterType(1, wordMethod.getDeclaringClass()));
            assert valueKind.equals(wordTypes.asKind(wordMethod.getSignature().getParameterType(2, wordMethod.getDeclaringClass()))) : wordMethod.getSignature();
            assert args[4].isConstant() : Arrays.toString(args);
            LocationIdentity location = snippetReflection.asObject(LocationIdentity.class, args[4].asJavaConstant());
            JavaType returnType = wordMethod.getSignature().getReturnType(wordMethod.getDeclaringClass());
            b.addPush(returnKind, casOp(valueKind, wordTypes.asKind(returnType), address, location, args[2], args[3]));
            break;
        default:
            throw new GraalError("Unknown opcode: %s", operation.opcode());
    }
}
Also used : WordFactory(org.graalvm.word.WordFactory) Operation(org.graalvm.compiler.word.Word.Operation) XorNode(org.graalvm.compiler.nodes.calc.XorNode) BarrierType(org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) GraalError(org.graalvm.compiler.debug.GraalError) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LocationIdentity(org.graalvm.word.LocationIdentity) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 37 with GraalError

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

the class OnStackReplacementPhase method getEntryMarker.

private static EntryMarkerNode getEntryMarker(StructuredGraph graph) {
    NodeIterable<EntryMarkerNode> osrNodes = graph.getNodes(EntryMarkerNode.TYPE);
    EntryMarkerNode osr = osrNodes.first();
    if (osr == null) {
        throw new PermanentBailoutException("No OnStackReplacementNode generated");
    }
    if (osrNodes.count() > 1) {
        throw new GraalError("Multiple OnStackReplacementNodes generated");
    }
    if (osr.stateAfter().stackSize() != 0) {
        throw new PermanentBailoutException("OSR with stack entries not supported: %s", osr.stateAfter().toString(Verbosity.Debugger));
    }
    return osr;
}
Also used : EntryMarkerNode(org.graalvm.compiler.nodes.EntryMarkerNode) GraalError(org.graalvm.compiler.debug.GraalError) PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException)

Example 38 with GraalError

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

the class ReplaceConstantNodesPhase method handleHotSpotMetaspaceConstant.

/**
 * Replace {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} with indirection.
 *
 * @param graph
 * @param stateMapper
 * @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs
 *            resolution.
 */
private void handleHotSpotMetaspaceConstant(StructuredGraph graph, FrameStateMapperClosure stateMapper, ConstantNode node) {
    HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) node.asConstant();
    HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) metaspaceConstant.asResolvedJavaType();
    if (type != null) {
        if (verifyFingerprints && checkForBadFingerprint(type)) {
            throw new GraalError("Type with bad fingerprint: " + type);
        }
        assert !metaspaceConstant.isCompressed() : "No support for replacing compressed metaspace constants";
        tryToReplaceWithExisting(graph, node);
        if (anyUsagesNeedReplacement(node)) {
            replaceWithResolution(graph, stateMapper, node);
        }
    } else {
        throw new GraalError("Unsupported metaspace constant type: " + type);
    }
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)

Example 39 with GraalError

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

the class IntrinsificationPredicate method getExtLoader.

private static ClassLoader getExtLoader() {
    try {
        Object launcher = Class.forName("sun.misc.Launcher").getMethod("getLauncher").invoke(null);
        ClassLoader appLoader = (ClassLoader) launcher.getClass().getMethod("getClassLoader").invoke(launcher);
        ClassLoader extLoader = appLoader.getParent();
        assert extLoader.getClass().getName().equals("sun.misc.Launcher$ExtClassLoader") : extLoader;
        return extLoader;
    } catch (Exception e) {
        throw new GraalError(e);
    }
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError)

Example 40 with GraalError

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

the class GraalCompilerTest method getCode.

/**
 * Gets installed code for a given method and graph, compiling it first if necessary.
 *
 * @param installedCodeOwner the method the compiled code will be associated with when installed
 * @param graph the graph to be compiled. If null, a graph will be obtained from
 *            {@code installedCodeOwner} via {@link #parseForCompile(ResolvedJavaMethod)}.
 * @param forceCompile specifies whether to ignore any previous code cached for the (method,
 *            key) pair
 * @param installAsDefault specifies whether to install as the default implementation
 * @param options the options that will be used in {@link #parseForCompile(ResolvedJavaMethod)}
 */
@SuppressWarnings("try")
protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
    boolean useCache = !forceCompile && getArgumentToBind() == null;
    if (useCache && graph == null) {
        InstalledCode cached = cache.get(installedCodeOwner);
        if (cached != null) {
            if (cached.isValid()) {
                return cached;
            }
        }
    }
    // loop for retrying compilation
    for (int retry = 0; retry <= BAILOUT_RETRY_LIMIT; retry++) {
        final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
        InstalledCode installedCode = null;
        StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
        DebugContext debug = graphToCompile.getDebug();
        try (AllocSpy spy = AllocSpy.open(installedCodeOwner);
            DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
            CompilationPrinter printer = CompilationPrinter.begin(options, id, installedCodeOwner, INVOCATION_ENTRY_BCI);
            CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(graphToCompile.compilationId()), id, options);
            printer.finish(compResult);
            try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
                DebugContext.Activation a = debug.activate()) {
                try {
                    if (installAsDefault) {
                        installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
                    } else {
                        installedCode = addMethod(debug, installedCodeOwner, compResult);
                    }
                    if (installedCode == null) {
                        throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
                    }
                } catch (BailoutException e) {
                    if (retry < BAILOUT_RETRY_LIMIT && graph == null && !e.isPermanent()) {
                        // retry (if there is no predefined graph)
                        TTY.println(String.format("Restart compilation %s (%s) due to a non-permanent bailout!", installedCodeOwner, id));
                        continue;
                    }
                    throw e;
                }
            } catch (Throwable e) {
                throw debug.handle(e);
            }
        } catch (Throwable e) {
            throw debug.handle(e);
        }
        if (useCache) {
            cache.put(installedCodeOwner, installedCode);
        }
        return installedCode;
    }
    throw GraalError.shouldNotReachHere();
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) DebugContext(org.graalvm.compiler.debug.DebugContext) BailoutException(jdk.vm.ci.code.BailoutException) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) CompilationPrinter(org.graalvm.compiler.core.CompilationPrinter) InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult)

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