The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution...
Transcript of The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution...
![Page 1: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/1.jpg)
Estimating Path Execution Frequency Statically
Ray Buse Wes Weimer
THE ROAD NOT TAKEN
![Page 2: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/2.jpg)
2
The Big Idea
Developers often have a expectations about common and uncommon cases in programs
The structure of code they write can sometimes reveal these expectations
![Page 3: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/3.jpg)
3
Example
public V function(K k , V v) { if ( v == null ) throw new Exception();
if ( c == x ) r();
i = k.h();
t[i] = new E(k, v); c++;
return v;}
![Page 4: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/4.jpg)
4
Example
public V function(K k , V v) { if ( v == null ) throw new Exception();
if ( c == x ) restructure();
i = k.h();
t[i] = new E(k, v); c++;
return v;}
Exception
Invocation that changesa lot of the object state
Some computation
![Page 5: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/5.jpg)
5
Path 1
public V function(K k , V v) { if ( v == null ) throw new Exception();
if ( c == x ) restructure();
i = k.h();
t[i] = new E(k, v); c++;
return v;}
![Page 6: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/6.jpg)
6
public V function(K k , V v) { if ( v == null ) throw new Exception();
if ( c == x ) restructure();
i = k.h();
t[i] = new E(k, v); c++;
return v;}
Path 2
![Page 7: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/7.jpg)
7
Path 3
public V function(K k , V v) { if ( v == null ) throw new Exception();
if ( c == x ) restructure();
i = k.h();
t[i] = new E(k, v); c++;
return v;}
![Page 8: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/8.jpg)
8
HashTable: put
public V put(K key , V value) { if ( value == null ) throw new Exception();
if ( count >= threshold ) rehash();
index = key.hashCode() % length;
table[index] = new Entry(key, value); count++;
return value;}
*simplified from java.util.HashTable jdk6.0
![Page 9: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/9.jpg)
9
Intuition
How a path modifies program state may correlate with its runtime execution frequency
Paths that change a lot of state are rare Exceptions, initialization code, recovery code,
etc. Common paths tend to change a small
amount of state
Stack State + Heap State
![Page 10: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/10.jpg)
10
More Intuition
Number of branches Number of method invocations Path length Percentage of statements in a method
executed …
![Page 11: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/11.jpg)
11
Hypothesis
We can accurately predict the runtime frequency of program paths by analyzing their static surface features
Goals: Know what programs are likely to do without
having to run them (Produce a static profile) Understand the factors that are predictive of
execution frequency
![Page 12: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/12.jpg)
12
Our Path
Intuition Candidates for static profiles Our approach
a descriptive model of path frequency
Some Experimental Results
![Page 13: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/13.jpg)
13
Applications for Static Profiles
Indicative (dynamic) profiles are often hard to get
Profile information can improve many analyses Profile guided optimization Complexity/Runtime estimation Anomaly detection Significance of difference between program
versions Prioritizing output from other static analyses
![Page 14: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/14.jpg)
14
Approach
Model path with a set of features that may correlate with runtime path frequency
Learn from programs for which we have indicative workloads
Predict which paths are most or least likely in other programs
![Page 15: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/15.jpg)
15
Experimental Components
Path Frequency Counter Input: Program, Input Output: List of paths + frequency count for each
Descriptive Path Model Classifier
![Page 16: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/16.jpg)
16
Our Definition of Path
Statically enumerating full program paths doesn't scale
Choosing only intra-method paths doesn't give us enough information
Compromise: Acyclic Intra-Class Paths Follow execution from public method entry point
until return from class Don’t follow back edges
![Page 17: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/17.jpg)
17
Experimental Components
Path Frequency Counter Input: Program, Input Output: List of paths + frequency count for each
Descriptive Path Model Input: Path Output: Feature Vector describing the path
Classifier
![Page 18: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/18.jpg)
18
Count Coverage Feature• pointer comparisons• new
• this
• all variables• assignments• dereferences• • fields• • fields written• • statements in invoked method• goto stmts• if stmts• local invocations• • local variables• non-local invocations• • parameters• return stmts• statements• throw stmts
![Page 19: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/19.jpg)
19
Experimental Components
Path Frequency Counter Input: Program, Input Output: List of paths + frequency count for each
Descriptive Path Model Input: Path Output: Feature Vector describing the path
Classifier Input: Feature Vector Output: Frequency Estimate
![Page 20: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/20.jpg)
20
Classifier: Logistic Regression
Learn a logistic function to estimate the runtime frequency of a path
Likely to be taken
Not likely to be taken
Input path {x1, x2 … xn}
![Page 21: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/21.jpg)
21
Model Evaluation
Use the model to rank all static paths in the program
Measure how much of total program runtime is spent: On the top X paths for each method On the top X% of all paths
Also, compare to static branch predictors Cross validation on Spec JVM98 Benchmarks
When evaluating on one, train on the others
![Page 22: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/22.jpg)
22
Spec JVM 98 BenchmarksName Description LOC Methods Paths Paths/
MethodRuntime
check check VM features
1627 107 1269 11.9 4.2s
compress compression 778 44 491 11.2 2.91s
db data management
779 34 807 23.7 2.8s
jack parser generator
7329 304 8692 28.6 16.9s
javac compiler 56645 1183 13136 11.1 21.4s
jess expert system shell
8885 44 147 3.3 3.12s
mtrt ray tracer 3295 174 1573 9.04 6.17s
Total or Average
79338 1620 26131 12.6 59s
![Page 23: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/23.jpg)
23
Evaluation: Top Paths
Choose 5% of all paths and get 50%
of runtime behavior
Choose 1 path per method and get 94% of runtime
behavior
![Page 24: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/24.jpg)
24
Static Branch Prediction
At each branching node… Partition the path set
entering the node into two sets corresponding to the paths that conform to each side of the branch.
Record the prediction for that branch to be the side with the highest frequency path available.
a=b
c=d
if (a<c)
e=f g=h
Given where we’ve been, which
branch represents the highest
frequency path?
![Page 25: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/25.jpg)
25
Evaluation: Static Branch Predictor
We are even a reasonable choice for static branch
predictionBranch Taken;Forward Not
Taken
A set of heuristics
Always choose the higher frequency
path
![Page 26: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/26.jpg)
26
Model Analysis: Feature Power
Exceptions are predictive but rare
Many features
“tie”
Path length matters most
More assignment statements → lower
frequency
![Page 27: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/27.jpg)
27
Conclusion
A formal model that statically predicts relative dynamic path execution frequencies
A generic tool (built using that model) that takes only the program source code (or bytecode) as input and produces for each method, an ordered list of paths
through that method
The promise of helping other program analyses and transformations
![Page 28: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/28.jpg)
28
Questions? Comments?
![Page 29: The Road More Takencrest.cs.ucl.ac.uk/cow/1/slides/pathfreq_crest.pdf · Estimating Path Execution Frequency Statically Ray Buse Wes Weimer THE ROAD NOT TAKEN. 2 ... the runtime frequency](https://reader033.fdocuments.in/reader033/viewer/2022043012/5fa9c16b0d040448ad38aadd/html5/thumbnails/29.jpg)
29
Evaluation by Benchmark
1.0 = perfect
0.67 = return all or return nothing