myEnv.alwaysHasNativeFrame = true; myEnv.JNITopJavaFP = VM_Address.fromInt(VM_Constants.STACKFRAME_SENTINAL_FP); myEnv.savedPRreg = nativeVP;   myEnv.savedTIreg = VM_Magic.getThreadId();
myEnv.setFromNative( VM_Address.fromInt(VM_Constants.STACKFRAME_SENTINAL_FP), nativeVP, VM_Magic.getThreadId());
  public void run() //- overrides VM_Thread  {    if (VM.TraceThreads) VM_Scheduler.trace("VM_JNIStartUp", "run");    if (trace) {      System.out.println("VM_JNIStartUp: Java thread " + 			 VM.intAsHexString(VM_Magic.objectAsAddress(VM_Thread.getCurrentThread()).toInt()) +			 " attaching external pthread " + pthreadID + "\n");      System.out.println("JNIEnv to be placed at " + VM.intAsHexString(externalJNIEnvAddress.toInt()));          }    // before executing the following code, bind ourselves to the current processor    VM_Processor currentVP = VM_Processor.getCurrentProcessor();    VM_Thread.getCurrentThread().processorAffinity = currentVP;    // Set up the JNICleanUpThread that will signal the external pthread    // it will also be bound to the same processor    VM_JNICreateVMFinishThread cleanupThread =       new VM_JNICreateVMFinishThread(VM_Thread.getCurrentThread(),				      externalJNIEnvAddress,				      currentVP);    // get it going    cleanupThread.start(currentVP.readyQueue);    // wait for it to come up    if (trace) {            System.out.println("VM_JNIStartUp: AttachCurrentThread waiting for clean up thread");     }    while (!cleanupThread.ready) {      VM_Thread.getCurrentThread().yield();    }    /***************************************************************************     * Now we prepare the data structure to create the appearance that the Java main     * thread has made a native method call and is executing in the native pthread     */    // Set up the native VM_Processor to associate with the external pthread    VM_Processor nativeVP = VM_Processor.createNativeProcessorForExistingOSThread(VM_Thread.getCurrentThread());     VM_Thread.getCurrentThread().nativeAffinity = nativeVP;    // register the vpStatusAddress for this thread in the VM_JNIEnvironment.JNIFunctionPointers    // this is normally done in the prolog of the native method on the Java to C transition    VM_JNIEnvironment.JNIFunctionPointers[(VM_Thread.getCurrentThread().getIndex() * 2) + 1] =       nativeVP.vpStatusAddress.toInt();    // normally done by StartupThread    nativeVP.pthread_id = pthreadID;    ++nativeVP.threadSwitchingEnabledCount;    // Set up the JNI environment for this thread for the external pthread    // to make JNI calls    VM_JNIEnvironment myEnv = VM_Thread.getCurrentThread().getJNIEnv();    myEnv.alwaysHasNativeFrame = true;     // indicate that no stack resize should occur    myEnv.JNITopJavaFP = VM_Address.fromInt(VM_Constants.STACKFRAME_SENTINAL_FP);      // indicate to GC that no Java stack frame below this point    myEnv.savedPRreg = nativeVP;       // make sure no locking is done after this point or lock info may be lost    myEnv.savedTIreg = VM_Magic.getThreadId();          // set affinity so JNI calls will get scheduled on this VM_Processor    VM_Thread.getCurrentThread().returnAffinity = VM_Processor.getCurrentProcessor();    if (trace) {      System.out.println("VM_JNIStartUp: attach done, moving thread to native VM_Processor ... ");    }    // take this main thread off the current VM_Processor    // from this point, it exists on the native VM_Processor and will    // only resume execution when the associated pthread make a JNI call    VM_Thread.getCurrentThread().beingDispatched = true;    cleanupThread.proceedToFinish = true;    VM_Thread.morph();    // Resume execution here when the associated pthread attempts to detach    // The thread state is restored here by JNIServiceThread    // We are now running on the original Java stack instead of the pthread stack    if (trace) {      System.out.println("VM_JNIStartUp: attached thread terminated, " +			 Thread.currentThread().getName() + ", " + 			 VM.intAsHexString(VM_Magic.objectAsAddress(VM_Thread.getCurrentThread()).toInt()));    }    // remove the VP data structure from the list maintained for GC    if (VM_Processor.unregisterAttachedProcessor(nativeVP)==0)      VM.sysWrite("ERROR:  VM_Processor for JNI_CreateJavaVM was not registered\n");    VM_Thread.terminate();  }