Skip to content

Commit 7ce402d

Browse files
committed
8368551: Core dump warning may be confusing
Backport-of: c146805
1 parent 9183b3f commit 7ce402d

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

src/hotspot/os/linux/os_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5255,7 +5255,7 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
52555255

52565256
if (core_pattern[0] == '|') {
52575257
written = jio_snprintf(buffer, bufferSize,
5258-
"\"%s\" (or dumping to %s/core.%d)",
5258+
"\"%s\" (alternatively, falling back to %s/core.%d)",
52595259
&core_pattern[1], p, current_process_id());
52605260
} else if (pid_pos != nullptr) {
52615261
*pid_pos = '\0';

src/hotspot/os/posix/os_posix.cpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,41 +107,60 @@ size_t os::_os_min_stack_allowed = PTHREAD_STACK_MIN;
107107

108108
// Check core dump limit and report possible place where core can be found
109109
void os::check_core_dump_prerequisites(char* buffer, size_t bufferSize, bool check_only) {
110+
stringStream buf(buffer, bufferSize);
110111
if (!FLAG_IS_DEFAULT(CreateCoredumpOnCrash) && !CreateCoredumpOnCrash) {
111-
jio_snprintf(buffer, bufferSize, "CreateCoredumpOnCrash is disabled from command line");
112-
VMError::record_coredump_status(buffer, false);
112+
buf.print("CreateCoredumpOnCrash is disabled from command line");
113+
VMError::record_coredump_status(buf.freeze(), false);
113114
} else {
114115
struct rlimit rlim;
115116
bool success = true;
116117
bool warn = true;
117118
char core_path[PATH_MAX];
118119
if (get_core_path(core_path, PATH_MAX) <= 0) {
119-
jio_snprintf(buffer, bufferSize, "core.%d (may not exist)", current_process_id());
120+
// In the warning message, let the user know.
121+
if (check_only) {
122+
buf.print("the core path couldn't be determined. It commonly defaults to ");
123+
}
124+
buf.print("core.%d%s", current_process_id(), check_only ? "" : " (may not exist)");
120125
#ifdef LINUX
121126
} else if (core_path[0] == '"') { // redirect to user process
122-
jio_snprintf(buffer, bufferSize, "Core dumps may be processed with %s", core_path);
127+
if (check_only) {
128+
buf.print("core dumps may be further processed by the following: ");
129+
} else {
130+
buf.print("Determined by the following: ");
131+
}
132+
buf.print("%s", core_path);
123133
#endif
124134
} else if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
125-
jio_snprintf(buffer, bufferSize, "%s (may not exist)", core_path);
135+
if (check_only) {
136+
buf.print("the rlimit couldn't be determined. If resource limits permit, the core dump will be located at ");
137+
}
138+
buf.print("%s%s", core_path, check_only ? "" : " (may not exist)");
126139
} else {
127140
switch(rlim.rlim_cur) {
128141
case RLIM_INFINITY:
129-
jio_snprintf(buffer, bufferSize, "%s", core_path);
142+
buf.print("%s", core_path);
130143
warn = false;
131144
break;
132145
case 0:
133-
jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again");
146+
buf.print("%s dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again", check_only ? "core" : "Core");
134147
success = false;
135148
break;
136149
default:
137-
jio_snprintf(buffer, bufferSize, "%s (max size " UINT64_FORMAT " k). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", core_path, uint64_t(rlim.rlim_cur) / K);
150+
if (check_only) {
151+
buf.print("core dumps are constrained ");
152+
} else {
153+
buf.print( "%s ", core_path);
154+
}
155+
buf.print( "(max size " UINT64_FORMAT " k). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", uint64_t(rlim.rlim_cur) / K);
138156
break;
139157
}
140158
}
159+
const char* result = buf.freeze();
141160
if (!check_only) {
142-
VMError::record_coredump_status(buffer, success);
161+
VMError::record_coredump_status(result, success);
143162
} else if (warn) {
144-
warning("CreateCoredumpOnCrash specified, but %s", buffer);
163+
warning("CreateCoredumpOnCrash specified, but %s", result);
145164
}
146165
}
147166
}

test/hotspot/jtreg/runtime/ErrorHandling/TestCrashOnOutOfMemoryError.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -72,8 +72,8 @@ public static void main(String[] args) throws Exception {
7272
#
7373
# JRE version: OpenJDK Runtime Environment (9.0) (build 1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00)
7474
# Java VM: OpenJDK 64-Bit Server VM (1.9.0-internal-debug-cheleswer_2015_10_20_14_32-b00, mixed mode, tiered, compressed oops, serial gc, linux-amd64)
75-
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %P" (or dumping to
76-
/home/cheleswer/Desktop/core.6212)
75+
# Core dump will be written. Default location: Determined by the following:
76+
"/usr/share/apport/apport %p %s %c %P" (alternatively, falling back to /home/cheleswer/Desktop/core.6212)
7777
#
7878
# An error report file with more information is saved as:
7979
# /home/cheleswer/Desktop/hs_err_pid6212.log

0 commit comments

Comments
 (0)