SlideShare a Scribd company logo
1 of 23
Download to read offline
Building run-time analysis tools by
 means of pluggable interpreters
Contents


    Introduction
    Method wrappers
    Interpreter
    Compatiblity issues
    Demo
    References
Introduction


  Need for tools
    Coverage
       Methods, blocks, arguments, variables
    Run-time typing information
    …
  Current tools
    Smalltalk reflection
    Low-level, hard to understand, operational
       Bytecodes, processes, ….
Introduction


  Smalltalk language
     Simple semantics
  Interpreter
     Declarative feel
     Easier to understand
     Selective
        Per method
        Embedded interpreter
Method wrappers


  Intercept method activations
    Smalltalk reflection
         Localized ‘tricks’
    Easy to extend
  Usage
    Before-after methods
    Build interaction diagrams
    ...
    Activate interpreter
Interpreter


  Recursive descent
    Abstract grammar
       Parse tree
    Eval method
  Smalltalk = run-time engine
    Garbage collection
    Primitives
       Include methods supporting interpreter implementation
    Unwinding stack
    ….
Abstract grammar


  Expression tree
  Expression ()
            Assignment ('variable' 'value')
            Code ('arguments' 'temporaries')
                      Block ('level')
                         Method ('mclass' 'selector')
            Literal ('value')
            MessageExpression ('receiver' 'selector' 'arguments’ ‘methodCache’)
            PseudoVariable ('isSuper')
            Return ('value')
            Variable ()
                      InstanceVariable ('index' 'class')
                      LocalVariable ('name' 'level' 'index')
                      SharedVariable ('binding')
Contexts


  Contexts
  CodeContext ()
            BlockContext ('outerContext' 'level')
            MethodContext ('receiver' 'method' 'returnHandler')



  Block closures
  BlockClosure ('block' 'outerContext')
Evaluation


  Method wrappers
  valueWithReceiver: anObject arguments: arrayOfObjects
            "Evaluate the method by invoking the interpreter.”

             ^ self methodExpression valueWithReceiver: anObject arguments: arrayOfObjects



  Method expressions
  valueWithReceiver: anObject arguments: arrayOfObjects
               ”Create a suitable context. Evaluate the method with given receiver and arguments
  in this context. Answer the result.”

             | context |

             context := self contextWithReceiver: anObject arguments: arrayOfObjects.
             ^ self valueInContext: context
Evaluation


  Method expressions
  contextWithReceiver: anObject arguments: arrayOfObjects
            ”Answer a context for evaluating the receiver. Install a return handler block.”

             ^ MethodContext on: self receiver: anObject arguments: arrayOfObjects
  returnHandler: [ :value | ^ value ]



  Method (Code) expressions
  valueInContext: aMethodContext
            ”Evaluate the statements for side effects. Answer the result of the last evaluation.”

             | answer |

             self statements do: [ :stat | answer := stat eval: aMethodContext ].
             ^ answer
Evaluation


  Literal expressions
  eval: aContext
            ”Answer the value.”

             ^ value



  Pseudo-variables (“self”, “super”)
  eval: aContext
            ”Answer the receiver.”

             ^ aContext receiver
Evaluation


  Shared variables
  eval: aContext
            ”Answer the value bound to the variable.”

             ^ binding value



  Shared variables
  bind: anObject context: aContext
            ”Bind the object to the variable.”

             binding value: anObject.
             ^ anObject
Evaluation


  Instance variables
  eval: aContext
            ”Answer the value bound to the variable.”

             ^ aContext receiver instVarAt: index



  Instance variables
  bind: anObject context: aContext
            ”Bind the object to the variable.”

             ^ aContext receiver instVarAt: index put: anObject
Evaluation


  Local variables
  eval: aContext
            ”Answer the value bound to the variable.”

             ^ (aContext contextAt: level) at: index



  Local variables
  bind: anObject context: aContext
            ”Bind the object to the variable.”

             ^ (aContext contextAt: level) at: index put: anObject
Evaluation


  Assignment expressions
  eval: aContext
            ”Bind the value to the variable. Answer the value.”

             ^ variable bind: (value eval: aContext) context: aContext



  Return expressions
  eval: aContext
             ”Evaluate the value expression. Return the answer as the return value of the
  method that ‘defines’ this return expression.”

             aContext returnHandler value: (value eval: aContext)
Evaluation


  Block expressions
  eval: aContext
            ”Build a block closure for this context. Answer the closure.”

             ^ BlockClosure block: self outerContext: aContext



  Executing block closures
  value
             ”Execute the block (closure) without arguments. Answer the result.”

            ^ block numTemps = 0
                          ifTrue: [ block valueInContext: outerContext ]
                          ifFalse: [ block valueInContext: (BlockContext outerContext:
  outerContext level: block level + 1 size: numTemps)]
Evaluation


  Wrapping block closures in ‘native’ closures
  asNativeBlockClosure
            ”Wrap the receiver in a native block closure. Note: this is self-modifying code.”

             | numArgs |

             (numArgs := block numArgs) = 0 ifTrue: [ ^ [ self value ]].
             numArgs = 1 ifTrue: [ ^ [ :arg1 | self value: arg1 ]].
             numArgs = 2 ifTrue: [ ^ [ :arg1 :arg2 | self value: arg1 value: arg2 ]].
             numArgs = 3 ifTrue: [ ^ [ :arg1 :arg2 :arg3 | self value: arg1 value: arg2 value: arg3 ]].
             numArgs = 4 ifTrue: [ ^ [ :arg1 :arg2 :arg3 :arg4 | | args |
                                                                  args := Array new: 4.
                                                                  args at: 1 put: arg1.
                                                                  args at: 2 put: arg2.
                                                                  args at: 3 put: arg3.
                                                                  args at: 4 put: arg4.
                                                                  self valueWithArguments: args ]].
             self generateUpTo: numArgs.
             ^ self asNativeBlockClosure
Evaluation


  Message expressions
  eval: aContext
            ”Evaluate receiver and arguments. Do the actual lookup and execute the method found.”
            | rcvr args behavior |

             rcvr := receiver eval: aContext .
             args := arguments collect: [ :arg | arg eval: aContext ].
             behavior := receiver isSuper
                                      ifTrue: [ aContext methodClass superclass ]
                                      ifFalse: [ rcvr class ].
             ^ self perform: selector receiver: rcvr arguments: args class: behavior
Evaluation


  Message expressions
  perform: sel receiver: rcvr arguments: args class: aBehavior
               ”Retrieve the method for given selector, starting the lookup in the class. Execute
  the method and return the result if successful. Otherwise fail with a #doesNotUnderstand:
  message. Note that executing a #perform: in the false branche instead of executing the
  method will acutally be faster. The lookup is only relevant in so far we are interested in keeping
  track of the different method invocations at the call site.”

              | method |

              ^ (method := self lookupMethod: sel in: aBehavior) isNil
                         ifTrue: [ rcvr doesNotUnderstand: (Message selector: sel arguments: args)]
                         ifFalse: [ method valueWithReceiver: rcvr arguments: args ]
Evaluation


  Message expressions
  lookupMethod: selector in: aClass
                   sel in: aBehavior
              ” Search for an appropriate method. First perform a lookup in the local cache.
  Upon failure do a regular lookup and cache the result.”

               ^ cache at: aClass ifAbsentPut: [ self basicLookupMethod: selector in: sel in: ]
                 methodCache at: aBehavior ifAbsentPut: [ self basicLookupMethod: aClass
  aBehavior]


  Message expressions
  basicLookupMethod: sel in: aBehavior
           "Search for a method in the class hierarchy. Answer nil upon failure."

               ^ (array := aBehavior findSelector: sel) isNil
                                       ifTrue: [ nil ]
                                       ifFalse: [ array at: 2 ]
Compatibility issues


  BlockClosure
    copied values, ...
  Pseudo-variables
    thisContext
  No saveguards
    Primitives
    ‘Kernel’ methods
Demo


  Tools
    Coverage tool
       Updating number of activations in #eval: methods
    Gathering run-time typing
       Remembering types in #eval: methods
           •  Variables
           •  Method invocations at call site

  Fine-grained
    Disjoint lexical occurrences of same variable
References

  Method wrappers
       http://st-www.cs.uiuc.edu/~brant

More Related Content

What's hot

Recommending Method Invocation Context Changes
Recommending Method Invocation Context ChangesRecommending Method Invocation Context Changes
Recommending Method Invocation Context ChangesBeat Fluri
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesEelco Visser
 
Variables: names, bindings, type, scope
Variables: names, bindings, type, scopeVariables: names, bindings, type, scope
Variables: names, bindings, type, scopesuthi
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserHoward Lewis Ship
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topicsRajesh Verma
 
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01Jérôme Rocheteau
 
Property Wrappers or how Swift decided to become Java
Property Wrappers or how Swift decided to become JavaProperty Wrappers or how Swift decided to become Java
Property Wrappers or how Swift decided to become JavaVincent Pradeilles
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in JavaMudit Gupta
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Agora Group
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1brecke
 

What's hot (16)

Recommending Method Invocation Context Changes
Recommending Method Invocation Context ChangesRecommending Method Invocation Context Changes
Recommending Method Invocation Context Changes
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and Scopes
 
Variables: names, bindings, type, scope
Variables: names, bindings, type, scopeVariables: names, bindings, type, scope
Variables: names, bindings, type, scope
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
perl_objects
perl_objectsperl_objects
perl_objects
 
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
How Green are Java Best Coding Practices? - GreenDays @ Rennes - 2014-07-01
 
Property Wrappers or how Swift decided to become Java
Property Wrappers or how Swift decided to become JavaProperty Wrappers or how Swift decided to become Java
Property Wrappers or how Swift decided to become Java
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in Java
 
Enumerable
EnumerableEnumerable
Enumerable
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1
 
Bililite range2
Bililite range2Bililite range2
Bililite range2
 
Lesson3
Lesson3Lesson3
Lesson3
 

Viewers also liked

Umlx
UmlxUmlx
UmlxESUG
 
Language-Independent Detection of Object-Oriented Design Patterns
Language-Independent Detection of Object-Oriented Design PatternsLanguage-Independent Detection of Object-Oriented Design Patterns
Language-Independent Detection of Object-Oriented Design PatternsESUG
 
Induced Intentional Software Views
Induced Intentional Software ViewsInduced Intentional Software Views
Induced Intentional Software ViewsESUG
 
Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Bryan O'Sullivan
 
QSOUL/Aop
QSOUL/AopQSOUL/Aop
QSOUL/AopESUG
 
OpenPonk modeling platform
OpenPonk modeling platformOpenPonk modeling platform
OpenPonk modeling platformESUG
 
Pragmas: Literal Messages as Powerful Method Annotations
Pragmas: Literal Messages as Powerful Method AnnotationsPragmas: Literal Messages as Powerful Method Annotations
Pragmas: Literal Messages as Powerful Method AnnotationsESUG
 
New Native Windows UI possibilities in Cincom Smalltalk ObjectStudio
New Native Windows UI possibilities in Cincom Smalltalk ObjectStudioNew Native Windows UI possibilities in Cincom Smalltalk ObjectStudio
New Native Windows UI possibilities in Cincom Smalltalk ObjectStudioESUG
 
The Object Repository - Pulling Objects out of the Ecosystem
The Object Repository - Pulling Objects out of the EcosystemThe Object Repository - Pulling Objects out of the Ecosystem
The Object Repository - Pulling Objects out of the EcosystemESUG
 

Viewers also liked (9)

Umlx
UmlxUmlx
Umlx
 
Language-Independent Detection of Object-Oriented Design Patterns
Language-Independent Detection of Object-Oriented Design PatternsLanguage-Independent Detection of Object-Oriented Design Patterns
Language-Independent Detection of Object-Oriented Design Patterns
 
Induced Intentional Software Views
Induced Intentional Software ViewsInduced Intentional Software Views
Induced Intentional Software Views
 
Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7
 
QSOUL/Aop
QSOUL/AopQSOUL/Aop
QSOUL/Aop
 
OpenPonk modeling platform
OpenPonk modeling platformOpenPonk modeling platform
OpenPonk modeling platform
 
Pragmas: Literal Messages as Powerful Method Annotations
Pragmas: Literal Messages as Powerful Method AnnotationsPragmas: Literal Messages as Powerful Method Annotations
Pragmas: Literal Messages as Powerful Method Annotations
 
New Native Windows UI possibilities in Cincom Smalltalk ObjectStudio
New Native Windows UI possibilities in Cincom Smalltalk ObjectStudioNew Native Windows UI possibilities in Cincom Smalltalk ObjectStudio
New Native Windows UI possibilities in Cincom Smalltalk ObjectStudio
 
The Object Repository - Pulling Objects out of the Ecosystem
The Object Repository - Pulling Objects out of the EcosystemThe Object Repository - Pulling Objects out of the Ecosystem
The Object Repository - Pulling Objects out of the Ecosystem
 

Similar to Runtime Tools

Introduction to ruby eval
Introduction to ruby evalIntroduction to ruby eval
Introduction to ruby evalNiranjan Sarade
 
Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksMarcus Denker
 
ScalaLanguage_ch_4_5.pptx
ScalaLanguage_ch_4_5.pptxScalaLanguage_ch_4_5.pptx
ScalaLanguage_ch_4_5.pptxjkapardhi
 
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
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 
First Class Variables as AST Annotations
 First Class Variables as AST Annotations First Class Variables as AST Annotations
First Class Variables as AST AnnotationsESUG
 
First Class Variables as AST Annotations
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST AnnotationsMarcus Denker
 
Static analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutesStatic analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutesAndrey Karpov
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0tutorialsruby
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0tutorialsruby
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming LanguageNicolò Calcavecchia
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With ScalaKnoldus Inc.
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkSerge Stinckwich
 
Collection advance
Collection advanceCollection advance
Collection advanceAakash Jain
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)Akshay soni
 
Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Marcus Denker
 
Introducing Pattern Matching in Scala
 Introducing Pattern Matching  in Scala Introducing Pattern Matching  in Scala
Introducing Pattern Matching in ScalaAyush Mishra
 

Similar to Runtime Tools (20)

Introduction to ruby eval
Introduction to ruby evalIntroduction to ruby eval
Introduction to ruby eval
 
Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinks
 
ScalaLanguage_ch_4_5.pptx
ScalaLanguage_ch_4_5.pptxScalaLanguage_ch_4_5.pptx
ScalaLanguage_ch_4_5.pptx
 
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
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
First Class Variables as AST Annotations
 First Class Variables as AST Annotations First Class Variables as AST Annotations
First Class Variables as AST Annotations
 
First Class Variables as AST Annotations
First Class Variables as AST AnnotationsFirst Class Variables as AST Annotations
First Class Variables as AST Annotations
 
About Python
About PythonAbout Python
About Python
 
Static analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutesStatic analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutes
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
 
Lesson3
Lesson3Lesson3
Lesson3
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With Scala
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source Smalltalk
 
Collection advance
Collection advanceCollection advance
Collection advance
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
 
Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"
 
Introducing Pattern Matching in Scala
 Introducing Pattern Matching  in Scala Introducing Pattern Matching  in Scala
Introducing Pattern Matching in Scala
 

More from ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in PharoESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector TuningESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FutureESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing ScoreESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsESUG
 

More from ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Recently uploaded

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
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...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

Runtime Tools

  • 1. Building run-time analysis tools by means of pluggable interpreters
  • 2. Contents   Introduction   Method wrappers   Interpreter   Compatiblity issues   Demo   References
  • 3. Introduction   Need for tools   Coverage   Methods, blocks, arguments, variables   Run-time typing information   …   Current tools   Smalltalk reflection   Low-level, hard to understand, operational   Bytecodes, processes, ….
  • 4. Introduction   Smalltalk language   Simple semantics   Interpreter   Declarative feel   Easier to understand   Selective   Per method   Embedded interpreter
  • 5. Method wrappers   Intercept method activations   Smalltalk reflection   Localized ‘tricks’   Easy to extend   Usage   Before-after methods   Build interaction diagrams   ...   Activate interpreter
  • 6. Interpreter   Recursive descent   Abstract grammar   Parse tree   Eval method   Smalltalk = run-time engine   Garbage collection   Primitives   Include methods supporting interpreter implementation   Unwinding stack   ….
  • 7. Abstract grammar   Expression tree Expression () Assignment ('variable' 'value') Code ('arguments' 'temporaries') Block ('level') Method ('mclass' 'selector') Literal ('value') MessageExpression ('receiver' 'selector' 'arguments’ ‘methodCache’) PseudoVariable ('isSuper') Return ('value') Variable () InstanceVariable ('index' 'class') LocalVariable ('name' 'level' 'index') SharedVariable ('binding')
  • 8. Contexts   Contexts CodeContext () BlockContext ('outerContext' 'level') MethodContext ('receiver' 'method' 'returnHandler')   Block closures BlockClosure ('block' 'outerContext')
  • 9. Evaluation   Method wrappers valueWithReceiver: anObject arguments: arrayOfObjects "Evaluate the method by invoking the interpreter.” ^ self methodExpression valueWithReceiver: anObject arguments: arrayOfObjects   Method expressions valueWithReceiver: anObject arguments: arrayOfObjects ”Create a suitable context. Evaluate the method with given receiver and arguments in this context. Answer the result.” | context | context := self contextWithReceiver: anObject arguments: arrayOfObjects. ^ self valueInContext: context
  • 10. Evaluation   Method expressions contextWithReceiver: anObject arguments: arrayOfObjects ”Answer a context for evaluating the receiver. Install a return handler block.” ^ MethodContext on: self receiver: anObject arguments: arrayOfObjects returnHandler: [ :value | ^ value ]   Method (Code) expressions valueInContext: aMethodContext ”Evaluate the statements for side effects. Answer the result of the last evaluation.” | answer | self statements do: [ :stat | answer := stat eval: aMethodContext ]. ^ answer
  • 11. Evaluation   Literal expressions eval: aContext ”Answer the value.” ^ value   Pseudo-variables (“self”, “super”) eval: aContext ”Answer the receiver.” ^ aContext receiver
  • 12. Evaluation   Shared variables eval: aContext ”Answer the value bound to the variable.” ^ binding value   Shared variables bind: anObject context: aContext ”Bind the object to the variable.” binding value: anObject. ^ anObject
  • 13. Evaluation   Instance variables eval: aContext ”Answer the value bound to the variable.” ^ aContext receiver instVarAt: index   Instance variables bind: anObject context: aContext ”Bind the object to the variable.” ^ aContext receiver instVarAt: index put: anObject
  • 14. Evaluation   Local variables eval: aContext ”Answer the value bound to the variable.” ^ (aContext contextAt: level) at: index   Local variables bind: anObject context: aContext ”Bind the object to the variable.” ^ (aContext contextAt: level) at: index put: anObject
  • 15. Evaluation   Assignment expressions eval: aContext ”Bind the value to the variable. Answer the value.” ^ variable bind: (value eval: aContext) context: aContext   Return expressions eval: aContext ”Evaluate the value expression. Return the answer as the return value of the method that ‘defines’ this return expression.” aContext returnHandler value: (value eval: aContext)
  • 16. Evaluation   Block expressions eval: aContext ”Build a block closure for this context. Answer the closure.” ^ BlockClosure block: self outerContext: aContext   Executing block closures value ”Execute the block (closure) without arguments. Answer the result.” ^ block numTemps = 0 ifTrue: [ block valueInContext: outerContext ] ifFalse: [ block valueInContext: (BlockContext outerContext: outerContext level: block level + 1 size: numTemps)]
  • 17. Evaluation   Wrapping block closures in ‘native’ closures asNativeBlockClosure ”Wrap the receiver in a native block closure. Note: this is self-modifying code.” | numArgs | (numArgs := block numArgs) = 0 ifTrue: [ ^ [ self value ]]. numArgs = 1 ifTrue: [ ^ [ :arg1 | self value: arg1 ]]. numArgs = 2 ifTrue: [ ^ [ :arg1 :arg2 | self value: arg1 value: arg2 ]]. numArgs = 3 ifTrue: [ ^ [ :arg1 :arg2 :arg3 | self value: arg1 value: arg2 value: arg3 ]]. numArgs = 4 ifTrue: [ ^ [ :arg1 :arg2 :arg3 :arg4 | | args | args := Array new: 4. args at: 1 put: arg1. args at: 2 put: arg2. args at: 3 put: arg3. args at: 4 put: arg4. self valueWithArguments: args ]]. self generateUpTo: numArgs. ^ self asNativeBlockClosure
  • 18. Evaluation   Message expressions eval: aContext ”Evaluate receiver and arguments. Do the actual lookup and execute the method found.” | rcvr args behavior | rcvr := receiver eval: aContext . args := arguments collect: [ :arg | arg eval: aContext ]. behavior := receiver isSuper ifTrue: [ aContext methodClass superclass ] ifFalse: [ rcvr class ]. ^ self perform: selector receiver: rcvr arguments: args class: behavior
  • 19. Evaluation   Message expressions perform: sel receiver: rcvr arguments: args class: aBehavior ”Retrieve the method for given selector, starting the lookup in the class. Execute the method and return the result if successful. Otherwise fail with a #doesNotUnderstand: message. Note that executing a #perform: in the false branche instead of executing the method will acutally be faster. The lookup is only relevant in so far we are interested in keeping track of the different method invocations at the call site.” | method | ^ (method := self lookupMethod: sel in: aBehavior) isNil ifTrue: [ rcvr doesNotUnderstand: (Message selector: sel arguments: args)] ifFalse: [ method valueWithReceiver: rcvr arguments: args ]
  • 20. Evaluation   Message expressions lookupMethod: selector in: aClass sel in: aBehavior ” Search for an appropriate method. First perform a lookup in the local cache. Upon failure do a regular lookup and cache the result.” ^ cache at: aClass ifAbsentPut: [ self basicLookupMethod: selector in: sel in: ] methodCache at: aBehavior ifAbsentPut: [ self basicLookupMethod: aClass aBehavior]   Message expressions basicLookupMethod: sel in: aBehavior "Search for a method in the class hierarchy. Answer nil upon failure." ^ (array := aBehavior findSelector: sel) isNil ifTrue: [ nil ] ifFalse: [ array at: 2 ]
  • 21. Compatibility issues   BlockClosure   copied values, ...   Pseudo-variables   thisContext   No saveguards   Primitives   ‘Kernel’ methods
  • 22. Demo   Tools   Coverage tool   Updating number of activations in #eval: methods   Gathering run-time typing   Remembering types in #eval: methods •  Variables •  Method invocations at call site   Fine-grained   Disjoint lexical occurrences of same variable
  • 23. References   Method wrappers   http://st-www.cs.uiuc.edu/~brant