Program: 150080
Project: 150080
Buggy source:
/** 
 * After register allocation, go back through the IR and insert compensating code to deal with spills.
 * @param set information from linear scan analysis
 */
void insertSpillCode(OPT_LinearScan.ActiveSet set){
  if (USE_LINEAR_SCAN) {
    activeSet=set;
  }
  if (verboseDebug) {
    System.out.println("String_Node_Str");
  }
  for (Enumeration blocks=ir.getBasicBlocks(); blocks.hasMoreElements(); ) {
    OPT_BasicBlock bb=(OPT_BasicBlock)blocks.nextElement();
    for (Enumeration e=bb.forwardInstrEnumerator(); e.hasMoreElements(); ) {
      boolean beCheap=(ir.options.FREQ_FOCUS_EFFORT && bb.getInfrequent());
      OPT_Instruction s=(OPT_Instruction)e.nextElement();
      if (verboseDebug) {
        System.out.println(s);
      }
      restoreScratchRegistersBefore(s);
      if (s.operator == BBEND || isPEIWithCatch(s) || s.isBranch() || s.isReturn()) {
        restoreAllScratchRegistersBefore(s);
      }
      if (s.operator == YIELDPOINT_PROLOGUE) {
        restoreAllScratchRegistersBefore(s);
      }
      if (s.isGCPoint()) {
        markDirtyScratchRegisters(s);
      }
      for (Enumeration ops=s.getOperands(); ops.hasMoreElements(); ) {
        OPT_Operand op=(OPT_Operand)ops.nextElement();
        if (op != null && op.isRegister()) {
          OPT_Register r=op.asRegister().register;
          if (!r.isPhysical()) {
            ScratchRegister scratch=getCurrentScratchRegister(r,s);
            if (verboseDebug) {
              System.out.println(r + "String_Node_Str" + scratch);
            }
            if (scratch != null) {
              boolean defined=definedIn(r,s) || definesSpillLocation(r,s);
              if (defined) {
                scratch.setDirty(true);
              }
              replaceRegisterWithScratch(s,r,scratch.scratch);
            }
 else {
              if (needScratch(r,s)) {
                boolean used=usedIn(r,s) || usesSpillLocation(r,s);
                boolean defined=definedIn(r,s) || definesSpillLocation(r,s);
                if (used) {
                  if (!usedIn(r,s)) {
                    OPT_Register r2=spillLocationUse(r,s);
                    scratch=moveToScratchBefore(s,r2,beCheap);
                    if (verboseDebug) {
                      System.out.println("String_Node_Str" + r2 + "String_Node_Str"+ scratch);
                    }
                  }
 else {
                    scratch=moveToScratchBefore(s,r,beCheap);
                    if (verboseDebug) {
                      System.out.println("String_Node_Str" + r + "String_Node_Str"+ scratch);
                    }
                  }
                }
                if (defined) {
                  scratch=holdInScratchAfter(s,r,beCheap);
                  scratch.setDirty(true);
                  if (verboseDebug) {
                    System.out.println("String_Node_Str" + r + "String_Node_Str"+ scratch);
                  }
                }
                replaceRegisterWithScratch(s,r,scratch.scratch);
              }
 else {
                if (s.operator != YIELDPOINT_OSR) {
                  replaceOperandWithSpillLocation(s,op.asRegister());
                  VM._assert(NOT_REACHED);
                }
              }
            }
          }
        }
      }
      if (isSysCall(s)) {
        OPT_CallingConvention.saveNonvolatilesAroundSysCall(s,ir);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * After register allocation, go back through the IR and insert compensating code to deal with spills.
 * @param set information from linear scan analysis
 */
void insertSpillCode(OPT_LinearScan.ActiveSet set){
  if (USE_LINEAR_SCAN) {
    activeSet=set;
  }
  if (verboseDebug) {
    System.out.println("String_Node_Str");
  }
  for (Enumeration blocks=ir.getBasicBlocks(); blocks.hasMoreElements(); ) {
    OPT_BasicBlock bb=(OPT_BasicBlock)blocks.nextElement();
    for (Enumeration e=bb.forwardInstrEnumerator(); e.hasMoreElements(); ) {
      boolean beCheap=(ir.options.FREQ_FOCUS_EFFORT && bb.getInfrequent());
      OPT_Instruction s=(OPT_Instruction)e.nextElement();
      if (verboseDebug) {
        System.out.println(s);
      }
      restoreScratchRegistersBefore(s);
      if (s.operator == BBEND || isPEIWithCatch(s) || s.isBranch() || s.isReturn()) {
        restoreAllScratchRegistersBefore(s);
      }
      if (s.operator == YIELDPOINT_PROLOGUE) {
        restoreAllScratchRegistersBefore(s);
      }
      if (s.isGCPoint()) {
        markDirtyScratchRegisters(s);
      }
      for (Enumeration ops=s.getOperands(); ops.hasMoreElements(); ) {
        OPT_Operand op=(OPT_Operand)ops.nextElement();
        if (op != null && op.isRegister()) {
          OPT_Register r=op.asRegister().register;
          if (!r.isPhysical()) {
            ScratchRegister scratch=getCurrentScratchRegister(r,s);
            if (verboseDebug) {
              System.out.println(r + "String_Node_Str" + scratch);
            }
            if (scratch != null) {
              boolean defined=definedIn(r,s) || definesSpillLocation(r,s);
              if (defined) {
                scratch.setDirty(true);
              }
              replaceRegisterWithScratch(s,r,scratch.scratch);
            }
 else {
              if (needScratch(r,s)) {
                boolean used=usedIn(r,s) || usesSpillLocation(r,s);
                boolean defined=definedIn(r,s) || definesSpillLocation(r,s);
                if (used) {
                  if (!usedIn(r,s)) {
                    OPT_Register r2=spillLocationUse(r,s);
                    scratch=moveToScratchBefore(s,r2,beCheap);
                    if (verboseDebug) {
                      System.out.println("String_Node_Str" + r2 + "String_Node_Str"+ scratch);
                    }
                  }
 else {
                    scratch=moveToScratchBefore(s,r,beCheap);
                    if (verboseDebug) {
                      System.out.println("String_Node_Str" + r + "String_Node_Str"+ scratch);
                    }
                  }
                }
                if (defined) {
                  scratch=holdInScratchAfter(s,r,beCheap);
                  scratch.setDirty(true);
                  if (verboseDebug) {
                    System.out.println("String_Node_Str" + r + "String_Node_Str"+ scratch);
                  }
                }
                replaceRegisterWithScratch(s,r,scratch.scratch);
              }
 else {
                replaceOperandWithSpillLocation(s,op.asRegister());
                VM._assert(NOT_REACHED);
              }
            }
          }
        }
      }
      if (isSysCall(s)) {
        OPT_CallingConvention.saveNonvolatilesAroundSysCall(s,ir);
      }
    }
  }
}