Skip to content

Commit 80b98c8

Browse files
committedMar 15, 2024
8320503: Print warning if VM reaches MallocLimit during error reporting
Reviewed-by: jsjolen
1 parent dde519d commit 80b98c8

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed
 

‎src/hotspot/share/nmt/mallocTracker.cpp

+23-10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "utilities/debug.hpp"
4343
#include "utilities/ostream.hpp"
4444
#include "utilities/vmError.hpp"
45+
#include "utilities/globalDefinitions.hpp"
4546

4647
MallocMemorySnapshot MallocMemorySummary::_snapshot;
4748

@@ -101,15 +102,21 @@ void MallocMemorySummary::initialize() {
101102

102103
bool MallocMemorySummary::total_limit_reached(size_t s, size_t so_far, const malloclimit* limit) {
103104

104-
// Ignore the limit break during error reporting to prevent secondary errors.
105-
if (VMError::is_error_reported()) {
106-
return false;
107-
}
108-
109105
#define FORMATTED \
110106
"MallocLimit: reached global limit (triggering allocation size: " PROPERFMT ", allocated so far: " PROPERFMT ", limit: " PROPERFMT ") ", \
111107
PROPERFMTARGS(s), PROPERFMTARGS(so_far), PROPERFMTARGS(limit->sz)
112108

109+
// If we hit the limit during error reporting, we print a short warning but otherwise ignore it.
110+
// We don't want to risk recursive assertion or torn hs-err logs.
111+
if (VMError::is_error_reported()) {
112+
// Print warning, but only the first n times to avoid flooding output.
113+
static int stopafter = 10;
114+
if (stopafter-- > 0) {
115+
log_warning(nmt)(FORMATTED);
116+
}
117+
return false;
118+
}
119+
113120
if (limit->mode == MallocLimitMode::trigger_fatal) {
114121
fatal(FORMATTED);
115122
} else {
@@ -122,15 +129,21 @@ bool MallocMemorySummary::total_limit_reached(size_t s, size_t so_far, const mal
122129

123130
bool MallocMemorySummary::category_limit_reached(MEMFLAGS f, size_t s, size_t so_far, const malloclimit* limit) {
124131

125-
// Ignore the limit break during error reporting to prevent secondary errors.
126-
if (VMError::is_error_reported()) {
127-
return false;
128-
}
129-
130132
#define FORMATTED \
131133
"MallocLimit: reached category \"%s\" limit (triggering allocation size: " PROPERFMT ", allocated so far: " PROPERFMT ", limit: " PROPERFMT ") ", \
132134
NMTUtil::flag_to_enum_name(f), PROPERFMTARGS(s), PROPERFMTARGS(so_far), PROPERFMTARGS(limit->sz)
133135

136+
// If we hit the limit during error reporting, we print a short warning but otherwise ignore it.
137+
// We don't want to risk recursive assertion or torn hs-err logs.
138+
if (VMError::is_error_reported()) {
139+
// Print warning, but only the first n times to avoid flooding output.
140+
static int stopafter = 10;
141+
if (stopafter-- > 0) {
142+
log_warning(nmt)(FORMATTED);
143+
}
144+
return false;
145+
}
146+
134147
if (limit->mode == MallocLimitMode::trigger_fatal) {
135148
fatal(FORMATTED);
136149
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.