Reflective Operations for Live Programming
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
Behind the Scene
- What is happening when we recompile a class?
- What are the reflective operations that take place?
A Typical Scenario
- Define one class
- Define some methods
- Create some instances
- Add an instance variable to the class
- Existing instances got mutated
- Continue working
Operations Supporting Interactive Coding
- Dynamic class (re)definition
- Method recompilation
- Transparent instance migration
- Collecting instances
- Switching pointers from old to new instances
Getting All Instances
Getting All Pointers to an Object
returns all objects that store a reference to anObject
Symmetric Pointer Swapping
- All the pointers to
anObject
point now to anotherObject
- And "the inverse" atomically
Symmetric Pointer Swapping
Asymmetric Pointer Swapping
Swap all the pointers from one object to the other (asymmetric)
Example: Asymmetric Pointer Swapping
Changing the Class of an Object
- Limited reflective feature
- Target class should have the same format as the original one
Essence of a Class
- A format i.e., a number of instance variables and types (named/indexed)
- A superclass
- A method dictionary
Class initialize
Instance Specific Behavior
Instance Specific Behavior
Anonymous Classes For Spying
Conclusion
- Reflection is a solid foundation for innovation and language extensibility
- Avoid using reflective operations in domain code
- Understand when you absolutely need reflection
/