+ All Categories
Home > Technology > Classboxes

Classboxes

Date post: 02-Dec-2014
Category:
Upload: esug
View: 847 times
Download: 0 times
Share this document with a friend
Description:
Classboxes: A Minimal Module Model Supporting Local Class Extension. Alexandre Bergel, Stéphane Ducasse, Oscar Nierstrasz, and Roel Wuyts (ESUG 2004, Koethen)
22
1 Classboxes: A Minimal Module Model Supporting Local Class Extension Alexandre Bergel, Stéphane Ducasse, Oscar Nierstrasz, and Roel Wuyts University of Bern (Switzerland) Université Libre de Bruxelles [email protected]
Transcript
Page 1: Classboxes

1

Classboxes: A Minimal Module Model Supporting

Local Class ExtensionAlexandre Bergel, Stéphane Ducasse,

Oscar Nierstrasz, and Roel Wuyts

University of Bern (Switzerland)Université Libre de Bruxelles

[email protected]

Page 2: Classboxes

2

Outline

1. Class Extension

2. Supporting Unanticipated Changes

3. The Classbox Model

4. Local Rebinding

5. Implementation

6. Conclusion

Page 3: Classboxes

3

Class Extension

• Adding a new method or redefining one on an already existing class is a class extension

• Decoupling a class definition from method definitions

• Relevant: HyperJ, AspectJ, MultiJava, Smalltalk, Clos, ...

Squeak

String

UrlPack

asUrl

Url

Page 4: Classboxes

4

In Smalltalk-80

• Class extensions are global

• Any application can modify any class in the system

• Three consequences:

• Conflicts may arise (e.g., two applications bring the same extensions)

• Robustness aspect (e.g., an application may redefine a critical method)

• Implicit dependencies

Page 5: Classboxes

5

In Squeak...

Morph

bounds ^ bounds

Changesetthat modify

Morph>>bounds

Morph

bounds ^ self

Result: unrecoverable crash

Page 6: Classboxes

6

Supporting Unanticipated Changes

• Java, Modula3 provide package mechanism and no class extension

• AspectJ, Smalltalk, CLOS provide class extension and weak packages

• How to combine module + class extension?

• Scoped changes: avoiding globality and reconciling with security

Page 7: Classboxes

7

The Classbox Model

• A classbox is a unit of scoping (it behaves as a namespace).

• Within a classbox:

• Classes can be defined

• Classes can be imported from other classboxes

• Methods can be defined on any visible class

• Code can be evaluated

• Local redefinitions take precedence over previous definitions

Page 8: Classboxes

8

Local Rebinding

MorphCB

Morphrepaint

paint

EnhMorphCB

paint

import

Button new repaint

Button

Button new repaint

Button

class extension

Morph...self paint...

“new implementation”

Button new paint Button new paint

Flatten view within a classbox

Page 9: Classboxes

9

Properties of the Model

• From within a classbox: flattened view of the world.

• Local changes are as if they would have been global.

• Extending some classes does not impact their clients.

Page 10: Classboxes

10

Visibility Bounded to a Classbox

MorphCB

Buttonrepaint

paint

EnhMorphCB

Button

paint

import

class extension

OldGUI

Button

Multiple versions of a method at the same time

NewGUI

Button

“original implementation”

“new implementation”

Page 11: Classboxes

11

Limited Class Extension Impact

MorphCB

FillInTheBlank

requestPassword...

MorphHackCB

import

class extension

BankAppCB

FillInTheBlank

Original Behavior is Preserved!

SecureApplicationrun passField := FillInTheBlank requestPassword

FillInTheBlank

requestPassword

...Transcript show: pass...

Page 12: Classboxes

12

Implementation

• In Squeak, an open-source Smalltalk.

• New method lookup semantics.

• No need to modify the VM.

• Uses a cache mechanism.

• Cache is checked in redefined methods by adding 5 extra byte-codes.

• No overhead for added method invocation

• Redefined method invocation (worst case): 2.5 times

Page 13: Classboxes

13

Conclusion

• Secure module system for controlling class extensions:

• Control the visibility of method addition and replacement

• Support for unanticipated evolution

• New method lookup semantics

• Use of a cache mechanism

Page 14: Classboxes

14

The Classbox Model

• http://www.iam.unibe.ch/~scg

• or Ask google.com about classbox

• Information: [email protected]

Page 15: Classboxes

15

Page 16: Classboxes

16

Import Before Inheritance

GraphicCB

Componentpaintupdate

Windowpaint

Framepaint

update

...

self paint

...

Frame new update => Normal Frame

DoubleBufferCB

Componentpaint

RoundedWindowCB

Windowpaint

Frame Frame

paint

"code 1"

super paint

...

DoubleBufferAndRoundedCB

Component

Frame

Frame new update =>Rounded Frame

Frame new update =>Double Buffered

Frame

Frame new update =>Double Buffered Rounded Frame

"code 2"

super paint

...

Page 17: Classboxes

17

Cache Mechanism (1/4)

A

Class creation

Page 18: Classboxes

18

Cache Mechanism (2/4)

Afoo CM1

Method addition

Page 19: Classboxes

19

Cache Mechanism (3/4)

Afoo

CM2

Method redefinition

DispatcherCM1

Page 20: Classboxes

20

Cache Mechanism (4/4)

Afoo

CM2

Method execution: A new foo

DispatcherCM1

CM2’kept in the literal frame

cache check

Page 21: Classboxes

21

• Model composed of 3 classes: Classbox, ClassboxSystem and Dispatcher

Page 22: Classboxes

22

Scope of a Method

MorphCB

Buttonrepaint

paint

EnhMorphCB

paint

import

Button new repaint Button new repaint

class extension

Button...self paint...

“new implementation”


Recommended