Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility
description
Transcript of Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility
![Page 1: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/1.jpg)
Emerald - et OO-språk for distribuerte applikasjonerReview – Concurrency -
Mobility
Eric JulOMS
Professor II
![Page 2: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/2.jpg)
Emerald Review
We’ll start with a review of Emerald from the first two lecture series (F1, F2):
• Everything is an object• Algol-60/Simula/Smalltalk heritage• Object constructors• Conformity based type system – think
interfaces
![Page 3: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/3.jpg)
Main Contributions• Distribution: Mobile objects (Eric/Hank)
Any object can move at any time. Full on-the-fly• object mobility• thread mobility• heterogeneous mobility
• Conformity based type system (Norm/Andrew)Type system based on conformity principleWell-defined semantics (e.g., NIL makes sense!)
• Clean OO language (better than succesors?) including uniform object model
![Page 4: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/4.jpg)
Class done by Syntatic Sugaring
The following turns into the previous double object constructor:class seqno
var prev: Integer = 0Integer operation getSeqNo[]
prev <- prev +1return prev
end getSeqnoend seqno
![Page 5: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/5.jpg)
Types
Types are abstract descriptions of the operations required of an object (think: Java Interfaces – they are close to identical to types in Emerald).
Collection of operation signatures.Signature is name & types of each parameter
![Page 6: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/6.jpg)
Conformity informally(substitution)
A type A conforms to another type B when any object that conforms to A can be used anywhere something of type B is required.
Substitution principle.
Means A is as larger or larger than B.
![Page 7: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/7.jpg)
What is conformity?type BankAccount operation deposit[Integer] operation withdraw[Integer]
->[Integer] function fetchBalance[] ->
[Integer]end BankAccount
type DepositOnlyBankAccount function fetchBalance[] ->
[Integer] operation deposit[Integer]end DepositOnlyBankAccount
Conformity object-to-type
and type-to-type
BankAccount conforms to DepositOnlyBankAccount because it support all the require operations – and the parameters also conform
![Page 8: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/8.jpg)
Conformity details
• Conformity is implicit. • It is a mathematical relation• No ”implements” as in Java• Operation names important• Parameter names do not matter, just their
types matters. (Parameter name for documentation only.)
• Arity matters: foo(char) different from foo(char, float)
![Page 9: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/9.jpg)
Conformity more formally
NOT IMPORTANT HERE
![Page 10: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/10.jpg)
Lattice of types
• Types form a lattice• Top is
type Anyend Any
• Bottom is Noone (it has ALL operations”)• NIL conforms to Noone • NIL can thus be assigned to any variable!
(Read ”Much Ado About NIL.)
![Page 11: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/11.jpg)
Array
• Just an object• Supports “of” which returns an object• Array.of[Integer]• This is a type (!)• But it is also an object – that supports create (!)
• Creates an EMPTY array.• Addupper, addlower
![Page 12: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/12.jpg)
Process Concept
A process is a thread of execution.
Every object can have ONE process.(Or none, but can also be modelled as a
process that is “empty”.)Process section in object constructor
![Page 13: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/13.jpg)
Synchronization Required
Classic Monitors as described by Tony Hoare
Example: hi – ho program (synch.m)
![Page 14: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/14.jpg)
Distribution
• Sea of objects (draw)• Sea is divided into disjunct parts called
Nodes• An object is on one and only one Node at a
time• Each node is represented by a Node object• Locate X returns the node where X is
(was!)
![Page 15: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/15.jpg)
Immutable Objects
• Immutable objects cannot change state• Examples: The integer 17• User-defined immutable objects: for
example complex numbers• Immutable objects are omnipresent• Types must be immutable to allow static
type checking
![Page 16: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/16.jpg)
Types are Immutable Objects
Example: arrays
var ai: Array.of[Integer]
ai <- Array.of[Integer].create[]
var aai: Array.of[Array.of[Integer]]
![Page 17: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/17.jpg)
Why Mobility?
• Local calls are typically 1,000 – 10,000 times faster than remote calls
• Mobility for:– performance– availability
![Page 18: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/18.jpg)
Mobility and Location Concepts
locate X returns (one of) the object X’s locationsmove X to Y move the object X to the node where Y is (or rather was)fix X at Y as move but disregard subsequent movesrefix X at Y as fix but for fixed objectsunfix X allow normal moves
![Page 19: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/19.jpg)
Call-by-move
var B: some data object… X.F[move B]…… X.F[visit B]…
object X operation F[arg:T] loop arg.g[…] exit after many loops end loopend X
![Page 20: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/20.jpg)
How Many Calls of B?Questions: given a normal PC enviroment, say 2
GHz CPU, 10 Mbit/s Ethernet, how many calls of a small (say 100 bytes) argument B before breakeven?
• 1• 10• 100• 1,000• 10,000• 100,000
![Page 21: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/21.jpg)
Killroyobject Killroy process var myNode <- locate self var up: array.of[Nodes] up <- myNode.getNodes[] foreach n in up move self to n end foreach end processend Killroy
• Object moves itself to all available nodes• On the original MicroVAX implementation:
20 moves/second• Note: the thread (called a process in
Emerald) moves along
![Page 22: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/22.jpg)
Attachment
Tree example
TreeNode
left, right
Mail message
ToFromSubjectBody
![Page 23: Emerald - et OO-språk for distribuerte applikasjoner Review – Concurrency - Mobility](https://reader034.fdocuments.in/reader034/viewer/2022051219/56816752550346895ddc0481/html5/thumbnails/23.jpg)
Grundliggende Distribution
• Remote References: Local &Global Objects• RPC – remote procedure call• Implementation of RPC• Location concept• Simple mobility• Asynchronous operations in Emerald• Immutability and its uses