Download presentation
Presentation is loading. Please wait.
Published byMonica Horton Modified over 9 years ago
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
9
Java Wildcards – List
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 {...} C – 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 {... } 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 world:E class E E
19
The ‘this’ context But, what about nesting?
20
The ‘this’ context Use bounds – class C Wildcards inherit declared bounds – C
21
The ‘this’ context class E world:E class E<C1, C2, Owner, This extends Owner> E
22
The ‘this’ context class E world:E class E<C1, C2, Owner, This extends Owner> E (E ) new
23
The ‘this’ context
24
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 {... } world:F class F {... } F
29
Universes rep CC peer CC any CC
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!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.