Search in sources :

Example 1 with BytecodeStream

use of org.graalvm.compiler.bytecode.BytecodeStream in project graal by oracle.

the class GraalOSRTestBase method getBackedgeBCI.

/**
 * Returns the target BCI of the first bytecode backedge. This is where HotSpot triggers
 * on-stack-replacement in case the backedge counter overflows.
 */
private static int getBackedgeBCI(DebugContext debug, ResolvedJavaMethod method) {
    Bytecode code = new ResolvedJavaMethodBytecode(method);
    BytecodeStream stream = new BytecodeStream(code.getCode());
    OptionValues options = debug.getOptions();
    BciBlockMapping bciBlockMapping = BciBlockMapping.create(stream, code, options, debug);
    for (BciBlock block : bciBlockMapping.getBlocks()) {
        if (block.startBci != -1) {
            int bci = block.startBci;
            for (BciBlock succ : block.getSuccessors()) {
                if (succ.startBci != -1) {
                    int succBci = succ.startBci;
                    if (succBci < bci) {
                        // back edge
                        return succBci;
                    }
                }
            }
        }
    }
    TTY.println("Cannot find loop back edge with bytecode loops at:%s", Arrays.toString(bciBlockMapping.getLoopHeaders()));
    TTY.println(new BytecodeDisassembler().disassemble(code));
    return -1;
}
Also used : BytecodeDisassembler(org.graalvm.compiler.bytecode.BytecodeDisassembler) OptionValues(org.graalvm.compiler.options.OptionValues) BciBlockMapping(org.graalvm.compiler.java.BciBlockMapping) BytecodeStream(org.graalvm.compiler.bytecode.BytecodeStream) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock)

Aggregations

Bytecode (org.graalvm.compiler.bytecode.Bytecode)1 BytecodeDisassembler (org.graalvm.compiler.bytecode.BytecodeDisassembler)1 BytecodeStream (org.graalvm.compiler.bytecode.BytecodeStream)1 ResolvedJavaMethodBytecode (org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode)1 BciBlockMapping (org.graalvm.compiler.java.BciBlockMapping)1 BciBlock (org.graalvm.compiler.java.BciBlockMapping.BciBlock)1 OptionValues (org.graalvm.compiler.options.OptionValues)1