[heap] Move CALL_HEAP_FUNCTION macro into factory.cc file.
authormstarzinger <mstarzinger@chromium.org>
Mon, 28 Sep 2015 18:08:17 +0000 (11:08 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 28 Sep 2015 18:08:30 +0000 (18:08 +0000)
R=hpayer@chromium.org

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

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

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

index 12d7f5750e3909c37d680b33052e5e38a343c72c..d6dd38d963d6dfeff29c20fe56ff14ca2344ed94 100644 (file)
@@ -15,6 +15,44 @@ namespace v8 {
 namespace internal {
 
 
+// Calls the FUNCTION_CALL function and retries it up to three times
+// to guarantee that any allocations performed during the call will
+// succeed if there's enough memory.
+//
+// Warning: Do not use the identifiers __object__, __maybe_object__,
+// __allocation__ or __scope__ in a call to this macro.
+
+#define RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE)         \
+  if (__allocation__.To(&__object__)) {                   \
+    DCHECK(__object__ != (ISOLATE)->heap()->exception()); \
+    return Handle<TYPE>(TYPE::cast(__object__), ISOLATE); \
+  }
+
+#define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE)                      \
+  do {                                                                        \
+    AllocationResult __allocation__ = FUNCTION_CALL;                          \
+    Object* __object__ = NULL;                                                \
+    RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE)                                 \
+    /* 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, TYPE)                               \
+    }                                                                         \
+    (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment();        \
+    (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc");          \
+    {                                                                         \
+      AlwaysAllocateScope __scope__(ISOLATE);                                 \
+      __allocation__ = FUNCTION_CALL;                                         \
+    }                                                                         \
+    RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE)                                 \
+    /* TODO(1181417): Fix this. */                                            \
+    v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \
+    return Handle<TYPE>();                                                    \
+  } while (false)
+
+
 template<typename T>
 Handle<T> Factory::New(Handle<Map> map, AllocationSpace space) {
   CALL_HEAP_FUNCTION(
index d9031807b3736581ffe6c1fe048b182f45d3005b..3f0676476d95e70f0419681a7ce6e209c5701699 100644 (file)
@@ -537,44 +537,6 @@ Isolate* Heap::isolate() {
 }
 
 
-// Calls the FUNCTION_CALL function and retries it up to three times
-// to guarantee that any allocations performed during the call will
-// succeed if there's enough memory.
-//
-// Warning: Do not use the identifiers __object__, __maybe_object__,
-// __allocation__ or __scope__ in a call to this macro.
-
-#define RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE)         \
-  if (__allocation__.To(&__object__)) {                   \
-    DCHECK(__object__ != (ISOLATE)->heap()->exception()); \
-    return Handle<TYPE>(TYPE::cast(__object__), ISOLATE); \
-  }
-
-#define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE)                      \
-  do {                                                                        \
-    AllocationResult __allocation__ = FUNCTION_CALL;                          \
-    Object* __object__ = NULL;                                                \
-    RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE)                                 \
-    /* 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, TYPE)                               \
-    }                                                                         \
-    (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment();        \
-    (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc");          \
-    {                                                                         \
-      AlwaysAllocateScope __scope__(ISOLATE);                                 \
-      __allocation__ = FUNCTION_CALL;                                         \
-    }                                                                         \
-    RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE)                                 \
-    /* TODO(1181417): Fix this. */                                            \
-    v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \
-    return Handle<TYPE>();                                                    \
-  } while (false)
-
-
 void Heap::ExternalStringTable::AddString(String* string) {
   DCHECK(string->IsExternalString());
   if (heap_->InNewSpace(string)) {
index d7043c2ce5a65b652c3a7666edc15d56a3ccb2e0..b9d0f61ef8e44d8ea41cbe35e853d6090882c521 100644 (file)
@@ -37,18 +37,8 @@ using namespace v8::internal;
 
 
 AllocationResult v8::internal::HeapTester::AllocateAfterFailures() {
-  static int attempts = 0;
-
-  // The first 4 times we simulate a full heap, by returning retry.
-  if (++attempts < 4) return AllocationResult::Retry();
-
-  // Expose some private stuff on Heap.
   Heap* heap = CcTest::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.
   heap->AllocateByteArray(100).ToObjectChecked();
   heap->AllocateFixedArray(100, NOT_TENURED).ToObjectChecked();
@@ -98,7 +88,12 @@ AllocationResult v8::internal::HeapTester::AllocateAfterFailures() {
 
 
 Handle<Object> v8::internal::HeapTester::TestAllocateAfterFailures() {
-  CALL_HEAP_FUNCTION(CcTest::i_isolate(), AllocateAfterFailures(), Object);
+  // Similar to what the CALL_AND_RETRY macro does in the last-resort case, we
+  // are wrapping the allocator function in an AlwaysAllocateScope.  Test that
+  // all allocations succeed immediately without any retry.
+  CcTest::heap()->CollectAllAvailableGarbage("panic");
+  AlwaysAllocateScope scope(CcTest::i_isolate());
+  return handle(AllocateAfterFailures().ToObjectChecked(), CcTest::i_isolate());
 }