Transactional Memory for Smalltalk
-
Upload
lukas-renggli -
Category
Business
-
view
1.997 -
download
2
description
Transcript of Transactional Memory for Smalltalk
Transactional Memoryfor Smalltalk
Software Composition GroupUniversity of Bern
Lukas RenggliOscar Nierstrasz
Concurrent Programmingin Smalltalk
Semaphore forMutualExclusion
RecursionLock new
Mutex new
SharedQueue new
Problems
Deadlocks
Starvation
Priority Inversion
Complexity
SoftwareTransactional Memory
Programmingwith Transactions
Lock Based
tree := BTree new.
lock := Semaphore forMutualExclusion.
" writing "
lock critical: [ tree at: #a put: 1 ].
" reading "
lock critical: [ tree at: #a ].
Transactional
tree := BTree new.
" writing "
[ tree at: #a put: 1 ] atomic.
" reading "
tree at: #a.
Inside Transactions
Our Approach
Full implementation in Smalltalk
Lazy code transformation
Method annotations
Context dependent code execution
Static Model
selector
parseTree
CompiledMethod
selector*
methods
/selector
/parseTree
AtomicMethod
atomicMethod
1
method
1
name
superclass
subclasses
instanceVariables
Class
Code Transformation
Instance Variables
Variable Bindings
Message Sends
Original Source Code
BTree>>at: aKey put: anObject
| leaf |
leaf := root leafForKey: aKey.
leaf insertKey: aKey value: anObject.
root := leaf root.
^ anObject
Transformed Source Code
BTree>>__atomic__at: aKey put: anObject
| leaf |
leaf := (self atomicInstVarAt: 1)
__atomic__leafForKey: aKey.
leaf __atomic__insertKey: aKey value: anObject.
self atomicInstVarAt: 1 put: leaf __atomic__root.
^ anObject
Transformed Source Code
BTree>>__atomic__at: aKey put: anObject
| leaf |
leaf := (self atomicInstVarAt: 1)
__atomic__leafForKey: aKey.
leaf __atomic__insertKey: aKey value: anObject.
self atomicInstVarAt: 1 put: leaf __atomic__root.
^ anObject
Transformed Source Code
BTree>>__atomic__at: aKey put: anObject
| leaf |
leaf := (self atomicInstVarAt: 1)
__atomic__leafForKey: aKey.
leaf __atomic__insertKey: aKey value: anObject.
self atomicInstVarAt: 1 put: leaf __atomic__root.
^ anObject
Annotate methodsthat need special treatment
Infrastructural code
Exception handling
Execution contexts
Many primitives
Variable sized objects
Dynamic Model
applyhasChangedhasConflict
Change
object
*changes
Process0..1
currentTransaction
do: aBlockretry: aBlockcheckpointabort: anObject
escapeContext
Transaction
previousCopyworkingCopy
ObjectChange
applyBlockconflictTestBlock
CustomChange
*
Validation
Speed Comparison
Method Invocation
Special Method Invocation
Instance Variable Read
Instance Variable Write
Indexed Variable Read
Indexed Variable Write
5× 10×
15×
20×
25×
17×
18×
19×
20×
2×
1×
0.0
100.0
200.0
300.0
400.0
500.0
600.0
700.0
800.0
0 10 20 30 40 50 60 70 80 90 100
non-synchronized lock-based transactional
n
t [ms]
Performance of n concurrent edit operations in Pier
1 CPU
2 CPUs
4 CPUs
8 CPUs
Future Work
Implement within a multi-core environment
Improve speed
Applications
Concurrency Contol
Source Code Loading
Context Oriented Programming