Ghost
Upcoming SlideShare
Loading in...5
×
 

Ghost

on

  • 1,889 views

ESUG 2011, Edinburgh

ESUG 2011, Edinburgh

Statistics

Views

Total Views
1,889
Views on SlideShare
1,884
Embed Views
5

Actions

Likes
0
Downloads
19
Comments
0

1 Embed 5

http://twitter.com 5

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Ghost Ghost Presentation Transcript

    • Mariano Martinez Peck marianopeck@gmail.com http://marianopeck.wordpress.com/ 1Monday, August 22, 2011
    • What is a proxy? A proxy object is a surrogate or placeholder that controls access to another target object. 2Monday, August 22, 2011
    • Glossary Target: object to proxify. Client: user of the proxy. Interceptor: object that intercepts message sending. Handler: object that performs a desired action as a consequence of an interception. 3Monday, August 22, 2011
    • Forwarder and Logging example 4Monday, August 22, 2011
    • With or without Object replacement? In proxies with object replacement (#become:), the target object is replaced by a proxy. Proxies without object replacement are a kind of factory. 5Monday, August 22, 2011
    • With or without Object replacement? In proxies with object replacement (#become:), the target object is replaced by a proxy. Proxies without object replacement are a kind of factory. 5Monday, August 22, 2011
    • Traditional proxy implementations Usage of a minimal object together with an implementation of a custom #doesNotUnderstand ProtoObject identityHash pointersTo nextObject ... Proxy target doesNotUnderstand: executeBeforeHandling executeAfterHandling 6Monday, August 22, 2011
    • We are going to play a little game... 7Monday, August 22, 2011
    • Are both prints in Transcript the same or not? 8Monday, August 22, 2011
    • Are both prints in Transcript the same or not? Conclusion: methods understood are NOT intercepted. Is that bad? 8Monday, August 22, 2011
    • Are both prints in Transcript the same or not? Conclusion: methods understood are NOT intercepted. Is that bad? Different execution paths 8 Errors difficult to findMonday, August 22, 2011
    • Do we want the regular #doesNotUnderstand or to intercept the message? 9Monday, August 22, 2011
    • Do we want the regular #doesNotUnderstand or to intercept the message? 10Monday, August 22, 2011
    • I wanted the normal #doesNotUnderstand!!! 11Monday, August 22, 2011
    • I wanted the normal #doesNotUnderstand!!! 12Monday, August 22, 2011
    • Problems #doesNotUnderstand: cannot be trapped like a regular message. Mix of handling procedure and proxy interception. Only methods that are not understood are intercepted. No separation between proxies and handlers This approach is not stratified 13Monday, August 22, 2011
    • Subclassing from nil does not solve the problem. 14Monday, August 22, 2011
    • VM CRASH This solution is not uniform 15Monday, August 22, 2011
    • A Uniform, Light-weight and Stratified Proxy Model and Implementation. 16Monday, August 22, 2011
    • Used hooks Object replacement (#become:) Change an object’s class (#adoptInstance:) Objects as methods (#run:with:in:) Classes with no method dictionary (#cannotInterpret:) 17Monday, August 22, 2011
    • Object replacement B B A A c become: d D D C C 18Monday, August 22, 2011
    • Objects as methods The VM sends #run: aSelector with: anArray in: aReceiver 19Monday, August 22, 2011
    • Objects as methods The VM sends #run: aSelector with: anArray in: aReceiver So.....We can implement in Proxy: 19Monday, August 22, 2011
    • CLasses with no method dictionary References Object instance of message send lookup subclass Proxy cannotInterpret: aMessage aProxy username 4: #cannotInterpret: lookup 1: #username send ProxyTrap methodDict := nil aProxy 2: #aProxy lookup 3: Since the method dictionary was nil, the VM sends #cannotInterpret to the receiver but starting the lookup in the superclass 20Monday, August 22, 2011
    • Ghost model Interception Object message proxy proxyState ProxyHandler Proxy handleInterception: anInterception handler target cannotInterpret: proxyFor: SimpleForwarderHandler handleInterception: anInterception ProxyTrap initialize nilMethodDict 21Monday, August 22, 2011
    • How it works? Object Proxy handler target cannotInterpret: proxyFor: ProxyTrap initialize nilMethodDict 22Monday, August 22, 2011
    • How it works? Object Proxy handler target cannotInterpret: Proxy class >> proxyFor: ProxyTrap initialize nilMethodDict 22Monday, August 22, 2011
    • How it works? Object Of Proxy ce handler ns tan target Proxy class >> i cannotInterpret: proxyFor: aProxy ProxyTrap initialize nilMethodDict aHandler ‘Mariano’ 22Monday, August 22, 2011
    • How it works? Object Of Proxy ce handler ns tan target Proxy class >> i cannotInterpret: proxyFor: aProxy ProxyTrap initialize nilMethodDict aHandler ‘Mariano’ ProxyTrap class >> 22Monday, August 22, 2011
    • How it works? Object Proxy handler target cannotInterpret: Proxy class >> aProxy ins proxyFor: tan ce Of ProxyTrap initialize nilMethodDict aHandler ‘Mariano’ ProxyTrap class >> 22Monday, August 22, 2011
    • How it works? Object Proxy handler target cannotInterpret: Proxy class >> aProxy ins proxyFor: tan ce Of ProxyTrap initialize nilMethodDict aHandler ‘Mariano’ 22Monday, August 22, 2011
    • How it works? References instance of Object message send lookup subclass Proxy cannotInterpret: aMessage aProxy username 4: #cannotInterpret: lookup 1: #username send ProxyTrap methodDict := nil aProxy 2: #aProxy lookup 3: Since the method dictionary was nil, the VM sends #cannotInterpret to the receiver but starting the lookup in the superclass 23Monday, August 22, 2011
    • How it works? References instance of Object message send lookup subclass Proxy cannotInterpret: aMessage aProxy username 4: #cannotInterpret: lookup 1: #username send ProxyTrap methodDict := nil aProxy 2: #aProxy lookup 3: Since the method dictionary was nil, the VM sends #cannotInterpret to the receiver but starting the lookup in the superclass 23Monday, August 22, 2011
    • How it works? References instance of Object message send lookup subclass Proxy cannotInterpret: aMessage aProxy username 4: #cannotInterpret: lookup 1: #username send ProxyTrap methodDict := nil aProxy 2: #aProxy lookup 3: Since the method dictionary was nil, the VM sends #cannotInterpret to the receiver but starting the lookup in the superclass 23Monday, August 22, 2011
    • How it works? References instance of Object message send lookup subclass Proxy cannotInterpret: aMessage aProxy username 4: #cannotInterpret: lookup 1: #username send ProxyTrap methodDict := nil aProxy 2: #aProxy lookup 3: Since the method dictionary was nil, the VM sends #cannotInterpret to the receiver but starting the lookup in the superclass 23Monday, August 22, 2011
    • How it works? References instance of Object message send lookup subclass Proxy cannotInterpret: aMessage aProxy username 4: #cannotInterpret: lookup 1: #username send ProxyTrap methodDict := nil aProxy 2: #aProxy lookup 3: Since the method dictionary was nil, the VM sends #cannotInterpret to the receiver but starting the lookup in the superclass 23Monday, August 22, 2011
    • How it works? References instance of Object message send lookup subclass Proxy >> Proxy cannotInterpret: aMessage aProxy username 4: #cannotInterpret: lookup 1: #username send ProxyTrap methodDict := nil aProxy 2: #aProxy lookup 3: Since the method dictionary was nil, the VM sends #cannotInterpret to the receiver but starting the lookup in the superclass 23Monday, August 22, 2011
    • How it works? References instance of Object message send lookup subclass Proxy >> Proxy cannotInterpret: aMessage aProxy username 4: #cannotInterpret: lookup 1: #username send ProxyTrap methodDict := nil aProxy 2: #aProxy lookup SimpleForwarderHandler >> 3: Since the method dictionary was nil, the VM sends #cannotInterpret to the receiver but starting the lookup in the superclass 23Monday, August 22, 2011
    • Traditional Ghost #doesNotUnderstand: #cannotInterpret: is cannot be trapped like a trapped like a regular regular message. message. Mix of handling No mix of handling procedure and proxy procedure and proxy interception. interception. Only methods that are “All” methods are not understood are intercepted. intercepted. No separation between Clear separation between proxies and handlers. proxies and handlers. 24Monday, August 22, 2011
    • is stratified 25Monday, August 22, 2011
    • Methods not intercepted 1) Optimizations done by the Compiler 2) Special shortcut bytecodes between Compiler and VM 2.1) Methods NEVER sent: #== and #class 2.2) Methods that may or may not be executed depending on the receiver and arguments: e.g. in ‘1+1’ #+ is not executed. But with ‘1+$C’ #+ is executed. 2.3)Always executed, they are just little optimizations. Examples #new, #next, 26 #nextPut:, #size, etc.Monday, August 22, 2011
    • Methods not intercepted 1) Optimizations done by the Compiler 2) Special shortcut bytecodes between Compiler and VM 2.1) Methods NEVER sent: #== and #class 2.2) Methods that may or may not be executed depending on the receiver and arguments: e.g. in ‘1+1’ #+ is not executed. But with ‘1+$C’ #+ is executed. 2.3)Always executed, they are just little optimizations. Examples #new, #next, 26 #nextPut:, #size, etc.Monday, August 22, 2011
    • Methods not intercepted 1) Optimizations done by the Compiler 2) Special shortcut bytecodes between Compiler and VM 2.1) Methods NEVER sent: #== and #class 2.2) Methods that may or may not be executed depending on the receiver and arguments: e.g. in ‘1+1’ #+ is not executed. But with ‘1+$C’ #+ is executed. 2.3)Always executed, they are just little optimizations. Examples #new, #next, 26 #nextPut:, #size, etc.Monday, August 22, 2011
    • Proxy for classes Object ClassProxy Proxy superclass handler methodDict target format cannotInterpret: handler proxyFor: target cannotInterpret: proxyFor: ProxyTrap initialize nilMethodDict ClassProxyTrap initialize nilMethodDict User username age logIn: validate: 27Monday, August 22, 2011
    • Proxy for classes Object ClassProxy Proxy superclass handler methodDict target format cannotInterpret: handler proxyFor: target cannotInterpret: proxyFor: ProxyTrap initialize nilMethodDict ClassProxyTrap initialize nilMethodDict User username age logIn: validate: 27Monday, August 22, 2011
    • Proxy for classes Object ClassProxy Proxy superclass handler methodDict target format cannotInterpret: handler proxyFor: target cannotInterpret: proxyFor: ProxyTrap initialize nilMethodDict ClassProxyTrap initialize nilMethodDict User username age logIn: validate: 27Monday, August 22, 2011
    • Proxy for classes Object ClassProxy Proxy superclass handler methodDict target format cannotInterpret: handler proxyFor: target cannotInterpret: proxyFor: ProxyTrap initialize nilMethodDict ClassProxyTrap initialize nilMethodDict User username age logIn: validate: 27Monday, August 22, 2011
    • Proxy for classes Object ClassProxy Proxy superclass handler methodDict target format cannotInterpret: handler proxyFor: target cannotInterpret: proxyFor: ProxyTrap initialize nilMethodDict ClassProxyTrap initialize nilMethodDict User username age logIn: ins tan validate: ce aUser of aClassProxy methodDict = nil superclass = ClassProxy 27Monday, August 22, 2011
    • Proxy for classes Object ClassProxy Proxy superclass handler methodDict target format cannotInterpret: handler proxyFor: target cannotInterpret: proxyFor: ProxyTrap initialize nilMethodDict ClassProxyTrap initialize nilMethodDict User username age logIn: ins tan validate: ce aUser of aClassProxy methodDict = nil superclass = ClassProxy 27 User nameMonday, August 22, 2011
    • Proxy for classes Object ClassProxy Proxy superclass handler methodDict target format cannotInterpret: handler proxyFor: target cannotInterpret: proxyFor: ProxyTrap initialize nilMethodDict ClassProxyTrap initialize nilMethodDict User username age logIn: ins tan validate: ce aUser of aClassProxy methodDict = nil aUser username superclass = ClassProxy 27 User nameMonday, August 22, 2011
    • Proxy for methods 28Monday, August 22, 2011
    • Proxy for methods Regular message 28Monday, August 22, 2011
    • Proxy for methods Regular message Method execution 28Monday, August 22, 2011
    • Proxy for methods Regular message Method execution Just handling #run:with:in correctly is enough to also intercept method execution. 28Monday, August 22, 2011
    • is Uniform 29Monday, August 22, 2011
    • is more Uniform 29Monday, August 22, 2011
    • More features Low memory footprint. Compact classes. Store the minimal needed state. Easy debugging. Custom list of messages. 30Monday, August 22, 2011
    • Conclusion With a little bit of special support from the VM (#cannotInterpret hook), we can have an image-side proxy solution much better than the classic #doesNotUnderstand: 31Monday, August 22, 2011
    • Future work Experiment with immediate proxies (memory address tag) in VM side. Think how to correctly intercept non- executed methods. 32Monday, August 22, 2011
    • Links http://rmod.lille.inria.fr/web/pier/software/ Marea/GhostProxies http://www.squeaksource.com/Marea.html 33Monday, August 22, 2011
    • A Uniform, Light-weight and Stratified Proxy Model and Implementation Mariano Martinez Peck marianopeck@gmail.com http://marianopeck.wordpress.com/Monday, August 22, 2011