Programming by imitation

Post on 30-Jun-2015

216 views 0 download

description

The research project I worked at while I visited MIT

transcript

PROGRAMMING BY IMITATIONMario SangiorgioKuat Yessenov

Armando Solar-Lezama

PLUG-IN ARCHITECTURE

Core System

Application Programming Interface

New feature New feature New feature

ISSUESIntegrating with the system is hard

Features need only a tiny part of the API

Integration requires several steps

GOAL

Improve 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 plug-ins are doing?

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

RECORDING THE EXECUTION

Keeping track of everything the application does

TRACE ANALYSIS

Understanding which elements are related to the feature

CODE SYNTHESIS

Generating the code imitating the feature

TRACE COLLECTION

DATA DRIVEN APPROACH

Lightweight instrumentation of method callsand field accesses in relevant classes

TRACES

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

TRACES

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

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

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 method declared in package B

ISOLATION OF FRAMEWORK CODE

A B

C

D

E

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

PLUG-IN

ISOLATION OF FRAMEWORK CODE

A B

C

D

E

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

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

PLUG-IN CODE

PLUG-IN

A

E

Code called only from other plug-in packages or

through special mechanisms (e.g. Reflection)

FRAMEWORK CODE

Called by plug-in code and only calls methods

declared in framework packages

FRAMEWORK

B

C

D

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

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

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

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

PLUG-IN FRAMEWORK

REMOVING IMPLEMENTATION DETAILS

A B

C

D

E

We are interested in code crossing the boundaries

A COMPACT REPRESENTATION

SO FAR

We know the plug-in uses the framework

We don’t know the precise method we need

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

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 level features they see

• The framework may use a different terminology

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

FEATURE SEARCHHigh Level

Query

Search in class names, methods and

documentation

Matching call trees

SEARCH RESULT

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

INTERACTIVE VISUALIZATION

INTERACTIVE VISUALIZATION

Compact representation of the call tree

INTERACTIVE VISUALIZATION

Compact representation of the call tree

Documentation

INTERACTIVE VISUALIZATION

Compact representation of the call tree

Documentation

Framework code

TRACE MATCHING

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

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

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

CODE SYNTHESIS

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

THANK YOU!