1 / 34

Encoding Ownership Types in Java

Encoding Ownership Types in Java. Nicholas Cameron James Noble Victoria University of Wellington, New Zealand. Ownership types for real life. Ownership types are great! (More later...). Ownership types for real life. But ownership type systems are big and complex

yoshe
Download Presentation

Encoding Ownership Types in Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Encoding Ownership Types in Java Nicholas Cameron James Noble Victoria University of Wellington, New Zealand

  2. Ownership types for real life • Ownership types are great! • (More later...)

  3. Ownership types for real life • But ownership type systems are big and complex • And writing compilers is hard • And the type systems are not well-understood

  4. Ownership types for real life • There is another way...

  5. Ownership Types • Are a facilitating type system: • Effects • Parallelisation • Optimisation • Concurrency • Memory management • Security • ...

  6. Ownership Types • When the heap gets large, reasoning gets hard • Solution: break it up into smaller regions • BUT, we don’t program this way • Nest the regions • Welcome to ownership types!

  7. Ownership Types • owner:ClassName • this:C • world:D • owner keyword names the owner of this • owner:C • Context parameters add flexibility

  8. Java • Generics • List<String> • List<Dog>

  9. Java • Wildcards • List<?> • List<? extends Dog>

  10. End of Background . . .

  11. Basic idea • We use type parameters to mimic ownership parameters (OGJ)

  12. An object’s owner (and the ‘world’ context) • class C {...} • world:C • class C<Owner> {...} • C<World> • class World {}

  13. Context parameters • Become type parameters

  14. Bounds

  15. The ‘this’ context • This* is where it gets interesting • We depart from OGJ • (OGJ does this with magic) • Must correspond with the this variable *no pun intended

  16. The ‘this’ context • Kind of like another context parameter • class C<Owner, This> { ... } • We can name This within the class

  17. The ‘this’ context • But this cannot be named outside the class • So neither should This • Use a wildcard to hide This

  18. The ‘this’ context • class E<c1, c2> • world:E<this, owner> • class E<C1, C2, Owner, This> • E<This, Owner, World, ?>

  19. The ‘this’ context • But, what about nesting?

  20. The ‘this’ context • Use bounds • class C<Owner, This extends Owner> • Wildcards inherit declared bounds • C<World, ?>

  21. The ‘this’ context • class E<c1, c2> • world:E<this, owner> • class E<C1, C2, Owner, This extends Owner> • E<This, Owner, World, ?>

  22. The ‘this’ context • class E<c1, c2> • world:E<this, owner> • class E<C1, C2, Owner, This extends Owner> • E<This, Owner, World, ?> • (E<This, Owner, World, ?>) new <This, Owner, World, World>

  23. The ‘this’ context

  24. The ‘this’ context • The type system thinks there is a hierarchy • X inside Y inside Z inside ... • But in reality all owners are World

  25. Nice...

  26. ? Existential Owners • and variant ownership • Use wildcards

  27. Inner Classes • Require inner classes to be able to name surrounding This parameter • Comes naturally with Java generics

  28. Type Parameters • Work alongside translated context parameters • class F<X> { ... } • world:F<Dog> • class F<X, Owner, This> { ... } • F<Dog, World, ?>

  29. Universes • rep C C<This, ?> • peer C C<Owner, ?> • any C C<?, ?>

  30. and... • Ownership Domains • Context-parametric methods • Dynamic aliases • Fields as contexts • Existential downcasting

  31. Owners-as-Dominators • Most of the work is done by the hiding of This using wildcards • Must ensure it cannot be named indirectly • Works with the extensions too • Including inner classes

  32. Owners-as-Dominators • Cannot be enforced by translating compiler • Requires enforcing well-formedness of intermediate types

  33. Contributions • Prototype compilers • Ownership types++ • Universes • How to leverage existing compiler technology for OTs • Formalisation of OTs in Java • Proved sound • Ownership hierarchy is preserved and enforced at runtime • Better understanding of OTs

  34. Thank you!

More Related