Prospector Osq 2004 Final

377 views
318 views

Published on

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
377
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Prospector Osq 2004 Final

    1. 1. Mining Jungloids to Cure Programmer Headaches Dave Mandelin, Ras Bodik UC Berkeley Doug Kimelman IBM
    2. 2. Motivation: the price of code reuse <ul><li>Inherently, reusable code has complex APIs. Why? </li></ul><ul><ul><li>Many classes and methods </li></ul></ul><ul><ul><li>Indirection </li></ul></ul><ul><ul><li>Many options </li></ul></ul><ul><li>Simple tasks often require arcane code — jungloids </li></ul><ul><ul><li>Example. In Eclipse IDE, parsing a Java file into an AST </li></ul></ul><ul><ul><li>simple: a handle for the Java file (object of type IFile ) </li></ul></ul><ul><ul><li>simple: what we want (object of type CompilationUnit ) </li></ul></ul><ul><ul><li>hard: finding the parser </li></ul></ul><ul><ul><ul><li>took hours of documentation/code browsing </li></ul></ul></ul>ICompilationUnit cu = JavaCore.createCompilationUnitFrom( javaFile ); CompilationUnit ASTroot = AST.parseCompilationUnit(cu, false);
    3. 3. First key observation <ul><li>Part 1: Headache task requirements can usually be described by a 1-1 query : “What code will transform a (single) object of (static) type A into a (single) object of (static) type B?” </li></ul><ul><li>Our experiments: </li></ul><ul><ul><li>12 out of 16 queries are of such single-source, single-target, static-type nature </li></ul></ul><ul><li>Same example: </li></ul><ul><ul><li>type A: IFile , type B: CompilationUnit </li></ul></ul>ICompilationUnit cu = JavaCore.createCompilationUnitFrom( javaFile ); CompilationUnit ASTroot = AST.parseCompilationUnit(cu, false);
    4. 4. First key observation (cont’d) <ul><li>Part 2: Most 1-1 queries are correctly answered with 1-1 jungloids </li></ul><ul><li>1-1 jungloid: an expression with single-input, single-output operations: </li></ul><ul><ul><li>field access; instance method calls with 0 arguments; static method and constructor calls with one argument ; array element access. </li></ul></ul><ul><li>Our experiments: </li></ul><ul><ul><li>9 out of 12 such 1-1 queries are 1-1 jungloids </li></ul></ul><ul><ul><li>Others require operations with k inputs </li></ul></ul>ICompilationUnit cu = JavaCore.createCompilationUnitFrom( javaFile ); CompilationUnit ASTroot = AST.parseCompilationUnit(cu, false);
    5. 5. Prospector: a jungloid assistant tool <ul><li>Prospector: a programmer’s “search engine” </li></ul><ul><ul><li>mine API implementation and sample client code </li></ul></ul><ul><ul><li>search a jungloid “database” </li></ul></ul><ul><ul><li>paste the result into programmers code </li></ul></ul><ul><li>User experience: </li></ul><ul><ul><li>similar to code assist in Eclipse or .Net </li></ul></ul><ul><ul><li>editor cursor position specifies both target type B and context from which the source type A is drawn </li></ul></ul><ul><li>Soundness guarantees? </li></ul><ul><ul><li>such as “does the mined jungloid do the work I intend?” </li></ul></ul><ul><ul><li>no such guarantees, of course (because the query doesn’t specify the full intention) </li></ul></ul>
    6. 6. Demo <ul><li>Place the demo already here, to show that Prospector is self-explanatory (no need to explain what’s under the hood to use the tool)? </li></ul><ul><ul><li>depends whether the demo exposes some limitations that you cannot explain without first explaining how Prospector works </li></ul></ul><ul><li>Return to the demo later, to show more complex examples? </li></ul><ul><li>Jungloids to demo here: </li></ul><ul><ul><li>IFile  ASTNode (so far, the running example; use context with size one) </li></ul></ul><ul><ul><li>IEditor  Shell (use a bigger context) </li></ul></ul><ul><ul><li>ISelection  ASTNode (needs cast) </li></ul></ul><ul><ul><li>File  FileChannel </li></ul></ul><ul><li>Jungloids that you are not able to demo, you can leave as non-demoed examples for later slides </li></ul>
    7. 7. Demo
    8. 8. Program representation <ul><li>The representation is defined to support 1-1 jungloid mining </li></ul><ul><ul><li>A directed graph where each path is a 1-1 jungloid </li></ul></ul><ul><ul><li>Vertices: pointer types (instances and arrays) </li></ul></ul><ul><ul><li>Edges: well-typed expressions with single pointer-typed input and single pointer-typed output </li></ul></ul><ul><li>A small part of our representation: </li></ul>JavaEditor IWorkbenchPartSite Shell ISourceViewer StyledText .getSite() .getShell() .getTextWidget() .getViewer() .getShell()
    9. 9. Second key observation <ul><li>The jungloid that answers a 1-1 query “How do I get from A to B ?” typically corresponds to the shortest path from A to B. </li></ul><ul><ul><li>Fewer steps are fewer chances to </li></ul></ul><ul><ul><ul><li>throw an exception </li></ul></ul></ul><ul><ul><ul><li>return semantically unrelated objects </li></ul></ul></ul><ul><ul><ul><li>confuse the programmer </li></ul></ul></ul>JavaEditor IWorkbenchPartSite Shell .getSite() .getShell() ISourceViewer StyledText .getTextWidget() .getViewer() .getShell() IViewPartInputProvider UserInputWizardPage String JFormattedTextField Object MouseMotionListener EventListenerProxy
    10. 10. Experiment (shortest-path jungloids) <ul><li>Result: </li></ul><ul><ul><li>in 10 out of 10 queries, shortest path produced correct code </li></ul></ul><ul><li>Breakdown: </li></ul><ul><ul><li>9 found best code (in 3, path length = 1, but code non-trivial) </li></ul></ul><ul><ul><li>1 found correct code, but the graph contains a subjectively better jungloid of equal length </li></ul></ul><ul><li>Conclusions: </li></ul><ul><ul><li>shortest path a very good heuristic for finding correct jungloids </li></ul></ul><ul><ul><li>offering k shortest jungloids likely to find the best jungloid </li></ul></ul>
    11. 11. The downcast problem <ul><li>Problem: Java code is full of downcasts </li></ul><ul><ul><li>containers return Objects </li></ul></ul><ul><ul><li>type depends on configuration files or other input </li></ul></ul>IStructuredSelection ssel = (IStructuredSelection) sel; ICompilationUnit cu = (ICompilationUnit) sel.getFirstElement(); CompilationUnit ast = AST.parseCompilationUnit(cu, false); CompilationUnit ICompilationUnit IStructuredSelection Object .getFirstElement() AST.parseCompilationUnit(_, false) .getFirstElement() ActionContext ac = new ActionContext(startVar); char[] char_ary = ac.toString().toCharArray(); CompilationUnit resultVar = AST.parseCompilationUnit(char_ary);
    12. 12. The subtype mining algorithm <ul><li>Mining a code base </li></ul><ul><ul><li>Mine sample API client code base to find valid casts </li></ul></ul><ul><ul><li>Assumption: Code base contains the scenario the user wants </li></ul></ul><ul><li>Goal: for A.f() declared to return object of T , find a superset of possible dynamic subtypes </li></ul><ul><ul><li>Superset ensures that the correct jungloid is in the graph </li></ul></ul><ul><li>Idea: mine invocation sites of A.f() , find casts reached by return value </li></ul><ul><li>Algorithm: flow insensitive, interprocedural inference </li></ul><ul><ul><li>(T) e 1  T  types[e 1 ] </li></ul></ul><ul><ul><li>e 1 instanceof T  T  types[e 1 ] </li></ul></ul><ul><ul><li>types[e 1 ]  types[(e 0 ? e 1 : e 2 )] </li></ul></ul><ul><ul><li>T x = e 1  types[x]  types[e 1 ] </li></ul></ul>
    13. 13. The big picture <ul><li>Prospector architecture </li></ul><ul><ul><li>cast miner </li></ul></ul><ul><ul><li>shortest path searcher </li></ul></ul><ul><ul><li>representation </li></ul></ul><ul><ul><li>UI </li></ul></ul><ul><ul><li>TODO (goal of slide is to use the architecture to recap how prospector works) </li></ul></ul>
    14. 14. Summary <ul><li>Two key observations </li></ul><ul><ul><li>many headache scenarios are searches for 1-1 jungloids </li></ul></ul><ul><ul><li>most jungloids can be found with “k-shortest paths” over a simple program representation based on declared types + static cast mining </li></ul></ul><ul><li>Under the hood </li></ul><ul><ul><li>new program representation </li></ul></ul><ul><ul><li>cast mining </li></ul></ul><ul><ul><li>memory footprint reduction (graph clustering) </li></ul></ul><ul><li>Prospector status </li></ul><ul><ul><li>for Java under Eclipse </li></ul></ul><ul><ul><li>to be available … Summer 2004 </li></ul></ul>
    15. 15. Future work <ul><li>Semantics </li></ul><ul><ul><li>Q: Is this jungloid semantically valid? </li></ul></ul><ul><ul><li>A: Model checking </li></ul></ul><ul><li>Types </li></ul><ul><ul><li>Q: Can we mine more kinds of jungloids? </li></ul></ul><ul><ul><li>A: Java 1.5 generics </li></ul></ul><ul><ul><li>A: Inferring polymorphic types </li></ul></ul><ul><ul><li>A: Inferring input types </li></ul></ul><ul><ul><li>A: Typestates </li></ul></ul><ul><li>Plenty more… </li></ul>
    16. 16. Future work <ul><li>Graph-theoretic considerations: </li></ul><ul><ul><li>breaking 2-cycles (conversion from A to B and back) </li></ul></ul><ul><ul><li>high-degree nodes may need special handling. </li></ul></ul><ul><ul><li>assign weights regarding probabilities that expressions will succeed, and use weighted SP. </li></ul></ul><ul><li>Generalize the downcast problem </li></ul><ul><ul><li>into a more general inference of narrower types. </li></ul></ul><ul><li>Modeling and inferring generics/polymorphic types </li></ul><ul><ul><li>legacy code </li></ul></ul><ul><li>k-shortest path results </li></ul><ul><ul><li>ranking </li></ul></ul><ul><ul><li>clustering </li></ul></ul><ul><li>Dynamic techniques </li></ul><ul><ul><li>finding downcasts controlled by configuration data </li></ul></ul>

    ×