Your SlideShare is downloading. ×
0
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Runtime Bytecode Transformation for Smalltalk
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Runtime Bytecode Transformation for Smalltalk

657

Published on

Talk from ESUG 2005

Talk from ESUG 2005

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

  • Be the first to like this

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  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

×