LoginSignup
117
123

More than 5 years have passed since last update.

Javaのスレッドダンプ、ヒープダンプの取り方

Last updated at Posted at 2014-01-24

JavaでFullGCが頻発したり、メモリリークしてたり、busyなスレッドに埋め尽くされそうになったとき、調査に必要なダンプを取得してから再起動することはよくあるでしょう。それらの取り方。

Javaのスレッドダンプを取得する - Qiita [キータ]
前にスレッドダンプだけ書いたけど、ヒープダンプもあったほうが良いのでまとめ

JavaのプロセスID取得

$ $JAVA_HOME/bin/jps -v
12345 Application -XX:OnOutOfMemoryError=/us…
67890 Bootstrap -Djava.util.logging.config.file=/us…

複数のプロセスが起動しているときは-vオプションで詳細を出したほうが良いけど、ひとつだけならオプションなしでOK

スレッドダンプ取得

実行中のスレッドの状態を取得する(スタックトレース)

$ $JAVA_HOME/bin/jstack -F 67890 > threaddump.txt
Attaching to process ID 67890, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 23.7-b01

下記のようなエラーが出るときは-Fをつけて強制出力する

67890: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding

ヒープダンプ取得

ヒープに割り当てられたオブジェクト情報を取得する(メモリーマップ)
スレッドダンプはすぐ取れるが、ヒープダンプは割り当てているヒープサイズによっては数十分かかることもあるので注意

# $JAVA_HOME/bin/jmap -F -dump:format=b,file=heapdump.map 67890
Attaching to process ID 67890, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 23.7-b01
Dumping heap to heapdump.map ...
none
null_check
null_assert
range_check
class_check
array_check
intrinsic
bimorphic
unloaded
uninitialized
unreached
unhandled
constraint
div0_check
age
predicate
loop_limit_check
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Heap dump file created

同じく-Fで強制射出!

117
123
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
117
123