Mais conteĂşdo relacionado Semelhante a Jug.ru 2014-j rockit architecture copy (20) Mais de Marcus Lagergren (6) Jug.ru 2014-j rockit architecture copy4. Safe'Harbor'Statement'
The following is intended to outline our
general product direction. It is intended for
information purposes only, and may not be
incorporated into any contract. It is not a
commitment to deliver any material, code, or
functionality, and should not be relied upon
in making purchasing decisions.
The development, release, and timing of any
features or functionality described for
Oracles products remains at the sole
discretion of Oracle.
5. Agenda'
⢠In'the'beginningâŚ'
⢠What'did'we'accomplish'/'Internals'
â Code'Genera*on'
â Memory'Management'
â Threads''Synchroniza*on'
⢠Externals'
â The'Java'Mission'Control'suite'
â A'parenthesis'on'JRockit'VE'
⢠QA'
9. About'the'speaker'
⢠M.'Sc.'from'KTH,'Stockholm'
â Narrowly'escaped'doing'a'PhD'on'bit'security'in'
cryptographic'systems'
⢠Run*me,'OS'and'compiler'engineer'since'
1999,'with'some'startup'breaks'
⢠One'of'the'original'creators'of'the'JRockit'JVM'
38. ⢠The'benchmark'wars'
â Constantly'keeping'it'going'with'Sun'and'IBM,'
driving'Java'server[side'performance'
'
The'real'value'adds'turned'out'to'be:''
44. ButâŚ'
⢠Startup'became'a'problem'
â We'removed'op*mizers'and'added'as'a'âspineâ'to'
the'normal'JIT'pipeline.''
⢠Lazy'code'genera*on'through'trampolines'
⢠Same'mechanism'for'code'invalida*on'
⢠Bookkeeping'to'iden*fy'a'program'point'
down'to'any'individual'machine'instruc*on'
47. Op*miza*ons'
⢠In'and'out'of'SSA'
⢠Applied'to'all'levels'of'IR'
â Loop%peeling,%value%numbering,%String%append%explosion,%Type%check%removal,%
sign%extension%elimina;on,%copy%propaga;on,%bounds%check%removal,%virtual%to%
fixed%calls,%inlining,%if%short%circui;ng,%straightening,%strength%reduc;on,%
constant%propaga;on,%dead%code%removal,%out%of%loop%hois;ng,%explode%
objects%and%array%copies,%boxing%%unboxing%removal,%local%escape%analysis,%
ASM%peephole%op;miza;on,%redundant%memory%access%removal,%etc%etc%etcâŚ%
⢠Support'for'regionalized'IRs'
⢠Graph'Fusion'Register'Allocator'
48. Op*miza*on'Targets'
⢠Thread'sampling'
⢠Partly'taken'over'by'safe'point'based'
approach'in'R28'
⢠Some'code'instrumenta*on,'for'example'for'
inlining'path'
â Not'in'the'general'case,'e.g'invoca*on'counters'
49. Op*miza*on'Targets'
⢠Hardware'sampling'where'available'
â Only'good'thing'about'IA64?'
â Could'also'match'e.g.'L2'misses'to'program'points'
⢠Bugging'the'processor'manufacturers'since'
2002'about'userland'PC'sample'buffer.'
⢠JRockit'VE'x'1000'more'samples'â'significantly'
proven'shorter'warmup'
52. HotSpot'Style'OSR'and'Deop*miza*on'
⢠Weâve'never'found'a'prac*cal'use'case.''
â So'we'canât'ever'swap'out'the'main'func*on'with'the'
microbenchmark'loop.'Who'cares?'
⢠An'assump*on'is'invalidated'
â Either'patch'code'directly'or'use'a'guard'when'
genera*ng'it'in'the'first'place'
⢠A'large'assump*on'
â Write'a'trap'in'the'code'and'schedule'lazy'
regenera*on'of'en*re'method'
⢠Not'strictly'true'for'dynamic'languages'
53. HotSpot'Style'OSR'and'Deop*miza*on'
⢠Weâve'never'found'a'prac*cal'use'case.''
â So'we'canât'ever'swap'out'the'main'func*on'with'the'
microbenchmark'loop.'Who'cares?'
⢠An'assump*on'is'invalidated'
â Either'patch'code'directly'or'use'a'guard'when'
genera*ng'it'in'the'first'place'
⢠A'large'assump*on'
â Write'a'trap'in'the'code'and'schedule'lazy'
regenera*on'of'en*re'method'
⢠Not'strictly'true'for'dynamic'languages'
54. HotSpot'Style'OSR'and'Deop*miza*on'
⢠Weâve'never'found'a'prac*cal'use'case.''
â So'we'canât'ever'swap'out'the'main'func*on'with'the'
microbenchmark'loop.'Who'cares?'
⢠An'assump*on'is'invalidated'
â Either'patch'code'directly'or'use'a'guard'when'
genera*ng'it'in'the'first'place'
⢠A'large'assump*on'
â Write'a'trap'in'the'code'and'do'regenera*on'of'en*re'
method'
⢠Not'strictly'true'for'dynamic'languages'
55. HotSpot'Style'OSR'and'Deop*miza*on'
⢠Weâve'never'found'a'prac*cal'use'case.''
â So'we'canât'ever'swap'out'the'main'func*on'with'the'
microbenchmark'loop.'Who'cares?'
⢠An'assump*on'is'invalidated'
â Either'patch'code'directly'or'use'a'guard'when'
genera*ng'it'in'the'first'place'
⢠A'large'assump*on'
â Write'a'trap'in'the'code'and'do'regenera*on'of'en*re'
method'
⢠Not'strictly'true'for'dynamic'languages'
59. The'IR'
⢠Use'IR'everywhere'(or'Java)'
⢠The'IR'should'ideally'reflect'any'of'several'
pluggable'frontends.' ''
â We'played'around'with'CLR'a'bit.'
â These'days'â'dynamic'languages':[)'
⢠No'Sea'of'Nodes'
⢠No'HotSpot'style'âhigh'level'IR'is'low'
levelâ'
71. Memory'management'
⢠Concurrent'collec*on'
â Your'basic'genera*onal'concurrent'mark'and'
sweep'collector'[Printezis,'Detlefs]'
â Supports'mul*'genera*on'(1)'young'spaces.'
⢠Combats'heavy'object'alloca*on'situa*ons.'
⢠Adap*vely'balanced'against'copy'overhead'
â Write'barriers'before'object'writes'
â Minimize'stopping'the'world'
â Young'collec*ons'use'a'variant'of'stop''copy'
74. Mark''Sweep'
⢠Two'colors'â'not'three.'
â Object'is'in'one'of'two'sets'
â Live'objects:'grey'bits'(mix'of'grey''black'
objects'in'tradi*onal'tri[coloring)'
â Dis*nc*on'handled'by'pu~ng'grey'objects'in'
thread'local'queues'for'each'GC'thread.''
â Parallel'threads'can'work'on'thread'local'data'
â Efficient'prefetching'is'possible'due'to'FIFO'
order.'
78. Other'nice'features'
⢠No'permgen!!!'Ever!'
⢠Pinned'objects.'
â Fast'memory'buffers.'
â Also'enable'non[con*guous'heaps.'
⢠Compac*on'
â âInternal'and'externalâ.''
â G1'evacuates'regions'instead'with'a'stop'the'
world[and[copy'policy'similar'to'JRockit'YC'
79. Memory'management'
⢠Concurrent'GC'has'an'addi*onal'set:'live'bits'
â Contains'all'live'objects'in'the'system,'including'
the'newly'created'ones.''
â JRockit'can'quickly'find'objects'that'have'been'
created'during'a'concurrent'mark'phase.''
â Card'tables''
⢠Not'just'for'genera*onal'GC'
⢠Also'to'avoid'searching'the'en*re'live'object'graph'
when'a'concurrent'mark'phase'cleans'up.'
⢠Just'look'at'dirty'cards'at'the'end'of'the'mark'phase.'
81. Young'Collec*ons'
⢠Young'and'old'collec*ons'may'occur'at'same'
*me.'
â All'bit'sets'and'data'structures'can'be'shared'as'
long'as'the'old'collec*on'is'guaranteed'to'see'all'
cards'that'have'become'dirty'during'a'
concurrent'phase.'(Extra'card'table'to'record'this'
âdifferenceâ'â'âmodified'union'setâ)''
â Keep'this'intact'for'old'collec*on'
84. Compressed'References'
⢠For'less'than'4'(or'4'*'x)'GB'of'maximum'
heap'size'
⢠Use'32'bit'pointers'(or'32'+'log2(x)'bits)'
CompRef compress(Ref ref) {
return (uint32_t)ref; //truncate reference to 32-bits
}
Ref decompress(CompRef ref) {
return globalHeapBase | ref;
}
CompRef compress(Ref ref) {
return (uint32_t)(ref log
(objectAlignment));
2
}
Ref decompress(CompRef ref) {
return globalHeapBase | (ref log
(objectAlignment));
2
}
87. Determinis*c'GC'â'How?'
⢠Greedy'strategy'
â Postpone'stopping'the'world'for'as'long'as'
possible.'
â Maybe'the'problem'goes'away'and'we'donât'have'
to'stop'the'world'
⢠Split'up'everything'into'work'packets'
â Drop'them'at'any'*me.'
90. Threads'and'Synchroniza*on'
⢠A'java.lang.Thread'is'a'na*ve'thread.'
â Interes*ng,'though:'thread'pooling'and'
pseudo'thin[threads'are'back,'for'example'in'
Akka.'
â Java'8'â'Collection.parallelStream
â The'world'is'moving'towards'implicit'
parallelism'in'general'
⢠Most'of'the'JRockit'thread'code'and'
adap*vity'logic'is'wriden'in'Java'
92. Threads'and'Synchroniza*on'
public class PseudoSpinlock {
private static final int LOCK_FREE = 0;
private static final int LOCK_TAKEN = 1;
public void lock() {
//burn cycles
while (cmpxchg(LOCK_TAKEN, lock) == LOCK_TAKEN) {
micropause(); //optional
}
}
public void unlock() {
int old = cmpxchg(LOCK_FREE, lock);
//guard against recursive locks
assert(old == LOCK_TAKEN);
}
}
99. Op*miza*ons'
⢠A'lot'of'smallish'code'gen'transforms:'e.g.'Lock'fusion'
⢠âFat'spinâ'
⢠Lazy'unlocking'(biased'locking)'
â Start'assuming'all'locks'are'lazy.'Tag'thin'locks'as'lazily'
locked.'
â If'object'already'lazily'locked'
⢠If'itâs'the'same'thread:'profit'
⢠Else'â'stop'the'lock'holder,'detect'the'ârealâ'lock'state'by'stack'
walk.'Convert'to'thin'lock'or'forcefully'unlock'it'
â Transfer'bits'
â Heuris*cs:'object'and'class'banning.'Ageing.'
102. Mission'Control'
⢠Use'âfreeâ'run*me'informa*on!'
â JRockit'(Java)'Mission'Control'
⢠JRockit'(Java)'flight'recorder'
⢠Memory'leak'detector'(JRockit'only)'
⢠Management'console'
⢠$JAVA_HOME/bin/JCMD'(used'to'be'JRCMD)'
⢠Everything'in'the'VM'abstracted'into'an'
event'that'may'or'may'not'have'a'dura*on'
⢠Soon:'public'API'
103. Java'Flight'Recorder'
⢠Always'on'
â Excellent'for'debugging'and'analysis'of'crashes'
â Can'be'set'to'record'more'intrusively'for'periods'in'
produc*on'
⢠E.g.'extensive'lock'profiling'
⢠Everything'is'an'event'
⢠Buffered'recording'â'the'last'n'seconds'available'
at'any'crash'or'when'a'command'is'given.'
⢠Very'fine'precision.'
â Mul*media'*mers'and'system'hardware'support'
required'for'e.g.'latencies'