asm.emitMOV_Reg_RegInd(S0, FP);  VM_ProcessorLocalState.emitMoveRegToField(asm, VM_Entrypoints.framePointerOffset, S0);
  static VM_MachineCode generateGlueCodeForNative ( int compiledMethodId, VM_Method method ) {    VM_Assembler asm	 = new VM_Assembler(100);   // some size for the instruction array    int nativeIP         = method.getNativeIP();    // recompute some constants    int parameterWords   = method.getParameterWords();    // Meaning of constant offset into frame:    // STACKFRAME_HEADER_SIZE =  12              (CHECK ??)    // SAVED_GPRS = 4 words/registers    // Stack frame:    //        on entry          after prolog    //    //      high address	high address    //      |          |	|          | Caller frame    //      |          |	|          |    // +    |arg 0     |	|arg 0     |    -> firstParameterOffset    // +    |arg 1     |	|arg 1     |    // +    |...       |	|...       |    // +8   |arg n-1   |	|arg n-1   |        // +4   |returnAddr|	|returnAddr|    //  0   +	       +	+saved FP  + <---- FP for glue frame    // -4   |	       |	|methodID  |    // -8   |	       |	|saved EDI |    -> STACKFRAME_BODY_OFFSET = -8    // -C   |	       |	|saved EBX |    // -10  |	       |	|returnAddr|  (return from OutOfLine to generated epilog)        // -14  |	       |	|saved PR  |    // -18  |	       |	|arg n-1   |  reordered args to native method    // -1C  |	       |	| ...      |  ...    // -20  |	       |	|arg 1     |  ...    // -24  |	       |	|arg 0     |  ...    // -28  |	       |	|class/obj |  required second arg to native method    // -2C  |	       |	|jniEnv    |  required first arg to native method    // -30  |	       |	|          |        //      |	       |	|          |        //      |	       |	|          |        //       low address	 low address    if (VM.TraceCompilation)      VM.sysWrite("VM_JNICompiler: begin compiling native " + method + "\n");    // TODO:  check and resize stack once on the lowest Java to C transition    // on the stack.  Not needed if we use the thread original stack    // Fill in frame header - similar to normal prolog    prepareStackHeader(asm, method, compiledMethodId);    // Process the arguments - specific to method being called    storeParametersForLintel(asm, method);        // load address of native into S0    asm.emitMOV_Reg_Imm (S0, nativeIP);      // branch to outofline code in bootimage    asm.emitCALL_RegDisp(JTOC, VM_Entrypoints.invokeNativeFunctionInstructionsOffset);    // return here from VM_OutOfLineMachineCode upon return from native code    // PR and RVM JTOC restored, T0,T1 contain return from native call    //If the return type is reference, look up the real value in the JNIref array     // S0 <- VM_Thread    VM_ProcessorLocalState.emitMoveFieldToReg(asm, S0,                                              VM_Entrypoints.activeThreadOffset);    asm.emitMOV_Reg_RegDisp (S0, S0, VM_Entrypoints.jniEnvOffset);        // S0 <- jniEnv        if (method.getReturnType().isReferenceType()) {      asm.emitADD_Reg_RegDisp(T0, S0, VM_Entrypoints.JNIRefsOffset);      // T0 <- address of entry (not index)      asm.emitMOV_Reg_RegInd (T0, T0);   // get the reference    } else if (method.getReturnType().isLongType()) {      asm.emitPUSH_Reg(T1);    // need to use T1 in popJNIrefForEpilog and to swap order T0-T1      }    // CHECK - may not do anything - leave below will remove whole frame    // asm.emitPUSH_Reg(T0);                // push the return value onto the stack    // pop frame in JNIRefs array (need to use    // S0 <- VM_Thread    VM_ProcessorLocalState.emitMoveFieldToReg(asm, S0,                                              VM_Entrypoints.activeThreadOffset);    asm.emitMOV_Reg_RegDisp (S0, S0, VM_Entrypoints.jniEnvOffset);        // S0 <- jniEnv        popJNIrefForEpilog(asm);                                        // then swap order of T0 and T1 for long    if (method.getReturnType().isLongType()) {      asm.emitMOV_Reg_Reg(T1, T0);        asm.emitPOP_Reg(T0);    }    // CHECK EXCEPTION AND BRANCH TO ATHROW CODE OR RETURN NORMALLY    // get pending exception from JNIEnv    VM_ProcessorLocalState.emitMoveFieldToReg(asm, S0,                                              VM_Entrypoints.activeThreadOffset);    asm.emitMOV_Reg_RegDisp (S0,  S0, VM_Entrypoints.jniEnvOffset);        	  // S0 <- jniEnv        asm.emitMOV_Reg_RegDisp (EBX, S0, VM_Entrypoints.JNIPendingExceptionOffset);  // EBX <- JNIPendingException    asm.emitMOV_RegDisp_Imm (S0, VM_Entrypoints.JNIPendingExceptionOffset, 0);    // clear the current pending exception    asm.emitCMP_Reg_Imm(EBX, 0);   // check for exception pending:  JNIPendingException = non zero    VM_ForwardReference fr = asm.forwardJcc(asm.EQ);            // Br if yes    // if pending exception, discard the return value and current stack frame    // then jump to athrow     asm.emitMOV_Reg_Reg(T0, EBX);    // after the next two instructions, sp will point to the return address to the caller of the native method    // and fp will point to the caller frame as well, so it appears as if the exception    // occurs in the caller at the call site    asm.emitMOV_Reg_Reg(SP, FP);    asm.emitPOP_Reg(FP);    // don't use CALL since it will push on the stack frame the return address to here     asm.emitJMP_RegDisp(JTOC, VM_Entrypoints.athrowOffset);    fr.resolve(asm);  // branch to here if no exception     // no exception, proceed to return to caller        asm.emitMOV_Reg_RegInd(S0, FP);       // restore caller FP into VM_Processor.framepointer    VM_ProcessorLocalState.emitMoveRegToField(asm,                                              VM_Entrypoints.framePointerOffset,                                              S0);    asm.emitMOV_Reg_RegDisp (EBX, FP, EBX_SAVE_OFFSET);    // restore nonvolatile ebx register    asm.emitMOV_Reg_RegDisp (JTOC, FP, EDI_SAVE_OFFSET);   // restore nonvolatile EDI/JTOC register    asm.emitMOV_Reg_Reg(SP, FP);                           // discard current stack frame    asm.emitPOP_Reg(FP);    // return to caller     // pop parameters from stack (Note that parameterWords does not include "this")    if (method.isStatic())      asm.emitRET_Imm(parameterWords << LG_WORDSIZE);     else      asm.emitRET_Imm((parameterWords+1) << LG_WORDSIZE);     if (VM.TraceCompilation)      VM.sysWrite("VM_Compiler: end compiling native " + method + "\n");        // return asm.makeMachineCode();    return new VM_MachineCode(asm.getMachineCodes(), null);  }