-XXïŒ+ DoEscapeAnalysis
ãããããæãèå³æ·±ããªãã·ã§ã³ã§ããDoEscapeAnalysisããå§ããŸãããã å€ãã®äººãç¥ã£ãŠããããã«ãããªããã£ããšãªããžã§ã¯ãåç §ã¯ããŒãäžã«äœæãããã®ã§ã¯ãªããã¹ããªãŒã ã¹ã¿ãã¯äžã«å²ãåœãŠãããŸãïŒHotspotã®ããã©ã«ãã§ã¯256KBïŒã Javaèšèªã§ã¯ãã¹ã¿ãã¯äžã«ãªããžã§ã¯ããçŽæ¥äœæã§ããªãããšã¯æããã§ãã ãã ããJVM 1.6ã¯ã14åç®ã®ã¢ããããŒã以éãããèªäœã§ãããå®è¡ã§ããŸãã
ã¢ã«ãŽãªãºã èªäœã®ä»çµã¿ã«ã€ããŠã¯ã ãã¡ãïŒPDFïŒãã芧ãã ãã ã èŠããã«ïŒ
- ãªããžã§ã¯ãã®ã¹ã³ãŒããäœæãããã¡ãœãããè¶ ããªãå Žåããã®ãããªãªããžã§ã¯ãã¯ããŒãã®ä»£ããã«ã¹ã¿ãã¯ãã¬ãŒã äžã«äœæã§ããŸãïŒå®éããªããžã§ã¯ãèªäœã§ã¯ãªãããªããžã§ã¯ãã眮ãæãããããã£ãŒã«ãå šäœïŒ;
- ãªããžã§ã¯ããã¹ããªãŒã ã®ã¹ã³ãŒããé¢ããªãå Žåãä»ã®ã¹ããªãŒã ã¯ãã®ãããªãªããžã§ã¯ãã«ã¢ã¯ã»ã¹ã§ããªãããããªããžã§ã¯ãã®ãã¹ãŠã®åææäœãåé€ã§ããŸãã
ãã®ã¢ã«ãŽãªãºã ãå®è£ ããããã«ãããããæ¥ç¶ã°ã©ããæ§ç¯ããã䜿çšãããŸããããã«åŸã£ãŠãåæã®æ®µéïŒããã€ãã®åæã¢ã«ãŽãªãºã ïŒã§ãä»ã®ãããŒãã¡ãœãããšã®äº€å·®ç¹ãèŠã€ããããã®éè·¯ãäœãããŸãã
ãããã£ãŠããªããžã§ã¯ãã®ãªã³ã¯ã°ã©ããæž¡ããšã次ã®ããããã®ç¶æ ãå¯èœã«ãªããŸãã
- GlobalEscape-ãªããžã§ã¯ãã¯ãä»ã®ã¹ããªãŒã ããã³ä»ã®ã¡ãœããïŒéçãã£ãŒã«ããªã©ïŒããã¢ã¯ã»ã¹ã§ããŸãã
- ArgEscape-ãªããžã§ã¯ãã¯åŒæ°ãšããŠæž¡ãããããŸãã¯åŒæ°ãªããžã§ã¯ããããªããžã§ã¯ããžã®ãªã³ã¯ããããŸãããããèªäœã¯äœæãããã¹ããªãŒã ã®ç¯å²ããåºãŸããã
- NoEscape-ãªããžã§ã¯ãã¯ã¡ãœããã®ã¹ã³ãŒããé¢ããããã®äœæã¯ã¹ã¿ãã¯ã«ããã·ã¥ã§ããŸãã
åæ段éã®åŸãJVMèªäœã¯ãã§ã«å¯èœãªæé©åãè¡ã£ãŠããŸããNoEscapeãªããžã§ã¯ãã®å Žåãã¹ã¿ãã¯äžã«äœæã§ããŸãã ãªããžã§ã¯ããNoEscapeãŸãã¯ArgEscapeã®å Žåããã®ãªããžã§ã¯ãã«å¯Ÿããåææäœã¯åé€ã§ããŸãã
ãªããžã§ã¯ãèªäœã§ã¯ãªãããã®ãã£ãŒã«ããã¹ã¿ãã¯äžã«äœæãããããšãæ確ã«ããå¿ èŠããããŸãã JVMã¯ãªããžã§ã¯ãå šäœããã®ãã£ãŒã«ãã®å šäœã«çœ®ãæããŸãïŒæ確ã«ããããã«Walrusã«æè¬ããŸãïŒã
ãã®çš®ã®åæã®ãããã§ãããã°ã©ã ã®åã ã®éšåã®ããã©ãŒãã³ã¹ãå€§å¹ ã«åäžããããšã¯æããã§ãã åæãã¹ãã§ã¯ã次ã®ããã«ãªããŸãã
for (int i = 0; i < 1000*1000*1000; i++) { Foo foo = new Foo(); }
å®è¡é床ã¯8ã15åã«ãªããŸãã ããããæè¿æžãããïŒ ãããšãã㧠ïŒç·Žç¿ããã®äžèŠæãããªã±ãŒã¹ã§ã¯ãEscapeAnalysã¯æ©èœããŸããã ããã¯ã¹ã¿ãã¯ã®ãµã€ãºã«ãããã®ãšæãããŸãã
ã¡ãªã¿ã«ãEscapeAnalysisã¯ãStringBuilderãšStringBufferã«ã€ããŠããç¥ãããŠããçŽäºã®äžéšãæ ã£ãŠããŸãã ã€ãŸããã¡ãœããã§StringBuilderã§ã¯ãªãStringBufferãçªç¶äœ¿çšããå ŽåãEscapeAnalysisïŒããªã¬ãŒãããå ŽåïŒã¯StringBufferã®ããã¯ã解é€ãããã®åŸãStringBufferã¯å®å šã«StringBuilderã«å€ãããŸãã
-XXïŒ+ AggressiveOpts
AggressiveOptsãªãã·ã§ã³ã¯ã¹ãŒããŒãªãã·ã§ã³ã§ãã ã¢ããªã±ãŒã·ã§ã³ã®ããã©ãŒãã³ã¹ãåçã«åäžããããšããæå³ã§ã¯ãªããä»ã®ãªãã·ã§ã³ã®å€ã®ã¿ãå€æŽãããšããæå³ã§ã¯ïŒå®éãããã¯å®å šã«çå®ã§ã¯ãããŸãã-JDKãœãŒã¹ã³ãŒãã«ã¯AggressiveOptsãJVMã®åäœãå€æŽããå ŽæãããªããããŸãïŒ ãåè¿°ã®ãªãã·ã§ã³ã«å ããŠã ããã®äŸã®1ã€ã§ã ïŒã 2ã€ã®ã³ãã³ãã䜿çšããŠãå€æŽããããã©ã°ã確èªããŸãã
java -server -XX:-AggressiveOpts -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal > no_aggr java -server -XX:+AggressiveOpts -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal > aggr
å®è¡åŸãã³ãã³ãã®å®è¡çµæã®éãã¯æ¬¡ã®ããã«ãªããŸããã
-AggressiveOpts
| + AggressiveOpts
| |
---|---|---|
AutoBoxCacheMax
| 128
| 20000
|
BiasedLockingStartupDelay
| 4000
| 500
|
EliminateAutoBox
| åœ
| æ¬åœ
|
OptimizeFill
| åœ
| æ¬åœ
|
OptimizeStringConcat
| åœ
| æ¬åœ
|
ã€ãŸãããã®ãªãã·ã§ã³ãè¡ãããšã¯ãä»®æ³ãã·ã³ã®5ã€ã®ããŒã¿ãã©ã¡ãŒã¿ãŒãå€æŽããããšã ãã§ãã ããã«ãããŒãžã§ã³1.6ã¢ããããŒã35ããã³1.7ã¢ããããŒã7ã§ã¯ãéãã¯èªããããŸããã§ããã ãã®ãªãã·ã§ã³ã¯ããã©ã«ãã§ç¡å¹ã«ãªã£ãŠãããã¯ã©ã€ã¢ã³ãã¢ãŒãã§ã¯äœãå€æŽãããŸããã
ç©æ¥µçãªæé©åã«ããjavaã®æå³ãæ€èšããŠãã ããã
-XXïŒAutoBoxCacheMax =ãµã€ãº
ä»®æ³ãã·ã³ã®èµ·åæã«ãæŽæ°åã®ãã£ãã·ã¥å€ã®ç¯å²ãæ¡åŒµã§ããŸãã ãã®ãªãã·ã§ã³ã«ã€ããŠã¯ãã§ã«èª¬æããŸããïŒ2çªç®ã®æ®µèœïŒ ã
-XXïŒBiasedLockingStartupDelay = delay
ãåãã®ãšãããJavaã®åæãããã¯ã¯ã次ã®3çš®é¡ã®ããã¯ã®ããããã§è¡šãããšãã§ããŸãã
- åã£ã
- èã
- 倪ã
ããã«ã€ããŠã¯ã ãã¡ã ã ãã¡ã ã ãã¡ããã芧ãã ãã ã
ã»ãšãã©ã®ãªããžã§ã¯ãïŒåæãããïŒã¯1ã€ã®ã¹ã¬ããã§æ倧1ã€ãããã¯ãããããããã®ãããªãªããžã§ã¯ãã¯ãã®ã¹ã¬ããã«ãã€ã¢ã¹ããããããšãã§ããã¹ããªãŒã å ã®ãã®ãªããžã§ã¯ãã®åææäœã®äŸ¡æ Œã¯å€§å¹ ã«åæžãããŸãã å¥ã®ã¹ã¬ããããã€ã¢ã¹ããããªããžã§ã¯ãã«ã¢ã¯ã»ã¹ããããšãããšããã®ãªããžã§ã¯ãã®ããã¯ã¯ã·ã³ããã¯ã«åãæ¿ãããŸãã
åãæ¿ãèªäœã¯æ¯èŒçé«äŸ¡ã§ãããããJVMã®éå§æã«é 延ããããŸããããã©ã«ãã§ã¯ããã¹ãŠã®ããã¯ãã·ã³ãšããŠäœæããã競åãæ€åºããããåãã¹ã¬ããã§ã³ãŒãã䜿çšãããå Žåãé 延ãçµäºãããšãã®ãããªããã¯ããã€ã¢ã¹ãããŸãã ã€ãŸããJVMã¯ããã¯ã®äœ¿çšã·ããªãªãæåããå®çŸ©ããããšããããã䜿çšããã¹ã€ããã®æ°ãå°ãªããªããŸãã ãããã£ãŠãBiasedLockingStartupDelayããŒãã«èšå®ãããšãåæã³ãŒãã®äž»èŠéšåãåãã¹ããªãŒã ã§ã®ã¿äœ¿çšããããšäºæ³ãããŸãã
-XXïŒ+ OptimizeStringConcat
ãŸããéåžžã«èå³æ·±ããªãã·ã§ã³ã§ãã 䌌ãŠãããã¿ãŒã³ãèªèãã
StringBuilder().append(...).toString() // StringBuilder().append(new StringBuiler().append(...).toString()).toString()
ãŸããæ°ããé£çµæäœã®ããã«ã¡ã¢ãªã絶ããå²ãåœãŠã代ããã«ãåé£çµãªããžã§ã¯ãã®æåã®ç·æ°ãèšç®ããŠãã¡ã¢ãªã1åã ãå²ãåœãŠãããšããŸãã
ã€ãŸãã20æåã®æååã«å¯ŸããŠappendïŒïŒæäœã20ååŒã³åºããšã charé åã®äœæã¯ã400æåã®é·ãã§1åçºçããŸãã
XXïŒ+ OptimizeFill
é åã®å å¡«/ã³ããŒãµã€ã¯ã«ã¯ãäœæ¥ãé«éåããããã®çŽæ¥çãªæ©æ¢°åœä»€ã«çœ®ãæããããŸãã
ããšãã°ã次ã®ãããã¯ïŒArrays.fillïŒïŒããååŸïŒïŒ
for (int i=fromIndex; i<toIndex; i++) a[i] = val;
memsetã«äŒŒã察å¿ããããã»ããµåœä»€ã§å®å šã«çœ®ãæããããŸãããmemcpyã¯äžäœã¬ãã«ã®ãã®ã®ã¿ã§ãã
XXïŒ+ EliminateAutoBox
ååã«åºã¥ããŠããã©ã°ã¯äœããã®æ¹æ³ã§ãªãŒããã¯ã·ã³ã°æäœã®æ°ãæžããå¿ èŠããããŸãã æ®å¿µãªãããç§ã¯ãŸã ãã®ãã©ã°ãäœãããŠããã®ãç解ã§ããŸããã§ããã ãããæŽæ°ã·ã§ã«ã«ã®ã¿é©çšãããããšãæ確ã«ããããšãã§ããå¯äžã®ãã®ã
-XXïŒ+ UseCompressedStrings
ç§ã®æèŠã§ã¯ãããªãè°è«ã®äœå°ã®ãããªãã·ã§ã³ã§ã...é ãã®90幎代ã«ãJavaéçºè ãæåããšã«2ãã€ããç¯çŽããªãã£ãå Žåãä»æ¥ãã®ãããªæé©åã¯ããªãã°ãããŠèŠããŸãã 誰ããæšæž¬ããªãã£ãå Žåããã®ãªãã·ã§ã³ã¯æåé åãå¯èœãªéãæååïŒASCIIïŒã®ãã€ãé åã«çœ®ãæããŸãã æ¬è³ªçã«ïŒ
char[] -> byte[]
ãããã£ãŠãã¡ã¢ãªãå€§å¹ ã«ç¯çŽã§ããŸãã ããããåãå€åããŠãããšããäºå®ãèæ ®ãããšãç¹å®ã®æäœäžã®åå¶åŸ¡ã®ãªãŒããŒããããçŸããŸãã ã€ãŸãããã®ãªãã·ã§ã³ã䜿çšãããšãJVMã®ããã©ãŒãã³ã¹ãäœäžããå¯èœæ§ããããŸãã å®éããªãã·ã§ã³ãããã©ã«ãã§ç¡å¹ã«ãªã£ãŠããã®ã¯ãã®ããã§ãã
-XXïŒ+ UseStringCache
ååããå€æãããšãããªãäžæè°ãªãªãã·ã§ã³ã§ãããäœããã®æ¹æ³ã§è¡ããã£ãã·ã¥ããå¿ èŠããããŸãã ã©ããã£ãŠïŒ æ確ã§ã¯ãããŸããã æ å ±ã¯ãããŸããã ã¯ãã ã³ãŒãã¯äœãããŠããªãããã§ãã 誰ããæ確ã«ã§ãããå¬ããã§ãã
-XXïŒ+ UseCompressedOops
ãŸããããã€ãã®äºå®ïŒ
- 32ãããJVMã®ãªããžã§ã¯ããžã®ãã€ã³ã¿ãŒã®ãµã€ãºã¯32ãããã§ãã 64ããã-64ãããã ãããã£ãŠãæåã®ã±ãŒã¹ã§ã¯ããµã€ãºã2 ^ 32ãã€ãïŒ4 GBïŒã®ã¢ãã¬ã¹ã¹ããŒã¹ã䜿çšã§ãã2çªç®ã®ã±ãŒã¹ã§ã¯ã2 ^ 64ãã€ãã䜿çšã§ããŸãã
- Javaã®ãªããžã§ã¯ãã®ãµã€ãºã¯ãä»®æ³ãã·ã³ã®ãµã€ãºã«é¢ä¿ãªãã8ãã€ãã®åæ°ã§ãïŒããã¯ãã¹ãŠã®ä»®æ³ãã·ã³ã«åœãŠã¯ãŸãããã§ã¯ãããŸãããããããã¹ãããã«é¢ãããã®ã§ãïŒã ã€ãŸãã32ããããã€ã³ã¿ãŒã䜿çšããå ŽåãæåŸã®3ãããã¯åžžã«ãŒãã«ãªããŸããå®éãä»®æ³ãã·ã³ã¯å®éã«ã¯29ããããã䜿çšããŸããã
ãã®ãªãã·ã§ã³ã«ããã64ãããJVMã®ãã€ã³ã¿ãŒã®ãµã€ãºã32ãããã«æžããããšãã§ããŸããããã®å ŽåãããŒããµã€ãºã¯4 GBã«å¶éãããŠãããããççž®ãã€ã³ã¿ãŒã«å ããŠã8ãã€ãã®å€é床ã®ããããã£ã䜿çšãããŸãã ãã®çµæããµã€ãº2 ^ 35ãã€ãïŒ32 GBïŒã®ã¢ãã¬ã¹ç©ºéã32ãããã®ãã€ã³ã¿ãŒã§äœ¿çšããæ©äŒãåŸãããŸãã
å®éãä»®æ³ãã·ã³å ã«ã¯ãã¡ã¢ãªå ã®ç¹å®ã®ãã€ãã§ã¯ãªãããªããžã§ã¯ããžã®ãã€ã³ã¿ãŒããããŸãã ãã®ãããªä»®å®ïŒå€é床ã«ã€ããŠïŒã«ããããã€ã³ã¿ãŒã®å€æã«è¿œå ã®ã³ã¹ããçºçããããšã¯æããã§ãã ããããæ¬è³ªçã«ããã¯1ã€ã®ã·ãããšåèšã®æäœã§ãã
ãã€ã³ã¿ãŒèªäœã®ãµã€ãºãå°ããããããšã«å ããŠããã®ãªãã·ã§ã³ã¯ãªããžã§ã¯ãã®ããããŒãšäœæããããªããžã§ã¯ãå ã®ãã¹ãŠã®çš®é¡ã®ã¢ã©ã€ã¡ã³ããšã·ãããåæžããŸããããã«ãããã¢ããªã±ãŒã·ã§ã³ã¢ãã«ã«å¿ããŠå¹³åã¡ã¢ãªæ¶è²»ã20ã60ïŒ åæžã§ããŸãã
ã€ãŸããæ¬ ç¹ã¯æ¬¡ã®ãšããã§ãã
- æ倧ããŒããµã€ãºã¯32 GBïŒ16ãã€ãã®ãªããžã§ã¯ãå€é床ãæã€JRockitã®å Žåã¯64 GBïŒã«å¶éãããŠããŸãã
- äœåã«è¡šç€ºãããŸãã JVMãªã³ã¯ããã€ãã£ãã«ããŸãã¯ãã®éã«å€æããã³ã¹ãã
ãã®ãªãã·ã§ã³ã«ã¯ã»ãšãã©ã®ã¢ããªã±ãŒã·ã§ã³ã§ããã€ãã®å©ç¹ããããããJDK 6 update 23以éã§ã¯ãJDK 7ãšåæ§ã«ããã©ã«ãã§æå¹ã«ãªã£ãŠããŸãã詳现ã¯ãã¡ããšãã¡ã ã
-XXïŒ+ EliminateLocks
ããã¯ãçµã¿åãããŠäžèŠãªããã¯ãæé€ãããªãã·ã§ã³ã ããšãã°ã次ã®ãããã¯ïŒ
synchronized (object) { //doSomething1 } synchronized (object) { //doSomething2 }
synchronized (object) { //doSomething3 } //doSomething4 synchronized (object) { //doSomething5 }
ããã«å¿ããŠå€æãããŸã
synchronized (object) { //doSomething1 //doSomething2 }
synchronized (object) { //doSomething3 //doSomething4 //doSomething5 }
ããã«ãããã¢ãã¿ãŒã®ãã£ããã£ãŒè©Šè¡åæ°ãåæžãããŸãã
ãããã«
1ã€ã®èšäºã«700åãŸã§ã®ãã©ã°ããã¹ãŠå ¥ããã®ã¯éåžžã«é£ãããããããªãå€ãã®èå³æ·±ããªãã·ã§ã³ãè¹å€ã«æ®ã£ãŠããŸãã ã³ã¬ã¯ã¿ãŒã調æŽããããã®ãªãã·ã§ã³ã«ã¯ç¹ã«è§Šããªãã£ãã®ã§ãããã¯ããªãåºç¯ã§è€éãªãããã¯ã§ãããããã€ãã®æçš¿ã«å€ããŸãã ãã®èšäºãã圹ã«ç«ãŠã°å¹žãã§ãã