180 likes | 206 Vues
Explore reconciliations as a new approach in OOP, covering concurrency, shared memory models, reconciled fields, reconcilable classes, and Java language extensions. Understand how Java supports multithreading and synchronization for efficient data sharing.
E N D
Object-Oriented Implementation of Reconciliations M.Sc. Seminar Talkby Costa Shapiro under supervision of Prof. Shmuel Katz Computer Science –Technion
Introduction • Concurrency implies information exchange • Convenient communication via data sharing • Various data sharing models and issues • Reconciliations as a new approach • Variables have “local” versions for each process • An operation on those versions to compute a “global” agreed version and distribute it • Means of control over participation of a particular version in such operations Reconciliations in OOP
Outline • Background • Java Concurrency Support • Shared Memory Models • Concept And Programming Technique • Reconciled Fields • Reconcilable Classes • Language Extension And Usage • Patterns And Samples • Implementation Notes Reconciliations in OOP
Java Concurrency Support • Java’s integrated multithreading support • Threads share the machine’s main memory • Built-in concurrent data access management and thread synchronization using monitors • Mutual exclusion language constructs • Suspension-notification mechanism • Flexible shared memory consistency model with a set of rules for synchronization Reconciliations in OOP
Shared Memory Models • Linearizability & sequential consistency • Relaxed sequential consistency • Weaker rules for greater efficiency • Hybrid memory consistency models • Additional (synchronization) operations • Java’s shared memory model • “Regular” variables (weaker rules) • “Volatile” variables (stricter rules) • Implicit synchronization operations Reconciliations in OOP
Reconciled Fields • Either a new kind of instance variables • Occasionally assigned an agreed “class-wide” value calculated separately • Can be guarded against such changes • Or a new kind of class variables • Having temporarily different “working” copies • Can be forced to get updated • Declared specially (in the extended language) • Can be seen as an additional (customizable) memory model for Java Reconciliations in OOP
FieldInstance HiddenMechanism a1 class A x a2 reconciled x Reconciler A::x x a3 ReconciledField x x ClassInstance TemporarilyDetached Reconciled Fields (cont.) Reconciliations in OOP
Reconcilable Classes • Reconcilability is a new addition to the possible class capabilities • Only reconcilable classes can be used to declare reconciled fields • Semantics of being reconcilable is identified by implementation of a special interface • Reconciliation mechanism has a default implementation that should be overridden • Means of iteration over the working copies • A “lightweight” precondition procedure Reconciliations in OOP
class A a1 class X(reconcilable) ReconciliationOverride x x1 reconciliation reconciled X x a2 x x2 A::x Reconciler a3 x reconciliation x3 x FieldValue Reconcilable Classes (cont.) Reconciliations in OOP
Java Language Extension • Reconciled fields: syntax • Variable declaration (a new reconciled modifier) • Variable “anti-reconciliation” guard options (a new localized statement and a method modifier) • Reconciled fields: semantics • Initialization (of “master and working copies”) • Reference, modification and assignment • “Localization” and “globalization” procedures • Reconciliations are as-if-atomic and independent Reconciliations in OOP
Java Platform Changes • A new javax.reconciliation package • An Object class – replaces the java.lang.Object class and contains reconciliation-related methods • A Reconcilable interface – serves to identify the semantics of being reconcilable if implemented • A NotReconciledException class – thrown if a non-reconciled variable encountered • Some hidden (system) classes • An optional javax.reconciliation.util package contains utility framework Reconciliations in OOP
Application Patterns • Customizable high-level caching • An arbitrary memory model can be realized • Distributed computation result reconciling • Independent computational agents are “improving” some global result • Weak and strong updates • Defer updates while performing work “locally” • Authorized commitment • Changes to some global data entity are reviewed by some authority prior to commitment Reconciliations in OOP
Sample • Theglobalizemethod suspends the caller until a reconciliation of the field occurs • The reconcilemethod calculates the reconciled value (and updates this object) public class NetNode { public Date currentTime() { clock.globalize(); return clock.getTime(); } private reconciledLocalClockclk = new LocalClock(); } Reconciliations in OOP
Sample (cont.) public class LocalClock implements Reconcilable { public localized void tick(long ticks) { localTime += ticks; } protected boolean reconcile(Collectionc) { Iteratori = c.iterator(); while (i.hasNext()) { LocalClocklc = (LocalClock)i.next(); if (lc.localTime > localTime) localTime = lc.localTime; } return true; } } Reconciliations in OOP
Implementation Architecture Reconciliation-Enabled Java Source Code Preprocess Stage I Decorated Java Source Code Compilation Stage I Intermediate Java Class Binary Preprocess Stage II Standardized Java Source Code Compilation Stage II Java Class Binary Auxiliary Java Binary JVM Runtime Extended Platform Binary Reconciliations in OOP
System Framework • The straightforward academic implementation is based on two new platform classes • javax.reconciliation.Object class • Serves as a new root of the class hierarchy • Has globalize methods & a reconciliation default • Contains “hidden” system fields and methods • javax.reconciliation.Reconciler abstract “hidden” system class • Reconciliation mechanism (synchronization, registration, etc) is implemented as its subclass Reconciliations in OOP
a1 rx x rx.globalize(); a2 localized (x) { x x.globalize(); x = ...; a3 x = ...; rx.globalize(); x localized (x) { x.globalize(); x.foo(); x.globalize(); } Sample Runtime x1 x3 x2 Reconciliations in OOP
Summary • A new object-oriented software engineering technique targeting common concurrent systems design issues and employing a programming language extension is proposed • The new technique is based on the reconciliations idea – a customizable shared memory consistency model • An academic implementation of the language extension has been built and working examples are supplied Reconciliations in OOP