Java core dump analyzer

Java core dump analyzer

Java projects generally use jstack, jmap and other Java tools can analyze process bugs, but sometimes jvm itself exits abnormally. At this time, there is usually no hprof file, but a core file is generated, especially in projects using JNI technology. It is necessary to fully exploit the useful information in the core file.

Core dump introduction

When the program is abnormally terminated or crashes during the running process, the operating system records the current memory state of the program and saves it in a file. This behavior is called Core Dump (Chinese translation is «core dump»). We can think of core dump as a «memory snapshot», but in fact, in addition to memory information, some key program running states will also be dumped at the same time, such as register information (including program pointers, stack pointers, etc.), memory management information. , other processor and operating system status and information. Core dump is very helpful for programmers to diagnose and debug programs because it is difficult to reproduce for some program errors, such as pointer exceptions, and the core dump file can reproduce the situation when the program went wrong.

Generate core dump

Since core dump files take up a certain amount of disk space, Linux does not allow core dump files to be generated by default. For example, the following command shows that the maximum core dump file size allowed by Linux is 0:

$ ulimit -a | grep core core file size (blocks, -c) 0 

Linux can be used to generate core dump files with the following settings:

Читайте также:  Передача значений переменных

Note that this setting is only valid for the current login callback. If you want this setting to be persistent, you can write it to the /etc/security/limits.conf file:

$ sudo vi /etc/security/limits.conf * soft core unlimited * soft hard unlimited 

gdb

gdb $JAVA_HOME$/bin/java core-26492
Enter the gdb context and execute bt Command, you can see the thread stack when the process exits.

$ gdb /data/soft/jdk/bin/java core.11668 GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: . Reading symbols from /data/soft/jdk1.8.0_141/bin/java. Missing separate debuginfo for /data/soft/jdk1.8.0_141/bin/java Try: yum --enablerepo='*debug*' install /usr/lib/debug/.build-id/c9/0f19ee0af98c47ccaa7181853cfd14867bc931.debug (no debugging symbols found). done. [New LWP 14367] . [New LWP 14355] [New LWP 11685] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Missing separate debuginfo for /data/soft/jdk1.8.0_141/jre/lib/amd64/server/libjvm.so Try: yum --enablerepo='*debug*' install /usr/lib/debug/.build-id/43/a2bc419314aa566cd5ba54779ae18b47022cad.debug Missing separate debuginfo for /data/soft/jdk1.8.0_141/jre/lib/amd64/libverify.so Try: yum --enablerepo='*debug*' install /usr/lib/debug/.build-id/b3/de2701fa3aef182d8e7b2db8d294a91af1eb7c.debug Missing separate debuginfo for /data/soft/jdk1.8.0_141/jre/lib/amd64/libmanagement.so Try: yum --enablerepo='*debug*' install /usr/lib/debug/.build-id/ee/7e746ef83f2c2fbe8ea0cb42706b63cd74de3f.debug Missing separate debuginfo for /data/soft/jdk1.8.0_141/jre/lib/amd64/libinstrument.so Try: yum --enablerepo='*debug*' install /usr/lib/debug/.build-id/13/552fe85b2af551ab806735bc5e5f2a5e00fbb1.debug Core was generated by `/data/soft/jdk/bin/java -Djava.util.logging.config.file=/data/home/aics/taskbot'. Program terminated with signal 6, Aborted. #0 0x00007f50d652b1d7 in __GI_raise ([email protected]=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 56 return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig); (gdb) bt #0 0x00007f50d652b1d7 in __GI_raise ([email protected]=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 #1 0x00007f50d652c8c8 in __GI_abort () at abort.c:90 #2 0x00007f50397417f4 in tensorflow::internal::LogMessageFatal::~LogMessageFatal() () from /data/home/aics/taskbot-tomcat/temp/tensorflow_native_libraries-1545395060637-0/libtensorflow_framework.so #3 0x00007f5039721cf0 in tensorflow::monitoring::CollectionRegistry::Register(tensorflow::monitoring::AbstractMetricDef const*, std::function const&) () from /data/home/aics/taskbot-tomcat/temp/tensorflow_native_libraries-1545395060637-0/libtensorflow_framework.so #4 0x00007f501520951f in ?? () from /data/home/aics/taskbot-tomcat/temp/tensorflow_native_libraries-1545633543384-0/libtensorflow_jni.so #5 0x00007f50151334db in ?? () from /data/home/aics/taskbot-tomcat/temp/tensorflow_native_libraries-1545633543384-0/libtensorflow_jni.so #6 0x00007f50d6efd1e3 in call_init (env=0x7f50d00c4460, argv=0x7ffe7bc01488, argc=21, l=) at dl-init.c:82 #7 _dl_init ([email protected]=0x7f50249fa900, argc=21, argv=0x7ffe7bc01488, env=0x7f50d00c4460) at dl-init.c:131 #8 0x00007f50d6f018f6 in dl_open_worker ([email protected]=0x7f503b2f7b98) at dl-open.c:560 #9 0x00007f50d6efcff4 in _dl_catch_error ([email protected]=0x7f503b2f7b88, [email protected]=0x7f503b2f7b90, [email protected]=0x7f503b2f7b80, [email protected]=0x7f50d6f01540 , [email protected]=0x7f503b2f7b98) at dl-error.c:177 #10 0x00007f50d6f00feb in _dl_open (file=0x7f5024008550 "/data/home/aics/taskbot-tomcat/temp/tensorflow_native_libraries-1545633543384-0/libtensorflow_jni.so", mode=-2147483647, caller_dlopen=, nsid=-2, argc=21, argv=0x7ffe7bc01488, env=0x7f50d00c4460) at dl-open.c:650 #11 0x00007f50d68b8fbb in dlopen_doit ([email protected]=0x7f503b2f7da0) at dlopen.c:66 #12 0x00007f50d6efcff4 in _dl_catch_error (objname=0x7f5024ae73e0, errstring=0x7f5024ae73e8, mallocedp=0x7f5024ae73d8, operate=0x7f50d68b8f60 , args=0x7f503b2f7da0) at dl-error.c:177 #13 0x00007f50d68b95bd in _dlerror_run ([email protected]=0x7f50d68b8f60 , [email protected]=0x7f503b2f7da0) at dlerror.c:163 #14 0x00007f50d68b9051 in __dlopen (file=, mode=) at dlopen.c:87 #15 0x00007f50d5e2a24e in os::dll_load(char const*, char*, int) () from /data/soft/jdk1.8.0_141/jre/lib/amd64/server/libjvm.so #16 0x00007f50d5c2198c in JVM_LoadLibrary () from /data/soft/jdk1.8.0_141/jre/lib/amd64/server/libjvm.so #17 0x00007f50d4ac7df8 in Java_java_lang_ClassLoader_00024NativeLibrary_load () from /data/soft/jdk1.8.0_141/jre/lib/amd64/libjava.so 

jstack

I never thought about it before, but I can also use the java tool to analyze the core file.

Use jstack to view the thread execution stack when the process core_dump
/data/soft/jdk/bin/jstack /data/soft/jdk/bin/java core.26492

Thread 15040: (state = IN_NATIVE) - java.lang.ClassLoader$NativeLibrary.load(java.lang.String, boolean) @bci=0 (Interpreted frame) - java.lang.ClassLoader.loadLibrary0(java.lang.Class, java.io.File) @bci=328, line=1941 (Interpreted frame) - java.lang.ClassLoader.loadLibrary(java.lang.Class, java.lang.String, boolean) @bci=48, line=1824 (Interpreted frame) - java.lang.Runtime.load0(java.lang.Class, java.lang.String) @bci=57, line=809 (Interpreted frame) - java.lang.System.load(java.lang.String) @bci=7, line=1086 (Interpreted frame) - org.tensorflow.NativeLibrary.load() @bci=212, line=101 (Interpreted frame) - org.tensorflow.TensorFlow.init() @bci=0, line=66 (Interpreted frame) - org.tensorflow.TensorFlow.() @bci=0, line=70 (Interpreted frame) - org.tensorflow.Graph.() @bci=0, line=258 (Interpreted frame) 

jmap

$ /data/soft/jdk/bin/jmap /data/soft/jdk/bin/java core.14652
The results are as follows:

Attaching to core core.14652 from executable /data/soft/jdk/bin/java, please wait. Debugger attached successfully. Server compiler detected. JVM version is 25.141-b15 0x0000000000400000 7K /data/soft/jdk/bin/java 0x00007fbc261fb000 41K /lib64/libonion.so 0x00007fbc25ec8000 139K /lib64/libpthread.so.0 0x00007fbc25cb2000 100K /data/soft/jdk1.8.0_141/bin/../lib/amd64/jli/libjli.so 0x00007fbc25aae000 18K /lib64/libdl.so.2 0x00007fbc256ec000 2063K /lib64/libc.so.6 0x00007fbc260e4000 151K /lib64/ld-linux-x86-64.so.2 0x00007fbc246f5000 16615K /data/soft/jdk1.8.0_141/jre/lib/amd64/server/libjvm.so 0x00007fbc243f3000 1114K /lib64/libm.so.6 0x00007fbc240ea000 42K /lib64/librt.so.1 0x00007fbc1fdf1000 64K /data/soft/jdk1.8.0_141/jre/lib/amd64/libverify.so 0x00007fbc1fbc5000 220K /data/soft/jdk1.8.0_141/jre/lib/amd64/libjava.so 0x00007fbc1f9aa000 121K /data/soft/jdk1.8.0_141/jre/lib/amd64/libzip.so 0x00007fbbed321000 49K /data/soft/jdk1.8.0_141/jre/lib/amd64/libmanagement.so 0x00007fbbed10a000 113K /data/soft/jdk1.8.0_141/jre/lib/amd64/libnet.so 0x00007fbbeca48000 90K /data/soft/jdk1.8.0_141/jre/lib/amd64/libnio.so 0x00007fbbec500000 251K /data/soft/jdk1.8.0_141/jre/lib/amd64/libsunec.so 0x00007fbbec2ea000 86K /lib64/libgcc_s.so.1 0x00007fbb78e4c000 50874K /data/home/aics/taskbot-tomcat/temp/tensorflow_native_libraries-1545634810127-0/libtensorflow_jni.so 0x00007fbb944f4000 15740K /data/home/aics/taskbot-tomcat/temp/tensorflow_native_libraries-1545634810127-0/libtensorflow_framework.so 0x00007fbb941d7000 972K /lib64/libstdc++.so.6 0x00007fbb69848000 50874K /data/home/aics/taskbot-tomcat/temp/tensorflow_native_libraries-1545641641135-0/libtensorflow_jni.so 

It seems that the memory usage is good, there is no special memory, but I don’t know why libtensorflow_jni.so takes up two 50874K heaps.

Analysis after conversion to hprof

/data/soft/jdk/bin/jmap -dump:format=b,file=dump.hprof /data/soft/jdk/bin/java core.14652
After conversion, you can use MAT or VisualVM for JVM heap memory analysis.

Читайте также:  Бинарное представление чисел java

common problem

  • Missing separate debuginfo for : Excuting an order debuginfo-install glibc-2.17-157.tl2.2.x86_64 libgcc-4.8.5-4.el7.x86_64 libstdc++-4.8.5-4.el7.x86_64

Here generally follow the prompts in the error to execute the command, but I have not installed jvm related, maybe you need to use OpenJDK to debug the package.

reference

  • Core dump under linux [summary]
  • Generate a core dump file on Linux
  • How to capture the behind-the-scenes of JVM crash? (One)
  • https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr016.html#BABBAIJC
  • https://docs.oracle.com/javase/7/docs/technotes/tools/share/jmap.html

Источник

Оцените статью