Do more to avoid last-resort stop-the-world GC
authorerikcorry <erikcorry@chromium.org>
Mon, 27 Apr 2015 14:10:27 +0000 (07:10 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 27 Apr 2015 14:10:05 +0000 (14:10 +0000)
BUG=chromium:481433
R=hpayer@chromium.org
LOG=y

Review URL: https://codereview.chromium.org/1104113002

Cr-Commit-Position: refs/heads/master@{#28082}

src/heap/heap-inl.h
test/cctest/test-alloc.cc

index 426e4326331cd84ced6fd02fc02deb00f3f1a912..12c46069eb52ccc9054f075edcff49c62bed5cb4 100644 (file)
@@ -538,10 +538,13 @@ Isolate* Heap::isolate() {
     AllocationResult __allocation__ = FUNCTION_CALL;                          \
     Object* __object__ = NULL;                                                \
     RETURN_OBJECT_UNLESS_RETRY(ISOLATE, RETURN_VALUE)                         \
-    (ISOLATE)->heap()->CollectGarbage(__allocation__.RetrySpace(),            \
-                                      "allocation failure");                  \
-    __allocation__ = FUNCTION_CALL;                                           \
-    RETURN_OBJECT_UNLESS_RETRY(ISOLATE, RETURN_VALUE)                         \
+    /* Two GCs before panicking.  In newspace will almost always succeed. */  \
+    for (int __i__ = 0; __i__ < 2; __i__++) {                                 \
+      (ISOLATE)->heap()->CollectGarbage(__allocation__.RetrySpace(),          \
+                                        "allocation failure");                \
+      __allocation__ = FUNCTION_CALL;                                         \
+      RETURN_OBJECT_UNLESS_RETRY(ISOLATE, RETURN_VALUE)                       \
+    }                                                                         \
     (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment();        \
     (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc");          \
     {                                                                         \
index 66f69f8b574d68ab57147c2f739bc8cb64aef851..74388d1785047b9319a5a521791a3bb14fc98c09 100644 (file)
@@ -38,9 +38,16 @@ using namespace v8::internal;
 static AllocationResult AllocateAfterFailures() {
   static int attempts = 0;
 
-  if (++attempts < 3) return AllocationResult::Retry();
+  // The first 4 times we simulate a full heap, by returning retry.
+  if (++attempts < 4) return AllocationResult::Retry();
+
+  // Expose some private stuff on Heap.
   TestHeap* heap = CcTest::test_heap();
 
+  // Now that we have returned 'retry' 4 times, we are in a last-chance
+  // scenario, with always_allocate.  See CALL_AND_RETRY.  Test that all
+  // allocations succeed.
+
   // New space.
   SimulateFullSpace(heap->new_space());
   heap->AllocateByteArray(100).ToObjectChecked();