Java Lock Implementations | Javalobby
Mechanical Sympathy: Java Lock Implementations
I would like to quote something from the post here:
JDK locks come with two implementations. One uses atomic CAS style instructions to manage the claim process. CAS instructions tend to be the most expensive type of CPU instructions and on x86 have memory ordering semantics. Often locks are un-contended which gives rise to a possible optimisation whereby a lock can be biased to the un-contended thread using techniques to avoid the use of atomic instructions. This biasing allows a lock in theory to be quickly reacquired by the same thread. If the lock turns out to be contended by multiple threads the algorithm with revert from being biased and fall back to the standard approach using atomic instructions. Biased locking became the default lock implementation with Java 6.
I found that my un-contended thread was incurring a bit more cost than I expected from the lock.
I think some time later, I need to do this test by myself and get back to this post.
Mechanical Sympathy: Java Lock Implementations
I would like to quote something from the post here:
JDK locks come with two implementations. One uses atomic CAS style instructions to manage the claim process. CAS instructions tend to be the most expensive type of CPU instructions and on x86 have memory ordering semantics. Often locks are un-contended which gives rise to a possible optimisation whereby a lock can be biased to the un-contended thread using techniques to avoid the use of atomic instructions. This biasing allows a lock in theory to be quickly reacquired by the same thread. If the lock turns out to be contended by multiple threads the algorithm with revert from being biased and fall back to the standard approach using atomic instructions. Biased locking became the default lock implementation with Java 6.
I found that my un-contended thread was incurring a bit more cost than I expected from the lock.
I think some time later, I need to do this test by myself and get back to this post.
No comments:
Post a Comment