Program: 149864
Project: 149864
Buggy source:
/** 
 * Return the stack trace for use by the Throwable API 
 */
public Element[] getStackTrace(Throwable cause){
  int first=firstRealMethod(cause);
  int last=lastRealMethod(first);
  Element[] elements=new Element[countFrames(first,last)];
  if (!VM.BuildForOptCompiler) {
    int element=0;
    for (int i=first; i <= last; i++) {
      elements[element]=new Element(VM_CompiledMethods.getCompiledMethod(compiledMethods[i]),instructionOffsets[i]);
      element++;
    }
  }
 else {
    int element=0;
    for (int i=first; i <= last; i++) {
      VM_CompiledMethod compiledMethod=VM_CompiledMethods.getCompiledMethod(compiledMethods[i]);
      if ((compiledMethod == null) || (compiledMethod.getCompilerType() != VM_CompiledMethod.OPT)) {
        elements[element]=new Element(compiledMethod,instructionOffsets[i]);
        element++;
      }
 else {
        Offset instructionOffset=Offset.fromIntSignExtend(instructionOffsets[i]);
        VM_OptCompiledMethod optInfo=(VM_OptCompiledMethod)compiledMethod;
        VM_OptMachineCodeMap map=optInfo.getMCMap();
        int iei=map.getInlineEncodingForMCOffset(instructionOffset);
        if (iei < 0) {
          elements[element]=new Element(compiledMethod,instructionOffsets[i]);
          element++;
        }
 else {
          int[] inlineEncoding=map.inlineEncoding;
          int bci=map.getBytecodeIndexForMCOffset(instructionOffset);
          for (; iei >= 0; iei=VM_OptEncodedCallSiteTree.getParent(iei,inlineEncoding)) {
            int mid=VM_OptEncodedCallSiteTree.getMethodID(iei,inlineEncoding);
            VM_Method method=VM_MemberReference.getMemberRef(mid).asMethodReference().getResolvedMember();
            int lineNumber=((VM_NormalMethod)method).getLineNumberForBCIndex(bci);
            elements[element]=new Element(method,lineNumber);
            element++;
          }
        }
      }
    }
  }
  return elements;
}

Fixed version (ground truth):
/** 
 * Return the stack trace for use by the Throwable API 
 */
public Element[] getStackTrace(Throwable cause){
  int first=firstRealMethod(cause);
  int last=lastRealMethod(first);
  Element[] elements=new Element[countFrames(first,last)];
  if (!VM.BuildForOptCompiler) {
    int element=0;
    for (int i=first; i <= last; i++) {
      elements[element]=new Element(getCompiledMethod(i),instructionOffsets[i]);
      element++;
    }
  }
 else {
    int element=0;
    for (int i=first; i <= last; i++) {
      VM_CompiledMethod compiledMethod=getCompiledMethod(i);
      if ((compiledMethod == null) || (compiledMethod.getCompilerType() != VM_CompiledMethod.OPT)) {
        elements[element]=new Element(compiledMethod,instructionOffsets[i]);
        element++;
      }
 else {
        Offset instructionOffset=Offset.fromIntSignExtend(instructionOffsets[i]);
        VM_OptCompiledMethod optInfo=(VM_OptCompiledMethod)compiledMethod;
        VM_OptMachineCodeMap map=optInfo.getMCMap();
        int iei=map.getInlineEncodingForMCOffset(instructionOffset);
        if (iei < 0) {
          elements[element]=new Element(compiledMethod,instructionOffsets[i]);
          element++;
        }
 else {
          int[] inlineEncoding=map.inlineEncoding;
          int bci=map.getBytecodeIndexForMCOffset(instructionOffset);
          for (; iei >= 0; iei=VM_OptEncodedCallSiteTree.getParent(iei,inlineEncoding)) {
            int mid=VM_OptEncodedCallSiteTree.getMethodID(iei,inlineEncoding);
            VM_Method method=VM_MemberReference.getMemberRef(mid).asMethodReference().getResolvedMember();
            int lineNumber=((VM_NormalMethod)method).getLineNumberForBCIndex(bci);
            elements[element]=new Element(method,lineNumber);
            element++;
          }
        }
      }
    }
  }
  return elements;
}