Reviewers: Michael Starzinger,

https://codereview.chromium.org/1325643002/diff/1/src/api.cc
File src/api.cc (right):

https://codereview.chromium.org/1325643002/diff/1/src/api.cc#newcode6876
src/api.cc:6876: DCHECK(heap->gc_state() == i::Heap::NOT_IN_GC);
On 2015/08/31 14:42:48, Michael Starzinger wrote:
nit: DCHECK_EQ?

Done.

Description:
[heap] Fix recursive GCs caused by adjusting externally allocated memory

[email protected]
BUG=chromium:526244
LOG=N

Please review this at https://codereview.chromium.org/1325643002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+7, -6 lines):
  M src/api.cc
  M src/heap/heap.cc


Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 42a887582723524f4773847d51cdb2da5f58827a..d2ad3069dd3106b11acf22b8396fc3e42d9ba292 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6873,6 +6873,7 @@ Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) {

 void Isolate::CollectAllGarbage(const char* gc_reason) {
   i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
+  DCHECK_EQ(heap->gc_state(), i::Heap::NOT_IN_GC);
   if (heap->incremental_marking()->IsStopped()) {
     if (heap->incremental_marking()->CanBeActivated()) {
       heap->StartIncrementalMarking(
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index ab52719fd8ed293df0df459a867a2784e0571695..a4357f11fd2810df88382b46e6482cedf957d5af 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<v8::Isolate*>(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<v8::Isolate*>(isolate_)
-        ->AdjustAmountOfExternalAllocatedMemory(
-            -static_cast<int64_t>(freed_memory));
-  }
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to