Presentation is loading. Please wait.

Presentation is loading. Please wait.

U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Method Profiling John Cavazos University.

Similar presentations


Presentation on theme: "U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Method Profiling John Cavazos University."— Presentation transcript:

1 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Method Profiling John Cavazos University of Delaware

2 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Method Profiling Counters Call Stack Sampling Combinations

3 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Method Profiling: Counters Insert method-specific counter on method entry and loop back edges Counts how often a method is called and approximate how much time is spent in a method Very popular approach: Self, HotSpot Issues: overhead for incrementing counter can be significant

4 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Method Profiling: Counters foo ( … ) { fooCounter++; if (fooCounter > Threshold) { recompile( … ); }... }

5 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Method Profiling: Call Stack Sampling Periodically record which method(s) on call stack Approximates amount of time spent in each method Can be compiled into the code Jikes RVM, JRocket or use hardware sampling Issues: timer-based sampling is not deterministic

6 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Method Profiling: Call Stack Sampling A B C A B A A B A B C A B C... Sample

7 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Method Profiling Mixed Combinations Use counters initially and sampling later on IBM DK for Java foo ( … ) { fooCounter++; if (fooCounter > Threshold) { recompile( … ); }... } A B C

8 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Method Profiling Mixed Software Hardware Combination Use interupts & sampling foo ( … ) { if (flag is set) { sample( … ); }... } A B C

9 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Recompilation Policies: Which Candidates to Optimize? Problem: given optimization candidates, which should be optimized? Counters: 1. Optimize method that surpasses threshold Simple, but hard to tune, doesn’t consider context 2. Optimize method on the call stack based on inlining policies Addresses context issue

10 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Recompilation Policies: Which Candidates to Optimize? Problem: given optimization candidates, which should be optimized? Call Stack Sampling: 1. Optimize all methods that are sampled Simple to implement 2. Use cost/benefit model Seemingly complicated, but easy to engineer Maintenance free Naturally supports multiple optimization levels

11 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Jikes RVM: Recompilation Policy – Cost/Benefit Model Define cur, current opt level for method m Exe(j), expected future execution time at level j Comp(j), compilation cost at opt level j Choose j > cur that minimizes Exe(j) + Comp(j) If Exe(j) + Comp(j) < Exe(cur) recompile at level j

12 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Jikes RVM: Recompilation Policy – Cost/Benefit Model Assumptions Sample data determines how long a method has executed Method will execute as much in the future as it has in the past Compilation cost and speedup are offline averages

13 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimization Levels Optimization Level Opt Level O0 Opt Level O1 Opt Level O2 Branch Opts Low Constant Prop / Local CSE Reorder Code Copy Prop / Tail Recursion Static Splitting / Branch Opt Med Simple Opts Low While into Untils / Loop Unroll Branch Opt High / Redundant BR Simple Opts Med / Load Elim Expression Fold / Coalesce Global Copy Prop / Global CSE SSA Optimizations Controlled

14 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Short Running Programs No FDO, Mar’04, AIX/PPC

15 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Short Running Programs No FDO, Mar’04, AIX/PPC

16 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Steady State No FDO, Mar’04, AIX/PPC

17 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Steady State

18 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Profiling for What to Do Myth: Sophisticated profiling is too expensive to perform online Reality: Well-known technology can collect sophisticated profiles with sampling and minimal overhead

19 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Method Profiling Timer Based class Thread scheduler (...) {... flag = 1; } void handler(...) { // sample stack, perform GC, swap threads, etc..... flag = 0; } foo ( … ) { // on method entry, exit, & all loop backedges if (flag) { handler( … ); }... } A B C Useful for more than profiling Jikes RVM Schedule garbage collection Thread scheduling policies, etc. if (flag) handler(); if (flag) handler(); if (flag) handler();

20 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Arnold-Ryder [PLDI 01]: Full Duplication Profiling Generate two copies of a method Execute “fast path” most of the time Execute “slow path” with detailed profiling occassionally Adapted by J9 due to proven accuracy and low overhead

21 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Suggested Reading Dynamic Compilation Adaptive optimization in the Jalapeno JVM, M. Arnold, S. Fink, D. Grove, M. Hind, and P. Sweeney, Proceedings of the 2000 ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages & Applications (OOPSLA '00), pages 47--65, Oct. 2000.


Download ppt "U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Method Profiling John Cavazos University."

Similar presentations


Ads by Google