42
42
#include " utilities/debug.hpp"
43
43
#include " utilities/ostream.hpp"
44
44
#include " utilities/vmError.hpp"
45
+ #include " utilities/globalDefinitions.hpp"
45
46
46
47
MallocMemorySnapshot MallocMemorySummary::_snapshot;
47
48
@@ -101,15 +102,21 @@ void MallocMemorySummary::initialize() {
101
102
102
103
bool MallocMemorySummary::total_limit_reached (size_t s, size_t so_far, const malloclimit* limit) {
103
104
104
- // Ignore the limit break during error reporting to prevent secondary errors.
105
- if (VMError::is_error_reported ()) {
106
- return false ;
107
- }
108
-
109
105
#define FORMATTED \
110
106
" MallocLimit: reached global limit (triggering allocation size: " PROPERFMT " , allocated so far: " PROPERFMT " , limit: " PROPERFMT " ) " , \
111
107
PROPERFMTARGS (s), PROPERFMTARGS (so_far), PROPERFMTARGS (limit->sz )
112
108
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
+
113
120
if (limit->mode == MallocLimitMode::trigger_fatal) {
114
121
fatal (FORMATTED);
115
122
} else {
@@ -122,15 +129,21 @@ bool MallocMemorySummary::total_limit_reached(size_t s, size_t so_far, const mal
122
129
123
130
bool MallocMemorySummary::category_limit_reached (MEMFLAGS f, size_t s, size_t so_far, const malloclimit* limit) {
124
131
125
- // Ignore the limit break during error reporting to prevent secondary errors.
126
- if (VMError::is_error_reported ()) {
127
- return false ;
128
- }
129
-
130
132
#define FORMATTED \
131
133
" MallocLimit: reached category \" %s\" limit (triggering allocation size: " PROPERFMT " , allocated so far: " PROPERFMT " , limit: " PROPERFMT " ) " , \
132
134
NMTUtil::flag_to_enum_name (f), PROPERFMTARGS (s), PROPERFMTARGS (so_far), PROPERFMTARGS (limit->sz )
133
135
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
+
134
147
if (limit->mode == MallocLimitMode::trigger_fatal) {
135
148
fatal (FORMATTED);
136
149
} else {
0 commit comments