if (t.beingDispatched && t != VM_Thread.getCurrentThread()) { VM_Scheduler.trace("VM_Processor", "getRunnableThread: readyQueue BUG", t.getIndex()); VM.sysWrite("current thread: "); VM_Thread.getCurrentThread().dump(); VM.sysWrite("offending thread: "); t.dump(); VM.assert(this == getCurrentProcessor()); VM_Scheduler.dumpVirtualMachine(); VM.sysExit(666); }
if (VM.VerifyAssertions) VM.assert(t.beingDispatched == false || t == VM_Thread.getCurrentThread());
  private VM_Thread getRunnableThread() {    VM_Magic.pragmaInline();    if (!transferQueue.isEmpty()) {      transferMutex.lock();      VM_Thread t = transferQueue.dequeue();      transferMutex.unlock();      if (t.beingDispatched && t != VM_Thread.getCurrentThread()) { // thread's stack in use by some OTHER dispatcher	if (trace) VM_Scheduler.trace("VM_Processor", "getRunnableThread: stack in use", t.getIndex());	transferMutex.lock();	transferQueue.enqueue(t);	transferMutex.unlock();      } else {	if (trace) VM_Scheduler.trace("VM_Processor", "getRunnableThread: transferQueue", t.getIndex());	return t;      }    }    if (!readyQueue.isEmpty()) {      VM_Thread t = readyQueue.dequeue();      if (trace) VM_Scheduler.trace("VM_Processor", "getRunnableThread: readyQueue", t.getIndex());      //      if (VM.VerifyAssertions) VM.assert(t.beingDispatched == false || t == VM_Thread.getCurrentThread()); // local queue: no other dispatcher should be running on thread's stack      if (t.beingDispatched && t != VM_Thread.getCurrentThread()) {	VM_Scheduler.trace("VM_Processor", "getRunnableThread: readyQueue BUG", t.getIndex());	VM.sysWrite("current thread: ");	VM_Thread.getCurrentThread().dump();	VM.sysWrite("offending thread: ");	t.dump();	VM.assert(this == getCurrentProcessor());	VM_Scheduler.dumpVirtualMachine();	VM.sysExit(666);      }      return t;    }    if (ioQueue.isReady()) {      VM_Thread t = ioQueue.dequeue();      if (trace) VM_Scheduler.trace("VM_Processor", "getRunnableThread: ioQueue", t.getIndex());      if (VM.VerifyAssertions) VM.assert(t.beingDispatched == false || t == VM_Thread.getCurrentThread()); // local queue: no other dispatcher should be running on thread's stack      return t;    }    if(!transferQueue.isEmpty()){      transferMutex.lock();      VM_Thread t = transferQueue.dequeue();      transferMutex.unlock();      if (!t.beingDispatched || t == VM_Thread.getCurrentThread()) {	if (trace) VM_Scheduler.trace("VM_Processor", "getRunnableThread: transferQueue", t.getIndex());	return t;      }      if (!VM_Thread.getCurrentThread().isNativeIdleThread) {	while(t.beingDispatched){	  VM_Magic.isync();	}        if (trace) VM_Scheduler.trace("VM_Processor", "getRunnableThread: transferQueue", t.getIndex());	return t;        }      // A nativeIdleThread trying to get back to its native vitrual processor.        // Let the idle thread run (possible deadlock otherwise).      if (trace) VM_Scheduler.trace("VM_Processor", "getRunnableThread: stack in use", t.getIndex());      transferMutex.lock();      transferQueue.enqueue(t);      transferMutex.unlock();    }    if (!idleQueue.isEmpty()) {      VM_Thread t = idleQueue.dequeue();      if (trace) VM_Scheduler.trace("VM_Processor", "getRunnableThread: idleQueue", t.getIndex());      if (VM.VerifyAssertions) VM.assert(t.beingDispatched == false || t == VM_Thread.getCurrentThread()); // local queue: no other dispatcher should be running on thread's stack      return t;    }    // if the idle thread isn't on the idle queue,     // it must be on the transfer queue    for (int i=transferQueue.length(); 0<i; i--) {       transferMutex.lock();      VM_Thread t = transferQueue.dequeue();      transferMutex.unlock();      if (!t.beingDispatched || t == VM_Thread.getCurrentThread()) {         if (trace) VM_Scheduler.trace("VM_Processor", "getRunnableThread: transferQueue", t.getIndex());	return t;      }      if (trace) VM_Scheduler.trace("VM_Processor", "getRunnableThread: stack in use", t.getIndex());      transferMutex.lock();      transferQueue.enqueue(t);      transferMutex.unlock();    } 	       // should not get here    debugGetRunnableThread();     VM.assert(VM.NOT_REACHED);    return null;  }