averroes: letting go of the library!karim ali averroes: letting go of the library! partial-program...

63
Averroes: Letting go of the library! Karim Ali Workshop on WALA - PLDI ‘15 June 13th, 2015

Upload: others

Post on 10-Apr-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Averroes: Letting go of the library!

Karim Ali

Workshop on WALA - PLDI ‘15 June 13th, 2015

Page 2: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 2

public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!");}

}

Page 3: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

• ~ 8 seconds

• ~ 600 MB of memory

• > 900 reachable methods

• > 1,700 call edges3

public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!");}

}

Page 4: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Hello, World!

4

Page 5: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Partial-Program Analysis

5

Page 6: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Partial-Program Analysis

6

I'd like to ignore library code

what about callbacks?

this would be unsound but better than nothing

ignore non-application program elements (e.g., system libraries)?

whole-program analysis always pulls in the world for completeness.

The problem is that the world is fairly large

I am NOT interested in those

Page 7: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Partial-Program Analysis

7

?

Page 8: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 8

Ideal Call Graph

Page 9: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 9

Ideal Call Graph

Whole-Program Call Graph

Page 10: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 10

Ideal Call Graph

Whole-Program Call Graph

Incomplete Call Graph (unsound)

Page 11: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 11

Ideal Call Graph

Whole-Program Call Graph

Incomplete Call Graph (unsound)

Conservative Call Graph

(highly imprecise)

Page 12: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 12

Analyzed Code

?m(){ ...

}

c.center = new Point(0,0);

call method

create objectmodify field

Conservative Assumptions

Page 13: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Ideal Call Graph

Whole-Program Call Graph

Incomplete Call Graph (unsound)

Conservative Call Graph

(highly imprecise)

Partial-Program Call Graph

13

Page 14: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

The Separate Compilation Assumption

14

Page 15: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

The Separate Compilation Assumption

All of the library classes can be compiled in the absence of the application classes.

15

Page 16: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Constraints

1. Class Hierarchy

2. Class Instantiation

3. Local Variables

4. Method Calls

16

5. Field Access

6. Array Access

7. Static Initialization

8. Exception Handling

Page 17: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Constraints

1. Class Hierarchy

2. Class Instantiation

3. Local Variables

4. Method Calls

17

5. Field Access

6. Array Access

7. Static Initialization

8. Exception Handling

Page 18: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Library Points-to Set (LPT)

18

Application Library

pt(v1) = o1 o3

pt(v2) = o2 o3

pt(v3) = o1 o4

LPT =o1

o2 o3 o5

[Tip & Palsberg OOPSLA’00]

Page 19: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Library Callbacks

19

Application Library

class C { m(); }

class B extends L { m(); }

class A extends L { m(); } calls

class L { m(); }

1

LPT = A C

2

Page 20: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 20

[K. Ali and O. Lhoták, ECOOP ’13]

Page 21: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

JAR

Placeholder Library

SCA

JAR

21

Page 22: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 22

REF

REF

Placeholder Library

SCA

REF

averroes.Library

Application

Page 23: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 23

averroes.Library

Page 24: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 24

public class averroes.Library {

public static Object libraryPointsTo;public static void doItAll() {// Class instantiation

// Library callbacks

// Field writes

// Array element writes

// Exception Handling}

}

Page 25: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Evaluated for SOOT and DOOP

✓ 300x smaller library!

✓ Up to 15x faster analysis

✓ Up to 8x less memory

✓ Precise

✓ Sound

25

Page 26: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Implementation Tweaks

26

Page 27: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Class Loaders in WALA

27

ClassLoaderReference.Extension

ClassLoaderReference.Primordial

ClassLoaderReference.Application

Page 28: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Problem 1: App.methods()

28

ClassLoaderReference.Extension

ClassLoaderReference.Primordial

ClassLoaderReference.Application

public class Library {

public static void doItAll() {// Class instantiationA a = new A();

// Library callbacksa.foo();

}}

Page 29: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Problem 1: App.methods()

29

ClassLoaderReference.Extension

ClassLoaderReference.Primordial

ClassLoaderReference.Application

public class Library {

public static void doItAll() {// Class instantiationA a = new A();

// Library callbacksa.foo();

}}

Page 30: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Solution 1: App.methods()

30

ClassLoaderReference.Extension

ClassLoaderReference.Primordial

ClassLoaderReference.Application

public class Library {

public static void doItAll() {// Class instantiationA a = new A();

// Library callbacksa.foo();

}}

Page 31: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Problem 2: doItAll()

31

ClassLoaderReference.Extension

ClassLoaderReference.Primordial

ClassLoaderReference.Application

public class Library {

public static void doItAll() {...

}}

public class PrintStream {

public void println(String s) {...

Library.doItAll();...

}}

Page 32: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Solution

32

Page 33: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 33

public class AbstractLibrary {public static AbstractLibrary instance;public abstract void doItAll();

}

public class Library extends AbstractLibrary {static {

AbstractLibrary.instance = new Library();}

public void doItAll() {...A a = new A();

}}

public class PrintStream {public void println(String s) {

... AbstractLibrary.instance.doItAll();

...}

}

ClassLoaderReference.Primordial

ClassLoaderReference.Primordial

ClassLoaderReference.Application

Page 34: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 34

public class AbstractLibrary {public static AbstractLibrary instance;public abstract void doItAll();

}

public class Library extends AbstractLibrary {static {

AbstractLibrary.instance = new Library();}

public void doItAll() {...A a = new A();

}}

public class PrintStream {public void println(String s) {

... AbstractLibrary.instance.doItAll();

...}

}

ClassLoaderReference.Primordial

ClassLoaderReference.Primordial

ClassLoaderReference.Application

Page 35: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

public class AbstractLibrary {public static AbstractLibrary instance;public abstract void doItAll();

}

public class Library extends AbstractLibrary {static {

AbstractLibrary.instance = new Library();}

public void doItAll() {...A a = new A();

}}

public class PrintStream {public void println(String s) {

... AbstractLibrary.instance.doItAll();

...}

}

ClassLoaderReference.Primordial

ClassLoaderReference.Primordial

ClassLoaderReference.Application

35

Page 36: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Evaluation

36

Page 37: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Evaluation

• What are the performance gains of using the placeholder library?

• How precise is Averroes?

• Does using the placeholder library affect the soundness of WALA?

37

Page 38: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Library Size

38

SCA

Original Library ~ 25 MB

Placeholder Library ~ 80 KB

300xSMALLER

ON AVG

Page 39: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 39

Execution Time

WALAOverhead WALAAVEAnalysis WALAAVE

OverheadWALAAnalysis AVERROES

Exec

utio

n Ti

me

(s)

0

5

10

15

20

25

30

antlr bloat chart hsqldb luindex lusearch pmd xalan compress db jack javac jess raytrace

2xFASTER

ON AVG

Page 40: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 40

WALA WALAAVE

Memory UsageM

emor

y Us

age

(GB)

0.00.10.20.30.40.50.60.70.80.91.01.1

antlr bloat chart hsqldb luindex lusearch pmd xalan compress db jack javac jess raytrace

2xLESS

ON AVG

Page 41: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Precision of Averroes

41

Page 42: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

|WALAAVE \ WALA| |WALA|

ANTLR 2.06%BLOAT 19.66%CHART 22.76%HSQLDB 32.56%LUINDEX 4.35%LUSEARCH 10.45%

PMD 7.78%XALAN 33,100.00%

COMPRESS 0.00%DB 7.04%JACK 3.63%JAVAC 1.21%JESS 8.70%

RAYTRACE 0.00%42

Precision of Averroes

8%ON AVG

Page 43: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 43

Imprecise Library Callbacks

Application Library

JDBC Implementation

JDBC Interface

Client Code

WALAAVE \ WALA

HSQLDB org.hsqldb.jdbc.* 577 (70%)

Page 44: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Sound(i?)ness

44

Page 45: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 45

Unsoundness w.r.t. Dynamic Call Graphs|DYNAMIC \ WALA|

|DYNAMIC||DYNAMIC \ WALAAVE|

|DYNAMIC|ANTLR - -BLOAT - -CHART 6% 6%HSQLDB 4% 4%LUINDEX 1% -LUSEARCH 1% -

PMD 3% -XALAN 99% -

COMPRESS - -DB - -

JACK - -JAVAC - -JESS - -

RAYTRACE - -

Page 46: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Reasons for Unsoundness

46

public void notifyListeners(Event event) { Object[] ls = this.listenerList.getListenerList(); for (int i = ls.length - 2; i >= 0; i -= 2) { if (ls[i] == Listener.class) { ((Listener)ls[(i + 1)]).changed(event); } } }

Page 47: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Correctness ProofBased on Featherweight Java

47

Page 48: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 48

FJ…

m

m’

Page 49: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library! 49

FJ FJAVE…

m

m’

m

m’

Page 50: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Evaluation Summary

✓ 300x smaller library!

✓ 2x faster

✓ 2x less memory

✓ Precise

✓ Sound

50

Page 51: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

What’s Next?

51

Page 52: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Automatic Library Detection

What’s Next?Analyzing Large Frameworks

SCALACGSCA

DOOPSCA

Application Library

The Past The Future

Incremental JAR Generation

Better Reflection Support

Integration with WALA

52

Page 53: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Analyzing Large Frameworks

SCALACG

DOOP

The Future

53

• library is much larger than application • event-based systems => many callbacks • modeling application lifecycle is not trivial

Page 54: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

Better Reflection Support

SCALACG

DOOP

The Future

54

better support for reflection

automatic library detection

incremental JAR generation

Page 55: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Karim Ali Averroes: Letting go of the library!

WALA Averroes Analysis Scope

WALA Analysis Scope

Integration with WALA

SCALACG

DOOP

The Future

55

Page 56: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound
Page 57: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound
Page 58: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound
Page 59: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound
Page 60: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound
Page 61: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound
Page 62: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound
Page 63: Averroes: Letting go of the library!Karim Ali Averroes: Letting go of the library! Partial-Program Analysis 6 I'd like to ignore library code what about callbacks? this would be unsound

Averroes: Letting go of the library! Karim Ali

Technische Universität Darmstadt karimali.ca

https://github.com/karimhamdanali/averroes