VmMagic.currentProcessor().getScheduler().addToWakeupQueue( proxy);
current.wakeupTime = VmSystem.currentKernelMillis() + timeout; VmMagic.currentProcessor().getScheduler().addToSleepQueue(current);
    public final void Wait(long timeout) throws InterruptedException {        final VmThread current = VmMagic.currentProcessor().getCurrentThread();        // final int id = current.getId();        String exMsg = null;        // Prepare allocations        final VmThreadProxy proxy;        final int waitState;        if (timeout > 0) {            waitState = VmThread.WAITING_NOTIFY_TIMEOUT;            proxy = new VmThreadProxy(current, VmSystem                    .currentKernelMillis()                    + timeout);        } else {            waitState = VmThread.WAITING_NOTIFY;            proxy = new VmThreadProxy(current);        }        // Claim the scheduler and the mutex        VmMagic.currentProcessor().disableReschedule(true, mutex);        if (owner != current) {            VmMagic.currentProcessor().enableReschedule(true, mutex);            exMsg = "Current thread is not the owner of this monitor";        } else if (lockCount == 0) {            VmMagic.currentProcessor().enableReschedule(true, mutex);            exMsg = "Monitor is not locked";        } else {            final int oldLockCount = lockCount;            current.goSleepByMonitor(this, object, proxy, waitState);            notifyQueue.enqueue(proxy);            // If there is a timeout, also add the current thread to the            // sleep queue.            if (timeout > 0) {                VmMagic.currentProcessor().getScheduler().addToWakeupQueue(                        proxy);            }            owner = null;            lockCount = 0;                        final VmThread t = this.enterQueue.dequeue();            if (t != null) {                t.wakeupFromEnterQueue(this);            }                        VmMagic.currentProcessor().suspend(true, mutex);            // When we return here, we have been notified or there            // was a timeout.            if (!current.isRunning()) {                Unsafe.debug("Back from wait, but state != running");                Unsafe.debug("state=");                Unsafe.debug(current.getThreadState());                Unsafe.die("Wait");            }            // We got back here from the enter queue, but we still have to            // reclaim the lock.            enter();                        // Restore lock and lock counter            mutex.lock();            this.lockCount = oldLockCount;            mutex.unlock();        }        if (exMsg != null) {            Unsafe.debug(exMsg);            throw new IllegalMonitorStateException(exMsg);        }        // Check for InterruptedException        current.testAndClearInterruptStatus();    }