Search in sources :

Example 6 with JavaMethod

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

the class ArrayCopyIntrinsificationTest method getCode.

@Override
protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph g, boolean forceCompile, boolean installAsDefault, OptionValues options) {
    StructuredGraph graph = g == null ? parseForCompile(method) : g;
    int nodeCount = graph.getNodeCount();
    InstalledCode result = super.getCode(method, graph, forceCompile, installAsDefault, options);
    boolean graphWasProcessed = nodeCount != graph.getNodeCount();
    if (graphWasProcessed) {
        if (mustIntrinsify) {
            for (Node node : graph.getNodes()) {
                if (node instanceof Invoke) {
                    Invoke invoke = (Invoke) node;
                    Assert.assertTrue(invoke.callTarget() instanceof DirectCallTargetNode);
                    LoweredCallTargetNode directCall = (LoweredCallTargetNode) invoke.callTarget();
                    JavaMethod callee = directCall.targetMethod();
                    if (callee.getDeclaringClass().equals(getMetaAccess().lookupJavaType(System.class)) && callee.getName().equals("arraycopy")) {
                    // A partial snippet (e.g., ArrayCopySnippets.checkcastArraycopy) may
                    // call the original arraycopy method
                    } else {
                        Assert.assertTrue(callee.toString(), callee.getName().equals("<init>"));
                        Assert.assertTrue(getMetaAccess().lookupJavaType(ArrayIndexOutOfBoundsException.class).equals(callee.getDeclaringClass()) || getMetaAccess().lookupJavaType(NullPointerException.class).equals(callee.getDeclaringClass()));
                    }
                }
            }
        } else {
            boolean found = false;
            for (Node node : graph.getNodes()) {
                if (node instanceof Invoke) {
                    Invoke invoke = (Invoke) node;
                    LoweredCallTargetNode directCall = (LoweredCallTargetNode) invoke.callTarget();
                    JavaMethod callee = directCall.targetMethod();
                    if (callee.getDeclaringClass().equals(getMetaAccess().lookupJavaType(System.class)) && callee.getName().equals("arraycopy")) {
                        found = true;
                    } else {
                        fail("found invoke to some method other than arraycopy: " + callee);
                    }
                }
            }
            Assert.assertTrue("did not find invoke to arraycopy", found);
        }
    }
    return result;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) Node(org.graalvm.compiler.graph.Node) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) InstalledCode(jdk.vm.ci.code.InstalledCode) JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 7 with JavaMethod

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

the class BytecodeDisassembler method getInvokedMethodAt.

public static JavaMethod getInvokedMethodAt(ResolvedJavaMethod method, int invokeBci) {
    if (method.getCode() == null) {
        return null;
    }
    ConstantPool cp = method.getConstantPool();
    BytecodeStream stream = new BytecodeStream(method.getCode());
    int opcode = stream.currentBC();
    while (opcode != Bytecodes.END) {
        int bci = stream.currentBCI();
        if (bci == invokeBci) {
            if (stream.nextBCI() > bci + 1) {
                switch(opcode) {
                    case INVOKEVIRTUAL:
                    case INVOKESPECIAL:
                    case INVOKESTATIC:
                        {
                            int cpi = stream.readCPI();
                            JavaMethod callee = cp.lookupMethod(cpi, opcode);
                            return callee;
                        }
                    case INVOKEINTERFACE:
                        {
                            int cpi = stream.readCPI();
                            JavaMethod callee = cp.lookupMethod(cpi, opcode);
                            return callee;
                        }
                    case INVOKEDYNAMIC:
                        {
                            int cpi = stream.readCPI4();
                            JavaMethod callee = cp.lookupMethod(cpi, opcode);
                            return callee;
                        }
                    default:
                        throw new InternalError(BytecodeDisassembler.disassembleOne(method, invokeBci));
                }
            }
        }
        stream.next();
        opcode = stream.currentBC();
    }
    return null;
}
Also used : ConstantPool(jdk.vm.ci.meta.ConstantPool) JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 8 with JavaMethod

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

the class BytecodeParser method genInvokeDynamic.

protected void genInvokeDynamic(int cpi, int opcode) {
    JavaMethod target = lookupMethod(cpi, opcode);
    genInvokeDynamic(target);
}
Also used : JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 9 with JavaMethod

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

the class BytecodeParser method genInvokeSpecial.

protected void genInvokeSpecial(int cpi, int opcode) {
    JavaMethod target = lookupMethod(cpi, opcode);
    genInvokeSpecial(target);
}
Also used : JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 10 with JavaMethod

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

the class HotSpotGraalCompiler method fmt.

/**
 * Wraps {@code obj} in a {@link Formatter} that standardizes formatting for certain objects.
 */
static Formattable fmt(Object obj) {
    return new Formattable() {

        @Override
        public void formatTo(Formatter buf, int flags, int width, int precision) {
            if (obj instanceof Throwable) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ((Throwable) obj).printStackTrace(new PrintStream(baos));
                buf.format("%s", baos.toString());
            } else if (obj instanceof StackTraceElement[]) {
                for (StackTraceElement e : (StackTraceElement[]) obj) {
                    buf.format("\t%s%n", e);
                }
            } else if (obj instanceof JavaMethod) {
                buf.format("%s", str((JavaMethod) obj));
            } else {
                buf.format("%s", obj);
            }
        }
    };
}
Also used : PrintStream(java.io.PrintStream) Formatter(java.util.Formatter) JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Formattable(java.util.Formattable)

Aggregations

JavaMethod (jdk.vm.ci.meta.JavaMethod)13 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)12 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)3 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 Formattable (java.util.Formattable)1 Formatter (java.util.Formatter)1 InstalledCode (jdk.vm.ci.code.InstalledCode)1 ConstantPool (jdk.vm.ci.meta.ConstantPool)1 CompilationResult (org.graalvm.compiler.code.CompilationResult)1 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)1 DebugConfig.asJavaMethod (org.graalvm.compiler.debug.DebugConfig.asJavaMethod)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 Graph (org.graalvm.compiler.graph.Graph)1 Node (org.graalvm.compiler.graph.Node)1 DirectCallTargetNode (org.graalvm.compiler.nodes.DirectCallTargetNode)1 Invoke (org.graalvm.compiler.nodes.Invoke)1 LoweredCallTargetNode (org.graalvm.compiler.nodes.LoweredCallTargetNode)1