ç¹ã«GCããã³CMSã®æäœã®äžè¬çãªååã«ã€ããŠã¯ã ããã§è©³ãã説æããŸã ã ãã®ãããã¯ãç解ããããã«å¿ èŠãªããšãããã§ç°¡åã«èŠçŽããŸãã
- ã¡ã¢ãªã¯ãYoungGenãšOldGenã®2ã€ã®é åã«åãããŠããŸã
- YoungGenã®æ°ããäœæããããªããžã§ã¯ã
- OldGenã¯ãããã€ãã®ãã€ããŒã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãçãæ®ããªããžã§ã¯ããååŸããŸã
- ãã€ããŒã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãYoungGenãã¯ãªãŒã³ã¢ãã
- ã¡ãžã£ãŒã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãOldGenãã¯ãªãŒã³ã¢ãã
- äž¡æ¹ã®é åã®ãã«GCã¯ãªãŒãã³ã°
- Stop-the-worldã¯ãã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®å®è¡äžã«ã¢ããªã±ãŒã·ã§ã³ãå®å šã«åæ¢ããããšãæå³ããŸã
- 䞊è¡ããã¢ã«ãŽãªãºã ãšãã§ãŒãºã«ãããã¢ããªã±ãŒã·ã§ã³ãåæ¢ããããšã¯ãããŸããã ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã¯ã¢ããªã±ãŒã·ã§ã³ãšäžŠè¡ããŠå®è¡ãããŸã
- 䞊åã¢ã«ãŽãªãºã ãšãã§ãŒãºã¯ãè€æ°ã®ã¹ã¬ããã§åäœããã¢ã¯ãã£ããã£ã§ãã ãããã¯ãåæãŸãã¯äžçãåæ¢ããããšãã§ããŸãã æ瀺çã«è¿°ã¹ãããŠããªãéããéåžžãããã¥ã¡ã³ãã¯ãŸãã«äžçãæ¢ããããšãæå³ããŸãã
- ãã€ããŒã¬ããŒãžã³ã¬ã¯ã·ã§ã³ïŒãã€ããŒGCïŒ-åžžã«äžçãæ¢ãã
- ãã«GCã¯äžçãæ¢ãã
- CMSïŒåæããŒã¯ã¹ã€ãŒãïŒã®äž»ãªãã§ãŒãºã¯æ¬¡ã®ãšããã§ãã
- åæããŒã¯-äžçãã¹ããã
- ããŒã¯-åæ
- äºåã¯ãªãŒã³-䞊è¡
- ãªããŒã¯-ã¹ãããã¶ã¯ãŒã«ã
- ã¹ã€ãŒã-åæ
- åŸæ¥ã®ã¬ããŒãžã³ã¬ã¯ã¿ãŒã§ã®ããããªããžã§ã¯ãïŒã¢ããªã±ãŒã·ã§ã³ã«ãªã³ã¯ããªãïŒã®æ€çŽ¢ã¯ããã¹ãŠã®çããŠãããªããžã§ã¯ãïŒGCã«ãŒãããã®ãªã³ã¯ãä»ããŠå°éå¯èœïŒãæ€çŽ¢ããããšã«ãã£ãŠå®è¡ãããŸãã
- CMSã¯ã¡ã¢ãªãæé©åããã空ããªã¹ãã䜿çšããŠç®¡çããŸãã
- GC人éå·¥åŠïŒæãŸããæ倧äŒæ¢æéãæå®ãããã©ã¡ãŒã¿ãŒïŒã¯CMSã§æ©èœããŸãã
ãããã£ãŠããã®å Žåãã¢ããªã±ãŒã·ã§ã³ãå®å šã«åæ¢ãã次ã®ç¬éããããŸãã
- ãã€ããŒã¬ããŒãžã³ã¬ã¯ã·ã§ã³
- åæåããŒã¯CMSãã§ãŒãº
- ãªããŒã¯ãã§ãŒãºCMS
- ãã«GC
æåã«ãããã4ã€ã®ã±ãŒã¹ã®äžæåæ¢ãéåžžã«å€§ãããã¢ããªã±ãŒã·ã§ã³ã®å¯¿åœãæãªããã©ãããå€æããå¿ èŠããããŸãã ããªããå¿ èŠãšãããŸãã«ãã®ãããªæ¡ä»¶ãããã®ã§ã誰ããçç£ã·ã¹ãã ãèŠãæ¹ãè¯ãã§ãã 次ã®ãã©ã¡ãŒã¿ã䜿çšããŠJVMãèµ·åããããšã«ããããããããã©ãŒãã³ã¹ãäœäžãããããšãªãå®å šã«å®è¡ã§ããããšãç¥ã«æè¬ããŸãã
-verbose:gc
-Xloggc:gc.log
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintGCApplicationStoppedTime
CMSãã°ã®èªã¿æ¹ã®è©³çŽ°ã«ã€ããŠã¯ã ãã¡ããã芧ãã ãã ã jvmã®éå§ããã®çžå¯Ÿçãªç§æ°ã§ã¯ãªãã人éçã«æéãåºåãããå Žåã¯ãpythonã§èšè¿°ããããŒãµãŒã䜿çšã§ããŸãã çŸåšãäžçã®ã¹ãããã€ãã³ãã«é¢ãããã°ã®äžéšã«ã®ã¿é¢å¿ããããŸãã
1.ãã€ããŒã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãé ããªããŸãã
[GC [DefNew: 209100K->25808K(235968K), 0.0828063 secs] 209100K->202964K(1284544K), 0.0828351 secs] [Times: user=0.02 sys=0.08, real=0.08 secs]
Total time for which application threads were stopped: 0.0829205 seconds
ãã€ããŒã¢ã»ã³ããªã®äž»ãªã¢ã«ãŽãªãºã ã¯ã³ããŒã§ãããããYougGenã®ã©ã€ããªããžã§ã¯ããå€ãã»ã©ããã€ããŒã¢ã»ã³ããªã®åäœæéãé·ããªããŸãã äžæåæ¢ãé·ãããŠãããªãã幞ãã§ãªããšããç§ã¯å°ãªããšã3ã€ã®äºæãèŠãªããã°ãªããŸããã
aã JVMãäžé©åãªã¢ã«ãŽãªãºã ã䜿çšããŠããŸãã äžèšã®ãã°ã¯ãã·ã³ã°ã«ã¹ã¬ããã¢ã«ãŽãªãºã ïŒDefNewïŒã䜿çšããŠããŸãã æ°ãããã«ãã¹ã¬ããã¢ã«ãŽãªãºã ïŒãã°ã§ã¯ParNewãšåŒã°ããŸãïŒãè©Šãããšããå§ãããŸããããã¯ã-XXïŒ+ UseParNewGCãã©ã¡ãŒã¿ãŒã§åŒ·å¶çã«æå¹ã«ã§ããŸãã ãŸãããã°ã«PSYoungGenãšããååã衚瀺ãããŠããå Žåã¯ãJVMã䞊åã¢ã«ãŽãªãºã ã䜿çšããŠããããšãæå³ããŸãããå€ãå®è£ ã§ãã CMSãšçµã¿åããããŠããŸãããå©çšã§ããªãããã§ãã
bã YoungGenã«å²ãåœãŠãããã¡ã¢ãªã倧ããããŸãïŒæå®ããããã°ã§ã¯235968Kã§ãïŒã -Xmnãã©ã¡ãŒã¿ãŒãèšå®ããããšã§åæžã§ããŸãã
cã ãªããžã§ã¯ãã«èš±å¯ããã幎霢ã®å€§ããªå€§ãããããµãã€ããŒã¹ããŒã¹ã䜿çšããŠããããããªããžã§ã¯ããã³ããŒãããŠOldGenã«ãã©ããããããäžå¿ èŠãªãã€ããŒGCè² è·ãçºçããŸãã ãã®ç¶æ³ã¯ã-XXïŒSurvivorRatioããã³-XXïŒMaxTenuringThresholdãã©ã¡ãŒã¿ãŒã䜿çšããŠä¿®æ£ã§ããŸãã ãã®ã±ãŒã¹ã®ãã詳现ãªåæã«ã€ããŠã¯ã-XXïŒ+ PrintTenuringDistributionãã©ã¡ãŒã¿ãŒãæå®ããŠJVMãå®è¡ããGCãã°å ã®ãªããžã§ã¯ãã®çæã«é¢ãã詳现æ å ±ãååŸã§ããŸãã
2. init-markã¯é·ãéæ©èœããŸã
[GC [1 CMS-initial-mark: 680168K(1048576K)] 706792K(1284544K), 0.0001161 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Total time for which application threads were stopped: 0.0002740 seconds
ãã®ãã§ãŒãºã§ã¯ãã¬ããŒãžã³ã¬ã¯ã¿ãŒã¯ãGCã«ãŒãããçŽæ¥ã¢ã¯ã»ã¹å¯èœãªãã¹ãŠã®ãªããžã§ã¯ããããŒã¯ããŸãã ãã®ãã§ãŒãºã«å€ãã®æéããããããšãããã£ãå Žåã¯ãããããããŒã«ã«å€æ°ãšéçãã£ãŒã«ãããã®ãªã³ã¯ããããããããŸãã
ããã§ã¯ããã®ãã§ãŒãºã«åå ããã¹ã¬ããïŒParallelCMSThreadsïŒã®æ°ãå¢ããããšãã§ããŸãã ããã©ã«ãã§ã¯ãïŒParallelGCThreads + 3ïŒ/ 4ïŒãšããŠèšç®ãããŸãã ã€ãŸã ParallelGCThreads = 8ã®å Žåã2ã€ã®ã¹ã¬ããã®ã¿ãinit-markãã§ãŒãºã«åå ããŸããããã¯ã䞊ååŠçã«ãããªãŒããŒãããã®ããã«ç¹å®ã®æé·ããããããªãå ŽåããããŸãã
3.çºèšãã§ãŒãºã§ã®å€§ããªäžæåæ¢
[GC[YG occupancy: 26624 K (235968 K)][Rescan (non-parallel) [grey object rescan, 0.0056478 secs][root rescan, 0.0001873 secs], 0.0059038 secs][weak refs processing, 0.0000090 secs] [1 CMS-remark: 750825K(1048576K)] 777449K(1284544K), 0.0059808 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
Total time for which application threads were stopped: 0.0061668 seconds
ããŒã¯ãã§ãŒãºã§ã¯ããã¹ãŠã®ãªã³ã¯ã®å€æŽãç£èŠããç¹å¥ãªããã»ã¹ãå®è¡ãããŸãã å€æŽãã§ãŒãºããã¹ãŠè¡šç€ºããã«ã¯ãã³ã¡ã³ããã§ãŒãºãå¿ èŠã§ãã
aã ãã°ã«ãRescanïŒnon-parallelïŒããšãããã¬ãŒãºã衚瀺ãããå Žåã¯ã-XXïŒ+ CMSParallelRemarkEnabledãªãã·ã§ã³ãæå¹ã«ããŠããã®ãã§ãŒãºã§è€æ°ã®ã¹ã¬ãããæå¹ã«ããããšããå§ãããŸãã
bã é±ã®åç §ã¯ãã®ãã§ãŒãºã§æ£ç¢ºã«ã¯ãªã¢ãããã®ã§ã䜿çšããåç §ãå€ããããã©ããã確èªããŸãã ïŒäŸïŒjava.util.WeakHashMapïŒ
cã ããããããªãã®ãªã³ã¯ã¯å€§ããå€åããŠããŸãã åæããŒã¯ãšçºèšã®éã®çµéæéã確èªããŸãã ãããã®ãã§ãŒãºéã§çµéããæéãçãã»ã©ãå€æŽããããªã³ã¯ãå°ãªããªãã泚éæ©èœãéããªããŸãã ãªããŒã¯ãã§ãŒãºã®çŽåã®5çªç®ã®Javaããéå§ããã¢ããŒãå¯èœãã¬ã¯ãªãŒã³ãã§ãŒãºãè¿œå ãããŸããããããã¯æ¬è³ªçã«ã¯äœãè¡ããŸããã ãã®ããžãã¯ã«ã¯2ã€ã®çç±ããããŸãã æåã®ã³ã¡ã³ãã¯ãYoungGenãã¹ãã£ã³ãããã«ãã¹ã¬ããã¢ãŒãã§åäœããå¯èœæ§ãããããããã€ããŒã¢ã»ã³ããªãå¿ èŠã§ãããã®åŸãYoungGenã®æ®ãã®ãªããžã§ã¯ãã䞊ååŠççšã®é åã«å¹æçã«åå²ããããšãå¯èœã«ãªããŸãã 2ã€ç®ã¯éåžžã«é·ãäœæ¥åæ¢ãã§ãŒãºã§ãããã€ããŒãã«ãã®çŽåŸã«æ©èœããå Žåã¯ã1ã€ã®å€§ããªé·ãäžæåæ¢ãçºçããŸãã ãã®åäœãå¶åŸ¡ã§ãããã©ã¡ãŒã¿ãŒãããã€ããããŸãïŒCMSScheduleRemarkEdenSizeThresholdãCMSScheduleRemarkEdenPenetrationãCMSMaxAbortablePrecleanTimeã ã³ã¡ã³ãã®çŽåã«ãã€ããŒã¢ã»ã³ããªãåŒã³åºãããCMSScavengeBeforeRemarkãè©Šãããšããå§ãããŸãã ãããã£ãŠãinit-markãšremarkã®éã®æéãå¯èœãªéãççž®ããremarkãã§ãŒãºã®äœæ¥ãå°ãªããªããŸãã ããã¯ãéåžžçºçãããã€ããŒã¢ã»ã³ããªã®äžæåæ¢ãçºèšããã¯ããã«çãå Žåã«ç¹ã«å¹æçã§ãã
4.ãã°å ã®ãã«GC
(concurrent mode failure): 798958K->74965K(1048576K), 0.0270334 secs] 1033467K->74965K(1284544K), [CMS Perm : 3022K->3022K(21248K)], 0.0270963 secs] [Times: user=0.03 sys=0.00, real=0.03 secs]
Total time for which application threads were stopped: 0.0271630 seconds
ãããšFull GCãåŒãèµ·ããä»ã®ããã€ãã®ã±ãŒã¹ã«ã€ããŠã¯ã ããã§è©³çŽ°ã«èª¬æããŸãã ã
äŒæ¢ã«ã€ããŠèšãããã£ãã®ã¯ããã ãã§ãã ã¯ãã1ã€ãŸãã¯2ã€ã®ã«ãŒãã«ããªãéããå¢åCMSïŒ-XXïŒ+ CMSIncrementalModeïŒã䜿çšããªãã§ãã ããã ãã¹ãŠããã£ãããšããæ©èœããŸããã
ãããŠãä»ã®ã¢ã«ãŽãªãºã ã«ã€ããŠã®ããã€ãã®èšèã
Garbage FirstïŒG1ïŒãããã¯ããã©ã«ãã§Java 7ã«è¡šç€ºããããªãã·ã§ã³-XXïŒ+ UnlockExperimentalVMOptionsããã³-XXïŒ+ UseG1GCã䜿çšããŠãJava SE 6 Update 14以éã®6çªç®ã®Javaã§æå¹ã«ããããšãã§ããŸãã ããã¯ããšãªã¢å šäœãã¡ã¢ãªã®å°ããªã»ã¯ã·ã§ã³ã«åå²ããããŸããŸãªæéã»ã¯ã·ã§ã³ã§åéã§ããããã«ããããšã§ãéåžžã«çãäžæåæ¢ãå®çŸãããšãããã®ã§ãã ã¡ã¢ãªãŒãé åã«åå²ããããšã«åºã¥ããŠãç®çã®äžæåæ¢ãèšå®ã§ããããŸããŸãªJVMãã©ã¡ãŒã¿ãŒããããŸãã ãã®ã¢ãããŒãã¯ããã®æå¹æ§ãã¡ã¢ãªå ã®ãªããžã§ã¯ãã®ããããžã«å€§ããäŸåããããããŠãããŒãµã«ãšåŒã¶ããšã¯ã§ããŸããã ãªããžã§ã¯ããã¢ããªã±ãŒã·ã§ã³å šäœã«ãªã³ã¯ããŠããããŸããŸãªãã£ãã·ã¥ãç©æ¥µçã«äœ¿çšããå Žåã1ã€ã®ãã£ããã£ã®ã¢ã»ã³ããªãä»ã®å€æ°ã®é åã®ã¹ãã£ã³ã«æ²¿ã£ãŠç§»åããé¡èãªäŒæ¢ãçºçããå¯èœæ§ããããŸãã
æè¿ãç§ã¯ããAzul GCã«é¢ããæçš¿ã«åºäŒããŸããAzulGCã¯ããªããžã§ã¯ãã®ããããžããµã€ãºãã¡ã¢ãªé åã«é¢ä¿ãªããåæ¢ããããšãªãåäœããŸãã éåžžã«ææã«æããŸãããã¢ã«ãŽãªãºã ã¯ç¹å¥ãªLVBåœä»€ïŒããŒããããå€ã®ããªã¢ïŒãå¿ èŠãšããããã圌ãã®ãœãªã¥ãŒã·ã§ã³ã¯ç¬èªã®ããŒããŠã§ã¢ïŒAzulã®Vegaã·ã¹ãã ïŒã§ããå©çšã§ããŸããã 幞ããªããšã«ãIntelããã»ããµã®x86-64ã¢ãŒããã¯ãã£ã«åæ§ã®ã¡ã«ããºã ãå®è£ ããæ©äŒããããããããŸãã è¶ äœé 延ã¢ããªã±ãŒã·ã§ã³ããŒãããäœæããå Žåããã®JVMã®äœ¿çšãæ€èšããŸãããã¢ããªã±ãŒã·ã§ã³ãæ¢ã«æ¬çªç°å¢ã«ããããã®å®å®æ§ãæãéèŠãªèŠä»¶ã®1ã€ã§ããå Žåã¯ãOracle HotSpot JVMããä»»æã®å¥ã®ããªãå±éºãªåãã 5çªç®ãã6çªç®ã®Javaã«ç§»è¡ããå Žåã§ãããŠãŒã¶ãŒãééããåé¡ã®æ°ãæãåºããŠã¿ãŸãããã
ãããã¯ãžã®ãªã³ã¯ïŒ
- å ¬åŒJavaã¡ã¢ãªç®¡çããã¥ã¡ã³ã
- ã¬ããŒãžã³ã¬ã¯ã¿ãŒã®ã»ããã¢ããã«é¢ãããã¯ã€ãããŒããŒ
- GCã«åãçµãã§ãããµã³ã®åŸæ¥å¡ã®ããã°ã ããã§ã¯ãã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®ããŸããŸãªåŽé¢ã«ã€ããŠè©³ãã説æããŸãã 匷ããå§ãããŸãã
- JVMã¡ã¢ãªç®¡çã®ããŸããŸãªåŽé¢ã«é¢ããFAQ
- 代æ¿Azul GCã®èª¬æã ãŸããæ¢åã®ãœãªã¥ãŒã·ã§ã³ã®æ¬ ç¹ãææãããã®åå ã説æããŸãã