[heap] Add safepoints in Heap GC methods

Add safepoints to GC methods in Heap. There is still stuff in
Heap::CollectGarbage which might work better or more precise in a global
safepoint. Be conservative here and move everything into the safepoint,
eventually we can start to move code out that is fine to run outside
the safepoint.

Bug: v8:10315
Change-Id: I656dfd72f032eff6f386cec63a02777506650aa7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2335192
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69228}
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 73ac5d0..6da4349 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -1268,6 +1268,8 @@
 
 void Heap::CollectAllGarbage(int flags, GarbageCollectionReason gc_reason,
                              const v8::GCCallbackFlags gc_callback_flags) {
+  SafepointScope scope(this);
+
   // Since we are ignoring the return value, the exact choice of space does
   // not matter, so long as we do not specify NEW_SPACE, which would not
   // cause a full GC.
@@ -1337,6 +1339,8 @@
 }  // anonymous namespace
 
 void Heap::CollectAllAvailableGarbage(GarbageCollectionReason gc_reason) {
+  SafepointScope scope(this);
+
   // Since we are ignoring the return value, the exact choice of space does
   // not matter, so long as we do not specify NEW_SPACE, which would not
   // cause a full GC.
@@ -1486,6 +1490,7 @@
 bool Heap::CollectGarbage(AllocationSpace space,
                           GarbageCollectionReason gc_reason,
                           const v8::GCCallbackFlags gc_callback_flags) {
+  SafepointScope scope(this);
   const char* collector_reason = nullptr;
   GarbageCollector collector = SelectGarbageCollector(space, &collector_reason);
   is_current_gc_forced_ = gc_callback_flags & v8::kGCCallbackFlagForced ||