Program: 150244
Project: 150244
Buggy source:
/** 
 * Generate inline code sequence for specified method.
 * @param methodToBeCalled: method whose name indicates semantics of code to be generated
 * @return true if there was magic defined for the method
 */
private boolean generateInlineCode(VM_MethodReference methodToBeCalled){
  VM_Atom methodName=methodToBeCalled.getName();
  if (methodToBeCalled.getType() == VM_TypeReference.SysCall) {
    VM_TypeReference[] args=methodToBeCalled.getParameterTypes();
    int paramWords=methodToBeCalled.getParameterWords();
    int gp=FIRST_OS_PARAMETER_GPR;
    int fp=FIRST_OS_PARAMETER_FPR;
    int stackIndex=paramWords;
    for (int i=0; i < args.length; i++) {
      VM_TypeReference t=args[i];
      if (t.isLongType()) {
        stackIndex-=2;
        if (VM.BuildFor64Addr) {
          peekLong(gp,gp,stackIndex);
          gp++;
        }
 else {
          gp+=(gp + 1) & 0x01;
          peekInt(gp++,stackIndex);
          peekInt(gp++,stackIndex + 1);
        }
      }
 else       if (t.isFloatType()) {
        stackIndex-=1;
        peekFloat(fp++,stackIndex);
      }
 else       if (t.isDoubleType()) {
        stackIndex-=2;
        peekDouble(fp++,stackIndex);
      }
 else       if (t.isIntLikeType()) {
        stackIndex-=1;
        peekInt(gp++,stackIndex);
      }
 else {
        stackIndex-=1;
        peekAddr(gp++,stackIndex);
      }
    }
    if (VM.VerifyAssertions) {
      VM._assert(stackIndex == 0);
      VM._assert(gp - 1 <= LAST_OS_PARAMETER_GPR);
      VM._assert(fp - 1 <= LAST_OS_PARAMETER_FPR);
    }
    int paramBytes=(VM.BuildFor64Addr ? args.length : paramWords) * BYTES_IN_STACKSLOT;
    VM_Field ip=VM_Entrypoints.getSysCallField(methodName.toString());
    generateSysCall(paramBytes,ip);
    discardSlots(paramWords);
    VM_TypeReference rtype=methodToBeCalled.getReturnType();
    if (rtype.isIntLikeType()) {
      pushInt(T0);
    }
 else     if (rtype.isWordType() || rtype.isReferenceType()) {
      pushAddr(T0);
    }
 else     if (rtype.isDoubleType()) {
      pushDouble(FIRST_OS_PARAMETER_FPR);
    }
 else     if (rtype.isFloatType()) {
      pushFloat(FIRST_OS_PARAMETER_FPR);
    }
 else     if (rtype.isLongType()) {
      pushLong(T0,VM.BuildFor64Addr ? T0 : T1);
    }
  }
 else   if (methodName == VM_MagicNames.getFramePointer) {
    pushAddr(FP);
  }
 else   if (methodName == VM_MagicNames.getCallerFramePointer) {
    popAddr(T0);
    asm.emitLAddr(T1,STACKFRAME_FRAME_POINTER_OFFSET,T0);
    pushAddr(T1);
  }
 else   if (methodName == VM_MagicNames.setCallerFramePointer) {
    popAddr(T1);
    popAddr(T0);
    asm.emitSTAddr(T1,STACKFRAME_FRAME_POINTER_OFFSET,T0);
  }
 else   if (methodName == VM_MagicNames.getCompiledMethodID) {
    popAddr(T0);
    asm.emitLInt(T1,STACKFRAME_METHOD_ID_OFFSET,T0);
    pushInt(T1);
  }
 else   if (methodName == VM_MagicNames.setCompiledMethodID) {
    popInt(T1);
    popAddr(T0);
    asm.emitSTW(T1,STACKFRAME_METHOD_ID_OFFSET,T0);
  }
 else   if (methodName == VM_MagicNames.getNextInstructionAddress) {
    popAddr(T0);
    asm.emitLAddr(T1,STACKFRAME_NEXT_INSTRUCTION_OFFSET,T0);
    pushAddr(T1);
  }
 else   if (methodName == VM_MagicNames.setNextInstructionAddress) {
    popAddr(T1);
    popAddr(T0);
    asm.emitSTAddr(T1,STACKFRAME_NEXT_INSTRUCTION_OFFSET,T0);
  }
 else   if (methodName == VM_MagicNames.getReturnAddressLocation) {
    popAddr(T0);
    asm.emitLAddr(T1,STACKFRAME_FRAME_POINTER_OFFSET,T0);
    asm.emitADDI(T2,STACKFRAME_NEXT_INSTRUCTION_OFFSET,T1);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.getTocPointer || methodName == VM_MagicNames.getJTOC) {
    pushAddr(JTOC);
  }
 else   if (methodName == VM_MagicNames.getProcessorRegister) {
    pushAddr(PROCESSOR_REGISTER);
  }
 else   if (methodName == VM_MagicNames.setProcessorRegister) {
    popAddr(PROCESSOR_REGISTER);
  }
 else   if (methodName == VM_MagicNames.getTimeBase) {
    if (VM.BuildFor64Addr) {
      asm.emitMFTB(T1);
    }
 else {
      int label=asm.getMachineCodeIndex();
      asm.emitMFTBU(T0);
      asm.emitMFTB(T1);
      asm.emitMFTBU(T2);
      asm.emitCMP(T0,T2);
      asm.emitBC(NE,label);
    }
    pushLong(T0,T1);
  }
 else   if (methodName == VM_MagicNames.invokeMain) {
    popAddr(T0);
    asm.emitMTCTR(T0);
    peekAddr(T0,0);
    asm.emitBCCTRL();
    discardSlot();
  }
 else   if (methodName == VM_MagicNames.invokeClassInitializer) {
    popAddr(T0);
    asm.emitMTCTR(T0);
    asm.emitBCCTRL();
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningVoid) {
    generateMethodInvocation();
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningInt) {
    generateMethodInvocation();
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningLong) {
    generateMethodInvocation();
    pushLong(T0,VM.BuildFor64Addr ? T0 : T1);
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningFloat) {
    generateMethodInvocation();
    pushFloat(F0);
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningDouble) {
    generateMethodInvocation();
    pushDouble(F0);
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningObject) {
    generateMethodInvocation();
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.addressArrayCreate) {
    VM_Array type=methodToBeCalled.getType().resolve().asArray();
    emit_resolved_newarray(type);
  }
 else   if (methodName == VM_MagicNames.addressArrayLength) {
    emit_arraylength();
  }
 else   if (methodName == VM_MagicNames.addressArrayGet) {
    if (VM.BuildFor32Addr || methodToBeCalled.getType() == VM_TypeReference.CodeArray) {
      emit_iaload();
    }
 else {
      genBoundsCheck();
      asm.emitSLDI(T1,T1,LOG_BYTES_IN_ADDRESS);
      asm.emitLAddrX(T2,T0,T1);
      pushAddr(T2);
    }
  }
 else   if (methodName == VM_MagicNames.addressArraySet) {
    if (VM.BuildFor32Addr || methodToBeCalled.getType() == VM_TypeReference.CodeArray) {
      emit_iastore();
    }
 else {
      popAddr(T2);
      genBoundsCheck();
      asm.emitSLDI(T1,T1,LOG_BYTES_IN_ADDRESS);
      asm.emitSTAddrX(T2,T0,T1);
    }
  }
 else   if (methodName == VM_MagicNames.getIntAtOffset) {
    popInt(T1);
    popAddr(T0);
    asm.emitLIntX(T0,T1,T0);
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.getObjectAtOffset || methodName == VM_MagicNames.getWordAtOffset || methodName == VM_MagicNames.getObjectArrayAtOffset) {
    popInt(T1);
    popAddr(T0);
    asm.emitLAddrX(T0,T1,T0);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.getByteAtOffset) {
    popInt(T1);
    popAddr(T0);
    asm.emitLBZX(T0,T1,T0);
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.getCharAtOffset) {
    popInt(T1);
    popAddr(T0);
    asm.emitLHZX(T0,T1,T0);
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.setIntAtOffset) {
    popInt(T2);
    popInt(T1);
    popAddr(T0);
    asm.emitSTWX(T2,T1,T0);
  }
 else   if (methodName == VM_MagicNames.setObjectAtOffset || methodName == VM_MagicNames.setWordAtOffset) {
    popAddr(T2);
    popInt(T1);
    popAddr(T0);
    asm.emitSTAddrX(T2,T1,T0);
  }
 else   if (methodName == VM_MagicNames.setByteAtOffset) {
    popInt(T2);
    popInt(T1);
    popAddr(T0);
    asm.emitSTBX(T2,T1,T0);
  }
 else   if (methodName == VM_MagicNames.setCharAtOffset) {
    popInt(T2);
    popInt(T1);
    popAddr(T0);
    asm.emitSTHX(T2,T1,T0);
  }
 else   if (methodName == VM_MagicNames.getLongAtOffset) {
    popInt(T2);
    popAddr(T1);
    if (VM.BuildFor32Addr) {
      asm.emitLWZX(T0,T1,T2);
      asm.emitADDI(T2,BYTES_IN_INT,T2);
      asm.emitLWZX(T1,T1,T2);
    }
 else {
      asm.emitLDX(T1,T1,T2);
    }
    pushLong(T0,T1);
  }
 else   if ((methodName == VM_MagicNames.setLongAtOffset) || (methodName == VM_MagicNames.setDoubleAtOffset)) {
    popLong(T3,T2);
    popInt(T1);
    popAddr(T0);
    if (VM.BuildFor32Addr) {
      asm.emitSTWX(T3,T1,T0);
      asm.emitADDI(T1,BYTES_IN_INT,T1);
      asm.emitSTWX(T2,T1,T0);
    }
 else {
      asm.emitSTDX(T2,T1,T0);
    }
  }
 else   if (methodName == VM_MagicNames.getMemoryInt) {
    popAddr(T0);
    asm.emitLInt(T0,0,T0);
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.getMemoryWord || methodName == VM_MagicNames.getMemoryAddress) {
    popAddr(T0);
    asm.emitLAddr(T0,0,T0);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.setMemoryInt) {
    popInt(T1);
    popAddr(T0);
    asm.emitSTW(T1,0,T0);
  }
 else   if (methodName == VM_MagicNames.setMemoryWord || methodName == VM_MagicNames.setMemoryAddress) {
    popAddr(T1);
    popAddr(T0);
    asm.emitSTAddr(T1,0,T0);
  }
 else   if (methodName == VM_MagicNames.prepareInt) {
    popInt(T1);
    popAddr(T0);
    if (VM.BuildForSingleVirtualProcessor) {
      asm.emitLWZX(T0,T1,T0);
    }
 else {
      asm.emitLWARX(T0,T1,T0);
    }
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.prepareObject || methodName == VM_MagicNames.prepareAddress || methodName == VM_MagicNames.prepareWord) {
    popInt(T1);
    popAddr(T0);
    if (VM.BuildForSingleVirtualProcessor) {
      asm.emitLAddrX(T0,T1,T0);
    }
 else {
      if (VM.BuildFor32Addr) {
        asm.emitLWARX(T0,T1,T0);
      }
 else {
        asm.emitLDARX(T0,T1,T0);
      }
    }
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.attemptInt) {
    popInt(T2);
    discardSlot();
    popInt(T1);
    popAddr(T0);
    if (VM.BuildForSingleVirtualProcessor) {
      asm.emitSTWX(T2,T1,T0);
      asm.emitLVAL(T0,1);
      pushInt(T0);
    }
 else {
      asm.emitSTWCXr(T2,T1,T0);
      asm.emitLVAL(T0,0);
      VM_ForwardReference fr=asm.emitForwardBC(NE);
      asm.emitLVAL(T0,1);
      fr.resolve(asm);
      pushInt(T0);
    }
  }
 else   if (methodName == VM_MagicNames.attemptObject || methodName == VM_MagicNames.attemptAddress || methodName == VM_MagicNames.attemptWord) {
    popAddr(T2);
    discardSlot();
    popInt(T1);
    popAddr(T0);
    if (VM.BuildForSingleVirtualProcessor) {
      asm.emitSTAddrX(T2,T1,T0);
      asm.emitLVAL(T0,1);
      pushAddr(T0);
    }
 else {
      if (VM.BuildFor32Addr) {
        asm.emitSTWCXr(T2,T1,T0);
      }
 else {
        asm.emitSTDCXr(T2,T1,T0);
      }
      asm.emitLVAL(T0,0);
      VM_ForwardReference fr=asm.emitForwardBC(NE);
      asm.emitLVAL(T0,1);
      fr.resolve(asm);
      pushInt(T0);
    }
  }
 else   if (methodName == VM_MagicNames.saveThreadState) {
    peekAddr(T0,0);
    asm.emitLAddrToc(S0,VM_Entrypoints.saveThreadStateInstructionsField.getOffset());
    asm.emitMTCTR(S0);
    asm.emitBCCTRL();
    discardSlot();
  }
 else   if (methodName == VM_MagicNames.threadSwitch) {
    peekAddr(T1,0);
    peekAddr(T0,1);
    asm.emitLAddrToc(S0,VM_Entrypoints.threadSwitchInstructionsField.getOffset());
    asm.emitMTCTR(S0);
    asm.emitBCCTRL();
    discardSlots(2);
  }
 else   if (methodName == VM_MagicNames.restoreHardwareExceptionState) {
    peekAddr(T0,0);
    asm.emitLAddrToc(S0,VM_Entrypoints.restoreHardwareExceptionStateInstructionsField.getOffset());
    asm.emitMTLR(S0);
    asm.emitBCLR();
  }
 else   if (methodName == VM_MagicNames.returnToNewStack) {
    peekAddr(FP,0);
    asm.emitLAddr(S0,STACKFRAME_NEXT_INSTRUCTION_OFFSET,FP);
    asm.emitMTLR(S0);
    asm.emitBCLR();
  }
 else   if (methodName == VM_MagicNames.dynamicBridgeTo) {
    if (VM.VerifyAssertions)     VM._assert(klass.isDynamicBridge());
    peekAddr(T0,0);
    asm.emitMTCTR(T0);
    int offset=frameSize;
    for (int i=LAST_NONVOLATILE_FPR; i >= FIRST_VOLATILE_FPR; --i)     asm.emitLFD(i,offset-=BYTES_IN_DOUBLE,FP);
    for (int i=LAST_NONVOLATILE_GPR; i >= FIRST_NONVOLATILE_GPR; --i)     asm.emitLAddr(i,offset-=BYTES_IN_ADDRESS,FP);
    offset-=(FIRST_NONVOLATILE_GPR - LAST_VOLATILE_GPR - 1) * BYTES_IN_ADDRESS;
    for (int i=LAST_VOLATILE_GPR; i >= FIRST_VOLATILE_GPR; --i)     asm.emitLAddr(i,offset-=BYTES_IN_ADDRESS,FP);
    asm.emitLAddr(FP,0,FP);
    asm.emitLAddr(S0,STACKFRAME_NEXT_INSTRUCTION_OFFSET,FP);
    asm.emitMTLR(S0);
    asm.emitBCCTR();
  }
 else   if (methodName == VM_MagicNames.objectAsAddress || methodName == VM_MagicNames.addressAsByteArray || methodName == VM_MagicNames.addressAsIntArray || methodName == VM_MagicNames.addressAsObject || methodName == VM_MagicNames.addressAsObjectArray || methodName == VM_MagicNames.addressAsType || methodName == VM_MagicNames.objectAsType || methodName == VM_MagicNames.objectAsByteArray || methodName == VM_MagicNames.objectAsShortArray || methodName == VM_MagicNames.objectAsIntArray || methodName == VM_MagicNames.addressAsThread || methodName == VM_MagicNames.objectAsThread || methodName == VM_MagicNames.objectAsProcessor || methodName == VM_MagicNames.threadAsCollectorThread || methodName == VM_MagicNames.addressAsRegisters || methodName == VM_MagicNames.addressAsStack || methodName == VM_MagicNames.floatAsIntBits || methodName == VM_MagicNames.intBitsAsFloat || methodName == VM_MagicNames.doubleAsLongBits || methodName == VM_MagicNames.longBitsAsDouble) {
  }
 else   if (methodName == VM_MagicNames.getObjectType) {
    popAddr(T0);
    VM_ObjectModel.baselineEmitLoadTIB(asm,T0,T0);
    asm.emitLAddr(T0,TIB_TYPE_INDEX << LOG_BYTES_IN_ADDRESS,T0);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.getArrayLength) {
    popAddr(T0);
    asm.emitLInt(T0,VM_ObjectModel.getArrayLengthOffset(),T0);
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.sync) {
    asm.emitSYNC();
  }
 else   if (methodName == VM_MagicNames.isync) {
    asm.emitISYNC();
  }
 else   if (methodName == VM_MagicNames.dcbst) {
    popAddr(T0);
    asm.emitDCBST(0,T0);
  }
 else   if (methodName == VM_MagicNames.icbi) {
    popAddr(T0);
    asm.emitICBI(0,T0);
  }
 else   if (methodName == VM_MagicNames.wordToInt || methodName == VM_MagicNames.wordToAddress || methodName == VM_MagicNames.wordToOffset || methodName == VM_MagicNames.wordToExtent || methodName == VM_MagicNames.wordToWord) {
  }
 else   if (methodName == VM_MagicNames.wordToLong) {
    asm.emitLVAL(T0,0);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.wordFromInt || methodName == VM_MagicNames.wordFromIntSignExtend) {
    if (VM.BuildFor64Addr) {
      popInt(T0);
      pushAddr(T0);
    }
  }
 else   if (methodName == VM_MagicNames.wordFromIntZeroExtend) {
    if (VM.BuildFor64Addr) {
      asm.emitLWZ(T0,spTopOffset + BYTES_IN_STACKSLOT - BYTES_IN_INT,FP);
      pokeAddr(T0,0);
    }
  }
 else   if (methodName == VM_MagicNames.wordFromLong) {
    discardSlot();
  }
 else   if (methodName == VM_MagicNames.wordAdd) {
    if (VM.BuildFor64Addr && (methodToBeCalled.getParameterTypes()[0] == VM_TypeReference.Int)) {
      popInt(T0);
    }
 else {
      popAddr(T0);
    }
    popAddr(T1);
    asm.emitADD(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordSub || methodName == VM_MagicNames.wordDiff) {
    if (VM.BuildFor64Addr && (methodToBeCalled.getParameterTypes()[0] == VM_TypeReference.Int)) {
      popInt(T0);
    }
 else {
      popAddr(T0);
    }
    popAddr(T1);
    asm.emitSUBFC(T2,T0,T1);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordEQ) {
    generateAddrComparison(false,EQ);
  }
 else   if (methodName == VM_MagicNames.wordNE) {
    generateAddrComparison(false,NE);
  }
 else   if (methodName == VM_MagicNames.wordLT) {
    generateAddrComparison(false,LT);
  }
 else   if (methodName == VM_MagicNames.wordLE) {
    generateAddrComparison(false,LE);
  }
 else   if (methodName == VM_MagicNames.wordGT) {
    generateAddrComparison(false,GT);
  }
 else   if (methodName == VM_MagicNames.wordGE) {
    generateAddrComparison(false,GE);
  }
 else   if (methodName == VM_MagicNames.wordsLT) {
    generateAddrComparison(true,LT);
  }
 else   if (methodName == VM_MagicNames.wordsLE) {
    generateAddrComparison(true,LE);
  }
 else   if (methodName == VM_MagicNames.wordsGT) {
    generateAddrComparison(true,GT);
  }
 else   if (methodName == VM_MagicNames.wordsGE) {
    generateAddrComparison(true,GE);
  }
 else   if (methodName == VM_MagicNames.wordIsZero) {
    asm.emitLVAL(T0,0);
    pushAddr(T0);
    generateAddrComparison(false,EQ);
  }
 else   if (methodName == VM_MagicNames.wordIsMax) {
    asm.emitLVAL(T0,-1);
    pushAddr(T0);
    generateAddrComparison(false,EQ);
  }
 else   if (methodName == VM_MagicNames.wordZero) {
    asm.emitLVAL(T0,0);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.wordOne) {
    asm.emitLVAL(T0,1);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.wordMax) {
    asm.emitLVAL(T0,-1);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.wordAnd) {
    popAddr(T0);
    popAddr(T1);
    asm.emitAND(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordOr) {
    popAddr(T0);
    popAddr(T1);
    asm.emitOR(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordNot) {
    popAddr(T0);
    asm.emitLVAL(T1,-1);
    asm.emitXOR(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordXor) {
    popAddr(T0);
    popAddr(T1);
    asm.emitXOR(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordLsh) {
    popInt(T0);
    popAddr(T1);
    asm.emitSLAddr(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordRshl) {
    popInt(T0);
    popAddr(T1);
    asm.emitSRAddr(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordRsha) {
    popInt(T0);
    popAddr(T1);
    asm.emitSRA_Addr(T2,T1,T0);
    pushAddr(T2);
  }
 else {
    return false;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Generate inline code sequence for specified method.
 * @param methodToBeCalled: method whose name indicates semantics of code to be generated
 * @return true if there was magic defined for the method
 */
private boolean generateInlineCode(VM_MethodReference methodToBeCalled){
  VM_Atom methodName=methodToBeCalled.getName();
  if (methodToBeCalled.getType() == VM_TypeReference.SysCall) {
    VM_TypeReference[] args=methodToBeCalled.getParameterTypes();
    int paramWords=methodToBeCalled.getParameterWords();
    int gp=FIRST_OS_PARAMETER_GPR;
    int fp=FIRST_OS_PARAMETER_FPR;
    int stackIndex=paramWords;
    for (int i=0; i < args.length; i++) {
      VM_TypeReference t=args[i];
      if (t.isLongType()) {
        stackIndex-=2;
        if (VM.BuildFor64Addr) {
          peekLong(gp,gp,stackIndex);
          gp++;
        }
 else {
          gp+=(gp + 1) & 0x01;
          peekInt(gp++,stackIndex);
          peekInt(gp++,stackIndex + 1);
        }
      }
 else       if (t.isFloatType()) {
        stackIndex-=1;
        peekFloat(fp++,stackIndex);
      }
 else       if (t.isDoubleType()) {
        stackIndex-=2;
        peekDouble(fp++,stackIndex);
      }
 else       if (t.isIntLikeType()) {
        stackIndex-=1;
        peekInt(gp++,stackIndex);
      }
 else {
        stackIndex-=1;
        peekAddr(gp++,stackIndex);
      }
    }
    if (VM.VerifyAssertions) {
      VM._assert(stackIndex == 0);
      VM._assert(gp - 1 <= LAST_OS_PARAMETER_GPR);
      VM._assert(fp - 1 <= LAST_OS_PARAMETER_FPR);
    }
    int paramBytes=(VM.BuildFor64Addr ? args.length : paramWords) * BYTES_IN_STACKSLOT;
    VM_Field ip=VM_Entrypoints.getSysCallField(methodName.toString());
    generateSysCall(paramBytes,ip);
    discardSlots(paramWords);
    VM_TypeReference rtype=methodToBeCalled.getReturnType();
    if (rtype.isIntLikeType()) {
      pushInt(T0);
    }
 else     if (rtype.isWordType() || rtype.isReferenceType()) {
      pushAddr(T0);
    }
 else     if (rtype.isDoubleType()) {
      pushDouble(FIRST_OS_PARAMETER_FPR);
    }
 else     if (rtype.isFloatType()) {
      pushFloat(FIRST_OS_PARAMETER_FPR);
    }
 else     if (rtype.isLongType()) {
      pushLong(T0,VM.BuildFor64Addr ? T0 : T1);
    }
  }
 else   if (methodName == VM_MagicNames.getFramePointer) {
    pushAddr(FP);
  }
 else   if (methodName == VM_MagicNames.getCallerFramePointer) {
    popAddr(T0);
    asm.emitLAddr(T1,STACKFRAME_FRAME_POINTER_OFFSET,T0);
    pushAddr(T1);
  }
 else   if (methodName == VM_MagicNames.setCallerFramePointer) {
    popAddr(T1);
    popAddr(T0);
    asm.emitSTAddr(T1,STACKFRAME_FRAME_POINTER_OFFSET,T0);
  }
 else   if (methodName == VM_MagicNames.getCompiledMethodID) {
    popAddr(T0);
    asm.emitLInt(T1,STACKFRAME_METHOD_ID_OFFSET,T0);
    pushInt(T1);
  }
 else   if (methodName == VM_MagicNames.setCompiledMethodID) {
    popInt(T1);
    popAddr(T0);
    asm.emitSTW(T1,STACKFRAME_METHOD_ID_OFFSET,T0);
  }
 else   if (methodName == VM_MagicNames.getNextInstructionAddress) {
    popAddr(T0);
    asm.emitLAddr(T1,STACKFRAME_NEXT_INSTRUCTION_OFFSET,T0);
    pushAddr(T1);
  }
 else   if (methodName == VM_MagicNames.setNextInstructionAddress) {
    popAddr(T1);
    popAddr(T0);
    asm.emitSTAddr(T1,STACKFRAME_NEXT_INSTRUCTION_OFFSET,T0);
  }
 else   if (methodName == VM_MagicNames.getReturnAddressLocation) {
    popAddr(T0);
    asm.emitLAddr(T1,STACKFRAME_FRAME_POINTER_OFFSET,T0);
    asm.emitADDI(T2,STACKFRAME_NEXT_INSTRUCTION_OFFSET,T1);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.getTocPointer || methodName == VM_MagicNames.getJTOC) {
    pushAddr(JTOC);
  }
 else   if (methodName == VM_MagicNames.getProcessorRegister) {
    pushAddr(PROCESSOR_REGISTER);
  }
 else   if (methodName == VM_MagicNames.setProcessorRegister) {
    popAddr(PROCESSOR_REGISTER);
  }
 else   if (methodName == VM_MagicNames.getTimeBase) {
    if (VM.BuildFor64Addr) {
      asm.emitMFTB(T1);
    }
 else {
      int label=asm.getMachineCodeIndex();
      asm.emitMFTBU(T0);
      asm.emitMFTB(T1);
      asm.emitMFTBU(T2);
      asm.emitCMP(T0,T2);
      asm.emitBC(NE,label);
    }
    pushLong(T0,T1);
  }
 else   if (methodName == VM_MagicNames.invokeMain) {
    popAddr(T0);
    asm.emitMTCTR(T0);
    peekAddr(T0,0);
    asm.emitBCCTRL();
    discardSlot();
  }
 else   if (methodName == VM_MagicNames.invokeClassInitializer) {
    popAddr(T0);
    asm.emitMTCTR(T0);
    asm.emitBCCTRL();
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningVoid) {
    generateMethodInvocation();
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningInt) {
    generateMethodInvocation();
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningLong) {
    generateMethodInvocation();
    pushLong(T0,VM.BuildFor64Addr ? T0 : T1);
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningFloat) {
    generateMethodInvocation();
    pushFloat(F0);
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningDouble) {
    generateMethodInvocation();
    pushDouble(F0);
  }
 else   if (methodName == VM_MagicNames.invokeMethodReturningObject) {
    generateMethodInvocation();
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.addressArrayCreate) {
    VM_Array type=methodToBeCalled.getType().resolve().asArray();
    emit_resolved_newarray(type);
  }
 else   if (methodName == VM_MagicNames.addressArrayLength) {
    emit_arraylength();
  }
 else   if (methodName == VM_MagicNames.addressArrayGet) {
    if (VM.BuildFor32Addr || methodToBeCalled.getType() == VM_TypeReference.CodeArray) {
      emit_iaload();
    }
 else {
      genBoundsCheck();
      asm.emitSLDI(T1,T1,LOG_BYTES_IN_ADDRESS);
      asm.emitLAddrX(T2,T0,T1);
      pushAddr(T2);
    }
  }
 else   if (methodName == VM_MagicNames.addressArraySet) {
    if (VM.BuildFor32Addr || methodToBeCalled.getType() == VM_TypeReference.CodeArray) {
      emit_iastore();
    }
 else {
      popAddr(T2);
      genBoundsCheck();
      asm.emitSLDI(T1,T1,LOG_BYTES_IN_ADDRESS);
      asm.emitSTAddrX(T2,T0,T1);
    }
  }
 else   if (methodName == VM_MagicNames.getIntAtOffset) {
    popInt(T1);
    popAddr(T0);
    asm.emitLIntX(T0,T1,T0);
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.getObjectAtOffset || methodName == VM_MagicNames.getWordAtOffset || methodName == VM_MagicNames.getObjectArrayAtOffset) {
    popInt(T1);
    popAddr(T0);
    asm.emitLAddrX(T0,T1,T0);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.getByteAtOffset) {
    popInt(T1);
    popAddr(T0);
    asm.emitLBZX(T0,T1,T0);
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.getCharAtOffset) {
    popInt(T1);
    popAddr(T0);
    asm.emitLHZX(T0,T1,T0);
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.setIntAtOffset) {
    popInt(T2);
    popInt(T1);
    popAddr(T0);
    asm.emitSTWX(T2,T1,T0);
  }
 else   if (methodName == VM_MagicNames.setObjectAtOffset || methodName == VM_MagicNames.setWordAtOffset) {
    popAddr(T2);
    popInt(T1);
    popAddr(T0);
    asm.emitSTAddrX(T2,T1,T0);
  }
 else   if (methodName == VM_MagicNames.setByteAtOffset) {
    popInt(T2);
    popInt(T1);
    popAddr(T0);
    asm.emitSTBX(T2,T1,T0);
  }
 else   if (methodName == VM_MagicNames.setCharAtOffset) {
    popInt(T2);
    popInt(T1);
    popAddr(T0);
    asm.emitSTHX(T2,T1,T0);
  }
 else   if (methodName == VM_MagicNames.getLongAtOffset) {
    popInt(T2);
    popAddr(T1);
    if (VM.BuildFor32Addr) {
      asm.emitLWZX(T0,T1,T2);
      asm.emitADDI(T2,BYTES_IN_INT,T2);
      asm.emitLWZX(T1,T1,T2);
    }
 else {
      asm.emitLDX(T1,T1,T2);
    }
    pushLong(T0,T1);
  }
 else   if ((methodName == VM_MagicNames.setLongAtOffset) || (methodName == VM_MagicNames.setDoubleAtOffset)) {
    popLong(T3,T2);
    popInt(T1);
    popAddr(T0);
    if (VM.BuildFor32Addr) {
      asm.emitSTWX(T3,T1,T0);
      asm.emitADDI(T1,BYTES_IN_INT,T1);
      asm.emitSTWX(T2,T1,T0);
    }
 else {
      asm.emitSTDX(T2,T1,T0);
    }
  }
 else   if (methodName == VM_MagicNames.getMemoryInt) {
    popAddr(T0);
    asm.emitLInt(T0,0,T0);
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.getMemoryWord || methodName == VM_MagicNames.getMemoryAddress) {
    popAddr(T0);
    asm.emitLAddr(T0,0,T0);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.setMemoryInt) {
    popInt(T1);
    popAddr(T0);
    asm.emitSTW(T1,0,T0);
  }
 else   if (methodName == VM_MagicNames.setMemoryWord || methodName == VM_MagicNames.setMemoryAddress) {
    popAddr(T1);
    popAddr(T0);
    asm.emitSTAddr(T1,0,T0);
  }
 else   if (methodName == VM_MagicNames.prepareInt) {
    popInt(T1);
    popAddr(T0);
    if (VM.BuildForSingleVirtualProcessor) {
      asm.emitLWZX(T0,T1,T0);
    }
 else {
      asm.emitLWARX(T0,T1,T0);
    }
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.prepareObject || methodName == VM_MagicNames.prepareAddress || methodName == VM_MagicNames.prepareWord) {
    popInt(T1);
    popAddr(T0);
    if (VM.BuildForSingleVirtualProcessor) {
      asm.emitLAddrX(T0,T1,T0);
    }
 else {
      if (VM.BuildFor32Addr) {
        asm.emitLWARX(T0,T1,T0);
      }
 else {
        asm.emitLDARX(T0,T1,T0);
      }
    }
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.attemptInt) {
    popInt(T2);
    discardSlot();
    popInt(T1);
    popAddr(T0);
    if (VM.BuildForSingleVirtualProcessor) {
      asm.emitSTWX(T2,T1,T0);
      asm.emitLVAL(T0,1);
      pushAddr(T0);
    }
 else {
      asm.emitSTWCXr(T2,T1,T0);
      asm.emitLVAL(T0,0);
      VM_ForwardReference fr=asm.emitForwardBC(NE);
      asm.emitLVAL(T0,1);
      fr.resolve(asm);
      pushAddr(T0);
    }
  }
 else   if (methodName == VM_MagicNames.attemptObject || methodName == VM_MagicNames.attemptAddress || methodName == VM_MagicNames.attemptWord) {
    popAddr(T2);
    discardSlot();
    popInt(T1);
    popAddr(T0);
    if (VM.BuildForSingleVirtualProcessor) {
      asm.emitSTAddrX(T2,T1,T0);
      asm.emitLVAL(T0,1);
      pushAddr(T0);
    }
 else {
      if (VM.BuildFor32Addr) {
        asm.emitSTWCXr(T2,T1,T0);
      }
 else {
        asm.emitSTDCXr(T2,T1,T0);
      }
      asm.emitLVAL(T0,0);
      VM_ForwardReference fr=asm.emitForwardBC(NE);
      asm.emitLVAL(T0,1);
      fr.resolve(asm);
      pushInt(T0);
    }
  }
 else   if (methodName == VM_MagicNames.saveThreadState) {
    peekAddr(T0,0);
    asm.emitLAddrToc(S0,VM_Entrypoints.saveThreadStateInstructionsField.getOffset());
    asm.emitMTCTR(S0);
    asm.emitBCCTRL();
    discardSlot();
  }
 else   if (methodName == VM_MagicNames.threadSwitch) {
    peekAddr(T1,0);
    peekAddr(T0,1);
    asm.emitLAddrToc(S0,VM_Entrypoints.threadSwitchInstructionsField.getOffset());
    asm.emitMTCTR(S0);
    asm.emitBCCTRL();
    discardSlots(2);
  }
 else   if (methodName == VM_MagicNames.restoreHardwareExceptionState) {
    peekAddr(T0,0);
    asm.emitLAddrToc(S0,VM_Entrypoints.restoreHardwareExceptionStateInstructionsField.getOffset());
    asm.emitMTLR(S0);
    asm.emitBCLR();
  }
 else   if (methodName == VM_MagicNames.returnToNewStack) {
    peekAddr(FP,0);
    asm.emitLAddr(S0,STACKFRAME_NEXT_INSTRUCTION_OFFSET,FP);
    asm.emitMTLR(S0);
    asm.emitBCLR();
  }
 else   if (methodName == VM_MagicNames.dynamicBridgeTo) {
    if (VM.VerifyAssertions)     VM._assert(klass.isDynamicBridge());
    peekAddr(T0,0);
    asm.emitMTCTR(T0);
    int offset=frameSize;
    for (int i=LAST_NONVOLATILE_FPR; i >= FIRST_VOLATILE_FPR; --i)     asm.emitLFD(i,offset-=BYTES_IN_DOUBLE,FP);
    for (int i=LAST_NONVOLATILE_GPR; i >= FIRST_NONVOLATILE_GPR; --i)     asm.emitLAddr(i,offset-=BYTES_IN_ADDRESS,FP);
    offset-=(FIRST_NONVOLATILE_GPR - LAST_VOLATILE_GPR - 1) * BYTES_IN_ADDRESS;
    for (int i=LAST_VOLATILE_GPR; i >= FIRST_VOLATILE_GPR; --i)     asm.emitLAddr(i,offset-=BYTES_IN_ADDRESS,FP);
    asm.emitLAddr(FP,0,FP);
    asm.emitLAddr(S0,STACKFRAME_NEXT_INSTRUCTION_OFFSET,FP);
    asm.emitMTLR(S0);
    asm.emitBCCTR();
  }
 else   if (methodName == VM_MagicNames.objectAsAddress || methodName == VM_MagicNames.addressAsByteArray || methodName == VM_MagicNames.addressAsIntArray || methodName == VM_MagicNames.addressAsObject || methodName == VM_MagicNames.addressAsObjectArray || methodName == VM_MagicNames.addressAsType || methodName == VM_MagicNames.objectAsType || methodName == VM_MagicNames.objectAsByteArray || methodName == VM_MagicNames.objectAsShortArray || methodName == VM_MagicNames.objectAsIntArray || methodName == VM_MagicNames.addressAsThread || methodName == VM_MagicNames.objectAsThread || methodName == VM_MagicNames.objectAsProcessor || methodName == VM_MagicNames.threadAsCollectorThread || methodName == VM_MagicNames.addressAsRegisters || methodName == VM_MagicNames.addressAsStack || methodName == VM_MagicNames.floatAsIntBits || methodName == VM_MagicNames.intBitsAsFloat || methodName == VM_MagicNames.doubleAsLongBits || methodName == VM_MagicNames.longBitsAsDouble) {
  }
 else   if (methodName == VM_MagicNames.getObjectType) {
    popAddr(T0);
    VM_ObjectModel.baselineEmitLoadTIB(asm,T0,T0);
    asm.emitLAddr(T0,TIB_TYPE_INDEX << LOG_BYTES_IN_ADDRESS,T0);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.getArrayLength) {
    popAddr(T0);
    asm.emitLInt(T0,VM_ObjectModel.getArrayLengthOffset(),T0);
    pushInt(T0);
  }
 else   if (methodName == VM_MagicNames.sync) {
    asm.emitSYNC();
  }
 else   if (methodName == VM_MagicNames.isync) {
    asm.emitISYNC();
  }
 else   if (methodName == VM_MagicNames.dcbst) {
    popAddr(T0);
    asm.emitDCBST(0,T0);
  }
 else   if (methodName == VM_MagicNames.icbi) {
    popAddr(T0);
    asm.emitICBI(0,T0);
  }
 else   if (methodName == VM_MagicNames.wordToInt || methodName == VM_MagicNames.wordToAddress || methodName == VM_MagicNames.wordToOffset || methodName == VM_MagicNames.wordToExtent || methodName == VM_MagicNames.wordToWord) {
  }
 else   if (methodName == VM_MagicNames.wordToLong) {
    asm.emitLVAL(T0,0);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.wordFromInt || methodName == VM_MagicNames.wordFromIntSignExtend) {
    if (VM.BuildFor64Addr) {
      popInt(T0);
      pushAddr(T0);
    }
  }
 else   if (methodName == VM_MagicNames.wordFromIntZeroExtend) {
    if (VM.BuildFor64Addr) {
      asm.emitLWZ(T0,spTopOffset + BYTES_IN_STACKSLOT - BYTES_IN_INT,FP);
      pokeAddr(T0,0);
    }
  }
 else   if (methodName == VM_MagicNames.wordFromLong) {
    discardSlot();
  }
 else   if (methodName == VM_MagicNames.wordAdd) {
    if (VM.BuildFor64Addr && (methodToBeCalled.getParameterTypes()[0] == VM_TypeReference.Int)) {
      popInt(T0);
    }
 else {
      popAddr(T0);
    }
    popAddr(T1);
    asm.emitADD(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordSub || methodName == VM_MagicNames.wordDiff) {
    if (VM.BuildFor64Addr && (methodToBeCalled.getParameterTypes()[0] == VM_TypeReference.Int)) {
      popInt(T0);
    }
 else {
      popAddr(T0);
    }
    popAddr(T1);
    asm.emitSUBFC(T2,T0,T1);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordEQ) {
    generateAddrComparison(false,EQ);
  }
 else   if (methodName == VM_MagicNames.wordNE) {
    generateAddrComparison(false,NE);
  }
 else   if (methodName == VM_MagicNames.wordLT) {
    generateAddrComparison(false,LT);
  }
 else   if (methodName == VM_MagicNames.wordLE) {
    generateAddrComparison(false,LE);
  }
 else   if (methodName == VM_MagicNames.wordGT) {
    generateAddrComparison(false,GT);
  }
 else   if (methodName == VM_MagicNames.wordGE) {
    generateAddrComparison(false,GE);
  }
 else   if (methodName == VM_MagicNames.wordsLT) {
    generateAddrComparison(true,LT);
  }
 else   if (methodName == VM_MagicNames.wordsLE) {
    generateAddrComparison(true,LE);
  }
 else   if (methodName == VM_MagicNames.wordsGT) {
    generateAddrComparison(true,GT);
  }
 else   if (methodName == VM_MagicNames.wordsGE) {
    generateAddrComparison(true,GE);
  }
 else   if (methodName == VM_MagicNames.wordIsZero) {
    asm.emitLVAL(T0,0);
    pushAddr(T0);
    generateAddrComparison(false,EQ);
  }
 else   if (methodName == VM_MagicNames.wordIsMax) {
    asm.emitLVAL(T0,-1);
    pushAddr(T0);
    generateAddrComparison(false,EQ);
  }
 else   if (methodName == VM_MagicNames.wordZero) {
    asm.emitLVAL(T0,0);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.wordOne) {
    asm.emitLVAL(T0,1);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.wordMax) {
    asm.emitLVAL(T0,-1);
    pushAddr(T0);
  }
 else   if (methodName == VM_MagicNames.wordAnd) {
    popAddr(T0);
    popAddr(T1);
    asm.emitAND(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordOr) {
    popAddr(T0);
    popAddr(T1);
    asm.emitOR(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordNot) {
    popAddr(T0);
    asm.emitLVAL(T1,-1);
    asm.emitXOR(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordXor) {
    popAddr(T0);
    popAddr(T1);
    asm.emitXOR(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordLsh) {
    popInt(T0);
    popAddr(T1);
    asm.emitSLAddr(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordRshl) {
    popInt(T0);
    popAddr(T1);
    asm.emitSRAddr(T2,T1,T0);
    pushAddr(T2);
  }
 else   if (methodName == VM_MagicNames.wordRsha) {
    popInt(T0);
    popAddr(T1);
    asm.emitSRA_Addr(T2,T1,T0);
    pushAddr(T2);
  }
 else {
    return false;
  }
  return true;
}