SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
Runtime Bytecode
     Transformation
      for Smalltalk
 Marcus Denker (University of Berne, Switzerland)
Stéphane Ducasse (University of Berne, Switzerland)
         Éric Tanter (University of Chile)
Motivation

• Runtime transformation needed for
 • Adaptation of running systems
 • Tracing / debugging
 • New language features (MOP, AOP)
ByteSurgeon

• Library for bytecode transformation in
  Smalltalk
• Full flexibility of Smalltalk: Runtime
• Provides high-level API
• For Squeak, but portable
Why Bytecode?

• No need to change the VM
• No source needed
• Other languages possible
• Performance
Examples
Counts the number of Bytecodes:
	   InstrCounter reset.
	   Example instrument: [ :instr | InstrCounter increase ]

Counts the number of Sends:
	   InstrCounter reset.
	   Example instrumentSend: [ :instr | InstrCounter increase ]

Introspection:
	   (Example>>#aMethod) instrumentSend: [ :send |
	   	 	 	 	 	 Transcript show: send selector printString]
Transformations
Modification: inlining of code
    	 insertBefore:, insertAfter:, replace:
	
	    (Example>>#aMethod) instrumentSend: [ :send |

    
 
 send insertAfter: ’InstrCounter increase’]

	
	
	    (Example>>#aMethod) instrumentSend: [ :send |

    
 
 send insertAfter: ‘Transcript show:’, send selector printString].
User-defined Variables
    Concatenate strings:
	    (Example>>#aMethod) instrumentSend: [ :send |

    
 send insertAfter: ’Logger logSend:’ , send selector printString]


    Poor man’s quasi-quoting:

	    (Example>>#aMethod) instrumentSend: [ :send |

    
 send insertAfter: ’Logger logSend: <: #sel> ’]
	    	 	     using: { #sel -> send selector }
Metavariables
• Goal: extend a send with after logging
• Problem: How to access receiver and args?
• Solution: metavariables
 Example instrumentSend: [ :s |
 
 m insertAfter: ’Logger logSendTo: <meta: #receiver> ’
 ]

#receiver, #arguments, #argn, #result....
#value, #newvalue
Implementation
 The Smalltalk Compiler:

     source text                         AST                                   bytecode
                          Scanner/                             Code
                           Parser                             Generator




 Backend of NewCompiler:

source text                  AST                         IR                         bytecode
               Scanner/
                                     ASTranslator                    IRTranslator
                Parser
                                                    Code Generator
Examples
• MethodWrapper with ByteSurgeon
 • 40 lines of code
 • Slower on install (factor 6)
 • Faster on execution (factor 5.3)

• A very simple MOP (MetaObject Protocol)
Simple MOP
    • Goal: Control instance variable access
    • Code for a trace metaobject:
	    TraceMO>>instVarRead: name in: object
	    	 | val |
	    	 val := object instVarNamed: name.

    
 Transcript show: ’var read: ’, val printString; cr.

    
 ˆval.

	    TraceMO>>instVarStore: name in: object value: newVal

    
 Transcript show: ’var store: ’, newVal printString; cr.

    
 ˆobject instVarNamed: name put: newVal.
MOP
MOP class >>install: mop on: aClass
	 | dict |
	 dict := Dictionary newFrom: #mo -> mop.
	 aClass instrumentInstVarAccess: [:instr |
	 	 dict at: #name put: instr varname.
	 	 instr isRead

 
 
 ifTrue: [instr replace: ’<: #mo> instVarRead: <: #name> in: self’
	 	 	 	 	               using: dict ]

 
 
 ifFalse: [instr replace: ’<: #mo> instVarStore: <: #name>

 
 
 
 
 
 
 
 in: self value: <meta: #newvalue> ‘ using: dict]
	 ]


                A simple MOP in <10 lines
Benchmark
Recompilation Vs. ByteSurgeon:

                     time        factor
  Bytesurgeon        4817          1
  standard
                     9760        2.03
  compiler
  new compiler      33611        6.98
Future Work
• Improvements
 • AST vs. Bytecode
• Applications of ByteSurgeon
 • Geppetto MOP
 • Omniscient Debugger

Mais conteúdo relacionado

Mais procurados

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
 
End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
vfabro
 

Mais procurados (20)

Expand Your Testing with Virtual Services
Expand Your Testing with Virtual ServicesExpand Your Testing with Virtual Services
Expand Your Testing with Virtual Services
 
Ecma script
Ecma scriptEcma script
Ecma script
 
Python to scala
Python to scalaPython to scala
Python to scala
 
PyParis2017 / Tutorial transcript - Function-as-a-service : a pythonic perspe...
PyParis2017 / Tutorial transcript - Function-as-a-service : a pythonic perspe...PyParis2017 / Tutorial transcript - Function-as-a-service : a pythonic perspe...
PyParis2017 / Tutorial transcript - Function-as-a-service : a pythonic perspe...
 
Javascript internals
Javascript internalsJavascript internals
Javascript internals
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 
Async and Await on the Server
Async and Await on the ServerAsync and Await on the Server
Async and Await on the Server
 
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
 
Java fork join
Java fork joinJava fork join
Java fork join
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programming
 
Fork and join framework
Fork and join frameworkFork and join framework
Fork and join framework
 
Seattle useR Group - R + Scala
Seattle useR Group - R + ScalaSeattle useR Group - R + Scala
Seattle useR Group - R + Scala
 
Closures
ClosuresClosures
Closures
 
End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
 
Async/Await
Async/AwaitAsync/Await
Async/Await
 
Async-await best practices in 10 minutes
Async-await best practices in 10 minutesAsync-await best practices in 10 minutes
Async-await best practices in 10 minutes
 
Reduce dependency on Rx with Kotlin Coroutines
Reduce dependency on Rx with Kotlin CoroutinesReduce dependency on Rx with Kotlin Coroutines
Reduce dependency on Rx with Kotlin Coroutines
 
ReactPHP – reaktor jądrowy w PHP
ReactPHP – reaktor jądrowy w PHPReactPHP – reaktor jądrowy w PHP
ReactPHP – reaktor jądrowy w PHP
 
Threads
ThreadsThreads
Threads
 
Idiomatic Kotlin for Android
Idiomatic Kotlin for AndroidIdiomatic Kotlin for Android
Idiomatic Kotlin for Android
 

Destaque

Destaque (18)

Type Feedback for Bytecode Interpreters
Type Feedback for Bytecode InterpretersType Feedback for Bytecode Interpreters
Type Feedback for Bytecode Interpreters
 
Unanticipated Partial Behavioral Reflection
Unanticipated Partial Behavioral ReflectionUnanticipated Partial Behavioral Reflection
Unanticipated Partial Behavioral Reflection
 
Talk: The Present and Future of Pharo
Talk: The Present and Future of PharoTalk: The Present and Future of Pharo
Talk: The Present and Future of Pharo
 
A JIT as a System Service
A JIT as a System ServiceA JIT as a System Service
A JIT as a System Service
 
How to Contribute to Pharo
How to Contribute to PharoHow to Contribute to Pharo
How to Contribute to Pharo
 
Entwurf von Optimierungen für Squeak
Entwurf von Optimierungen für SqueakEntwurf von Optimierungen für Squeak
Entwurf von Optimierungen für Squeak
 
Beyond VI
Beyond VIBeyond VI
Beyond VI
 
Pharo. Next Steps.
Pharo. Next Steps.Pharo. Next Steps.
Pharo. Next Steps.
 
Pharo: A Reflective System
Pharo: A Reflective SystemPharo: A Reflective System
Pharo: A Reflective System
 
Pharo: Objects at your Fingertips
Pharo: Objects at your FingertipsPharo: Objects at your Fingertips
Pharo: Objects at your Fingertips
 
Squeak als agile Entwicklungsumgebung
Squeak als agile EntwicklungsumgebungSqueak als agile Entwicklungsumgebung
Squeak als agile Entwicklungsumgebung
 
Reflection and Context
Reflection and ContextReflection and Context
Reflection and Context
 
Lecture: Reflection
Lecture: ReflectionLecture: Reflection
Lecture: Reflection
 
RBuilder and ByteSurgeon
RBuilder and ByteSurgeonRBuilder and ByteSurgeon
RBuilder and ByteSurgeon
 
Beyond Text - Methods as Objects
Beyond Text - Methods as ObjectsBeyond Text - Methods as Objects
Beyond Text - Methods as Objects
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
 
What's new in Squeak 3.9
What's new in Squeak 3.9What's new in Squeak 3.9
What's new in Squeak 3.9
 
Squeak
SqueakSqueak
Squeak
 

Semelhante a Runtime Bytecode Transformation for Smalltalk

Semelhante a Runtime Bytecode Transformation for Smalltalk (20)

Working with Bytecode
Working with BytecodeWorking with Bytecode
Working with Bytecode
 
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5
 
Behavioral Reflection in Pharo
Behavioral Reflection in PharoBehavioral Reflection in Pharo
Behavioral Reflection in Pharo
 
Behavioral Reflection
Behavioral ReflectionBehavioral Reflection
Behavioral Reflection
 
Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"Lecture: "Advanced Reflection: MetaLinks"
Lecture: "Advanced Reflection: MetaLinks"
 
Lecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinksLecture. Advanced Reflection: MetaLinks
Lecture. Advanced Reflection: MetaLinks
 
#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity
 
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
 
Opal compiler
Opal compilerOpal compiler
Opal compiler
 
What the CRaC - Superfast JVM startup
What the CRaC - Superfast JVM startupWhat the CRaC - Superfast JVM startup
What the CRaC - Superfast JVM startup
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 
IronSmalltalk
IronSmalltalkIronSmalltalk
IronSmalltalk
 
Ice mini guide
Ice mini guideIce mini guide
Ice mini guide
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 
Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...Building Continuous Application with Structured Streaming and Real-Time Data ...
Building Continuous Application with Structured Streaming and Real-Time Data ...
 
Cs30 New
Cs30 NewCs30 New
Cs30 New
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Typesafe spark- Zalando meetup
Typesafe spark- Zalando meetupTypesafe spark- Zalando meetup
Typesafe spark- Zalando meetup
 
Modern C++
Modern C++Modern C++
Modern C++
 
Parallel and Async Programming With C#
Parallel and Async Programming With C#Parallel and Async Programming With C#
Parallel and Async Programming With C#
 

Mais de Marcus Denker

Mais 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
 
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
 
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
 
Lecture: MetaLinks
Lecture: MetaLinksLecture: MetaLinks
Lecture: MetaLinks
 
PharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to PharoPharoTechTalk: Contributing to Pharo
PharoTechTalk: Contributing to Pharo
 
Feedback Loops in Practice
Feedback Loops in PracticeFeedback Loops in Practice
Feedback Loops in Practice
 
Pharo6 - ESUG17
Pharo6 - ESUG17Pharo6 - ESUG17
Pharo6 - ESUG17
 
Pharo6
Pharo6Pharo6
Pharo6
 
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
 
Dynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection PromisesDynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection Promises
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 

Último

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
vu2urc
 

Último (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Runtime Bytecode Transformation for Smalltalk

  • 1. Runtime Bytecode Transformation for Smalltalk Marcus Denker (University of Berne, Switzerland) Stéphane Ducasse (University of Berne, Switzerland) Éric Tanter (University of Chile)
  • 2. Motivation • Runtime transformation needed for • Adaptation of running systems • Tracing / debugging • New language features (MOP, AOP)
  • 3. ByteSurgeon • Library for bytecode transformation in Smalltalk • Full flexibility of Smalltalk: Runtime • Provides high-level API • For Squeak, but portable
  • 4. Why Bytecode? • No need to change the VM • No source needed • Other languages possible • Performance
  • 5. Examples Counts the number of Bytecodes: InstrCounter reset. Example instrument: [ :instr | InstrCounter increase ] Counts the number of Sends: InstrCounter reset. Example instrumentSend: [ :instr | InstrCounter increase ] Introspection: (Example>>#aMethod) instrumentSend: [ :send | Transcript show: send selector printString]
  • 6. Transformations Modification: inlining of code insertBefore:, insertAfter:, replace: (Example>>#aMethod) instrumentSend: [ :send | send insertAfter: ’InstrCounter increase’] (Example>>#aMethod) instrumentSend: [ :send | send insertAfter: ‘Transcript show:’, send selector printString].
  • 7. User-defined Variables Concatenate strings: (Example>>#aMethod) instrumentSend: [ :send | send insertAfter: ’Logger logSend:’ , send selector printString] Poor man’s quasi-quoting: (Example>>#aMethod) instrumentSend: [ :send | send insertAfter: ’Logger logSend: <: #sel> ’] using: { #sel -> send selector }
  • 8. Metavariables • Goal: extend a send with after logging • Problem: How to access receiver and args? • Solution: metavariables Example instrumentSend: [ :s | m insertAfter: ’Logger logSendTo: <meta: #receiver> ’ ] #receiver, #arguments, #argn, #result.... #value, #newvalue
  • 9. Implementation The Smalltalk Compiler: source text AST bytecode Scanner/ Code Parser Generator Backend of NewCompiler: source text AST IR bytecode Scanner/ ASTranslator IRTranslator Parser Code Generator
  • 10. Examples • MethodWrapper with ByteSurgeon • 40 lines of code • Slower on install (factor 6) • Faster on execution (factor 5.3) • A very simple MOP (MetaObject Protocol)
  • 11. Simple MOP • Goal: Control instance variable access • Code for a trace metaobject: TraceMO>>instVarRead: name in: object | val | val := object instVarNamed: name. Transcript show: ’var read: ’, val printString; cr. ˆval. TraceMO>>instVarStore: name in: object value: newVal Transcript show: ’var store: ’, newVal printString; cr. ˆobject instVarNamed: name put: newVal.
  • 12. MOP MOP class >>install: mop on: aClass | dict | dict := Dictionary newFrom: #mo -> mop. aClass instrumentInstVarAccess: [:instr | dict at: #name put: instr varname. instr isRead ifTrue: [instr replace: ’<: #mo> instVarRead: <: #name> in: self’ using: dict ] ifFalse: [instr replace: ’<: #mo> instVarStore: <: #name> in: self value: <meta: #newvalue> ‘ using: dict] ] A simple MOP in <10 lines
  • 13. Benchmark Recompilation Vs. ByteSurgeon: time factor Bytesurgeon 4817 1 standard 9760 2.03 compiler new compiler 33611 6.98
  • 14. Future Work • Improvements • AST vs. Bytecode • Applications of ByteSurgeon • Geppetto MOP • Omniscient Debugger