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 Changes
Beat 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 Scopes
Eelco Visser
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
Agora Group
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1
brecke
 

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

Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7
Bryan O'Sullivan
 
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
ESUG
 
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
ESUG
 
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
ESUG
 

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

Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
shinolajla
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
tutorialsruby
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
tutorialsruby
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
Phúc Đỗ
 
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
Serge Stinckwich
 

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 programming
ESUG
 
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
ESUG
 
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 results
ESUG
 
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
ESUG
 
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
ESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
ESUG
 
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
ESUG
 
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
ESUG
 
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
ESUG
 
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
ESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
ESUG
 
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
ESUG
 

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

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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 New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

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