Title: Lock Reservation: Java Locks Can Mostly Do Without Atomic Operations Kawachiya, Koseki,
1Lock Reservation Java Locks Can Mostly Do
Without Atomic OperationsKawachiya, Koseki,
OnoderaIBM Research, Tokyo Research Lab,
JapanOOPSLA 2002
- Jon Steelman
- cs8803g
- 26 November 2002
2What is paper seeking to accomplish?
- Increase in threaded performance
- Why important?
- Built-in support for multi-threaded programming
- Java programs perform many lock operations
- Atomic operations are very expensive
3What is being exploited?
- Thread locality
- How is thread locality being exploited?
- Novel algorithm called lock reservation
4Thread Locality- What is it?
- Sequence of threads in temporal order that
acquire the lock. - Dominant locker long repetition of a specific
thread
5Exploitable Thread Locality of Java Locks
Even for multi-threaded programs, more than 75
of lock operations were performed by the initial
lockers in first repetition.
6Lock Reservation
- Exploits Thread Locality and reserves locks for
threads - Algorithm that can built on any existing locking
algorithm that uses a lockword and allows use of
one bit in the lockword, q.v. the fast Tasuki
lock used in IBMs jdk 1.3.1 - Bit used for to represent lock reservation status
and named LRV
7Lock Reservation
- If objects lock reserved for thread, thread
acquires lock with a few instructions and no
atomic operations. - If lock reserved for another thread, reservation
cancelled and falls back to conventional locking
algorithm - If objects lock not reserved, system uses the
conventional locking algorithm - When LRV is set, lockword in reserve mode and
lockword structure defined by the lock
reservation algorithm. Otherwise, lockword is in
base mode.
8Lockword Structure
LRV bit
Thread ID
Recursion Cnt
1
(defined by base locking algorithm)
0
Lockword semantics in reserve mode
A
0
1
Reserved for Thread A, but not held
A
gt0
1
Reserved for and held by Thread A
0
0
1
Reserved anonymously
9Lock State Transitions
10Notes on State
- Owner thread can read-modify-write the lockword
without atomic operations - Once reservation is cancelled, lockword will
never be reserved again - Cancellation is most expensive operation but
ratio to lock operations is less than 0.05 in
actual lock-intensive programs
11Performance Improvements
12Lock Statistics
13Observations
- Significantly improves performance if reservation
succeeds while maintaining comparable performance
if reservation fails - Since lock reservation is a runtime technique, it
is complementary to compiler optimizations like
escape analysis and recursive lock elimination
14Future Extensions
- Lowering cost of cancellations
- Avoiding cancellations, for example, by starting
in base mode and avoiding reserve mode - Dynamic profiling
- Static analysis
- When cancellation cost lowered, pursuing an
algorithm enhancement allowing repeated lock
reservations on an object