hotspot/src/share/vm/runtime/synchronizer.cpp
// Release all inflated monitors owned by THREAD. Lightweight monitors are
// ignored. This is meant to be called during JNI thread detach which assumes
// all remaining monitors are heavyweight. All exceptions are swallowed.
// Scanning the extant monitor list can be time consuming.
// A simple optimization is to add a per-thread flag that indicates a thread
// called jni_monitorenter() during its lifetime.
//
// Instead of No_Savepoint_Verifier it might be cheaper to
// use an idiom of the form:
// auto int tmp = SafepointSynchronize::_safepoint_counter ;
// <code that must not run at safepoint>
// guarantee (((tmp ^ _safepoint_counter) | (tmp & 1)) == 0) ;
// Since the tests are extremely cheap we could leave them enabled
// for normal product builds.
void ObjectSynchronizer::release_monitors_owned_by_thread(TRAPS) {
{- -------------------------------------------
(1) (assert)
---------------------------------------- -}
assert(THREAD == JavaThread::current(), "must be current Java thread");
{- -------------------------------------------
(1) (デバッグ用の処理) (See: No_Safepoint_Verifier)
---------------------------------------- -}
No_Safepoint_Verifier nsv ;
{- -------------------------------------------
(1) (変数宣言など)
---------------------------------------- -}
ReleaseJavaMonitorsClosure rjmc(THREAD);
{- -------------------------------------------
(1) ObjectSynchronizer::monitors_iterate() を呼んで,
重量ロック状態になっている全てのオブジェクトに対して ReleaseJavaMonitorsClosure を適用していく.
(なお, この処理は ListLock で排他した状態で行う)
---------------------------------------- -}
Thread::muxAcquire(&ListLock, "release_monitors_owned_by_thread");
ObjectSynchronizer::monitors_iterate(&rjmc);
Thread::muxRelease(&ListLock);
{- -------------------------------------------
(1) pending_exception があれば消しておく.
---------------------------------------- -}
THREAD->clear_pending_exception();
}
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.