SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
Part II: Reflection




  Marcus Denker
  denker@iam.unibe.ch

  Universität Bern




© Marcus Denker
Roadmap




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




© Marcus Denker                        X.
Roadmap




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




© Marcus Denker                        X.
Reflection



>    Reflection: computation about computation
     — Base level / meta level
     — Causally connected


>    Structural Reflection
     — Reification of structure

>    Behavioral Reflection
     — Reification of execution



© Marcus Denker                                 X.
Reflection in 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                                 X.
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 in
     Squeak
     — We should do better!


© Marcus Denker                                               X.
Roadmap




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




© Marcus Denker                        X.
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

>    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
From the last lecture...




© 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                        X.
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 metaobjects
     — Define Protocol between base and meta
                                                           metaobject
>    Goals
     — Highly selective reification   links                 activation
                                                           condition
     — Flexiblel metalevel 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
>    Metaobject:
     — 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 represenation
     — 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
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



>    Implement Context Oriented Programming (COP)




© 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                                                                                                 X.

Más contenido relacionado

La actualidad más candente

Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in PharoMarcus Denker
 
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5Marcus Denker
 
Architectural Patterns - Interactive and Event Handling Patterns
Architectural Patterns  - Interactive and Event Handling PatternsArchitectural Patterns  - Interactive and Event Handling Patterns
Architectural Patterns - Interactive and Event Handling Patternsassinha
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingsaykopatt
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and AkkaYung-Lin Ho
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaNexThoughts Technologies
 
Repository design pattern in laravel
Repository design pattern in laravelRepository design pattern in laravel
Repository design pattern in laravelSameer Poudel
 
Asynkron programmering i Visual Studio 11
Asynkron programmering i Visual Studio 11Asynkron programmering i Visual Studio 11
Asynkron programmering i Visual Studio 11MortenWennevik
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014Matthias Noback
 
Crafting high quality code
Crafting high quality code Crafting high quality code
Crafting high quality code Allan Mangune
 
Smalltalk in a .NET World
Smalltalk in a  .NET WorldSmalltalk in a  .NET World
Smalltalk in a .NET WorldESUG
 
Newspeak: Evolving Smalltalk for the Age of the Net
Newspeak: Evolving Smalltalk for the Age of the NetNewspeak: Evolving Smalltalk for the Age of the Net
Newspeak: Evolving Smalltalk for the Age of the NetESUG
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive ProgrammingAndres Almiray
 
Kubernetes at Telekom Austria Group
Kubernetes at Telekom Austria Group Kubernetes at Telekom Austria Group
Kubernetes at Telekom Austria Group Oliver Moser
 

La actualidad más candente (19)

Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5
 
Introduction to reactive programming
Introduction to reactive programmingIntroduction to reactive programming
Introduction to reactive programming
 
Java
Java Java
Java
 
Architectural Patterns - Interactive and Event Handling Patterns
Architectural Patterns  - Interactive and Event Handling PatternsArchitectural Patterns  - Interactive and Event Handling Patterns
Architectural Patterns - Interactive and Event Handling Patterns
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Java 8 concurrency abstractions
Java 8 concurrency abstractionsJava 8 concurrency abstractions
Java 8 concurrency abstractions
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
 
Repository design pattern in laravel
Repository design pattern in laravelRepository design pattern in laravel
Repository design pattern in laravel
 
Asynkron programmering i Visual Studio 11
Asynkron programmering i Visual Studio 11Asynkron programmering i Visual Studio 11
Asynkron programmering i Visual Studio 11
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014
 
Crafting high quality code
Crafting high quality code Crafting high quality code
Crafting high quality code
 
Smalltalk in a .NET World
Smalltalk in a  .NET WorldSmalltalk in a  .NET World
Smalltalk in a .NET World
 
Newspeak: Evolving Smalltalk for the Age of the Net
Newspeak: Evolving Smalltalk for the Age of the NetNewspeak: Evolving Smalltalk for the Age of the Net
Newspeak: Evolving Smalltalk for the Age of the Net
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 
Kubernetes at Telekom Austria Group
Kubernetes at Telekom Austria Group Kubernetes at Telekom Austria Group
Kubernetes at Telekom Austria Group
 

Destacado

A JIT as a System Service
A JIT as a System ServiceA JIT as a System Service
A JIT as a System ServiceMarcus Denker
 
Pharo: Objects at your Fingertips
Pharo: Objects at your FingertipsPharo: Objects at your Fingertips
Pharo: Objects at your FingertipsMarcus Denker
 
Fotografias Tomadas En El Tiempo Exacto
Fotografias Tomadas En El Tiempo ExactoFotografias Tomadas En El Tiempo Exacto
Fotografias Tomadas En El Tiempo Exactohagustigma
 
Talk: Pharo at JM2L 2009
Talk: Pharo at JM2L 2009Talk: Pharo at JM2L 2009
Talk: Pharo at JM2L 2009Marcus Denker
 
Pharo4: Plans and Dreams
Pharo4: Plans and DreamsPharo4: Plans and Dreams
Pharo4: Plans and DreamsMarcus Denker
 
Esug Lehrer Tag Squeak e.V
Esug Lehrer Tag Squeak e.VEsug Lehrer Tag Squeak e.V
Esug Lehrer Tag Squeak e.VMarcus Denker
 
Practical Object-Oriented Back-in-Time Debugging
Practical Object-Oriented Back-in-Time DebuggingPractical Object-Oriented Back-in-Time Debugging
Practical Object-Oriented Back-in-Time Debugginglienhard
 

Destacado (9)

A JIT as a System Service
A JIT as a System ServiceA JIT as a System Service
A JIT as a System Service
 
Pharo: Objects at your Fingertips
Pharo: Objects at your FingertipsPharo: Objects at your Fingertips
Pharo: Objects at your Fingertips
 
Fotografias Tomadas En El Tiempo Exacto
Fotografias Tomadas En El Tiempo ExactoFotografias Tomadas En El Tiempo Exacto
Fotografias Tomadas En El Tiempo Exacto
 
Talk: Pharo at JM2L 2009
Talk: Pharo at JM2L 2009Talk: Pharo at JM2L 2009
Talk: Pharo at JM2L 2009
 
Gmcase
GmcaseGmcase
Gmcase
 
Pharo4: Plans and Dreams
Pharo4: Plans and DreamsPharo4: Plans and Dreams
Pharo4: Plans and Dreams
 
Esug Lehrer Tag Squeak e.V
Esug Lehrer Tag Squeak e.VEsug Lehrer Tag Squeak e.V
Esug Lehrer Tag Squeak e.V
 
Pharo ESUG
Pharo ESUGPharo ESUG
Pharo ESUG
 
Practical Object-Oriented Back-in-Time Debugging
Practical Object-Oriented Back-in-Time DebuggingPractical Object-Oriented Back-in-Time Debugging
Practical Object-Oriented Back-in-Time Debugging
 

Similar a Reflection

Reflection and Context
Reflection and ContextReflection and Context
Reflection and ContextMarcus Denker
 
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
 
Sub-method Structural and Behavioral Reflection
Sub-method Structural and Behavioral ReflectionSub-method Structural and Behavioral Reflection
Sub-method Structural and Behavioral ReflectionMarcus Denker
 
Presentation about my Research
Presentation about my ResearchPresentation about my Research
Presentation about my ResearchMarcus Denker
 
The Reflectivity
The ReflectivityThe Reflectivity
The ReflectivityESUG
 
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
 
Performance and Scale: Billions of request per day (DDD2019)
Performance and Scale: Billions of request per day (DDD2019)Performance and Scale: Billions of request per day (DDD2019)
Performance and Scale: Billions of request per day (DDD2019)Marcel Dempers
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design PatternRothana Choun
 
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
 

Similar a Reflection (20)

Lecture: Reflection
Lecture: ReflectionLecture: Reflection
Lecture: Reflection
 
Lecture: Reflection
Lecture: ReflectionLecture: Reflection
Lecture: Reflection
 
Reflection and Context
Reflection and ContextReflection and Context
Reflection and Context
 
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
 
Refactoring
RefactoringRefactoring
Refactoring
 
Sub-method Structural and Behavioral Reflection
Sub-method Structural and Behavioral ReflectionSub-method Structural and Behavioral Reflection
Sub-method Structural and Behavioral Reflection
 
Presentation about my Research
Presentation about my ResearchPresentation about my Research
Presentation about my Research
 
The Reflectivity
The ReflectivityThe Reflectivity
The Reflectivity
 
Talk: Practical, Pluggable Types
Talk: Practical, Pluggable TypesTalk: Practical, Pluggable Types
Talk: Practical, Pluggable Types
 
Unstuck
UnstuckUnstuck
Unstuck
 
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
 
Performance and Scale: Billions of request per day (DDD2019)
Performance and Scale: Billions of request per day (DDD2019)Performance and Scale: Billions of request per day (DDD2019)
Performance and Scale: Billions of request per day (DDD2019)
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
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
 

Más de 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
 
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
 
Perfection & Feedback Loops or: why worse is better
Perfection & Feedback Loops or: why worse is betterPerfection & Feedback Loops or: why worse is better
Perfection & Feedback Loops or: why worse is betterMarcus Denker
 
How to Contribute to Pharo
How to Contribute to PharoHow to Contribute to Pharo
How to Contribute to PharoMarcus Denker
 

Más de 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
 
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
 
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
 
Perfection & Feedback Loops or: why worse is better
Perfection & Feedback Loops or: why worse is betterPerfection & Feedback Loops or: why worse is better
Perfection & Feedback Loops or: why worse is better
 
How to Contribute to Pharo
How to Contribute to PharoHow to Contribute to Pharo
How to Contribute to Pharo
 

Último

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Reflection

  • 1. Part II: Reflection Marcus Denker denker@iam.unibe.ch Universität Bern © Marcus Denker
  • 2. Roadmap > Introduction: Reflection in Squeak > I. Sub-Method Structural Reflection > II. Partial Behavioral Reflection © Marcus Denker X.
  • 3. Roadmap > Introduction: Reflection in Squeak > I. Sub-Method Structural Reflection > II. Partial Behavioral Reflection © Marcus Denker X.
  • 4. Reflection > Reflection: computation about computation — Base level / meta level — Causally connected > Structural Reflection — Reification of structure > Behavioral Reflection — Reification of execution © Marcus Denker X.
  • 5. Reflection in 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 X.
  • 6. 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 in Squeak — We should do better! © Marcus Denker X.
  • 7. Roadmap > Introduction: Reflection in Squeak > I. Sub-Method Structural Reflection > II. Partial Behavioral Reflection © Marcus Denker X.
  • 8. Structural Reflection > Structure modeled as objects — e.g. Classes, methods — Causally connected > Uses: — Development environments — Language extensions and experiments © Marcus Denker
  • 9. 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
  • 10. 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
  • 11. Existing Method Representations > Existing representations for Methods — Text — Bytecode — AST © Marcus Denker
  • 12. Requirements > Causal Connection > Abstraction Level > Extensibility > Persistency > Size and Performance © Marcus Denker
  • 13. Text > Low level abstraction — String of Characters > Not causally connected — Need to call compiler © Marcus Denker
  • 14. 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
  • 15. 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
  • 16. 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
  • 17. Persephone > Implementation of Reflective Methods for Squeak Smalltalk > 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
  • 18. Requirements revisited > Abstraction Level OK > Causal Connection OK > Extensibility OK > Persistency OK > Size and Performance OK © Marcus Denker
  • 19. From the last lecture... © Marcus Denker
  • 20. 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
  • 21. 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
  • 22. 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
  • 23. Roadmap > Introduction: Reflection in Squeak > I. Sub-Method Structural Reflection > II. Partial Behavioral Reflection © Marcus Denker X.
  • 24. 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
  • 25. 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
  • 26. Reflex: Partial Behavioral Reflection > Hooksets: collection of operation occurrences > Links — Bind hooksets to metaobjects — Define Protocol between base and meta metaobject > Goals — Highly selective reification links activation condition — Flexiblel metalevel engineering – Protocol specification hookset – Cross-cutting hooksets Tanter, OOPSLA03 © Marcus Denker
  • 27. Example: Profiler > Operation: — Method Execution (around) > Hookset: — All execution operations in a package metaobject > Metaobject: — A profiling tool links activation condition hookset © Marcus Denker
  • 28. 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
  • 29. Problems > Annotation performance — Decompile bytecode > Execution performance — Preambles for stack manipulation > Low-level represenation — ifTrue:ifFalse: — Blocks — Global variables © Marcus Denker
  • 30. Links as Annotations > Links can be annotations on the AST Method Meta Link © Marcus Denker
  • 31. 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
  • 32. Reflectivity > Prototype Implementation in Squeak — Sub-Method Structure — Partial Behavioral Reflection > Download: http:/scg.unibe.ch/Research/Reflectivity © Marcus Denker
  • 33. Whatʼs next... > Optimize Size of AST Representation — Simpler AST — AST Compression > Implement Context Oriented Programming (COP) © Marcus Denker
  • 34. 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 X.