Transcript
Page 1: Transactional Memory for Smalltalk

Transactional Memoryfor Smalltalk

Software Composition GroupUniversity of Bern

Lukas RenggliOscar Nierstrasz

Page 2: Transactional Memory for Smalltalk

Concurrent Programmingin Smalltalk

Semaphore forMutualExclusion

RecursionLock new

Mutex new

SharedQueue new

Page 3: Transactional Memory for Smalltalk

Problems

Deadlocks

Starvation

Priority Inversion

Complexity

Page 4: Transactional Memory for Smalltalk

SoftwareTransactional Memory

Page 5: Transactional Memory for Smalltalk

Programmingwith Transactions

Page 6: Transactional Memory for Smalltalk

Lock Based

tree := BTree new.

lock := Semaphore forMutualExclusion.

" writing "

lock critical: [ tree at: #a put: 1 ].

" reading "

lock critical: [ tree at: #a ].

Page 7: Transactional Memory for Smalltalk

Transactional

tree := BTree new.

" writing "

[ tree at: #a put: 1 ] atomic.

" reading "

tree at: #a.

Page 8: Transactional Memory for Smalltalk

Inside Transactions

Page 9: Transactional Memory for Smalltalk

Our Approach

Full implementation in Smalltalk

Lazy code transformation

Method annotations

Context dependent code execution

Page 10: Transactional Memory for Smalltalk

Static Model

Page 11: Transactional Memory for Smalltalk

selector

parseTree

CompiledMethod

selector*

methods

/selector

/parseTree

AtomicMethod

atomicMethod

1

method

1

name

superclass

subclasses

instanceVariables

Class

Page 12: Transactional Memory for Smalltalk

Code Transformation

Instance Variables

Variable Bindings

Message Sends

Page 13: Transactional Memory for Smalltalk

Original Source Code

BTree>>at: aKey put: anObject

| leaf |

leaf := root leafForKey: aKey.

leaf insertKey: aKey value: anObject.

root := leaf root.

^ anObject

Page 14: Transactional Memory for Smalltalk

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

Page 15: Transactional Memory for Smalltalk

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

Page 16: Transactional Memory for Smalltalk

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

Page 17: Transactional Memory for Smalltalk

Annotate methodsthat need special treatment

Infrastructural code

Exception handling

Execution contexts

Many primitives

Variable sized objects

Page 18: Transactional Memory for Smalltalk

Dynamic Model

Page 19: Transactional Memory for Smalltalk

applyhasChangedhasConflict

Change

object

*changes

Process0..1

currentTransaction

do: aBlockretry: aBlockcheckpointabort: anObject

escapeContext

Transaction

previousCopyworkingCopy

ObjectChange

applyBlockconflictTestBlock

CustomChange

*

Page 20: Transactional Memory for Smalltalk

Validation

Page 21: Transactional Memory for Smalltalk

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×

Page 22: Transactional Memory for Smalltalk

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

Page 23: Transactional Memory for Smalltalk

Future Work

Page 24: Transactional Memory for Smalltalk

Implement within a multi-core environment

Page 25: Transactional Memory for Smalltalk

Improve speed

Page 26: Transactional Memory for Smalltalk

Applications

Concurrency Contol

Source Code Loading

Context Oriented Programming


Top Related