Title: Deuce STM Painless Java concurrency
1Deuce STM Painless Java concurrency
- Guy Korland
- TAU GigaSpaces
2Outline
- Motivation
- Deuce
- Implementation
- TL2
- LSA
- Benchmarks
- Summary
- References
3Motivation
4Moores Law
Transistor count still rising
Clock speed flattening sharply
(hat tip Simon Peyton-Jones)
5The Problem
- Cannot exploit cheap threads
- Todays Software
- Non-scalable methodologies
- Todays Hardware
- Poor support for scalable synchronization
6Why Locking Doesnt Scale?
- Not Robust
- Relies on conventions
- Hard to Use
- Conservative
- Deadlocks
- Lost wake-ups
- Not Composable
7The Brief History of STM
8TM Overview
- synchronized
- ltsequence of instructionsgt
-
- atomic
- ltsequence of instructionsgt
-
9What is a transaction?
- Atomicity all or nothing
- Consistency consistent state (after before)
- Isolation Other cant see intermediate.
- Durability - persistent
10Outline
- Motivation
- Deuce
- Implementation
- TL2
- LSA
- Benchmarks
- Summary
- References
11Deuce
- Java STM framework
- _at_Atomic methods
- Field based access
- More scalable than Object bases.
- More efficient than word based.
- Support external libraries
- Can be part of a transaction
- No reserved words
- No need for new compilers (Existing IDEs can be
used) - Research tool
- API for developing and testing new algorithms.
12Deuce - API
- public class Bank
- final private static double MAXIMUM_TRANSACTION
1000 - private double commission 0
- _at_Atomic(retries64)
- public void transaction( Account ac1, Account
ac2, double amount) - if( amount lt 0 amount gt MAXIMUM_TRANSACTION
) - throw new IllegalArgumentException(Illega
l transaction) - ac1.balance - (amount commission)
- ac2.balance amount
-
- _at_Atomic
- public void update( double value)
- commission value
-
13Deuce - Overview
14Deuce - Running
- javaagentdeuceAgent.jar
- Dynamic bytecode manipulation.
- -Xbootclasspath/prt.jar
- Offline instrumentation to support boot
classloader. - -Dorg.deuce.excludeorg.junit.,org.eclipse.
- Exclude class from being instrumented.
- _at_Exclude
- java javaagentdeuceAgent.jar cp
ex.jarmyjar.jar MyMain
15Outline
- Motivation
- Deuce
- Implementation
- TL2
- LSA
- Benchmarks
- Summary
- References
16Implementation
- ASM Bytecode manipulation
- Online Offline
- Fields
- private double commission
- final static public long commission__ADDRESS...
- Relative address (-1 if final).
- final static public Object __CLASS_BASE__ ...
- Mark the class base for static fields access.
17Implementation
- Method
- _at_Atomic methods.
- Replace the with a transaction retry loop.
- Add another instrumented method.
- Non-Atomic methods
- Duplicate each with an instrumented version.
18Implementation
_at_Atomic public void update ( double value)
commission value
_at_Atomic public void update ( double value)
double tmp commission commission tmp
value
19Implementation
public void update( double value, Context c)
double tmp if( commission__ADDRESS lt 0 ) //
final field tmp commission else
c.beforeRead( this, commission__ADDRESS)
tmp c.onRead( this, commission,
commission__ADDRESS) if(
commission__ADDRESS lt 0 ) // final field
commission tmp value else
c.onWrite( this, tmp value, commission__ADDRESS)
20Implementation
public void update( double value) Context
context ContextDelegetor.getContext() for(
int i retries i gt 0 --i)
context.init() try update(
value, context) if(
context.commit()) return
catch ( TransactionException e )
context.rollback() continue
catch ( Throwable t ) if(
context.commit()) throw t
throw new TransactionException()
21Implementation
public interface Context void init ( int
atomicBlockId) boolean commit() void
rollback () void beforeReadAccess( Object
obj , long field ) Object onReadAccess(
Object obj, Object value , long field ) int
onReadAccess( Object obj, int value , long field
) long onReadAccess( Object obj, long value ,
long field ) void onWriteAccess( Object
obj , Object value , long field ) void
onWriteAccess( Object obj , int value , long
field ) void onWriteAccess( Object obj , long
value , long field )
22Outline
- Motivation
- Deuce
- Implementation
- TL2
- LSA
- Benchmarks
- Summary
- References
23TL2 (Transaction Locking II)Dave Dice, Ori
Shalev and Nir Shavit DISC 2006
- CTL - Commit-time locking
- Start
- Sample global version-clock
- Run through a speculative execution
- Collect write-set read-set
- End
- Lock the write-set
- Increment global version-clock
- Validate the read-set
- Commit and release the locks
24Outline
- Motivation
- Deuce
- Implementation
- TL2
- LSA
- Benchmarks
- Summary
- References
25LSA (Lazy Snapshot Algorithm)Torvald Riegel,
Pascal Felber and Christof Fetzer DISC 2006
- ETL - Encounter-time locking
- Start
- Sample global version-clock
- Run through a speculative execution
- Lock on write access
- Collect read-set write-set
- End
- Increment global version-clock
- Validate the read-set
- Commit and release the locks
26Outline
- Motivation
- Deuce
- Implementation
- TL2
- LSA
- Benchmarks
- Summary
- References
27Benchmarks (Azul Vega2 2 x 46)
28Benchmarks (SuperMicro 2 x Quad Intel)
29Benchmarks (Sun UltraSPARC T2 Plus 2 x Quad
x 8HT)
30Outline
- Motivation
- Deuce
- Implementation
- TL2
- LSA
- Benchmarks
- Summary
- References
31Summary
- Simple API
- _at_Atomic
- No change to Java
- No reserved word
- OpenSource
- On Google code
- Shows nice scalabilty
- Field based
32Outline
- Motivation
- Deuce
- Implementation
- TL2
- LSA
- Benchmarks
- Summary
- References
33References
- Homepage - http//sites.google.com/site/deucestm/
- Project - http//code.google.com/p/deuce/
- Wikipedia -http//en.wikipedia.org/wiki/Software_t
ransactional_memory - TL2 http//research.sun.com/scalable/
- LSA-STM - http//tmware.org/lsastm
34Appendix
- Can you just replace synchronized blocks with
_at_Atomic blocks? - Privatization
- wait() (Message passing)