250 likes | 370 Views
Crafting a Ready-to-Go STM. Guy Korland Tel Aviv University. DSTM2 Maurice Herlihy et al, A flexible framework … [OOPSLA06]. Limited to Objects. V ery intrusive. Doesn’t support libraries. Bad performance (fork). . @atomic public interface INode { int getValue ();
E N D
Craftinga Ready-to-Go STM Guy Korland Tel Aviv University
DSTM2Maurice Herlihy et al, A flexible framework … [OOPSLA06] • Limited to Objects. • Very intrusive. • Doesn’t support libraries. • Badperformance (fork). @atomicpublic interface INode{ intgetValue (); void setValue (int value ); } Factory<INode> factory = Thread.makeFactory(INode.class); final INode node = factory.create(); factory result = Thread.doIt(new Callable<Boolean>() { public Boolean call () { return node.setValue(value); } });
JVSTMJoãoCachopo and AntónioRito-Silva, Versioned boxes as the basis for memory transactions [SCOOL05] • Doesn’t support libraries. • Less intrusive. • Need to “Announce” shared fields public class Account{ private VBox<Long> balance = new VBox<Long>(); public @Atomic void withdraw(long amount) { balance.put (balance.get() - amount); } }
public static class Node<E> { private Ref<E> value; final Node parent; Node(E value, Node prev) {this.value = value;this.parent = prev; } } MultiversePeter Veentjer, since 2009 • Doesn’t support libraries. • Need to “Announce” shared things. • But, used commercially (AKKA). @TransactionalObject public class Stack<E>{ private Node<E> head; @TransactionalMethod public void push(E item) { head = new Node(item, head); } }
Atom-JavaB. Hindman and D. Grossman. Atomicity via source-tosourcetranslation. [MSPC06] • Add a reserved word. • Need pre-compilation. • Doesn’t support libraries. • Even Lessintrusive. public void update ( double value) { Atomic { commission += value; } }
Guy Korland, Nir Shavit and Pascal Felber, “Noninvasive Java Concurrency with Deuce STM”,[MultiProg '10] Deuce STM Annotation based--> @Atomicmethods Field basedaccess More scalable than Object bases. More efficient than word based. No reserved words No need for new compilers (Existing IDEs can be used)
Deuce STM Supports external libraries Can be part of a transaction Research tool API for developing and testing new algorithms. Real life feedback.
Deuce STM - API public class Bank{ private double commission = 10; @Atomic(retries=64) public void transaction( Account ac1, Account ac2, double amount){ ac1.balance -= (amount + commission); ac2.balance += amount; } @Atomic public void update( double value){ commission += value; } }
public interface Context{ • void init ( intatomicBlockId) • boolean commit(); • void rollback (); • void beforeReadAccess( Object obj , long field ); • Object onReadAccess( Object obj, Object value , long field ); • intonReadAccess( 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 ); • … • } Research tool(Context- interface)
Overhead Contention – Retries, Aborts, Contention Manager … STM Algorithm– Data structures, optimistic, pessimistic… Semantic– Consistency model, Privatization… Instrumented Memory access– Linear overhead on every read/write
Static analysis OPTIMIZATIONS • Avoiding instrumentation of accesses to immutableand transaction-local memory. • Avoiding lock acquisition and releases for thread-localmemory. • Avoiding readset population in read-onlytransactions.
NEWStatic analysis OPTIMIZATIONS Yehuda Afek, Guy Korland, and ArieZilberstein, “Lowering STM Overhead with Static Analysis”, LCPC'10 • Reduce amount of instrumented memory reads using load elimination. • Reduce amount of instrumented memory writes using scalar promotion. • Avoid writeset lookups for memory not yet written to. • Avoid writesetrecord keeping for memory that will not be read. • Reduce false conflicts byTransaction re-scoping. • …
1. LOAD ELIMINATION IN ATOMIC BLOCKS • for (int j = 0; j < nfeatures; j++) { newCenters[index][j] = newCenters[index][j] + feature[i][j]; } • if (0 < nfeatures) { nci = new_centers[index]; fi = feature[i]; for (j = 0; j < nfeatures; j++) nci[j] = nci[j] + fi[j]; } 5 instrumented memory reads per loop iteration 2 instrumented memory reads per loop iteration
STM Friendly Libraries • Most of the developers/application only use Data Structures. @Atomic(retries=64) public void transaction( Map map1, Map map2, String key){ map2.put(key, map1.remove(key)); } • We should build a set of “STM Friendly” libraries. Maurice Herlihy, Eric Koskinen: Transactional boosting: a methodology for highly-concurrent transactional objects. PPOPP’08