50
PROGRAMMING BY IMITATION Mario Sangiorgio Kuat Yessenov Armando Solar-Lezama

Programming by imitation

Embed Size (px)

DESCRIPTION

The research project I worked at while I visited MIT

Citation preview

Page 1: Programming by imitation

PROGRAMMING BY IMITATIONMario SangiorgioKuat Yessenov

Armando Solar-Lezama

Page 2: Programming by imitation

PLUG-IN ARCHITECTURE

Core System

Application Programming Interface

New feature New feature New feature

Page 3: Programming by imitation

ISSUESIntegrating with the system is hard

Features need only a tiny part of the API

Integration requires several steps

Page 4: Programming by imitation

GOAL

Improve productivity by synthesizing the glue code.Programmers should only care about their features.

Page 5: Programming by imitation

IDEAS

Different plug-ins may need the same functionality from

the framework

Why don’t we imitate what existing plug-ins are doing?

Page 6: Programming by imitation

APPROACH

1. Show our tool what you want to do

2. Generate the code that imitates that feature

3. Put everything together and add your own code

Page 7: Programming by imitation

RECORDING THE EXECUTION

Keeping track of everything the application does

Page 8: Programming by imitation

TRACE ANALYSIS

Understanding which elements are related to the feature

Page 9: Programming by imitation

CODE SYNTHESIS

Generating the code imitating the feature

Page 10: Programming by imitation

TRACE COLLECTION

Page 11: Programming by imitation

DATA DRIVEN APPROACH

Lightweight instrumentation of method callsand field accesses in relevant classes

Page 12: Programming by imitation

TRACES

Byte-code level Describe everything is going on in the application

Page 13: Programming by imitation

TRACES

Have a lot of information(Up to several MBs/sec)

Byte-code level Describe everything is going on in the application

Page 14: Programming by imitation

WE NEED ABSTRACTION!

Page 15: Programming by imitation

TRACE ANALYSIS

Page 16: Programming by imitation

PACKAGE DEPENDENCY GRAPH

A B

Page 17: Programming by imitation

PACKAGE DEPENDENCY GRAPH

packages

A B

Page 18: Programming by imitation

PACKAGE DEPENDENCY GRAPH

packages

A B

call from a method in package A to a method declared in package B

Page 19: Programming by imitation

ISOLATION OF FRAMEWORK CODE

A B

C

D

E

The structure of the graph reflects the high level structure of the application

Page 20: Programming by imitation

PLUG-IN

ISOLATION OF FRAMEWORK CODE

A B

C

D

E

The structure of the graph reflects the high level structure of the application

Page 21: Programming by imitation

PLUG-IN FRAMEWORK

ISOLATION OF FRAMEWORK CODE

A B

C

D

E

The structure of the graph reflects the high level structure of the application

Page 22: Programming by imitation

PLUG-IN CODE

PLUG-IN

A

E

Code called only from other plug-in packages or

through special mechanisms (e.g. Reflection)

Page 23: Programming by imitation

FRAMEWORK CODE

Called by plug-in code and only calls methods

declared in framework packages

FRAMEWORK

B

C

D

Page 24: Programming by imitation

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); /* ... */ }}

Page 25: Programming by imitation

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); /* ... */ }}

The plug-in extends a framework class

Page 26: Programming by imitation

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); /* ... */ }}

The plug-in extends a framework class

This is the method used by the framework

Page 27: Programming by imitation

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); /* ... */ }}

The plug-in extends a framework class

This is the method used by the framework

The plug-in uses the framework

Page 28: Programming by imitation

PLUG-IN FRAMEWORK

REMOVING IMPLEMENTATION DETAILS

A B

C

D

E

We are interested in code crossing the boundaries

Page 29: Programming by imitation

A COMPACT REPRESENTATION

Page 30: Programming by imitation

SO FAR

We know the plug-in uses the framework

We don’t know the precise method we need

Page 31: Programming by imitation

SO FAR

We know the plug-in uses the framework

We don’t know the precise method we need

WE SHOULD GUIDE THE USER DISCOVERY OF THE METHODS HE NEEDS

Page 32: Programming by imitation

CALL TREES ABSTRACTION

Page 33: Programming by imitation

CALL TREES ABSTRACTION

Page 34: Programming by imitation

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

Page 35: Programming by imitation

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

Page 36: Programming by imitation

FEATURE SEARCHHigh Level

Query

Search in class names, methods and

documentation

Matching call trees

Page 37: Programming by imitation

SEARCH RESULT

Page 38: Programming by imitation

CALL TREE EXPLORATIONThe user wants The user doesn’t want

See matching methods

Know how to reach them

Navigate the tree

See the documentation

Redundant information (loops)

Sub-trees with only plug-in code

Framework implementation details

Page 39: Programming by imitation

INTERACTIVE VISUALIZATION

Page 40: Programming by imitation

INTERACTIVE VISUALIZATION

Compact representation of the call tree

Page 41: Programming by imitation

INTERACTIVE VISUALIZATION

Compact representation of the call tree

Documentation

Page 42: Programming by imitation

INTERACTIVE VISUALIZATION

Compact representation of the call tree

Documentation

Framework code

Page 43: Programming by imitation

TRACE MATCHING

Page 44: Programming by imitation

THE SHORT TRACE IS NOT ENOUGH

It contains the code that causes the feature to execute

It misses all the setup code

WE NEED TO GET INFORMATION FROM A LARGER DATABASE

Page 45: Programming by imitation

THE COMPLETE TRACE

Contains the compete execution of several runs of the application, exercising different features

This trace contains all the information we need to properly setup the plug-in

Page 46: Programming by imitation

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 trace

calls that in demo share a receiver do it also in the complete trace

Page 47: Programming by imitation

CODE SYNTHESIS

Page 48: Programming by imitation

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

Page 49: Programming by imitation
Page 50: Programming by imitation

THANK YOU!