From Objects to Actors Study of a Limited Symbiosis in Smalltalk-80.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Intertask Communication and Synchronization In this context, the terms “task” and “process” are used interchangeably.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
Computer Systems/Operating Systems - Class 8
Stéphane Ducasse«ChapterNr».1 Selected Design Patterns Design Patterns are recurrent solutions to design problems They are pros and cons We already saw:
Principles of Object-Oriented Software Development The language Smalltalk.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Introduction in algorithms and applications Introduction in algorithms and applications Parallel machines and architectures Parallel machines and architectures.
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
Stéphane Ducasse«ChapterNr».1 Arthur Riel Design Heuristics from Object-Oriented Design Heuristics by Arthur Riel Read the Heuristics… –Find reasons why.
Stéphane Ducasse9.1 Inheritance Semantics and Lookup.
Stéphane Ducasse 1 The Taste of Smalltalk.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Summer Semester 2006.
Principles of Object-Oriented Software Development Object-oriented programming languages.
Concurrency CS 510: Programming Languages David Walker.
PZ06BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06BX - Introduction to Smalltalk Programming Language.
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.
Asynchronous Message Passing EE 524/CS 561 Wanliang Ma 03/08/2000.
03G-1 Everything is an Object Examining builtin classes All these are classes in Little Smalltalk:  Object  Class  Method  Block  Boolean True False.
Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses.
Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell.
On the Duality of Operating System Structures Hugh C. Lauer Xerox Corporation Roger M. Needham Cambridge University Presented By: Ashwini Kulkarni.
Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Real Time Operating System
Programming Network Servers Topic 6, Chapters 21, 22 Network Programming Kansas State University at Salina.
Austin Java Users Group developerWorks article – µActor Library BARRY FEIGENBAUM, PH. D. 02/26/13.
Parallel Programming Models Jihad El-Sana These slides are based on the book: Introduction to Parallel Computing, Blaise Barney, Lawrence Livermore National.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
S.Ducasse Stéphane Ducasse 1 Processes and Concurrency in VW.
CS 598 Scripting Languages Design and Implementation 7. Smalltalk 80.
- 1 - Embedded Systems - SDL Some general properties of languages 1. Synchronous vs. asynchronous languages Description of several processes in many languages.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Concurrent Aggregates (CA) Andrew A. Chien and William J. Dally Presented by: John Lynn and Ryan Wu.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
Chapter 12 Support for Object oriented Programming.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Inheritance Semantics and Method Lookup.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Smalltalk in a.NET World How to write a Smalltalk compiler without writing a VM John Brant
Stéphane Ducasse 1 Singleton.
S.Ducasse 1 7. Understanding Metaclasses. S.Ducasse 2 Roadmap Metaclasses in 7 points Indexed Classes Class Instance Variables Class Variables Pool Dictionaries.
3C-1 Purity Typing Language semantics Inheritance model  Single vs. Multiple inheritance  Common root Modular mechanisms Generics Object Oriented Languages.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
ACTORS. Motivation Develop language for concurrency “ Parallel Execution of actions ”.
3C-1 Identifiers Variables Literal Objects  Numbers  Characters  Strings Control Structure  Blocks  Conditionals  Loops Messages Defining New Classes.
Stéphane Ducasse7.1 Let’s Play Objects Simulate a LAN physically Set up a context for –future chapters –Exercises Some forward references to intriguate.
S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Smalltalk in a Nutshell.
CSE 3302 Programming Languages Chengkai Li Fall 2007 Smalltalk Lecture 14 – Smalltalk, Fall CSE3302 Programming Languages, UT-Arlington ©Chengkai.
Concurrent Object-Oriented Programming Languages Chris Tomlinson Mark Scheevel.
Stéphane Ducasse 1 A Little Journey in the Smalltalk Syntax.
Stéphane Ducasse 1 Abstract Classes.
Administrative Issues Lecture 22 – Prolog (III), Fall 2007 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li, HW3 (due at March 18 th ) Essay.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
Message passing model. buffer producerconsumer PRODUCER-CONSUMER PROBLEM.
Smalltalk Meta-Programming Programming Languages HUJI 2010 Yardena Meymann.
Let’s Play Objects.
Chapter 3: Process Concept
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
2.2 Framework Techniques.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Presented by Gitit Amihud
Reflective Programming in Smalltalk eXterme Metaprogramming
Introduction to Smalltalk
Introduction to Smalltalk
CSE 3302 Programming Languages
Presentation transcript:

From Objects to Actors Study of a Limited Symbiosis in Smalltalk-80

Actalk Minimal extension needed to introduce and study concurrency Jean-Pierre Briot

Goals Preservation No change made to Smalltalk-80 Minimality Extensibility Synergy The current model of objects and the extended set of actors should be compatible and able to cooperate Pedagogy

Computation Model of Smalltalk-80 Synchronous communication A single thread of activity which is passed among objects in a call/return fashion when sending messages. The sender is waiting for the reply from the receiver and remains blocked until this moment. Some tools for concurrency Processus + semaphores

Computation Model of Smalltalk-80 Environment of computation The environment of the object Bindings of instance variables, class variables... The environment of the message. Bindings of parameters The global environment Blocks Closure mechanism Delayed evaluation and abstraction Control structures

Computation Model of Smalltalk-80 Multiple activities Process Semaphores To protect the internal state of an object that is shared by multiple processes

From passive to active objects An active object is able to decide when and how it will compute the messages A serializer encapsulates an object and serializes the incoming messages in a message queue Actor = a serialized and active object.

Modeling an actor as a serialized object Message queue Object Actor

Implementing Actors in ST-80 Two classes : Actor and ActorBehavior Any ST-80 object may be used as a behavior of a new actor if its class is a subclass of ActorBehavior A background process will be created when creating the actor to implement the autonomy of the behavior of the actor. mailbox behavior aself

The class Actor EOBject subclass: #Actor instanceVariableNames: ‘mailbox behavior’ classVariableNames: ‘’ poolDictionaries: ‘’ Category ‘Actors’ !Actor methodFor: ‘initialization’! initialize mailbox := SharedQueue new initializeBehavior: aBehavior behavior := aBehavior. behavior initializeAself: self !Actor methodFor: ‘iv access’! mailbox ^mailbox !Actor methodFor: ‘message passing’! asynchronousSend: aMessage mailbox nextPut: aMessage

The (meta)class of Actor Actor class instanceVariableNames: ‘’ !Actor class methodFor: ‘instance creation and initialization’! behavior: aBehavior ^self new initializeBehavior: aBehavior new ^super new initialize

The class ActorBehavior OBject subclass: #ActorBehavior instanceVariableNames: ‘aself’ classVariableNames: ‘’ poolDictionaries: ‘’ Category ‘Actors’ !ActorBehavior methodFor: ‘initialization’! initializeAself: anActor aself := anActor. self setProcess setProcess [[true] whileTrue: [self acceptNextMessage]] fork !ActorBehavior methodFor: ‘message acceptance’! acceptNextMessage self acceptMessage: aself mailbox next acceptMessage: aMessage self performMessage: aMessage The process is suspended and resumed when there is a message by the semaphore synchronizing the availability of message(s) in the shared queue

Support Method !Object methodFor: ‘message handling’! performMessage: aMessage ^self perform: aMessage selector arguments: aMessage arguments

Example: the class Counter ActorBehavior subclass: #Counter instanceVariableNames: ‘value’ classVariableNames: ‘’ poolDictionaries: ‘’ Category ‘Actors’ !Counter methodFor: ‘script’! incr value := value + 1 reset value := 0 !Counter class methodFor: ‘examples’! example | aCounter aCounterActor | aCounter := Counter new. aCounter reset; incr; incr; aCounterActor := Actor behavior: Counter new reset aCounterActor asynchronousSend: (Message selector: #incr)

Transparent Asynchronous Message Passing !Actor methodFor: ‘message passing’ ! doesNotUnderstand: aMessage self asynchronousSend: aMessage

The class EObject EObject subclass: #Actor instanceVariableNames: ‘’ classVariableNames: ‘’ poolDictionaries: ‘’ Category ‘Encapsulator’ !EObject class methodFor: ‘initialization’! initialize self superclass: nil. #( doesNotUnderstand: error: ~~ isNil = == printString printOn: class inspect basicInspect basicAt: basicSize instVarAt: instVarAt:Put) do: [ :selector | Object copyMethodSelector: selector inClass: self] !EObject class methodFor: ‘superclass access’! superclass: aClass superclass := aClass EObject initialize

Support Method !Class methodFor: ‘recopying method’! copyMethodSelector: selector inClass: self class compile: (self sourceCodeAt: selector) classified: (self whichCategoryIncludeSelector: aSelector)

How to create an actor ? !ActorBehavior methodFor: ‘actor creation’! 1st choice : create an actor from an instance of ActorBehavior actor ^Actor behavior: self 2nd choice : creating an actor from the model of behavior by redefining the new method new ^Actor behavior: super new 3nd choice : creating an actor from the model of behavior by creating a new selector newActor ^Actor behavior: self new

Compatibility with initialization !Counter class methodFor: ‘instance creation’! new ^super new reset !Counter class methodFor: ‘instance creation and initialization’! contents: anInteger ^self new contents: anInteger !Counter methodFor: ‘iv access’! contents: anInteger contents := anInteger What happens for each of the three approaches to actor creation?

Actor Framework ExtendedActorBehavior methodfor: ‘generic scheduling control’ scheduleAfterAcceptedMessage! scheduleAfterPerformedMessage! scheduleAfterReceivedMessage! ! ExtendedActorBehavior methodfor: ‘generic scheduling control’ acceptMessage: aMessage self scheduleAfterAcceptedMessage. super acceptMessage: aMessage. self scheduleAfterPerformedMessage! ! ExtendedActor methodsFor: ‘message passing’ asynchronousSend: aMessage super asynchronousSend: aMessage. behavior scheduleAfterReceivedMessage

Redefining scheduling update user interface Counter methodFor: ‘scheduling control’ scheduleAfterPerformedMessage self changed. Processor yield

Symbiosis between objects and actors Sending a message to an actor Interpreted as asynchronous send Sending a message to objects Synchronous control The target of the message defines the semantics of message passing

Delegation Sub-computation can be passed on by an actor to another actor which continues the processing. Delegation promotes modularity of the code.

Reply Destination and Delegation ActorBehavior subclass: #Printer instanceVariableNames: ‘’ classVariablesNames: ‘’ poolDIctionaries: ‘’ category: ‘Actor-Examples’ !Printer methodFor: ‘script’! reply: value Transcript show: ‘> ‘, value printString; cr! ! Printer class methodsFor: ‘initialization’! intialize Smalltalk at: #Print put: self new actor! ! Printer initialize!

Reply Destination and Delegation !Counter methodFor: ‘script’ consultAndReplyTo: replyDestination replyDestination reply: contents! ! !Counter class methodsFor: ‘example’! example (Counter contents: 100) actor incr; incr; consultAndReplyTo: Print! !

Exploitation of Concurrency The Prime Number Example ActorBehavior subclass: #PrimeGenerator instanceVariables: ‘firstPrimeFilter’ initialize firstPrimeFilter := (PrimeFilter n: 2) actor upTo: max 2 to: max do: [:i | firstPrimeFilter filter: i] PrimeGenerator class new ^super new initialize example PrimeGenerator new actor upTo: 100

Exploitation of Concurrency The Prime Number Example ActorBehavior subclass: #PrimeFilter instanceVariables: ‘n next’ n: aPrimeNumber n := aPrimeNumber filter: i i \\ n = 0 ifFalse: [next isNil ifTrue: [Print reply: i. next := (PrimeFilter n: i) actor] ifFalse: [next filter: i]] PrimeFilter class n: n ^self new n: n

References Briot, Jean-Pierre, From Objects to Actors: Study of a Limited Symbiosis in Smalltalk-80, LITP RXF, Université Pierre et Marie Curie, France, sept From Objects to Actors: Study of a Limited Symbiosis in Smalltalk-80