...
A similar mechanism, called bulk rebiasing, optimizes situations in which objects of a class are locked and unlocked by different threads but never concurrently. It invalidates the bias of all instances of a class without disabling biased locking. An epoch value in the class acts as a timestamp that indicates the validity of the bias. This value is copied into the header word upon object allocation. Bulk rebiasing can then efficiently be implemented as an increment of the epoch in the appropriate class. The next time an instance of this class is going to be locked, the code detects a different value in the header word and rebiases the object towards the current thread.
Source Code Hints
Synchronization affects multiple parts of the JVM: The structure of the object header is defined in the classes oopDesc
and markOopDesc
, the code for thin locks is integrated in the interpreter and compilers, and the class ObjectMonitor
represents inflated locks. Biased locking is centralized in the class BiasedLocking
. It can be enabled via the flag -XX:+UseBiasedLocking
and disabled via -XX:-UseBiasedLocking
. It is enabled by default for Java 6 and Java 7, but activated only some seconds after the application startup. Therefore, beware of short-running micro-benchmarks. If necessary, turn off the delay using the flag -XX:BiasedLockingStartupDelay=0
.
References
Wiki Markup |
---|
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="ec640d69d6531c70-94410ff5-4d19463b-91849f4e-16c2c03f50e72ce25127b4c0"><ac:parameter ac:name="">Agesen99</ac:parameter></ac:structured-macro>\[Agesen99\] O. Agesen, D. Detlefs, A. Garthwaite, R. Knippel, Y. S. Ramakrishna, D. White: _An Efficient Meta-lock for Implementing Ubiquitous Synchronization_. In _Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications_, pages 207-222. ACM Press, 1999. [doi:10.1145/320384.320402|http://dx.doi.org/10.1145/320384.320402] |
Wiki Markup |
---|
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="e42db051d520f7db-f3799dce-4a8e48ba-a08d8cac-585843972793fcdcdf1e72c8"><ac:parameter ac:name="">Bacon98</ac:parameter></ac:structured-macro>\[Bacon98\] D. F. Bacon, R. Konuru, C. Murthy, M. Serrano: _Thin Locks: Featherweight Synchronization for Java_. In _Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation_, pages 258-268. ACM Press, 1998. [doi:10.1145/277650.277734|http://dx.doi.org/10.1145/277650.277734] |
Wiki Markup |
---|
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="d4e1f7c6e672e1fe-8d12e052-438c4022-8d8da80e-fbdc49b1c3e1d409fbf23c83"><ac:parameter ac:name="">Kawachiya02</ac:parameter></ac:structured-macro>\[Kawachiya02\] K. Kawachiya, A. Koseki, T. Onodera: Lock Reservation: Java Locks can Mostly do without Atomic Operations. In _Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications_, pages 130-141. ACM Press, 2002. [doi:10.1145/582419.582433|http://dx.doi.org/10.1145/582419.582433] |
Wiki Markup |
---|
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="9608397c6e47f29d-51741537-415540b1-aa1aad2c-312be8a983776bc9ff2d6c94"><ac:parameter ac:name="">Russell06</ac:parameter></ac:structured-macro>\[Russel06\] K. Russell, D. Detlefs: Eliminating Synchronization-Related Atomic Operations with Biased Locking and Bulk Rebiasing. In _Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications_, pages 263-272. ACM Press, 2006. [doi:10.1145/1167473.1167496|http://dx.doi.org/10.1145/1167473.1167496] |