target.registerThread();
  static VM_Processor createNativeProcessor () {    int processId = generateNativeProcessorId();    VM_Processor newProcessor = new VM_Processor(processId, NATIVE);    // create idle thread for processor    VM_Thread t = new VM_NativeIdleThread(newProcessor);    t.isAlive = true;    // There is a race between the native pthread which will be started shortly    // and will run and intilize its idle thread, and our pthread/thread which    // will shortly enqueus the current thread on the native processor transfer    // queue.  If we win the race, the the native idle thread will not intialize    // properly.  To avoid this we enqueue the idle thread on the transfer queue    // of the native processor now, before the native pthread starts.    //    ////newProcessor.idleQueue.enqueue(t);    newProcessor.transferQueue.enqueue(t);    // create VM_Thread for virtual cpu to execute    //    VM_Thread target = new VM_StartupThread(VM_RuntimeStructures.newStack(STACK_SIZE_NORMAL));    // create virtual cpu and wait for execution to enter target's code/stack.    // this is done with gc disabled to ensure that garbage     // collector doesn't move    // code or stack before the C startoff function has a chance    // to transfer control into vm image.    //    if (trace)       VM_Scheduler.trace("VM_Processor",                          "starting native virtual cpu pthread ");    // Acquire global GC lockout field (at fixed address in the boot record).    // This field will be released by this thread when it runs on the native     // processor and transfers control to the native code.    // get the GC lockout lock .. yield if someone else has it    while (true) {      int lockoutVal = VM_Magic.prepare(VM_BootRecord.the_boot_record, 					VM_Entrypoints.lockoutProcessorOffset);      if ( lockoutVal == 0){	lockoutId   = 	if(VM_Magic.attempt(VM_BootRecord.the_boot_record, 			    VM_Entrypoints.lockoutProcessorOffset,			    VM_Magic.objectAsAddress                            (VM_ProcessorLocalState.getCurrentProcessor()),			    0, lockoutId))          break;      }else VM_Thread.yield();    }    newProcessor.activeThread = target;    newProcessor.activeThreadStackLimit = target.stackLimit;    //-#if RVM_FOR_POWERPC    VM.sysVirtualProcessorCreate(VM_Magic.getTocPointer(),                                 VM_Magic.objectAsAddress(newProcessor),                                 target.contextRegisters.gprs[VM.THREAD_ID_REGISTER],                                 target.contextRegisters.gprs[VM.FRAME_POINTER]);    //-#endif    //-#if RVM_FOR_IA32    VM.sysVirtualProcessorCreate(VM_Magic.getTocPointer(),                                 VM_Magic.objectAsAddress(newProcessor),                                 0,                                  target.contextRegisters.gprs[VM.FRAME_POINTER]);    //-#endif    while (!newProcessor.isInitialized)      VM.sysVirtualProcessorYield();    ///    VM.enableGC();    if (trace)       VM_Scheduler.trace("VM_Processor", "started native virtual cpu pthread ");    return newProcessor;  }   /***********  static VM_Processor getRVMProcessor () {    // does current thread have a processor affinity    //    VM_Processor p = VM_Thread.getCurrentThread().processorAffinity;    if ( p != null) return p;    // if a processor is idle, put thread there    //    p = idleProcessor;    if ( p != null) {      idleProcessor = null;      return p;    }    // otherwise round robin    //    return getCurrentProcessor().chooseNextProcessor();       **************///-#else  // default implementation of jni  // create a native processor for default implementation of jni  //  static VM_Processor createNativeProcessor () {//-#if RVM_FOR_IA32    // NOT YET IMPLEMENTED !!!    VM.sysWrite("VM_Processor createNativeProcessor NOT YET IMPLEMENTED for IA32\n");    VM.sysExit(666);    return null;//-#else    // create native processor object without id - set later    VM_Processor newProcessor = new VM_Processor(0, NATIVE);    VM.disableGC();    // add to native Processors array-  note: GC will see it now    synchronized (nativeProcessorCountLock) {        int processId = generateNativeProcessorId();      newProcessor.id = processId;        nativeProcessors[-processId] = newProcessor;      if (debug_native) {        VM_Scheduler.trace( "VM_Processor",                             "created native processor", processId);      }    }    VM.enableGC();    // create idle thread for processor - with affinity to native processor.    // ?? will this affinity be a problem when idle thread temporarily migrates    // ?? to a blue processor ??    VM_Thread t = new VM_NativeIdleThread(newProcessor);    t.isAlive = true;    newProcessor.transferQueue.enqueue(t);    // create VM_Thread for virtual cpu to execute    //    VM_Thread target = new VM_StartupThread(VM_RuntimeStructures.newStack(STACK_SIZE_NORMAL));    // create virtual cpu and wait for execution to enter target's code/stack.    // this is done with gc disabled to ensure that garbage     // collector doesn't move    // code or stack before the C startoff function has a chance    // to transfer control into vm image.    VM.disableGC();    //-#if RVM_FOR_SINGLE_VIRTUAL_PROCESSOR    //-#else		// Need to set startuplock here    VM.sysInitializeStartupLocks(1);		//-#endif    newProcessor.activeThread = target;    newProcessor.activeThreadStackLimit = target.stackLimit;    VM.sysVirtualProcessorCreate(VM_Magic.getTocPointer(),				 VM_Magic.objectAsAddress(newProcessor),				 target.contextRegisters.gprs[VM.THREAD_ID_REGISTER],				 target.contextRegisters.gprs[VM.FRAME_POINTER]);    while (!newProcessor.isInitialized)      VM.sysVirtualProcessorYield();    VM.enableGC();    if (debug_native) {      VM_Scheduler.trace("VM_Processor", "started native processor",                          newProcessor.id);      VM_Scheduler.trace("VM_Processor", "native processor pthread_id",                          newProcessor.pthread_id);    }    return newProcessor;//-#endif  } // createNativeProcessor//-#endif  //---------------------//  // Garbage Collection  //  //---------------------////-#if RVM_WITH_DEDICATED_NATIVE_PROCESSORS// alternate implementation of jni  /**   * sets the VP state to indicate that VP is part of GC that is starting   *  returns the previous value of VPState   */   public int  setGCState () {    int newState, oldState;    do{      oldState = VM_Magic.prepare(this, VM_Entrypoints.vpStateOffset);      if (VM.VerifyAssertions) VM.assert((oldState & GC_IN_PROGRESS) == 0) ;      newState = oldState | GC_IN_PROGRESS;    }while (! (VM_Magic.attempt(this, VM_Entrypoints.vpStateOffset,                                 oldState, newState)));    return oldState;  }