* @throws InterruptedException if the Thread is (or was) interrupted;
* it's <i>interrupted status</i> will be cleared
*/
- static void sleep(long ms, int ns) throws InterruptedException
- {
- // Note: JDK treats a zero length sleep is like Thread.yield(),
- // without checking the interrupted status of the thread.
- // It's unclear if this is a bug in the implementation or the spec.
- // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203
- if (ms == 0 && ns == 0)
- {
- if (Thread.interrupted())
- throw new InterruptedException();
- return;
- }
+// static void sleep(long ms, int ns) throws InterruptedException
+// {
+// // Note: JDK treats a zero length sleep is like Thread.yield(),
+// // without checking the interrupted status of the thread.
+// // It's unclear if this is a bug in the implementation or the spec.
+// // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203
+// if (ms == 0 && ns == 0)
+// {
+// if (Thread.interrupted())
+// throw new InterruptedException();
+// return;
+// }
- // Compute end time, but don't overflow
- long now = System.currentTimeMillis();
- long end = now + ms;
- if (end < now)
- end = Long.MAX_VALUE;
+// // Compute end time, but don't overflow
+// long now = System.currentTimeMillis();
+// long end = now + ms;
+// if (end < now)
+// end = Long.MAX_VALUE;
- // A VM is allowed to return from wait() without notify() having been
- // called, so we loop to handle possible spurious wakeups.
- VMThread vt = Thread.currentThread().vmThread;
- synchronized (vt)
- {
- while (true)
- {
- vt.wait(ms, ns);
- now = System.currentTimeMillis();
- if (now >= end)
- break;
- ms = end - now;
- ns = 0;
- }
- }
- }
+// // A VM is allowed to return from wait() without notify() having been
+// // called, so we loop to handle possible spurious wakeups.
+// VMThread vt = Thread.currentThread().vmThread;
+// synchronized (vt)
+// {
+// while (true)
+// {
+// vt.wait(ms, ns);
+// now = System.currentTimeMillis();
+// if (now >= end)
+// break;
+// ms = end - now;
+// ns = 0;
+// }
+// }
+// }
+ static native void sleep(long ms, int ns) throws InterruptedException;
/**
* Determine whether the current Thread has been interrupted, and clear
}
+/*
+ * Class: java/lang/VMThread
+ * Method: sleep
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMThread_sleep(JNIEnv *env, jclass clazz, int64_t ms, int32_t ns)
+{
+#if defined(ENABLE_THREADS)
+ threads_sleep(ms, ns);
+#endif
+}
+
+
/*
* Class: java/lang/VMThread
* Method: interrupted
{ (char*) "nativeStop", (char*) "(Ljava/lang/Throwable;)V", (void*) (uintptr_t) &Java_java_lang_VMThread_nativeStop },
{ (char*) "currentThread", (char*) "()Ljava/lang/Thread;", (void*) (uintptr_t) &Java_java_lang_VMThread_currentThread },
{ (char*) "yield", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_VMThread_yield },
+ { (char*) "sleep", (char*) "(JI)V", (void*) (uintptr_t) &Java_java_lang_VMThread_sleep },
{ (char*) "interrupted", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_VMThread_interrupted },
{ (char*) "holdsLock", (char*) "(Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_VMThread_holdsLock },
{ (char*) "getState", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_VMThread_getState },