Up Top

Thread の一時停止処理の枠組み (Safepoint 処理) : 停止する側の処理


概要(Summary)

Safepoint 停止に関する機能は SafepointSynchronize クラスの以下のメソッドに定義されている (See: SafepointSynchronize).

備考(Notes)

SafepointSynchronize::begin() と SafepointSynchronize::end() は (ほとんど) VMThread からしか呼び出されない. ただし, 例外的に ConcurrentGCThread からは呼ばれるパスが存在する.

(一瞬だけ stop the world しないといけない処理のために使っている模様) (See: ConcurrentGCThread::stopWorldAndDo())

処理の流れ (概要)(Execution Flows : Summary)

SafepointSynchronize::begin() の処理

SafepointSynchronize::begin()
-> (1) Threads_lock をロックしておく. (これは SafepointSynchronize::end() の中で開放する)
       -> Monitor::lock()

   (1) SafepointSynchronize::_state を _synchronizing に変更

   (1) serialize page のメモリプロテクションを変化させる.
       -> os::serialize_thread_states()

   (1) インタープリタ実行中のスレッドを止めるための処理を行う (dispatch table を Safepoint 用のものに置き換える, 等)
       -> Interpreter::notice_safepoints() (またはそれをサブクラスがオーバーライドしたもの)

   (1) Safepoint Polling page をアクセス不可にしておく.
       -> os::make_polling_page_unreadable()

   (1) 全ての JavaThread の ThreadSafepointState が running 以外の状態に変わるまで待機
       -> ThreadSafepointState::examine_state_of_thread()
       -> ThreadSafepointState::is_running()
       -> SpinPause()  or  os::NakedYield()  or  os::yield_all()

   (1) _waiting_to_block が 0 になるまで待機
       -> Monitior::wait()  (Safepoint_lock に対して. 起こす処理は SafepointSynchronize::block() で行われる)

   (1) SafepointSynchronize::_state を _synchronized に変更

   (1) 様々なクリーンアップ処理を実行
       -> SafepointSynchronize::do_cleanup_tasks()
          -> ObjectSynchronizer::deflate_idle_monitors()
          -> InlineCacheBuffer::update_inline_caches()
          -> CompilationPolicy::do_safepoint_work() (を各サブクラスがオーバーライドしたもの)
          -> NMethodSweeper::scan_stacks()

SafepointSynchronize::end() の処理

SafepointSynchronize::end()
-> (1) Safepoint Polling page をアクセス可能な状態に戻す
       -> os::make_polling_page_readable()

   (1) インタープリタ実行中のスレッドを再開させるための処理を行う (dispatch table を通常時用のものに戻す, 等)
       -> Interpreter::ignore_safepoints() (またはそれをサブクラスがオーバーライドしたもの)

   (1) SafepointSynchronize::_state を _not_synchronized に戻す.

   (1) 全ての JavaThread を起床させる.
       -> ThreadSafepointState::restart()

   (1) Threads_lock のロックを解除する.
       -> Monitor::unlock()

処理の流れ (詳細)(Execution Flows : Details)

SafepointSynchronize::begin()

See: here for details

SafepointSynchronize::deferred_initialize_stat()

See: here for details

os::serialize_thread_states()

See: here for details

TemplateInterpreter::notice_safepoints()

See: here for details

copy_table()

See: here for details

CppInterpreter::notice_safepoints()

See: here for details

os::make_polling_page_unreadable() (Linux の場合)

See: here for details

os::make_polling_page_unreadable() (Solaris の場合)

See: here for details

os::make_polling_page_unreadable() (Windows の場合)

See: here for details

ThreadSafepointState::is_running()

See: here for details

ThreadSafepointState::examine_state_of_thread()

See: here for details

SafepointSynchronize::safepoint_safe()

See: here for details

ThreadSafepointState::roll_forward()

See: here for details

SafepointSynchronize::signal_thread_at_safepoint()

See: here for details

ThreadSafepointState::set_has_called_back()

See: here for details

SpinPause() (Linux x86-32 の場合)

See: here for details

SpinPause() (Linux x86-64 の場合)

See: here for details

SpinPause() (Linux Sparc の場合)

(#Under Construction)

SpinPause() (Linux zero の場合)

See: here for details

SpinPause() (Solaris Sparc の場合)

See: here for details

SpinPause() (Solaris x86 の場合)

(#Under Construction)

SpinPause() (Windows x86 の場合)

See: here for details

os::NakedYield() (Linux の場合)

See: here for details

os::NakedYield() (Solaris の場合)

See: here for details

os::NakedYield() (Windows の場合)

See: here for details

os::yield_all() (Linux の場合)

See: here for details

os::yield_all() (Solaris の場合)

See: here for details

os::yield_all() (Windows の場合)

See: here for details

RuntimeService::record_safepoint_begin()

(#Under Construction)

RuntimeService::record_safepoint_synchronized()

(#Under Construction)

SafepointSynchronize::begin_statistics()

See: here for details

SafepointSynchronize::update_statistics_on_spin_end()

See: here for details

SafepointSynchronize::update_statistics_on_sync_end()

See: here for details

SafepointSynchronize::update_statistics_on_cleanup_end()

See: here for details

SafepointSynchronize::do_cleanup_tasks()

See: here for details

SimpleThresholdPolicy::do_safepoint_work()

See: here for details

NonTieredCompPolicy::do_safepoint_work()

See: here for details

SafepointSynchronize::end()

See: here for details

SafepointSynchronize::end_statistics()

See: here for details

os::make_polling_page_readable() (Linux の場合)

See: here for details

os::make_polling_page_readable() (Solaris の場合)

See: here for details

os::make_polling_page_readable() (Windows の場合)

See: here for details

TemplateInterpreter::ignore_safepoints()

See: here for details

CppInterpreter::ignore_safepoints()

See: here for details


This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.