yue li tian tan yulei sui jingling xue n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Yue Li , Tian Tan, Yulei Sui, Jingling Xue PowerPoint Presentation
Download Presentation
Yue Li , Tian Tan, Yulei Sui, Jingling Xue

Loading in 2 Seconds...

play fullscreen
1 / 92

Yue Li , Tian Tan, Yulei Sui, Jingling Xue - PowerPoint PPT Presentation


  • 143 Views
  • Uploaded on

Self- Inferencing Reflection Resolution for Java. Yue Li , Tian Tan, Yulei Sui, Jingling Xue. Complier Research Group @ UNSW, Australia. July 30, 2014. Static analysis for OO in practice ?. Static analysis for OO in practice ?. re re re … reflection !. Class Person {.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Yue Li , Tian Tan, Yulei Sui, Jingling Xue' - boone


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
yue li tian tan yulei sui jingling xue

Self-Inferencing Reflection

Resolution for Java

Yue Li, Tian Tan, Yulei Sui, Jingling Xue

Complier Research Group @ UNSW, Australia

July 30, 2014

slide3

Static analysis for OO in practice ?

re re re … reflection !

slide4

Class Person {

String name;

void setName(String nm) {…};

}

… …

Person p = new Person();

p.setName(“John”);

slide5

Class Person {

String name;

void setName(String nm) {…};

}

… …

Person p = new Person();

p.setName(“John”);

slide6

Class Person {

String name;

void setName(String nm) {…};

}

… …

Person p = new Person();

p.setName(“John”);

slide7

Class Person {

String name;

void setName(String nm) {…};

}

… …

Person p = new Person();

p.setName(“John”);

class

field

method

slide8

Class Person {

String name;

void setName(String nm) {…};

}

… …

Person p = new Person();

p.setName(“John”);

Metaobject !

Class

Method

Field

class

field

method

slide9

Class Person {

String name;

void setName(String nm) {…};

}

… …

Person p = new Person();

p.setName(“John”);

Metaobject !

Class

Method

Classc = Class.forName(“Person”);

Field

Methodm = c.getMethod(“setName”, …);

class

Object p = c.newInstance();

field

method

m.invoke(p, “John”);

slide10

Classc = Class.forName(“Person”);

Class Person {

Methodm = c.getMethod(“setName”, …);

String name;

Fieldf = c.getField(“name”);

void setName(String nm) {…};

Object p = c.newInstance();

}

… …

m.invoke(p, “John”);

Person p = new Person();

p.setName(“John”);

Metaobject !

Class

Method

Field

class

field

method

slide11

Classc = Class.forName(“Person”);

Class Person {

Methodm = c.getMethod(“setName”, …);

String name;

Fieldf = c.getField(“name”);

void setName(String nm) {…};

Object p = c.newInstance();

}

… …

m.invoke(p, “John”);

f.set(p, xx); / s = (String) f.get(p);

Person p = new Person();

p.setName(“John”);

Metaobject !

Class

Method

Field

class

field

method

slide12

Class Person {

String name;

void setName(String nm) {…};

Runtime

}

… …

Person p = new Person();

p.setName(“John”);

Metaobject !

Class

Method

Compile Time

Classc = Class.forName(“Person”);

Field

Methodm = c.getMethod(“setName”, …);

Fieldf = c.getField(“name”);

class

Object p = c.newInstance();

field

method

m.invoke(p, “John”);

f.set(p, xx); / s = (String) f.get(p);

slide13

Classc = Class.forName(cName);

Bug Detection

Methodm = c.getMethod(mName, …);

A a = new A();

Call graph edge

m.invoke(a, …);

method 1

method 3

method 2

B b = new B();

Fieldf = c.getField(“fld”);

Not Safe

Bug

f.set(a, a); // a.fld = a

a.fld = b;

B b2 = (B) a.fld;

Optimization

reflection analysis for java

How existing work handle reflection ?

(APLAS 2005)

Benjamin Livshits, John Whaley, and Monica S. Lam

Reflection Analysis for Java

reflection analysis for java1

How existing work handle reflection ?

(APLAS 2005)

Benjamin Livshits, John Whaley, and Monica S. Lam

Reflection Analysis for Java

reflection analysis for java2

How existing work handle reflection ?

(APLAS 2005)

Benjamin Livshits, John Whaley, and Monica S. Lam

Classc = Class.forName(“Person”);

Reflection Analysis for Java

Methodm = c.getMethod(“setName”, …);

Fieldf = c.getField(“name”);

Analyzing the string values of the arguments !

reflection analysis for java3

How existing work handle reflection ?

(APLAS 2005)

Benjamin Livshits, John Whaley, and Monica S. Lam

Classc = Class.forName(“Person”);

Reflection Analysis for Java

Methodm = c.getMethod(“setName”, …);

Fieldf = c.getField(“name”);

Configuration Files

Analyzing the string values of the arguments !

reflection analysis for java4

How existing work handle reflection ?

(APLAS 2005)

Benjamin Livshits, John Whaley, and Monica S. Lam

Classc = Class.forName(“Person”);

Reflection Analysis for Java

Command Lines

Methodm = c.getMethod(“setName”, …);

Fieldf = c.getField(“name”);

Configuration Files

Analyzing the string values of the arguments !

reflection analysis for java5

How existing work handle reflection ?

(APLAS 2005)

Benjamin Livshits, John Whaley, and Monica S. Lam

Classc = Class.forName(“Person”);

Reflection Analysis for Java

Command Lines

Methodm = c.getMethod(“setName”, …);

Fieldf = c.getField(“name”);

Complicated String

Operations

Configuration Files

Analyzing the string values of the arguments !

reflection analysis for java6

How existing work handle reflection ?

(APLAS 2005)

Benjamin Livshits, John Whaley, and Monica S. Lam

Can we do better ?

Reflection Analysis for Java

slide22

GOAL:

Analyze reflection in a better way

slide23

GOAL:

?

Analyze reflection in a better way

slide24

GOAL:

?

Analyze reflection in a better way

191 methods (Java Reflection API)

slide25

Three kinds of methods

Entry Methods

Member-introspecting Methods

Side-Effect Methods

slide26

Three kinds of methods

Entry Methods

Classc = Class.forName(“Person”);

Member-introspecting Methods

Side-Effect Methods

slide27

Three kinds of methods

Entry Methods

Classc = Class.forName(“Person”);

Member-introspecting Methods

Methodm = c.getMethod(“setName”, …);

Fieldf = c.getField(“name”);

Side-Effect Methods

slide28

Three kinds of methods

Entry Methods

Classc = Class.forName(“Person”);

Member-introspecting Methods

Methodm = c.getMethod(“setName”, …);

Fieldf = c.getField(“name”);

Side-Effect Methods

Object p = c.newInstance();

m.invoke(p, “John”);

f.set(p, xx); / s = (String) f.get(p);

slide30

Empirical Study

DaCapo (2006-10-MR2)

javac (1.7.0)

Eclipse (4.2.2)

jEdit (5.1.0)

Tomcat (7.0.42)

Jetty (9.0.5)

slide31

Empirical Study

DaCapo (2006-10-MR2)

javac (1.7.0)

Side-Effect Methods

Eclipse (4.2.2)

Demand-driven

jEdit (5.1.0)

Tomcat (7.0.42)

Manually

Jetty (9.0.5)

slide32

Empirical Study

DaCapo (2006-10-MR2)

javac (1.7.0)

Side-Effect Methods

Eclipse (4.2.2)

Demand-driven

jEdit (5.1.0)

Tomcat (7.0.42)

Manually

Jetty (9.0.5)

Side-Effect callsites: 609

Member-Introspecting callsites: 304

Entry callsites: 501

slide33

Empirical Study

DaCapo (2006-10-MR2)

javac (1.7.0)

Side-Effect Methods

Eclipse (4.2.2)

Useful findings

Demand-driven

jEdit (5.1.0)

Tomcat (7.0.42)

Manually

Jetty (9.0.5)

Side-Effect callsites: 609

Member-Introspecting callsites: 304

Entry callsites: 501

slide38

Self-Inferencing Property

Class Person {

String name;

void setName(String nm) {…};

}

Person p = new Person();

Classc = Class.forName(“Person”);

Fieldf = c.getField(“name”);

String s = (String) f.get(p);

// s = p.f

slide39

Self-Inferencing Property

Class Person {

String name;

void setName(String nm) {…};

}

Person p = new Person();

Classc = Class.forName( ? );

Fieldf = c.getField(“name”);

String s = (String) f.get(p);

// s = p.f

slide40

Self-Inferencing Property

Class Person {

String name;

void setName(String nm) {…};

}

Person p = new Person();

Classc = Class.forName( ? );

Fieldf = c.getField(”name”);

String s = (String) f.get(p);

// s = p.f

slide41

Self-Inferencing Property

Class Person {

String name;

void setName(String nm) {…};

}

Person p = new Person();

Classc = Class.forName( ? );

Fieldf = c.getField(”name”);

String s = (String) f.get(p);

// s = p.f

slide42

Self-Inferencing Property

Class Person {

String name;

void setName(String nm) {…};

}

Person p = new Person();

Classc = Class.forName(“Person”);

Fieldf = c.getField( ? );

String s = (String) f.get(p);

// s = p.f

slide43

Self-Inferencing Property

Class Person {

String name;

void setName(String nm) {…};

}

Person p = new Person();

Classc = Class.forName(“Person”);

Fieldf = c.getField( ? );

String s = (String) f.get(p);

// s = p.f

slide44

Self-Inferencing Property

Class Person {

String name;

void setName(String nm) {…};

}

Person p = new Person();

Classc = Class.forName(“Person”);

Fieldf = c.getField( ? );

String s = (String) f.get(p);

// s = p.f

slide45

ELF

Self-inferencing Reflection Resolution for Java

slide46

Intuition

When string arguments cannot be resolved statically

Infer the reflective targets at their usage points

slide49

ELF

class name known

slide50

ELF

class name known

slide51

ELF

class name known

slide52

ELF

class name known

method/field name known

slide53

ELF

class name known

method/field name known

slide54

ELF

class name unknown

method/field name known

slide55

ELF

class name unknown

method/field name known

slide56

ELF

class name known

method/field name unknown

slide57

ELF

class name known

method/field name unknown

slide69

Example

50 targets

48!

ELF

slide70

ELF

207 rules

Most comprehensive in

handling reflection API

Open source

http://www.cse.unsw.edu.au/~corg/elf/

slide71

Evaluation

DOOPvs ELF

slide72

The number of resolved reflective callsites

Method:

invoke

Field:

get

Field:

set

slide73

Precision Comparison

DOOP & ELF unsound

DOOP

(class type)

ELF

(class type + method/field signature)

Callsites & targets

Recall (TamiFlex + DaCapo inputs)

For most targets

slide74

The number of resolved reflective targets

Method:

invoke

Field:

get

Field:

set

slide75

The number of resolved reflective targets

Method:

invoke

Field:

get

Field:

set

slide76

The number of resolved reflective targets

Method:

invoke

Field:

get

Class: org.eclipse.osgi.util.NLS

Field:

set

Two set() callsites

Initialize all non-final static fields in 4 classes

552 in total

slide77

The number of resolved reflective targets

Method:

invoke

Field:

get

Class: org.eclipse.osgi.util.NLS

Field:

set

Two set() callsites

Initialize all non-final static fields in 4 classes

552 in total

slide79

DOOP: 2 callsites

ELF: 8 callsites

DOOP: 6 callsites

ELF: 26 callsites

slide80

The invoke() case: 48 true targets

ELF resolves 50 at that callsite

48 x 2 = 96 targets

DOOP: 2 callsites

ELF: 8 callsites

DOOP: 6 callsites

ELF: 26 callsites

slide81

Recall Experiment

TAMIFLEX (ICSE 2011)

DaCapo Inputs: small, default and large

All true targets resolved by DOOP can be resolved by ELFexceptone special case

slide82

Recall Experiment

TAMIFLEX (ICSE 2011)

DaCapo Inputs: small, default and large

All true targets resolved by DOOP can be resolved by ELFexceptone special case

DOOP: spurious  true field target

in jython accidentally

slide83

Scalability

Comparing ELF and DOOP in term of analysis times (secs)

ELF: 1.9X slowdown on average with hsqldbdisregarded

slide84

Conclusion

Study: useful findings on reflection usage

ELF: a self-inferencing resolution approach

An open-source implementation

slide85

http://www.cse.unsw.edu.au/~corg/elf/

Static analysis for OO in practice ?

Self-Inferencing Property

Reflection

slide86

Conclusion

Study: useful findings on reflection usage

ELF: a self-inferencing resolution approach

An open-source implementation

Potential Impact

Reflection

Analysis

Many Popular Frameworks (e.g., Chord)

& Hundreds of Papers

slide87

Conclusion

Study: useful findings on reflection usage

ELF: a self-inferencing resolution approach

An open-source implementation

Potential Impact

Reflection

Analysis

ELF

Many Popular Frameworks (e.g., Chord)

& Hundreds of Papers

slide88

Conclusion

Study: useful findings on reflection usage

ELF: a self-inferencing resolution approach

An open-source implementation

Potential Impact

Reflection

Analysis

ELF

Nothing needs

to change

Many Popular Frameworks (e.g., Chord)

& Hundreds of Papers

slide89

Conclusion

Study: useful findings on reflection usage

ELF: a self-inferencing resolution approach

An open-source implementation

Potential Impact

Reflection

Analysis

ELF

More bugs, etc.

Nothing needs

to change

Many Popular Frameworks (e.g., Chord)

& Hundreds of Papers

slide92

Thank You

Yue Li

CORG @ UNSW, Australia

July 30, 2014