Reland "[heap] Move unittests gc helper to heap-utils"

This is a reland of commit 4f38bd596773115f9b6804e68ca76ecc8344b058

Original change's description:
> [heap] Move unittests gc helper to heap-utils
>
> Drive-by: Remove redundant/duplicate helpers
>
> This is mostly a mechanical change.
>
> Change-Id: I7d66f72f0527f0998bddd148949013efe8709da4
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4536815
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Commit-Queue: Omer Katz <omerkatz@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#87921}

Change-Id: I721228ada9d3598caf8664beb5bf5c2204e38f1c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4573632
Auto-Submit: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#87942}
diff --git a/test/unittests/api/api-wasm-unittest.cc b/test/unittests/api/api-wasm-unittest.cc
index fe340d9..4bfb97d 100644
--- a/test/unittests/api/api-wasm-unittest.cc
+++ b/test/unittests/api/api-wasm-unittest.cc
@@ -15,6 +15,7 @@
 #include "src/handles/global-handles.h"
 #include "src/wasm/wasm-features.h"
 #include "test/common/flag-utils.h"
+#include "test/unittests/heap/heap-utils.h"
 #include "test/unittests/test-utils.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -124,7 +125,7 @@
   TestWasmStreaming(WasmStreamingCallbackTestCallbackIsCalled,
                     Promise::kPending);
   CHECK(wasm_streaming_callback_got_called);
-  CollectAllAvailableGarbage();
+  CollectAllAvailableGarbage(i_isolate());
   CHECK(wasm_streaming_data_got_collected);
 }
 
diff --git a/test/unittests/assembler/macro-assembler-x64-unittest.cc b/test/unittests/assembler/macro-assembler-x64-unittest.cc
index 2241cc7..d6a0445 100644
--- a/test/unittests/assembler/macro-assembler-x64-unittest.cc
+++ b/test/unittests/assembler/macro-assembler-x64-unittest.cc
@@ -548,9 +548,9 @@
   CHECK_EQ(old_array->ptr(), result.ptr());
 
   // Collect garbage to ensure reloc info can be walked by the heap.
-  CollectAllGarbage();
-  CollectAllGarbage();
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
+  CollectGarbage(OLD_SPACE);
+  CollectGarbage(OLD_SPACE);
 
   PtrComprCageBase cage_base(isolate);
 
diff --git a/test/unittests/deoptimizer/deoptimization-unittest.cc b/test/unittests/deoptimizer/deoptimization-unittest.cc
index 46dcb89..9dca047 100644
--- a/test/unittests/deoptimizer/deoptimization-unittest.cc
+++ b/test/unittests/deoptimizer/deoptimization-unittest.cc
@@ -149,7 +149,7 @@
         "function f() { g(); };"
         "f();");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   CheckJsInt32(1, "count", context());
 
   CHECK(!GetJSFunction("f")->HasAttachedOptimizedCode());
@@ -164,7 +164,7 @@
         "function f(x) { if (x) { g(); } else { return } };"
         "f(true);");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CheckJsInt32(1, "count", context());
   CHECK(!GetJSFunction("f")->HasAttachedOptimizedCode());
@@ -184,7 +184,7 @@
         "function f(x, y, z) { g(1,x); y+z; };"
         "f(1, \"2\", false);");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CheckJsInt32(1, "count", context());
   CHECK(!GetJSFunction("f")->HasAttachedOptimizedCode());
@@ -200,7 +200,7 @@
         "function f(x, y, z) { if (x) { g(x, y); } else { return y + z; } };"
         "f(true, 1, \"2\");");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CheckJsInt32(1, "count", context());
   CHECK(!GetJSFunction("f")->HasAttachedOptimizedCode());
@@ -221,7 +221,7 @@
         "function g(z) { count++; %DeoptimizeFunction(f); return z;}"
         "function f(x,y,z) { return h(x, y, g(z)); };"
         "result = f(1, 2, 3);");
-    CollectAllGarbage();
+    CollectGarbage(OLD_SPACE);
 
     CheckJsInt32(1, "count", context());
     CheckJsInt32(6, "result", context());
@@ -244,7 +244,7 @@
         "function f(x) { calls++; if (x > 0) { f(x - 1); } else { g(); } };"
         "f(10);");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CheckJsInt32(1, "count", context());
   CheckJsInt32(11, "calls", context());
@@ -274,7 +274,7 @@
         "function f1(x) { return f2(x + 1, x + 1) + x; };"
         "result = f1(1);");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CheckJsInt32(1, "count", context());
   CheckJsInt32(14, "result", context());
@@ -293,7 +293,7 @@
         "function f() {  g(); };"
         "result = new f() instanceof f;");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CheckJsInt32(1, "count", context());
   CHECK(context()
@@ -313,7 +313,7 @@
         "result = new f(1, 2);"
         "result = result.x + result.y;");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CheckJsInt32(1, "count", context());
   CheckJsInt32(3, "result", context());
@@ -340,7 +340,7 @@
         "function f1(x) { this.result = new f2(x + 1, x + 1).result + x; };"
         "result = new f1(1).result;");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CheckJsInt32(1, "count", context());
   CheckJsInt32(14, "result", context());
@@ -389,7 +389,7 @@
     RunJS(
         "deopt = true;"
         "var result = f(7, new X());");
-    CollectAllGarbage();
+    CollectGarbage(OLD_SPACE);
     CHECK(!GetJSFunction("f")->HasAttachedOptimizedCode());
   }
 };
@@ -433,7 +433,7 @@
         "deopt = true;"
         "var result = f('a+', new X());");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CHECK(!GetJSFunction("f")->HasAttachedOptimizedCode());
   CheckJsInt32(1, "count", context());
@@ -537,7 +537,7 @@
         "deopt = true;"
         "var result = f('a', new X());");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CHECK(!GetJSFunction("f")->HasAttachedOptimizedCode());
   CheckJsInt32(1, "count", context());
@@ -621,7 +621,7 @@
         "f2(new X(), 'z');"
         "g2(new X(), 'z');");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CHECK(!GetJSFunction("f1")->HasAttachedOptimizedCode());
   CHECK(!GetJSFunction("g1")->HasAttachedOptimizedCode());
@@ -704,7 +704,7 @@
         "deopt = true;"
         "var result = f1(new X());");
   }
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 
   CHECK(!GetJSFunction("f1")->HasAttachedOptimizedCode());
   CHECK(!GetJSFunction("g1")->HasAttachedOptimizedCode());
diff --git a/test/unittests/heap/cppgc-js/embedder-roots-handler-unittest.cc b/test/unittests/heap/cppgc-js/embedder-roots-handler-unittest.cc
index 82432b5..4110cd0 100644
--- a/test/unittests/heap/cppgc-js/embedder-roots-handler-unittest.cc
+++ b/test/unittests/heap/cppgc-js/embedder-roots-handler-unittest.cc
@@ -134,7 +134,7 @@
   SetupOptimizedAndNonOptimizedHandle(v8_isolate(), kClassIdToOptimize,
                                       optimized_handle, non_optimized_handle);
   EXPECT_EQ(initial_count + 2, traced_handles->used_node_count());
-  YoungGC();
+  CollectGarbage(NEW_SPACE);
   EXPECT_EQ(initial_count + 1, traced_handles->used_node_count());
   EXPECT_TRUE(optimized_handle->IsEmpty());
   delete optimized_handle;
@@ -220,8 +220,8 @@
   TemporaryEmbedderRootsHandleScope roots_handler_scope(v8_isolate(), &handler);
   TracedReferenceTest(
       v8_isolate(), ConstructJSObject,
-      [](const TracedReference<v8::Object>&) {}, [this]() { FullGC(); },
-      SurvivalMode::kDies);
+      [](const TracedReference<v8::Object>&) {},
+      [this]() { CollectGarbage(OLD_SPACE); }, SurvivalMode::kDies);
 }
 
 // EmbedderRootsHandler does not affect full GCs.
@@ -242,7 +242,7 @@
             v8::Global<v8::Object>(v8_isolate(), handle.Get(v8_isolate()));
       },
       [this, &strong_global]() {
-        FullGC();
+        CollectGarbage(OLD_SPACE);
         strong_global.Reset();
       },
       SurvivalMode::kDies);
@@ -258,8 +258,8 @@
   TemporaryEmbedderRootsHandleScope roots_handler_scope(v8_isolate(), &handler);
   TracedReferenceTest(
       v8_isolate(), ConstructJSObject,
-      [](const TracedReference<v8::Object>&) {}, [this]() { YoungGC(); },
-      SurvivalMode::kSurvives);
+      [](const TracedReference<v8::Object>&) {},
+      [this]() { CollectGarbage(NEW_SPACE); }, SurvivalMode::kSurvives);
 }
 
 // EmbedderRootsHandler does not affect non-API objects, even when the handle
@@ -277,7 +277,7 @@
       [](TracedReference<v8::Object>& handle) {
         handle.SetWrapperClassId(kClassIdToOptimize);
       },
-      [this]() { YoungGC(); }, SurvivalMode::kSurvives);
+      [this]() { CollectGarbage(NEW_SPACE); }, SurvivalMode::kSurvives);
 }
 
 // EmbedderRootsHandler does not affect API objects for handles that have
@@ -291,8 +291,8 @@
   TemporaryEmbedderRootsHandleScope roots_handler_scope(v8_isolate(), &handler);
   TracedReferenceTest(
       v8_isolate(), ConstructJSApiObject<TracedReference<v8::Object>>,
-      [](const TracedReference<v8::Object>&) {}, [this]() { YoungGC(); },
-      SurvivalMode::kSurvives);
+      [](const TracedReference<v8::Object>&) {},
+      [this]() { CollectGarbage(NEW_SPACE); }, SurvivalMode::kSurvives);
 }
 
 // EmbedderRootsHandler resets API objects for handles that have their class ids
@@ -315,7 +315,7 @@
           local->SetAlignedPointerInInternalField(0, &handle);
         }
       },
-      [this]() { YoungGC(); }, SurvivalMode::kDies);
+      [this]() { CollectGarbage(NEW_SPACE); }, SurvivalMode::kDies);
 }
 
 // Test that concurrently processed handles are reprocessed on the main thread.
@@ -350,7 +350,7 @@
     }
   }
 
-  YoungGC();
+  CollectGarbage(NEW_SPACE);
 
   EXPECT_TRUE(handler.unprocessed().empty());
 }
diff --git a/test/unittests/heap/cppgc-js/unified-heap-unittest.cc b/test/unittests/heap/cppgc-js/unified-heap-unittest.cc
index b3ea81c..72f40ac 100644
--- a/test/unittests/heap/cppgc-js/unified-heap-unittest.cc
+++ b/test/unittests/heap/cppgc-js/unified-heap-unittest.cc
@@ -439,7 +439,7 @@
     observer.SetWeak();
   }
   EXPECT_FALSE(observer.IsEmpty());
-  FullGC();
+  CollectGarbage(OLD_SPACE);
   EXPECT_FALSE(observer.IsEmpty());
 }
 
@@ -478,6 +478,7 @@
 
 V8_NOINLINE void StackToHeapTest(v8::Isolate* v8_isolate, Operation op,
                                  TargetHandling target_handling) {
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
   v8::Global<v8::Object> observer;
   v8::TracedReference<v8::Value> stack_handle;
   v8::CppHeap* cpp_heap = v8_isolate->GetCppHeap();
@@ -492,7 +493,7 @@
         IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
     if (!v8_flags.single_generation &&
         target_handling == TargetHandling::kInitializedOldGen) {
-      FullGC(v8_isolate);
+      CollectGarbage(OLD_SPACE, i_isolate);
       EXPECT_FALSE(
           i::Heap::InYoungGeneration(*v8::Utils::OpenHandle(*to_object)));
     }
@@ -507,10 +508,10 @@
     observer.SetWeak();
   }
   EXPECT_FALSE(observer.IsEmpty());
-  FullGC(v8_isolate);
+  CollectGarbage(OLD_SPACE, i_isolate);
   EXPECT_FALSE(observer.IsEmpty());
   PerformOperation(op, &cpp_heap_obj->heap_handle, &stack_handle);
-  FullGC(v8_isolate);
+  CollectGarbage(OLD_SPACE, i_isolate);
   EXPECT_FALSE(observer.IsEmpty());
   cpp_heap_obj.Clear();
   {
@@ -518,13 +519,14 @@
     // Disable scanning, assuming the slots are overwritten.
     DisableConservativeStackScanningScopeForTesting no_stack_scanning(
         reinterpret_cast<i::Isolate*>(v8_isolate)->heap());
-    FullGC(v8_isolate);
+    CollectGarbage(OLD_SPACE, i_isolate);
   }
   ASSERT_TRUE(observer.IsEmpty());
 }
 
 V8_NOINLINE void HeapToStackTest(v8::Isolate* v8_isolate, Operation op,
                                  TargetHandling target_handling) {
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
   v8::Global<v8::Object> observer;
   v8::TracedReference<v8::Value> stack_handle;
   v8::CppHeap* cpp_heap = v8_isolate->GetCppHeap();
@@ -539,7 +541,7 @@
         IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
     if (!v8_flags.single_generation &&
         target_handling == TargetHandling::kInitializedOldGen) {
-      FullGC(v8_isolate);
+      CollectGarbage(OLD_SPACE, i_isolate);
       EXPECT_FALSE(
           i::Heap::InYoungGeneration(*v8::Utils::OpenHandle(*to_object)));
     }
@@ -554,10 +556,10 @@
     observer.SetWeak();
   }
   EXPECT_FALSE(observer.IsEmpty());
-  FullGC(v8_isolate);
+  CollectGarbage(OLD_SPACE, i_isolate);
   EXPECT_FALSE(observer.IsEmpty());
   PerformOperation(op, &stack_handle, &cpp_heap_obj->heap_handle);
-  FullGC(v8_isolate);
+  CollectGarbage(OLD_SPACE, i_isolate);
   EXPECT_FALSE(observer.IsEmpty());
   stack_handle.Reset();
   {
@@ -565,13 +567,14 @@
     // Disable scanning, assuming the slots are overwritten.
     DisableConservativeStackScanningScopeForTesting no_stack_scanning(
         reinterpret_cast<i::Isolate*>(v8_isolate)->heap());
-    FullGC(v8_isolate);
+    CollectGarbage(OLD_SPACE, i_isolate);
   }
   EXPECT_TRUE(observer.IsEmpty());
 }
 
 V8_NOINLINE void StackToStackTest(v8::Isolate* v8_isolate, Operation op,
                                   TargetHandling target_handling) {
+  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
   v8::Global<v8::Object> observer;
   v8::TracedReference<v8::Value> stack_handle1;
   v8::TracedReference<v8::Value> stack_handle2;
@@ -583,7 +586,7 @@
         IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
     if (!v8_flags.single_generation &&
         target_handling == TargetHandling::kInitializedOldGen) {
-      FullGC(v8_isolate);
+      CollectGarbage(OLD_SPACE, i_isolate);
       EXPECT_FALSE(
           i::Heap::InYoungGeneration(*v8::Utils::OpenHandle(*to_object)));
     }
@@ -598,10 +601,10 @@
     observer.SetWeak();
   }
   EXPECT_FALSE(observer.IsEmpty());
-  FullGC(v8_isolate);
+  CollectGarbage(OLD_SPACE, i_isolate);
   EXPECT_FALSE(observer.IsEmpty());
   PerformOperation(op, &stack_handle2, &stack_handle1);
-  FullGC(v8_isolate);
+  CollectGarbage(OLD_SPACE, i_isolate);
   EXPECT_FALSE(observer.IsEmpty());
   stack_handle2.Reset();
   {
@@ -609,7 +612,7 @@
     // Disable scanning, assuming the slots are overwritten.
     DisableConservativeStackScanningScopeForTesting no_stack_scanning(
         reinterpret_cast<i::Isolate*>(v8_isolate)->heap());
-    FullGC(v8_isolate);
+    CollectGarbage(OLD_SPACE, i_isolate);
   }
   EXPECT_TRUE(observer.IsEmpty());
 }
diff --git a/test/unittests/heap/global-handles-unittest.cc b/test/unittests/heap/global-handles-unittest.cc
index 0789f67..97af61b 100644
--- a/test/unittests/heap/global-handles-unittest.cc
+++ b/test/unittests/heap/global-handles-unittest.cc
@@ -216,7 +216,7 @@
     CHECK(!eternals[i].IsEmpty());
   }
 
-  CollectAllAvailableGarbage();
+  CollectAllAvailableGarbage(isolate);
 
   for (int i = 0; i < kArrayLength; i++) {
     for (int j = 0; j < 2; j++) {
@@ -294,7 +294,7 @@
   }
   CHECK(!g1.IsEmpty());
   CHECK(!g2.IsEmpty());
-  CollectAllAvailableGarbage();
+  CollectAllAvailableGarbage(i_isolate());
   CHECK(g1.IsEmpty());
   CHECK(g2.IsEmpty());
 }
@@ -328,7 +328,7 @@
 
   WeakHandleTest(
       v8_isolate(), &ConstructJSObject<FlagAndHandles>,
-      [](FlagAndHandles* fp) {}, [this]() { CollectAllGarbage(); },
+      [](FlagAndHandles* fp) {}, [this]() { CollectGarbage(OLD_SPACE); },
       SurvivalMode::kDies);
 }
 
@@ -339,7 +339,7 @@
       [this](FlagAndHandles* fp) {
         fp->local = v8::Local<v8::Object>::New(v8_isolate(), fp->handle);
       },
-      [this]() { CollectAllGarbage(); }, SurvivalMode::kSurvives);
+      [this]() { CollectGarbage(OLD_SPACE); }, SurvivalMode::kSurvives);
 }
 
 TEST_F(GlobalHandlesTest, WeakHandleToUnmodifiedJSApiObjectDiesOnScavenge) {
@@ -406,7 +406,7 @@
 
   WeakHandleTest(
       v8_isolate(), &ConstructJSApiObject<FlagAndHandles>,
-      [](FlagAndHandles* fp) {}, [this]() { CollectAllGarbage(); },
+      [](FlagAndHandles* fp) {}, [this]() { CollectGarbage(OLD_SPACE); },
       SurvivalMode::kDies);
 }
 
@@ -417,7 +417,7 @@
       [this](FlagAndHandles* fp) {
         fp->local = v8::Local<v8::Object>::New(v8_isolate(), fp->handle);
       },
-      [this]() { CollectAllGarbage(); }, SurvivalMode::kSurvives);
+      [this]() { CollectGarbage(OLD_SPACE); }, SurvivalMode::kSurvives);
 }
 
 TEST_F(GlobalHandlesTest,
@@ -468,24 +468,24 @@
 
 namespace {
 
-void ForceScavenge2(const v8::WeakCallbackInfo<FlagAndHandles>& data) {
+void ForceMinorGC2(const v8::WeakCallbackInfo<FlagAndHandles>& data) {
   data.GetParameter()->flag = true;
-  YoungGC(data.GetIsolate());
+  CollectGarbage(NEW_SPACE, reinterpret_cast<Isolate*>(data.GetIsolate()));
 }
 
-void ForceScavenge1(const v8::WeakCallbackInfo<FlagAndHandles>& data) {
+void ForceMinorGC1(const v8::WeakCallbackInfo<FlagAndHandles>& data) {
   data.GetParameter()->handle.Reset();
-  data.SetSecondPassCallback(ForceScavenge2);
+  data.SetSecondPassCallback(ForceMinorGC2);
 }
 
-void ForceMarkSweep2(const v8::WeakCallbackInfo<FlagAndHandles>& data) {
+void ForceMajorGC2(const v8::WeakCallbackInfo<FlagAndHandles>& data) {
   data.GetParameter()->flag = true;
-  FullGC(data.GetIsolate());
+  CollectGarbage(OLD_SPACE, reinterpret_cast<Isolate*>(data.GetIsolate()));
 }
 
-void ForceMarkSweep1(const v8::WeakCallbackInfo<FlagAndHandles>& data) {
+void ForceMajorGC1(const v8::WeakCallbackInfo<FlagAndHandles>& data) {
   data.GetParameter()->handle.Reset();
-  data.SetSecondPassCallback(ForceMarkSweep2);
+  data.SetSecondPassCallback(ForceMajorGC2);
 }
 
 }  // namespace
@@ -504,8 +504,8 @@
     CHECK_IMPLIES(!v8_flags.single_generation,
                   !InYoungGeneration(isolate, fp.handle));
     fp.flag = false;
-    fp.handle.SetWeak(&fp, &ForceMarkSweep1, v8::WeakCallbackType::kParameter);
-    CollectAllGarbage();
+    fp.handle.SetWeak(&fp, &ForceMajorGC1, v8::WeakCallbackType::kParameter);
+    CollectGarbage(OLD_SPACE);
     EmptyMessageQueues();
     CHECK(fp.flag);
     return;
@@ -513,13 +513,13 @@
 
   static const int kNumberOfGCTypes = 2;
   using Callback = v8::WeakCallbackInfo<FlagAndHandles>::Callback;
-  Callback gc_forcing_callback[kNumberOfGCTypes] = {&ForceScavenge1,
-                                                    &ForceMarkSweep1};
+  Callback gc_forcing_callback[kNumberOfGCTypes] = {&ForceMinorGC1,
+                                                    &ForceMajorGC1};
 
   using GCInvoker = std::function<void(void)>;
   GCInvoker invoke_gc[kNumberOfGCTypes] = {
       [this]() { CollectGarbage(i::NEW_SPACE); },
-      [this]() { CollectAllGarbage(); }};
+      [this]() { CollectGarbage(OLD_SPACE); }};
 
   for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
     for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
@@ -561,8 +561,8 @@
   fp.flag = false;
   fp.handle.SetWeak(&fp, FirstPassCallback, v8::WeakCallbackType::kParameter);
   CHECK(!fp.flag);
-  CollectAllGarbage();
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
+  CollectGarbage(OLD_SPACE);
   CHECK(fp.flag);
 }
 
@@ -572,10 +572,10 @@
 
   v8::Global<v8::Object>* global = new Global<v8::Object>();
   ConstructJSObject(isolate, global);
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   v8::Global<v8::Object> global2(std::move(*global));
   delete global;
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 }
 
 TEST_F(GlobalHandlesTest, MoveWeakGlobal) {
@@ -584,11 +584,11 @@
 
   v8::Global<v8::Object>* global = new Global<v8::Object>();
   ConstructJSObject(isolate, global);
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   global->SetWeak();
   v8::Global<v8::Object> global2(std::move(*global));
   delete global;
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
 }
 
 TEST_F(GlobalHandlesTest, TotalSizeRegularNode) {
@@ -618,7 +618,7 @@
   CHECK_GT(i_isolate()->traced_handles()->total_size_bytes(), 0);
   CHECK_GT(i_isolate()->traced_handles()->used_size_bytes(), 0);
   delete handle;
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   CHECK_GT(i_isolate()->traced_handles()->total_size_bytes(), 0);
   CHECK_EQ(i_isolate()->traced_handles()->used_size_bytes(), 0);
 }
diff --git a/test/unittests/heap/heap-utils.h b/test/unittests/heap/heap-utils.h
index 41ed1b3..6dbb6ea 100644
--- a/test/unittests/heap/heap-utils.h
+++ b/test/unittests/heap/heap-utils.h
@@ -25,6 +25,20 @@
                        std::vector<Handle<FixedArray>>* out_handles = nullptr);
 };
 
+inline void CollectGarbage(AllocationSpace space, Isolate* isolate) {
+  isolate->heap()->CollectGarbage(space, GarbageCollectionReason::kTesting);
+}
+
+inline void CollectAllAvailableGarbage(Isolate* isolate) {
+  isolate->heap()->CollectAllAvailableGarbage(
+      GarbageCollectionReason::kTesting);
+}
+
+inline void PreciseCollectAllGarbage(Isolate* isolate) {
+  isolate->heap()->PreciseCollectAllGarbage(GCFlag::kNoFlags,
+                                            GarbageCollectionReason::kTesting);
+}
+
 template <typename TMixin>
 class WithHeapInternals : public TMixin, HeapInternalsBase {
  public:
@@ -36,18 +50,20 @@
     heap()->CollectGarbage(space, GarbageCollectionReason::kTesting);
   }
 
-  void FullGC() {
-    heap()->CollectGarbage(OLD_SPACE, GarbageCollectionReason::kTesting);
-  }
-
-  void YoungGC() {
-    heap()->CollectGarbage(NEW_SPACE, GarbageCollectionReason::kTesting);
+  void CollectAllGarbage() {
+    heap()->CollectAllGarbage(GCFlag::kNoFlags,
+                              GarbageCollectionReason::kTesting);
   }
 
   void CollectAllAvailableGarbage() {
     heap()->CollectAllAvailableGarbage(GarbageCollectionReason::kTesting);
   }
 
+  void PreciseCollectAllGarbage() {
+    heap()->PreciseCollectAllGarbage(GCFlag::kNoFlags,
+                                     GarbageCollectionReason::kTesting);
+  }
+
   Heap* heap() const { return this->i_isolate()->heap(); }
 
   void SimulateIncrementalMarking(bool force_completion = true) {
@@ -78,8 +94,8 @@
     // test: v8_flags.stress_concurrent_allocation = false; Background thread
     // allocating concurrently interferes with this function.
     CHECK(!v8_flags.stress_concurrent_allocation);
-    FullGC();
-    FullGC();
+    CollectGarbage(OLD_SPACE);
+    CollectGarbage(OLD_SPACE);
     heap()->EnsureSweepingCompleted(
         Heap::SweepingForcedFinalizationMode::kV8Only);
     heap()->old_space()->FreeLinearAllocationArea();
@@ -112,21 +128,6 @@
     WithContextMixin<                    //
         TestWithHeapInternals>;
 
-inline void CollectGarbage(AllocationSpace space, v8::Isolate* isolate) {
-  Heap* heap = reinterpret_cast<i::Isolate*>(isolate)->heap();
-  heap->CollectGarbage(space, GarbageCollectionReason::kTesting);
-}
-
-inline void FullGC(v8::Isolate* isolate) {
-  Heap* heap = reinterpret_cast<i::Isolate*>(isolate)->heap();
-  heap->CollectAllGarbage(GCFlag::kNoFlags, GarbageCollectionReason::kTesting);
-}
-
-inline void YoungGC(v8::Isolate* isolate) {
-  Heap* heap = reinterpret_cast<i::Isolate*>(isolate)->heap();
-  heap->CollectGarbage(NEW_SPACE, GarbageCollectionReason::kTesting);
-}
-
 template <typename GlobalOrPersistent>
 bool InYoungGeneration(v8::Isolate* isolate, const GlobalOrPersistent& global) {
   CHECK(!v8_flags.single_generation);
diff --git a/test/unittests/heap/local-handles-unittest.cc b/test/unittests/heap/local-handles-unittest.cc
index 0f23703..a868cc2 100644
--- a/test/unittests/heap/local-handles-unittest.cc
+++ b/test/unittests/heap/local-handles-unittest.cc
@@ -90,7 +90,7 @@
 
   sema_started.Wait();
 
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   sema_gc_finished.Signal();
 
   thread->Join();
diff --git a/test/unittests/heap/local-heap-unittest.cc b/test/unittests/heap/local-heap-unittest.cc
index cbbdeb1..6292354 100644
--- a/test/unittests/heap/local-heap-unittest.cc
+++ b/test/unittests/heap/local-heap-unittest.cc
@@ -9,6 +9,7 @@
 #include "src/heap/heap.h"
 #include "src/heap/parked-scope.h"
 #include "src/heap/safepoint.h"
+#include "test/unittests/heap/heap-utils.h"
 #include "test/unittests/test-utils.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
diff --git a/test/unittests/heap/persistent-handles-unittest.cc b/test/unittests/heap/persistent-handles-unittest.cc
index 3e36461..569bcac 100644
--- a/test/unittests/heap/persistent-handles-unittest.cc
+++ b/test/unittests/heap/persistent-handles-unittest.cc
@@ -189,7 +189,7 @@
 
   sema_started.Wait();
 
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   sema_gc_finished.Signal();
 
   thread->Join();
diff --git a/test/unittests/heap/shared-heap-unittest.cc b/test/unittests/heap/shared-heap-unittest.cc
index f53b9bd..17afef8 100644
--- a/test/unittests/heap/shared-heap-unittest.cc
+++ b/test/unittests/heap/shared-heap-unittest.cc
@@ -65,7 +65,7 @@
                 10, AllocationType::kSharedOld);
           }
 
-          CollectGarbage(OLD_SPACE, client_isolate);
+          CollectGarbage(OLD_SPACE, i_client_isolate);
 
           v8::platform::PumpMessageLoop(i::V8::GetCurrentPlatform(),
                                         client_isolate);
@@ -110,7 +110,7 @@
             CHECK(MemoryChunk::FromHeapObject(*fixed_array)->IsLargePage());
           }
 
-          CollectGarbage(OLD_SPACE, client_isolate);
+          CollectGarbage(OLD_SPACE, i_client_isolate);
 
           v8::platform::PumpMessageLoop(i::V8::GetCurrentPlatform(),
                                         client_isolate);
@@ -151,7 +151,7 @@
                 TERMINAL_FAST_ELEMENTS_KIND, 0, AllocationType::kSharedMap);
           }
 
-          CollectGarbage(OLD_SPACE, client_isolate);
+          CollectGarbage(OLD_SPACE, i_client_isolate);
 
           v8::platform::PumpMessageLoop(i::V8::GetCurrentPlatform(),
                                         client_isolate);
@@ -175,7 +175,7 @@
 }
 
 TEST_F(SharedHeapNoClientsTest, SharedCollectionWithoutClients) {
-  ::v8::internal::CollectGarbage(OLD_SPACE, shared_space_isolate());
+  ::v8::internal::CollectGarbage(OLD_SPACE, i_shared_space_isolate());
 }
 
 void AllocateInSharedHeap(int iterations = 100) {
@@ -458,10 +458,10 @@
   });
 
   test->with_execute(
-      [](TestType* test) { i::CollectGarbage(space, test->v8_isolate()); });
+      [](TestType* test) { i::CollectGarbage(space, test->i_isolate()); });
 
   thread->with_execute([](ThreadType* thread) {
-    i::CollectGarbage(space, thread->client_isolate());
+    i::CollectGarbage(space, thread->i_client_isolate());
   });
 
   test->with_complete([](TestType* test) {
@@ -473,12 +473,12 @@
     // The handle should keep the fixed array from being reclaimed.
     EXPECT_FALSE(thread->state()->weak.IsEmpty());
     thread->state()->scope.reset();  // Deallocate the handle scope.
-    i::CollectGarbage(space, thread->client_isolate());
+    i::CollectGarbage(space, thread->i_client_isolate());
   });
 
   test->with_teardown([](TestType* test) {
     test->state()->scope.reset();  // Deallocate the handle scope.
-    i::CollectGarbage(space, test->v8_isolate());
+    i::CollectGarbage(space, test->i_isolate());
   });
 
   // Perform the test.
@@ -567,10 +567,10 @@
   });
 
   test->with_execute(
-      [](TestType* test) { i::CollectGarbage(space, test->v8_isolate()); });
+      [](TestType* test) { i::CollectGarbage(space, test->i_isolate()); });
 
   thread->with_execute([](ThreadType* thread) {
-    i::CollectGarbage(space, thread->client_isolate());
+    i::CollectGarbage(space, thread->i_client_isolate());
   });
 
   test->with_complete([](TestType* test) {
@@ -583,11 +583,11 @@
     // With conservative stack scanning, the raw pointer should keep the fixed
     // array from being reclaimed.
     EXPECT_FALSE(thread->state()->weak.IsEmpty());
-    i::CollectGarbage(space, thread->client_isolate());
+    i::CollectGarbage(space, thread->i_client_isolate());
   });
 
   test->with_teardown(
-      [](TestType* test) { i::CollectGarbage(space, test->v8_isolate()); });
+      [](TestType* test) { i::CollectGarbage(space, test->i_isolate()); });
 
   // Perform the test.
   test->Interact();
diff --git a/test/unittests/inspector/inspector-unittest.cc b/test/unittests/inspector/inspector-unittest.cc
index ec70f06..aa5350a 100644
--- a/test/unittests/inspector/inspector-unittest.cc
+++ b/test/unittests/inspector/inspector-unittest.cc
@@ -300,14 +300,14 @@
     CHECK(!result.IsEmpty());
 
     // Run GC and check that the task is still here.
-    CollectAllGarbage();
+    CollectGarbage(OLD_SPACE);
     CHECK_EQ(console->AllConsoleTasksForTest().size(), 1);
   }
 
   // Get rid of the task on the context, run GC and check we no longer have
   // the TaskInfo in the inspector.
   v8_context()->Global()->Delete(v8_context(), NewString("task")).Check();
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   CHECK_EQ(console->AllConsoleTasksForTest().size(), 0);
 }
 
diff --git a/test/unittests/libplatform/single-threaded-default-platform-unittest.cc b/test/unittests/libplatform/single-threaded-default-platform-unittest.cc
index f6ef983..d4cefa1 100644
--- a/test/unittests/libplatform/single-threaded-default-platform-unittest.cc
+++ b/test/unittests/libplatform/single-threaded-default-platform-unittest.cc
@@ -4,6 +4,7 @@
 
 #include "include/v8-platform.h"
 #include "src/init/v8.h"
+#include "test/unittests/heap/heap-utils.h"
 #include "test/unittests/test-utils.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -63,8 +64,8 @@
         "f();");
   }
 
-  CollectGarbage(i::NEW_SPACE);
-  CollectAllAvailableGarbage();
+  CollectGarbage(i::NEW_SPACE, i_isolate());
+  CollectAllAvailableGarbage(i_isolate());
 }
 
 }  // namespace v8
diff --git a/test/unittests/objects/feedback-vector-unittest.cc b/test/unittests/objects/feedback-vector-unittest.cc
index c9eedf2..37d250a 100644
--- a/test/unittests/objects/feedback-vector-unittest.cc
+++ b/test/unittests/objects/feedback-vector-unittest.cc
@@ -167,7 +167,7 @@
   CHECK_EQ(InlineCacheState::GENERIC, nexus.ic_state());
 
   // After a collection, state should remain GENERIC.
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   CHECK_EQ(InlineCacheState::GENERIC, nexus.ic_state());
 }
 
@@ -237,7 +237,7 @@
   CHECK(nexus.GetFeedback()->GetHeapObjectIfWeak(&heap_object));
   CHECK_EQ(*foo, heap_object);
 
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   // It should stay monomorphic even after a GC.
   CHECK_EQ(InlineCacheState::MONOMORPHIC, nexus.ic_state());
 }
@@ -297,7 +297,7 @@
   CHECK(nexus.GetFeedback()->GetHeapObjectIfWeak(&heap_object));
   CHECK_EQ(*isolate->array_function(), heap_object);
 
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   // It should stay monomorphic even after a GC.
   CHECK_EQ(InlineCacheState::MONOMORPHIC, nexus.ic_state());
 }
@@ -484,7 +484,7 @@
   CHECK(nexus.GetFirstMap().is_null());
 
   // After a collection, state should not be reset to PREMONOMORPHIC.
-  CollectAllGarbage();
+  CollectGarbage(OLD_SPACE);
   CHECK_EQ(InlineCacheState::MEGAMORPHIC, nexus.ic_state());
 }
 
diff --git a/test/unittests/objects/managed-unittest.cc b/test/unittests/objects/managed-unittest.cc
index 66cd652..bb38570 100644
--- a/test/unittests/objects/managed-unittest.cc
+++ b/test/unittests/objects/managed-unittest.cc
@@ -8,6 +8,7 @@
 
 #include "src/objects/managed-inl.h"
 #include "src/objects/objects-inl.h"
+#include "test/unittests/heap/heap-utils.h"
 #include "test/unittests/test-utils.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -41,7 +42,7 @@
 
   // We need to invoke GC without stack, otherwise the objects may survive.
   DisableConservativeStackScanningScopeForTesting scope(isolate()->heap());
-  CollectAllAvailableGarbage();
+  CollectAllAvailableGarbage(isolate());
 
   CHECK_EQ(1, deleted1);
   CHECK_EQ(0, deleted2);
diff --git a/test/unittests/objects/symbols-unittest.cc b/test/unittests/objects/symbols-unittest.cc
index ca94c26..d30ae69 100644
--- a/test/unittests/objects/symbols-unittest.cc
+++ b/test/unittests/objects/symbols-unittest.cc
@@ -65,7 +65,7 @@
   }
 
   CollectGarbage(i::NEW_SPACE);
-  CollectAllGarbage();
+  CollectGarbage(i::OLD_SPACE);
 
   // All symbols should be distinct.
   for (int i = 0; i < kNumSymbols; ++i) {
diff --git a/test/unittests/test-utils.h b/test/unittests/test-utils.h
index 16a6192..1a278ae 100644
--- a/test/unittests/test-utils.h
+++ b/test/unittests/test-utils.h
@@ -212,24 +212,6 @@
     iso->heap()->CollectGarbage(space, i::GarbageCollectionReason::kTesting);
   }
 
-  void CollectAllGarbage(i::Isolate* isolate = nullptr) {
-    i::Isolate* iso = isolate ? isolate : i_isolate();
-    iso->heap()->CollectAllGarbage(i::GCFlag::kNoFlags,
-                                   i::GarbageCollectionReason::kTesting);
-  }
-
-  void CollectAllAvailableGarbage(i::Isolate* isolate = nullptr) {
-    i::Isolate* iso = isolate ? isolate : i_isolate();
-    iso->heap()->CollectAllAvailableGarbage(
-        i::GarbageCollectionReason::kTesting);
-  }
-
-  void PreciseCollectAllGarbage(i::Isolate* isolate = nullptr) {
-    i::Isolate* iso = isolate ? isolate : i_isolate();
-    iso->heap()->PreciseCollectAllGarbage(i::GCFlag::kNoFlags,
-                                          i::GarbageCollectionReason::kTesting);
-  }
-
   v8::Local<v8::String> NewString(const char* string) {
     return v8::String::NewFromUtf8(this->v8_isolate(), string).ToLocalChecked();
   }