Runtime Bytecode
Transformation
for Smalltalk
Marcus Denker (University of Berne, Switzerland)
Stéphane Ducasse (Universit...
Motivation
• Runtime transformation needed for
• Adaptation of running systems
• Tracing / debugging
• New language featur...
ByteSurgeon
• Library for bytecode transformation in
Smalltalk
• Full flexibility of Smalltalk: Runtime
• Provides high-lev...
Why Bytecode?
• No need to change theVM
• No source needed
• Other languages possible
• Performance
Examples
Counts the number of Bytecodes:
	 InstrCounter reset.
	 Example instrument: [ :instr | InstrCounter increase ]
Co...
Transformations
Modification: inlining of code
	 insertBefore:, insertAfter:, replace:
	
	 (Example>>#aMethod) instrumentSe...
User-definedVariables
Concatenate strings:
	 (Example>>#aMethod) instrumentSend: [ :send |

 
 send insertAfter: ’Logger lo...
Metavariables
• Goal: extend a send with after logging
• Problem: How to access receiver and args?
• Solution: metavariabl...
Implementation
Code
Generator
Scanner/
Parser
source text bytecodeAST
IRTranslatorASTranslator
AST bytecodeIR
Scanner/
Par...
Examples
• MethodWrapper with ByteSurgeon
• 40 lines of code
• Slower on install (factor 6)
• Faster on execution (factor ...
Simple MOP
• Goal: Control instance variable access
• Code for a trace metaobject:
	 TraceMO>>instVarRead: name in: object...
MOP
MOP class >>install: mop on: aClass
	 | dict |
	 dict := Dictionary newFrom: #mo -> mop.
	 aClass instrumentInstVarAcc...
Benchmark
time factor
Bytesurgeon 4817 1
standard
compiler
9760 2.03
new compiler 33611 6.98
RecompilationVs. ByteSurgeon:
Future Work
• Improvements
• AST vs. Bytecode
• Applications of ByteSurgeon
• Geppetto MOP
• Omniscient Debugger
Upcoming SlideShare
Loading in...5
×

Runtime Bytecode Transformation for Smalltalk

303

Published on

Runtime Bytecode Transformation for Smalltalk, Marcus Denker, ESUG 2005, Brussels

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
303
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Runtime Bytecode Transformation for Smalltalk"

  1. 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. 2. Motivation • Runtime transformation needed for • Adaptation of running systems • Tracing / debugging • New language features (MOP, AOP)
  3. 3. ByteSurgeon • Library for bytecode transformation in Smalltalk • Full flexibility of Smalltalk: Runtime • Provides high-level API • For Squeak, but portable
  4. 4. Why Bytecode? • No need to change theVM • No source needed • Other languages possible • Performance
  5. 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. 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. 7. User-definedVariables 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. 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. 9. Implementation Code Generator Scanner/ Parser source text bytecodeAST IRTranslatorASTranslator AST bytecodeIR Scanner/ Parser source text Code Generator The Smalltalk Compiler: Backend of NewCompiler:
  10. 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. 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. 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. 13. Benchmark time factor Bytesurgeon 4817 1 standard compiler 9760 2.03 new compiler 33611 6.98 RecompilationVs. ByteSurgeon:
  14. 14. Future Work • Improvements • AST vs. Bytecode • Applications of ByteSurgeon • Geppetto MOP • Omniscient Debugger
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×