Skip to content

Commit b2f7c32

Browse files
mhdawsonofrobots
authored andcommitted
deps: cherry-pick 1ef7487b from v8 upstream
Original commit message: Improved diagnostic message for JS heap out of memory This patch replaces the unused 'take_snapshot' parameter on FatalProcessOutOfMemory() with a 'is_heap_oom' parameter. The parameter is set to true on error paths where the JS heap is out of memory, as distinct from a malloc() failure i.e. process out of memory. The message output to stderr or passed to embedding applications via FatalErrorCallback is 'Javascript heap out of memory' rather than 'process out of memory'. BUG= R=jochen@chromium.org, verwaest@chromium.org, michael_dawson@ca.ibm.com Review URL: https://codereview.chromium.org/1873443002 Cr-Commit-Position: refs/heads/master@{#35431} We'd like this in 6.x to help with diagnosing customer problems. It provides a better message on OOM so that it is easier to be able to tell whether the OOM was due to heap exhaustion or running out of native memory. PR-URL: #6218 Reviewed-By: Ben Noordhuis <ben@strongloop.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7af2f63 commit b2f7c32

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

deps/v8/src/api.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void i::FatalProcessOutOfMemory(const char* location) {
241241

242242
// When V8 cannot allocated memory FatalProcessOutOfMemory is called.
243243
// The default fatal error handler is called and execution is stopped.
244-
void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) {
244+
void i::V8::FatalProcessOutOfMemory(const char* location, bool is_heap_oom) {
245245
i::Isolate* isolate = i::Isolate::Current();
246246
char last_few_messages[Heap::kTraceRingBufferSize + 1];
247247
char js_stacktrace[Heap::kStacktraceBufferSize + 1];
@@ -303,7 +303,9 @@ void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) {
303303
PrintF("\n<--- Last few GCs --->\n%s\n", first_newline);
304304
PrintF("\n<--- JS stacktrace --->\n%s\n", js_stacktrace);
305305
}
306-
Utils::ApiCheck(false, location, "Allocation failed - process out of memory");
306+
Utils::ApiCheck(false, location, is_heap_oom
307+
? "Allocation failed - JavaScript heap out of memory"
308+
: "Allocation failed - process out of memory");
307309
// If the fatal error handler returns, we stop execution.
308310
FATAL("API fatal error handler returned after process out of memory");
309311
}

deps/v8/src/heap/heap.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4018,8 +4018,7 @@ AllocationResult Heap::AllocateUninitializedFixedDoubleArray(
40184018
AllocationResult Heap::AllocateRawFixedDoubleArray(int length,
40194019
PretenureFlag pretenure) {
40204020
if (length < 0 || length > FixedDoubleArray::kMaxLength) {
4021-
v8::internal::Heap::FatalProcessOutOfMemory("invalid array length",
4022-
kDoubleAligned);
4021+
v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true);
40234022
}
40244023
int size = FixedDoubleArray::SizeFor(length);
40254024
AllocationSpace space = SelectSpace(pretenure);
@@ -5648,9 +5647,8 @@ void Heap::CompactRetainedMaps(ArrayList* retained_maps) {
56485647
if (new_length != length) retained_maps->SetLength(new_length);
56495648
}
56505649

5651-
5652-
void Heap::FatalProcessOutOfMemory(const char* location, bool take_snapshot) {
5653-
v8::internal::V8::FatalProcessOutOfMemory(location, take_snapshot);
5650+
void Heap::FatalProcessOutOfMemory(const char* location, bool is_heap_oom) {
5651+
v8::internal::V8::FatalProcessOutOfMemory(location, is_heap_oom);
56545652
}
56555653

56565654
#ifdef DEBUG

deps/v8/src/heap/heap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ class Heap {
568568
static inline bool IsOneByte(T t, int chars);
569569

570570
static void FatalProcessOutOfMemory(const char* location,
571-
bool take_snapshot = false);
571+
bool is_heap_oom = false);
572572

573573
static bool RootIsImmortalImmovable(int root_index);
574574

deps/v8/src/heap/mark-compact.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,8 +1728,8 @@ class MarkCompactCollector::EvacuateNewSpaceVisitor final
17281728
compaction_spaces_->Get(OLD_SPACE)->AllocateRaw(size_in_bytes,
17291729
alignment);
17301730
if (allocation.IsRetry()) {
1731-
FatalProcessOutOfMemory(
1732-
"MarkCompactCollector: semi-space copy, fallback in old gen\n");
1731+
v8::internal::Heap::FatalProcessOutOfMemory(
1732+
"MarkCompactCollector: semi-space copy, fallback in old gen", true);
17331733
}
17341734
return allocation;
17351735
}

deps/v8/src/v8.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class V8 : public AllStatic {
2121
// Report process out of memory. Implementation found in api.cc.
2222
// This function will not return, but will terminate the execution.
2323
static void FatalProcessOutOfMemory(const char* location,
24-
bool take_snapshot = false);
24+
bool is_heap_oom = false);
2525

2626
static void InitializePlatform(v8::Platform* platform);
2727
static void ShutdownPlatform();

0 commit comments

Comments
 (0)