Full GC ã«ãã Stop the World ã§ãµã¼ããåæ¢ç¶æ
ã«â¦ããããªã¨ãã«èª¿æ»ã®å©ãã«ãªãã®ã GC ã®ãã°ãPermanent é åã溢ãã¦ããã®ããJava Heap ã溢ãã¦ããã®ããHeap ã溢ãã¦ããã®ãªãä½ã®ãªãã¸ã§ã¯ãã溢ãã¦ããã®ããã¡ã¢ãªãªã¼ã¯ãçºçãã¦ããã®ãããããåãããªãã¨ä½æ°ã«å¯¾å¦ã®ãããããªãã
ãã ããã® GC ã®ãã°ããããªãã®è¨å®ããã¦ãããªãã¨è§£æã«èããªããå½¹ã«ç«ããªããå½¹ã«ç«ããªããã°åºåã¯ãã£ã¹ã¯å®¹éãå§è¿«ããã´ãã«ãªããããããæãã®ãã°ãç®ã«ãã¦ããªãã¨ããªããããããªã¼ããªãã¨ãããã°ãªã¼ã¨æ¤è¨ãã¦ãããOracle ã®ãã¼ã¸ããããã£ã½ããªãã·ã§ã³ã調ã¹ã¦ã¿ã¦ãã
å½ç¶ãªãããOracle ã®ãã¼ã¸ãã¨æ¸ãã¦ããããã«ãOracle ã® JVM ã対象ã§ãã£ã¦ãä»ã® JVM ã使ã£ã¦ãå ´åã¯ä»¥ä¸ã®å 容ã¯å½¹ã«ç«ããªãããã¨ãä»ããæ¤è¨¼ã®æ®µéã§ãã£ã¦ãå®éã«ã¯ã¾ã 試ãã¦ãªãã
GC ãã°åºå
+XX:PrintGCDetails
ããä»ãã¦ãªãã·ã¹ãã ã¯ã¤ãããGC ã®ã¨ãã®è©³ç´°æ
å ±ãåºåãããªãã·ã§ã³ã詳細ã¨ãã£ãã£ã¦ãã§ããã§ãã£ã¨åºãã ãã ããããã¨ç¡ãã¨ã§ã¯å¤§éãã«ãªãã
åºåã¯ä»¥ä¸ã®ãããªæãã§ãNew é åã Tenured (Old)é åã GC åå¾ã§ã©ãå¤ãã£ãã®ããGC ã®æè¦æéã¯ã©ãã ããã¨ããæ
å ±ãåå¾ã§ãããä½è«ã ããã©ããã®ãããã®ã¡ã¢ãªä½¿ç¨éã®æ¨ç§»ãã°ã©ãåããã¨ãããç¥ãããé¸åã®ã°ã©ããæãã¦ãããããã¨æãã
ãããªæãã®ãã°ãã§ã¦ããã
1.831: [GC 1.831: [DefNew: 4096K->4096K(4544K), 0.0000118 secs]1.831: [Tenured: 56595K->60544K(60544K), 0.2608705 secs] 60691K->60689K(65088K), 0.2610212 secs] 2.097: [Full GC 2.097: [Tenured: 60544K->60544K(60544K), 0.2638188 secs] 62056K->61982K(65088K), [Perm : 262K->262K(8192K)], 0.2639318 secs] 2.361: [Full GC 2.361: [Tenured: 60544K->60544K(60544K), 0.2532709 secs] 61982K->61982K(65088K), [Perm : 262K->262K(8192K)], 0.2533446 secs]GCをみる - techlog
ã¿ã¤ã ã¹ã¿ã³ãã®ä»å
+XX:PrintGCTimeStamps
æåã«ç¥ã£ãã¨ãã¯ä¿¡ããããªãã£ãã®ã ããã©ãã©ããããã©ã«ãã® GC ãã°ã¯ã¿ã¤ã ã¹ã¿ã³ããåºåãã¦ãããªãã£ã½ããåºåãããããã«ã¯ä¸è¨ãªãã·ã§ã³ãæå¹åãããå¿ è¦ãããã®ã ããã©ãããã«ãã£ã¦åºåãããã®ã¯çµ¶å¯¾æå»ã§ã¯ãªããJVM èµ·åæããã®ç¸å¯¾æéã«ãªãããããã
ãã JVM ã Java 6 以éã§åãã¦ãããªãã絶対æå»ãåºåã§ãã
-XX:+PrintGCDateStamps
ã使ããã
ãªãã¸ã§ã¯ãã®å¹´é½¢æ å ±
-XX:PrintTenuringDistribution
å¹´é½¢ãªãã¦æ¸ãæ¹ããããã¨ç解ãé£è§£ã«ãªãã®ã ããã©ãããããã¯åãªãã¸ã§ã¯ãã Scavenge GC ãä½åçµã¦ãããã®çµ±è¨æ
å ±ãªãã ã¨ç解ãã¦ããã
ç解ã®çç±ã¯ Sun ã®ä»¥ä¸ã®è¨è¿°ããã
In this example we see that the application seems to be based on a few short-lived objects because after the first copy only 1808712 bytes survive to the following scavange; after 10 hops, 1061472 bytes are finally promoted to the old, so we need 34598776 bytes of free space in survivor to keep aging all these objects
Desired survivor size 107374180 bytes, new threshold 10 (max 10) - age 1: 17601288 bytes, 17601288 total - age 2: 1808712 bytes, 19410000 total - age 3: 1770784 bytes, 21180784 total - age 4: 2042888 bytes, 23223672 total - age 5: 2335648 bytes, 25559320 total - age 6: 2422632 bytes, 27981952 total - age 7: 2487376 bytes, 30469328 total - age 8: 1869224 bytes, 32338552 total - age 9: 1198752 bytes, 33537304 total - age 10: 1061472 bytes, 34598776 totalhttp://webcache.googleusercontent.com/search?q=cache:cuwH5i1H8uwJ:bugs.sun.com/bugdatabase/view_bug.do%3Fbug_id%3D6453675+&cd=10&hl=ja&ct=clnk&gl=jp&client=firefox-beta
ãã¼ããã³ã
-XX:HeapDumpPath=./java_pid<pid>.hprof -XX:-HeapDumpOnOutOfMemoryError
OutOfMemoryError (OOME) çºçã¿ã¤ãã³ã°ã§ãã¼ããã³ããåºåã§ããããã«ãªããåºåå
ã -XX:HeapDumpPath ã§æå®ããã
ãã¼ããã³ãåºåä¸ã¯ã試ãã¦ãªãã JVM ã®ã¹ã¬ãããå®å
¨åæ¢ãããããããã¾ãããã³ããã¡ã¤ã«ã®å¤§ããã¯(å½ç¶ãªãã) Java ãã¼ãã¨ãã¦äºç´ãã¦ããã¡ã¢ãªã®å¤§ããã¨å¼·ãç¸é¢é¢ä¿ãããã®ã§ããã£ã¹ã¯å®¹éã«ã¯æ³¨æãå¿
è¦ãã¾ãå½ç¶ãªãã HeapDumpPath ã§æå®ãããã¹ã«å¯¾ããæ¸ãè¾¼ã¿æ¨©éãå¿
è¦ãªç¹ã«æ³¨æã
JVM ãçãç¶ãã¦ããå ´åãOOEM ãçºçããæ¯ã«ãã¼ããã³ããåºåããã¦ãã¾ãã¨ãã£ã¨ããéã« DISK FULL ã«é¥ãã®ã§ã¯ãªããã¨éªæ¨ãã¦ããã®ã ããã©ã
A memory snapshot is captured automatically on first OutOfMemoryError, if the profiled application runs on Sun Java 6 or newer, or on JRockit R28.0.0 or newer.
(解æ対象ã®ã¢ããªã±ã¼ã·ã§ã³ã Sun ã® Java 6 以éãããã㯠JRockit ã® R28.0.0 以éã§åãã¦ããå ´åãOutOfMemoryError ã®ååçºçã¿ã¤ãã³ã°ã§ã¡ã¢ãªã®ã¹ãããã·ã§ãããèªååå¾ããã)
YourKit Java Profiler Help - Out of memory error (OutOfMemoryError and -XX:+HeapDumpOnOutOfMemoryError)
ã¨ãããã¨ã§ãååçºçæã ãã®ããã
対å¿ãã¦ããã®ã¯ Java 1.4.2 u12 以éãJava 5.0 u7 以éãJava 6.0 以éã«ãªããããæå¤ã§æå®ããã¨ãJVM ãèªèããªãããããããã JVM èªä½ãèµ·åããªãã
OOEM ããªã¬ã§ã®ã³ãã³ãå®è¡
-XX:OnOutOfMemoryError="<cmd args>;<cmd args>"
OOEM çºçæç¹ã§åºæ¬çã«ã¯ JVM ã®ç¶æ ã¯ç°å¸¸ãªã®ã§ããã¯ããã以éã®å復å¦çã JVM èªèº«ã«å§ãããã¨ã¯ã§ããªãã
JVMã§OutOfMemoryErrorã¨ã©ã¼ãçºçããã¨ãæªè§£æ±ºã®ã¾ã¾ã¨ã©ã¼ãæ®ããããã¨ããããã¯ã©ã¹ã¿ã«æªãå½±é¿ãä¸ããå¯è½æ§ãããã¾ããOutOfMemoryErrorãçºçããå ´åã®å¦çã¨ãã¦ãJVMããªã«ããªããã®ã§ã¯ãªããJVMãçµäºããããã«æ§æãããã¨ããè¦ããã¾ãã
http://otndnld.oracle.co.jp/document/products/coherence/34/doc_cd/coh.340/B52975-01/docerrata.htm
OutOfMemoryErrorãçºçãã¦ãã¹ã¬ãããç°ç©ºéã«è¬ãã ãã§Java VMã¯ãã®ã¾ã¾åãç¶ããå ´åããããã©ãå½ç¶ãªããç¶æ ã«ä¸è²«æ§ã®ãªãç¶æ ã§åãã¦ããå¯è½æ§ãããããã§åºæ¬çã«ã¯ã¨ã£ã¨ã¨æ»ãã§æ¬²ããããã§ãããä¸è¬çã«è¨ãã¨ããã®ãä¸å®ãç¶æ ã§ãããOOMEã¯Errorã§ãã£ã¦ä¾å¤ã§ã¯ãªããè´å½çãªJava VMã¨ã©ã¼ã§ãããOOMEçºçå¾ã«ããã»ã¹åèµ·åããªãã§ãã®ã¾ã¾ã©ããããããã¨ããã®ã¯çµ¶å¯¾ã«é¿ããæ¹ãè¯ãã
OutOfMemoryErrorが発生したときにきちんとJavaプロセスを殺す - nekop's blog
JVM ã®å¤ã®ä¸çã«ãã«ããæ±ããããã«ããã®ãªãã·ã§ã³ã使ç¨ããã
å¼ç¨å
ã®ã¨ã³ããªã§ã¯ã以ä¸ã®ããã«å¼·å¶ç㪠JVM ã® kill ãå®æ½ãã¦ããã
-XX:OnOutOfMemoryError="kill -9 %p"
%p 㯠JVM ã® pid ã«ç½®æãããããã ãããã®æ£å¼ãªä»æ§ã®æç®ã¯ã¾ã è¦ã¤ãããã¦ããªãã
対å¿ãã¦ããã®ã¯ Java 1.4.2 u12 以é
ãã¼ãå ã®ã¯ã©ã¹æ¯ã®çµ±è¨æ å ±ãåå¾ãã
-XX:-PrintClassHistogram
ãã®ãªãã·ã§ã³ãæå®ããã ãã§çµ±è¨æ å ±ãåå¾ãããããã§ã¯ãªãã"ãã®ãªãã·ã§ã³ãæå®ãã JVM" ã«å¯¾ã㦠QUIT ã·ã°ãã«ãéä¿¡ããå¿ è¦ãããã
PrintClassHistogramãªãã·ã§ã³ã¯ããã¼ãå ã®ã¯ã©ã¹çµ±è¨æ å ±ãåºåããããã®ãªãã·ã§ã³ã ãåºåæç¹ã§ã®åã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã®åæ°ããã³å ¨ã¤ã³ã¹ã¿ã³ã¹ã®åè¨ãµã¤ãºããGCãã°ã¨ã¨ãã«åºåããã
肥え続けるTomcatと胃を痛めるトラブルハッカー:現場から学ぶWebアプリ開発のトラブルハック(8)(2/3 ページ) - @IT
(ä¸ç¥)
ãã®ãªãã·ã§ã³ãä»å ãã¦Javaãèµ·åå¾ããã®ããã»ã¹ã«å¯¾ãã¦ä¸å®ééãã¨ã«SIGQUITã·ã°ãã«ãéä¿¡ããã
åºåä¾ã¯ä»¥ä¸ã®ããã«ãªãã
num #instances #bytes class name -------------------------------------- 1: 244594 35380344 [C 2: 982063 23569512 java.lang.String 3: 15788 17285632 [B 4: 59009 9135936 <methodKlass> 5: 292468 7019232 java.util.Hashtable$Entry 6: 96069 5493752 [Ljava.util.Hashtable$Entry;肥え続けるTomcatと胃を痛めるトラブルハッカー:現場から学ぶWebアプリ開発のトラブルハック(8)(2/3 ページ) - @IT
å½ç¶ãªãã 1 度ã®åå¾ã§ã¯ããããã®ã¯ã©ã¹ã¯ããã¶ãã¡ã¢ãªãé£ã£ã¦ããããã¨ãããã¨ããåãããªãã
å¥ã«ã¡ã¢ãªãåã£ã¦ããããã¨ãã£ã¦è«¸æªã®æ ¹æºã¨ã¯éããªãããã¨ãã° Scavenge GC ã§éæ¾ãããã®ã§ããã°ãå°ã
ã®ã¡ã¢ãªå®¹éã使ã£ã¦ããã¨ãã¦ãå¤å°ç®ãã¤ã¶ã£ã¦ãè¯ãã¨æããææªã®ã±ã¼ã¹ã¯ã¡ã¢ãªã GC ã«ãã£ã¦éæ¾ãããã«çã¾ãç¶ããããã«ã¯å¢ãç¶ãããã¨ã§ãã£ã¦ãããã確ãããããã«ã¯ç¶ç¶è¦³å¯ãããªãã
çµæã¨ãã¦ãSIGQUIT ãå®æçã«éãã¹ã¯ãªããã cron ãããã«ä»è¾¼ãéç¨ãå¿
è¦ã«ãªãã
ãã ããSIGQUIT ãéã£ãæç¹ã§ JVM å´ã§ FUll GC ãèµ°ãã¨ããæ
å ±ãããã¤ãããããã®ãããFull GC ãèµ°ããã¨ã«ããããã©ã¼ãã³ã¹å£åã®ç¨åº¦ã¯ææ¡ãã¦ãããã¨ãå¿
è¦ã
javaã®èµ·åãªãã·ã§ã³ã§-XX:+PrintClassHistogram?ã追å ãããã¨ã§ãSUGQUITã·ã°ãã«ãåä¿¡ããéã«ãVMã§FullGCãå¼·å¶çã«å®è¡ãã
http://www.hiihah.info/index.php?実行中のJAVAMVの中身を見てみる
ã¾ããJava 5 ã§ã¯ GC ã¢ã«ã´ãªãºã ã«ãã£ã¦ãã¹ãã°ã©ã åºåãã§ããªãã¨ããåé¡ãå ±åããã¦ããã®ã§ããã®ãããã¯æ³¨æãå¿ è¦ã
https://forums.oracle.com/forums/thread.jspa?threadID=1540728
- PrintClassHistogram did not (in 1.5.0 and earlier) work with the parallel scavenging (PS) collector. In 1.5.0 on "server class machines" you get that collector by default. So if you are running on what might be considered a "server-class machine", you will get the PS collector and +PrintClassHistogram will be ignored. This is fixed in Java SE 6 (Mustang) in bug 5023697.
ãã°ãã¡ã¤ã«å
-Xloggc:<filename>
ã¾ãããã§ããã¨ããå 容ããããæå®ãã¦ãªãã£ãããæ¨æºåºåã«åºåããã£ã½ãããã®ãããTomcat ã 㨠catalina.out ãããã«ã§ãã
ãã°ãã¼ãã¼ã·ã§ã³
-XX:-UseGCLogFileRotation -XX:NumberOfGClogFiles=<n> -XX:GCLogFileSize=8K
御親åã«ãã°ãã¼ãã¼ã·ã§ã³ã®æ©è½ãå
¥ã£ã¦ãããããããã®ãªãã·ã§ã³ãè¦ã¦åããããã«ãã¼ãã¼ã·ã§ã³ã®ããªã¬ã¯æéã§ã¯ãªããã°ãµã¤ãºã®æ¨¡æ§ã
ãã°ãµã¤ãºã§ã®ãã¼ãã¼ã·ã§ã³ã¯å人çã«ã¯å¥½ãã§ã¯ãªãã