内部的には FlatProfiler クラスおよび FlatProfilerTask クラスによって実現されている (See: FlatProfiler) (See: FlatProfilerTask).
起動時に FlatProfiler クラスによって FlatProfilerTask オブジェクトが生成され, 以後は定期間隔で FlatProfilerTask から以下の関数が呼び出される.
これらの関数で集められた統計情報は, HotSpot の終了時に FlatProfiler クラスによって出力される.
FlatProfiler::record_vm_tick() では, プロファイリング情報取得のタイミングで実行中だった関数名を取得する.
この際には OS 依存の方法で対象のスレッドを停止させている (なお, これらのスレッド停止手法は現状ではここでしか使われていない).
(HotSpot の起動時処理) (See: here for details) -> Threads::create_vm() -> FlatProfiler::engage()
(HotSpot の起動時処理) (See: here for details) -> Threads::create_vm() -> os::init_2() -> SR_initialize()
FlatProfilerTask::task()
-> (1) ProfileVM オプションが指定されている場合, 以下の計測処理を行う.
-> FlatProfiler::record_vm_tick()
-> os::get_thread_pc()
-> * Linux の場合
* 停止させる側
-> do_suspend()
-> os::Linux::SuspendResume::set_suspend_action()
-> pthread_kill() (<= SR_handler() を起動させて処理を停止させる)
-> os::Linux::ucontext_get_pc()
-> do_resume()
-> os::Linux::SuspendResume::set_suspend_action()
-> pthread_kill() (<= 処理を再開させる)
* 停止させられる側
-> SR_handler()
-> os::Linux::SuspendResume::set_suspended()
-> sigsuspend() (<= 再開させられるまで待機)
-> resume_clear_context()
* Solaris の場合
* 停止させる側
-> OSThread::Sync_Interrupt_Callback::interrupt()
-> OSThread::set_interrupt_callback()
-> thr_kill() (<= シグナルハンドラを起動させる)
-> Monitor::wait() (<= 処理が終わるまで待機)
-> OSThread::remove_interrupt_callback()
-> GetThreadPC_Callback::addr()
* 停止させられる側
-> JVM_handle_solaris_signal()
-> OSThread::do_interrupt_callbacks_at_interrupt()
-> GetThreadPC_Callback::execute()
-> OSThread::Sync_Interrupt_Callback::leave_callback()
-> Monitor::notify_all() (<= 停止させる側を起床させる)
* Windows の場合
* 停止させる側
-> GetThreadContext()
(2) 何らかの VM_Operation が実行中の場合, 以下の計測処理を行う.
-> FlatProfiler::record_vm_operation()
(3) Safepoint が開始されていない場合, 以下の計測処理を行う.
-> FlatProfiler::record_thread_ticks()
(See: here for details) -> before_exit() -> FlatProfiler::disengage() -> FlatProfiler::print()
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
(#Under Construction) See: here for details
(#Under Construction)
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.