Search in sources :

Example 1 with EncodedOSRMap

use of org.jikesrvm.osr.EncodedOSRMap in project JikesRVM by JikesRVM.

the class OptExecutionStateExtractor method extractState.

@Override
public ExecutionState extractState(RVMThread thread, Offset osrFPoff, Offset methFPoff, int cmid) {
    /* perform machine and compiler dependent operations here
    * osrFPoff is the fp offset of
    * OptSaveVolatile.threadSwithFrom<...>
    *
    *  (stack grows downward)
    *          foo
    *     |->     <-- methFPoff
    *     |
    *     |    <tsfrom>
    *     |--     <-- osrFPoff
    *
    *
    * The <tsfrom> saves all volatiles, nonvolatiles, and scratch
    * registers. All register values for 'foo' can be obtained from
    * the register save area of '<tsfrom>' method.
    */
    byte[] stack = thread.getStack();
    // get registers for the caller ( real method )
    TempRegisters registers = new TempRegisters(thread.getContextRegisters());
    if (VM.VerifyAssertions) {
        int foocmid = Magic.getIntAtOffset(stack, methFPoff.plus(STACKFRAME_METHOD_ID_OFFSET));
        if (foocmid != cmid) {
            for (Offset o = osrFPoff; o.sGE(methFPoff.minus(2 * BYTES_IN_ADDRESS)); o = o.minus(BYTES_IN_ADDRESS)) {
                VM.sysWriteHex(Magic.objectAsAddress(stack).plus(o));
                VM.sysWrite(" : ");
                VM.sysWriteHex(Magic.getWordAtOffset(stack, o).toAddress());
                VM.sysWriteln();
            }
            CompiledMethod cm = CompiledMethods.getCompiledMethod(cmid);
            VM.sysWriteln("unmatch method, it should be " + cm.getMethod());
            CompiledMethod foo = CompiledMethods.getCompiledMethod(foocmid);
            VM.sysWriteln("but now it is " + foo.getMethod());
            walkOnStack(stack, osrFPoff);
        }
        VM._assert(foocmid == cmid);
    }
    OptCompiledMethod fooCM = (OptCompiledMethod) CompiledMethods.getCompiledMethod(cmid);
    /* Following code get the machine code offset to the
     * next instruction. All operation of the stack frame
     * are kept in GC critical section.
     * All code in the section should not cause any GC
     * activities, and avoid lazy compilation.
     */
    // get the next machine code offset of the real method
    VM.disableGC();
    Address methFP = Magic.objectAsAddress(stack).plus(methFPoff);
    Address nextIP = Magic.getNextInstructionAddress(methFP);
    Offset ipOffset = fooCM.getInstructionOffset(nextIP);
    VM.enableGC();
    EncodedOSRMap fooOSRMap = fooCM.getOSRMap();
    /* get register reference map from OSR map
     * we are using this map to convert addresses to objects,
     * thus we can operate objects out of GC section.
     */
    int regmap = fooOSRMap.getRegisterMapForMCOffset(ipOffset);
    {
        int bufCMID = Magic.getIntAtOffset(stack, osrFPoff.plus(STACKFRAME_METHOD_ID_OFFSET));
        CompiledMethod bufCM = CompiledMethods.getCompiledMethod(bufCMID);
        // SaveVolatile can only be compiled by OPT compiler
        if (VM.VerifyAssertions) {
            VM._assert(bufCM instanceof OptCompiledMethod);
        }
        restoreValuesFromOptSaveVolatile(stack, osrFPoff, registers, regmap, bufCM);
    }
    // return a list of states: from caller to callee
    // if the osr happens in an inlined method, the state is
    // a chain of recoverd methods.
    ExecutionState state = getExecStateSequence(thread, stack, ipOffset, methFPoff, cmid, osrFPoff, registers, fooOSRMap);
    // reverse callerState points
    ExecutionState prevState = null;
    ExecutionState nextState = state;
    while (nextState != null) {
        // 1. current node
        state = nextState;
        // 1. hold the next state first
        nextState = nextState.callerState;
        // 2. redirect pointer
        state.callerState = prevState;
        // 3. move prev to current
        prevState = state;
    }
    if (VM.TraceOnStackReplacement) {
        VM.sysWriteln("OptExecutionState : recovered states");
        ExecutionState temp = state;
        while (temp != null) {
            VM.sysWriteln(temp.toString());
            temp = temp.callerState;
        }
    }
    return state;
}
Also used : OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) ExecutionState(org.jikesrvm.osr.ExecutionState) Address(org.vmmagic.unboxed.Address) EncodedOSRMap(org.jikesrvm.osr.EncodedOSRMap) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Offset(org.vmmagic.unboxed.Offset)

Example 2 with EncodedOSRMap

use of org.jikesrvm.osr.EncodedOSRMap in project JikesRVM by JikesRVM.

the class OptExecutionStateExtractor method extractState.

@Override
public ExecutionState extractState(RVMThread thread, Offset osrFPoff, Offset methFPoff, int cmid) {
    /* perform machine and compiler dependent operations here
    * osrFPoff is the fp offset of
    * OptSaveVolatile.threadSwithFrom<...>
    *
    *  (stack grows downward)
    *          foo
    *     |->     <-- methFPoff
    *     |
    *     |    <tsfrom>
    *     |--     <-- osrFPoff
    *
    *
    * The threadSwitchFrom method saves all volatiles, nonvolatiles, and
    * scratch registers. All register values for 'foo' can be obtained
    * from the register save area of '<tsfrom>' method.
    */
    byte[] stack = thread.getStack();
    // get registers for the caller ( real method )
    TempRegisters registers = new TempRegisters(thread.getContextRegisters());
    if (VM.VerifyAssertions) {
        int foocmid = Magic.getIntAtOffset(stack, methFPoff.plus(STACKFRAME_METHOD_ID_OFFSET));
        if (foocmid != cmid) {
            CompiledMethod cm = CompiledMethods.getCompiledMethod(cmid);
            VM.sysWriteln("unmatch method, it should be " + cm.getMethod());
            CompiledMethod foo = CompiledMethods.getCompiledMethod(foocmid);
            VM.sysWriteln("but now it is " + foo.getMethod());
            walkOnStack(stack, osrFPoff);
        }
        VM._assert(foocmid == cmid);
    }
    OptCompiledMethod fooCM = (OptCompiledMethod) CompiledMethods.getCompiledMethod(cmid);
    /* Following code get the machine code offset to the
     * next instruction. All operation of the stack frame
     * are kept in GC critical section.
     * All code in the section should not cause any GC
     * activities, and avoid lazy compilation.
     */
    /* Following code is architecture dependent. In IA32, the return address
     * saved in caller stack frames, so use osrFP to get the next instruction
     * address of foo
     */
    // get the next machine code offset of the real method
    VM.disableGC();
    Address osrFP = Magic.objectAsAddress(stack).plus(osrFPoff);
    Address nextIP = Magic.getReturnAddressUnchecked(osrFP);
    Offset ipOffset = fooCM.getInstructionOffset(nextIP);
    VM.enableGC();
    EncodedOSRMap fooOSRMap = fooCM.getOSRMap();
    /* get register reference map from OSR map
     * we are using this map to convert addresses to objects,
     * thus we can operate objects out of GC section.
     */
    int regmap = fooOSRMap.getRegisterMapForMCOffset(ipOffset);
    {
        int bufCMID = Magic.getIntAtOffset(stack, osrFPoff.plus(STACKFRAME_METHOD_ID_OFFSET));
        CompiledMethod bufCM = CompiledMethods.getCompiledMethod(bufCMID);
        // SaveVolatile can only be compiled by OPT compiler
        if (VM.VerifyAssertions)
            VM._assert(bufCM instanceof OptCompiledMethod);
        restoreValuesFromOptSaveVolatile(stack, osrFPoff, registers, regmap, bufCM);
    }
    // return a list of states: from caller to callee
    // if the osr happens in an inlined method, the state is
    // a chain of recoverd methods.
    ExecutionState state = getExecStateSequence(thread, stack, ipOffset, methFPoff, cmid, osrFPoff, registers, fooOSRMap);
    // reverse callerState points, it becomes callee -> caller
    ExecutionState prevState = null;
    ExecutionState nextState = state;
    while (nextState != null) {
        // 1. current node
        state = nextState;
        // 1. hold the next state first
        nextState = nextState.callerState;
        // 2. redirect pointer
        state.callerState = prevState;
        // 3. move prev to current
        prevState = state;
    }
    if (VM.TraceOnStackReplacement) {
        VM.sysWriteln("OptExecState : recovered states " + thread.toString());
        ExecutionState temp = state;
        do {
            VM.sysWriteln(temp.toString());
            temp = temp.callerState;
        } while (temp != null);
    }
    return state;
}
Also used : OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) ExecutionState(org.jikesrvm.osr.ExecutionState) Address(org.vmmagic.unboxed.Address) EncodedOSRMap(org.jikesrvm.osr.EncodedOSRMap) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Offset(org.vmmagic.unboxed.Offset)

Aggregations

CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)2 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)2 EncodedOSRMap (org.jikesrvm.osr.EncodedOSRMap)2 ExecutionState (org.jikesrvm.osr.ExecutionState)2 Address (org.vmmagic.unboxed.Address)2 Offset (org.vmmagic.unboxed.Offset)2