0

I am currently using JDK8, in the 17.4.2 Collect Core Dumps on Linux, there is the following description:

By default, the core dump is created in the current working directory of the process and the name of the core dump file is core.pid, where pid is the process id of the crashed Java process.

But I want to change the path of core dump, is there any way to achieve this?

I use sysctl -wq kernel.core_pattern=/opt/shared/core_%e.%p to set it, but it doesn't work for the JVM process.

I use kill -11 java_pid to simulate this situation, but the core dump is generated in the JVM process working directory, not the directory I set.

#
# 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]

Answer: The path to core dump can only be modified by changing the process working directory.

// 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);
}

Reference: jdk/os_linux.cpp at jdk8-b120 · openjdk/jdk · GitHub

Poison
  • 389
  • 2
  • 14

2 Answers2

1

The answer depends on your Java version and the OS platform.

For Java 8 on Linux, the location is hard-wired to the current directory.

For Java 11 and Java 17 on Linux, the JVM uses the Linux "/proc/sys/kernel/core_pattern" mechanism described in Changing location of core dump and other places.

On BSD (e.g. Darwin), the location is Java version dependent: either "/core" (hard wired) or a location provided by the OS kernel.

On AIX and Windows it seems to use the current directory in all Java versions.

And so on.

(The above is from looking at the OpenJDK source code for Java 8, 11 and 17. Note that the relevant code changed substantially between Java 8 and 11.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

There are multiple resources available showing how to change the default core dump pathname:

Juraj Martinka
  • 3,991
  • 2
  • 23
  • 25
  • I tried the above method and found that it does not work for the JVM process. It seems that the JVM process does not use the above path. – Poison Jun 15 '22 at 06:52
  • Eventually I found out that the JVM process had the path hardcoded to the process working directory, not using the path specified by `kernel.core_pattern`. – Poison Jun 15 '22 at 07:15
  • Note: the above resources are for changing the location of a Linux kernel core dump. The OP is asking about JVM "panic" dumps. – Stephen C Jun 15 '22 at 07:42