sleep 用のシステムコールを呼び出すだけ. ただし, 条件によっては yield 用のシステムコールが呼ばれることもある.
なお, os::sleep() は引数の interruptible の値によって処理が異なることに注意.
なお, java.lang.Thread.sleep() はオーバーロードされており, 2種類存在する.
native メソッド. 実体は JVM_Sleep()
native メソッドではない. 内部的には java.lang.Thread.sleep(long millis) を呼び出すだけ.
なお, 引数の nanos は「500000 以上なら切り上げて millis を 1つ増加させる」という効果しかない (つまり, 今のところ sleep 時間に付いてはミリ秒単位でしか指定はできない). といっても, 普通の OS ではミリ秒以下のスリープ要求は聞いてくれないだろうが... (<= いや自分でビジーループすればいいのか. まぁデスケジューリングされたら終わりだけど...)
JVM_Sleep() (= java.lang.Thread.sleep(long millis))
-> (条件に応じて, 以下のどれかを呼び出す)
* 引数の sleep 時間が 0 で, ConvertSleepToYield オプションも指定されている
-> os::yield()
-> OS によって処理が異なる.
* Linux の場合
-> sched_yield() (<= スレッドが SCHED_OTHER なんだが, この場合も sched_yield() でいいんだっけ?? 要確認 #TODO)
* Solaris の場合
-> os::sleep() (<= 引数の interruptible は false)
-> (上述)
* Windows の場合
-> os::NakedYield()
以下のどちらかを呼び出す.
-> SwitchToThread()
-> Sleep()
* 引数の sleep 時間が 0 で, ConvertSleepToYield オプションは指定されていない
-> os::sleep() (<= 引数の interruptible は false)
-> OS によって処理が異なる.
* Linux の場合
-> ParkEvent::park()
* Solaris の場合
以下のどちらかを呼び出す
-> thr_yield() (<= 指定されたスリープ時間が 0 以下の場合)
-> os_sleep() (<= それ以外の場合)
* Windows の場合
-> Sleep()
* 引数の sleep 時間が 0 ではない
-> os::sleep() (<= 引数の interruptible は true)
* Linux の場合
-> os::is_interrupted()
-> ParkEvent::park()
-> JavaThread::check_and_wait_while_suspended() (See: here for details)
-> JavaThread::handle_special_suspend_equivalent_condition()
-> JavaThread::java_suspend_self()
* Solaris の場合
-> os_sleep()
-> (上述)
-> JavaThread::check_and_wait_while_suspended() (See: here for details)
-> (上述)
* Windows の場合
-> WaitForMultipleObjects()
-> JavaThread::check_and_wait_while_suspended() (See: here for details)
-> (上述)
See: here for details
java.lang.Thread.sleep(long millis) は JVM_Sleep() で実装されている.
((cite: jdk/src/share/native/java/lang/Thread.c))
static JNINativeMethod methods[] = {
...
{"sleep", "(J)V", (void *)&JVM_Sleep},
See: here for details
See: here for details
See: here for details
See: here for details
(#Under Construction) See: here for details
See: here for details
(#Under Construction) See: here for details
See: here for details
See: here for details
See: here for details
(#Under Construction) See: here for details
See: here for details
See: here for details
See: here for details
(#Under Construction) See: here for details
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.