ownkit inferring modularly checkable ownership
play

OwnKit: Inferring Modularly Checkable Ownership Annotations for Java - PowerPoint PPT Presentation

OwnKit: Inferring Modularly Checkable Ownership Annotations for Java Constantine Dymnikov, David J. Pearce and Alex Potanin School of Engineering and Computer Science Victoria University of Wellington What is Ownership? Ownership is an approach


  1. OwnKit: Inferring Modularly Checkable Ownership Annotations for Java Constantine Dymnikov, David J. Pearce and Alex Potanin School of Engineering and Computer Science Victoria University of Wellington

  2. What is Ownership? Ownership is an approach for managing aliasing For example: public class Rectangle { private @Owned List<Point> points; ... } Objects reachable from points are owned (a.k.a deep ownership ) Useful for lots of things! e.g. parallelisation , verification , and more. And, of course, it helps you find bugs in your code!

  3. Ownership Inference versus Ownership Checking For this to work, inference can be expensive , but checking must be efficient . Ensuring annotations are modularly checkable is our approach.

  4. What are Modularly Checkable Annotations? Definition (Modular Type Checking) A type checker is modular if checking a given module only requires access to the type signatures of external methods. This characterises type checking in Java (and other languages), as well as e.g. checking final class modifiers. This does not characterise interprocedural analysis, which requires access to all method bodies simultaneously. When checking a given method, signatures for other methods are assumed correct .

  5. Overview Definition (Object Graph) An object graph , O G , is a directed graph capturing a snapshot of the C . f heap at a given moment. Here, o 1 → o 2 ∈ O G denotes that object o 1 refers to object o 2 via the field f declared in class C . Definition (Ownership Guarantee) Let C . f be a non-primitive field annotated with @ Owned which is C . f declared in class C . Then, for all objects o 1 , o 2 , o 3 where o 1 → o 3 ∈ O G C . f and o 2 → o 3 ∈ O G it follows that o 1 = o 2 . Aim: to infer which fields may safely be annotated @Owned Approach: determine which fields are exposed . Assumptions: parameters and return values for public or protected methods are exposed ; fields declared public or protected are exposed .

  6. Read Exposure public class MyClass { private List<String> myList = ...; public List<String> getMyList(){ return myList; } } public class External { public void expose(){ MyClass mc = ...; List<String> alias = mc.getMyList(); alias.add( "bad" ); } } A variable is read exposed if its value may be read externally.

  7. Write Exposure public class MyClass { private List<String> myList = ...; public void setMyList(List<String> par){ myList = par; } } public class External { public void expose() { MyClass mc = ...; List<String> alias = ...; mc.setMyList(alias); } } A variable is write exposed if can be assigned a value that may be read externally.

  8. Implementation — Class Graph Construction public class MyClass { private Object field; public Object fun(Object p, MyClass q) { Object t = field; if (p!= null ) { this .field = p; } else { this .field = q.field; } return t; }}

  9. Implementation — Exposure Propagation X X this this Z Z a b a b this this c c Y Y ... ... (Before) (After) (case #1 — read exposure )

  10. Implementation — Exposure Propagation X X this this Z Z a b a b this this c c Y Y ... ... (Before) (After) (case #2 — write exposure )

  11. Implementation — Exposure Propagation X X Z Z this this this this a b c a b c Y1 Y2 Y1 Y2 ... ... ... ... (Before) (State 1) X Z this this a b c Y1 Y2 ... ... (State 2)

  12. Implementation — Self Exposure One complication for our analysis is self exposure : public class Z { public Z(){ S.staticField = this ; } } public class S { public static Z staticField = ...; } Any variable that can reference objects of type Z are read exposed . In presence of self exposure, ownership remains modularly checkable with an explicit annotation (e.g. @SelfExposed ).

  13. Experimental Results — How much Ownership? Program LOC Total % of Owned Fields Classes Fields OwnKit UNO Self-Exp. % Total java-std 62,508 690 3.77 - 16.0 763 javacc 36,672 406 4.7 11.8 13.3 150 polyglot 14,148 421 0.5 2.9 11.0 327 asm 22,474 259 4.2 10.8 14.0 172 jgraph 12,262 178 5.1 3.9 29.2 89 raytracer 1,928 40 12.5 5.0 28.0 25 Average 5.1 6.9 18.6

  14. Experimental Results — Reasons for Exposure 100 Non-Private Flow to Read Flow from Read Field Exposure Reason (%) 80 Flow from Write Other-Instance Self-Exposed Static 60 40 20 0 j j p a j j A a a g v o s v v v r m l m a e a a y p 9 r - c g a s h 8 c l o g t d r t e a y t r a c e r Benchmark

  15. Conclusion For ownership to be used, it needs to fit within day-day development . This means it must not impose significant overhead . Our approach is to focus on modularly checkable annotations: - Annotations are inferred using expensive inference . - Annotations are maintained using efficient checker . We presented a simple ownership inference scheme. Results are encouraging, compared with a heavy weight interprocedural analysis .

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend