5. Hotspotのlock関係のオプション
-XX:+UseBiasedLocking BiasedLockingを有効に。
-XX:-TraceMonitorInflation Inflation/deflation発生時にトレースを表示。
-XX:-TraceBiasedLocking BaisedLockingに変更にトレースを表示。
-XX:BiasedLockingStartupDelay=4000 VM起動後に時間をおいてからbiased locking
を有効化する。その待機時間をミリ秒で指定。
-XX:BiasedLockingBulkRebiasThreshold=20 Threshold of number of revocations per type to
try to rebias all objects in the heap of that type
-XX:BiasedLockingBulkRevokeThreshold=40 Threshold of number of revocations per type to
permanently revoke biases of all objects in the
heap of that type
-XX:BiasedLockingDecayTime=25000 Decay time (in milliseconds) to re-enable bulk
rebiasing of a type after previous bulk rebias
-XX:-PrintBiasedLockingStatistics Print statistics of biased locking in JVM
5
21. Synchronized getterはCASを使わない
class Hoge { class Hoge {
<<counter>>
int _hoge; int _hoge;
public synchronized int getHoge() { public synchronized int getHoge() {
return _hoge; old = counter;
} ret = _hoge;
if (old == counter)
return ret;
// 再実行
}
public synchronized void setHoge(int hoge) { public synchronized void setHoge(int hoge) {
_hoge = hoge; fetchadd counter +1
} _hoge = hoge;
}
} }
21
22. 参考文献
• David Dice, “Implementing fast Java monitors
with relaxed locks”, In proceedings of the Java
Virtual Machine, Research and Technology
Symposium(JVM’01), April 2001, pp.79-90.
• Kenneth Russell and David Detlefs, “Eliminating
Synchronization-Related Atomic Operations with
Biased Locking and Bulk Rebiasing”, OOPSLA’06,
pp.
• Takuya Nakaike and Maged M. Michael, “Lock
Elision for Read-Only Critical Section in Java”,
PLDI’10
22