+ All Categories
Home > Technology > Sub-method Structural and Behavioral Reflection

Sub-method Structural and Behavioral Reflection

Date post: 11-May-2015
Category:
Upload: marcus-denker
View: 649 times
Download: 1 times
Share this document with a friend
Description:
University of Berne. PhD Defense: "Sub-method Structural and Behavioral Reflection", 26.05.2008
Popular Tags:
61
© Marcus Denker Sub-method Structural and Behavioral Reflection Marcus Denker Universität Bern
Transcript
Page 1: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Sub-method Structural and Behavioral Reflection

Marcus Denker

Universität Bern

Page 2: Sub-method Structural and Behavioral Reflection

© 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

Page 3: Sub-method Structural and Behavioral Reflection

© 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

Page 4: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Reflection

4

Page 5: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Reflection

5

Program Description

Page 6: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Reflection

6

Program Description

Query and Change

Page 7: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Repeat: Demands

> Dynamic Analysis— Fine-grained Selection— Install / retract at runtime— Complete System

> Development Environment— Complete representation of the system— Extensible

7

Page 8: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Reflection to the Rescue

> Where?

> At runtime!

> Complete Structure

> Everywhere!

8

Page 9: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Reflection to the Rescue

> Where?

> At runtime!

> Complete structure

> Everywhere!

9

Solved (Partial Behavioral Reflection, Eric Tanter)

Page 10: Sub-method Structural and Behavioral Reflection

© 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

Page 11: Sub-method Structural and Behavioral Reflection

© 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

Page 12: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Three Problems of Reflection

1. Anticipation

2. Sub-method Structure

3. Behavioral reflection cannot be applied to the whole system

12

Page 13: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Three Problems of Reflection

1. Anticipation

2. Sub-method Structure

3. Context

13

Page 14: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Thesis

To support unanticipated behavioral reflection, reflection needs to be extended with sub-method structure and with the concept of context.

14

Page 15: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Contributions of the Dissertation

> Unanticipated partial behavioral reflection

> Sub-Method Structural Reflection

> Partial Behavioral Reflection using Annotations

> Contextual Reflection

15

Page 16: Sub-method Structural and Behavioral Reflection

© Marcus Denker

xx x x

x

xx

x

Roadmap

16

1. Unanticipated partial behavioral reflection2. Sub-Method Structure3. Revisit Partial Reflection4. Context

Page 17: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Roadmap

17

1. Unanticipated partial behavioral reflection2. Sub-Method Structure3. Revisit Partial Reflection4. Context

Page 18: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Roadmap

18

1. Unanticipated partial behavioral reflection2. Sub-Method Structure3. Revisit Partial Reflection4. Context

Page 19: Sub-method Structural and Behavioral Reflection

© Marcus Denker

base

meta

Roadmap

19

1. Unanticipated partial behavioral reflection2. Sub-Method Structure3. Revisit Partial Reflection4. Context

Page 20: Sub-method Structural and Behavioral Reflection

© Marcus Denker

xx x x

x

xx

x

Roadmap

20

1. Unanticipated partial behavioral reflection2. Sub-Method Structure3. Revisit Partial Reflection4. Context

Page 21: Sub-method Structural and Behavioral Reflection

© Marcus Denker

xx 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, OOPSLA0321

Page 22: Sub-method Structural and Behavioral Reflection

© Marcus Denker

xx 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

Page 23: Sub-method Structural and Behavioral Reflection

© Marcus Denker

xx x x

x

xx

x

Live Analysis

— Install profiler— Analyze— Retract profiler

23

... while the system is running!

Page 24: Sub-method Structural and Behavioral Reflection

© Marcus Denker

xx 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

Page 25: Sub-method Structural and Behavioral Reflection

© Marcus Denker

xx 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 RuntimeJournal of Computer Languages, Systems and Structures, vol. 34, no. 2-3, July 2008, pp. 46-65.

25

Page 26: Sub-method Structural and Behavioral Reflection

© Marcus Denker

xx x x

x

xx

x

Good Results

> Completely dynamic

> Simpler

> High performance

26

Page 27: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Benchmarks Geppetto

> Slowdown for reification of message send

System Slowdown

Geppetto 10.85

Iguana/J 24

Metaclasstalk 20

Page 28: Sub-method Structural and Behavioral Reflection

© Marcus Denker

xx x x

x

xx

x

Missing Sub-method Structure

> Semantic Mismatch

> Code Quality

> Synthesized Code

28

Page 29: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Roadmap

1. Dynamic partial behavioral reflection2. Sub-Method Structure3. Revisit Partial Reflection4. Context

29

Page 30: Sub-method Structural and Behavioral Reflection

© 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

Page 31: Sub-method Structural and Behavioral Reflection

© 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

Page 32: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Sub-method Representation Requirements

> Causal Connection

> Abstraction Level

> Extensibility

> Persistent

> Size and Performance

32

Page 33: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Existing Method Representations

> Existing representations for Methods

— Text

— Bytecode

— AST

33

Page 34: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Text

> Low level abstraction

> Not causally connected

34

Page 35: Sub-method Structural and Behavioral Reflection

© 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

Page 36: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Abstract Syntax Tree

> Not causally connected

> Not extensible

> Not persistent

36

Page 37: Sub-method Structural and Behavioral Reflection

© 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

Page 38: Sub-method Structural and Behavioral Reflection

© 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 ReflectionJournal of Object Technology, vol. 6, no. 9,

38

Page 39: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Requirements revisited

> Abstraction Level

> Causal Connection

> Extensibility

> Persistency

> Size and Performance

39

Page 40: Sub-method Structural and Behavioral Reflection

© 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

Page 41: Sub-method Structural and Behavioral Reflection

© 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

Page 42: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Memory Requirements

number of classes memory

Squeak 3.9

Persephoneno reflective methods

Persephonereflective methods

2040 15.7 MB

2224 20 MB

2224 123 MB

42

Page 43: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Roadmap

1. Realize partial behavioral reflection in a dynamic language

2. Sub-Method Structure3. Revisit Partial Reflection4. Context

43

Page 44: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Partial Behavioral Reflection Revisited

> Problems of Bytecode:— Semantic Mismatch— Code Quality— Synthesized Code

> With Sub-method Reflection, we can do better!

44

Page 45: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Sub-method Structure

> Links can be annotations on the AST

45

+ =xx x x

x

xx

x

Page 46: Sub-method Structural and Behavioral Reflection

© 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

Page 47: Sub-method Structural and Behavioral Reflection

© Marcus Denker

xx x x

x

xx

x

Repeat: Missing Sub-method Structure

> Semantic Mismatch

> Code Quality

> Synthesized Code

47

Page 48: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Sub-method Structure

> Semantic Mismatch

> Code Quality

> Synthesized Code

48

Page 49: Sub-method Structural and Behavioral Reflection

© 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

Page 50: Sub-method Structural and Behavioral Reflection

© Marcus Denker

base

meta

Roadmap

1. Realize partial behavioral reflection in a dynamic language

2. Sub-Method Structure3. Revisit Partial Reflection4. Context

50

Page 51: Sub-method Structural and Behavioral Reflection

© Marcus Denker

base

meta

Problem: Whole System

> Behavioral reflection cannot be applied to the whole system

> Problem: recursion— System classes— Meta-objects

51

Page 52: Sub-method Structural and Behavioral Reflection

© 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.

Page 53: Sub-method Structural and Behavioral Reflection

© 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

Page 54: Sub-method Structural and Behavioral Reflection

© Marcus Denker

base

meta

Representing Meta-level Execution

> Link enables MetaContext

Base Level Meta Level

MetaContext activation

MetaContext deactivation

54

Page 55: Sub-method Structural and Behavioral Reflection

© Marcus Denker

base

meta

Context-aware Links

> Disable call when already on the meta-level

Base Level Meta Level

Stop meta-level call

55

Page 56: Sub-method Structural and Behavioral Reflection

© Marcus Denker

base

meta

MetaContext: Conclusion

> Recursion problem solved

56

operation

meta-object

links

level 0

base

meta

Page 57: Sub-method Structural and Behavioral Reflection

© Marcus Denker

base

meta

MetaContext: Conclusion

> Meta-level Analysis

Marcus Denker, Mathieu Suen,Stéphane Ducasse: The Meta in Meta-object ArchitecturesTOOLS EUROPE 2008

operation

meta-object

links

level 0

metameta-

object

link

level 1

base

meta

meta-2

57

Page 58: Sub-method Structural and Behavioral Reflection

© 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

Page 59: Sub-method Structural and Behavioral Reflection

© 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

Page 60: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Contributions of the Dissertation

> Unanticipated partial behavioral reflection

> Sub-Method Structural Reflection

> Partial Behavioral Reflection using Annotations

> Contextual Reflection

60

Page 61: Sub-method Structural and Behavioral Reflection

© Marcus Denker

Questions

> Unanticipated partial behavioral reflection

> Sub-Method Structural Reflection

> Partial Behavioral Reflection using Annotations

> Contextual Reflection

61

Questions?


Recommended