Program: 149994
Project: 149994
Buggy source:
/** 
 * Setup a map  within a JSR Subroutine. This requires using up one of the unusual maps. This routine is called when the caller gets a negative mapindex value return from locateGCPoint. This routine searches the map tables and uses its stack frameAddress input to build reference and returnAddress maps. The caller uses the getNext... routines to scan these maps for offsets in the frame of the related references.
 * @param frameAddr         address of stack frame being scanned
 * @param mapid             index of map of instruction where map is required( this value was returned by locateGCpoint) steps for this routine use the mapid to get index of the Unusual Map from the unusual map and the frame - get the location of the jsr invoker from the invoker address and the code base address - get the machine code offset from the machine code offset locate the map for that instruction if the invoker was itself in a jsr- merge the delta maps of each jsr and compute the new total delta maps else the invoker was not already in a jsr merge the unusual map differences with the invoker map
 */
public void setupJSRSubroutineMap(Address frameAddress,int mapid,WordArray registerLocations,VM_CompiledMethod compiledMethod){
  int j=extraUnusualMap.getReferenceMapIndex();
  int k=extraUnusualMap.getNonReferenceMapIndex();
  int l=extraUnusualMap.getReturnAddressMapIndex();
  for (int i=0; i < bytesPerMap; i++) {
    unusualReferenceMaps[j + i]=0;
    unusualReferenceMaps[k + i]=0;
    unusualReferenceMaps[l + i]=0;
  }
  if (VM.TraceStkMaps) {
    VM.sysWriteln("String_Node_Str",mapid,"String_Node_Str",-mapid);
    VM.sysWriteln("String_Node_Str",referenceMaps[(-mapid) * bytesPerMap]);
    VM.sysWriteln("String_Node_Str",referenceMaps[(-mapid) * bytesPerMap] & JSR_INDEX_MASK);
  }
  int unusualMapid=(referenceMaps[(-mapid) * bytesPerMap] & JSR_INDEX_MASK);
  if (unusualMapid == JSR_INDEX_MASK) {
    unusualMapid=findUnusualMap(-mapid);
  }
  VM_QuickUnusualMaps unusualMap=unusualMaps[unusualMapid];
  unusualMapcopy(unusualMap);
  int jsrAddressLocation=unusualMap.getReturnAddressLocation();
  Address jsrAddressAddress=null;
  if (VM_QuickCompiler.isRegister(jsrAddressLocation))   jsrAddressAddress=registerLocations.get(VM_QuickCompiler.locationToRegister(jsrAddressLocation)).toAddress();
 else   jsrAddressAddress=frameAddress.add(VM_QuickCompiler.locationToOffset(jsrAddressLocation));
  Address callerAddress=jsrAddressAddress.loadAddress();
  Offset machineCodeOffset=compiledMethod.getInstructionOffset(callerAddress);
  if (VM.TraceStkMaps) {
    VM.sysWriteln("String_Node_Str",mapid);
    VM.sysWriteln("String_Node_Str",jsrAddressLocation);
    VM.sysWriteln("String_Node_Str",callerAddress);
    VM.sysWriteln("String_Node_Str",machineCodeOffset);
    if (machineCodeOffset.sLT(Offset.zero()))     VM.sysWriteln("String_Node_Str");
  }
  int jsrMapid=locateGCPoint(machineCodeOffset,compiledMethod.getMethod());
  if (VM.TraceStkMaps) {
    VM.sysWriteln("String_Node_Str",jsrMapid);
  }
  while (jsrMapid < 0) {
    jsrMapid=-jsrMapid;
    if (VM.TraceStkMaps) {
      VM.sysWriteln("String_Node_Str",jsrMapid,"String_Node_Str",referenceMaps[jsrMapid]);
    }
    int unusualMapIndex=JSR_INDEX_MASK & referenceMaps[jsrMapid * bytesPerMap];
    if (unusualMapIndex == JSR_INDEX_MASK) {
      unusualMapIndex=findUnusualMap(jsrMapid);
    }
    extraUnusualMap=combineDeltaMaps(unusualMapIndex);
    VM_QuickUnusualMaps thisMap=unusualMaps[unusualMapIndex];
    int thisJsrAddressLocation=thisMap.getReturnAddressLocation();
    Address thisJsrAddressAddress=null;
    if (VM_QuickCompiler.isRegister(thisJsrAddressLocation))     thisJsrAddressAddress=registerLocations.get(VM_QuickCompiler.locationToRegister(thisJsrAddressLocation)).toAddress();
 else     thisJsrAddressAddress=frameAddress.add(VM_QuickCompiler.locationToOffset(thisJsrAddressLocation));
    Address nextCallerAddress=thisJsrAddressAddress.loadAddress();
    Offset nextMachineCodeOffset=compiledMethod.getInstructionOffset(nextCallerAddress);
    jsrMapid=locateGCPoint(nextMachineCodeOffset,compiledMethod.getMethod());
    if (VM.TraceStkMaps) {
      VM.sysWriteln("String_Node_Str");
      extraUnusualMap.showInfo();
      VM.sysWriteln();
      VM.sysWriteln("String_Node_Str");
      thisMap.showInfo();
      VM.sysWriteln();
      VM.sysWriteln("String_Node_Str");
      VM.sysWriteln("String_Node_Str",thisJsrAddressLocation);
      VM.sysWriteln("String_Node_Str",nextCallerAddress);
      VM.sysWriteln("String_Node_Str",nextMachineCodeOffset);
    }
  }
  finalMergeMaps((jsrMapid * bytesPerMap),extraUnusualMap);
  if (VM.TraceStkMaps) {
    VM.sysWriteln("String_Node_Str");
    extraUnusualMap.showInfo();
    VM.sysWriteln();
    VM.sysWriteln("String_Node_Str",mergedReferenceMap);
    VM.sysWrite("String_Node_Str");
    showAnUnusualMap(mergedReferenceMap);
    VM.sysWriteln(unusualReferenceMaps[mergedReferenceMap]);
    VM.sysWriteln("String_Node_Str",mergedReturnAddressMap);
    VM.sysWriteln("String_Node_Str",unusualReferenceMaps[mergedReturnAddressMap]);
    showInfo();
    showUnusualMapInfo();
  }
}

Fixed version (ground truth):
/** 
 * Setup a map  within a JSR Subroutine. This requires using up one of the unusual maps. This routine is called when the caller gets a negative mapindex value return from locateGCPoint. This routine searches the map tables and uses its stack frameAddress input to build reference and returnAddress maps. The caller uses the getNext... routines to scan these maps for offsets in the frame of the related references.
 * @param frameAddr         address of stack frame being scanned
 * @param mapid             index of map of instruction where map is required( this value was returned by locateGCpoint) steps for this routine use the mapid to get index of the Unusual Map from the unusual map and the frame - get the location of the jsr invoker from the invoker address and the code base address - get the machine code offset from the machine code offset locate the map for that instruction if the invoker was itself in a jsr- merge the delta maps of each jsr and compute the new total delta maps else the invoker was not already in a jsr merge the unusual map differences with the invoker map
 */
public void setupJSRSubroutineMap(Address frameAddress,int mapid,WordArray registerLocations,VM_CompiledMethod compiledMethod){
  int j=extraUnusualMap.getReferenceMapIndex();
  int k=extraUnusualMap.getNonReferenceMapIndex();
  int l=extraUnusualMap.getReturnAddressMapIndex();
  for (int i=0; i < bytesPerMap; i++) {
    unusualReferenceMaps[j + i]=0;
    unusualReferenceMaps[k + i]=0;
    unusualReferenceMaps[l + i]=0;
  }
  if (VM.TraceStkMaps) {
    VM.sysWriteln("String_Node_Str",mapid,"String_Node_Str",-mapid);
    VM.sysWriteln("String_Node_Str",referenceMaps[(-mapid) * bytesPerMap]);
    VM.sysWriteln("String_Node_Str",referenceMaps[(-mapid) * bytesPerMap] & JSR_INDEX_MASK);
  }
  int unusualMapid=(referenceMaps[(-mapid) * bytesPerMap] & JSR_INDEX_MASK);
  if (unusualMapid == JSR_INDEX_MASK) {
    unusualMapid=findUnusualMap(-mapid);
  }
  VM_QuickUnusualMaps unusualMap=unusualMaps[unusualMapid];
  unusualMapcopy(unusualMap);
  int jsrAddressLocation=unusualMap.getReturnAddressLocation();
  Address jsrAddressAddress=null;
  if (VM_QuickCompiler.isRegister(jsrAddressLocation))   jsrAddressAddress=registerLocations.get(VM_QuickCompiler.locationToRegister(jsrAddressLocation)).toAddress();
 else   jsrAddressAddress=frameAddress.plus(VM_QuickCompiler.locationToOffset(jsrAddressLocation));
  Address callerAddress=jsrAddressAddress.loadAddress();
  Offset machineCodeOffset=compiledMethod.getInstructionOffset(callerAddress);
  if (VM.TraceStkMaps) {
    VM.sysWriteln("String_Node_Str",mapid);
    VM.sysWriteln("String_Node_Str",jsrAddressLocation);
    VM.sysWriteln("String_Node_Str",callerAddress);
    VM.sysWriteln("String_Node_Str",machineCodeOffset);
    if (machineCodeOffset.sLT(Offset.zero()))     VM.sysWriteln("String_Node_Str");
  }
  int jsrMapid=locateGCPoint(machineCodeOffset,compiledMethod.getMethod());
  if (VM.TraceStkMaps) {
    VM.sysWriteln("String_Node_Str",jsrMapid);
  }
  while (jsrMapid < 0) {
    jsrMapid=-jsrMapid;
    if (VM.TraceStkMaps) {
      VM.sysWriteln("String_Node_Str",jsrMapid,"String_Node_Str",referenceMaps[jsrMapid]);
    }
    int unusualMapIndex=JSR_INDEX_MASK & referenceMaps[jsrMapid * bytesPerMap];
    if (unusualMapIndex == JSR_INDEX_MASK) {
      unusualMapIndex=findUnusualMap(jsrMapid);
    }
    extraUnusualMap=combineDeltaMaps(unusualMapIndex);
    VM_QuickUnusualMaps thisMap=unusualMaps[unusualMapIndex];
    int thisJsrAddressLocation=thisMap.getReturnAddressLocation();
    Address thisJsrAddressAddress=null;
    if (VM_QuickCompiler.isRegister(thisJsrAddressLocation))     thisJsrAddressAddress=registerLocations.get(VM_QuickCompiler.locationToRegister(thisJsrAddressLocation)).toAddress();
 else     thisJsrAddressAddress=frameAddress.plus(VM_QuickCompiler.locationToOffset(thisJsrAddressLocation));
    Address nextCallerAddress=thisJsrAddressAddress.loadAddress();
    Offset nextMachineCodeOffset=compiledMethod.getInstructionOffset(nextCallerAddress);
    jsrMapid=locateGCPoint(nextMachineCodeOffset,compiledMethod.getMethod());
    if (VM.TraceStkMaps) {
      VM.sysWriteln("String_Node_Str");
      extraUnusualMap.showInfo();
      VM.sysWriteln();
      VM.sysWriteln("String_Node_Str");
      thisMap.showInfo();
      VM.sysWriteln();
      VM.sysWriteln("String_Node_Str");
      VM.sysWriteln("String_Node_Str",thisJsrAddressLocation);
      VM.sysWriteln("String_Node_Str",nextCallerAddress);
      VM.sysWriteln("String_Node_Str",nextMachineCodeOffset);
    }
  }
  finalMergeMaps((jsrMapid * bytesPerMap),extraUnusualMap);
  if (VM.TraceStkMaps) {
    VM.sysWriteln("String_Node_Str");
    extraUnusualMap.showInfo();
    VM.sysWriteln();
    VM.sysWriteln("String_Node_Str",mergedReferenceMap);
    VM.sysWrite("String_Node_Str");
    showAnUnusualMap(mergedReferenceMap);
    VM.sysWriteln(unusualReferenceMaps[mergedReferenceMap]);
    VM.sysWriteln("String_Node_Str",mergedReturnAddressMap);
    VM.sysWriteln("String_Node_Str",unusualReferenceMaps[mergedReturnAddressMap]);
    showInfo();
    showUnusualMapInfo();
  }
}