编辑: sunny爹 | 2017-09-03 |
3198 Client?Compiler?for?the?Java? HotSpot??Virtual?Machine Tom Rodriguez, Ken Russell Sun Microsystems, Inc.
Technology?and?Application S ession
3198 2 Overall?Presentation?Goal Learn about compilation in the J ava HotS pot? Virtual Machine, and the C lient C ompiler Understand how the C lient C ompiler deals with specific J ava? programming language features G et to know tuning and trouble-shooting techniques S ession
3198 3 Learning?Objectives ? As a result of this presentation, you will be able to: C Understand J ava HotS pot compilation C Write better code in the J ava programming language C Improve the performance of your applications C S ee what'
s new in 1.4 and what'
s coming S ession
3198 4 Speaker'
s?Qualifications ? Tom R odriguez is the technical lead for the J ava HotS pot C lient C ompiler ? K en R ussell has worked on the J ava HotS pot runtime and compiler for over two years S ession
3198 5 Presentation?Agenda ? C ompilation in the J ava HotS pot? VM ? S tructure of the C lient C ompiler ? Implications for C ode written in the J ava? P rogramming Language ? Miscellaneous ? S ummary ? Q &
A S ession
3198 6 Compilation?in?the Java?HotSpot??VM ? VM C onfigurations ? C ompilation S teps ? O n-S tack R eplacement ? C lass Hierarchy Analysis ? Deoptimization ? Q uick S ummary S ession
3198 7 VM?Configurations O S Libraries O S J ava Hardware libjvm.so/ jvm.dll T ypical J ava V M S oftware S tack ? C ore VM C lient C ompiler S erver C ompiler java java-client java-server T opic of T his T alk S ession
3198 8 Compilation?Steps ? E very method is interpreted first ? Hot methods are scheduled for compilation C Method invocations C Loops ? C ompilation can be foreground/ background C F oreground compilation default for C lient VM C Background compilation in parallel S ession
3198 9 On?Stack?Replacement?(1) ? C hoice between interpreted/compiled execution ? P roblem with long-running interpreted methods C Loops! ? Need to switch to compiled method in the middle of interpreted method execution C O n-S tack R eplacement (O S R ) S ession
3198 10 On?Stack?Replacement?(2) S tack before O S R void m1() { ... while (i <
n-1) { // OSR here ... } ... } dead m1 frame m0 frame S tack after O S R m1 compiled frame m1 interpreted frame m0 frame O S R S ession
3198 11 Class?Hierarchy?Analysis?(1) ? Dynamic pruning of receiver class set C S tatic calls instead of virtual calls C Inlining across virtual calls C F aster type tests ? C lass Hierarchy Analysis (C HA) C Analysis of loaded classes C C an change over time C E ffective S ession
3198 12 Class?Hierarchy?Analysis?(2) A virtual?m B virtual?m D virtual?n C virtual?m E virtual?n F extends loaded unloaded a.m A.m, B.m b.m B.m d.m A.m d.n D.n f.m A.m f.n D.n G virtual?m A a;
B b;
C c;
D d;
E e;
F f;
G g;
S ession
3198 13 Deoptimization?(1) ? C ompile-time assumptions may become invalid over time C C lass loading ? Debugging of program desired C S ingle-stepping ? Active compiled methods become invalid ? Need to switch to interpreted method in the middle of compiled method execution C Deoptimization S ession
3198 14 Deoptimization?(2) T3 m3(...) { ... // Deopt. here } T2 m2(...) { m3(...);
} T1 m1() { ... m2(...);
... } S tack m0 frame m1 interpreted m2 interpreted m3 interpr. m0 frame comp. m1 w/inlined m2, m3 frame Deopt. S ession
3198 15 Quick?Summary ? C lient VM differs from S erver V M in compiler ? Hotspots trigger compilation C C ompiled method invocation C O S R ? C lass loading, debugging changes compile-time assumptions C Deoptimization S ession