Program: 150274
Project: 150274
Buggy source:
private static void storeParametersForAIX(VM_Assembler asm,int frameSize,VM_Method method,VM_Class klass){
  int nextAIXArgReg, nextAIXArgFloatReg, nextVMArgReg, nextVMArgFloatReg;
  int spillOffsetAIX=NATIVE_FRAME_HEADER_SIZE + 2 * BYTES_IN_STACKSLOT;
  int spillOffsetVM=frameSize + STACKFRAME_HEADER_SIZE;
  VM_TypeReference[] types=method.getParameterTypes();
  int numArguments=types.length;
  asm.emitLAddr(PROCESSOR_REGISTER,VM_Entrypoints.JNIRefsField.getOffset(),S0);
  asm.emitLInt(KLUDGE_TI_REG,VM_Entrypoints.JNIRefsTopField.getOffset(),S0);
  asm.emitADD(KLUDGE_TI_REG,PROCESSOR_REGISTER,KLUDGE_TI_REG);
  asm.emitLInt(S1,VM_Entrypoints.JNIRefsSavedFPField.getOffset(),S0);
  asm.emitSTWU(S1,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
  asm.emitSUBFC(S1,PROCESSOR_REGISTER,KLUDGE_TI_REG);
  asm.emitSTW(S1,VM_Entrypoints.JNIRefsSavedFPField.getOffset(),S0);
  nextAIXArgFloatReg=FIRST_OS_PARAMETER_FPR;
  nextVMArgFloatReg=FIRST_VOLATILE_FPR;
  nextAIXArgReg=FIRST_OS_PARAMETER_GPR + 2;
  if (method.isStatic()) {
    nextVMArgReg=FIRST_VOLATILE_GPR;
  }
 else {
    nextVMArgReg=FIRST_VOLATILE_GPR + 1;
  }
  if (VM.VerifyAssertions)   VM._assert(FIRST_OS_PARAMETER_FPR == FIRST_VOLATILE_FPR);
  if (VM.VerifyAssertions)   VM._assert(LAST_OS_PARAMETER_FPR <= LAST_VOLATILE_FPR);
  if (VM.VerifyAssertions)   VM._assert(FIRST_OS_PARAMETER_GPR == FIRST_VOLATILE_GPR);
  if (VM.VerifyAssertions)   VM._assert(LAST_OS_PARAMETER_GPR <= LAST_VOLATILE_GPR);
  VM_Assembler[] asmForArgs=new VM_Assembler[numArguments];
  for (int arg=0; arg < numArguments; arg++) {
    boolean mustSaveFloatToSpill;
    asmForArgs[arg]=new VM_Assembler(0);
    VM_Assembler asmArg=asmForArgs[arg];
    if (types[arg].isFloatType()) {
      if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR) {
        nextAIXArgReg++;
        mustSaveFloatToSpill=false;
      }
 else {
        mustSaveFloatToSpill=true;
      }
      if (nextVMArgFloatReg <= LAST_OS_PARAMETER_FPR) {
        if (mustSaveFloatToSpill) {
          asmArg.emitSTFS(nextVMArgFloatReg,spillOffsetAIX,FP);
        }
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
        nextAIXArgFloatReg++;
        nextVMArgFloatReg++;
      }
 else       if (nextVMArgFloatReg <= LAST_VOLATILE_FPR) {
        asmArg.emitSTFS(nextVMArgFloatReg,spillOffsetAIX,FP);
        nextVMArgFloatReg++;
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
      }
 else {
        spillOffsetVM+=BYTES_IN_STACKSLOT;
        asmArg.emitLFS(FIRST_SCRATCH_FPR,spillOffsetVM - BYTES_IN_FLOAT,FP);
        asmArg.emitSTFS(FIRST_SCRATCH_FPR,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
      }
    }
 else     if (types[arg].isDoubleType()) {
      if (VM.BuildFor64Addr) {
        if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR) {
          nextAIXArgReg++;
          mustSaveFloatToSpill=false;
        }
 else {
          mustSaveFloatToSpill=true;
        }
      }
 else {
        if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR - 1) {
          nextAIXArgReg+=2;
          mustSaveFloatToSpill=false;
        }
 else {
          if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR)           nextAIXArgReg++;
          mustSaveFloatToSpill=true;
        }
      }
      if (nextVMArgFloatReg <= LAST_OS_PARAMETER_FPR) {
        if (mustSaveFloatToSpill) {
          asmArg.emitSTFD(nextVMArgFloatReg,spillOffsetAIX,FP);
        }
        spillOffsetAIX+=BYTES_IN_DOUBLE;
        nextAIXArgFloatReg++;
        nextVMArgFloatReg++;
      }
 else       if (nextVMArgFloatReg <= LAST_VOLATILE_FPR) {
        asmArg.emitSTFD(nextVMArgFloatReg,spillOffsetAIX,FP);
        nextVMArgFloatReg++;
        spillOffsetAIX+=BYTES_IN_DOUBLE;
      }
 else {
        asmArg.emitLFD(FIRST_SCRATCH_FPR,spillOffsetVM,FP);
        asmArg.emitSTFD(FIRST_SCRATCH_FPR,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_DOUBLE;
        spillOffsetVM+=BYTES_IN_DOUBLE;
      }
    }
 else     if (VM.BuildFor32Addr && types[arg].isLongType()) {
      if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR - 1) {
        asmArg.emitMR(nextAIXArgReg + 1,nextVMArgReg + 1);
        asmArg.emitMR(nextAIXArgReg,nextVMArgReg);
        nextAIXArgReg+=2;
        nextVMArgReg+=2;
        spillOffsetAIX+=2 * BYTES_IN_STACKSLOT;
      }
 else       if (nextAIXArgReg == LAST_OS_PARAMETER_GPR && nextVMArgReg <= LAST_VOLATILE_GPR - 1) {
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
        asmArg.emitSTW(nextVMArgReg + 1,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
        asmArg.emitMR(nextAIXArgReg,nextVMArgReg);
        nextAIXArgReg+=2;
        nextVMArgReg+=2;
      }
 else       if (nextAIXArgReg > LAST_OS_PARAMETER_GPR && nextVMArgReg <= LAST_VOLATILE_GPR - 1) {
        asmArg.emitSTW(nextVMArgReg++,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
        asmArg.emitSTW(nextVMArgReg++,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
      }
 else       if (nextVMArgReg == LAST_VOLATILE_GPR) {
        asmArg.emitSTW(nextVMArgReg++,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
        asmArg.emitLWZ(REGISTER_ZERO,spillOffsetVM,FP);
        asmArg.emitSTW(REGISTER_ZERO,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
        spillOffsetVM+=BYTES_IN_STACKSLOT;
      }
 else {
        asmArg.emitLFD(FIRST_SCRATCH_FPR,spillOffsetVM,FP);
        asmArg.emitSTFD(FIRST_SCRATCH_FPR,spillOffsetAIX,FP);
        spillOffsetAIX+=2 * BYTES_IN_STACKSLOT;
        spillOffsetVM+=2 * BYTES_IN_STACKSLOT;
      }
    }
 else     if (types[arg].isReferenceType()) {
      if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR) {
        asmArg.emitSTAddrU(nextVMArgReg++,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
        asmArg.emitSUBFC(nextAIXArgReg++,PROCESSOR_REGISTER,KLUDGE_TI_REG);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
      }
 else       if (nextVMArgReg <= LAST_VOLATILE_GPR) {
        asmArg.emitSTAddrU(nextVMArgReg++,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
        asmArg.emitSUBFC(REGISTER_ZERO,PROCESSOR_REGISTER,KLUDGE_TI_REG);
        asmArg.emitSTAddr(REGISTER_ZERO,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
      }
 else {
        asmArg.emitLAddr(REGISTER_ZERO,spillOffsetVM,FP);
        asmArg.emitSTAddrU(REGISTER_ZERO,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
        asmArg.emitSUBFC(REGISTER_ZERO,PROCESSOR_REGISTER,KLUDGE_TI_REG);
        asmArg.emitSTAddr(REGISTER_ZERO,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
        spillOffsetVM+=BYTES_IN_STACKSLOT;
      }
    }
 else {
      if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR) {
        asmArg.emitMR(nextAIXArgReg++,nextVMArgReg++);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
      }
 else       if (nextVMArgReg <= LAST_VOLATILE_GPR) {
        asmArg.emitSTAddr(nextVMArgReg++,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
      }
 else {
        asmArg.emitLAddr(REGISTER_ZERO,spillOffsetVM,FP);
        asmArg.emitSTAddr(REGISTER_ZERO,spillOffsetAIX,FP);
        spillOffsetAIX+=BYTES_IN_STACKSLOT;
        spillOffsetVM+=BYTES_IN_STACKSLOT;
      }
    }
  }
  for (int arg=numArguments - 1; arg >= 0; arg--) {
    VM_MachineCode codeForArg=asmForArgs[arg].makeMachineCode();
    asm.appendInstructions(codeForArg.getInstructions());
  }
  if (method.isStatic()) {
    klass.getClassForType();
    asm.emitLAddrToc(4,klass.getTibOffset());
    asm.emitLAddr(4,0,4);
    asm.emitLAddr(4,VM_Entrypoints.classForTypeField.getOffset(),4);
    asm.emitSTAddrU(4,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
    asm.emitSUBFC(4,PROCESSOR_REGISTER,KLUDGE_TI_REG);
  }
 else {
    asm.emitSTAddrU(3,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
    asm.emitSUBFC(4,PROCESSOR_REGISTER,KLUDGE_TI_REG);
  }
  asm.emitSUBFC(KLUDGE_TI_REG,PROCESSOR_REGISTER,KLUDGE_TI_REG);
  asm.emitSTW(KLUDGE_TI_REG,VM_Entrypoints.JNIRefsTopField.getOffset(),S0);
}

Fixed version (ground truth):
private static void storeParametersForAIX(VM_Assembler asm,int frameSize,VM_Method method,VM_Class klass){
  int nextAIXArgReg, nextAIXArgFloatReg, nextVMArgReg, nextVMArgFloatReg;
  int spillOffsetAIX=NATIVE_FRAME_HEADER_SIZE + 2 * BYTES_IN_STACKSLOT;
  int spillOffsetVM=frameSize + STACKFRAME_HEADER_SIZE;
  VM_TypeReference[] types=method.getParameterTypes();
  int numArguments=types.length;
  asm.emitLAddr(PROCESSOR_REGISTER,VM_Entrypoints.JNIRefsField.getOffset(),S0);
  asm.emitLInt(KLUDGE_TI_REG,VM_Entrypoints.JNIRefsTopField.getOffset(),S0);
  asm.emitADD(KLUDGE_TI_REG,PROCESSOR_REGISTER,KLUDGE_TI_REG);
  asm.emitLInt(S1,VM_Entrypoints.JNIRefsSavedFPField.getOffset(),S0);
  asm.emitSTWU(S1,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
  asm.emitSUBFC(S1,PROCESSOR_REGISTER,KLUDGE_TI_REG);
  asm.emitSTW(S1,VM_Entrypoints.JNIRefsSavedFPField.getOffset(),S0);
  nextAIXArgFloatReg=FIRST_OS_PARAMETER_FPR;
  nextVMArgFloatReg=FIRST_VOLATILE_FPR;
  nextAIXArgReg=FIRST_OS_PARAMETER_GPR + 2;
  if (method.isStatic()) {
    nextVMArgReg=FIRST_VOLATILE_GPR;
  }
 else {
    nextVMArgReg=FIRST_VOLATILE_GPR + 1;
  }
  if (VM.VerifyAssertions)   VM._assert(FIRST_OS_PARAMETER_FPR == FIRST_VOLATILE_FPR);
  if (VM.VerifyAssertions)   VM._assert(LAST_OS_PARAMETER_FPR <= LAST_VOLATILE_FPR);
  if (VM.VerifyAssertions)   VM._assert(FIRST_OS_PARAMETER_GPR == FIRST_VOLATILE_GPR);
  if (VM.VerifyAssertions)   VM._assert(LAST_OS_PARAMETER_GPR <= LAST_VOLATILE_GPR);
  VM_Assembler[] asmForArgs=new VM_Assembler[numArguments];
  for (int arg=0; arg < numArguments; arg++) {
    boolean mustSaveFloatToSpill;
    asmForArgs[arg]=new VM_Assembler(0);
    VM_Assembler asmArg=asmForArgs[arg];
    if (types[arg].isFloatType()) {
      if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR) {
        nextAIXArgReg++;
        mustSaveFloatToSpill=false;
      }
 else {
        mustSaveFloatToSpill=true;
      }
      spillOffsetAIX+=BYTES_IN_STACKSLOT;
      if (nextVMArgFloatReg <= LAST_OS_PARAMETER_FPR) {
        if (mustSaveFloatToSpill) {
          asmArg.emitSTFS(nextVMArgFloatReg,spillOffsetAIX - BYTES_IN_FLOAT,FP);
        }
        nextAIXArgFloatReg++;
        nextVMArgFloatReg++;
      }
 else       if (nextVMArgFloatReg <= LAST_VOLATILE_FPR) {
        asmArg.emitSTFS(nextVMArgFloatReg,spillOffsetAIX - BYTES_IN_FLOAT,FP);
        nextVMArgFloatReg++;
      }
 else {
        spillOffsetVM+=BYTES_IN_STACKSLOT;
        asmArg.emitLFS(FIRST_SCRATCH_FPR,spillOffsetVM - BYTES_IN_FLOAT,FP);
        asmArg.emitSTFS(FIRST_SCRATCH_FPR,spillOffsetAIX - BYTES_IN_FLOAT,FP);
      }
    }
 else     if (types[arg].isDoubleType()) {
      if (VM.BuildFor64Addr) {
        if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR) {
          nextAIXArgReg++;
          mustSaveFloatToSpill=false;
        }
 else {
          mustSaveFloatToSpill=true;
        }
      }
 else {
        if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR - 1) {
          nextAIXArgReg+=2;
          mustSaveFloatToSpill=false;
        }
 else {
          if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR)           nextAIXArgReg++;
          mustSaveFloatToSpill=true;
        }
      }
      spillOffsetAIX+=BYTES_IN_DOUBLE;
      if (nextVMArgFloatReg <= LAST_OS_PARAMETER_FPR) {
        if (mustSaveFloatToSpill) {
          asmArg.emitSTFD(nextVMArgFloatReg,spillOffsetAIX - BYTES_IN_DOUBLE,FP);
        }
        nextAIXArgFloatReg++;
        nextVMArgFloatReg++;
      }
 else       if (nextVMArgFloatReg <= LAST_VOLATILE_FPR) {
        asmArg.emitSTFD(nextVMArgFloatReg,spillOffsetAIX - BYTES_IN_DOUBLE,FP);
        nextVMArgFloatReg++;
      }
 else {
        spillOffsetVM+=BYTES_IN_DOUBLE;
        asmArg.emitLFD(FIRST_SCRATCH_FPR,spillOffsetVM - BYTES_IN_DOUBLE,FP);
        asmArg.emitSTFD(FIRST_SCRATCH_FPR,spillOffsetAIX - BYTES_IN_DOUBLE,FP);
      }
    }
 else     if (VM.BuildFor32Addr && types[arg].isLongType()) {
      spillOffsetAIX+=BYTES_IN_LONG;
      if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR - 1) {
        asmArg.emitMR(nextAIXArgReg + 1,nextVMArgReg + 1);
        asmArg.emitMR(nextAIXArgReg,nextVMArgReg);
        nextAIXArgReg+=2;
        nextVMArgReg+=2;
      }
 else       if (nextAIXArgReg == LAST_OS_PARAMETER_GPR && nextVMArgReg <= LAST_VOLATILE_GPR - 1) {
        asmArg.emitSTW(nextVMArgReg + 1,spillOffsetAIX - BYTES_IN_STACKSLOT,FP);
        asmArg.emitMR(nextAIXArgReg,nextVMArgReg);
        nextAIXArgReg+=2;
        nextVMArgReg+=2;
      }
 else       if (nextAIXArgReg > LAST_OS_PARAMETER_GPR && nextVMArgReg <= LAST_VOLATILE_GPR - 1) {
        asmArg.emitSTW(nextVMArgReg++,spillOffsetAIX - 2 * BYTES_IN_STACKSLOT,FP);
        asmArg.emitSTW(nextVMArgReg++,spillOffsetAIX - BYTES_IN_STACKSLOT,FP);
      }
 else       if (nextVMArgReg == LAST_VOLATILE_GPR) {
        spillOffsetVM+=BYTES_IN_STACKSLOT;
        asmArg.emitSTW(nextVMArgReg++,spillOffsetAIX - 2 * BYTES_IN_STACKSLOT,FP);
        asmArg.emitLWZ(REGISTER_ZERO,spillOffsetVM - BYTES_IN_STACKSLOT,FP);
        asmArg.emitSTW(REGISTER_ZERO,spillOffsetAIX - BYTES_IN_STACKSLOT,FP);
      }
 else {
        spillOffsetVM+=BYTES_IN_LONG;
        asmArg.emitLFD(FIRST_SCRATCH_FPR,spillOffsetVM - BYTES_IN_LONG,FP);
        asmArg.emitSTFD(FIRST_SCRATCH_FPR,spillOffsetAIX - BYTES_IN_LONG,FP);
      }
    }
 else     if (VM.BuildFor64Addr && types[arg].isLongType()) {
      spillOffsetAIX+=BYTES_IN_LONG;
      if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR) {
        asmArg.emitMR(nextAIXArgReg++,nextVMArgReg++);
      }
 else       if (nextVMArgReg <= LAST_VOLATILE_GPR) {
        asmArg.emitSTAddr(nextVMArgReg++,spillOffsetAIX - BYTES_IN_LONG,FP);
      }
 else {
        spillOffsetVM+=BYTES_IN_LONG;
        asmArg.emitLAddr(REGISTER_ZERO,spillOffsetVM - BYTES_IN_LONG,FP);
        asmArg.emitSTAddr(REGISTER_ZERO,spillOffsetAIX - BYTES_IN_LONG,FP);
      }
    }
 else     if (types[arg].isReferenceType()) {
      spillOffsetAIX+=BYTES_IN_ADDRESS;
      if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR) {
        asmArg.emitSTAddrU(nextVMArgReg++,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
        asmArg.emitSUBFC(nextAIXArgReg++,PROCESSOR_REGISTER,KLUDGE_TI_REG);
      }
 else       if (nextVMArgReg <= LAST_VOLATILE_GPR) {
        asmArg.emitSTAddrU(nextVMArgReg++,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
        asmArg.emitSUBFC(REGISTER_ZERO,PROCESSOR_REGISTER,KLUDGE_TI_REG);
        asmArg.emitSTAddr(REGISTER_ZERO,spillOffsetAIX - BYTES_IN_ADDRESS,FP);
      }
 else {
        spillOffsetVM+=BYTES_IN_STACKSLOT;
        asmArg.emitLAddr(REGISTER_ZERO,spillOffsetVM - BYTES_IN_ADDRESS,FP);
        asmArg.emitSTAddrU(REGISTER_ZERO,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
        asmArg.emitSUBFC(REGISTER_ZERO,PROCESSOR_REGISTER,KLUDGE_TI_REG);
        asmArg.emitSTAddr(REGISTER_ZERO,spillOffsetAIX - BYTES_IN_ADDRESS,FP);
      }
    }
 else {
      spillOffsetAIX+=BYTES_IN_STACKSLOT;
      if (nextAIXArgReg <= LAST_OS_PARAMETER_GPR) {
        asmArg.emitMR(nextAIXArgReg++,nextVMArgReg++);
      }
 else       if (nextVMArgReg <= LAST_VOLATILE_GPR) {
        asmArg.emitSTAddr(nextVMArgReg++,spillOffsetAIX - BYTES_IN_ADDRESS,FP);
      }
 else {
        spillOffsetVM+=BYTES_IN_STACKSLOT;
        asmArg.emitLInt(REGISTER_ZERO,spillOffsetVM - BYTES_IN_INT,FP);
        asmArg.emitSTAddr(REGISTER_ZERO,spillOffsetAIX - BYTES_IN_ADDRESS,FP);
      }
    }
  }
  for (int arg=numArguments - 1; arg >= 0; arg--) {
    VM_MachineCode codeForArg=asmForArgs[arg].makeMachineCode();
    asm.appendInstructions(codeForArg.getInstructions());
  }
  if (method.isStatic()) {
    klass.getClassForType();
    asm.emitLAddrToc(4,klass.getTibOffset());
    asm.emitLAddr(4,0,4);
    asm.emitLAddr(4,VM_Entrypoints.classForTypeField.getOffset(),4);
    asm.emitSTAddrU(4,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
    asm.emitSUBFC(4,PROCESSOR_REGISTER,KLUDGE_TI_REG);
  }
 else {
    asm.emitSTAddrU(3,BYTES_IN_ADDRESS,KLUDGE_TI_REG);
    asm.emitSUBFC(4,PROCESSOR_REGISTER,KLUDGE_TI_REG);
  }
  asm.emitSUBFC(KLUDGE_TI_REG,PROCESSOR_REGISTER,KLUDGE_TI_REG);
  asm.emitSTW(KLUDGE_TI_REG,VM_Entrypoints.JNIRefsTopField.getOffset(),S0);
}