if (VM.BuildForCpuMonitoring) VM_RuntimeMeasurements.monitorThreadExit();
  private static void startoff () {  //VM_Scheduler.trace("VM_Thread", "startoff");    VM_Thread currentThread = getCurrentThread();    currentThread.run();    terminate();    if (VM.VerifyAssertions) VM.assert(VM.NOT_REACHED);  }   /**   * Terminate execution of current thread by abandoning all    * references to it and   * resuming execution in some other (ready) thread.   */   static void terminate () {    boolean terminateSystem = false;    //VM_Scheduler.trace("VM_Thread", "terminate");    VM_Thread myThread = getCurrentThread();    // allow java.lang.Thread.exit() to remove this thread from ThreadGroup    myThread.exit();     synchronized (myThread) { // release anybody waiting on this thread - 	// begin critical section	//	VM_Scheduler.threadCreationMutex.lock();	VM_Processor.getCurrentProcessor().disableThreadSwitching();		// in particular, see java.lang.Thread.join()	myThread.isAlive = false;	myThread.notifyAll();    }	//-#if RVM_WITH_ADAPTIVE_SYSTEM    if (VM.BuildForCpuMonitoring) VM_RuntimeMeasurements.monitorThreadExit();//-#endif    //    // if the thread terminated because of an exception, remove    // the mark from the exception register object, or else the    // garbage collector will attempt to relocate its ip field.    myThread.hardwareExceptionRegisters.inuse = false;        VM_Scheduler.numActiveThreads -= 1;    if (myThread.isDaemon)      VM_Scheduler.numDaemons -= 1;    if (VM_Scheduler.numDaemons == VM_Scheduler.numActiveThreads) {      // no non-daemon thread remains      terminateSystem = true;    }    // end critical section    //    VM_Processor.getCurrentProcessor().enableThreadSwitching();    VM_Scheduler.threadCreationMutex.unlock();    if (VM.VerifyAssertions)       VM.assert(VM_Processor.getCurrentProcessor().threadSwitchingEnabled());    if (terminateSystem) {      VM.sysExit(0);      if (VM.VerifyAssertions) VM.assert(VM.NOT_REACHED);    }    //add Native Thread Virtual Processor to dead VP queue    // check for  native processor    VM_Processor p  = myThread.nativeAffinity;              if ( p != null) {      // put VP on dead queue      VM_Scheduler.deadVPQueue.enqueue(p);                        myThread.nativeAffinity    = null;          // clear native processor      myThread.processorAffinity = null;          // clear processor affinity//-#if RVM_WITH_PURPLE_VPS      VM_Processor.vpStatus[p.vpStatusIndex] = VM_Processor.RVM_VP_GOING_TO_WAIT;//-#endif    }       // become another thread    // begin critical section    //    VM_Scheduler.threadCreationMutex.lock();    myThread.beingDispatched = true;    VM_Scheduler.deadQueue.enqueue(myThread);    VM_Scheduler.threadCreationMutex.unlock();    VM_Magic.saveThreadState(myThread.contextRegisters);    VM_Processor.getCurrentProcessor().dispatch();    if (VM.VerifyAssertions) VM.assert(VM.NOT_REACHED);  }    /**   * Get this thread's index in VM_Scheduler.threads[]   */   public final int getIndex() { return threadSlot; }