Presentation is loading. Please wait.

Presentation is loading. Please wait.

Supporting Unanticipated Dynamic Adaptation of Application Behaviour Barry Redmond and Vinny Cahill Distributed Systems Group Trinity College, Dublin.

Similar presentations


Presentation on theme: "Supporting Unanticipated Dynamic Adaptation of Application Behaviour Barry Redmond and Vinny Cahill Distributed Systems Group Trinity College, Dublin."— Presentation transcript:

1 Supporting Unanticipated Dynamic Adaptation of Application Behaviour Barry Redmond and Vinny Cahill Distributed Systems Group Trinity College, Dublin

2 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 20022 Introduction Uses of unanticipated dynamic adaptation: –Long running applications –Applications which must adapt to a changing environment –Applications for which source code is not available “Unanticipated” –No preparatory modifications to source or compiled code “Dynamic”: –Insertion and removal of new behaviour at runtime Usually implemented for interpreted languages –MetaXa, Guaraná, PROSE, MetaclassTalk, Iguana/J

3 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 20023 Iguana/J An architecture to support unanticipated dynamic adaptation of Java programs Implemented as –An extended JVM –A class library Provides a strong separation between new and existing behaviours –New behaviour is reusable in compiled form Uses reflective techniques –Some reflective terms

4 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 20024 A Simple Example Add synchronisation to this class –while it is running –without access to the source code public class Stack { … public void push(Object o) { … } public Object pop() { … } }

5 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 20025 Implement the New Behaviour 1.Create a class to implement the new behaviour –Extend Iguana/J library class MExecute public class Sync extends MExecute { public Object execute( Object targ, Object[] args, Method m) { synchronized(targ) { return(proceed(targ, args, m)); } } } This is called a metaobject class

6 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 20026 Create a Protocol 2.Declare that our new class is for handling method invocation: protocol SyncProtocol { reify Invocation: Sync; } 3.Use the Iguana/J protocol compiler to convert this to a Java class file

7 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 20027 Associate the New Behaviour 4.Associate the new behaviour with the Stack class: Meta.associate(“Stack”, “SyncProtocol”); Affects all existing and future instances of Stack Association is inherited –Affects all subclasses of Stack and all their existing and future instances

8 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 20028 Associating with One Object Apply new behaviour to a single object: Object x = new Object(); … Meta.associate(x, “SyncProtocol”); Remove new behaviour: Meta.reset(x);

9 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 20029 Organisation Uanticipated adaptation Dynamic adaptation JVM Iguana/J extension Application classes Protocol compiler Protocol declarations Metaobject classes Protocol classes Iguana/J classes

10 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200210 A More Focused Solution Apply synchronisation to selected methods of Stack: public class Sync extends MExecute { public Object execute( Object targ, Object[] args, Method m) { String s = m.getName(); if(s.equals(“push”) || s.equals(“pop”)) { synchronized(targ) { return(proceed(targ, args, m)); } } else return(proceed(targ, args, m)); } }

11 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200211 A Reusable Solution public class Sync extends MExecute { private String[] names; public Sync(String[] n) { names = n;// Accept & store parameters } public Object execute( Object targ, Object[] args, Method m) { if(match(m.getName())) { synchronized(targ) { return(proceed(targ, args, m)); } } else return(proceed(targ, args, m)); } // Check for match with an element of names[]: private boolean match(String s) { … } }

12 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200212 Applying the Reusable Solution Add parameters to the protocol declaration: protocol SyncProt(String[] mNames) { reify Invocation: Sync(mNames); } Provide parameter values at association time: Object[] params = new Object[1]; params[0] = new String[] {“push”, “pop”}; Meta.associate(“Stack”, “SyncProt”, params);

13 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200213 Context Sensitivity Allow calls only from a specified class: public class Guard extends MExecute { private String name; public Guard(String c) { name = c & “.*”; } public Object execute( Object targ, Object[] args, Method m) { if(getCallStack().containsCallTo(name)) return(proceed(targ, args, m)); else throw new RuntimeException(); } } protocol GuardProt(String cName) { reify Invocation: Guard(cName); }

14 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200214 Deriving New Behaviour Protocols may be derived from other protocols protocol NewP(String c, String[] m): GuardProt(c), SyncProt(m) { reify Invocation: Verbose; } Automatic composition of metaobject classes for each category (no overriding) Composition is a simple chain SyncProt NewP GuardProt

15 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200215 Restrictions on Association The protocol associated with a class must be equal to or derived from the protocol associated with its superclass  Every class includes all new behaviour applied to any superclass The protocol associated with an object must be equal to or derived from the protocol associated with its class  Every object includes all new behaviour applied to its class

16 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200216 Inheritance and Derivation Association is inherited (B) Inheritance can be overridden by explicit association (C) –P2 must be derived from P1 New behaviour cannot be inadvertantly omitted from subclasses CP2 AP1 Explicit association BP1 Inherited association

17 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200217 Implementation Interception mechanism is an extended JVM Prototype extends Sun JDK1.3 using the JIT Interface JIT Interface supports: –Close integration with the JVM –Insertion of hooks before the application loads –Interception of all class loading –Access to internal JVM data structures Interception is by dynamically changing invoker functions and altering bytecode

18 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200218 Performance No effect on classes and objects with no associated metaobject protocol No effect on non-intercepted operations Prototype: Overhead of 24 times for intercepted method invocation –Affects invocation only, not method execution –Performance of other dynamic architectures: 40 times for Guaraná and 70 times for PROSE

19 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200219 Conclusion The Iguana/J architecture supports: Dynamic insertion/removal of new behaviour Unanticipated change without source code Inheritance of new behaviour Strong separation Context sensitivity Reusable new behaviour

20 Supporting Unanticipated Dynamic Adaptation of Application Behaviour ECOOP 200220 Ireland for the World Cup!


Download ppt "Supporting Unanticipated Dynamic Adaptation of Application Behaviour Barry Redmond and Vinny Cahill Distributed Systems Group Trinity College, Dublin."

Similar presentations


Ads by Google