for (int i=osrFPoff; i>=methFPoff-8; i-=4) { VM.sysWriteHex(VM_Magic.objectAsAddress(stack).add(i)); VM.sysWrite(" : "); VM.sysWriteHex(stack[i<<2]); VM.sysWriteln();
for (Offset o =osrFPoff; o.sGE(methFPoff.sub(2*BYTES_IN_ADDRESS)); o=o.sub(BYTES_IN_ADDRESS)) { VM.sysWriteHex(VM_Magic.objectAsAddress(stack).add(o)); VM.sysWrite(" : "); VM.sysWriteHex(VM_Magic.getWordAtOffset(stack, o).toAddress()); VM.sysWriteln();
  public OSR_ExecutionState extractState(VM_Thread thread,                                  int osrFPoff,                                  int methFPoff,                                  int cmid) {  /* perform machine and compiler dependent operations here   * osrFPoff is the fp offset of    * VM_OptSaveVolatile.OPT_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.stack;    // get registers for the caller ( real method )    OSR_TempRegisters registers =       new OSR_TempRegisters(thread.contextRegisters);    if (VM.VerifyAssertions) {      int foocmid = VM_Magic.getIntAtOffset(stack,                                 methFPoff + STACKFRAME_METHOD_ID_OFFSET);      if (foocmid != cmid) {        for (int i=osrFPoff; i>=methFPoff-8; i-=4) {          VM.sysWriteHex(VM_Magic.objectAsAddress(stack).add(i));          VM.sysWrite(" : "); VM.sysWriteHex(stack[i<<2]); VM.sysWriteln();        }                VM_CompiledMethod cm = VM_CompiledMethods.getCompiledMethod(cmid);        VM.sysWriteln("unmatch method, it should be "+cm.getMethod());        VM_CompiledMethod foo = VM_CompiledMethods.getCompiledMethod(foocmid);        VM.sysWriteln("but now it is "+foo.getMethod());        walkOnStack(stack, osrFPoff);         }      VM._assert(foocmid == cmid);    }    VM_OptCompiledMethod fooCM =       (VM_OptCompiledMethod)VM_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 = VM_Magic.objectAsAddress(stack).add(methFPoff);    Address nextIP     = VM_Magic.getNextInstructionAddress(methFP);    int ipOffset = fooCM.getInstructionOffset(nextIP);    VM.enableGC();    VM_OptMachineCodeMap fooMCmap = fooCM.getMCMap();        OSR_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 = VM_Magic.getIntAtOffset(stack,                                 osrFPoff + STACKFRAME_METHOD_ID_OFFSET);      VM_CompiledMethod bufCM =         VM_CompiledMethods.getCompiledMethod(bufCMID);      // OPT_SaveVolatile can only be compiled by OPT compiler      if (VM.VerifyAssertions)         VM._assert(bufCM instanceof VM_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.     OSR_ExecutionState state = getExecStateSequence(thread,                                                    stack,                                                    ipOffset,                                                    methFPoff,                                                    cmid,                                                    osrFPoff,                                                    registers,                                                    fooOSRMap);    // reverse callerState points    OSR_ExecutionState prevState = null;    OSR_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");      OSR_ExecutionState temp = state;      while (temp != null) {        VM.sysWriteln(temp.toString());        temp = temp.callerState;      }    }    return state;  }