You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改JDK8环境下Oracle JVM core dump文件的生成路径?

JDK8 调整Core Dump生成路径的实现方式

问题背景

使用JDK8版本时,参照官方文档17.4.2 Collect Core Dumps on Linux章节说明:

默认情况下,core dump文件创建在进程的当前工作目录下,文件名为core.pid,其中pid为崩溃Java进程的进程ID。

尝试通过执行sysctl -wq kernel.core_pattern=/opt/shared/core_%e.%p命令配置全局core dump存放路径,但配置对JVM进程不生效。
执行kill -11 java_pid模拟进程段错误崩溃场景验证,core dump仍然生成在JVM进程的原有工作目录下,未写入预设的/opt/shared目录,JVM崩溃时输出的日志如下:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f6249b4e4a5, pid=1, tid=0x00007f6249b3cb80
#
# JRE version: OpenJDK Runtime Environment (8.0_332-b09) (build 1.8.0_332-b09)
# Java VM: OpenJDK 64-Bit Server VM (25.332-b09 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libpthread.so.0+0xa4a5]  __pthread_clockjoin_ex+0x235
#
# Core dump written. Default location: /opt/core or core.1
#
# An error report file with more information is saved as:
# /opt/shared/java_error.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

[error occurred during error reporting , id 0xb]

结论

JDK8的JVM不会读取Linux系统的kernel.core_pattern全局配置,core dump文件的生成路径仅能通过修改JVM进程的启动工作目录调整。
JDK8 HotSpot虚拟机源码中获取core dump存放路径的逻辑如下,仅将进程当前工作目录作为core文件的生成位置,没有适配系统全局core路径配置的逻辑:

// Get the default path to the core file
// Returns the length of the string
int os::get_core_path(char* buffer, size_t bufferSize) {
  const char* p = get_current_directory(buffer, bufferSize);

  if (p == NULL) {
    assert(p != NULL, "failed to get current directory");
    return 0;
  }

  return strlen(buffer);
}

如果需要统一收集JVM的core dump文件,启动Java进程前先切换工作目录到目标存放路径即可。


内容的提问来源于stack exchange,提问作者Poison

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.02 09:54:30