[vm, gc] Address TSAN warning on access to PageSpace::phase_.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/49323
Change-Id: I6e98cbd33b69332a01db4fdcceb0b3da164e725e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249760
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/vm/heap/heap.cc b/runtime/vm/heap/heap.cc
index 2b021a0..d8b0c3f 100644
--- a/runtime/vm/heap/heap.cc
+++ b/runtime/vm/heap/heap.cc
@@ -485,9 +485,11 @@
   }
   {
     GcSafepointOperationScope safepoint_operation(thread);
-    if (reason == GCReason::kFinalize &&
-        old_space_.phase() != PageSpace::kAwaitingFinalization) {
-      return;  // Lost race.
+    if (reason == GCReason::kFinalize) {
+      MonitorLocker ml(old_space_.tasks_lock());
+      if (old_space_.phase() != PageSpace::kAwaitingFinalization) {
+        return;  // Lost race.
+      }
     }
 
     thread->isolate_group()->ForEachIsolate(