java bytecode instrumentation - reconciling developer ...four quad-core intel xeon cpus e7340, 2.4...

33
Java Bytecode Instrumentation - Reconciling Developer Productivity Aibek Sarimbekov , Yudi Zheng, Danilo Ansaloni, Walter Binder University of Lugano, Lugano, Switzerland March 23rd 2013 Lubomir Bulej, Lukas Marek, Petr Tuma Charles University, Prague, Czech Republic Zhengwei Qi Shanghai Jiao Tong University, Shanghai, China

Upload: others

Post on 21-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

Java Bytecode Instrumentation - Reconciling Developer Productivity

Aibek Sarimbekov, Yudi Zheng, Danilo Ansaloni, Walter BinderUniversity of Lugano, Lugano, Switzerland

March 23rd 2013

Lubomir Bulej, Lukas Marek, Petr TumaCharles University, Prague, Czech Republic

Zhengwei QiShanghai Jiao Tong University, Shanghai, China

Page 2: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

2

Tools that observe relevant activities of running programs.Examples: ✦ profiling✦ debugging✦ testing✦ reverse engineering✦ program comprehension

Dynamic Program Analysis Tools

Page 3: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

3

base program

Instrumentation Classes

Instrumentation Classes vs. Analysis Classes

Page 4: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

base program

4

Instrumentation Classes

at instrumentation time

Instrumentation Classes vs. Analysis Classes

Page 5: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

5

base program Analysis Classes

at run-time

Instrumentation Classes vs. Analysis Classes

Page 6: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

6

BCEL

ASM

JavassistDiSL

Soot

jChord

Bytecode Instrumentation

Page 7: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

7

BCEL

ASM

JavassistDiSL

Soot

jChord

Bytecode Instrumentation

Which to use?

Page 8: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

8

Can we raise the abstraction level for writing dynamic analysis tools, allowing software engineers to rapidly develop custom analysis tools, impairing neither expressiveness nor tool performance?

Research Question

Page 9: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

9

ASMDiSL

VS.

Page 10: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

10

Empirical Study

✦ Controlled Experiment ✦ Recasts of 10 open-source DPA Tools

Page 11: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

11

DiSL: a DSL for Instrumentations

✦ Provide higher abstraction layer to write instrumentations✦ Reduce development effort for writing instrumentations ✦ Avoid shortcomings of AOP-based approach✦ Do not impair the performance of the resulting tools

Page 12: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

12

DiSL at a Glance

Language constructs✦ markers and snippets✦ static and dynamic context✦ scope and guards✦ synthetic and thread local variables

Page 13: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

13

DiSL Markers and Snippets Example

public class DiSL { @Before(marker = BasicBlockMarker.class) public static void onBB() { Profile.profileBB(); // count number of executed basic blocks of code } @AfterReturning(marker = BytecodeMarker.class, args = "new") public static void onAlloc() { Profile.profileAlloc(); // count the number of allocated objects }}

Page 14: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

14

DiSL Static Context Information Example

public class DiSL { @Before(marker = BasicBlockMarker.class) public static void onBB(MethodStaticContext msc, UniqueMethodId uid, BasicBlockStaticContext bbsc) { Profile.profileBB( msc.thisMethodFullName(), // full method name uid.get(), // unique method ID (int value) bbsc.getBBindex(), // basic block index (int value) bbsc.getBBSize() // bytecodes in the BB (int value) ); }}

Page 15: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

15

DiSL Dynamic Context Information Example

public class DiSL { @AfterReturning(marker = BytecodeMarker.class, args = "new") public static void onBB(DynamicContext dc) { // access allocated object Object allocObj = dc.getStackValue(0, Object.class); Profile.profileAlloc(allocObj); }}

Page 16: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

16

DiSL Scope and Guards Example

public class DiSL {

@Before(marker = BasicBlockMarker.class, scope = "TargetClass.*", // constrain instrumentation guard = LoopGuard.class) // constrain instrumentation public static void onBB(BasicBlockStaticContext bbsc) { Profile.profileBB(bbsc.getBBSize()); }}

public class LoopGuard { @GuardMethod public static boolean isApplicable(BasicBlockStaticContext bbsc) { return bbsc.isFirstOfLoop(); // instrument only first BBs of loops }}

Page 17: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

17

DiSL Synthetic Local Variables Examplepublic class DiSL {

@SyntheticLocal static int bbsSL; @SyntheticLocal static long sizeSL; @Before(marker = BasicBlockMarker.class) public static void onBB(BasicBlockStaticContext bbsc) { bbsSL++; sizeSL += bbsc.getBBSize(); } @After(marker = BodyMarker.class) public static void onMethodCompletion() { Profile.profileExecBytecodes(bbsSL, sizeSL); }}

Page 18: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

18

DiSL Thread Local Variables Example

public class DiSL {

@ThreadLocal static Profile profileTL; @Before(marker = BodyMarker.class, order = 1) public static void onMethodEntry() { if (profileTl == null) profileTL = new Profile(); } @Before(marker = BasicBlockMarker.class, order = 0) public static void onBB(BasicBlockStaticContext bbsc) { profileTL.profileBB(bbsc.getBBSize()); }}

Page 19: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

19

Empirical Study

✦ Controlled Experiment ✦ Recasts of 10 open-source DPA Tools

Page 20: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

20

1. Goal: to identify a framework that allows rapid development of correct DPA tools 2. Subjects: students from Shanghai Jiao Tong University3. Variables

✦ independent: use of ASM or DiSL✦ dependent: time, correctness

4. Tasks: 6 typical instrumentations

Controlled Experiment

Page 21: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

21

✦ Self-assessment Questionnaire✦ Tutorial on DPA✦ Distribution of tasks✦ Q&A Session✦ Experiment✦ Debriefing Questionnaire

Controlled Experiment: Procedure

Page 22: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

22

Controlled Experiment: Procedure! ! !!

Thank you for participating in our experiment. We very much appreciate your help. Please fill in the following questionnaire.

Participant’s details

1. Full name: ________________________________________

2. Contact e-mail address: _______________________________

3. Age: _______________

4. Gender: ! male ! female

5. Affiliation: ___________________________________________

6. Current highest academic degree:

! Bachelor student

! Master student

! Ph.D. student

! Professor

! Other: _______________

7. Experience level in:

None Beginner Knowledgeable Advanced Expert OOP ! ! ! ! ! Java ! ! ! ! !

Using Eclipse IDE !! !! !! !! !!Dynamic Program

Analysis !! !! !! !! !!

AspectJ !! !! !! !! !!ASM !! !! !! !! !!

Linux !! !! !! !! !!JVM and Java

bytecode !! !! !! !! !!

Page 23: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

23

0 - none 1 - beginner 2 - knowledgeable 3 - advanced 4 - expert

In total: 16 BSc, MSc, and PhD students

Controlled Experiment: Procedure

Page 24: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

24

20

40

60

80

100

120

140

160

180

Tim

e sp

ent [

min

utes

]

ASM DISL

5

10

15

20

25

Cor

rect

ness

[poi

nts]

ASM DISL

Controlled Experiment: Results

Page 25: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

25

Controlled Experiment: Results

descriptive statistics

Page 26: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

26

DiSL improves developer productivity compared to ASM. Results are both practically and statistically significant.

Controlled Experiment: Summary

Page 27: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

27

Empirical Study

✦ Controlled Experiment ✦ Recasts of 10 open-source DPA Tools

Page 28: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

28

10 open-source DPA tools.Metrics: ✦ Logical SLOC✦ Performance Overhead

Recasts

Page 29: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

29

500 1,500

500

1,500

Original

DiS

L-b

ased

ReCrash

TamiFlex

JCarder

Senseo

RacerAJ

Cobertura

JP2Emma

JRrat

Logical SLOC

Page 30: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

30

15x 30x 60x

15x

30x

60x

DiS

L-ba

sed

Cobertura

5x 10x 20x

5x

10x

20xEMMA

10x 20x 40x

10x

20x

40xHPROF*

3x 6x 12x

3x

6x

12xJCarder

5x 10x 20x

5x

10x

20xJP2

10x 20x 40x

10x

20x

40x

Original

DiS

L-ba

sed

JRat

35x 70x 140x

35x

70x

140x

Original

RacerAJ

10x 20x 40x

10x

20x

40x

Original

ReCrash

5x 10x 20x

5x

10x

20x

Original

Senseo

10x 20x 40x

10x

20x

40x

Original

TamiFlex

Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot 64-bit Server VM 1.6.0_29

- benchmarks from the Dacapo-9.12 suite

- geometric meanstartup

Performance Overhead

Page 31: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

31

25x 50x 100x

25x

50x

100x

DiS

L-ba

sed

Cobertura

5x 10x 20x

5x

10x

20xEMMA

20x 40x 80x

20x

40x

80xHPROF*

10x 20x 40x

10x

20x

40xJCarder

10x 20x 40x

10x

20x

40xJP2

20x 40x 80x

20x

40x

80x

Original

DiS

L-ba

sed

JRat

100x 200x 400x

100x

200x

400x

Original

RacerAJ

25x 50x 100x

25x

50x

100x

Original

ReCrash

15x 30x 60x

15x

30x

60x

Original

Senseo

5x 10x 20x

5x

10x

20x

Original

TamiFlex

Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot 64-bit Server VM 1.6.0_29

- benchmarks from the Dacapo-9.12 suite

- geometric meansteady-state

Performance Overhead

Page 32: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

32

Conclusions

RQ: Can we raise the abstraction level for writing dynamic analysis tools, allowing software engineers to rapidly develop custom analysis tools, impairing neither expressiveness nor tool performance?

Page 33: Java Bytecode Instrumentation - Reconciling Developer ...Four quad-core Intel Xeon CPUs E7340, 2.4 GHz, 16 GB RAM, Ubuntu GNU/Linux11.04 64-bit with kernel 2.6.38, Oracle Java HotSpot

33

Conclusions

RQ: Can we raise the abstraction level for writing dynamic analysis tools, allowing software engineers to rapidly develop custom analysis tools, impairing neither expressiveness nor tool performance?

A: yes, use DiSL!