Sub-method Structural and Behavioral Reflection

846 views

Published on

University of Berne. PhD Defense: "Sub-method Structural and Behavioral Reflection", 26.05.2008

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

  • Be the first to like this

No Downloads
Views
Total views
846
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sub-method Structural and Behavioral Reflection

  1. 1. © Marcus Denker Sub-method Structural and Behavioral Reflection Marcus Denker Universität Bern
  2. 2. © Marcus Denker The Systems of the future... > ... are getting larger and more complex > ... are getting more and more dependent on each other > The demands are changing 2
  3. 3. © Marcus Denker Examples of New Demands > Dynamic Analysis — Fine-grained selection — Install / retract at runtime — Complete system > Development Environment — Complete representation of the system — Extensible 3
  4. 4. © Marcus Denker Reflection 4
  5. 5. © Marcus Denker Reflection 5 Program Description
  6. 6. © Marcus Denker Reflection 6 Program Description Query and Change
  7. 7. © Marcus Denker Repeat: Demands > Dynamic Analysis — Fine-grained Selection — Install / retract at runtime — Complete System > Development Environment — Complete representation of the system — Extensible 7
  8. 8. © Marcus Denker Reflection to the Rescue > Where? > At runtime! > Complete Structure > Everywhere! 8
  9. 9. © Marcus Denker Reflection to the Rescue > Where? > At runtime! > Complete structure > Everywhere! 9 Solved (Partial Behavioral Reflection, Eric Tanter)
  10. 10. © Marcus Denker Three Problems of Reflection 1. Partial behavioral reflection needs to be anticipated 2. Structural reflection is limited to the granularity of a method 3. Behavioral reflection cannot be applied to the whole system 10
  11. 11. © Marcus Denker Three Problems of Reflection 1. Anticipation 2. Structural reflection is limited to the granularity of a method 3. Behavioral reflection cannot be applied to the whole system 11
  12. 12. © Marcus Denker Three Problems of Reflection 1. Anticipation 2. Sub-method Structure 3. Behavioral reflection cannot be applied to the whole system 12
  13. 13. © Marcus Denker Three Problems of Reflection 1. Anticipation 2. Sub-method Structure 3. Context 13
  14. 14. © Marcus Denker Thesis To support unanticipated behavioral reflection, reflection needs to be extended with sub-method structure and with the concept of context. 14
  15. 15. © Marcus Denker Contributions of the Dissertation > Unanticipated partial behavioral reflection > Sub-Method Structural Reflection > Partial Behavioral Reflection using Annotations > Contextual Reflection 15
  16. 16. © Marcus Denker x x x x x xx x Roadmap 16 1. Unanticipated partial behavioral reflection 2. Sub-Method Structure 3. Revisit Partial Reflection 4. Context
  17. 17. © Marcus Denker Roadmap 17 1. Unanticipated partial behavioral reflection 2. Sub-Method Structure 3. Revisit Partial Reflection 4. Context
  18. 18. © Marcus Denker Roadmap 18 1. Unanticipated partial behavioral reflection 2. Sub-Method Structure 3. Revisit Partial Reflection 4. Context
  19. 19. © Marcus Denker base meta Roadmap 19 1. Unanticipated partial behavioral reflection 2. Sub-Method Structure 3. Revisit Partial Reflection 4. Context
  20. 20. © Marcus Denker x x x x x xx x Roadmap 20 1. Unanticipated partial behavioral reflection 2. Sub-Method Structure 3. Revisit Partial Reflection 4. Context
  21. 21. © Marcus Denker x x x x x xx x Reflex: Partial Behavioral Reflection > Hooksets: collection of operation occurrences > Links — Bind hooksets to meta-objects — Define protocol between base and meta > Goals — Highly selective reification — Flexible meta-level engineering – Protocol specification – Cross-cutting hooksets activation condition hookset metaobject links Tanter, OOPSLA03 21
  22. 22. © Marcus Denker x x x x x xx x Example: Live Analysis > Typical Web application (e.g. Wiki) > Shows performance problem under high load > Goals: — Profile and fix the problem — No restart / interruption of service 22
  23. 23. © Marcus Denker x x x x x xx x Live Analysis — Install profiler — Analyze — Retract profiler 23 ... while the system is running!
  24. 24. © Marcus Denker x x x x x xx x Live Profiling > Operation: — Method Execution (around) > Hookset: — All execution operations in the wiki package > Metaobject: — A profiling tool activation condition hookset metaobject links 24
  25. 25. © Marcus Denker x x x x x xx x Unanticipated Partial Behavioral Reflection > Geppetto: Unanticipated Partial Behavioral Reflection — For Squeak 3.9 with Bytecode transformation David Röthlisberger, Marcus Denker and Éric Tanter: Unanticipated Partial Behavioral Reflection: Adapting Applications at Runtime Journal of Computer Languages, Systems and Structures, vol. 34, no. 2-3, July 2008, pp. 46-65. 25
  26. 26. © Marcus Denker x x x x x xx x Good Results > Completely dynamic > Simpler > High performance 26
  27. 27. © Marcus Denker Benchmarks Geppetto > Slowdown for reification of message send System Slowdown Geppetto 10.85 Iguana/J 24 Metaclasstalk 20
  28. 28. © Marcus Denker x x x x x xx x Missing Sub-method Structure > Semantic Mismatch > Code Quality > Synthesized Code 28
  29. 29. © Marcus Denker Roadmap 1. Dynamic partial behavioral reflection 2. Sub-Method Structure 3. Revisit Partial Reflection 4. Context 29
  30. 30. © Marcus Denker Methods and Reflection > Method are Objects — e.g in Smalltalk > No high-level model for sub-method elements — Message sends — Assignments — Variable access > Structural reflection stops at the granularity of methods 30
  31. 31. © Marcus Denker Sub-Method Reflection > Many tools work on sub method level — Profiler, Refactoring Tool, Debugger, Type Checker > Communication between tools needed — Example: Code coverage > All tools use different representations — Tools are harder to build — Communication not possible 31
  32. 32. © Marcus Denker Sub-method Representation Requirements > Causal Connection > Abstraction Level > Extensibility > Persistent > Size and Performance 32
  33. 33. © Marcus Denker Existing Method Representations > Existing representations for Methods — Text — Bytecode — AST 33
  34. 34. © Marcus Denker Text > Low level abstraction > Not causally connected 34
  35. 35. © Marcus Denker Bytecode > Low level abstraction > Missing extensibility > Mix of base- and meta-level code 35 1 16 0 0 160 197 59 17 172 94 7 17 204 122 70 17 92 94 7 17 65 112 224 135 120 88 141 0 252
  36. 36. © Marcus Denker Abstract Syntax Tree > Not causally connected > Not extensible > Not persistent 36
  37. 37. © Marcus Denker Solution: Reflective Methods > Annotated, persistent AST > Bytecode generated on demand and cached :ReflectiveMethod annotation #(12 13 45 38 98 128 84 72 42 77 22 28 59 32 7 49 51 87 64) :CompiledMethod compiledMethod reflectiveMethodannotation Tools VM 37
  38. 38. © Marcus Denker Implementation: Persephone > Implementation of Reflective Methods for Squeak > Smalltalk compiler generates Reflective Methods — Translated to bytecode on demand > Open Compiler: Plugins — Called before code generation — Transform a copy of the AST Marcus Denker, Stéphane Ducasse, Adrian Lienhard Philippe Marschall: Sub-Method Reflection Journal of Object Technology, vol. 6, no. 9, 38
  39. 39. © Marcus Denker Requirements revisited > Abstraction Level > Causal Connection > Extensibility > Persistency > Size and Performance 39
  40. 40. © Marcus Denker Extensible with Annotations > Source visible annotations — extended Smalltalk syntax > Source invisible annotations — Reflective API — Can reference any object > Every node can be annotated > Semantics: Compiler Plugins (9 raisedTo: 10000) <:evaluateAtCompiletime:> 40
  41. 41. © Marcus Denker Example: Pluggable Type-System > Example for textual annotations bitFromBoolean: aBoolean <:type: Boolean :> ^ (aBoolean ifTrue: [1] ifFalse: [0]) <:type: Integer :> > Optional, pluggable type-system > Types stored as annotations in the Reflective Methods Niklaus Haldiman, Marcus Denker, Oscar Nierstrasz: “Practical, Pluggable Types,” (ICDL 2007) 41
  42. 42. © Marcus Denker Memory Requirements number of classes memory Squeak 3.9 Persephone no reflective methods Persephone reflective methods 2040 15.7 MB 2224 20 MB 2224 123 MB 42
  43. 43. © Marcus Denker Roadmap 1. Realize partial behavioral reflection in a dynamic language 2. Sub-Method Structure 3. Revisit Partial Reflection 4. Context 43
  44. 44. © Marcus Denker Partial Behavioral Reflection Revisited > Problems of Bytecode: — Semantic Mismatch — Code Quality — Synthesized Code > With Sub-method Reflection, we can do better! 44
  45. 45. © Marcus Denker Sub-method Structure > Links can be annotations on the AST 45 + =x x x x x xx x
  46. 46. © Marcus Denker Performance Properties > Very fast annotations — No decompile! > On-the-fly code generation — Only code executed gets generated > Generated code is fast — Better then working on bytecode level 46
  47. 47. © Marcus Denker x x x x x xx x Repeat: Missing Sub-method Structure > Semantic Mismatch > Code Quality > Synthesized Code 47
  48. 48. © Marcus Denker Sub-method Structure > Semantic Mismatch > Code Quality > Synthesized Code 48
  49. 49. © Marcus Denker Example: Feature Annotations > Features modeled as traces > Many Problems — Space — Merging Traces > Solution: annotate structure Marcus Denker, Orla Greevy, Oscar Nierstrasz: Supporting Feature Analysis with Runtime Annotations (PCODA 2007) 49 source code (AST) instruction is meta-object links
  50. 50. © Marcus Denker base meta Roadmap 1. Realize partial behavioral reflection in a dynamic language 2. Sub-Method Structure 3. Revisit Partial Reflection 4. Context 50
  51. 51. © Marcus Denker base meta Problem: Whole System > Behavioral reflection cannot be applied to the whole system > Problem: recursion — System classes — Meta-objects 51
  52. 52. © Marcus Denker base meta The Problem of Recursion > Call the Beeper from OrderedCollection>>#add 52 beepLink := Link new metaObject: Beeper. beepLink selector: #beep. (OrderedCollection>>#add:) methodNode link: beepLink.
  53. 53. © Marcus Denker base meta Meta-object Call Recursion 53 Base Level Meta Object Meta Object Infinite recursion #beep send #add: send #add: send #beep send #add: send
  54. 54. © Marcus Denker base meta Representing Meta-level Execution > Link enables MetaContext Base Level Meta Level MetaContext activation MetaContext deactivation 54
  55. 55. © Marcus Denker base meta Context-aware Links > Disable call when already on the meta-level Base Level Meta Level Stop meta-level call 55
  56. 56. © Marcus Denker base meta MetaContext: Conclusion > Recursion problem solved 56 operation meta-object links level 0 base meta
  57. 57. © Marcus Denker base meta MetaContext: Conclusion > Meta-level Analysis Marcus Denker, Mathieu Suen,Stéphane Ducasse: The Meta in Meta-object Architectures TOOLS EUROPE 2008 operation meta-object links level 0 metameta- object link level 1 base meta meta-2 57
  58. 58. © Marcus Denker Thesis Revisited To support unanticipated behavioral reflection, reflection needs to be extended with sub-method structure and with the concept of context. 58
  59. 59. © Marcus Denker Future Work > Sub-method Structure — Simpler AST — AST compression — Replace text with sub-method representation > Behavioral Reflection — Composition of Links — Generalize context model: beyond the MetaContext 59
  60. 60. © Marcus Denker Contributions of the Dissertation > Unanticipated partial behavioral reflection > Sub-Method Structural Reflection > Partial Behavioral Reflection using Annotations > Contextual Reflection 60
  61. 61. © Marcus Denker Questions > Unanticipated partial behavioral reflection > Sub-Method Structural Reflection > Partial Behavioral Reflection using Annotations > Contextual Reflection 61 Questions?

×