What changes were made to the JVM's implementation of intrinsic locks in Java 6?
-
The book Java Concurrency in Practise indicates that the performance of instrinsic locks was improved dramatically in Java 6. What were those changes, how are they different from the implementation of ReentrantLock, and why could those optimizations not be implemented in Java 5?
-
Answer:
Well, while there were http://docs.oracle.com/javase/6/docs/technotes/guides/management/enhancements.html added in Java 6, the real change you're probably referring to biased locking, lock coarsening, and adaptive spinning improvements, detailed here: http://www.oracle.com/technetwork/java/6-performance-137236.html#2.1.1 ... Biased locking is where the JVM saves on the cost of context switches by guessing that the "first" thread to acquire a lock will want the lock next time. It's pretty expensive for other threads to grab the lock, rather than a simple context switch with unbiased locking, but in practice, the performance benefit was enough to make this the default behavior. It can be switched back to Java 5's behavior with a JVM command line option. Lock coarsening means lowering the frequency for opportunities for locks to change state. In practice, Java 5's frequency was fast enough where locks were released then reacquired with nothing done in between, and this was meant to help prevent that needless activity from occurring as often. Adaptive spinning is an improved locking implementation that allows context switches to be less expensive by changing its operation based on the current efficiency of the lock's operation. That's not a great explanation, but thankfully it suggests more detail on adaptive spinning here: http://home.comcast.net/~pjbishop/Dave/MustangSync.pdf Why was this not backported to Java 5? These are major changes and production systems could somehow depend on Java 5's locking implementations. While minor improvements are tolerable, this was quite an overhaul. It's possible locking patterns were optimized, for instance, to accommodate the coarser locks, or perhaps even took advantage of the faster switches. Bugs could arise or functionality could outright break if complex concurrent software is unnecessarily exposed to theoretical improvements. I'm assuming you meant backporting, rather than not just implementing the improvements in Java 5 when Java 5 was released. If you did mean the latter, well, they just didn't invent the better implementation yet. The ReentrantLock class uses the same lock implementation as the basic monitor/intrinsic lock, and just adds functionality to it. So however they're implemented in the JVM dictates how ReentrantLock will operate. See the first line in the description here: http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/locks/ReentrantLock.html
Scott Danzig at Quora Visit the source
Related Q & A:
- What is the best way to make UI for an Isometric game in Java?Best solution by Game Development
- What is glitter made of?Best solution by Yahoo! Answers
- How is a fork made and what is it made out of?Best solution by madehow.com
- What is steel made from?Best solution by Yahoo! Answers
- Difference between Java 2 and Java 6?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.