JVM調優命令-jhat
阿新 • • 發佈:2017-09-25
cin nta toolbar 進行 訪問 osi form 關閉 true
-stack false|true 關閉對象分配調用棧跟蹤(tracking object allocation call stack)。 如果分配位置信息在堆轉儲中不可用. 則必須將此標誌設置為 false. 默認值為 true.
-refs false|true 關閉對象引用跟蹤(tracking of references to objects)。 默認值為 true. 默認情況下, 返回的指針是指向其他特定對象的對象,如反向鏈接或輸入引用(referrers or incoming references), 會統計/計算堆中的所有對象。
-port port-number 設置 jhat HTTP server 的端口號. 默認值 7000。-exclude exclude-file 指定對象查詢時需要排除的數據成員列表文件(a file that lists data members that should be excluded from the reachable objects query)。 例如, 如果文件列列出了 java.lang.String.value , 那麽當從某個特定對象 Object o 計算可達的對象列表時, 引用路徑涉及 java.lang.String.value 的都會被排除。
-baseline exclude-file 指定一個基準堆轉儲(baseline heap dump)。 在兩個 heap dumps 中有相同 object ID 的對象會被標記為不是新的(marked as not being new). 其他對象被標記為新的(new). 在比較兩個不同的堆轉儲時很有用。
-debug int 設置 debug 級別. 0 表示不輸出調試信息。 值越大則表示輸出更詳細的 debug 信息。
-version 啟動後只顯示版本信息就退出。
示例
觀察是否大量應該被回收的對象在一直被引用或者是否有占用內存特別大的對象無法被回收。
jhat
JVM Heap Analysis Tool命令是與jmap搭配使用,用來分析jmap生成的dump,jhat內置了一個微型的HTTP/HTML服務器,生成dump的分析結果後,可以在瀏覽器中查看。在此要註意,一般不會直接在服務器上進行分析,因為jhat是一個耗時並且耗費硬件資源的過程,一般把服務器生成的dump文件復制到本地或其他機器上進行分析。【內存分析】
1234567891011121314151617181920212223242526 | [[email protected] bin] # jhat -help Usage: jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline < file >] [-debug <int>] [-version] [-h|-help] < file > -J<flag> Pass <flag> directly to the runtime system. For example, -J-mx512m to use a maximum heap size of 512MB -stack false : Turn off tracking object allocation call stack. -refs false : Turn off tracking of references to objects -port <port>: Set the port for the HTTP server. Defaults to 7000 -exclude < file >: Specify a file that lists data members that should be excluded from the reachableFrom query. -baseline < file >: Specify a baseline object dump. Objects in both heap dumps with the same ID and same class will be marked as not being "new" . -debug <int>: Set debug level. 0: No debug output 1: Debug hprof file parsing 2: Debug hprof file parsing, no server -version Report version number -h|-help Print this help and exit < file > The file to read For a dump file that contains multiple heap dumps, you may specify which dump in the file by appending "#<number>" to the file name, i.e. "foo.hprof#3" . All boolean options default to "true" |
參數
-J< flag > 因為 jhat 命令實際上會啟動一個JVM來執行, 通過 -J 可以在啟動JVM時傳入一些啟動參數. 例如, -J-Xmx512m 則指定運行 jhat 的Java虛擬機使用的最大堆內存為 512 MB. 如果需要使用多個JVM啟動參數,則傳入多個 -Jxxxxxx.-stack false|true 關閉對象分配調用棧跟蹤(tracking object allocation call stack)。 如果分配位置信息在堆轉儲中不可用. 則必須將此標誌設置為 false. 默認值為 true.
-refs false|true 關閉對象引用跟蹤(tracking of references to objects)。 默認值為 true. 默認情況下, 返回的指針是指向其他特定對象的對象,如反向鏈接或輸入引用(referrers or incoming references), 會統計/計算堆中的所有對象。
-port port-number 設置 jhat HTTP server 的端口號. 默認值 7000。-exclude exclude-file 指定對象查詢時需要排除的數據成員列表文件(a file that lists data members that should be excluded from the reachable objects query)。 例如, 如果文件列列出了 java.lang.String.value , 那麽當從某個特定對象 Object o 計算可達的對象列表時, 引用路徑涉及 java.lang.String.value 的都會被排除。
-baseline exclude-file 指定一個基準堆轉儲(baseline heap dump)。 在兩個 heap dumps 中有相同 object ID 的對象會被標記為不是新的(marked as not being new). 其他對象被標記為新的(new). 在比較兩個不同的堆轉儲時很有用。
-debug int 設置 debug 級別. 0 表示不輸出調試信息。 值越大則表示輸出更詳細的 debug 信息。
-version 啟動後只顯示版本信息就退出。
示例
1 | jhat -J-Xmx512m dump.hprof |
1 | jhat -port 7000 mem.dat |
jmap -dump:format=b,file=mem.dat pid #將內存使用的詳細情況輸出到mem.dat 文件
通過jhat -port 7000 mem.dat可以將mem.dat的內容以web的方式暴露到網絡,訪問http://ip-server:7000查看。
觀察是否大量應該被回收的對象在一直被引用或者是否有占用內存特別大的對象無法被回收。
JVM調優命令-jhat