「VM定期タスクスレッド」WatcherThreadはJVM監視ルーチンをどのように起動しますか?
「WatcherThread」と言います。これは定期的に タスクを実行するVMスレッドです(パフォーマンスカウンタの更新など)。
スレッドのlink
定期的なタスクスケジューリングを参照してください、それはWatcherThreadによって設立された、シングルトンオブジェクトです。
JVMのスレッドが頻繁に使用される、たとえば、メモリ監視の実行中の状態、JVMの定期的な監視。そして、私たちはしばしば、GCの場合には
jstat
このコマンドを実行する必要があります。次のようになります。
jstat -gcutil 234832507
このコマンドを実行すると、コンソールのJVMはPID:GC 23483、250ミリ秒の間隔a、計7回以上のプリントを出力します。
これは私がJVMのソースコードで見つけるものですlink
を参照してください。
"VM Periodic Task Thread"(WatcherThread)が起動すると "実行"機能が実行されるはずです。 私が気づく唯一の事は、whileループで回転することです。 ウォッチャースレッドはjstat
のようなJVM監視ルーチンをどのように起動しますか? このwhileループではjstat
のサブルーチンはどこにありますか? WatcherThreadがパフォーマンスカウンターなどを更新する方法が不思議です。
void WatcherThread::run() {
assert(this == watcher_thread(), "just checking");
this->record_stack_base_and_size();
this->set_native_thread_name(this->name());
this->set_active_handles(JNIHandleBlock::allocate_block());
while (true) {
assert(watcher_thread() == Thread::current(), "thread consistency check");
assert(watcher_thread() == this, "thread consistency check");
// Calculate how long it'll be until the next PeriodicTask work
// should be done, and sleep that amount of time.
int time_waited = sleep(); // return 50
if (is_error_reported()) {
// A fatal error has happened, the error handler(VMError::report_and_die)
// should abort JVM after creating an error log file. However in some
// rare cases, the error handler itself might deadlock. Here we try to
// kill JVM if the fatal error handler fails to abort in 2 minutes.
//
// This code is in WatcherThread because WatcherThread wakes up
// periodically so the fatal error handler doesn't need to do anything;
// also because the WatcherThread is less likely to crash than other
// threads.
for (;;) {
if (!ShowMessageBoxOnError
&& (OnError == NULL || OnError[0] == '\0')
&& Arguments::abort_hook() == NULL) {
os::sleep(this, (jlong)ErrorLogTimeout * 1000, false); // in seconds
fdStream err(defaultStream::output_fd());
err.print_raw_cr("# [ timer expired, abort... ]");
// skip atexit/vm_exit/vm_abort hooks
os::die();
}
// Wake up 5 seconds later, the fatal handler may reset OnError or
// ShowMessageBoxOnError when it is ready to abort.
os::sleep(this, 5 * 1000, false);
}
}
if (_should_terminate) {
// check for termination before posting the next tick
break;
}
PeriodicTask::real_time_tick(time_waited);
}
// Signal that it is terminated
{
MutexLockerEx mu(Terminator_lock, Mutex::_no_safepoint_check_flag);
_watcher_thread = NULL;
Terminator_lock->notify();
}
}
'jstat'はコマンドラインツールです。私はJVMが外部コマンドラインツールを呼び出さないことを確信しています。このループは明らかに、各定期的な反復で 'PeriodicTask :: real_time_tick'を呼び出します。それに加えて、あなたは、そのソースを参照することなく、テキストのブロックを引用しました。誰がそれをどんな文脈で書いていますか? – Holger
@Holger参考リンクを追加しました。 'PeriodicTask :: real_time_tick'で私が見つけたのは、タイマーに関するいくつかのアカウンティング情報を行うことです。最も目立つのは '_tasks [index] - > execute_if_pending(delay_time)'です。それは 'task()'の中でいくつかの実際の仕事をしているようです。とった!私はサンプルを実行している場合、最終的に 'StatSamplerTask :: task'を呼び出すと思います。 – skytree
実行可能な情報を取得するための第2のソースを本当に検討しましたか?私はまだ "作ることを作ることを作る"と "作ることを作る"の違いは何か、そして元のテキストがその壊れた翻訳の前にもっと意味を成すかどうかを疑問に思っています。 – Holger