Search in sources :

Example 1 with Goto

use of org.jikesrvm.osr.bytecodes.Goto in project JikesRVM by JikesRVM.

the class ExecutionState method generatePrologue.

/**
 * Goes through variable elements and produces specialized
 * prologue using pseudo-bytecode.
 *
 * @return the specialized prologue
 */
public byte[] generatePrologue() {
    int size = varElms.size();
    this.objs = new Object[size];
    this.objnum = 0;
    this.rid = ObjectHolder.handinRefs(this.objs);
    PseudoBytecode head = new Nop();
    PseudoBytecode tail = head;
    int elmcount = 0;
    // restore "this"
    if (!this.meth.isStatic()) {
        VariableElement var = varElms.get(elmcount);
        tail = processElement(var, tail, elmcount);
        elmcount++;
        if (VM.VerifyAssertions) {
            VM._assert(var.isLocal() && (var.getNumber() == 0));
        }
    }
    // restore other parameters,
    int paranum = this.meth.getParameterTypes().length;
    for (int i = 0; i < paranum; i++) {
        VariableElement var = varElms.get(elmcount);
        tail = processElement(var, tail, elmcount);
        elmcount++;
        if (VM.VerifyAssertions) {
            VM._assert(var.isLocal());
        // the number may not match because of long and double type
        }
    }
    // ok, ready to indicate param initialized, thread switch
    // and stack overflow check happens here
    tail.next = new ParamInitEnd();
    tail = tail.next;
    // were sorted
    for (; elmcount < size; elmcount++) {
        VariableElement var = varElms.get(elmcount);
        tail = processElement(var, tail, elmcount);
    }
    if (this.objnum != 0) {
        tail.next = new LoadIntConst(this.rid);
        tail = tail.next;
        tail.next = new InvokeStatic(CLEANREFS);
        tail = tail.next;
    } else {
        ObjectHolder.cleanRefs(this.rid);
    }
    // default situation
    int branchTarget = this.bcIndex;
    /* when this method must start with a call of callee,
     * we are using invokeCompiledMethod,
     */
    if (callee_cmid != -1) {
        // remember the callee's cmid, and the index of original index
        tail.next = new InvokeCompiledMethod(callee_cmid, this.bcIndex);
        tail = tail.next;
        // if this method needs a call, than we must jump to
        // the instruction after the call.
        BytecodeStream bcodes = this.meth.getBytecodes();
        bcodes.reset(this.bcIndex);
        int code = bcodes.nextInstruction();
        if (JBC_isJava6Call(code)) {
            branchTarget = this.bcIndex + JBC_length(code);
        } else {
            if (VM.VerifyAssertions) {
                String msg = "ExecutionState: unknown bytecode " + code + " at " + this.bcIndex + "@" + this.meth;
                VM._assert(VM.NOT_REACHED, msg);
            }
        }
    }
    // add goto statement, be careful, after goto
    // there may be several pop instructions
    int pops = computeStackHeight(head);
    // preserve space
    branchTarget += pops;
    {
        Goto togo = new Goto(branchTarget);
        int osize = togo.getSize();
        togo.patch(branchTarget + osize);
        int nsize = togo.getSize();
        if (nsize != osize) {
            togo.patch(branchTarget + nsize);
        }
        tail.next = togo;
        tail = tail.next;
    }
    // compute stack heights and padding pops
    tail = adjustStackHeight(tail, pops);
    int bsize = paddingBytecode(head);
    byte[] prologue = generateBinaries(head, bsize);
    // clean fields
    this.objs = null;
    this.objnum = 0;
    return prologue;
}
Also used : PseudoBytecode(org.jikesrvm.osr.bytecodes.PseudoBytecode) Goto(org.jikesrvm.osr.bytecodes.Goto) LoadIntConst(org.jikesrvm.osr.bytecodes.LoadIntConst) BytecodeStream(org.jikesrvm.classloader.BytecodeStream) ParamInitEnd(org.jikesrvm.osr.bytecodes.ParamInitEnd) InvokeCompiledMethod(org.jikesrvm.osr.bytecodes.InvokeCompiledMethod) Nop(org.jikesrvm.osr.bytecodes.Nop) InvokeStatic(org.jikesrvm.osr.bytecodes.InvokeStatic)

Aggregations

BytecodeStream (org.jikesrvm.classloader.BytecodeStream)1 Goto (org.jikesrvm.osr.bytecodes.Goto)1 InvokeCompiledMethod (org.jikesrvm.osr.bytecodes.InvokeCompiledMethod)1 InvokeStatic (org.jikesrvm.osr.bytecodes.InvokeStatic)1 LoadIntConst (org.jikesrvm.osr.bytecodes.LoadIntConst)1 Nop (org.jikesrvm.osr.bytecodes.Nop)1 ParamInitEnd (org.jikesrvm.osr.bytecodes.ParamInitEnd)1 PseudoBytecode (org.jikesrvm.osr.bytecodes.PseudoBytecode)1