MonitorEnter,MonitorExit,JNI によるロック処理は, 基本的には monitorenter/monitorexit と類似した処理になる (See: here for details).
ただし, JNI によるロック処理では biased locking や stack-locked 等といった最適化は行われず, 常に ObjectMonitor が用いられる (このため, 当然ながらロック状態は inflated になる. biased 状態だった場合は revoke 処理なども行われる).
また, JNI によるロック/アンロックでは BasicObjectLock がまったく使用されない (このため JNI でロックしたものは monitorexit では解放できない. まぁそもそも現在の HotSpot では他メソッドで取得したロックは monitorexit では解放できないけど...)
なお, JNI で確保したロックについては DetachCurrentThread() 時にも解放処理が行われる (これは JNI 仕様に沿った挙動. そのスレッドが保持している全てのモニターが解放される).
jni_MonitorEnter()
-> ObjectSynchronizer::jni_enter()
-> BiasedLocking::revoke_and_rebias()
-> (See: here for details)
-> ObjectSynchronizer::inflate()
-> (See: here for details)
-> ObjectMonitor::enter()
-> (See: here for details)
jni_MonitorExit()
-> ObjectSynchronizer::jni_exit()
-> BiasedLocking::revoke_and_rebias()
-> (See: here for details)
-> ObjectSynchronizer::inflate()
-> (See: here for details)
-> ObjectMonitor::check()
-> ObjectMonitor::exit()
-> (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
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.