Search in sources :

Example 11 with ResolvedJavaMethod

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

the class ForeignCallStub method getGraph.

/**
 * Creates a graph for this stub.
 * <p>
 * If the stub returns an object, the graph created corresponds to this pseudo code:
 *
 * <pre>
 *     Object foreignFunctionStub(args...) {
 *         foreignFunction(currentThread,  args);
 *         if (clearPendingException(thread())) {
 *             getAndClearObjectResult(thread());
 *             DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
 *         }
 *         return verifyObject(getAndClearObjectResult(thread()));
 *     }
 * </pre>
 *
 * If the stub returns a primitive or word, the graph created corresponds to this pseudo code
 * (using {@code int} as the primitive return type):
 *
 * <pre>
 *     int foreignFunctionStub(args...) {
 *         int result = foreignFunction(currentThread,  args);
 *         if (clearPendingException(thread())) {
 *             DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
 *         }
 *         return result;
 *     }
 * </pre>
 *
 * If the stub is void, the graph created corresponds to this pseudo code:
 *
 * <pre>
 *     void foreignFunctionStub(args...) {
 *         foreignFunction(currentThread,  args);
 *         if (clearPendingException(thread())) {
 *             DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
 *         }
 *     }
 * </pre>
 *
 * In each example above, the {@code currentThread} argument is the C++ JavaThread value (i.e.,
 * %r15 on AMD64) and is only prepended if {@link #prependThread} is true.
 */
@Override
@SuppressWarnings("try")
protected StructuredGraph getGraph(DebugContext debug, CompilationIdentifier compilationId) {
    WordTypes wordTypes = providers.getWordTypes();
    Class<?>[] args = linkage.getDescriptor().getArgumentTypes();
    boolean isObjectResult = !LIRKind.isValue(linkage.getOutgoingCallingConvention().getReturn());
    try {
        ResolvedJavaMethod thisMethod = providers.getMetaAccess().lookupJavaMethod(ForeignCallStub.class.getDeclaredMethod("getGraph", DebugContext.class, CompilationIdentifier.class));
        GraphKit kit = new GraphKit(debug, thisMethod, providers, wordTypes, providers.getGraphBuilderPlugins(), compilationId, toString());
        StructuredGraph graph = kit.getGraph();
        ParameterNode[] params = createParameters(kit, args);
        ReadRegisterNode thread = kit.append(new ReadRegisterNode(providers.getRegisters().getThreadRegister(), wordTypes.getWordKind(), true, false));
        ValueNode result = createTargetCall(kit, params, thread);
        kit.createInvoke(StubUtil.class, "handlePendingException", thread, ConstantNode.forBoolean(isObjectResult, graph));
        if (isObjectResult) {
            InvokeNode object = kit.createInvoke(HotSpotReplacementsUtil.class, "getAndClearObjectResult", thread);
            result = kit.createInvoke(StubUtil.class, "verifyObject", object);
        }
        kit.append(new ReturnNode(linkage.getDescriptor().getResultType() == void.class ? null : result));
        debug.dump(DebugContext.VERBOSE_LEVEL, graph, "Initial stub graph");
        kit.inlineInvokes();
        new RemoveValueProxyPhase().apply(graph);
        debug.dump(DebugContext.VERBOSE_LEVEL, graph, "Stub graph before compilation");
        return graph;
    } catch (Exception e) {
        throw GraalError.shouldNotReachHere(e);
    }
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) WordTypes(org.graalvm.compiler.word.WordTypes) DebugContext(org.graalvm.compiler.debug.DebugContext) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) GraphKit(org.graalvm.compiler.replacements.GraphKit) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ReadRegisterNode(org.graalvm.compiler.replacements.nodes.ReadRegisterNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 12 with ResolvedJavaMethod

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

the class VMErrorNode method generate.

@Override
public void generate(NodeLIRBuilderTool gen) {
    String whereString;
    if (stateBefore() != null) {
        String nl = CodeUtil.NEW_LINE;
        StringBuilder sb = new StringBuilder("in compiled code associated with frame state:");
        FrameState fs = stateBefore();
        while (fs != null) {
            Bytecode.appendLocation(sb.append(nl).append("\t"), fs.getCode(), fs.bci);
            fs = fs.outerFrameState();
        }
        whereString = sb.toString();
    } else {
        ResolvedJavaMethod method = graph().method();
        whereString = "in compiled code for " + (method == null ? graph().toString() : method.format("%H.%n(%p)"));
    }
    LIRKind wordKind = gen.getLIRGeneratorTool().getLIRKind(StampFactory.pointer());
    Value whereArg = gen.getLIRGeneratorTool().emitConstant(wordKind, new CStringConstant(whereString));
    Value formatArg = gen.getLIRGeneratorTool().emitConstant(wordKind, new CStringConstant(format));
    ForeignCallLinkage linkage = gen.getLIRGeneratorTool().getForeignCalls().lookupForeignCall(VM_ERROR);
    gen.getLIRGeneratorTool().emitForeignCall(linkage, null, whereArg, formatArg, gen.operand(value));
}
Also used : Value(jdk.vm.ci.meta.Value) LIRKind(org.graalvm.compiler.core.common.LIRKind) ForeignCallLinkage(org.graalvm.compiler.core.common.spi.ForeignCallLinkage) FrameState(org.graalvm.compiler.nodes.FrameState) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CStringConstant(org.graalvm.compiler.replacements.nodes.CStringConstant)

Example 13 with ResolvedJavaMethod

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

the class AbstractInliningPolicy method previousLowLevelGraphSize.

protected static int previousLowLevelGraphSize(InlineInfo info) {
    int size = 0;
    for (int i = 0; i < info.numberOfMethods(); i++) {
        ResolvedJavaMethod m = info.methodAt(i);
        ProfilingInfo profile = info.graph().getProfilingInfo(m);
        int compiledGraphSize = profile.getCompilerIRSize(StructuredGraph.class);
        if (compiledGraphSize > 0) {
            size += compiledGraphSize;
        }
    }
    return size;
}
Also used : ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 14 with ResolvedJavaMethod

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

the class GraphUtil method approxSourceStackTraceElement.

/**
 * Gets approximate stack trace elements for a bytecode position.
 */
public static StackTraceElement[] approxSourceStackTraceElement(BytecodePosition bytecodePosition) {
    ArrayList<StackTraceElement> elements = new ArrayList<>();
    BytecodePosition position = bytecodePosition;
    while (position != null) {
        ResolvedJavaMethod method = position.getMethod();
        if (method != null) {
            elements.add(method.asStackTraceElement(position.getBCI()));
        }
        position = position.getCaller();
    }
    return elements.toArray(new StackTraceElement[0]);
}
Also used : BytecodePosition(jdk.vm.ci.code.BytecodePosition) ArrayList(java.util.ArrayList) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 15 with ResolvedJavaMethod

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

the class HotSpotClassInitializationPlugin method shouldApply.

@Override
public boolean shouldApply(GraphBuilderContext builder, ResolvedJavaType type) {
    if (!builder.parsingIntrinsic()) {
        if (!type.isArray()) {
            ResolvedJavaMethod method = builder.getGraph().method();
            ResolvedJavaType methodHolder = method.getDeclaringClass();
            return !type.isAssignableFrom(methodHolder) || type.isInterface();
        } else if (!type.getComponentType().isPrimitive()) {
            // Always apply to object array types
            return true;
        }
    }
    return false;
}
Also used : 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