Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Like this? Share it with your network


Runtime Bytecode Transformation for Smalltalk

Uploaded on

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

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

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 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