Program: 149910
Project: 149910
Buggy source:
/** 
 * Run method for collector thread (one per VM_Processor).  Enters an infinite loop, waiting for collections to be requested, performing those collections, and then waiting again.  Calls Collection.collect to perform the collection, which will be different for the different allocators/collectors that the RVM can be configured to use.
 */
@LogicallyUninterruptible @NoOptCompile @BaselineNoRegisters @BaselineSaveLSRegisters @Uninterruptible public void run(){
  for (int count=0; ; count++) {
    VM_GreenScheduler.collectorMutex.lock("String_Node_Str");
    if (verbose >= 1)     VM.sysWriteln("String_Node_Str");
    if (count > 0) {
      VM_GreenProcessor.getCurrentProcessor().enableThreadSwitching();
    }
    VM_GreenScheduler.getCurrentThread().yield(VM_GreenScheduler.collectorQueue,VM_GreenScheduler.collectorMutex);
    VM_GreenProcessor.getCurrentProcessor().disableThreadSwitching("String_Node_Str");
    if (verbose >= 2)     VM.sysWriteln("String_Node_Str");
    gcOrdinal=VM_Synchronization.fetchAndAdd(participantCount,Offset.zero(),1) + 1;
    long startCycles=VM_Time.cycles();
    if (verbose > 2)     VM.sysWriteln("String_Node_Str",gcOrdinal);
    boolean userTriggered=handshake.gcTrigger == Collection.EXTERNAL_GC_TRIGGER;
    if (gcOrdinal == 1) {
      Plan.setUserTriggeredCollection(userTriggered);
    }
    if (verbose >= 2)     VM.sysWriteln("String_Node_Str");
    gcBarrier.startupRendezvous();
    do {
      if (verbose >= 2)       VM.sysWriteln("String_Node_Str");
      if (isActive)       Selected.Collector.get().collect();
      if (verbose >= 2)       VM.sysWriteln("String_Node_Str");
      gcBarrier.rendezvous(5200);
      if (gcOrdinal == 1) {
        long elapsedCycles=VM_Time.cycles() - startCycles;
        HeapGrowthManager.recordGCTime(VM_Time.cyclesToMillis(elapsedCycles));
        if (Selected.Plan.get().lastCollectionFullHeap()) {
          if (Options.variableSizeHeap.getValue() && !userTriggered) {
            HeapGrowthManager.considerHeapSize();
          }
          HeapGrowthManager.reset();
        }
        VM_CompiledMethods.snipObsoleteCompiledMethods();
        collectionCount+=1;
        collectionAttemptBase++;
      }
      startCycles=VM_Time.cycles();
      gcBarrier.rendezvous(5201);
    }
 while (Selected.Plan.get().lastCollectionFailed() && !Selected.Plan.get().isEmergencyCollection());
    if (gcOrdinal == 1) {
      if (Selected.Plan.get().isEmergencyCollection()) {
        Plan.startEmergencyAllocation();
        boolean gcFailed=Selected.Plan.get().lastCollectionFailed();
        for (int t=0; t < VM_Scheduler.getThreadHighWatermark(); t++) {
          VM_Thread thread=VM_Scheduler.threads[t];
          if (thread != null) {
            if (thread.getCollectionAttempt() > 0) {
              if (gcFailed || thread.physicalAllocationFailed()) {
                allocateOOMEForThread(thread);
              }
            }
          }
        }
        Plan.finishEmergencyAllocation();
      }
    }
    if (gcOrdinal == 1) {
      collectionAttemptBase=0;
      handshake.notifyCompletion();
      handshake.reset();
      Collection.scheduleFinalizerThread();
    }
    rendezvous(5210);
    if (verbose > 2)     VM.sysWriteln("String_Node_Str");
    if (gcOrdinal == 1) {
      if (verbose >= 2)       VM.sysWriteln("String_Node_Str");
      for (int i=1; i <= VM_GreenScheduler.numProcessors; i++) {
        VM_GreenProcessor vp=VM_GreenScheduler.processors[i];
        if (VM.VerifyAssertions)         VM._assert(vp != null);
        if (vp.vpStatus == VM_GreenProcessor.BLOCKED_IN_NATIVE) {
          vp.vpStatus=VM_GreenProcessor.IN_NATIVE;
          if (verbose >= 2)           VM.sysWriteln("String_Node_Str",vp.id);
        }
      }
      Plan.collectionComplete();
      gcThreadRunning=false;
    }
    rendezvous(9999);
  }
}

Fixed version (ground truth):
/** 
 * Run method for collector thread (one per VM_Processor).  Enters an infinite loop, waiting for collections to be requested, performing those collections, and then waiting again.  Calls Collection.collect to perform the collection, which will be different for the different allocators/collectors that the RVM can be configured to use.
 */
@LogicallyUninterruptible @NoOptCompile @BaselineNoRegisters @BaselineSaveLSRegisters @Uninterruptible public void run(){
  for (int count=0; ; count++) {
    VM_GreenScheduler.collectorMutex.lock("String_Node_Str");
    if (verbose >= 1)     VM.sysWriteln("String_Node_Str");
    if (count > 0) {
      VM_GreenProcessor.getCurrentProcessor().enableThreadSwitching();
    }
    VM_GreenScheduler.getCurrentThread().yield(VM_GreenScheduler.collectorQueue,VM_GreenScheduler.collectorMutex);
    VM_GreenProcessor.getCurrentProcessor().disableThreadSwitching("String_Node_Str");
    if (verbose >= 2)     VM.sysWriteln("String_Node_Str");
    gcOrdinal=VM_Synchronization.fetchAndAdd(participantCount,Offset.zero(),1) + 1;
    long startCycles=VM_Time.cycles();
    if (verbose > 2)     VM.sysWriteln("String_Node_Str",gcOrdinal);
    boolean userTriggered=handshake.gcTrigger == Collection.EXTERNAL_GC_TRIGGER;
    if (gcOrdinal == 1) {
      Plan.setUserTriggeredCollection(userTriggered);
    }
    if (verbose >= 2)     VM.sysWriteln("String_Node_Str");
    gcBarrier.startupRendezvous();
    do {
      if (verbose >= 2)       VM.sysWriteln("String_Node_Str");
      if (isActive)       Selected.Collector.get().collect();
      if (verbose >= 2)       VM.sysWriteln("String_Node_Str");
      gcBarrier.rendezvous(5200);
      if (gcOrdinal == 1) {
        long elapsedCycles=VM_Time.cycles() - startCycles;
        HeapGrowthManager.recordGCTime(VM_Time.cyclesToMillis(elapsedCycles));
        if (Selected.Plan.get().lastCollectionFullHeap()) {
          if (Options.variableSizeHeap.getValue() && !userTriggered) {
            HeapGrowthManager.considerHeapSize();
          }
          HeapGrowthManager.reset();
        }
        VM_CompiledMethods.snipObsoleteCompiledMethods();
        collectionCount+=1;
        collectionAttemptBase++;
      }
      startCycles=VM_Time.cycles();
      gcBarrier.rendezvous(5201);
    }
 while (Selected.Plan.get().lastCollectionFailed() && !Selected.Plan.get().isEmergencyCollection());
    if (gcOrdinal == 1) {
      if (Selected.Plan.get().isEmergencyCollection()) {
        Plan.startEmergencyAllocation();
        boolean gcFailed=Selected.Plan.get().lastCollectionFailed();
        for (int t=0; t <= VM_Scheduler.getThreadHighWatermark(); t++) {
          VM_Thread thread=VM_Scheduler.threads[t];
          if (thread != null) {
            if (thread.getCollectionAttempt() > 0) {
              if (gcFailed || thread.physicalAllocationFailed()) {
                allocateOOMEForThread(thread);
              }
            }
          }
        }
        Plan.finishEmergencyAllocation();
      }
    }
    if (gcOrdinal == 1) {
      collectionAttemptBase=0;
      handshake.notifyCompletion();
      handshake.reset();
      Collection.scheduleFinalizerThread();
    }
    rendezvous(5210);
    if (verbose > 2)     VM.sysWriteln("String_Node_Str");
    if (gcOrdinal == 1) {
      if (verbose >= 2)       VM.sysWriteln("String_Node_Str");
      for (int i=1; i <= VM_GreenScheduler.numProcessors; i++) {
        VM_GreenProcessor vp=VM_GreenScheduler.processors[i];
        if (VM.VerifyAssertions)         VM._assert(vp != null);
        if (vp.vpStatus == VM_GreenProcessor.BLOCKED_IN_NATIVE) {
          vp.vpStatus=VM_GreenProcessor.IN_NATIVE;
          if (verbose >= 2)           VM.sysWriteln("String_Node_Str",vp.id);
        }
      }
      Plan.collectionComplete();
      gcThreadRunning=false;
    }
    rendezvous(9999);
  }
}