Program: 149947
Project: 149947
Buggy source:
/** 
 * Compute the number of stack words needed to hold nonvolatile registers. Side effects:  <ul> <li> updates the VM_OptCompiler structure  <li> updates the <code>frameSize</code> field of this object <li> updates the <code>frameRequired</code> field of this object </ul>
 */
public void computeNonVolatileArea(){
  OPT_PhysicalRegisterSet phys=ir.regpool.getPhysicalRegisterSet();
  if (ir.compiledMethod.isSaveVolatile()) {
    int numGprNv=OPT_PhysicalRegisterSet.getNumberOfNonvolatileGPRs();
    ir.compiledMethod.setNumberOfNonvolatileGPRs((short)numGprNv);
    frameSize+=numGprNv * BYTES_IN_ADDRESS;
    int numFprNv=OPT_PhysicalRegisterSet.getNumberOfNonvolatileFPRs();
    ir.compiledMethod.setNumberOfNonvolatileFPRs((short)numFprNv);
    frameSize+=numFprNv * BYTES_IN_DOUBLE;
    frameSize=align(frameSize,STACKFRAME_ALIGNMENT);
    setFrameRequired();
    int i=0;
    for (Enumeration e=phys.enumerateVolatileGPRs(); e.hasMoreElements(); i++) {
      OPT_Register r=(OPT_Register)e.nextElement();
      saveVolatileGPRLocation[i]=allocateNewSpillLocation(INT_REG);
    }
    i=0;
    for (Enumeration e=phys.enumerateNonvolatileGPRs(); e.hasMoreElements(); i++) {
      OPT_Register r=(OPT_Register)e.nextElement();
      nonVolatileGPRLocation[i]=allocateNewSpillLocation(INT_REG);
    }
    saveXERLocation=allocateNewSpillLocation(INT_REG);
    saveCTRLocation=allocateNewSpillLocation(INT_REG);
    i=0;
    for (Enumeration e=phys.enumerateVolatileFPRs(); e.hasMoreElements(); i++) {
      OPT_Register r=(OPT_Register)e.nextElement();
      saveVolatileFPRLocation[i]=allocateNewSpillLocation(DOUBLE_REG);
    }
    int gprOffset=getNonvolatileGPROffset(0);
    ir.compiledMethod.setUnsignedNonVolatileOffset(gprOffset);
  }
 else {
    int numGprNv=0;
    int i=0;
    for (Enumeration e=phys.enumerateNonvolatileGPRs(); e.hasMoreElements(); ) {
      OPT_Register r=(OPT_Register)e.nextElement();
      if (r.isTouched()) {
        nonVolatileGPRLocation[i++]=allocateNewSpillLocation(INT_REG);
        numGprNv++;
      }
    }
    i=0;
    int numFprNv=0;
    for (Enumeration e=phys.enumerateNonvolatileFPRs(); e.hasMoreElements(); ) {
      OPT_Register r=(OPT_Register)e.nextElement();
      if (r.isTouched()) {
        nonVolatileFPRLocation[i++]=allocateNewSpillLocation(DOUBLE_REG);
        numFprNv++;
      }
    }
    ir.compiledMethod.setNumberOfNonvolatileGPRs((short)numGprNv);
    ir.compiledMethod.setNumberOfNonvolatileFPRs((short)numFprNv);
    if (numGprNv > 0 || numFprNv > 0) {
      int gprOffset=getNonvolatileGPROffset(0);
      ir.compiledMethod.setUnsignedNonVolatileOffset(gprOffset);
      setFrameRequired();
    }
 else {
      ir.compiledMethod.setUnsignedNonVolatileOffset(0);
    }
    frameSize=align(frameSize,STACKFRAME_ALIGNMENT);
  }
}

Fixed version (ground truth):
/** 
 * Compute the number of stack words needed to hold nonvolatile registers. Side effects:  <ul> <li> updates the VM_OptCompiler structure  <li> updates the <code>frameSize</code> field of this object <li> updates the <code>frameRequired</code> field of this object </ul>
 */
public void computeNonVolatileArea(){
  OPT_PhysicalRegisterSet phys=ir.regpool.getPhysicalRegisterSet();
  if (ir.compiledMethod.isSaveVolatile()) {
    int numGprNv=OPT_PhysicalRegisterSet.getNumberOfNonvolatileGPRs();
    ir.compiledMethod.setNumberOfNonvolatileGPRs((short)numGprNv);
    frameSize+=numGprNv * BYTES_IN_ADDRESS;
    int numFprNv=OPT_PhysicalRegisterSet.getNumberOfNonvolatileFPRs();
    ir.compiledMethod.setNumberOfNonvolatileFPRs((short)numFprNv);
    frameSize+=numFprNv * BYTES_IN_DOUBLE;
    setFrameRequired();
    int i=0;
    for (Enumeration e=phys.enumerateVolatileGPRs(); e.hasMoreElements(); i++) {
      OPT_Register r=(OPT_Register)e.nextElement();
      saveVolatileGPRLocation[i]=allocateNewSpillLocation(INT_REG);
    }
    i=0;
    for (Enumeration e=phys.enumerateNonvolatileGPRs(); e.hasMoreElements(); i++) {
      OPT_Register r=(OPT_Register)e.nextElement();
      nonVolatileGPRLocation[i]=allocateNewSpillLocation(INT_REG);
    }
    saveXERLocation=allocateNewSpillLocation(INT_REG);
    saveCTRLocation=allocateNewSpillLocation(INT_REG);
    i=0;
    for (Enumeration e=phys.enumerateVolatileFPRs(); e.hasMoreElements(); i++) {
      OPT_Register r=(OPT_Register)e.nextElement();
      saveVolatileFPRLocation[i]=allocateNewSpillLocation(DOUBLE_REG);
    }
    int gprOffset=getNonvolatileGPROffset(0);
    ir.compiledMethod.setUnsignedNonVolatileOffset(gprOffset);
  }
 else {
    int numGprNv=0;
    int i=0;
    for (Enumeration e=phys.enumerateNonvolatileGPRs(); e.hasMoreElements(); ) {
      OPT_Register r=(OPT_Register)e.nextElement();
      if (r.isTouched()) {
        nonVolatileGPRLocation[i++]=allocateNewSpillLocation(INT_REG);
        numGprNv++;
      }
    }
    i=0;
    int numFprNv=0;
    for (Enumeration e=phys.enumerateNonvolatileFPRs(); e.hasMoreElements(); ) {
      OPT_Register r=(OPT_Register)e.nextElement();
      if (r.isTouched()) {
        nonVolatileFPRLocation[i++]=allocateNewSpillLocation(DOUBLE_REG);
        numFprNv++;
      }
    }
    ir.compiledMethod.setNumberOfNonvolatileGPRs((short)numGprNv);
    ir.compiledMethod.setNumberOfNonvolatileFPRs((short)numFprNv);
    if (numGprNv > 0 || numFprNv > 0) {
      int gprOffset=getNonvolatileGPROffset(0);
      ir.compiledMethod.setUnsignedNonVolatileOffset(gprOffset);
      setFrameRequired();
    }
 else {
      ir.compiledMethod.setUnsignedNonVolatileOffset(0);
    }
  }
  frameSize=align(frameSize,STACKFRAME_ALIGNMENT);
}