From 1a8c38c50513f9af07ada479629a653e1cf36ff3 Mon Sep 17 00:00:00 2001 From: mlippautz Date: Mon, 31 Aug 2015 08:36:24 -0700 Subject: [PATCH] [heap] Fix recursive GCs caused by adjusting externally allocated memory R=mstarzinger@chromium.org BUG=chromium:526244 LOG=N Review URL: https://codereview.chromium.org/1325643002 Cr-Commit-Position: refs/heads/master@{#30478} --- src/api.cc | 1 + src/heap/heap.cc | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/api.cc b/src/api.cc index 42a88758272..d2ad3069dd3 100644 --- a/src/api.cc +++ b/src/api.cc @@ -6873,6 +6873,7 @@ Local v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) { void Isolate::CollectAllGarbage(const char* gc_reason) { i::Heap* heap = reinterpret_cast(this)->heap(); + DCHECK_EQ(heap->gc_state(), i::Heap::NOT_IN_GC); if (heap->incremental_marking()->IsStopped()) { if (heap->incremental_marking()->CanBeActivated()) { heap->StartIncrementalMarking( diff --git a/src/heap/heap.cc b/src/heap/heap.cc index ab52719fd8e..a4357f11fd2 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -1800,6 +1800,9 @@ void Heap::RegisterNewArrayBuffer(bool in_new_space, void* data, RegisterNewArrayBufferHelper(live_array_buffers_for_scavenge_, data, length); } + + // We may go over the limit of externally allocated memory here. We call the + // api function to trigger a GC in this case. reinterpret_cast(isolate_) ->AdjustAmountOfExternalAllocatedMemory(length); } @@ -1842,16 +1845,13 @@ void Heap::FreeDeadArrayBuffers(bool from_scavenge) { live_array_buffers_for_scavenge_.erase(buffer.first); } } - size_t freed_memory = FreeDeadArrayBuffersHelper( + + // Do not call through the api as this code is triggered while doing a GC. + amount_of_external_allocated_memory_ += FreeDeadArrayBuffersHelper( isolate_, from_scavenge ? live_array_buffers_for_scavenge_ : live_array_buffers_, from_scavenge ? not_yet_discovered_array_buffers_for_scavenge_ : not_yet_discovered_array_buffers_); - if (freed_memory) { - reinterpret_cast(isolate_) - ->AdjustAmountOfExternalAllocatedMemory( - -static_cast(freed_memory)); - } }