2个月前 (02-26)  jvm |   抢沙发  53 
文章评分 0 次,平均分 0.0

什么是core dump核心转储?

当程序异常终止时,应将程序在终止点的状态保存在某个位置以供进一步分析。此状态以核心转储文件的形式记录。

核心转储core dump文件包含异常终止发生的位置、进程堆栈、符号表等详细信息。

为什么需要core dump?

当生成堆转储jmap 块时,对于大堆,这可能需要很长时间。在这些情况下,获取核心然后运行 ​​jmap 从core dump提取堆转储通常要快得多。通常最好在创建core dump的同一机器上创建堆转储,以避免环境差异。

如何确保将保存core dump?

每个进程都有这个核心的大小限制。如果超过这个限制,将不会保存核心转储。默认情况下,此限制为0,这意味着默认情况下不会转储任何core

我们需要在linux中使用“ulimit”命令来查找核心文件的限制。“ulimit”命令为当前进程设置各种限制。

检查核心文件大小限制:

[root@vx111a ~]# ulimit -a | grep core
core file size          (blocks, -c) 0

由于是“0”,因此无法保存任何内容。

[root@vx111a ~]# ulimit -c unlimited
Change the limitation to unlimited

[root@vx111a ~]# ulimit -a | grep core
core file size          (blocks, -c) unlimited

一旦我们改变了限制,我们就会使用linux中可用的“gdb”命令生成一个核心转储 core dump。

GDB命令允许您查看另一个程序在执行时内部发生了什么,或者另一程序在崩溃时正在做什么。

所以我启动了一个名为“TestOome”的Java类

[root@vx111a ~]# /usr/jdk1.6.0_14/bin/java -Xms1500m -Xmx1500m TestOome &
[1] 4588

现在我将把gdb附加到进程4588上,就像

[root@vx111a ~]# gdb --pid=4588
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-32.el5)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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 "i386-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Attaching to process 4588
Reading symbols from /usr/jdk1.6.0_14/bin/java...(no debugging symbols found)...done.
Reading symbols from /lib/libpthread.so.0...(no debugging symbols found)...done.
[Thread debugging using libthread_db enabled]
[New Thread 0x51953b90 (LWP 4599)]
[New Thread 0x519a4b90 (LWP 4598)]
[New Thread 0x51a25b90 (LWP 4597)]
[New Thread 0x51aa6b90 (LWP 4596)]
[New Thread 0x51af7b90 (LWP 4595)]
[New Thread 0x51d48b90 (LWP 4594)]
[New Thread 0x51d99b90 (LWP 4593)]
[New Thread 0x51e1ab90 (LWP 4592)]
[New Thread 0x52064b90 (LWP 4591)]
[New Thread 0x520e5b90 (LWP 4590)]
[New Thread 0xb7419b90 (LWP 4589)]
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /usr/jdk1.6.0_14/bin/../jre/lib/i386/jli/libjli.so...(no debugging symbols found)...done.
Loaded symbols for /usr/jdk1.6.0_14/bin/../jre/lib/i386/jli/libjli.so
Reading symbols from /lib/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /usr/jdk1.6.0_14/jre/lib/i386/server/libjvm.so...(no debugging symbols found)...done.
Loaded symbols for /usr/jdk1.6.0_14/jre/lib/i386/server/libjvm.so
Reading symbols from /lib/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /lib/librt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/librt.so.1
Reading symbols from /usr/jdk1.6.0_14/jre/lib/i386/libverify.so...(no debugging symbols found)...done.
Loaded symbols for /usr/jdk1.6.0_14/jre/lib/i386/libverify.so
Reading symbols from /usr/jdk1.6.0_14/jre/lib/i386/libjava.so...(no debugging symbols found)...done.
Loaded symbols for /usr/jdk1.6.0_14/jre/lib/i386/libjava.so
Reading symbols from /lib/libnsl.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libnsl.so.1
Reading symbols from /usr/jdk1.6.0_14/jre/lib/i386/native_threads/libhpi.so...(no debugging symbols found)...done.
Loaded symbols for /usr/jdk1.6.0_14/jre/lib/i386/native_threads/libhpi.so
Reading symbols from /lib/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_files.so.2
Reading symbols from /usr/jdk1.6.0_14/jre/lib/i386/libzip.so...(no debugging symbols found)...done.
Loaded symbols for /usr/jdk1.6.0_14/jre/lib/i386/libzip.so
0xb7f72402 in __kernel_vsyscall ()
(gdb) gcore
Saved corefile core.4588
(gdb) detach
Detaching from program: /usr/jdk1.6.0_14/bin/java, process 4588
(gdb) quit

最后3个命令基本上是重要的,

  • Gcore:生成Core文件
  • Detach:从进程ID 4588中分离gdb
  • Quit:退出

现在我们可以看到核心文件是这样生成的:

[root@vx111a ~]# file core.4588
core.4588: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4-style, from 'java'

还有另一种方法可以使用生成Core文件

[root@vx111a ~]# kill -SIGABRT 4705

现在,我们需要从这个核心文件使用“jmap”创建一个堆转储,如

jmap -heap:format=b JAVA_HOME/bin/java COREFILE > heap.hprof 2>&1

现在我们可以在这个核心文件上执行许多其他功能,比如

获取线程转储信息:

[root@vx111a ~]# /usr/jdk1.6.0_14/bin/jstack  /usr/jdk1.6.0_14/bin/java core.4588
Attaching to core core.4588 from executable /usr/jdk1.6.0_14/bin/java, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14.0-b16
Deadlock Detection:

No deadlocks found.

Thread 4595: (state = BLOCKED)

Thread 4594: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.ref.ReferenceQueue.remove(long) @bci=44, line=118 (Interpreted frame)
 - java.lang.ref.ReferenceQueue.remove() @bci=2, line=134 (Interpreted frame)
 - java.lang.ref.Finalizer$FinalizerThread.run() @bci=3, line=159 (Interpreted frame)


Thread 4593: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.Object.wait() @bci=2, line=485 (Interpreted frame)
 - java.lang.ref.Reference$ReferenceHandler.run() @bci=46, line=116 (Interpreted frame)


Thread 4589: (state = BLOCKED)
 - java.util.Arrays.copyOf(java.lang.Object[], int, java.lang.Class) @bci=8, line=2760 (Interpreted frame)
 - java.util.Arrays.copyOf(java.lang.Object[], int) @bci=6, line=2734 (Interpreted frame)
 - java.util.ArrayList.ensureCapacity(int) @bci=51, line=167 (Compiled frame)
 - java.util.ArrayList.add(java.lang.Object) @bci=7, line=351 (Compiled frame)
 - TestOome.main(java.lang.String[]) @bci=23, line=15 (Compiled frame)

为了获得堆详细信息,jmap检查一个核心文件并打印出共享对象内存映射或堆详细信息

[root@vx111a ~]# /usr/jdk1.6.0_14/bin/jmap  /usr/jdk1.6.0_14/bin/java core.4588
Attaching to core core.4588 from executable /usr/jdk1.6.0_14/bin/java, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14.0-b16
0x08048000      46K     /usr/jdk1.6.0_14/bin/java
0x00887000      134K    /lib/libpthread.so.0
0xb7f58000      37K     /usr/jdk1.6.0_14/bin/../jre/lib/i386/jli/libjli.so
0x00880000      20K     /lib/libdl.so.2
0x006fa000      1654K   /lib/libc.so.6
0x006db000      126K    /lib/ld-linux.so.2
0xb741a000      8965K   /usr/jdk1.6.0_14/jre/lib/i386/server/libjvm.so
0x00855000      211K    /lib/libm.so.6
0x008b7000      47K     /lib/librt.so.1
0xb7f65000      55K     /usr/jdk1.6.0_14/jre/lib/i386/libverify.so
0xb73a4000      184K    /usr/jdk1.6.0_14/jre/lib/i386/libjava.so
0x00924000      107K    /lib/libnsl.so.1
0xb739d000      37K     /usr/jdk1.6.0_14/jre/lib/i386/native_threads/libhpi.so
0xb7381000      49K     /lib/libnss_files.so.2
0xb7370000      74K     /usr/jdk1.6.0_14/jre/lib/i386/libzip.so
 

除特别注明外,本站所有文章均为老K的Java博客原创,转载请注明出处来自https://javakk.com/2955.html

关于

发表评论

表情 格式

暂无评论

登录

忘记密码 ?

切换登录

注册