andling of exceptions java points-to analysis · george kastrinis, yannis smaragdakis ~ efficient...

84
EFFICIENT AND EFFECTIVE HANDLING OF EXCEPTIONS IN JAVA POINTS-TO ANALYSIS George Kastrinis ~ Yannis Smaragdakis University of Athens

Upload: others

Post on 15-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

EFFICIENT AND EFFECTIVE

HANDLING OF EXCEPTIONS

IN JAVA POINTS-TO ANALYSIS

George Kastrinis ~ Yannis SmaragdakisUniversity of Athens

Page 2: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

● Huge amount of analysis time spent on exceptions

● They mainly affect control-flow

● Significant speedup from coarsening exceptions

● Type-based merging as an effective coarsening

● No trade-off in precision (in “normal” code)

● Datalog formalism makes changes clear

● Also excellent implementation platform

EXECUTIVE SUMMARY

Page 3: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EFFICIENT AND EFFECTIVE

HANDLING OF EXCEPTIONS

IN JAVA POINTS-TO ANALYSIS

Page 4: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EFFICIENT AND EFFECTIVE

HANDLING OF EXCEPTIONS

IN JAVA POINTS-TO ANALYSIS

What objects may a variable point to?(statically, object = allocation site)

Page 5: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EFFICIENT AND EFFECTIVE

HANDLING OF EXCEPTIONS

IN JAVA POINTS-TO ANALYSIS

Page 6: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

void foo (...) throws AnException {try {

...

throw new MyException();...

}

catch (OtherException e) { ... }}

REFRESHER ON EXCEPTIONS

Page 7: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

SIGNIFICANCE OF EXCEPTIONS

● Exceptions are non-local control flow

● They are also regular objects with data fields

● How significant is the data-flow of exceptions?

● Our research indirectly answers this

Page 8: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

FLOW OF OBJECTS

method

Page 9: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

NORMAL FLOW OF OBJECTS

methodarguments

return

Page 10: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EXCEPTIONAL FLOW OF OBJECTS

methodarguments

return

throw

Page 11: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

methodarguments

return

throw

Normal Flow

Exceptional Flow

VS

Page 12: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

Normal Flow VS Exceptional Flow

Which one do you think dominates?

● i.e., for the average method are there more objects that may be thrown outof it or that may be passed into/out

of it as args/returns?

Page 13: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

Normal Flow VS Exceptional Flow

normal flow exceptional flow

Which one do you think dominates?

Page 14: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

NEED PRECISE EXCEPTIONS?

Page 15: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

Not per se

NEED PRECISE EXCEPTIONS?

Page 16: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

Overall analysis effect

Not per se

NEED PRECISE EXCEPTIONS?

Page 17: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

COARSEN EXCEPTIONS

A. Context Insensitive

Page 18: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

A. Context Insensitive

B. Type-based Merging

COARSEN EXCEPTIONS

Page 19: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EFFICIENT AND EFFECTIVE

HANDLING OF EXCEPTIONS

IN JAVA POINTS-TO ANALYSIS

Page 20: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EFFICIENT AND EFFECTIVE

HANDLING OF EXCEPTIONS

IN JAVA POINTS-TO ANALYSIS

Page 21: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

INPUT

Page 22: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

v = new A();

to = from;

to = base.fld;base.fld = from;

void meth(..., A arg, ...) {...return ret;

}

base.sig(...);

JAVA CODE

Page 23: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

JAVA CODE AS TABLES

v = new A();

to = from;

to = base.fld;base.fld = from;

void meth(..., A arg, ...) {...return ret;

}

base.sig(...);

ALLOC (var, obj, meth)OBJTYPE (obj, type)

MOVE (to, from)

LOAD (to, base, fld)STORE (base, fld, from)

FORMALARG (meth, i, arg)

FORMALRETURN (meth, ret)

VCALL (base, sig, invo)

Page 24: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

JAVA CODE AS TABLES

v = new A();

to = from;

to = base.fld;base.fld = from;

void meth(..., A arg, ...) {...return ret;

}

base.sig(...);

ALLOC (var, obj, meth)OBJTYPE (obj, type)

MOVE (to, from)

LOAD (to, base, fld)STORE (base, fld, from)

FORMALARG (meth, i, arg)

FORMALRETURN (meth, ret)

VCALL (base, sig, invo)

Page 25: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

JAVA CODE AS TABLES

and many more...

v = new A();

to = from;

to = base.fld;base.fld = from;

void meth(..., A arg, ...) {...return ret;

}

base.sig(...);

ALLOC (var, obj, meth)OBJTYPE (obj, type)

MOVE (to, from)

LOAD (to, base, fld)STORE (base, fld, from)

FORMALARG (meth, i, arg)

FORMALRETURN (meth, ret)

VCALL (base, sig, invo)

Page 26: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

JAVA CODE AS TABLES

v = new A();

to = from;

to = base.fld;base.fld = from;

void meth(..., A arg, ...) {...return ret;

}

base.sig(...);

ALLOC (var, obj, meth)OBJTYPE (obj, type)

MOVE (to, from)

LOAD (to, base, fld)STORE (base, fld, from)

FORMALARG (meth, i, arg)

FORMALRETURN (meth, ret)

VCALL (base, sig, invo)

Blue is Input

and many more...

Page 27: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

OUTPUT

Page 28: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

OUTPUT

VARPOINTSTO (var, ctx, obj, objCtx)

most important...

Page 29: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

OUTPUT

VARPOINTSTO (var, ctx, obj, objCtx)

REACHABLE (meth, ctx)CALLGRAPH (invo, callerCtx, meth, calleeCtx)

most important...

“On the fly” construction

Page 30: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

OUTPUT

VARPOINTSTO (var, ctx, obj, objCtx)

REACHABLE (meth, ctx)CALLGRAPH (invo, callerCtx, meth, calleeCtx)

most important...

“On the fly” construction

Orange is Output

Page 31: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

CONTEXTS : BLACK BOX

VARPOINTSTO (var, ctx, obj, objCtx)

REACHABLE (meth, ctx)CALLGRAPH (invo, callerCtx, meth, calleeCtx)

Page 32: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

CONTEXTS CONSTRUCTORS

RECORD (...) = newObjCtx

MERGE (...) = newCtxPick Your Contexts Well:

Understanding Object-SensitivitySmaragdakis – Bravenboer – Lhotak

POPL'11

VARPOINTSTO (var, ctx, obj, objCtx)

REACHABLE (meth, ctx)CALLGRAPH (invo, callerCtx, meth, calleeCtx)

Page 33: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RULES

Page 34: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EXAMPLE RULE

P (x), Q (x, z) ← R (x, y, w), S (y, z).

Page 35: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EXAMPLE RULE

“Body”

If...

P (x), Q (x, z) ← R (x, y, w), S (y, z).

Page 36: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EXAMPLE RULE

“Body”

If...

“Head”

Then...

P (x), Q (x, z) ← R (x, y, w), S (y, z).

Page 37: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

REACHABLE (meth, ctx), ALLOC (var, obj, meth).

var = new ...

OBJECT ALLOCATION

Page 38: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

VARPOINTSTO (var, obj ) ←REACHABLE (meth, ctx), ALLOC (var, obj, meth).

var = new ...

OBJECT ALLOCATION

Page 39: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

VARPOINTSTO (var, ctx, obj ) ←REACHABLE (meth, ctx), ALLOC (var, obj, meth).

var = new ...

Variables share context with their methods

OBJECT ALLOCATION

Page 40: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RECORD (...) = objCtx,VARPOINTSTO (var, ctx, obj, objCtx) ←

REACHABLE (meth, ctx), ALLOC (var, obj, meth).

var = new ...

Construct a new object context

OBJECT ALLOCATION

Page 41: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

LOCAL ASSIGNMENTto = from

MOVE (to, from), VARPOINTSTO (from, ctx, obj, objCtx).

Page 42: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

to = from

VARPOINTSTO (to, ctx, obj, objCtx) ←MOVE (to, from), VARPOINTSTO (from, ctx, obj, objCtx).

LOCAL ASSIGNMENT

Page 43: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

to = from

Recursion

VARPOINTSTO (to, ctx, obj, objCtx) ←MOVE (to, from), VARPOINTSTO (from, ctx, obj, objCtx).

LOCAL ASSIGNMENT

Page 44: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EFFICIENT AND EFFECTIVE

HANDLING OF EXCEPTIONS

IN JAVA POINTS-TO ANALYSIS

NullPointerException

Page 45: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

INPUT

THROW (instr, e)CATCH (objT, instr, arg)

Page 46: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

INPUT

OUTPUT

THROWPOINTSTO (meth, ctx, obj, objCtx)

THROW (instr, e)CATCH (objT, instr, arg)

Page 47: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

“On the fly” handling of exceptions

INPUT

OUTPUT

THROWPOINTSTO (meth, ctx, obj, objCtx)

THROW (instr, e)CATCH (objT, instr, arg)

Exception Analysis and Points-to Analysis:Better Together

Bravenboer – Smaragdakis

ISSTA'09

Page 48: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

void meth() {...throw e;...

}

THROW (instr, e)

EXCEPTION RULES

Page 49: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

void meth() {...throw e;...

}

THROW (instr, e), VARPOINTSTO (e, ctx, obj, objCtx),OBJTYPE (obj, objT)

EXCEPTION RULES

Page 50: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

void meth() {...throw e;...

}

THROW (instr, e), VARPOINTSTO (e, ctx, obj, objCtx),OBJTYPE (obj, objT), ¬CATCH (objT, instr, _)

EXCEPTION RULES

Page 51: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

void meth() {...throw e;...

}

THROWPOINTSTO (meth, ctx, obj, objCtx) ←THROW (instr, e), VARPOINTSTO (e, ctx, obj, objCtx),OBJTYPE (obj, objT), ¬CATCH (objT, instr, _),INMETHOD (instr, meth).

EXCEPTION RULES

Page 52: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EXCEPTION RULES

void meth() {try {

throw e;}catch (objT arg) {...}

}

THROW (instr, e), VARPOINTSTO (e, ctx, obj, objCtx),OBJTYPE (obj, objT), CATCH (objT, instr, arg).

Page 53: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

void meth() {try {

throw e;}catch (objT arg) {...}

}

EXCEPTION RULES

VARPOINTSTO (arg, ctx, obj, objCtx) ←THROW (instr, e), VARPOINTSTO (e, ctx, obj, objCtx),OBJTYPE (obj, objT), CATCH (objT, instr, arg).

Page 54: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EXCEPTION RULES

Same logic for method invocation

Page 55: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

IS IT ENOUGH?

Page 56: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

NORMAL FLOW VS EXCEPTIONAL FLOW

antlr bloat eclipse luindex xalan0

1000

2000

3000

4000

5000

Context Insensitive

normal flow exceptional flow

(in th

ousa

nds)

antlr bloat eclipse luindex xalan0

20000

40000

60000

80000

1-Call-Site-Sensitive + Heap

normal flow exceptional flow

(in th

ousa

nds)

antlr bloat eclipse luindex xalan0

10000

20000

30000

40000

50000

1-Type-Sensitive + Heapnormal flow exceptional flow

(in th

ousa

nds)

Page 57: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EFFICIENT AND EFFECTIVE

HANDLING OF EXCEPTIONS

IN JAVA POINTS-TO ANALYSIS

Page 58: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EFFICIENT AND EFFECTIVE

HANDLING OF EXCEPTIONS

IN JAVA POINTS-TO ANALYSIS

Coarsen Exceptions

Page 59: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RECORD (...) = objCtx,VARPOINTSTO (var, ctx, obj, objCtx) ←

REACHABLE (meth, ctx), ALLOC (var, obj, meth).

Recall...

OBJECT ALLOCATION

Page 60: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RECORD (...) = objCtx,VARPOINTSTO (var, ctx, obj, objCtx) ←

REACHABLE (meth, ctx), ALLOC (var, obj, meth),OBJTYPE (obj, objT), ¬EXCEPTIONTYPE (objT).

Change to...

FILTER OUT EXCEPTIONS

Page 61: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

HANDLING EXCEPTIONS

REACHABLE (meth, ctx), ALLOC (var, obj, meth),OBJTYPE (obj, objT), EXCEPTIONTYPE (objT).

Page 62: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

HANDLING EXCEPTIONS

VARPOINTSTO (var, ctx, obj ) ←REACHABLE (meth, ctx), ALLOC (var, obj, meth),OBJTYPE (obj, objT), EXCEPTIONTYPE (objT).

Page 63: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

A. CONTEXT INSENSITIVE EXCEPTIONS

VARPOINTSTO (var, ctx, obj, ?) ←REACHABLE (meth, ctx), ALLOC (var, obj, meth),OBJTYPE (obj, objT), EXCEPTIONTYPE (objT).

Page 64: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

Single Context

VARPOINTSTO (var, ctx, obj, “ConstantObjCtx”) ←REACHABLE (meth, ctx), ALLOC (var, obj, meth),OBJTYPE (obj, objT), EXCEPTIONTYPE (objT).

A. CONTEXT INSENSITIVE EXCEPTIONS

Page 65: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

B. MERGE EXCEPTIONS

VARPOINTSTO (var, ctx, obj, “ConstantObjCtx”) ←REACHABLE (meth, ctx), ALLOC (var, obj, meth),OBJTYPE (obj, objT), EXCEPTIONTYPE (objT).

Not enoughGet more aggressive

Page 66: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

B. MERGE EXCEPTIONS

VARPOINTSTO (var, ctx, obj, “ConstantObjCtx”) ←REACHABLE (meth, ctx), ALLOC (var, obj, meth),OBJTYPE (obj, objT), EXCEPTIONTYPE (objT).

Page 67: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

B. MERGE EXCEPTIONS

VARPOINTSTO (var, ctx, reprObj, “ConstantObjCtx”) ←REACHABLE (meth, ctx), ALLOC (var, obj, meth),OBJTYPE (obj, objT), EXCEPTIONTYPE (objT),REPRESENTATIVE (obj, reprObj).

Page 68: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EXPERIMENTS

Page 69: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

EXPERIMENTS

JDK 1.6JDK 1.6

Page 70: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

Page 71: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

insensitive1object

1object+H2object+H

1type+H2type+H

1call-site1call-site+H

0

500

1000

1500

2000

2500Eclipse sensitive insensitive

(sec

onds

)

CONTEXT INSENSITIVE EXCEPTIONS

insensitive 1object 1object+H 1type+H 2type+H 1call-site 1call-site+H0

500100015002000250030003500

Bloat sensitive insensitive(s

econ

ds)

Page 72: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

insensitive1object

1object+H2object+H

1type+H2type+H

1call-site1call-site+H

0

200

400

600

800

1000

1200

Eclipse insensitive merge

(sec

onds

)

insensitive 1object 1object+H 1type+H 2type+H 1call-site 1call-site+H0

500

1000

1500

2000

2500

insensitive merge(s

econ

ds)

Bloat

MERGE EXCEPTIONS

Page 73: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

MERGE EXCEPTIONS

insensitive1object

1object+H2object+H

1type+H2type+H

1call-site1call-site+H

0

200

400

600

800

1000

1200

Eclipse insensitive merge

(sec

onds

)

insensitive 1object 1object+H 1type+H 2type+H 1call-site 1call-site+H0

500

1000

1500

2000

2500

insensitive merge(s

econ

ds)

Bloat

Speedup as high as 70%Usually around 50%

Page 74: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

insensitive 1object+H 2object+H 1type+H 1call-site+H0

10000

20000

30000

40000

Eclipse - Context Insensitive Exceptions normal flow exceptional flow

(in th

ousa

nds)

NORMAL FLOW VS EXCEPTIONAL FLOW

Page 75: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

insensitive 1object+H 2object+H 1type+H 1call-site+H0

5000

10000

15000

20000

Eclipse - Merge Exceptions normal flow exceptional flow

(in th

ousa

nds)

NORMAL FLOW VS EXCEPTIONAL FLOW

insensitive 1object+H 2object+H 1type+H 1call-site+H0

10000

20000

30000

40000

Eclipse - Context Insensitive Exceptions normal flow exceptional flow

(in th

ousa

nds)

Page 76: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

Page 77: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RECAP

● Huge amount of analysis time spent on exceptions

Page 78: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RECAP

● Huge amount of analysis time spent on exceptions

● They mainly affect control-flow

Page 79: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RECAP

● Huge amount of analysis time spent on exceptions

● They mainly affect control-flow

● Significant speedup from coarsening exceptions

Page 80: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RECAP

● Huge amount of analysis time spent on exceptions

● They mainly affect control-flow

● Significant speedup from coarsening exceptions

● Type-based merging as an effective coarsening

Page 81: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RECAP

● Huge amount of analysis time spent on exceptions

● They mainly affect control-flow

● Significant speedup from coarsening exceptions

● Type-based merging as an effective coarsening

● No trade-off in precision (in “normal” code)

Page 82: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RECAP

● Huge amount of analysis time spent on exceptions

● They mainly affect control-flow

● Significant speedup from coarsening exceptions

● Type-based merging as an effective coarsening

● No trade-off in precision (in “normal” code)

● Datalog formalism makes changes clear

Page 83: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis

RECAP

● Huge amount of analysis time spent on exceptions

● They mainly affect control-flow

● Significant speedup from coarsening exceptions

● Type-based merging as an effective coarsening

● No trade-off in precision (in “normal” code)

● Datalog formalism makes changes clear

● Also excellent implementation platform

Page 84: ANDLING OF EXCEPTIONS JAVA POINTS-TO ANALYSIS · George Kastrinis, Yannis Smaragdakis ~ Efficient and Effective Handling of Exceptions in Java Points-To Analysis Huge amount of analysis

Hope you enjoyed!George Kastrinis http://gkastrinis.info•