SlideShare a Scribd company logo
1 of 41
Download to read offline
Reflection




  Marcus Denker
  denker@iam.unibe.ch

  Universität Bern




© Marcus Denker
Roadmap




> Introduction: Reflection
> I. Sub-Method Structural Reflection
> II. Partial Behavioral Reflection




© Marcus Denker
Roadmap




> Introduction: Reflection
> I. Sub-Method Structural Reflection
> II. Partial Behavioral Reflection




© Marcus Denker
System




Definition:

A computational system is a computer-based system
whose purpose is to answer questions and/or support
actions about some domain.
                  (P. Maes, “Concepts and Experiments in
                  Computational Reflection," Proceedings of OOPLA 87)




© Marcus Denker
Causally Connected




Definition:

A system is said to be causally connected to its domain if
the internal structures and the domain they represent are
linked in such a way that if one of them changes, this leads
to a corresponding effect of the other.



                                         (Patty Maes, OOPSLA 87)

© Marcus Denker
Reflective System




Definition:

A reflective system is a system which incorporates
causally connected structures representing (aspects of)
itself.

                                        (Patty Maes, OOPSLA 87)




© Marcus Denker
Introspection



>    Introspection
     — Self-representation can be queried

>    Intercession
     — Self-representation can be changed




           Reflection = Introspection + Intercession


© Marcus Denker
Structure and Behavior




>    Structural Reflection
     — Concerned with static structure
     — For example: packages, data-types, procedures

>    Behavioral Reflection
     — Concerned with execution
     — For example: procedure execution, assignment, variable read




© Marcus Denker
Tower of Interpreters



>    First studied for
     procedural languages

>    David A. Smith: 3Lisp        Interpreter at level 3

                                  Interpreter at level 2
>    Tower-of-Interpreters
                                  Interpreter at level 1

>    Theoretical. Slow!      User Program running a level 0




© Marcus Denker
Reflection and OOP


>    A good match: self-representation build of objects
     — Better then interpreter data-structures


>    Language-based reflection
     — Language entities represented as objects
     — Meta-objects describe behavior of base level objects

> Structure: classes/methods are objects
> Behavior: meta-objects define behavior
     — Example: meta-class defines method lookup


© Marcus Denker
Example: Java


>    Structural introspection
     — java.lang.reflect
     — Query a model of the program (classes, protocols)


>    Limited intercession
     — No change of classes

>    Limited behavioral reflection
     — Wrappers on objects
     — No way to intercept method calls, variable access


© Marcus Denker
Example: Squeak



>    Squeak has support for reflection

>    Structural reflection
     — Classes / methods are objects
     — Can be changed at runtime

>    Behavioral reflection
     — Current execution reified (thisContext)
     — #doesNotUnderstand / MethodWrappers



© Marcus Denker
Can we do better?


>    Structural Reflection stops at method level
     — Bytecode in the CompiledMethod: Numbers
     — Text: Just a String, needs to be compiled

>    Behavior hard coded in the Virtual Machine
     — Message Sending
     — Variable Access

>    Both structural and behavioral reflection is limited
     — We should do better!


© Marcus Denker
Roadmap




> Introduction: Reflection
> I. Sub-Method Structural Reflection
> II. Partial Behavioral Reflection




© Marcus Denker
Structural Reflection



>    Structure modeled as objects

     — e.g. Classes, methods
     — Causally connected

>    Uses:
     — Development environments
     — Language extensions and experiments




© Marcus Denker
Methods and Reflection



>    Method are Objects
     — e.g in Smalltalk


>    No high-level model for sub-method elements
     — Message sends
     — Assignments
     — Variable access


>    Structural reflection stops at the granularity of methods


© Marcus Denker
Sub-Method Reflection



>    Many tools work on sub method level
     — Profiler, Refactoring Tool, Debugger, Type Checker

>    Communication between tools needed
     — Example: Code coverage

>    All tools use different representations
     — Tools are harder to build
     — Communication not possible


© Marcus Denker
Existing Method Representations




>    Existing representations for Methods

     — Text

     — Bytecode

     — AST




© Marcus Denker
Requirements


>    Causal Connection

>    Abstraction Level

>    Extensibility

>    Persistency

>    Size and Performance


© Marcus Denker
Text




>    Low level abstraction
     — String of characters


>    Not causally connected
     — Need to call compiler




© Marcus Denker
Bytecode



>    Low level abstraction
     — Array of Integers


>    Missing extensibility
     — e.g. for tools

>    Mix of base- and meta-level code
     — Problems with synthesized code when changing code
     — Examples: AOP point-cut residues, reflection hooks



© Marcus Denker
Abstract Syntax Tree



>    Not causally connected
     — Need to call compiler


>    Not extensible
     — Fixed set of codes, no way to store meta data

>    Not persistent
     — Generated by compiler from text, never stored




© Marcus Denker
Solution: Reflective Methods


> Annotated, persistent AST
> Bytecode generated on demand and cached


    :ReflectiveMethod                                           :CompiledMethod
                     annotation               compiledMethod

                                                               #(12 13 45 38 98 128
                     annotation
                                  reflectiveMethod              84 72 42 77 22 28 59
                                                                 32 7 49 51 87 64)




             Tools                                                     VM



© Marcus Denker
Persephone



>    Implementation of Reflective Methods for Squeak

>    Smalltalk compiler generates Reflective Methods
     — Translated to bytecode on demand

>    Open Compiler: Plugins
     — Called before code generation
     — Transform a copy of the AST




© Marcus Denker
Requirements revisited


>    Abstraction Level OK

>    Causal Connection OK

>    Extensibility OK

>    Persistency OK

>    Size and Performance OK


© Marcus Denker
Annotations


>    Source visible annotations
     — extended Smalltalk syntax

                  (9 raisedTo: 10000) <:evaluateAtCompiletime:>

>    Source invisible annotations
     — Reflective API
     — Can reference any object

> Every node can be annotated
> Semantics: Compiler Plugins


© Marcus Denker
Example: Pluggable Type-System


>    Example for textual annotations


      bitFromBoolean: aBoolean <:type: Boolean :>
      ^ (aBoolean ifTrue: [1] ifFalse: [0]) <:type: Integer :>




> Optional, pluggable type-system
> Types stored as annotations in the Reflective Methods



© Marcus Denker
Memory




                            number of classes memory


     Squeak 3.9             2040             15.7 MB


     Persephone             2224             20 MB
     no reflective methods

     Persephone             2224             123 MB
     reflective methods


© Marcus Denker
Roadmap




> Introduction: Reflection in Squeak
> I. Sub-Method Structural Reflection
> II. Partial Behavioral Reflection




© Marcus Denker
Behavioral Reflection


>    Reflect on the execution
     — method execution
     — message sending, variable access

>    In Smalltalk
     — No model of execution below method body
     — message sending / variable access hard coded by VM
     — #doesNotUnderstand / MethodWrappers

>    Reflective capabilities of Smalltalk should be improved!


© Marcus Denker
MetaclassTalk


>    Extends the Smalltalk metaclass model
     — Similar to CLOS MOP


>    Metaclass defines
     — message lookup
     — access to instance variables

>    Problems:
     — Reflection only controllable at class boundaries
     — No fine-grained selection (e.g. single operations)
     — Protocol between base and meta level is fixed


© Marcus Denker
Reflex: Partial Behavioral Reflection


> Hooksets: collection of operation occurrences
> Links
     — Bind hooksets to meta-objects
     — Define protocol between base and meta
                                                           metaobject
>    Goals
     — Highly selective reification   links                 activation
                                                           condition
     — Flexible meta-level engineering
           –      Protocol specification                     hookset
           –      Cross-cutting hooksets

                                              Tanter, OOPSLA03
© Marcus Denker
Example: Profiler



>    Operation:
     — Method execution (around)


>    Hookset:
     — All execution operations in a package

                                               metaobject
>    Meta-object:
     — A profiling tool             links       activation
                                               condition

                                                hookset

© Marcus Denker
Reflex for Squeak




>    Partial Behavioral Reflection pioneered in Java
     — Code transformation at load time
     — Not unanticipated (itʼs Java...)



>    Geppetto: Partial Behavioral Reflection for Smalltalk
     — For Squeak 3.9 with Bytecode transformation




© Marcus Denker
Problems


>    Annotation performance
     — Decompile bytecode


>    Execution performance
     — Preambles for stack manipulation

>    Low-level representation
     — ifTrue:ifFalse:
     — Blocks
     — Global variables


© Marcus Denker
Links as Annotations

>    Links can be annotations on the AST

            Method
                                           Meta
                        Link




© Marcus Denker
Properties



>    Very fast annotations
     — No decompile!

>    On-the-fly code generation
     — Only code executed gets generated

>    Generated code is fast
     — Better then working on bytecode level




© Marcus Denker
Demo




>    Show Bounce Demo




© Marcus Denker
Reflectivity




>    Prototype implementation in Squeak

     — Sub-Method Structure
     — Partial Behavioral Reflection

>    Download:
    http:/scg.unibe.ch/Research/Reflectivity



© Marcus Denker
Whatʼs next...




>    Optimize Size of AST Representation
     — Simpler AST
     — AST Compression

>    Beyond Text
     — Store only AST (no text)
     — Build text from annotated AST




© Marcus Denker
License

>    http://creativecommons.org/licenses/by-sa/2.5/



                                           Attribution-ShareAlike 2.5
     You are free:
     • to copy, distribute, display, and perform the work
     • to make derivative works
     • to make commercial use of the work

     Under the following conditions:

              Attribution. You must attribute the work in the manner specified by the author or licensor.

     
              Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting
              work only under a license identical to this one.

     • For any reuse or distribution, you must make clear to others the license terms of this work.
     • Any of these conditions can be waived if you get permission from the copyright holder.

                     Your fair use and other rights are in no way affected by the above.
© Marcus Denker

More Related Content

What's hot

Performance evaluation of larger matrices over cluster of four nodes using mpi
Performance evaluation of larger matrices over cluster of four nodes using mpiPerformance evaluation of larger matrices over cluster of four nodes using mpi
Performance evaluation of larger matrices over cluster of four nodes using mpieSAT Journals
 
dos mutual exclusion algos
dos mutual exclusion algosdos mutual exclusion algos
dos mutual exclusion algosAkhil Sharma
 
Ch4 OS
Ch4 OSCh4 OS
Ch4 OSC.U
 
An Overview of Distributed Debugging
An Overview of Distributed DebuggingAn Overview of Distributed Debugging
An Overview of Distributed DebuggingAnant Narayanan
 
resource management
  resource management  resource management
resource managementAshish Kumar
 
Error tolerant resource allocation and payment minimization for cloud system
Error tolerant resource allocation and payment minimization for cloud systemError tolerant resource allocation and payment minimization for cloud system
Error tolerant resource allocation and payment minimization for cloud systemIEEEFINALYEARPROJECTS
 
DOTNET 2013 IEEE CLOUDCOMPUTING PROJECT Error tolerant resource allocation an...
DOTNET 2013 IEEE CLOUDCOMPUTING PROJECT Error tolerant resource allocation an...DOTNET 2013 IEEE CLOUDCOMPUTING PROJECT Error tolerant resource allocation an...
DOTNET 2013 IEEE CLOUDCOMPUTING PROJECT Error tolerant resource allocation an...IEEEGLOBALSOFTTECHNOLOGIES
 
Final jaypaper linux
Final jaypaper linuxFinal jaypaper linux
Final jaypaper linuxjaya380
 
(Slides) Task scheduling algorithm for multicore processor system for minimiz...
(Slides) Task scheduling algorithm for multicore processor system for minimiz...(Slides) Task scheduling algorithm for multicore processor system for minimiz...
(Slides) Task scheduling algorithm for multicore processor system for minimiz...Naoki Shibata
 
Resource Management for Computer Operating Systems
Resource Management for Computer Operating SystemsResource Management for Computer Operating Systems
Resource Management for Computer Operating Systemsinside-BigData.com
 
Lec 4 (program and network properties)
Lec 4 (program and network properties)Lec 4 (program and network properties)
Lec 4 (program and network properties)Sudarshan Mondal
 
System Structure for Dependable Software Systems
System Structure for Dependable Software SystemsSystem Structure for Dependable Software Systems
System Structure for Dependable Software SystemsVincenzo De Florio
 
Computer Network Performance evaluation based on Network scalability using OM...
Computer Network Performance evaluation based on Network scalability using OM...Computer Network Performance evaluation based on Network scalability using OM...
Computer Network Performance evaluation based on Network scalability using OM...Jaipal Dhobale
 

What's hot (20)

Ch4
Ch4Ch4
Ch4
 
Performance evaluation of larger matrices over cluster of four nodes using mpi
Performance evaluation of larger matrices over cluster of four nodes using mpiPerformance evaluation of larger matrices over cluster of four nodes using mpi
Performance evaluation of larger matrices over cluster of four nodes using mpi
 
dos mutual exclusion algos
dos mutual exclusion algosdos mutual exclusion algos
dos mutual exclusion algos
 
OS_Ch4
OS_Ch4OS_Ch4
OS_Ch4
 
Ch4 OS
Ch4 OSCh4 OS
Ch4 OS
 
Process
ProcessProcess
Process
 
An Overview of Distributed Debugging
An Overview of Distributed DebuggingAn Overview of Distributed Debugging
An Overview of Distributed Debugging
 
resource management
  resource management  resource management
resource management
 
Error tolerant resource allocation and payment minimization for cloud system
Error tolerant resource allocation and payment minimization for cloud systemError tolerant resource allocation and payment minimization for cloud system
Error tolerant resource allocation and payment minimization for cloud system
 
DOTNET 2013 IEEE CLOUDCOMPUTING PROJECT Error tolerant resource allocation an...
DOTNET 2013 IEEE CLOUDCOMPUTING PROJECT Error tolerant resource allocation an...DOTNET 2013 IEEE CLOUDCOMPUTING PROJECT Error tolerant resource allocation an...
DOTNET 2013 IEEE CLOUDCOMPUTING PROJECT Error tolerant resource allocation an...
 
5. Distributed Operating Systems
5. Distributed Operating Systems5. Distributed Operating Systems
5. Distributed Operating Systems
 
Final jaypaper linux
Final jaypaper linuxFinal jaypaper linux
Final jaypaper linux
 
(Slides) Task scheduling algorithm for multicore processor system for minimiz...
(Slides) Task scheduling algorithm for multicore processor system for minimiz...(Slides) Task scheduling algorithm for multicore processor system for minimiz...
(Slides) Task scheduling algorithm for multicore processor system for minimiz...
 
Resource Management for Computer Operating Systems
Resource Management for Computer Operating SystemsResource Management for Computer Operating Systems
Resource Management for Computer Operating Systems
 
Resource management
Resource managementResource management
Resource management
 
CS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMSCS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMS
 
Lec 4 (program and network properties)
Lec 4 (program and network properties)Lec 4 (program and network properties)
Lec 4 (program and network properties)
 
System Structure for Dependable Software Systems
System Structure for Dependable Software SystemsSystem Structure for Dependable Software Systems
System Structure for Dependable Software Systems
 
Computer Network Performance evaluation based on Network scalability using OM...
Computer Network Performance evaluation based on Network scalability using OM...Computer Network Performance evaluation based on Network scalability using OM...
Computer Network Performance evaluation based on Network scalability using OM...
 
10. resource management
10. resource management10. resource management
10. resource management
 

Similar to Reflection in Smalltalk: Structural and Behavioral Concepts

Beyond Text - Methods as Objects
Beyond Text - Methods as ObjectsBeyond Text - Methods as Objects
Beyond Text - Methods as ObjectsMarcus Denker
 
Unanticipated Partial Behavioral Reflection
Unanticipated Partial Behavioral ReflectionUnanticipated Partial Behavioral Reflection
Unanticipated Partial Behavioral ReflectionESUG
 
Unanticipated Partial Behavioral Reflection
Unanticipated Partial Behavioral ReflectionUnanticipated Partial Behavioral Reflection
Unanticipated Partial Behavioral ReflectionMarcus Denker
 
Sub-Method Reflection
Sub-Method ReflectionSub-Method Reflection
Sub-Method ReflectionMarcus Denker
 
The Reflectivity
The ReflectivityThe Reflectivity
The ReflectivityESUG
 
Presentation about my Research
Presentation about my ResearchPresentation about my Research
Presentation about my ResearchMarcus Denker
 
Talk: Practical, Pluggable Types
Talk: Practical, Pluggable TypesTalk: Practical, Pluggable Types
Talk: Practical, Pluggable TypesMarcus Denker
 
Software Evolution from the Field: an Experience Report
Software Evolution from the Field: an Experience ReportSoftware Evolution from the Field: an Experience Report
Software Evolution from the Field: an Experience ReportMarcus Denker
 
Behavioral Reflection
Behavioral ReflectionBehavioral Reflection
Behavioral ReflectionMarcus Denker
 
The meta of Meta-object Architectures
The meta of Meta-object ArchitecturesThe meta of Meta-object Architectures
The meta of Meta-object ArchitecturesMarcus Denker
 
Crafted Design - GeeCON 2014
Crafted Design - GeeCON 2014Crafted Design - GeeCON 2014
Crafted Design - GeeCON 2014Sandro Mancuso
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCAndy Butland
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design PatternRothana Choun
 
Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"LogeekNightUkraine
 

Similar to Reflection in Smalltalk: Structural and Behavioral Concepts (20)

Reflection
ReflectionReflection
Reflection
 
Reflectivity Demo
Reflectivity DemoReflectivity Demo
Reflectivity Demo
 
Beyond Text - Methods as Objects
Beyond Text - Methods as ObjectsBeyond Text - Methods as Objects
Beyond Text - Methods as Objects
 
Unanticipated Partial Behavioral Reflection
Unanticipated Partial Behavioral ReflectionUnanticipated Partial Behavioral Reflection
Unanticipated Partial Behavioral Reflection
 
Unanticipated Partial Behavioral Reflection
Unanticipated Partial Behavioral ReflectionUnanticipated Partial Behavioral Reflection
Unanticipated Partial Behavioral Reflection
 
Sub-Method Reflection
Sub-Method ReflectionSub-Method Reflection
Sub-Method Reflection
 
Demo: Reflectivity
Demo: ReflectivityDemo: Reflectivity
Demo: Reflectivity
 
The Reflectivity
The ReflectivityThe Reflectivity
The Reflectivity
 
Presentation about my Research
Presentation about my ResearchPresentation about my Research
Presentation about my Research
 
Unstuck
UnstuckUnstuck
Unstuck
 
Talk: Practical, Pluggable Types
Talk: Practical, Pluggable TypesTalk: Practical, Pluggable Types
Talk: Practical, Pluggable Types
 
Software Evolution from the Field: an Experience Report
Software Evolution from the Field: an Experience ReportSoftware Evolution from the Field: an Experience Report
Software Evolution from the Field: an Experience Report
 
Behavioral Reflection
Behavioral ReflectionBehavioral Reflection
Behavioral Reflection
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
The meta of Meta-object Architectures
The meta of Meta-object ArchitecturesThe meta of Meta-object Architectures
The meta of Meta-object Architectures
 
Crafted Design - GeeCON 2014
Crafted Design - GeeCON 2014Crafted Design - GeeCON 2014
Crafted Design - GeeCON 2014
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
10 reflection
10 reflection10 reflection
10 reflection
 
Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"
 

More from Marcus Denker

ConstantBlocks in Pharo11
ConstantBlocks in Pharo11ConstantBlocks in Pharo11
ConstantBlocks in Pharo11Marcus Denker
 
First Class Variables as AST Annotations
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST AnnotationsMarcus Denker
 
Supporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo SupportSupporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo SupportMarcus Denker
 
Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Marcus Denker
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerMarcus Denker
 
Lecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinksLecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinksMarcus Denker
 
Improving code completion for Pharo
Improving code completion for PharoImproving code completion for Pharo
Improving code completion for PharoMarcus Denker
 
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksVUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksMarcus Denker
 
Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksMarcus Denker
 
Open-Source: An Infinite Game
Open-Source: An Infinite GameOpen-Source: An Infinite Game
Open-Source: An Infinite GameMarcus Denker
 
PharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to PharoPharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to PharoMarcus Denker
 
Feedback Loops in Practice
Feedback Loops in PracticeFeedback Loops in Practice
Feedback Loops in PracticeMarcus Denker
 

More from Marcus Denker (20)

Soil And Pharo
Soil And PharoSoil And Pharo
Soil And Pharo
 
ConstantBlocks in Pharo11
ConstantBlocks in Pharo11ConstantBlocks in Pharo11
ConstantBlocks in Pharo11
 
Demo: Improved DoIt
Demo: Improved DoItDemo: Improved DoIt
Demo: Improved DoIt
 
First Class Variables as AST Annotations
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST Annotations
 
Supporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo SupportSupporting Pharo / Getting Pharo Support
Supporting Pharo / Getting Pharo Support
 
Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Variables in Pharo
Variables in PharoVariables in Pharo
Variables in Pharo
 
Lecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinksLecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinks
 
Improving code completion for Pharo
Improving code completion for PharoImproving code completion for Pharo
Improving code completion for Pharo
 
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksVUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
 
Slot Composition
Slot CompositionSlot Composition
Slot Composition
 
Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinks
 
PHARO IOT
PHARO IOTPHARO IOT
PHARO IOT
 
Open-Source: An Infinite Game
Open-Source: An Infinite GameOpen-Source: An Infinite Game
Open-Source: An Infinite Game
 
Lecture: MetaLinks
Lecture: MetaLinksLecture: MetaLinks
Lecture: MetaLinks
 
PharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to PharoPharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to Pharo
 
Feedback Loops in Practice
Feedback Loops in PracticeFeedback Loops in Practice
Feedback Loops in Practice
 
Pharo6 - ESUG17
Pharo6 - ESUG17Pharo6 - ESUG17
Pharo6 - ESUG17
 
Pharo6
Pharo6Pharo6
Pharo6
 

Recently uploaded

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

Reflection in Smalltalk: Structural and Behavioral Concepts

  • 1. Reflection Marcus Denker denker@iam.unibe.ch Universität Bern © Marcus Denker
  • 2. Roadmap > Introduction: Reflection > I. Sub-Method Structural Reflection > II. Partial Behavioral Reflection © Marcus Denker
  • 3. Roadmap > Introduction: Reflection > I. Sub-Method Structural Reflection > II. Partial Behavioral Reflection © Marcus Denker
  • 4. System Definition: A computational system is a computer-based system whose purpose is to answer questions and/or support actions about some domain. (P. Maes, “Concepts and Experiments in Computational Reflection," Proceedings of OOPLA 87) © Marcus Denker
  • 5. Causally Connected Definition: A system is said to be causally connected to its domain if the internal structures and the domain they represent are linked in such a way that if one of them changes, this leads to a corresponding effect of the other. (Patty Maes, OOPSLA 87) © Marcus Denker
  • 6. Reflective System Definition: A reflective system is a system which incorporates causally connected structures representing (aspects of) itself. (Patty Maes, OOPSLA 87) © Marcus Denker
  • 7. Introspection > Introspection — Self-representation can be queried > Intercession — Self-representation can be changed Reflection = Introspection + Intercession © Marcus Denker
  • 8. Structure and Behavior > Structural Reflection — Concerned with static structure — For example: packages, data-types, procedures > Behavioral Reflection — Concerned with execution — For example: procedure execution, assignment, variable read © Marcus Denker
  • 9. Tower of Interpreters > First studied for procedural languages > David A. Smith: 3Lisp Interpreter at level 3 Interpreter at level 2 > Tower-of-Interpreters Interpreter at level 1 > Theoretical. Slow! User Program running a level 0 © Marcus Denker
  • 10. Reflection and OOP > A good match: self-representation build of objects — Better then interpreter data-structures > Language-based reflection — Language entities represented as objects — Meta-objects describe behavior of base level objects > Structure: classes/methods are objects > Behavior: meta-objects define behavior — Example: meta-class defines method lookup © Marcus Denker
  • 11. Example: Java > Structural introspection — java.lang.reflect — Query a model of the program (classes, protocols) > Limited intercession — No change of classes > Limited behavioral reflection — Wrappers on objects — No way to intercept method calls, variable access © Marcus Denker
  • 12. Example: Squeak > Squeak has support for reflection > Structural reflection — Classes / methods are objects — Can be changed at runtime > Behavioral reflection — Current execution reified (thisContext) — #doesNotUnderstand / MethodWrappers © Marcus Denker
  • 13. Can we do better? > Structural Reflection stops at method level — Bytecode in the CompiledMethod: Numbers — Text: Just a String, needs to be compiled > Behavior hard coded in the Virtual Machine — Message Sending — Variable Access > Both structural and behavioral reflection is limited — We should do better! © Marcus Denker
  • 14. Roadmap > Introduction: Reflection > I. Sub-Method Structural Reflection > II. Partial Behavioral Reflection © Marcus Denker
  • 15. Structural Reflection > Structure modeled as objects — e.g. Classes, methods — Causally connected > Uses: — Development environments — Language extensions and experiments © Marcus Denker
  • 16. Methods and Reflection > Method are Objects — e.g in Smalltalk > No high-level model for sub-method elements — Message sends — Assignments — Variable access > Structural reflection stops at the granularity of methods © Marcus Denker
  • 17. Sub-Method Reflection > Many tools work on sub method level — Profiler, Refactoring Tool, Debugger, Type Checker > Communication between tools needed — Example: Code coverage > All tools use different representations — Tools are harder to build — Communication not possible © Marcus Denker
  • 18. Existing Method Representations > Existing representations for Methods — Text — Bytecode — AST © Marcus Denker
  • 19. Requirements > Causal Connection > Abstraction Level > Extensibility > Persistency > Size and Performance © Marcus Denker
  • 20. Text > Low level abstraction — String of characters > Not causally connected — Need to call compiler © Marcus Denker
  • 21. Bytecode > Low level abstraction — Array of Integers > Missing extensibility — e.g. for tools > Mix of base- and meta-level code — Problems with synthesized code when changing code — Examples: AOP point-cut residues, reflection hooks © Marcus Denker
  • 22. Abstract Syntax Tree > Not causally connected — Need to call compiler > Not extensible — Fixed set of codes, no way to store meta data > Not persistent — Generated by compiler from text, never stored © Marcus Denker
  • 23. Solution: Reflective Methods > Annotated, persistent AST > Bytecode generated on demand and cached :ReflectiveMethod :CompiledMethod annotation compiledMethod #(12 13 45 38 98 128 annotation reflectiveMethod 84 72 42 77 22 28 59 32 7 49 51 87 64) Tools VM © Marcus Denker
  • 24. Persephone > Implementation of Reflective Methods for Squeak > Smalltalk compiler generates Reflective Methods — Translated to bytecode on demand > Open Compiler: Plugins — Called before code generation — Transform a copy of the AST © Marcus Denker
  • 25. Requirements revisited > Abstraction Level OK > Causal Connection OK > Extensibility OK > Persistency OK > Size and Performance OK © Marcus Denker
  • 26. Annotations > Source visible annotations — extended Smalltalk syntax (9 raisedTo: 10000) <:evaluateAtCompiletime:> > Source invisible annotations — Reflective API — Can reference any object > Every node can be annotated > Semantics: Compiler Plugins © Marcus Denker
  • 27. Example: Pluggable Type-System > Example for textual annotations bitFromBoolean: aBoolean <:type: Boolean :> ^ (aBoolean ifTrue: [1] ifFalse: [0]) <:type: Integer :> > Optional, pluggable type-system > Types stored as annotations in the Reflective Methods © Marcus Denker
  • 28. Memory number of classes memory Squeak 3.9 2040 15.7 MB Persephone 2224 20 MB no reflective methods Persephone 2224 123 MB reflective methods © Marcus Denker
  • 29. Roadmap > Introduction: Reflection in Squeak > I. Sub-Method Structural Reflection > II. Partial Behavioral Reflection © Marcus Denker
  • 30. Behavioral Reflection > Reflect on the execution — method execution — message sending, variable access > In Smalltalk — No model of execution below method body — message sending / variable access hard coded by VM — #doesNotUnderstand / MethodWrappers > Reflective capabilities of Smalltalk should be improved! © Marcus Denker
  • 31. MetaclassTalk > Extends the Smalltalk metaclass model — Similar to CLOS MOP > Metaclass defines — message lookup — access to instance variables > Problems: — Reflection only controllable at class boundaries — No fine-grained selection (e.g. single operations) — Protocol between base and meta level is fixed © Marcus Denker
  • 32. Reflex: Partial Behavioral Reflection > Hooksets: collection of operation occurrences > Links — Bind hooksets to meta-objects — Define protocol between base and meta metaobject > Goals — Highly selective reification links activation condition — Flexible meta-level engineering – Protocol specification hookset – Cross-cutting hooksets Tanter, OOPSLA03 © Marcus Denker
  • 33. Example: Profiler > Operation: — Method execution (around) > Hookset: — All execution operations in a package metaobject > Meta-object: — A profiling tool links activation condition hookset © Marcus Denker
  • 34. Reflex for Squeak > Partial Behavioral Reflection pioneered in Java — Code transformation at load time — Not unanticipated (itʼs Java...) > Geppetto: Partial Behavioral Reflection for Smalltalk — For Squeak 3.9 with Bytecode transformation © Marcus Denker
  • 35. Problems > Annotation performance — Decompile bytecode > Execution performance — Preambles for stack manipulation > Low-level representation — ifTrue:ifFalse: — Blocks — Global variables © Marcus Denker
  • 36. Links as Annotations > Links can be annotations on the AST Method Meta Link © Marcus Denker
  • 37. Properties > Very fast annotations — No decompile! > On-the-fly code generation — Only code executed gets generated > Generated code is fast — Better then working on bytecode level © Marcus Denker
  • 38. Demo > Show Bounce Demo © Marcus Denker
  • 39. Reflectivity > Prototype implementation in Squeak — Sub-Method Structure — Partial Behavioral Reflection > Download: http:/scg.unibe.ch/Research/Reflectivity © Marcus Denker
  • 40. Whatʼs next... > Optimize Size of AST Representation — Simpler AST — AST Compression > Beyond Text — Store only AST (no text) — Build text from annotated AST © Marcus Denker
  • 41. License > http://creativecommons.org/licenses/by-sa/2.5/ Attribution-ShareAlike 2.5 You are free: • to copy, distribute, display, and perform the work • to make derivative works • to make commercial use of the work Under the following conditions: Attribution. You must attribute the work in the manner specified by the author or licensor. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. • For any reuse or distribution, you must make clear to others the license terms of this work. • Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above. © Marcus Denker