Skip to content

Commit 1a8c38c

Browse files
mlippautzCommit bot
authored andcommitted
[heap] Fix recursive GCs caused by adjusting externally allocated memory
[email protected] BUG=chromium:526244 LOG=N Review URL: https://codereview.chromium.org/1325643002 Cr-Commit-Position: refs/heads/master@{#30478}
1 parent ca8134c commit 1a8c38c

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/api.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6873,6 +6873,7 @@ Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) {
68736873

68746874
void Isolate::CollectAllGarbage(const char* gc_reason) {
68756875
i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
6876+
DCHECK_EQ(heap->gc_state(), i::Heap::NOT_IN_GC);
68766877
if (heap->incremental_marking()->IsStopped()) {
68776878
if (heap->incremental_marking()->CanBeActivated()) {
68786879
heap->StartIncrementalMarking(

src/heap/heap.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,9 @@ void Heap::RegisterNewArrayBuffer(bool in_new_space, void* data,
18001800
RegisterNewArrayBufferHelper(live_array_buffers_for_scavenge_, data,
18011801
length);
18021802
}
1803+
1804+
// We may go over the limit of externally allocated memory here. We call the
1805+
// api function to trigger a GC in this case.
18031806
reinterpret_cast<v8::Isolate*>(isolate_)
18041807
->AdjustAmountOfExternalAllocatedMemory(length);
18051808
}
@@ -1842,16 +1845,13 @@ void Heap::FreeDeadArrayBuffers(bool from_scavenge) {
18421845
live_array_buffers_for_scavenge_.erase(buffer.first);
18431846
}
18441847
}
1845-
size_t freed_memory = FreeDeadArrayBuffersHelper(
1848+
1849+
// Do not call through the api as this code is triggered while doing a GC.
1850+
amount_of_external_allocated_memory_ += FreeDeadArrayBuffersHelper(
18461851
isolate_,
18471852
from_scavenge ? live_array_buffers_for_scavenge_ : live_array_buffers_,
18481853
from_scavenge ? not_yet_discovered_array_buffers_for_scavenge_
18491854
: not_yet_discovered_array_buffers_);
1850-
if (freed_memory) {
1851-
reinterpret_cast<v8::Isolate*>(isolate_)
1852-
->AdjustAmountOfExternalAllocatedMemory(
1853-
-static_cast<int64_t>(freed_memory));
1854-
}
18551855
}
18561856

18571857

0 commit comments

Comments
 (0)