ç®ã®åã®ãããªã¬ããŒãïŒ
ãããŠãã«ããã®äžã«ãåã ã®ã¹ã©ã€ããå«ãå šæ転åãæçš¿ããŸããã
çšèªã«é¢ããå°ãåæ çãªäœè«ããå§ããŸãããã
ãšã¹ã±ãŒãåæãšæé©åã«ããããã®å Žæ
ãšã¹ã±ãŒãåæã¯ããªããžã§ã¯ãã®ãªã³ã¯ã®å°éå¯èœé åãéçã«ïŒã³ã³ãã€ã«æã«ïŒæ±ºå®ã§ããã³ãŒãåæææ³ã§ãã 倧ãŸãã«èšã£ãŠããªããžã§ã¯ããå²ãåœãŠãåœä»€ããããåæäžã«ãå¥ã®åœä»€ãäœæããããªããžã§ã¯ããžã®ãªã³ã¯ãäœããã®æ¹æ³ã§ååŸã§ãããã©ãããç解ããããšããŸãã
ãšã¹ã±ãŒãåæã¯ããèªäœãæé©åã§ã¯ãªããåãªãåæã§ããããã®çµæã¯åŸç¶ã®æé©åã«äœ¿çšã§ããŸãã éåžžãéåžžãåœä»€ã«å¯ŸããŠæ£ç¢ºã§ã¯ãªãå°éå¯èœæ§ã«é¢å¿ããããŸããããäœããã®ã¡ãœããã§äœæããããªããžã§ã¯ãããã®ã¡ãœããã®å€éšã«å°éå¯èœãã©ãããã®ãããªãã®ã§ãã ãããŠãæé©åã¿ã¹ã¯ã®äžéšãšããŠãçããããããããªããžã§ã¯ãã¯ã¡ãœããã®å€éšã«å°éã§ããªãããšããç¶æ³ã«æãèå³ããããŸãã
ã¹ã«ã©ãŒçœ®æ ã¹ã«ã©åãšã¯ãã¡ãœããå ã«ã®ã¿ååšãããªããžã§ã¯ããããŒã«ã«å€æ°ã«çœ®ãæããããšã§ãã ãªããžã§ã¯ããååŸãïŒå®éã«ã¯ãŸã ååšããŸãã-ããã°ã©ã ã®å®è¡æã«äœæãããŸãïŒãäœæããå¿ èŠã¯ãããŸããïŒãã¹ãŠã®ãã£ãŒã«ããããŒã«ã«å€æ°ã«å ¥ãããããã®ãã£ãŒã«ããåç §ããããã«ã³ãŒããå€æããå²ãåœãŠãŸãã³ãŒãããæ¶å»ããŸãã
ç§ã¯ãEA / SRããã®ãããªéçãªã¬ããŒãžã³ã¬ã¯ã¿ã§ãããšããæ¯metaã奜ãã§ãã éåžžã®ïŒåçãªïŒGCã¯ã©ã³ã¿ã€ã ã§å®è¡ããããªããžã§ã¯ãã®ã°ã©ããã¹ãã£ã³ããŠå°éå¯èœæ§åæãå®è¡ããŸããå°éäžèœã«ãªã£ããªããžã§ã¯ããèŠã€ãã䜿çšããŠããã¡ã¢ãªã解æŸããŸãã ãšã¹ã±ãŒããšã¹ã«ã©ãŒåã®ãã¢ã¯ãJITã³ã³ãã€ã«æã«åãããšãè¡ããŸãã ãšã¹ã±ãŒãåæãã³ãŒããèŠãŠãããã®åœä»€ã®åŸã«ããã§äœæããããªããžã§ã¯ãã¯ã©ãã«ãå°éã§ããªããããç¹å®ã®æ¡ä»¶äžã§ã¯ãŸã£ããäœæã§ããŸãããããšèšããŸãã
ããã€ãã®ãšã¹ã±ãŒãåæãšã¹ã«ã©ãŒçœ®æãJavaã§é·ãéç»å ŽããŸããã2009幎ã«æåã«å®éšçãªãªãã·ã§ã³ãšããŠç»å Žãã2010幎ããããã©ã«ãã§æå¹ã«ãªã£ãŠããŸãã
çµæã¯ãããŸããïŒ çãåã§ã¯ã2010幎ã«äœæãããã¬ããŒãžã³ã¬ã¯ã¿ãŒã®èªã¿èŸŒã¿ã¹ã±ãžã¥ãŒã«ã®å®éã®æçã¯ããã€ãéè¡ã«éãããŸãã ãã®å³ã¯ãæé©åã®ããã«ãŸã£ããäœãã§ããªããã次ã®Javaã®æŽæ°ãåŸ ã€ããšãããããšã瀺ããŠããŸãã
ãœãŒã¹ïŒ dolzhenko.blogspot.ru
ãã¡ãããããã¯ãã£ãã«èµ·ãããŸãããããã¯äŸå€çãªã±ãŒã¹ã§ãã ããçŸå®çãªäŸã§ã¯ãå¹³åçãªã¢ããªã±ãŒã·ã§ã³ã®ããŸããŸãªãœãŒã¹ã«ãããšããšã¹ã±ãŒãåæã¯å²ãåœãŠã®çŽ15ïŒ ãæé€ã§ãã幞éãªå Žåã¯æ倧70ïŒ ãæé€ã§ããŸãã
2010幎ã«ãã®ããŒã«ãç»å Žãããšããç§ã¯æ£çŽãéåžžã«åºæ¿ãåããŸããã ç§ã¯ãããžã§ã¯ããçµããã°ããã§ãç§åŠçãªèšç®ããããããããŸãããç¹ã«ãããããçš®é¡ã®ãã¯ãã«ãç©æ¥µçã«äœ¿ããŸããã ãããŠãåã®åœä»€ãã次ã®åœä»€ãŸã§çãç¶ããå€ãã®ãªããžã§ã¯ãããããŸããã ãããèŠããšããç§ã¯ããã§Cãè¯ãã ãããšå·éãªèããæã£ãŠããŸããã ãããŠããã®æé©åã«ã€ããŠèªãã åŸããã®ãããªåé¡ã解決ã§ããããšã«æ°ä»ããŸããã ãã ãããã®ãªãªãŒã¹ã§ã®Sunã®åäœã®æ§ãããªäŸããã£ãããããã詳现ãªèª¬æïŒåäœããç¶æ³ãåäœããªãç¶æ³ãåäœã«å¿ èŠãªãã®ïŒãåŸ ã£ãŠããŸããã ãããŠãç§ã¯é·ãéåŸ ã¡ãŸããã
æ®å¿µãªããšã«ã7幎以äžã«ãããã䜿çšäŸã3ã€ãããããŸããã§ãããããã®ãã¡ã®1ã€ã¯Sunã®äŸã§ãã ãã¹ãŠã®äŸã®åé¡ã¯ãèšäºãã³ã¡ã³ãä»ãã®ã³ãŒããåŒçšããŠããããšã§ããïŒããããã©ã®ããã«æ©èœããããã ãããŠãåœä»€ãåé 眮ãããšãã¹ã«ã©ãŒåã¯ããããå£ããŸããïŒ ãããŠãArrayListã®ä»£ããã«LinkedListã䜿çšãããšãæ©èœããŸããïŒ ã¯ã£ããããŸããã§ããã ãã®çµæãç§ã¯ä»ã®èª°ãã®ç 究ãã€ãŸã ãã®äœæ¥ãèªåã§è¡ãå¿ èŠããããŸãã
å®éšçµè·¯
äœãæã«å ¥ãããã§ããïŒ ãŸããçŽæçãªç解ãæ±ããŠããŸããã æããã«ãJITã³ã³ãã€ã«ã¯äžè¬çã«éåžžã«è€éãªãã®ã§ãããå€ãã®ããšã«äŸåããŠããŸãã 詳现ãç解ããã«ã¯ãOracleã§äœæ¥ããå¿ èŠããããŸãã ãã®ãããªä»äºã¯ãããŸããã§ããã ã³ãŒããèŠãŠããããè©äŸ¡ã§ããããã«ãçŽæçã«ç解ããå¿ èŠããããŸã-ã»ãŒééããªãã¯ãïŒ ãããŠããã®ããã«ã¯ãåäœãããšããšåäœããªããšããèŠãããšãã§ããããã€ãã®äŸãå¿ èŠã§ãã ãããŠããããã®äŸãç°¡åã«èšè¿°ã§ããããã«ãããã¬ãŒã ã¯ãŒã¯ã
ç§ã®ä»äºã¯å®éšçãªãã®ã§ãããããšãã°ãã³ã³ãã¥ãŒã¿ãŒã«JDKããããŸããåœå±ã«å°ããããšãªãããšã¹ã±ãŒãåæã®ååã«ã€ããŠã©ã®ãããªæ å ±ãå ¥æã§ããŸããã ã€ãŸããããã¯éåžžã«èªç¶ç§åŠçãªã¢ãããŒãã§ããç§ãã¡ã«ã¯ããçªã£èŸŒãã§ããã©ã®ããã«æ©èœããããèŠããã©ãã¯ããã¯ã¹ãã»ãšãã©ãããŸãã
å®éšãã®ãã®ã«åããããåã«ãããå°ãçè«çãªäœè«ã ãšã¹ã±ãŒãåæãšã¹ã«ã©ãŒåã¯ããµãŒããŒã³ã³ãã€ã©ãæã€å€§èŠæš¡ãªæé©åã®äžéšã«ãããªãããšãç解ããããšãéèŠã§ãã éåžžã«äžè¬çãªçšèªã§ã¯ãC2æé©åããã»ã¹ãå³ã«ç€ºãããŠããŸãã
ããã§éèŠãªããšã¯ããšã¹ã±ãŒãåæã®åã§ãã£ãŠããä»ã®æé©åããŒã«ãåé¡ãåŠçããããšã§ãã ããšãã°ãã€ã³ã©ã€ã³åãä»®æ³åãå®æ°ã®æãç³ã¿ãããã³é »ç¹ãŸãã¯ãŸããªã«ãŒãã®åŒ·èª¿è¡šç€ºïŒå®éãããã«å€ãã®ã«ãŒãããããŸãããããã§ã¯ãšã¹ã±ãŒãåæã«æãé »ç¹ã«åœ±é¿ããã«ãŒãã瀺ããŸããïŒã ãã®ããããšã¹ã±ãŒãåæã®çµæã«åŸã£ãŠãäžéšã®ãªããžã§ã¯ããã¹ã«ã©ãŒåãããããããã§ãŒã³ã®ä»¥åã®ãã¹ãŠã®ãªã³ã¯ã以åã®æé©åã¯ããšã¹ã±ãŒãåæãšã¹ã«ã©ãŒåã®åã«ããŸãæ©èœããå¿ èŠããããŸãã ãããŠãäœããå£ããå¯èœæ§ããããããã¯ã©ã®æ®µéã§ãèµ·ããããŸããããåŸã§èŠãããã«ãã»ãšãã©ã®å Žåããšã¹ã±ãŒãåæã®çŽåã«äœããå£ããŸãã ãããŠãå Žåã«ãã£ãŠã®ã¿ãã¿ã¹ã¯ã«å¯ŸåŠããªãã®ã¯ãšã¹ã±ãŒãåæãã®ãã®ã§ãã
ããŒã«ããã
æ°å¹Žåãã¹ã«ã©ãŒåã®å®éšãè©Šã¿ãŠãäž»ã«
GarbageCollectorMXBean.getCollectionCount()
äŸåããŠããŸããã ããã¯ããªãç²éãªã¡ããªãã¯ã§ãã ããããããæ確ãªæž¬å®å€
ThreadMBean.getThreadAllocatedBytes(threadId)
ããããŸããããã¯ãã¹ã¬ããIDã«ãã£ãŠçŽæ¥ããã®ç¹å®ã®ã¹ã¬ããã«ãã£ãŠå²ãåœãŠããããã€ãæ°ã瀺ããŸãã å®éšã«ã¯ä»ã«äœãå¿ èŠãããŸããããæåã«äœ¿çšããæåã®å€ãã¡ããªãã¯ã䜿çšããŠçµæãæ¯èŒããŸããã å¥ã®å¶åŸ¡æ¹æ³ã¯ãé©åãªããŒïŒ
-XX:-EliminateAllocations
ïŒã§
-XX:-EliminateAllocations
åãç¡å¹ã«ãã芳å¯ãããå¹æããšã¹ã±ãŒãåæã«ãã£ãŠå®éã«æ±ºå®ããããã©ããã確èªããããšã§ãã
ãã¹ãçµæã«é©ãå ŽåãPrintCompilationããŒãšPrintInliningããŒã䜿çšããŠã詳现æ å ±ãååŸã§ããŸãã 3çªç®ã®ããŒLogCompilationããããŸããããã¯ãåããã®ãããå€ããããã«xml圢åŒã§çæããŸãããããJITWatchãŠãŒãã£ãªãã£ã«ãã£ãŒããããšããã¹ãŠãçŸããUIã§è¡šç€ºãããŸãã
è«ççãªè³ªåã¯ããªãJMHã䜿çšããªãã®ããšããããšã§ãã JMHã¯æ¬åœã«ãããè¡ãããšãã§ããŸãã ãããã¡ã€ã©ãŒã§ãã
-prof gc
ã䜿çšãããšãåãå²ãåœãŠãåºåããã1åã®ç¹°ãè¿ãã«æ£èŠåãããŸãã
ãããŠãæåã¯ãã¡ãããå ¥ãããšããŸããã ããããå®éã®ãšãããJMHã¯äž»ã«ããã©ãŒãã³ã¹ã«éç¹ã眮ããŠãããããããŸãèå³ããããŸããã ç¹°ãè¿ãã«ã©ãã ãæéãããã£ããã«ã€ããŠã¯èå³ããããŸããã ç¹å®ã®æé©åãããã§æ©èœãããã©ãããèšãæããã°ãããªã¬ãŒå¿çãå¿ èŠãã©ããçåã«æã£ãŠããŸãã ãããŠãããã«ç§ãããã«åé€ããæ¹æ³ãèŠã€ããããªãã£ãå€ãã®æ å ±ããããŸãã æçµçã«ãç§ã¯ä»æ¥ã30å以å ã«çµæãååŸãããå Žåãèªåã§ãããæžãæ¹ãç°¡åã ãšæ±ºããŸããã ãããã£ãŠãç§ã¯èªåã®ãèªè»¢è»ããæã£ãŠããŸãã ãããã誰ãããããã®å®éšãç¶ãããããŸãã¯èªåã§å®éšããããå Žåã¯ãæšæºãéåžžããè¯ãã®ã§ãæšæºããŒã«ã䜿çšããããšã匷ããå§ãããŸãã
ããŒã1.åºæ¬
äŸ1.1ã ããŒã·ãã¯
ç°¡åãªãã¹ãããå§ããŸãããïŒSunãªãªãŒã¹ã®äŸã«äŒŒãŠããŸãã
åçŽãªVector2Dã¯ã©ã¹ããããŸãã ã©ã³ãã æ§ã®å©ããåããŠ3ã€ã®ã©ã³ãã ãªãã¯ãã«ãäœæãããããã䜿çšããŠç¹å®ã®æŒç®ãå®è¡ããŸãïŒã¹ã«ã©ãŒç©ãè¿œå ããã³èšç®ããŸãïŒã ææ°ã®JVMã§ãããå®è¡ãããšãããã§ããã€ã®ãªããžã§ã¯ããäœæãããŸããïŒ
ãã®çµæãæåã«äœããå²ãåœãŠãããŸãïŒã³ã³ãã€ã«ã¯ãŸã æž¡ãããŠããŸããïŒãããããããã¹ãŠãéåžžã«ãããã§ã-åŒã³åºãããšã«0ãã€ãã
ããã¯æšæºçãªäŸã§ãããããæ©èœããããšã¯é©ãããšã§ã¯ãããŸããã
å¶åŸ¡ã®ããã«ãå²ãåœãŠã®æ¶å»ãç¡å¹ã«ããããŒãè¿œå ããåŒã³åºãããšã«128ãã€ããååŸããŸãã ãããã¯ãã 4ã€ã®Vector2Dãªããžã§ã¯ãã§ãã3ã€ã¯æ確ã«äœæããããã1ã€ã¯è¿œå äžã«è¡šç€ºãããŸããã
äŸ1.2 ã«ãŒã环ç©
åã®äŸã«ã«ãŒããè¿œå ããŸãã
ã«ãŒãå ã§ãã¯ãã«ãè¿œå ããããããªãŒãã¯ãã«ãéå§ããŸãã
ãã®ã·ããªãªã§ããã¹ãŠé 調ã§ãïŒç§ã調ã¹ã
SIZE
å€ã«ã€ããŠïŒã
äŸ1.3 ã«ãŒãå ã§çœ®æ
ä»åã¯ãå®æ°-doubleãä¹ç®ããçµæãåãå€æ°ã«æžã蟌ã¿ãŸãã ããã¯å®éã«ã¯åãããããªãŒã§ããããã§ã¯ããã¯ãã«ã«ããæ°ãæããŸãã
äºæ³å€ã§ãããããã§ã¯ã¹ã«ã©ãŒåã¯æ©èœããŸããã§ããïŒ2080ãã€ã= 32 *ïŒSIZE + 1ïŒïŒã
çç±ãç解ããåã«ãããã€ãã®äŸãæ€èšããŠãã ããã
äŸ1.4 å¶åŸ¡ãããŒ
ç°¡åãªäŸïŒãµã€ã¯ã«ã¯ãããŸãããæ¡ä»¶ä»ãé·ç§»ããããŸãã ã©ã³ãã ã«åº§æšãéžæããVector2DãäœæããŸãã
ãããŠãããã§ã¹ã«ã©ãŒåã¯åœ¹ã«ç«ããªãïŒ1ã€ã®ãã¯ãã«ãäœæããããã³ã«-ãããã®åã32ãã€ãã
äŸ1.5 å¶åŸ¡ãããŒ
ãã®äŸãå°ãå€æŽããŠã¿ãŸãããã ãã¯ãã«ã®äœæãäž¡æ¹ã®ãã©ã³ãå ã«è¿œå ããã ãã§ãã
ãããŠãããã§ã¯ãã¹ãŠãå®å šã«ã¹ã«ã©ãŒåãããŠããŸãã
çµµãçŸãå§ããŸã-ããã§äœãèµ·ãã£ãŠããŸããïŒ
ããã€ã³ããããŒãžã
ããã°ã©ã ã«å®è¡ã¹ã¬ããããããšæ³åããŠãã ããã v1ãªããžã§ã¯ããäœæãã1ã€ã®ãã©ã³ããšãv2ãªããžã§ã¯ããäœæãã2çªç®ã®ãã©ã³ãããããŸãã 3çªç®ã®å€æ°v3ã«ã¯ãå®è¡ã«ããã£ãã«ãŒãã«å¿ããŠãæåã®ãªããžã§ã¯ããŸãã¯2çªç®ã®ãªããžã§ã¯ããžã®ãªã³ã¯ãèšè¿°ããŸãã æåŸã«ãv3ãªã³ã¯ãä»ããŠãã£ãŒã«ããè¿ããŸãã ã¹ã«ã©ãŒåãçºçãããã£ãŒã«ãv1.xãv1.yãv2.xãv2.yãããŒã«ã«å€æ°ãããšãã°v1 $ xãv1 $ yãv2 $ xãv2 $ yã«ãªã£ããšããŸãã ãããŠãv3ãªã³ã¯ãã©ãããŸããïŒ ãšãããããã£ãŒã«ãv3.xãžã®ã¢ããŒã«ã¯ã©ããªãã®ã§ããããïŒ
ããã¯è³ªåã§ãã ãããäŸ1.4ã®ãããªããã€ãã®ç°¡åãªäŸã§ã¯ããœãªã¥ãŒã·ã§ã³ã¯çŽæçã§ãããã®ã³ãŒãããã¹ãŠã§ããå Žåãæ¡ä»¶å ã§ã¹ããŒãã¡ã³ããè¿ãã ãã§ãåãã©ã³ãã«1ã€ãã€ã2ã€ã®æ»ãå€ããããŸãã ããããŠããããããã®å€ãè¿ããŸãã ããããã±ãŒã¹ã¯ããè€éã§ãããããJVMéçºè ã¯ãã®ã·ããªãªãåçŽã«æé©åããªããšå€æããŸããã äžè¬çãªå Žåããããè¡ãã«ã¯-䜿çšãããªããžã§ã¯ãã®ãã£ãŒã«ããææ¡ããŸã-é£ããããããšãå€æããŸããïŒããšãã°ãJDK-6853701ãã°ããŸãã¯JVMãœãŒã¹ã³ãŒãã®å¯Ÿå¿ããã³ã¡ã³ããåç §ïŒã
ãã®äŸããŸãšãããšã次ã®å Žåã«ã¯ã¹ã«ã©ãŒåã¯ãããŸããã
- åç
§å€æ°ã¯è€æ°ã®ãªããžã§ã¯ããæãããšãã§ããŸãã
- ãããç°ãªãå®è¡ã·ããªãªã§çºçããå Žåã§ãã
ã¹ã«ã©ãŒåã®å¯èœæ§ãé«ãããå Žåã¯ã1ã€ã®ãªã³ã¯ã1ã€ã®ãªããžã§ã¯ããæããŠããå¿ èŠããããŸãã åžžã«1ã€ã®ãªããžã§ã¯ããæããŸãããç°ãªãå®è¡ã·ããªãªã§ã¯ç°ãªããªããžã§ã¯ãã«ãªãå¯èœæ§ããããŸã -ããã§ããããšã¹ã±ãŒãåæãæ··ä¹±ãããŸãã
ããŒã2. EqualsBuilder
ããã¯commons.langã®ã¯ã©ã¹ã§ãããã¯ã©ã¹ã®ãã£ãŒã«ããBuilderã«è¿œå ããããšã«ããããã®æ¹æ³ã§åçã®ãã®ãçæã§ãããšããèãæ¹ã§ãã æ£çŽã«èšã£ãŠãç§ã¯ãããèªåã§ã¯äœ¿çšããããã«ããŒã®äŸãå¿ èŠãšããŠããŸããã å®éã®äŸã¯éåžžãåæã®äŸãããåªããŠããŸãã
ãã¡ããããã¹ãŠã®equalsåŒã³åºãã«å¯ŸããŠãªããžã§ã¯ããäœæããããšã¯ãå§ãã§ããŸããã®ã§ããã®ããšãã¹ã«ã©ãŒåãããšããã§ãããã
äŸ2.1 EqualsBuilder
ç°¡åãªã³ãŒããæžããŸãã-æ瀺çã«æžããã2ã€ã®intã ãã§ãïŒãã ãããã£ãŒã«ããããã«æå®ãããŠããŠããæ¬è³ªã¯å€ãããŸããïŒã
ãã®ç¶æ³ã¯ã¹ã«ã©ãŒåãããããšãäºæ³ãããŸãã
äŸ2.2 EqualsBuilder
äŸãå°ãå€æŽããŠã¿ãŸãããã2ã€ã®intã®ä»£ããã«ã2è¡ãè¿œå ããŸãã
ãã®çµæãã¹ã«ã©ãŒåã¯æ©èœããŸããã
.appendïŒ...ïŒã¡ãœããã«ã¯ãŸã å ¥ããŸããã ãŸããã³ã³ãã€ã©ã§äœãèµ·ããããå°ãªããšãç°¡åã«äŒããããŒããããŸãã
appendã¡ãœããã倱æããªãã£ãããããšã¹ã±ãŒãåæãç解ã§ããªãããšãããããŸãããããã«ããã®ããã«.appendïŒïŒã¡ãœããã®å éšã«å ¥ã£ããã«ããŒãžã®ãªã³ã¯ããããŸãã ããã¯äžæã§ãïŒã³ã³ãã€ã©ãŒã¯.appendã¡ãœããã®å éšã調ã¹ãªããããJITã¯ããã·ãŒãžã£ãŒéã®æé©åãè¡ããŸããïŒã å€å圌女ã¯ããã§ã°ããŒãã«å€æ°ã«å²ãåœãŠãããã®ã§ãããã ãããŠããã®ãããªç¶æ³ã§ã¯ãè±åºåæã¯éäŒããŸãã
ããããã¡ãœããã倧ããããããšãã蚺æã¯ã©ãããæå³ã§ããïŒ ã¡ãœããããããã§ããããšãã€ãŸã ããã¯äœåºŠãåŒã³åºããããã®ãã€ãã³ãŒãã®ãµã€ãºã¯ç¹å®ã®å¶éã§ããã€ã³ã©ã€ã³åãããå€ïŒå¶éã¯é »ç¹ãªã¡ãœããã®å¶éïŒããã倧ãããªã£ãŠããŸãã ãã®å¶é-FreqInlineSizeããŒã«ãã£ãŠèšå®ãããããã©ã«ãã§ã¯325ã§ãã蚺æã§ã¯327ã衚瀺ãããŸã-ã€ãŸãã2ãã€ãã ããæ¬ èœããŠããŸãã
ã¡ãœããã®å 容ã¯æ¬¡ã®ãšããã§ã-327ãã€ãããããšç°¡åã«ä¿¡ããããŸãã
仮説ãã©ã®ããã«ãã¹ãã§ããŸããïŒ FreqInlineSizeããŒãè¿œå ããã€ã³ã©ã€ã³åã®ãããå€ãããšãã°328ã«å¢ããããšãã§ããŸãã
ã³ã³ãã€ã«ãããã¡ã€ã«ã§ã¯ã.appendïŒïŒãã€ã³ã©ã€ã³åããããã¹ãŠãå®å šã«ã¹ã±ãŒã©ãã«ã§ããããšãããããŸãã
æ確ã«ããŸããããJVMãã©ã°ãJITã³ã³ãã€ã«ãªãã·ã§ã³ãïŒä»¥äžã§ïŒå€æŽãããšããç¶æ³ãä¿®æ£ããã®ã§ã¯ãªãã仮説ããã¹ãããããã«ãããè¡ããŸãã JITã³ã³ãã€ã«ãªãã·ã§ã³ã¯ãç¹å¥ã«èšç·Žããã人ã ã«ãã£ãŠéžæãããããããããã®ãªãã·ã§ã³ã䜿çšããããšã¯ãå§ãããŸããã ãã¡ãããè©ŠããŠã¿ãããšã¯ã§ããŸãããå¹æãäºæž¬ããããšã¯å°é£ã§ãããã®ãããªãã©ã¡ãŒã¿ãŒã¯ãäœããã¹ã«ã©ãŒåããç¹å®ã®ã¡ãœããã§ã¯ãªããããã°ã©ã å šäœã«åœ±é¿ããŸãã
çµè«2ã
- ã€ã³ã©ã€ã³åã¯ã¢ãããã£ãã©ã³ã¿ã€ã ã®èŠªåã§ã
- ãããŠç°¡æœãã¯åœŒã倧ãã«å©ããŸãã
ããçãã¡ãœãããèšè¿°ããŸãã ç¹ã«ã.appendïŒïŒã®äŸã§ã¯ãé åã§åäœãã倧ããªã·ãŒãããããŸã-é åã®æ¯èŒãè©Šã¿ãŸãã å¥ã®ã¡ãœããã«å ¥ããã ãã§ããã¹ãŠãå®å šã«ã€ã³ã©ã€ã³åãããã¹ã«ã©ãŒåãããŸãïŒè©ŠããŸããïŒã ãã®ã€ã³ã©ã€ã³ãã¥ãŒãªã¹ãã£ãã¯ã§ã¯ãããã¯éåžžã«é»ãåãã§ãïŒçœãå ŽåããããŸãïŒïŒ328ãã€ãã®ã¡ãœããã¯ã€ã³ã©ã€ã³ã§ã¯ãããŸãããã200ãã€ãã®2ã€ã®ã¡ãœããã«å®å šã«ã€ã³ã©ã€ã³ã§åå²ãããŠããŸãã
ããŒã3.è€æ°å€ã®æ»ãå€
tupleã¡ãœããããæ»ãããšãæ€èšããŠãã ãã-äžåºŠã«ããã€ãã®å€ã
Pairãªã©ã®ç°¡åãªãªããžã§ã¯ããšãå®å šã«åçŽãªäŸãèŠãŠã¿ãŸããããäºåã«èšå®ãããããŒã«ããã©ã³ãã ã«éžæããã2ã3ã®è¡ãè¿ããŸãã ã³ã³ãã€ã©ããã®ã³ãŒãããŸã£ããã¹ããŒããªãããã«ãå¯äœçšãå°å ¥ããŸãããããã®ã¿ã€ãæååã§äœããã«ãŠã³ãããçµæãè¿ããŸãã
ãã®ã·ããªãªã¯ã¹ã«ã©ãŒåãããŠããŸãã ããã¯éåžžã«å®çšçãªäŸã§ããã䜿çšããããšãã§ããŸããã¡ãœããããããã§ã€ã³ã©ã€ã³ã®å Žåããã®ãããªè€æ°å€ã¯å®å šã«ã¹ã«ã©ãŒåãè¿ããŸãã
äŸ3.1 å€ãŸãã¯null
äŸãå°ãå€æŽããŠã¿ãŸããããç¶æ³ã«ãã£ãŠã¯ãnullãè¿ããŸãã
ã芧ã®ãšãããå²ãåœãŠã¯æ®ããŸãïŒåŒã³åºãããšã®å¹³åãã€ãæ°ã¯æŽæ°ã§ã¯ãããŸãããããã¯ãnullãè¿ãããšããããããã³ã¹ãã¯ããããŸããïŒã
äŸ3.2 æ··ååïŒ
ããè€éãªäŸïŒPairã€ã³ã¿ãŒãã§ãŒã¹ãšããã®ã€ã³ã¿ãŒãã§ãŒã¹ã®2ã€ã®å®è£ ããããŸãã 人çºçãªæ¡ä»¶ã«å¿ããŠããã®å®è£ ãŸãã¯å¥ã®å®è£ ãè¿ããŸãã
ããã§ããå²ãåœãŠã®ãŸãŸã§ãã
æ£çŽãªãšãããæåã¯ç°ãªãã¿ã€ãã§ãããšç¢ºä¿¡ããŠããŸããããé·ãéä¿¡ããŠããŸããããåãã¿ã€ãã§ã¹ã«ã©ãŒã§ã¯ãªã次ã®äŸãäœæããŸããã
ããã§äœãèµ·ãã£ãŠããŸããïŒ ããŠããã¹ãŠã®ã¡ãœããããã³ã§ã€ã³ã©ã€ã³åããããšãããšãæåã®å®éšã®ããã«ãåãã¹ã¯ãªããã«ããŒãžãã€ã³ãïŒ=ãªã³ã¯ã«ã¯2ã€ã®æ¹æ³ããããŸãïŒã衚瀺ãããŸãã
çµè«3ïŒ
ã·ã³ãã«ã«ä¿ã€ïŒãã©ã³ãã®æ°ãæžãã-ãšã¹ã±ãŒãåæãæ··ä¹±ããã«ãã
äŸ4.ã€ãã¬ãŒã¿ãŒ
å¥ã®é »ç¹ãªãã¿ãŒã³ãšéåžžã«é »ç¹ã«è¡šç€ºãããäžéãªããžã§ã¯ãããã®äœæã¯é¿ãããã
ããã¯ãã³ã¬ã¯ã·ã§ã³ãå埩åŠçããéåžžã«åçŽãªã·ããªãªã§ãã ã³ã¬ã¯ã·ã§ã³ã1åäœæããå埩ããšã«åäœæããã®ã§ã¯ãªããå埩åãåäœæããŸããåã¡ãœããã®èµ·åæã«ãå埩åãä»ããŠã³ã¬ã¯ã·ã§ã³ãå®è¡ããå¯äœçšãèæ ®ããŸãïŒã³ã³ãã€ã©ãŒããã®éšåãã¹ããŒããªãããã«ããããïŒã
ããŸããŸãªã³ã¬ã¯ã·ã§ã³ã«å¯ŸããŠãã®ã·ããªãªãæ€èšããŠãã ããã ãŸãArrayListã«ã€ããŠèããŸããã
äŸ4.1 ArrayList.iterator
ArrayListã®å Žåãå埩åã¯å®éã«ã¹ã«ã©ãŒåãããŸãïŒSIZEãµã€ãºã¯æ¡ä»¶ä»ãã§ååŸãããŸãïŒååãšããŠãããã¯åºç¯å²ã®SIZEã«å¯ŸããŠå®å®ããŠæ©èœããŸãïŒã LinkedListã®å Žåããããæ©èœããŸãã é·ãéããã¹ãŠã®ãªãã·ã§ã³ãæ€èšããããšã¯ããŸãããããã«ãç§ãè©Šããã³ã¬ã¯ã·ã§ã³ã®èŠçŽè¡šã瀺ããŸãã
Java 8ã§ã¯ããããã®å埩åã¯ãã¹ãŠïŒå°ãªããšãåçŽãªã¹ã¯ãªããã§ã¯ïŒã¹ã«ã©ãŒåãããŸãã
ããããææ°ã®æŽæ°ã§ã¯ãJava 7ã®æ¹ãæ±ãã«ããã§ãã ããã詳ããèŠãŠã¿ãŸãããïŒ1.7ã¯ãã§ã«å»æ¢ããã1.7.0_80ãæåŸã®æŽæ°ã§ããããšã誰ããç¥ã£ãŠããŸãïŒã
ãµã€ãºã2ã®LinkedListã®å Žåããã¹ãŠããŸããããŸãã
ãã ãããµã€ãºã65ã®LinkedListã®å Žå-ãããã
äœãèµ·ãã£ãŠããã®ïŒ
ããžãã¯ããŒãååŸãããµã€ãº2ã®å Žåããã®ãããªã€ã³ã©ã€ã³ãã°ã®äžéšãååŸããŸãã
ãµã€ãº65ã®å ŽåïŒ
åããã°ã®å é ã«è¿ããšããã«ããã®ãããªç»åã®è¿œå ãã©ã°ã¡ã³ãããŸã ãããŸãã
次ã®ããšãèµ·ãããŸããæåã«ããããã¡ã€ãªã³ã°ããŠããã¡ãœãããã³ã³ãã€ã«ã«è¡ããŸãã-JITããã¥ãŒã«å ¥ããŸããã JITã¯éåæã«åäœããŸããã€ãŸãã 圌ã«ã¯ãã¥ãŒããããã³ã³ãã€ã«ã¿ã¹ã¯ãããã«ã¹ããŒãããå¥ã®ã¹ã¬ããïŒãŸãã¯è€æ°ã®ã¹ã¬ããïŒã§äœããã®ã¬ãŒãã§ãã¥ãŒããããããåãåºããŠã³ã³ãã€ã«ããŸãã ã€ãŸãã圌ã«ã¿ã¹ã¯ãäžããããç¬éãšãæ°ããã³ãŒããæé©åãããç¬éã®éã«ããã°ããæéãããããŸãã
ãããŠä»ãç§ãã¡ã®
iterate()
ã¡ãœããã¯åããŠã³ã³ãã€ã«ã«è¡ããŸããããã®éã«ããã®äžã®
LinkedList.listIterator()
ã¡ãœããããŸã å®è¡ãããŠããªãããšãçºèŠãããŸããã ãŸã ã€ã³ã©ã€ã³åã§ããŠããŸããïŒ
MinInliningThreshold
= 250ã³ãŒã«ïŒã ãã°ããããŠã
iterate()
åŒã³åºããåã³ã³ãã€ã«ã«äœ¿çšããããšãã
LinkedList.listIterator()
ã®ã³ã³ãã€ã«ãããïŒãã·ã³ïŒã³ãŒã
LinkedList.listIterator()
倧ããããããšã
LinkedList.listIterator()
ã
ã¯ãã蚺æã®æ£ç¢ºãªæå³ïŒ
ã€ãŸãã ã³ã³ãã€ã«æžã¿ã®ã¡ãœããã®ãµã€ãºãæšå®ãããšãã¯ããã€ãã³ãŒãã§ã¯ãªãããã·ã³ã³ãŒãã調ã¹ãŸãïŒããã¯ããé©åãªã¡ããªãã¯ã§ããããïŒã ãããŠãããã2ã€ã®ãã¥ãŒãªã¹ãã£ãã¯-ãã€ãã³ãŒããšãã·ã³ã³ãŒãã®èŠ³ç¹ãã-ã¯å¿ ãããäžè²«ããŠããŸããã 5ã€ã®ãã€ãã³ãŒãã®ã¿ã®ã¡ãœããã¯ãä»ã®ããã€ãã®ã¡ãœãããåŒã³åºããŠè²Œãä»ãããã·ã³ã³ãŒãã®ãµã€ãºããããå€ããã倧ããããããšãã§ããŸãã ãã®ççŸãæ ¹æ¬çã«è§£æ±ºããããšã¯ã§ããŸãããããŸããŸãªãã¥ãŒãªã¹ãã£ãã¯ã®ãããå€ãå€å°èª¿æŽããã ãã§ãå¹³åããŠãã¹ãŠãããçšåºŠè¯ããªãããšãæåŸ ããŠããŸãã
ãããå€-ç¹ã«InlineSmallCode-ã¯ããŒãžã§ã³ã«ãã£ãŠç°ãªããŸãã 8ã«ã¯2åã®InlineSmallCodeããããããJava 8ã§ã¯ãã®ã¹ã¯ãªããã¯æ£åžžã«æ©èœããŸããã¡ãœããã¯ã€ã³ã©ã€ã³ã§ãã€ãã¬ãŒã¿ãŒã¯ã¹ã«ã©ãŒåãããŸããã7ã§ã¯ããã§ã¯ãããŸããã
ãã®äŸã§ã¯ãäžå®å®ã§ããããšãéèŠã§ãã ã³ã³ãã€ã«ã¿ã¹ã¯ããã®é åºã§é²ãã«ã¯ïŒå¹žéãªããšã«ïŒã¯ãã§ãã 2åç®ã®åã³ã³ãã€ã«ã®æç¹ã§
LinkedList.listIterator()
ã¡ãœããããŸã åå¥ã«ã³ã³ãã€ã«ãããŠããªãã£ãå ŽåããŸã ãã·ã³ã³ãŒãã¯ãªãããã€ãã³ãŒãã®ãµã€ãºã®åºæºã«åæ Œããæ£åžžã«ã€ã³ã©ã€ã³åãããŠããŸããã ãã®ãããçµæã¯ãªã¹ãã®ãµã€ãºã«äŸåããŸããç°ãªãã¡ãœãããã³ã³ãã€ã«ã«éä¿¡ãããé床ã¯ãã«ãŒãå ã®å埩åæ°ã«äŸåããŸãã
ãã®ä»®èª¬ããã¹ãã§ããŸããæ¥æµã§éã¶ããšã§ãã å®éããããããã£ããã£ã³ã°ãããšãã¹ã«ã©ãŒåãæ©èœãå§ããŸãã
çµè«4ïŒ
- JVMã®æåã®é®®åºŠã¯ãæåã®é®®åºŠãããåªããŠããŸãã
- -XXïŒ+ PrintInlining-éåžžã«åªãã蚺æãã¹ã«ã©ãŒåäžã«äœãèµ·ããããç解ã§ããäž»èŠãªèšºæã®1ã€ã
- å®éã®ããŒã¿ã§ãã¹ãããŸã-150ãæåŸ
ããå Žåã2ã®ãµã€ãºã§ãã¹ãããå¿
èŠã¯ãããŸããã150ã§ãã¹ããããšãéããèŠãããšãã§ããŸãã
- ArrayListã¯åã³LinkedListãèšå®ããŸãïŒ
åçã©ã³ã¿ã€ã ã¯ã«ãŒã¬ããã§ãã JITã³ã³ãã€ã«ã¯é決å®çã§ãããé¿ããããŸããã æè¿ã®ããŒãžã§ã³ïŒ8-keïŒã§ã¯ããã¥ãŒãªã¹ãã£ãã¯ã®ãã©ã¡ãŒã¿ãŒã¯äºãã«è¥å¹²èª¿æŽãããŠããŸãããããã¯é決å®æ§ããã£ã³ã»ã«ãããã®ã§ã¯ãªããåã«ãã£ããããã®ãããå°é£ã§ãã
äŸ4.4 Arrays.asListïŒïŒ
ã³ã¬ã¯ã·ã§ã³ã®å¥ã®èå³æ·±ãããŒãžã§ã³ããããŸã-é åã®ã©ãããŒãArrays.asListïŒïŒã JITããããã¹ã«ã©ãŒåããããã«ããã®ã©ãããŒã䟡å€ããªãããšãæã¿ãŸãã
ããã§ã¯ããªãå¥åŠãªã·ããªãªããå§ããŸã-é åãããªã¹ããäœæããã€ã³ããã¯ã¹ã䜿çšããŠãé åãééãããã®ããã«ãªã¹ãã調ã¹ãŸãã
ããã§ãã¹ãŠãæ©èœããã©ãããŒã®äœæã¯ã¹ã«ã©ãŒåãããŸãã
ãããŠãã€ãã¬ãŒã¿ã«æ»ããŸã-é åã®ããã«ãªã¹ãå ã移åã§ããããã«ãé åããªã¹ãã§ã©ããããããšã¯ããŸãæå³ããããŸããã
æ®å¿µãªãããææ°ããŒãžã§ã³ã®Javaã§ããå²ãåœãŠã¯æ®ã£ãŠããŸãã
åæã«ãPrintInliningã«ã¯ç¹å¥ãªãã®ã¯èŠåœãããŸããã
ããããããèŠããšãArrays $ ArrayListã®ã€ãã¬ãŒã¿ãããèªäœã§ã¯ãªãããšã«æ³šç®ããŠãã ããããã®å®è£ ã¯AbstractListããå®å šã«ç¶æ¿ãããŸãã
ãããŠãAbstractList $ Itrã¯ãå éšã¯ã©ã¹ãééçå éšã¯ã©ã¹ã§ãã ãããŠããããééçã§ãããšããäºå®-äœããã®çç±ã§ã¹ã«ã©ãŒåã劚ããŸãã ã€ãã¬ãŒã¿ã¯ã©ã¹ãæžãæããïŒã€ãŸããArrays $ ArrayListã¯ã©ã¹å šäœãããèªäœã«ã³ããŒããŠå€æŽããïŒå Žåãã€ãã¬ãŒã¿ããã¢ã³ãã£ãã«ããŸã-ã€ãã¬ãŒã¿ã«é åãæž¡ãããã€ãã¬ãŒã¿ã«ã¯ãªã¹ããªããžã§ã¯ããžã®åç §ãå«ãŸããªããªããŸã-ãã®ã·ããªãªã§ã¯ãå²ãåœãŠãšããŠã¹ã«ã©ãŒåãããŸãã€ãã¬ãŒã¿ãããã³ã©ãããŒèªäœã®å²ãåœãŠ$ ArrayListã
ããã¯ããªãäžå¯è§£ãªã±ãŒã¹ã§ãããããã¯JITã®ãã°ã®ããã§ãããä»æ¥ãŸã§ã®ã¢ã©ã«ã¯æ¬¡ã®ãšããã§ãããã¹ãããããªããžã§ã¯ãã¯ã¹ã«ã©ãŒåãæ··ä¹±ãããŸãã
äŸ4.4 ã³ã¬ã¯ã·ã§ã³*
ãã®ãããªã·ã³ã°ã«ãã³ã®ã³ã¬ã¯ã·ã§ã³ããŸã ããã€ãããããããã®ãã¹ãŠãšãã®ã€ãã¬ãŒã¿ã¯ãäžèšã®Arrays.asListãé€ããJavaã®çŸåšããã³ä»¥åã®ããŒãžã§ã³ã§æ£åžžã«ã¹ã«ã©ãŒåãããŠããŸãã
çµè«4.4ã
ãã¹ãããããªããžã§ã¯ãã¯éåžžã«ã¹ã±ãŒã©ãã«ã§ã¯ãããŸããã
- ã³ã¬ã¯ã·ã§ã³ããã®ã©ãããŒã®å埩ã
- ... Arrays.asListïŒïŒãé€ã
- ãã¹ãããããªããžã§ã¯ãã¯ã¹ã«ã©ãŒåãããŸããïŒå
éšã¯ã©ã¹ãå«ãïŒã
- -XXïŒ+ PrintInliningã¯åŒãç¶ãåé¡ã解決ããŸãã
äŸ5.äžå®ãµã€ãºã®é å
å¯å€ãµã€ãºã®é åïŒã€ãŸããJITãäºæž¬ã§ããªããµã€ãºïŒã®ã¹ã«ã©ãŒåããæãã§ããªãããšãããã«æ確ã«ããŸãã äžå®ã®é·ãã®é åã䜿çšããŸãã
äŸ5.1ã å¯å€ã€ã³ããã¯ã¹
ãã®äŸãèããŠã¿ãŸããããé åãååŸããããã®ã»ã«ã«äœããæžã蟌ã¿ãããããäœããåŒããŸãã
ãµã€ãº1ã®å Žåããã¹ãŠãæ£åžžã§ãã
ãµã€ãº2ã§ã¯ãäœãèµ·ãããŸããã
äŸ5.2ã å®æ°ã€ã³ããã¯ã¹
ãããã«ç°ãªãã¢ã¯ã»ã¹ãè©ŠããŠã¿ãŸãããïŒåããµã€ãº2ãåãããã³ãã«ã§ïŒå±éïŒã«ãŒããå±éããã ãã§ã-ãããååŸããæ瀺çãªã€ã³ããã¯ã¹ãèŠãŠãã ããïŒ
ãã®å Žåãå¥åŠãªããšã«ãã¹ã«ã©ãŒåãæ©èœããŸãã
ç§ã¯é·ãéè°è«ããŸãã-以äžã¯èŠçŽçã§ãã æåã§å±éããããµã€ã¯ã«ã®ãã®ã±ãŒã¹ã¯ããµã€ãº64ãŸã§ã¹ã«ã©ãŒåãããŸããããçš®ã®å€æ°ã€ã³ããã¯ã¹ãããå Žåããµã€ãº1ãš2ã¯äœããã®æ¹æ³ã§ã¹ã«ã©ãŒåãããŸããããã以äžã¯ã¹ã«ã©ãŒåãããŸããã
ããã°ã®èª°ããç§ã«æžããããã«ãJVMã«ã¯ãã¹ãŠã®ããã®ç¬èªã®ããŒããããŸãã ãã®äžéãããå€ïŒ-XXïŒEliminateAllocationArraySizeLimit = 64ïŒãèšå®ã§ããŸãããæå³ããªãããã«æããŸãã 極端ãªå Žåã64åã®ããŒã«ã«å€æ°ãè¿œå ãããŸãããããã¯å€ãããŸãã
äŸ5.3 ããªããã£ãé å
ãŸã£ããåãã³ãŒããããªããã£ãåã®é åã®ã¿-intãshort ...
ãã¹ãŠã¯ããªããžã§ã¯ãã®å ŽåãšãŸã£ããåãå Žåã«æ©èœããŸãã
ã«ãŒãããé åãã¹ã«ã©ãŒåã§ããªãã®ã¯ãªãã§ããïŒ ã©ã®ã€ã³ããã¯ã¹ãiã®åŸãã«é ããŠããããæ確ã§ã¯ãªãããã§ãã ã³ãŒãã«é å[2]ã¿ã€ããããå ŽåãJITã¯ãããé å$ 2ã®ããŒã«ã«å€æ°ã«å€æã§ããŸãã ãããŠãé å[i]ãäœã«å€ããŸããïŒ ããªãã¯æ£ç¢ºã«äœã§ããããç¥ãå¿ èŠããããŸãã ããã€ãã®ç¹å¥ãªå Žåãçãé åã®å ŽåãJITã¯ããããæšæž¬ãã§ããŸããäžè¬çãªå Žå-ãããã
äŸ5.4 åææ¡ä»¶
guava ,
checkArguments(expression, errorMessageTemplate, args...)
, expression, expression == false. â vararg, , . ,
checkArguments
expressions == false, .
, expression . : vararg , expression false?
â 10 -7 :
.
10 -9 , , , , - .
, - :
⊠.
, â checkArguments, vararg â , , , expression false. checkArguments, expression false, - , - . , , , false , vararg , .
ãŸãšã
- , ( );
- , (.. , , : - , );
- JVM .
: ( JVM). , , . . - , .
â :
- JVM;
- ( );
- ( , 1; 2-3 â , , , );
- ;
- null â ;
- â , , , ;
- .
â JPoint 2017 (7-8 ) JBreak 2017 (4 ) . , â , .