java产生core文件分析

在c语音和c++语言编写的程序里,core文件比较常见,但是java程序产生core文件还是比较少见的,最近在一个dubbo项目中发现了一个core文件,这样的情况下一般是jvm自身的异常退出,因此我们可以使用gdb命令执行jvm路径来定位问题

gdb $JAVA_HOME/bin/java  core.118746

然后输入bt就可以看到进程退出时的线程栈

java产生core文件分析_第1张图片

可以看到,是在连接tt数据库时执行freestmt产生的问题

jstack  $JAVA_HOME/bin/java core.118746

查看线程执行栈,其中有一段确实是在freestmt这里IN_NATIVE(正在执行本地方法)

Thread 119385: (state = IN_NATIVE)
 - com.timesten.jdbc.JdbcOdbcClient.freeStmt(long, int) @bci=0 (Compiled frame; information may be imprecise)
 - com.timesten.jdbc.JdbcOdbc.SQLFreeStmt(long, int) @bci=45, line=1103 (Compiled frame)
 - com.timesten.jdbc.JdbcOdbcConnection.dropOdbcStatement(long) @bci=62, line=2643 (Compiled frame)
 - com.timesten.jdbc.JdbcOdbcStatement.close(boolean, boolean) @bci=184, line=556 (Compiled frame)
 - com.timesten.jdbc.JdbcOdbcPreparedStatement.close(boolean, boolean) @bci=196, line=1771 (Compiled frame)
 - com.timesten.jdbc.JdbcOdbcPreparedStatement.close() @bci=3, line=1723 (Compiled frame)
 - org.apache.commons.dbcp.PoolingConnection.destroyObject(java.lang.Object, java.lang.Object) @bci=14, line=311 (Compiled frame)
 - org.apache.commons.pool.impl.GenericKeyedObjectPool.destroy(java.util.Map) @bci=80, line=1450 (Compiled frame)
 - org.apache.commons.pool.impl.GenericKeyedObjectPool.clear() @bci=168, line=1345 (Compiled frame)
 - org.apache.commons.pool.impl.GenericKeyedObjectPool.close() @bci=9, line=1725 (Compiled frame)
 - org.apache.commons.dbcp.PoolingConnection.close() @bci=19, line=84 (Compiled frame)
 - org.apache.commons.dbcp.DelegatingConnection.close() @bci=8, line=247 (Interpreted frame)
 - org.apache.commons.dbcp.PoolableConnection.reallyClose() @bci=1, line=122 (Interpreted frame)
 - org.apache.commons.dbcp.PoolableConnectionFactory.destroyObject(java.lang.Object) @bci=11, line=628 (Interpreted frame)
 - org.apache.commons.pool.impl.GenericObjectPool.returnObject(java.lang.Object) @bci=22, line=1346 (Compiled frame)
 - org.apache.commons.dbcp.PoolableConnection.close() @bci=79, line=90 (Compiled frame)
 - org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close() @bci=11, line=191 (Compiled frame)
 - com.tydic.abm.common.db.JdbcManager.release() @bci=92, line=1088 (Compiled frame)
 - com.tydic.abm.common.db.JdbcManager.rollback() @bci=182, line=1067 (Compiled frame)

我们还可以用jmap命令将core文件转为hprof文件,用MAT或VisualVM进行JVM堆内存分析

jmap -dump:format=b,file=dump.hprof $JAVA_HOME/bin/java core.118746

 

你可能感兴趣的:(研发技术)