Docstoc

Institut National de Recherche e

Document Sample
Institut National de Recherche e Powered By Docstoc
					          SOM: Sequential Object Monitors
                                   Denis Caromel
                       Institut universitaire de France (IUF)
                INRIA Sophia-Antipolis – CNRS – I3S – Université de Nice

                                     Luis Mateu
                              DCC – Universidad de Chile

                                     Eric Tanter
                DCC – Universidad de Chile – Ecole des Mines de Nantes


          1. SOM Principles: Thread-Less Active Object
                 2. Scheduling Strategy and API
                           3. Examples
               4. Implementation and Benchmarks
Denis Caromel                                                              1
      Thread Locks, Notify, Synchronization

wait/notifyAll of
Java monitors are:
• Difficult to understand for
  most programmers
• Inefficient: may trigger lots
  of thread context-switches
• Tangling of synchronization           Not “Sequential”:
  concern with application logic   many pending, interleaved, method calls

     Denis Caromel                                                  2
                SOM Orientations

• Easier to understand:
      • Sequentiality of monitor code

• Efficient:
      • Minimize thread context-switches

• Separation of concerns:
     • Separate synchronization code       from
                   synchronized code

Denis Caromel                                     3
SOM: an Object and a thread-less scheduler

                                  (1) Method
                                    call
                                    reification
                                    in queue

                                  (2) Schedule
                                    method

                                  (3) Request
                                    execution
  Denis Caromel                          4
                    SOM Principles

• Any method invocation on a SOM:
      • reified as a request, and
      • delayed in a pending queue until scheduled
• The scheduling method is:
      • guaranteed to be executed if a request may be scheduled
• A scheduled request is executed:
      • in mutual excusion with other requests and scheduling


  Denis Caromel                                             5
 What’s in the name ?
S equential:            no interleaving,
              ”run-to-completion” action

O bject:           Method Call,
                   Reification: Request

M onitor:Mutual Exclusion
  Denis Caromel                       6
                Scheduling:

    Principles         and   API
Denis Caromel                      7
          SOM: thread-less scheduling +
            minimizing context switch




Denis Caromel                             8
          SOM: thread-less scheduling +
            minimizing context switch




Denis Caromel                             9
                SOM Strategy and Guarantees

• No infinite busy execution of scheduling method
• schedule() is called by caller threads, in mutual exclusion
• No additional thread is needed to execute schedule
• Several requests can be scheduled at a time:
   • requests executed by their caller threads, in scheduling order
   • schedule will not be called again before all scheduled requests complete
• After a request is executed:
      • the caller thread does at most one schedule
     Denis Caromel                                                    10
   Principle
    for the
scheduling API

                   Standard class:

                   class Buffer {
                     ...
                     void put(Object o) { ... }
                     Object get() { ... }
                     boolean isEmpty() { ... }
                     boolean isFull() { ... }
                   }

   Denis Caromel                                  11
                    Scheduler API




scheduleOldest ();          scheduleAll(new RequestFilter()
scheduleOldest (“get”);       boolean accept(Request req){
scheduleAll(“exitRead”);          if …     return true
scheduleOlderThan(“foo”,”bar”);   if …     return false
    Denis Caromel
                                 … } );             12
  The Full Scheduler for buffer-like classes




 public void schedule () {
                              scheduleOldest (“get”);
     if (!buffer.isEmpty() ) scheduleOldest(putMethod);
     if (!buffer.isFull() ) scheduleOldest (“put”);
   }



                 Full control to tune any method names !
                Can be abstracted forthe synchronization !
Denis Caromel                                                13
       Fair

Reader Writer

      with

      SOM


  Denis Caromel   14
 Implementation
      and
  Benchmarks
Denis Caromel   15
                         Implementation
• Based on a specific MOP: Reflex [Tanter et al. OOPSLA 03]
   • Bytecode transformation
   • A generic metaobject (scheduler) uses Java monitor for synchronization


• Small configuration language:
                 schedule:   Buffer     with:    BufferScheduler
                 ...
• Runtime API
   Buffer b = (Buffer) SOM.newMonitor(Buffer.class,
                                      BufferScheduler.class);


 Denis Caromel                                                     16
                    Linux 2.4 JDK 1.4.2 Benchmarks
    Single item buffer, one producer, multiple consumers
                            12000
                                        Java monitors
      Execution time (ms)

                            10000
                                        SOM
                            8000

                            6000

                            4000

                            2000

                               0
                                    1         2         4   8     16    32

                                           Number of consumer threads


     SOM monitors scale better than Java monitors
Denis Caromel                                                                17
                  SOM Expressiveness
                          (in the paper)
SOM-based solutions for
                                • Full access to request queue,
 • Bounded buffer                 order of requests, filter, etc. :
 • Readers and writers                 ==> Full control to express
 • Dining philosophers                      various policies
                                • E.g: Reader Writers :
SOM-based Abstractions of
                                   •   Fair,
 • Guards                          •   Reader Priority,
 • Chords                          •   Writer Priority
                                   •   ...

  Denis Caromel                                              18
                         Related Work
• Classical monitors [Hoare and Brinch Hansen]
• Java monitors
• Java Specification Request 166 (JDK 1.5)
• Guards:
      • Easy to express declarative synchronizations in SOM
• Scheduler, Active Objects:
           • SOM = AO without Activity, AO without its own thread
• Chords, Join, Functional Nets:
        • Storing monitor state in parameters of pending calls,
        • Calls Interleaving
    My view: in a stateful OO, better of to reason about pending queue state
Denis Caromel                                                         19
       SÖM: Sæquentiål Øbjæct Mönitör
• An alternative to standard, interleaving, monitors
• Key points:
   • Thread-less scheduler, Thread-less Active Object
   • Threads collaborate for Mutual Scheduling
• Separation of concerns:
   • Synchronizing + Synchronized code
• Expressive and Efficient:
   • Full access to pending calls
   • Avoids context-switches
• Stateful (object) vs. Pending Function Calls :
   • Reason about data structure state rather than call interleaving
   • Sequentiality: easier to reason about, to maintain, to reuse
Denis Caromel                                                          20
Denis Caromel   21
                Chords (Polyphonic C#)
Related to functional calculus (Join, Functional Nets):
       • Storing monitor state in pending calls
             e.g. calling an asynchronous sharedRead (n-1)
       • Passing information from one call to another (copied)
             ==> No mutual exclusion is intrinsically required
An asynchronous call is also a kind of ’’Firing Token’’ + Value

Very nice abstraction for a purely functional setting but :
       • No access to the queue of pending calls,
       • Does not really promote interleaving-free reasoning


Denis Caromel                                                     22
                Reader Writer Chords in C#




Denis Caromel                                23
                Reader Writer Interface




Denis Caromel                             24
                      SOM
       Writer priority // Reader priority




Denis Caromel                               25
       A declarative abstraction: Guards




Denis Caromel                              26
                Windows 2000, JDK 1.4.2




Denis Caromel                             27
                Linux 2.4, JDK 1.4.2




Denis Caromel                          28
                Linux 2.6, JDK 1.5




Denis Caromel                        29
Denis Caromel   30
                SOM key originalities

 • Thread-less scheduler, Thread-less Active Object

 • Threads collaborate for mutual schedulling


From Active Objects, Scheduler, to SOM



Denis Caromel                                         31
                    SOM Goals

• Powerful: other synchronization mechanisms are easily
  expressed with SOMs

• Easier to understand: method requests are executed
  sequentially

• Efficient: SOMs minimize thread context-switches

• Separation of concerns: SOMs separate the
  synchronization concern from the application logic

Denis Caromel                                             32
       An Example: The Bounded Buffer
                               Scheduler:
Standard object:
                               class BufferScheduler
class Buffer {                       extends Scheduler {
  ...                            Buffer buf;
  void put(Object o) { ... }     ...
  Object get() { ... }           void schedule() {
  boolean isEmpty() { ... }        if (buf.isEmpty())
                                     scheduleOldest(“put”);
  boolean isFull() { ... }
                                   else if (buf.isFull())
}
                                     scheduleOldest(“get”);
                                   else
                                     scheduleOldest();
                                 }
                               }
Denis Caromel                                                 33

				
DOCUMENT INFO