Your SlideShare is downloading. ×
0
Transactional Memory
    for Smalltalk

   Software Composition Group
        University of Bern

         Lukas Renggli
 ...
Concurrent Programming
      in Smalltalk
   Semaphore forMutualExclusion



        RecursionLock new



            Mute...
Problems


   Deadlocks
   Starvation
Priority Inversion


   Complexity
Software
Transactional Memory
Programming
with Transactions
Lock Based

tree := BTree new.

lock := Semaphore forMutualExclusion.



quot; writing quot;

lock critical: [ tree at: #a...
Transactional

tree := BTree new.




quot; writing quot;

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



quot; reading quot;

tree at:...
Inside Transactions
Our Approach


 Full implementation in Smalltalk


    Lazy code transformation
      Method annotations
Context dependent...
Static Model
Class
name                                   CompiledMethod
superclass                           * selector         1
    ...
Code Transformation



     Instance Variables
     Variable Bindings


      Message Sends
Original Source Code


BTree>>at: aKey put: anObject

    | leaf |

    leaf := root leafForKey: aKey.

    leaf insertKey...
Transformed Source Code

BTree>>__atomic__at: aKey put: anObject

    | leaf |

    leaf := (self atomicInstVarAt: 1)

   ...
Transformed Source Code

BTree>>__atomic__at: aKey put: anObject

   | leaf |

   leaf := (self atomicInstVarAt: 1)

     ...
Transformed Source Code

BTree>>__atomic__at: aKey put: anObject

    | leaf |

    leaf := (self atomicInstVarAt: 1)

   ...
Annotate methods
that need special treatment

        Infrastructural code
         Exception handling
         Execution ...
Dynamic Model
Transaction
                                                                       Change
                               e...
Validation
Speed Comparison

       Method Invocation     1×



Special Method Invocation         2×



   Instance Variable Read    ...
Performance of n concurrent
   t [ms]
800.0
               edit operations in Pier
700.0                                  ...
Future Work
Implement within a
multi-core environment
Improve speed
Applications



     Concurrency Contol
    Source Code Loading
Context Oriented Programming
Upcoming SlideShare
Loading in...5
×

Transactional Memory for Smalltalk

2,069

Published on

Concurrency control is mostly based on locks and is therefore notoriously difficult to use. Even though some programming languages provide high-level constructs, these add complexity and potentially hard-to-detect bugs to the application. Transactional memory is an attractive mechanism that does not have the drawbacks of locks, however the underlying implementation is often difficult to integrate into an existing language. In this paper we show how we have introduced transactional semantics into Smalltalk by using the reflective facilities of the language. Our approach is based on method annotations, incremental parse tree transformations and an optimistic commit protocol. The implementation does not depend on modifications to the virtual machine and therefor can be changed at the language level. We report on a practical case study, benchmarks and further and on-going work.

Published in: Business, Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,069
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
36
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Transactional Memory for Smalltalk"

  1. 1. Transactional Memory for Smalltalk Software Composition Group University of Bern Lukas Renggli Oscar Nierstrasz
  2. 2. Concurrent Programming in Smalltalk Semaphore forMutualExclusion RecursionLock new Mutex new SharedQueue new
  3. 3. Problems Deadlocks Starvation Priority Inversion Complexity
  4. 4. Software Transactional Memory
  5. 5. Programming with Transactions
  6. 6. Lock Based tree := BTree new. lock := Semaphore forMutualExclusion. quot; writing quot; lock critical: [ tree at: #a put: 1 ]. quot; reading quot; lock critical: [ tree at: #a ].
  7. 7. Transactional tree := BTree new. quot; writing quot; [ tree at: #a put: 1 ] atomic. quot; reading quot; tree at: #a.
  8. 8. Inside Transactions
  9. 9. Our Approach Full implementation in Smalltalk Lazy code transformation Method annotations Context dependent code execution
  10. 10. Static Model
  11. 11. Class name CompiledMethod superclass * selector 1 selector subclasses methods parseTree method instanceVariables AtomicMethod /selector 1 /parseTree atomicMethod
  12. 12. Code Transformation Instance Variables Variable Bindings Message Sends
  13. 13. Original Source Code BTree>>at: aKey put: anObject | leaf | leaf := root leafForKey: aKey. leaf insertKey: aKey value: anObject. root := leaf root. ^ anObject
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. Annotate methods that need special treatment Infrastructural code Exception handling Execution contexts Many primitives Variable sized objects
  18. 18. Dynamic Model
  19. 19. Transaction Change escapeContext 0..1 do: aBlock * Process apply currentTransaction retry: aBlock changes hasChanged checkpoint object hasConflict abort: anObject * ObjectChange CustomChange previousCopy applyBlock workingCopy conflictTestBlock
  20. 20. Validation
  21. 21. Speed Comparison Method Invocation 1× Special Method Invocation 2× Instance Variable Read 20× Instance Variable Write 19× Indexed Variable Read 18× Indexed Variable Write 17× 5× 10× 15× 20× 25×
  22. 22. Performance of n concurrent t [ms] 800.0 edit operations in Pier 700.0 1 CPU 600.0 500.0 400.0 2 CPUs 300.0 200.0 4 CPUs 100.0 8 CPUs 0.0 n 0 10 20 30 40 50 60 70 80 90 100 non-synchronized lock-based transactional
  23. 23. Future Work
  24. 24. Implement within a multi-core environment
  25. 25. Improve speed
  26. 26. Applications Concurrency Contol Source Code Loading Context Oriented Programming
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×