+ All Categories
Home > Documents > Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

Date post: 12-Jan-2016
Category:
Upload: fynn
View: 26 times
Download: 1 times
Share this document with a friend
Description:
Minding the Gap Between Slicing and Refactoring (or “Fine Slicing: A new slicing technique to yield slices whose complements are slices too”). Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010 Joint work with Aharon Abadi and Yishai Feldman. - PowerPoint PPT Presentation
40
1 Minding the Gap Between Slicing and Refactoring (or “Fine Slicing: A new slicing technique to yield slices whose complements are slices too”) Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010 Joint work with Aharon Abadi and Yishai Feldman
Transcript
Page 1: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

1

Minding the GapBetween Slicing and Refactoring

(or “Fine Slicing: A new slicing technique to yield slices whose complements are slices too”)

Ran Ettinger, IBM Haifa Research LabCREST Open Workshop, King’s College, London

28 April 2010Joint work with Aharon Abadi and Yishai Feldman

Page 2: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

2

The gap is in the complement

• Both techniques care for syntax and semantics preservation, but– Syntactically…

• Slicing is about program decomposition• Refactoring is about program recomposition

– Semantically…• Slicing preserves a subset of the original behavior• Refactoring is expected to preserve the full

behavior (or functionality)

• Is the meaning of “extract” the same?

Page 3: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

3

Slice-Extraction Refactoring

• Make a slice of code reusable– Not merely copying and pasting it– Update the original code too, like in the “Extract

Method” refactoring

• Turn a non-contiguous slice into a contiguous fragment of code, before applying “Extract Method”– Rearrange the rest of the code

• Prepare parameters• Use slice results• Hide unwanted side-effects• Compute further results

– A kind of defragmentation

Page 4: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

4

TCP Example

• Taken from recent work on automatic recovery of state diagrams from procedural code* [Moria Abadi and Yishai Feldman, PLDE10]

• Recovery algorithm requires all state changes from a given state to occur in a single procedure– Precede recovery with refactoring when this is not the

case– Isolate state-changing code in called procedures and

move it all to a single procedure* Code example from Comer et al. 2004

Page 5: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

5

Is this a correct isolation step?int tcpclosing(Tcb ptcb, Ep pep) { ... result = tcbdealloc(ptcb); ...}

int tcbdealloc(Tcb ptcb) { if (ptcb.tcb_state == TCPS_FREE) return OK; switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq >= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); return SYSERR; } ptcb.tcb_state = TCPS_FREE; sdelete(ptcb.tcb_mutex); return OK;}

int tcpclosing(Tcb ptcb, Ep pep) { ... if (ptcb.tcb_type == TCPT_CONNECTION || ptcb.tcb_type == TCPT_SERVER)) ptcb.tcb_state = TCPS_FREE; result = tcbdealloc(ptcb); ...}int tcbdealloc(Tcb ptcb) { if (ptcb.tcb_state == TCPS_FREE) return OK; switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq >= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); return SYSERR; }

sdelete(ptcb.tcb_mutex); return OK;}

Page 6: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

6

A new slicing technique to assist in automated extraction

• Informally, a traditional (backward) slice of a given program with respect to selected “interesting” variables is a subprogram that computes the same values as the original program for the selected variables

• Accordingly, a (backward) fine slice of a given program with respect to selected “interesting” variables and other “oracle” variables is a subprogram that computes the same values as the original program for the selected variables, given values for the oracle variables

Page 7: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

7

Fine Slicing

• A generalization of traditional program slicing• Fine slices can be precisely bounded

– Slicing criteria include set of data and control dependences to ignore

• Fine slices are executable and extractable• Oracle-based semantics for fine slices• Algorithm for computing data-structure

representing the oracle• Forward fine slices are executable

– Might be larger than traditional forward slices

Page 8: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

8

Extract Computation

• A new refactoring

• Extracts a fine slice into contiguous code

• Computes the co-slice

• Computation can then be extracted into a separate method using Extract Method

• Passes necessary “oracle” variables between slice and co-slice

• Generates new containers if series of values need to be passed

Page 9: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

9

A Case Study inEnterprise Refactoring [WRT08-09]

• Converted a Java Servlet to use the MVC pattern, using a series of small refactoring steps*

• Inadequate automation for most steps• Most significant deficit in Extract Method

(a) Extract multiple fragments

(b) Extract a partial fragment

(c) Extract loop with partial body

(d) Extract code with conditional exits

• All 4 cases involve the extraction of fine slices* Based on: Alex Chaffee, “Refactoring to Model-View-Controller”

(http://www.purpletech.com/articles/mvc/refactoring-to-mvc.html)

Page 10: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

10

(a) Extract multiple fragmentsUser user = getCurrentUser(request);

if (user == null) {

response.sendRedirect(LOGIN_PAGE_URL);

return;

}

response.setContentType("text/html");

disableCache(response);

String albumName = request.getParameter("album");

PrintWriter out = response.getWriter();

Page 11: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

11

(b) Extract a partial fragment

out.println(DOCTYPE_HTML);

out.println("<html>");

out.println("<head>");

out.println("<title>Error</title>");

out.println("</head>");

out.print("<body><p class='error'>");

out.print("Could not load album '" +

albumName + "'");

out.println("</p></body>");

out.println("</html>");

Page 12: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

12

out.println("<table border=0>");

int start = page * 20;

int end = start + 20;

end = Math.min(end,

album.getPictures().size());

for (int i = start; i < end; i++) {

Picture picture = album.getPicture(i);

printPicture(out, picture);

}

out.println("</table>");

(c) Extract loop with partial body

1

2

3

4

5

6

7

8

9

10

Page 13: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

13

2

3

4

5

***

***

6

7

***

9

1

6

8

10

int start = page * 20;

int end = start + 20;

end = Math.min(end,

album.getPictures().size());

Queue<Picture> pictures =

new LinkedList<Picture>();

for (int i = start; i < end; i++) {

Picture picture = album.getPicture(i);

pictures.add(picture);

}

out.println("<table border=0>");

for (int i = start; i < end; i++)

printPicture(out, pictures.remove());

out.println("</table>");

Page 14: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

14

(d) Extract code with conditional exits

if (album == null) {

new ErrorPage("Could not load album '"

+ album.getName() + "'").printMessage(out);

return;

}

//...

Page 15: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

15

if (invalidAlbum(album, out))

return;

}

//...

boolean invalidAlbum(Album album,

PrintWriter out) {

boolean invalid = album == null;

if (invalid) {

new ErrorPage("Could not load album '"

+ album.getName() + "'").printMessage(out);

}

return invalid;

}

Page 16: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

16

++

out.println("<table border=0>");int start = page * 20;int end = start + 20;end = Math.min(end, album.getPictures().size());for (int i = start; i < end; i++) { Picture picture = album.getPicture(i); printPicture(out, picture);}out.println("</table>");

entry

println

out

*

album

getPictures

size

page

min

+ out

start

end

T F

>

getPicture

i

out

end

printPicture

out

out

println

i

"<table border=0>"

20

"</table>"

exit

p1

p1

p2

p2

Token Semantics

Page 17: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

17

++

out.println("<table border=0>");int start = page * 20;int end = start + 20;end = Math.min(end, album.getPictures().size());for (int i = start; i < end; i++) { Picture picture = album.getPicture(i); printPicture(out, picture);}out.println("</table>");

entry

println

out

*

album

getPictures

size

page

min

+ out

start

end

T F

>

getPicture

i

out

end

printPicture

out

out

println

i

"<table border=0>"

20

"</table>"

exit

printPicture

Fine Slicing

Page 18: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

18

++

out.println("<table border=0>");for (int i = start; i < end; i++) { printPicture(out, picture);}out.println("</table>");

entry

println

out

T F

>

i

out

end

printPicture

out

out

println

i

"<table border=0>"

"</table>"

exit

printPicture

startpicture

The Fine Slice

out

Page 19: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

19

++

out.println("<table border=0>");int start = page * 20;int end = start + 20;end = Math.min(end, album.getPictures().size());for (int i = start; i < end; i++) { Picture picture = album.getPicture(i); printPicture(out, picture);}out.println("</table>");

entry

println

out

*

album

getPictures

size

page

min

+ out

start

end

T F

>

getPicture

i

out

end

printPicture

out

out

println

i

"<table border=0>"

20

"</table>"

exit

printPicture

Co-Slicing

Page 20: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

20

++

out.println("<table border=0>");int start = page * 20;int end = start + 20;end = Math.min(end, album.getPictures().size());for (int i = start; i < end; i++) { Picture picture = album.getPicture(i); }

entry

*album

getPictures

size

min

+

start

end

T F

>

getPicture

i

end

out

i

20

exit

startpicture

The Co-Slice

page

Page 21: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

21

++

entry

*

album

getPictures

size

page

min

+

start

end

T F

>

getPicture

i

end

out

i

20

exit

startpicture

++

entry

println

out

T F

>

end

out

println

i

"<table border=0>"

"</table>"

exit

printPicture

startpicture

Fine slice Co-slice

out

Page 22: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

22

++

println

>

remove

printPicture println

++

out.println("<table border=0>");int start = page * 20;int end = start + 20;end = Math.min(end, album.getPictures().size());Queue<Picture> pictures = new LinkedList<Picture>();for (int i = start; i < end; i++) { Picture picture = album.getPicture(i); pictures.add(picture); printPicture(out,pictures.remove());}out.println("</table>");

entry

println

out

*

album

getPictures

size

page

min

+ out

start

end

T F

>

getPicture

i

out

end

printPicture

out

out

println

i

"<table border=0>"

20

"</table>"

exit

new

remove

add

picture

pictures

picture

pictures

pictures

Adding a Container

pictures

Page 23: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

23

++

println

<

remove

printPicture println

++

void display(PrintStream out, int start, int end, Queue<Picture> pictures){ out.println("<table border=0>"); for (int i = start; i < end; i++) { printPicture(out, pictures.remove()); } out.println("</table>");}

entry

println

out

out

start

T F

>

out

end

printPicture

out

println

i

"<table border=0>"

"</table>"

exit

pictures

remove

entry

i

out

The Fine Slice

pictures

pictures

picture

Page 24: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

24

++

println

>

remove

printPicture println

++

entry

println

out

*

album

getPictures

size

page

min

+ out

start

end

T F

>

getPicture

i

out

end

printPicture

out

out

println

i

"<table border=0>"

20

"</table>"

exit

new

remove

add

out.println("<table border=0>");int start = page * 20;int end = start + 20;end = Math.min(end, album.getPictures().size());Queue<Picture> pictures = new LinkedList<Picture>();for (int i = start; i < end; i++) { Picture picture = album.getPicture(i); pictures.add(picture); printPicture(out,pictures.remove());}out.println("</table>");

Program with

Container

pictures

pictures

pictures

pictures

picture

picture

Page 25: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

25

++

>

++

int start = page * 20;int end = start + 20;end = Math.min(end, album.getPictures().size());Queue<Picture> pictures = new LinkedList<Picture>();for (int i = start; i < end; i++) { Picture picture = album.getPicture(i); pictures.add(picture); }display(out,start,end, pictures);

entry

*

album

getPictures

size

page

min

+

out

start

end

T F

>

getPicture

i

end

i

20

exit

newpictures

add

display

pictures

start

out

The Co-Slice

pictures

pictures

pictures

picture

i

Page 26: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

26

int tcbdealloc(Tcb ptcb) { if (ptcb.tcb_state == TCPS_FREE) return OK; switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq >= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); return SYSERR; } ptcb.tcb_state = TCPS_FREE; sdelete(ptcb.tcb_mutex); return OK;}

Revisiting the TCP Example

Page 27: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

27

Slicing Unstructured Code [FSE09]p

q

• A plan-based slicing algorithm in two main stages– Compute initial slice by following all control and data

dependences– Complete the slice by identifying required control structure

• Lemma: “Let P be a surface plan, and let Q be a slice computed from P. If (p,q) is a control edge in Q, then every path from p to the exit in the source program P passes through q without passing through any other port of Q before it.”

• Theorem: “It is always possible to add to the slice a control path consisting of branches from the original program for every control edge in the plan. Regardless of which paths are chosen, two points in the resulting slice have a control path between them iff they are connected by a control path in the original program that does not go through any other point in the slice.”

– Proof for flat languages, with conditional and unconditional branch statements

• Precisely identifies the possible sets of branches (gotos, jumps) that may be added to the slice

• Any path in the original program can be chosen• Optimizations can be performed

Page 28: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

28

int tcbdealloc(Tcb ptcb) { if (ptcb.tcb_state == TCPS_FREE) return OK; switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq <= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); return SYSERR; } ptcb.tcb_state = TCPS_FREE; sdelete(ptcb.tcb_mutex); return OK;}

Control Flow Graph of Initial Slice

Exit

Entry

Page 29: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

29

int tcbdealloc(Tcb ptcb) { if (ptcb.tcb_state == TCPS_FREE) return OK; switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq <= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); return SYSERR; } ptcb.tcb_state = TCPS_FREE; sdelete(ptcb.tcb_mutex); return OK;}

Adding relevant branches (a)

Exit

Entry

Page 30: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

30

int tcbdealloc(Tcb ptcb) { if (ptcb.tcb_state == TCPS_FREE) return OK; switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq <= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); return SYSERR; } ptcb.tcb_state = TCPS_FREE; sdelete(ptcb.tcb_mutex); return OK;}

Adding relevant branches (b)

Exit

Entry

Page 31: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

31

int tcbdealloc(Tcb ptcb) { if (ptcb.tcb_state == TCPS_FREE) return OK; switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq <= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); return SYSERR; } ptcb.tcb_state = TCPS_FREE; sdelete(ptcb.tcb_mutex); return OK;}

Adding relevant branches (c)

Exit

Entry

Page 32: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

32

int tcbdealloc(Tcb ptcb) { if (ptcb.tcb_state == TCPS_FREE) return OK; switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq <= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); return SYSERR; } ptcb.tcb_state = TCPS_FREE; sdelete(ptcb.tcb_mutex); return OK;}

Adding relevant branches (d)

Exit

Entry

Page 33: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

33

int tcbdealloc(Tcb ptcb) { if (ptcb.tcb_state == TCPS_FREE) return OK; switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq <= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); return SYSERR; } ptcb.tcb_state = TCPS_FREE; sdelete(ptcb.tcb_mutex); return OK;}

Adding relevant branches (e)

Exit

Entry

Page 34: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

34

int tcbdealloc(Tcb ptcb) { if (ptcb.tcb_state == TCPS_FREE) return OK; switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq >= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); return SYSERR; } ptcb.tcb_state = TCPS_FREE; sdelete(ptcb.tcb_mutex); return OK;}

Complete Slice

Page 35: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

35

Isolated State-Changing Codeint tcbdealloc(Tcb ptcb) { int old_tcb_state = ptcb.tcb_state; if (ptcb.tcb_state == TCPS_FREE) goto L1; switch (ptcb.tcb_type) { case TCPT_CONNECTION: break; case TCPT_SERVER: break; default: goto L1; } ptcb.tcb_state = TCPS_FREE;L1: int new_tcb_state = ptcb.tcb_state; int result; ptcb.tcb_state = old_tcb_state; if (ptcb.tcb_state == TCPS_FREE) { result = OK; goto L2; }

switch (ptcb.tcb_type) { case TCPT_CONNECTION: tcpkilltimers(ptcb); sdelete(ptcb.tcb_ocsem); sdelete(ptcb.tcb_ssema); sdelete(ptcb.tcb_rsema); freemem(ptcb.tcb_sndbuf, ptcb.tcb_sbsize); freemem(ptcb.tcb_rcvbuf, ptcb.tcb_rbsize); if (ptcb.tcb_rsegq >= 0) freeq(ptcb.tcb_rsegq); break; case TCPT_SERVER: pdelete(ptcb.tcb_listenq, 0); break; default: signal(ptcb.tcb_mutex); result = SYSERR; goto L2; } sdelete(ptcb.tcb_mutex); result = OK;L2: ptcb.tcb_state = new_tcb_state; return result;}

Page 36: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

36

Related Work (I): (Non-)Executable Slices

• A wide range of slicing techniques which yield a non-executable* collection of program statements– Traditional backward slicing (e.g., Weiser, ICSE81 or

Ottenstein&Ottenstein, PSDE84), when applied to unstructured code• Solved by a designated stage in plan-based slicing (Abadi, Ettinger &

Feldman, FSE09)– Forward slicing (Horwitz, Reps & Binkley, TOPLAS90)– Barrier slicing (Krinke, SCAM03)– Chopping (Jackson & Rollins, FSE94) and Barrier Chopping (Krinke,

SCAM03)– Thin slicing (Sridharan, Fink & Bodik, PLDI07)

• Hypothesis: All the above can be made executable with an appropriate oracle, by adding the required control structure

* An executable slice is a program in itself, one that preserves the original program's behavior with respect to a given slicing criterion

Page 37: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

37

Related Work (II): Executable Slices with Reduced Scope or Size

• Other techniques for limiting the scope of slicing, for getting smaller and more focused slices:– Block-based slicing (Maruyama, SSR01): structured code only,

no correctness proof– Co-slicing (my thesis, 2006): limited to slicing from the end and

oracle of final values only; proof on toy language– Parametric slicing (Field, Ramalingam & Tip, POPL95): their

constrained slices are an executable generalization of static and dynamic slices; like oracle semantics, they formalize programs with holes; however, their hole stand for an expression whose value is irrelevant, while our hole stand for a significant (oracle) value to be sent as a parameter

– Some forms of dynamic and forward slicing are executable (Venkatesh, PLDI91; Binkley et al,. SCAM04): forward slices made excessively large through the addition of backward slices

Page 38: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

38

Related Work (III): Behavior Preserving Procedure Extraction

• Contiguous code– Bill Opdyke's thesis (UIUC, 92): for C++– Griswold&Notkin (ToSE93): for Scheme

• Arbitrary selections of (not necessarily contiguous) statements– Tucking (Lakhotia&Deprez, IST98): the complement is a slice too (from all non-extracted

points; no dataflow from the extracted slice to its complement yields over-duplication; strong preconditions (e.g., no global variables involved and no live-on-exit variable defined on both the slice and complement

– Semantics-Preserving Procedure Extraction (Komondoor&Horwitz, POPL00): considers all permutations of selected and surrounding statements; no duplication allowed; not practical (exponential time complexity)

– Effective Automatic Procedure Extraction (Komondoor&Horwitz, IWPC03): improves on their POPL00 algorithm by being more practical (cubic time and space), allowing some duplication (of conditionals and jumps); might miss some correct permutations though; no duplication of assignments or loops; allows dataflow from complementary to extracted code and from extracted code to (a second portion of) complementary code; supports exiting jumps

– Extraction of block-based slices (Maruyama, SSR01): extracts a slice of one variable only; restricted to structured code; no proof given

– My thesis (Sliding, 2006): sliding transformation, sequentially composes a slice and its complement, allowing dataflow from the former to the latter; supports loop untangling and duplication of assignments; but restricted to slicing from the end, and only final values from the extracted slice can be reused in the complement; proof for toy language

Page 39: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

39

Conclusion• Fine slicing is a generalization of program slicing

– It can be used to compute meaningful sub-programs• For extraction, in automated refactoring tools• For program understanding too

– Can be used to compute the complementary code required for correct refactoring• This work is part of a long-term research project focusing on advanced

enterprise refactoring tools, aiming to assist in daily software development on the one hand and in legacy modernization on the other

• The new Extract Computation refactoring for isolating fine slices is a crucial building block in this endeavor

– It will be used to enhance the automation for complex code-motion refactorings in order to support enterprise transformations such as the move to MVC [WRT08-09]

– As our prototype matures, it will be possible to evaluate to what extent such enterprise transformations can be automated

• Present and future work– Interprocedural fine slicing– Support for aliasing– Support interprocedural transformations– Automate a wide range of known refactorings, based on fine slicing and Extract

Computation

Page 40: Ran Ettinger, IBM Haifa Research Lab CREST Open Workshop, King’s College, London 28 April 2010

40

References

• Abadi, Ettinger, and Feldman, WRT08: Re-approaching the refactoring rubicon. Workshop on Refactoring Tools @ OOPSLA08.

• Abadi, Ettinger, and Feldman, WRT09: Fine slicing for advanced method extraction. Workshop on Refactoring Tools @ OOPSLA09.

• Abadi, Ettinger, and Feldman, FSE09: Improving slice accuracy by compression of data and control flow paths.

• M. Abadi&Feldman, PLDE10: Refactoring in multiple representations: code and statecharts.• Field, Ramalingam & Tip, POPL95: Parametric program slicing.• Griswold&Notkin, ToSE93: Automated assistance for program restructuring.• Horwitz, Reps & Binkley, TOPLAS90: Interprocedural slicing using dependence gaphs.• Jackson&Rollins, FSE94: A new model of program dependences for reverse engineering.• Komondoor&Horwitz, POPL00: Semantics-preserving procedure extraction.• Komondoor and Horwitz, IWPC03: Effective automatic procedure extraction.• Krinke, SCAM03: Barrier slicing and chopping.• Krinke et al., SCAM04: Formalizing executable dynamic and forward slicing.• Lakhotia&Deprez, IST98: Restructuring programs by tucking statements into functions.• Maruyama, SSR01: Automated method-extraction refactoring by using block-based slicing• My thesis, 2006: Refactoring via program slicing and sliding.• Opdyke’s PhD thesis, UIUC92: Refactoring Object-Oriented Frameworks.• Sridharan, Fink & Bodik, PLDI07: Thin slicing.• Venkatesh, PLDI91: The semantic approach to program slicing.• Weiser, ICSE81: Program slicing.


Recommended