hotspot/src/share/vm/runtime/thread.cpp
// Last thread running calls java.lang.Shutdown.shutdown()
void JavaThread::invoke_shutdown_hooks() {
{- -------------------------------------------
(1) (変数宣言など)
---------------------------------------- -}
HandleMark hm(this);
{- -------------------------------------------
(1)
---------------------------------------- -}
// We could get here with a pending exception, if so clear it now.
if (this->has_pending_exception()) {
this->clear_pending_exception();
}
{- -------------------------------------------
(1) (assert) (See: ExceptionMark)
---------------------------------------- -}
EXCEPTION_MARK;
{- -------------------------------------------
(1) JavaCalls::call_static() 経由で
java.lang.Shutdown.shutdown() を呼び出し,
finalizer を実行させる.
(ただし, SystemDictionary::resolve_or_null() 中で例外が発生した場合は
java.lang.Shutdown が取得できないので, 何もしない)
(とはいえ, shutdown hook の登録や runFinalizersOnExit() の呼び出しが行われた場合には,
その時点で java.lang.Shutdown はロードされるので, ここでの失敗はない??)
---------------------------------------- -}
klassOop k =
SystemDictionary::resolve_or_null(vmSymbols::java_lang_Shutdown(),
THREAD);
if (k != NULL) {
// SystemDictionary::resolve_or_null will return null if there was
// an exception. If we cannot load the Shutdown class, just don't
// call Shutdown.shutdown() at all. This will mean the shutdown hooks
// and finalizers (if runFinalizersOnExit is set) won't be run.
// Note that if a shutdown hook was registered or runFinalizersOnExit
// was called, the Shutdown class would have already been loaded
// (Runtime.addShutdownHook and runFinalizersOnExit will load it).
instanceKlassHandle shutdown_klass (THREAD, k);
JavaValue result(T_VOID);
JavaCalls::call_static(&result,
shutdown_klass,
vmSymbols::shutdown_method_name(),
vmSymbols::void_method_signature(),
THREAD);
}
{- -------------------------------------------
(1)
---------------------------------------- -}
CLEAR_PENDING_EXCEPTION;
}
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.