PROGRAMMING BY IMITATION          Mario Sangiorgio          Kuat Yessenov       Armando Solar-Lezama
PLUG-IN ARCHITECTURE New feature   New feature     New feature     Application Programming Interface               Core Sy...
ISSUES       Integrating with the system is hardFeatures need only a        Integration requires tiny part of the API     ...
GOALImprove productivity by synthesizing the glue code.Programmers should only care about their features.
IDEAS  Different plug-ins may need  the same functionality from         the framework  Why don’t we imitate what  existing...
APPROACH1.      Show our tool what you want to do2.   Generate the code that imitates that feature3. Put everything togeth...
RECORDING THE EXECUTION Keeping track of everything the application does
TRACE ANALYSISUnderstanding which elements are related to the feature
CODE SYNTHESISGenerating the code imitating the feature
TRACE COLLECTION
DATA DRIVEN APPROACHLightweight instrumentation of method calls    and field accesses in relevant classes
TRACESByte-code level   Describe everything is going                     on in the application
TRACESByte-code level    Describe everything is going                      on in the application       Have a lot of infor...
WE NEED ABSTRACTION!
TRACE ANALYSIS
PACKAGE DEPENDENCY GRAPH       A      B
PACKAGE DEPENDENCY GRAPH           packages       A              B
PACKAGE DEPENDENCY GRAPH               packages           A               B   call from a method in package A to   a metho...
ISOLATION OF FRAMEWORK CODE                                C          A                B        D              E    The st...
ISOLATION OF FRAMEWORK CODE                                C          A                B        D              E         P...
ISOLATION OF FRAMEWORK CODE                                C          A                B        D              E         P...
PLUG-IN CODE                Code called only from               other plug-in packages orA             through special mec...
FRAMEWORK CODE     C             Called by plug-in code and                only calls methods B       D    declared in fra...
EXAMPLEimport org.gjt.sp.jedit.buffer.JEditBuffer;import org.gjt.sp.jedit.buffer.FoldHandler;public class JavaFold extends...
EXAMPLE                                                  The plug-in extendsimport org.gjt.sp.jedit.buffer.JEditBuffer;imp...
EXAMPLE                                                  The plug-in extendsimport org.gjt.sp.jedit.buffer.JEditBuffer;imp...
EXAMPLE                                                  The plug-in extendsimport org.gjt.sp.jedit.buffer.JEditBuffer;imp...
REMOVING IMPLEMENTATION DETAILS                              C          A               B       D              E         P...
A COMPACT REPRESENTATION
SO FAR  We know the plug-in uses the frameworkWe don’t know the precise method we need
SO FAR  We know the plug-in uses the frameworkWe don’t know the precise method we need    WE SHOULD GUIDE THE USERDISCOVER...
CALL TREES ABSTRACTION
CALL TREES ABSTRACTION
TRACE EXPLORATION• We    still have too many call trees• Users  should search the framework calls in term of the high leve...
TRACE EXPLORATION• We    still have too many call trees• Users  should search the framework calls in term of the high leve...
FEATURE SEARCH       High Level        Query     Search in class   names, methods and     documentation      Matching call...
SEARCH RESULT
CALL TREE EXPLORATION  The user wants         The user doesn’t want See matching methods    Redundant information (loops)K...
INTERACTIVE VISUALIZATION
INTERACTIVE VISUALIZATIONCompact representation   of the call tree
INTERACTIVE VISUALIZATION                         DocumentationCompact representation   of the call tree
INTERACTIVE VISUALIZATION                         DocumentationCompact representation   of the call tree                  ...
TRACE MATCHING
THE SHORT TRACE IS NOT ENOUGHIt contains the code that causes the feature to execute             It misses all the setup c...
THE COMPLETE TRACEContains the compete execution of several runs  of the application, exercising different featuresThis tr...
MATCHINGA demo and a complete trace match if:    the corresponding method handles match call events in the complete trace ...
CODE SYNTHESIS
SYNTHESIS THROUGH SLICING We look for the minimal set of instruction  (slice) that can reproduce the matched trace The res...
THANK YOU!
Programming by imitation
Upcoming SlideShare
Loading in …5
×

Programming by imitation

455 views

Published on

The research project I worked at while I visited MIT

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
455
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Programming by imitation

  1. 1. PROGRAMMING BY IMITATION Mario Sangiorgio Kuat Yessenov Armando Solar-Lezama
  2. 2. PLUG-IN ARCHITECTURE New feature New feature New feature Application Programming Interface Core System
  3. 3. ISSUES Integrating with the system is hardFeatures need only a Integration requires tiny part of the API several steps
  4. 4. GOALImprove productivity by synthesizing the glue code.Programmers should only care about their features.
  5. 5. IDEAS Different plug-ins may need the same functionality from the framework Why don’t we imitate what existing plug-ins are doing?
  6. 6. APPROACH1. Show our tool what you want to do2. Generate the code that imitates that feature3. Put everything together and add your own code
  7. 7. RECORDING THE EXECUTION Keeping track of everything the application does
  8. 8. TRACE ANALYSISUnderstanding which elements are related to the feature
  9. 9. CODE SYNTHESISGenerating the code imitating the feature
  10. 10. TRACE COLLECTION
  11. 11. DATA DRIVEN APPROACHLightweight instrumentation of method calls and field accesses in relevant classes
  12. 12. TRACESByte-code level Describe everything is going on in the application
  13. 13. TRACESByte-code level Describe everything is going on in the application Have a lot of information (Up to several MBs/sec)
  14. 14. WE NEED ABSTRACTION!
  15. 15. TRACE ANALYSIS
  16. 16. PACKAGE DEPENDENCY GRAPH A B
  17. 17. PACKAGE DEPENDENCY GRAPH packages A B
  18. 18. PACKAGE DEPENDENCY GRAPH packages A B call from a method in package A to a method declared in package B
  19. 19. ISOLATION OF FRAMEWORK CODE C A B D E The structure of the graph reflects the high level structure of the application
  20. 20. ISOLATION OF FRAMEWORK CODE C A B D E PLUG-IN The structure of the graph reflects the high level structure of the application
  21. 21. ISOLATION OF FRAMEWORK CODE C A B D E PLUG-IN FRAMEWORK The structure of the graph reflects the high level structure of the application
  22. 22. PLUG-IN CODE Code called only from other plug-in packages orA through special mechanisms (e.g. Reflection) EPLUG-IN
  23. 23. FRAMEWORK CODE C Called by plug-in code and only calls methods B D declared in framework packagesFRAMEWORK
  24. 24. EXAMPLEimport org.gjt.sp.jedit.buffer.JEditBuffer;import org.gjt.sp.jedit.buffer.FoldHandler;public class JavaFold extends FoldHandler { /* ... */ @Override public int getFoldLevel(JEditBuffer buffer, int lineIndex, Segment segment) { buffer.getLineText(lineIndex, segment); /* ... */ }}
  25. 25. EXAMPLE The plug-in extendsimport org.gjt.sp.jedit.buffer.JEditBuffer;import org.gjt.sp.jedit.buffer.FoldHandler; a framework classpublic class JavaFold extends FoldHandler { /* ... */ @Override public int getFoldLevel(JEditBuffer buffer, int lineIndex, Segment segment) { buffer.getLineText(lineIndex, segment); /* ... */ }}
  26. 26. EXAMPLE The plug-in extendsimport org.gjt.sp.jedit.buffer.JEditBuffer;import org.gjt.sp.jedit.buffer.FoldHandler; a framework classpublic class JavaFold extends FoldHandler { /* ... */ This is the method used @Override by the framework public int getFoldLevel(JEditBuffer buffer, int lineIndex, Segment segment) { buffer.getLineText(lineIndex, segment); /* ... */ }}
  27. 27. EXAMPLE The plug-in extendsimport org.gjt.sp.jedit.buffer.JEditBuffer;import org.gjt.sp.jedit.buffer.FoldHandler; a framework classpublic class JavaFold extends FoldHandler { /* ... */ This is the method used @Override by the framework public int getFoldLevel(JEditBuffer buffer, int lineIndex, Segment segment) { buffer.getLineText(lineIndex, segment); /* ... */} } The plug-in uses the framework
  28. 28. REMOVING IMPLEMENTATION DETAILS C A B D E PLUG-IN FRAMEWORK We are interested in code crossing the boundaries
  29. 29. A COMPACT REPRESENTATION
  30. 30. SO FAR We know the plug-in uses the frameworkWe don’t know the precise method we need
  31. 31. SO FAR We know the plug-in uses the frameworkWe don’t know the precise method we need WE SHOULD GUIDE THE USERDISCOVERY OF THE METHODS HE NEEDS
  32. 32. CALL TREES ABSTRACTION
  33. 33. CALL TREES ABSTRACTION
  34. 34. TRACE EXPLORATION• We still have too many call trees• Users should search the framework calls in term of the high level features they see• The framework may use a different terminology
  35. 35. TRACE EXPLORATION• We still have too many call trees• Users should search the framework calls in term of the high level features they see• The framework may use a different terminology USERS SHOULD BE ABLE TO SEARCH FOR THE MOST RELEVANT CALL TREES
  36. 36. FEATURE SEARCH High Level Query Search in class names, methods and documentation Matching call trees
  37. 37. SEARCH RESULT
  38. 38. CALL TREE EXPLORATION The user wants The user doesn’t want See matching methods Redundant information (loops)Know how to reach them Sub-trees with only plug-in code Navigate the tree Framework implementation See the documentation details
  39. 39. INTERACTIVE VISUALIZATION
  40. 40. INTERACTIVE VISUALIZATIONCompact representation of the call tree
  41. 41. INTERACTIVE VISUALIZATION DocumentationCompact representation of the call tree
  42. 42. INTERACTIVE VISUALIZATION DocumentationCompact representation of the call tree Framework code
  43. 43. TRACE MATCHING
  44. 44. THE SHORT TRACE IS NOT ENOUGHIt contains the code that causes the feature to execute It misses all the setup code WE NEED TO GET INFORMATION FROM A LARGER DATABASE
  45. 45. THE COMPLETE TRACEContains the compete execution of several runs of the application, exercising different featuresThis trace contains all the information we need to properly setup the plug-in
  46. 46. MATCHINGA demo and a complete trace match if: the corresponding method handles match call events in the complete trace are covered by the same package we found in the demo tracecalls that in demo share a receiver do it also in the complete trace
  47. 47. CODE SYNTHESIS
  48. 48. SYNTHESIS THROUGH SLICING We look for the minimal set of instruction (slice) that can reproduce the matched trace The result is code with holes that should be filled by the user to integrate the features he needs
  49. 49. THANK YOU!

×