jug.ru 2014-j rockit architecture copy

113
Design Ra*onales in the JRockit JVM Marcus Lagergren Java Language team, Oracle

Upload: marcus-lagergren

Post on 12-Jul-2015

1.064 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Jug.ru 2014-j rockit architecture copy

Design'Ra*onales'in'the'JRockit'JVM'Marcus'Lagergren'

Java'Language'team,'Oracle'

Page 2: Jug.ru 2014-j rockit architecture copy

Design'Ra*onales'in'the'JRockit'JVM'Marcus'Lagergren'

Java'Language'team,'Oracle'

Page 3: Jug.ru 2014-j rockit architecture copy

Design'Ra*onales'in'the'JRockit'JVM'Marcus'Lagergren'

Java'Language'team,'Oracle'

Page 4: Jug.ru 2014-j rockit architecture copy

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 Oracle�s products remains at the sole discretion of Oracle.

Safe'Harbor'Statement'

Page 5: Jug.ru 2014-j rockit architecture copy

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'

•  Q&A'

Page 6: Jug.ru 2014-j rockit architecture copy

About'the'speaker'

@lagergren'

Page 7: Jug.ru 2014-j rockit architecture copy

About'the'speaker'

@lagergren'

Page 8: Jug.ru 2014-j rockit architecture copy

Buy'this'book!'

Page 9: Jug.ru 2014-j rockit architecture copy

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'

Page 10: Jug.ru 2014-j rockit architecture copy

In'the'beginning'

Page 11: Jug.ru 2014-j rockit architecture copy

Appeal'Virtual'Machines'

•  Appeal'SoYware'Solu*ons'– Consul*ng,'almost'exclusively'Java'by'1997'

•  S*ll'the'pre[app'server'era'

Page 12: Jug.ru 2014-j rockit architecture copy

Appeal'Virtual'Machines'•  We'saw'that'Java'would'be'great'on'the'server'side'

Page 13: Jug.ru 2014-j rockit architecture copy

Appeal'Virtual'Machines'•  We'saw'that'Java'would'be'great'on'the'server'side'– Shorter'development'cycles'–'money'in'the'bank'•  Buffer'overrun'protec*on'•  Automa*c'memory'management ''• Write'once'run'everywhere'

Page 14: Jug.ru 2014-j rockit architecture copy

Appeal'Virtual'Machines'•  We'saw'that'Java'would'be'great'on'the'server'side'– Shorter'development'cycles'–'money'in'the'bank'•  Buffer'overrun'protec*on'•  Automa*c'memory'management ''• Write'once'run'everywhere'

•  Tremendous'scalability'problems'•  Sun'ClassicVM'was'all[encompassing'

Page 15: Jug.ru 2014-j rockit architecture copy

JavaOne'1997'

•  Sun'Microsystems'presents'the'HotSpot'virtual'machine'

Page 16: Jug.ru 2014-j rockit architecture copy

JavaOne'1997'

•  Sun'Microsystems'presents'the'HotSpot'virtual'machine'– “WOW!'This'is'the'way'to'do'it!'Adap*ve'run*mes!”'

Page 17: Jug.ru 2014-j rockit architecture copy

JavaOne'1998'

•  Sun'Microsystems'presents'the'HotSpot'virtual'machine'again%

Page 18: Jug.ru 2014-j rockit architecture copy

JavaOne'1998'

•  Sun'Microsystems'presents'the'HotSpot'virtual'machine'again%– “WTF!'This'is'slide[by[slide'the'exact'same'presenta*on'as'last'year!?!”'

– We'can’t'wait'any'longer.'Let’s'build'our'own'VM.'How'hard'can'it'be?''

Page 19: Jug.ru 2014-j rockit architecture copy

Crea*ng'our'own'JVM'['JRockit'

Page 20: Jug.ru 2014-j rockit architecture copy

Produc*ze'a'narrower'domain?'

•  Server[side'usage'only.'Headless.''– We'need'to'help'the'early'app'server'vendors'get'performance'and'scalability'

Page 21: Jug.ru 2014-j rockit architecture copy

Produc*ze'a'narrower'domain?'

•  Server[side'usage'only.'Headless.''– We'need'to'help'the'early'app'server'vendors'get'performance'and'scalability'

•  No'interpreter''– “startup'*me'doesn’t'mader'on'the'server'anyway”'

Page 22: Jug.ru 2014-j rockit architecture copy

Produc*ze'a'narrower'domain?'

•  Server[side'usage'only.'Headless.''– We'need'to'help'the'early'app'server'vendors'get'performance'and'scalability'

•  No'interpreter''– “startup'*me'doesn’t'mader'on'the'server'anyway”'

•  Green'threads'or'n'x'm'threads.''– Explicit'parallelism'was'all[pervasive.'

Page 23: Jug.ru 2014-j rockit architecture copy

Produc*ze'a'narrower'domain?'

•  Incremental'GC''– We'thought'something'like'[Seligman,'Grarup]'would'suffice.''

Page 24: Jug.ru 2014-j rockit architecture copy

Produc*ze'a'narrower'domain?'

•  Incremental'GC'– We'thought'something'like'[Seligman,'Grarup]'would'suffice.''

•  Support'ourselves'on'consul*ng'only.'– Nope'–'needed'venture'capital'

Page 25: Jug.ru 2014-j rockit architecture copy

The'Java'License'

•  You'can’t'call'yourself'“Java”'without'a'Java'license'

•  You'need'to'pass'the'TCK'test'suite'– Not'available'without'license'

•  To'get'a'Java'License'you'need'a'“value'add”'

Page 26: Jug.ru 2014-j rockit architecture copy

The'Java'License'

•  What’s'a'“value'add”?'

Page 27: Jug.ru 2014-j rockit architecture copy

The'Java'License'

•  What’s'a'“value'add”?'

Page 28: Jug.ru 2014-j rockit architecture copy

The'Java'License'

•  What’s'a'“value'add”?'

Page 29: Jug.ru 2014-j rockit architecture copy

The'Java'License'

•  What’s'a'“value'add”?'– Superior'performance!'

Page 30: Jug.ru 2014-j rockit architecture copy

The'Java'License'

•  What’s'a'“value'add”?'– Superior'performance!'– What?'You'didn’t'like'that?'

Page 31: Jug.ru 2014-j rockit architecture copy

The'Java'License'

•  What’s'a'“value'add”?'– Superior'performance!'– What?'You'didn’t'like'that?'– OK…'Let’s'see…'Err..'“managability”'

Page 32: Jug.ru 2014-j rockit architecture copy

The'Java'License'

•  Java'License'was'granted'2001'– Helped'us'partner'up'with'BEA'Systems'and'Intel'

– BEA'acquired'us'in'2002'– Oracle'acquired'BEA'in'2008'– Oracle'acquired'Sun'in'2010'

Page 33: Jug.ru 2014-j rockit architecture copy

What'did'we'accomplish?''!

Page 34: Jug.ru 2014-j rockit architecture copy

The'real'value'adds'turned'out'to'be:''

•  Mul*'*ered'support'for'paying'customers'– Part'of'the'WLS'stack'

'

Page 35: Jug.ru 2014-j rockit architecture copy

•  Monitoring'and'Serviceability'–  JRockit'Mission'Control'(now'Java'Mission'Control)'

– Record'and'introspect'produc*on'systems'with'zero'overhead.'

'

The'real'value'adds'turned'out'to'be:''

Page 36: Jug.ru 2014-j rockit architecture copy

•  Pioneered'“SoY'real*me”'GC'– Determinis*c'GC'– Low'latency'GC'

The'real'value'adds'turned'out'to'be:''

Page 37: Jug.ru 2014-j rockit architecture copy

•  Virtualiza*on'–  JRockit'Virtual'Edi*on'–'an'opera*ng'system'for'Java'

– Shorter'paths'between'Java'and'hardware'– Hypervisor'required'–  JRockit'VE'on'virtual'hardware'outperformed'physical'Linux!'

'

The'real'value'adds'turned'out'to'be:''

Page 38: Jug.ru 2014-j rockit architecture copy

•  The'benchmark'wars'– Constantly'keeping'it'going'with'Sun'and'IBM,'driving'Java'server[side'performance'

'

The'real'value'adds'turned'out'to'be:''

Page 39: Jug.ru 2014-j rockit architecture copy

•  JRockit'became'the'default'JVM'in'the'Oracle'stack'in'2008'

•  ExaLogic''

…'and'then'

Page 40: Jug.ru 2014-j rockit architecture copy

INTERNALS!

@SimmsUpNorth

Page 41: Jug.ru 2014-j rockit architecture copy

Code'Genera*on'

Page 42: Jug.ru 2014-j rockit architecture copy

Code'genera*on'–'No'Interpreter'

•  Keep'test'matrix'small'•  Keep'opera*onal'complexity'down'•  Targe*ng'server'side'apps'–'warmup'a'small'issue'

•  “Code'caching'/'AOT'can'be'done'later”'

Page 43: Jug.ru 2014-j rockit architecture copy

Code'genera*on'–'One'JIT'

•  Keep'test'matrix'small'•  Keep'opera*on'complexity'down'•  Run'it'in'different'modes,'with'maximum'code'reuse'

•  Same'IR'throughout'– With'gradual'augmenta*ons'

Page 44: Jug.ru 2014-j rockit architecture copy

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'

Page 45: Jug.ru 2014-j rockit architecture copy

Code'Genera*on'

•  Same'“spine”'used'in'all'*ers'of'code'genera*on'

Page 46: Jug.ru 2014-j rockit architecture copy

Code'Genera*on'

•  Same'“spine”'used'in'all'*ers'of'code'genera*on'

Page 47: Jug.ru 2014-j rockit architecture copy

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'

Page 48: Jug.ru 2014-j rockit architecture copy

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'

Page 49: Jug.ru 2014-j rockit architecture copy

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'

Page 50: Jug.ru 2014-j rockit architecture copy

HotSpot'style?'

•  On[stack'replacement?'•  Deop*miza*on?'

Page 51: Jug.ru 2014-j rockit architecture copy

HotSpot'style?'

•  On[stack'replacement?'•  Deop*miza*on?'•  Never'much'cared'for'any'it';[)'

Page 52: Jug.ru 2014-j rockit architecture copy

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'

Page 53: Jug.ru 2014-j rockit architecture copy

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'

Page 54: Jug.ru 2014-j rockit architecture copy

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'

Page 55: Jug.ru 2014-j rockit architecture copy

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'

Page 56: Jug.ru 2014-j rockit architecture copy

“Garbage'collec*ng'code”'

•  Code'kept'in'binary'tree'of'code'blocks'~'64M'– More'if'large'pages'enabled'

•  Class'loader'unloading'!'garbage'collec*on'•  Reference'count'to'ac*ve'code'modified'when'backpatching'

•  Specialized'usage'of'code'blocks.'– Trampolines'only'– Op*mized'code'only'

Page 57: Jug.ru 2014-j rockit architecture copy

Bytecode'is'bad'–'kill'it'quickly'•  What’s'with'the'goto:s?'•  Why'can'it'express'more'than'Java'source'code?''– OK'we'understand'the'mul*'language'concept,'we'sorta'forgive'you.'

– But'man,'dominators'and'loop'analysis'–'that’s'a'lot'of'compile'*me'

Page 58: Jug.ru 2014-j rockit architecture copy

Bytecode'is'bad'–'kill'it'quickly'•  …and'why'is'it'a'stack'machine'AND'a'register'machine'with'65535'registers'at'the'same'*me!? ' ''

•  Ini*ally'tried'to'reconstruct'ASTs'– Obfuscators'etc'made'this'predy'hopeless.'

•  ~15%'of'the'klocs'in'JRockit/codegen'do'flow'control'analysis'on'the'goto:s'

Page 59: Jug.ru 2014-j rockit architecture copy

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”'

Page 60: Jug.ru 2014-j rockit architecture copy

The'IR'

•  Simple'IR'in'MIR'form'(playorm'independent)'

Page 61: Jug.ru 2014-j rockit architecture copy

The'IR'–'Design'Ra*onale'•  We'had'some'compiler'experience'–'wanted'to'be'on'track'quickly.'Do'it'the'tradi*onal'way.'

•  We'are'not'“wrong”.'LLVM'is'very'similar.'

Page 62: Jug.ru 2014-j rockit architecture copy

The'IR'–'Design'Ra*onale'•  Tiered:%highest%;er%=='always'high'level'•  Hardware'agnos*c.''•  No'architecture'specific'memory'ops'

•  Tiered:%lowest%;er%=='always'the'na*ve'architecture'instruc*on'for'instruc*on.''•  A'gradual'transi*on.''•  A'CPU'has'no'sea'of'nodes.'

Page 63: Jug.ru 2014-j rockit architecture copy

The'IR'•  Highest'IR'level'may'have'opera*ons'as'operands'

•  Intrinsics'everywhere'–  arraycopy, membar, cmpuXX, sse4IndexOf, doubleToLongBits, crypto, Math.sin%and%so%on%…'

•  Regret'not'doing'more'in'SSA'form'

Page 64: Jug.ru 2014-j rockit architecture copy

The'IRInfo'“database”'•  Lazily'computable'informa*on'–  Liveness'– Dominators'–  Loop'informa*on'– Aliases'–  Type'inference'–  Ranges'– Nullness'analysis'– …'–  Invalidate'on'modifica*on.'

•  Not'a'very'stable'model.'

Page 65: Jug.ru 2014-j rockit architecture copy

Memory'management'!

Page 66: Jug.ru 2014-j rockit architecture copy

Transi*on:'object'layout,'types'and'livemaps…'

Page 67: Jug.ru 2014-j rockit architecture copy

Object'layout'and'types'

•  Object'headers'should'be'fixed'sized.'•  JRockit'Object'header'is'32'+'32'bits'on'all'playorms'with'some'content'varia*ons.'

•  [Grove]'ramblings'on'object'models'•  Type'tree'maintained'similar'to'[Krall,'Vitek,'Horspool]''

'

Page 68: Jug.ru 2014-j rockit architecture copy

Livemaps'(oopmaps)'

•  Registers'and'stack'slots'on'the'local'frame'that'contain'objects.''

•  Nothing'strange'here.'Required'for'non[conserva*ve'garbage'collec*on'of'any'sort.'

•  Internal'pointer'bit'•  Forms'the'root'set.''•  Rollforwarding'vs'the'safepoint'approach'

Page 69: Jug.ru 2014-j rockit architecture copy

Transi*on'['Livemaps'

Page 70: Jug.ru 2014-j rockit architecture copy

Memory'management'•  Garbage'collectors'– Concurrent'– Parallel'– Determinis*c'

•  With'or'without'genera*ons'

Page 71: Jug.ru 2014-j rockit architecture copy

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'

Page 72: Jug.ru 2014-j rockit architecture copy

Memory'management'•  Can'also'run'with'a'parallel'policy'– Stop'the'world'and'clean'up'quickly'– Only'throughput'oriented'– No'write'barriers,'as'there'is'no'need'for'a'card'table'

Page 73: Jug.ru 2014-j rockit architecture copy

Mark'&'Sweep'•  Backbone'of'GC'based'on'tradi*onal'tri[color'mark'and'sweep'

•  Adap*ve'thread'usage'and'addi*onal'concurrency'

Page 74: Jug.ru 2014-j rockit architecture copy

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.'

Page 75: Jug.ru 2014-j rockit architecture copy

No'permgen!'Ever!'

Page 76: Jug.ru 2014-j rockit architecture copy

Other'nice'features'•  No'permgen!!!'Ever!'

Page 77: Jug.ru 2014-j rockit architecture copy

Other'nice'features'•  No'permgen!!!'Ever!'•  Pinned'objects.'– Fast'memory'buffers'– Also'enable'non[con*guous'heaps'

Page 78: Jug.ru 2014-j rockit architecture copy

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'

Page 79: Jug.ru 2014-j rockit architecture copy

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.'

Page 80: Jug.ru 2014-j rockit architecture copy

Young'Collec*ons'•  A'variant'of'stop'and'copy'is'used.''– All'threads'are'halted'and'objects'are'deleted'or'promoted'– Hierarchical'breadth'first'copy'for'cache'locality'• Parallelizes'nicely'• Many'threads'always'harvest'a'young'space'

Page 81: Jug.ru 2014-j rockit architecture copy

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'

Page 82: Jug.ru 2014-j rockit architecture copy

Thread'Local'Alloca*on'•  Thread'local'alloca*on''•  Thread'local'areas'are'roughly'L2'cache'sized'and'objects'are'allocated'here'before'they'are'forced'upon'the'heap'

Page 83: Jug.ru 2014-j rockit architecture copy

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;

}

Page 84: Jug.ru 2014-j rockit architecture copy

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 >> log2(objectAlignment));

}

Ref decompress(CompRef ref) {

return globalHeapBase | (ref << log2(objectAlignment));

}

Page 85: Jug.ru 2014-j rockit architecture copy

Determinis*c'GC'•  QoS'level'for'latencies.'“No'more'than'X'ms”'•  Down'to'single'digits'on'modern'x86'hardware'

•  Caveat:'live'data'on'heap'is'the'main'constraint.''– Up'to'50%'of'heap'live'data's*ll'feasible'

Page 86: Jug.ru 2014-j rockit architecture copy

Determinis*c'GC'

Page 87: Jug.ru 2014-j rockit architecture copy

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.'

Page 88: Jug.ru 2014-j rockit architecture copy

Determinis*c'GC'–'How?'

•  Efficient'paralleliza*on.'– Mark'phase'is'90%'of'GC'*me''

•  Efficient'heuris*cs'– Some'more'work'in'e.g.'write'barriers'

Page 89: Jug.ru 2014-j rockit architecture copy

Threads'and'Synchroniza*on'!

Page 90: Jug.ru 2014-j rockit architecture copy

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'

Page 91: Jug.ru 2014-j rockit architecture copy

Threads'and'Synchroniza*on'•  Locks'are'thin'or'fat''– Adap*ve'infla*on'and'defla*on'

•  Lazy'locking'(biased'locking'supported)'– Adap*ve'heuris*cs'for'banning'and'retrying'the'lazy'approach.'

Page 92: Jug.ru 2014-j rockit architecture copy

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 cycleswhile (cmpxchg(LOCK_TAKEN, &lock) == LOCK_TAKEN) {

micropause(); //optional}

}

public void unlock() { int old = cmpxchg(LOCK_FREE, &lock); //guard against recursive locksassert(old == LOCK_TAKEN);

} }

Page 93: Jug.ru 2014-j rockit architecture copy

Threads'and'Synchroniza*on'•  Locks'are'thin'when'first'taken'•  Time'spent'in'lock'and'*mes'taken'triggers'infla*on'

•  wait'or'notify'immediately'inflates'a'lock'

•  Fat'locks'are'also'deflated'when'uncontended'for'too'long'

'

Page 94: Jug.ru 2014-j rockit architecture copy

Threads'and'Synchroniza*on'

Page 95: Jug.ru 2014-j rockit architecture copy

Threads'and'Synchroniza*on'•  Thin'lock'lifecycle'

Page 96: Jug.ru 2014-j rockit architecture copy

Threads'and'Synchroniza*on'Thin'&'fat'lock'lifecycle'

Page 97: Jug.ru 2014-j rockit architecture copy

Lock'Pairing'•  Bytecode'again'–'no'restric*on'on'matching'monitorenter'with'monitorexit

•  Not'all'of'them'can'be'analyzed'by'the'JIT'

Page 98: Jug.ru 2014-j rockit architecture copy

Lock'Pairing'•  We'can'store'what'we'know,'and'make'unlocks'quick.''– Lock'tokens'(the'object'OR'3'bits)'•  Thin,'fat,'recursive,'lazily'taken,'unmatched'

– Livemap'system'contains'nes*ng'order.'

Page 99: Jug.ru 2014-j rockit architecture copy

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.'

Page 100: Jug.ru 2014-j rockit architecture copy

Threads'and'Synchroniza*on'

•  Thin,'fat'&'lazy'lock'lifecycle'

Page 101: Jug.ru 2014-j rockit architecture copy

Export'it'all!'–'JRockit'Mission'Control'

(now'Java'Mission'Control)'

!

@javamissionctrl!$JAVA_HOME/bin/jmc

Page 102: Jug.ru 2014-j rockit architecture copy

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'

Page 103: Jug.ru 2014-j rockit architecture copy

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'

Page 104: Jug.ru 2014-j rockit architecture copy

Latency'Analysis'

Page 105: Jug.ru 2014-j rockit architecture copy

The'Management'Console'•  Peek'into'the'running'produc*on'JVM'•  Add'triggers'on'events'•  Interact'with'the'VM:'force'GC'etc.'

Page 106: Jug.ru 2014-j rockit architecture copy

The'Memory'Leak'Detector'•  Introspect'the'type'graph'in'real*me.'Look'for'types'that'are'growing'despite'GC:s'

•  “Trending'alloca*ons”'

Page 107: Jug.ru 2014-j rockit architecture copy

Studying'a'recording'offline'

Page 108: Jug.ru 2014-j rockit architecture copy

JRockit'Virtual'Edi*on'

Page 109: Jug.ru 2014-j rockit architecture copy

Is'the'JVM'an'OS?'

Page 110: Jug.ru 2014-j rockit architecture copy

Is'the'JVM'an'OS?'

•  Add'a'coopera*ve'aspect'to'thread'switching'•  Zero[copy'networking'code'•  Reduce'cost'of'entering'OS'•  Balloon'driver'•  Runs'only'on'hypervisor'•  Facilitates'pauseless'GC'

Page 111: Jug.ru 2014-j rockit architecture copy

Is'the'JVM'an'OS?'

Page 112: Jug.ru 2014-j rockit architecture copy

Thank'you!''

Would!you!like!to!!

know!more?!

Oracle'JRockit'–''

the'Defini3ve'Guide'

Page 113: Jug.ru 2014-j rockit architecture copy