2024年6月15日发(作者:)

浅析JVM 崩溃的原因及解决方法

王树大 2010-2-8

一 问题的提出

二 JVM 崩溃原因

常见的能够引起JVM崩溃的原因主要有:

 线程阻塞

 CPU 使用率过高

 JVM Crash

 堆内存不足

 类装载

 Java虚拟机自身的Bug

 JDK与服务器(CPU、内存、操作系统)的兼容性

 内存溢出

三 日志分析

1. 日志文件的生成

当Java虚拟机非正常退出时,都会产生hs_err_pid.log的错误日志,缺省情况下,这个文

件会产生在bin(对Tomcat来说一般在CATALINA_HOME/bin)目录下, 可以在Java启动参数通过

下面的设置,来改变这个文件的位置和命名规则。例如:

java -XX:ErrorFile=%CATALINA_HOME%/logs/java_error_%

2. 日志内容分析

1) Signal Name

#

# An unexpected error has been detected by HotSpot Virtual Machine:

#

# SIGSEGV (0xb) at pc=0x004e57dc, pid=7189, tid=1831316368

#

# Java VM: Java HotSpot(TM) Server VM (1.5.0_06-b05 mixed mode)

# Problematic frame:

# C [.6+0x717dc] memcpy+0x1c

#

具体含义如下:

# SIGSEGV (0xb) at pc=

0x004e57dc

, pid=

7189

, tid=

1831316368

| | | | +--- thread id

| | | +------------- process id

| | +--------------------------- program counter

| | (instruction pointer)

| +--------------------------------------- signal number

+---------------------------------------------- signal name

其中Signal Name:

 SIGSEGV:意味着JVM正在执行本地或JNI的代码;

 EXCEPTION_ACCESS_VIOLATION:意味着Java应用Crash的时候,正在运行JVM自己的

代码,而不是外部的Java代码或其他类库代码;

 EXCEPTION_STACK_OVERFLOW:表示这是个栈溢出的错误;

 SIGILL:

2) Problematic frame

它说明JVM在Crash的时候,JVM正在从哪个库文件执行代码。具体含义如下:

Frame Type Description

C

j

V

v

J

Native C frame

Interpreted Java frame

VM frame

VM generated stub frame

Other frame types, including compiled Java frames

也就是说:

 C:表示是JVM或者JNI在执行C代码时出错;

 j: 表示加载或者执行Jvm的代码时出错;

 V:执行虚拟机本身的代码时出错;

 J:表示是虚拟机之外的类代码在执行的时候出错;

3) 线程信息(Thread Section)

Current thread (0x0805ac88): JavaThread "main" [_thread_in_native, id=21139]

| | | | +-- ID

| | | +------------- state

| | +-------------------------- name

| +------------------------------------ type

+-------------------------------------------------- pointer

a) 线程类型(Thread Type):

 JavaThread

 VMThread

 CompilerThread

 GCTaskThread

 WatcherThread

 ConcurrentMarkSweepThread

b) 线程状态(Thread Stat)

Thread State Description

Thread is not created. This occurs only in the case of memory corruption.

Thread has been created but it has not yet started.

Thread is running native code. The error is probably a bug in native code.

Thread is running VM code.

Thread is running either interpreted or compiled Java code.

Thread is blocked.

If any of the above states is followed by the string

_trans

, that means that the thread is

changing to a different state.

_thread_uninitialized

_thread_new

_thread_in_native

_thread_in_vm

_thread_in_Java

_thread_blocked

..._trans

c) 信号信息(Signal Information)

On Solaris OS and Linux systems the signal number (si_signo) and signal code (si_code) are used to

identify the exception, as follows.