Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding Coffee Breaks

Understanding Coffee Breaks

Visualizing Java memory internals and understanding GC

Avatar for sunkarah

sunkarah

June 14, 2013

Other Decks in Programming

Transcript

  1. Run+me  Data  Areas   Method   Area   Heap  

    Java   Stacks   PC   Registers   Ma+ve   Method   Stacks  
  2. Sizing  the  Heap   •  -­‐Xms  3670k   •  -­‐Xmx

     64m   •  -­‐XX:MinHeapFreeRa+o    40   •  -­‐XX:MaxHeapFreeRa+o  70  
  3. Memory  Genera+ons   •  Young  Genera+on   –  Eden  Space

      –  Survior  Space   •  Old/Tenured  Genera+on   •  Permanent  Genera+on          Eden   Survivor  1   Survivor  2                                                Old  Gen       Perm   Gen       Na=ve   Heap   Young  Gen  
  4. Sizing  Young  Genera+on   •  -­‐XX:NewRa+o      2  

    •  -­‐XX:NewSize      2228K   •  -­‐XX:MaxNewSize    not  limited   •  -­‐XX:SurvivorRa+o  32  
  5. Op+ons  with  GC   •  Serial  versus  Parallel   • 

    Concurrent  versus  Stop-­‐the-­‐world   •  Compac+ng  versus  Non-­‐compac+ng   versus  Copying  
  6. Serial  Collector   -­‐XX:+UseSerialGC   •  Young  Gen   – Single

     step  collec+on,  uses  only  1  CPU   – Stop  the  world   – Copy  compac+on  from  Eden  space  to   survivor  space    
  7. •  Old  Gen   – Mark-­‐sweep  collec+on,  uses  only  1  

    CPU   – Stop  the  world   – Sliding  compac+on   Serial  Collector   -­‐XX:+UseSerialGC  
  8. •  Applies  only  to  Young  Gen   – Parallel  version  of

     Serial  Collector   – Uses  mul+ple  threads   Parallel  Collector   -­‐XX:+UseParallelGC  
  9. •  Old  Gen   – Mark-­‐summary-­‐sweep  collec+on   – Uses  mul+ple  threads

     (-­‐XX:ParallelGCThreads=n)   – Stop  the  world   – Logically  divided  into  fixed-­‐sized  regions   – Cleans  regions  with  more  garbage   – Copy  compac+on   – Lea  dense,  right  free   Parallel  Compac+ng  Collector   -­‐XX:+UseParallelOldGC  
  10. •  Old  Gen   – Ini+al  mark,  stop  the  world  

    – Concurrent  mark   – Re-­‐mark,  stop  the  world   – Concurrent  Sweep   Concurrent  Mark-­‐Sweep     -­‐XX:+UseConcMarkSweepGC  
  11. •  Old  Gen   – Low  latency  collec+on  (short  pauses)  

    – Low  throughput  (due  to  remarking)   – No  compac+on  (suffers  fragmenta+on)   – Causes  Floa+ng  garbage   – –XX:CMSIni+a+ngOccupancyFrac+on=n   •  Incremental  Mode   – –XX:+CMSIncrementalMode   Concurrent  Mark-­‐Sweep     -­‐XX:+UseConcMarkSweepGC  
  12. •  Maximum  Pause  Time  Goal   – -­‐XX:MaxGCPauseMillis=n   •  Throughput

     Goal   – -­‐XX:GCTimeRa+o=n  [1  :  (1+n)]   •  Footprint  Goal   – Reduces  the  footprint  un+l  only  one   of  the  above  goals  is  met   – Goal  Priori+es   – Maximum  Pause  Time,  Throughput,   Footprint  in  that  order   Behavior-­‐based  Tuning  
  13. •  Ini+al  Mark  -­‐  Stop  the  World   •  Concurrent

     Marking   •  Remark  -­‐  Stop  the  World  Event  -­‐   completely  empty  regions  are   reclaimed   •  Copying/Cleanup:    Regions  with   max  garbage  are  reclaimed  in  the   available  +me  –  concurrent  for   most  part   Garbage-­‐First  Collector   -­‐XX:+UseG1GC