Program: 149995
Project: 149995
Buggy source:
/** 
 * Given a machine code instruction offset, return an index to identify the stack map closest to the offset ( but not beyond) Usage note: "machCodeOffset" must point to the instruction *following the actual instruction whose stack map is sought. This allows us to properly handle the case where the only address we have to work with is a return address (ie. from a stackframe) or an exception address (ie. from a null pointer dereference, array bounds check, or divide by zero) on a machine architecture with variable length instructions. In such situations we'd have no idea how far to back up the instruction pointer to point to the "call site" or "exception site". If the located site is within the scope of a jsr subroutine the index value returned is a negative number
 */
public int locateGCPoint(Offset machCodeOffset,VM_Method method){
  machCodeOffset=machCodeOffset.sub(1 << VM.LG_INSTRUCTION_WIDTH);
  if (VM.TraceStkMaps) {
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(machCodeOffset);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(method.getName());
    VM.sysWrite("String_Node_Str");
  }
  Offset distance=Offset.zero();
  int index=0;
  for (int i=0; i < mapCount; i++) {
    distance=machCodeOffset.sub(MCSites[i]);
    if (distance.sGE(Offset.zero())) {
      index=i;
      break;
    }
  }
  for (int i=index + 1; i < mapCount; i++) {
    Offset dist=machCodeOffset.sub(MCSites[i]);
    if (dist.sLT(Offset.zero()))     continue;
    if (dist.sLE(distance)) {
      index=i;
      distance=dist;
    }
  }
  if (VM.TraceStkMaps) {
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(index);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(referenceMaps[index]);
    VM.sysWrite("String_Node_Str");
    if (index - 1 >= 0) {
      VM.sysWrite("String_Node_Str");
      VM.sysWrite(machCodeOffset.sub(MCSites[index - 1]));
      VM.sysWrite("String_Node_Str");
    }
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(machCodeOffset.sub(MCSites[index]));
    VM.sysWrite("String_Node_Str");
    if (index + 1 < MCSites.length) {
      VM.sysWrite("String_Node_Str");
      VM.sysWrite(machCodeOffset.sub(MCSites[index + 1]));
      VM.sysWrite("String_Node_Str");
    }
  }
  if ((0x000000FF & (referenceMaps[index * bytesPerMap] & JSR_MASK)) == (0x000000FF & JSR_MASK)) {
    index=-index;
    if (VM.TraceStkMaps) {
      VM.sysWrite("String_Node_Str");
      VM.sysWrite(-index);
      VM.sysWrite("String_Node_Str");
    }
  }
  if (VM.TraceStkMaps) {
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(machCodeOffset);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(index);
    VM.sysWrite("String_Node_Str");
  }
  return index;
}

Fixed version (ground truth):
/** 
 * Given a machine code instruction offset, return an index to identify the stack map closest to the offset ( but not beyond) Usage note: "machCodeOffset" must point to the instruction *following the actual instruction whose stack map is sought. This allows us to properly handle the case where the only address we have to work with is a return address (ie. from a stackframe) or an exception address (ie. from a null pointer dereference, array bounds check, or divide by zero) on a machine architecture with variable length instructions. In such situations we'd have no idea how far to back up the instruction pointer to point to the "call site" or "exception site". If the located site is within the scope of a jsr subroutine the index value returned is a negative number
 */
public int locateGCPoint(Offset machCodeOffset,VM_Method method){
  machCodeOffset=machCodeOffset.minus(1 << VM.LG_INSTRUCTION_WIDTH);
  if (VM.TraceStkMaps) {
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(machCodeOffset);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(method.getName());
    VM.sysWrite("String_Node_Str");
  }
  Offset distance=Offset.zero();
  int index=0;
  for (int i=0; i < mapCount; i++) {
    distance=machCodeOffset.minus(MCSites[i]);
    if (distance.sGE(Offset.zero())) {
      index=i;
      break;
    }
  }
  for (int i=index + 1; i < mapCount; i++) {
    Offset dist=machCodeOffset.minus(MCSites[i]);
    if (dist.sLT(Offset.zero()))     continue;
    if (dist.sLE(distance)) {
      index=i;
      distance=dist;
    }
  }
  if (VM.TraceStkMaps) {
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(index);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(referenceMaps[index]);
    VM.sysWrite("String_Node_Str");
    if (index - 1 >= 0) {
      VM.sysWrite("String_Node_Str");
      VM.sysWrite(machCodeOffset.minus(MCSites[index - 1]));
      VM.sysWrite("String_Node_Str");
    }
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(machCodeOffset.minus(MCSites[index]));
    VM.sysWrite("String_Node_Str");
    if (index + 1 < MCSites.length) {
      VM.sysWrite("String_Node_Str");
      VM.sysWrite(machCodeOffset.minus(MCSites[index + 1]));
      VM.sysWrite("String_Node_Str");
    }
  }
  if ((0x000000FF & (referenceMaps[index * bytesPerMap] & JSR_MASK)) == (0x000000FF & JSR_MASK)) {
    index=-index;
    if (VM.TraceStkMaps) {
      VM.sysWrite("String_Node_Str");
      VM.sysWrite(-index);
      VM.sysWrite("String_Node_Str");
    }
  }
  if (VM.TraceStkMaps) {
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(machCodeOffset);
    VM.sysWrite("String_Node_Str");
    VM.sysWrite(index);
    VM.sysWrite("String_Node_Str");
  }
  return index;
}