Classboxes

835 views

Published on

Classboxes: A Minimal
Module Model Supporting
Local Class Extension. Alexandre Bergel, Stéphane Ducasse, Oscar Nierstrasz, and Roel Wuyts (ESUG 2004, Koethen)

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

  • Be the first to like this

No Downloads
Views
Total views
835
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Classboxes

  1. 1. 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 bergel@iam.unibe.ch
  2. 2. 2 Outline 1. Class Extension 2. Supporting Unanticipated Changes 3. The Classbox Model 4. Local Rebinding 5. Implementation 6. Conclusion
  3. 3. 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
  4. 4. 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
  5. 5. 5 In Squeak... Morph bounds ^ bounds Changeset that modify Morph>>bounds Morph bounds ^ self Result: unrecoverable crash
  6. 6. 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
  7. 7. 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
  8. 8. 8 Local Rebinding MorphCB Morph repaint 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
  9. 9. 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.
  10. 10. 10 Visibility Bounded to a Classbox MorphCB Button repaint paint EnhMorphCB Button paint import class extension OldGUI Button Multiple versions of a method at the same time NewGUI Button “original implementation” “new implementation”
  11. 11. 11 Limited Class Extension Impact MorphCB FillInTheBlank requestPassword ... MorphHackCB import class extension BankAppCB FillInTheBlank Original Behavior is Preserved! SecureApplication run passField := FillInTheBlank requestPassword FillInTheBlank requestPassword ... Transcript show: pass ...
  12. 12. 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
  13. 13. 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
  14. 14. 14 The Classbox Model • • http://www.iam.unibe.ch/~scg • or Ask google.com about classbox • Information: bergel@iam.unibe.ch
  15. 15. 15
  16. 16. 16 Import Before Inheritance GraphicCB Component paint update Window paint Frame paint update ... self paint ... Frame new update => Normal Frame DoubleBuffer CB Component paint Rounded WindowCB Window paint Frame Frame paint "code 1" super paint ... DoubleBuffer AndRoundedCB Component Frame Frame new update => Rounded Frame Frame new update => Double Buffered Frame Frame new update => Double Buffered Rounded Frame "code 2" super paint ...
  17. 17. 17 Cache Mechanism (1/4) A Class creation
  18. 18. 18 Cache Mechanism (2/4) A foo CM1 Method addition
  19. 19. 19 Cache Mechanism (3/4) A foo CM2 Method redefinition Dispatcher CM1
  20. 20. 20 Cache Mechanism (4/4) A foo CM2 Method execution: A new foo Dispatcher CM1 CM2’ kept in the literal frame cache check
  21. 21. 21 • Model composed of 3 classes: Classbox, ClassboxSystem and Dispatcher
  22. 22. 22 Scope of a Method MorphCB Button repaint paint EnhMorphCB paint import Button new repaint Button new repaint class extension Button... self paint ... “new implementation”

×