[vm, gc] Ensure PageSpace::heap_ is never null.

TEST=ci
Change-Id: I65753a62a9e02890555fbceb7870e5189032d282
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/314300
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
diff --git a/runtime/vm/heap/heap_sources.gni b/runtime/vm/heap/heap_sources.gni
index a2afa19..9009a1b 100644
--- a/runtime/vm/heap/heap_sources.gni
+++ b/runtime/vm/heap/heap_sources.gni
@@ -42,7 +42,6 @@
   "become_test.cc",
   "freelist_test.cc",
   "heap_test.cc",
-  "pages_test.cc",
   "weak_table_test.cc",
   "safepoint_test.cc",
 ]
diff --git a/runtime/vm/heap/pages.cc b/runtime/vm/heap/pages.cc
index 230130c..12a35d3 100644
--- a/runtime/vm/heap/pages.cc
+++ b/runtime/vm/heap/pages.cc
@@ -77,6 +77,8 @@
       collections_(0),
       mark_words_per_micro_(kConservativeInitialMarkSpeed),
       enable_concurrent_mark_(FLAG_concurrent_mark) {
+  ASSERT(heap != nullptr);
+
   // We aren't holding the lock but no one can reference us yet.
   UpdateMaxCapacityLocked();
   UpdateMaxUsed();
@@ -326,10 +328,8 @@
 
   if (growth_policy != kForceGrowth) {
     ASSERT(!Thread::Current()->force_growth());
-    if (heap_ != nullptr) {  // Some unit tests.
-      heap_->CheckConcurrentMarking(Thread::Current(), GCReason::kOldSpace,
-                                    kPageSize);
-    }
+    heap_->CheckConcurrentMarking(Thread::Current(), GCReason::kOldSpace,
+                                  kPageSize);
   }
 
   uword result = 0;
@@ -368,10 +368,7 @@
 
   if (growth_policy != kForceGrowth) {
     ASSERT(!Thread::Current()->force_growth());
-    if (heap_ != nullptr) {  // Some unit tests.
-      heap_->CheckConcurrentMarking(Thread::Current(), GCReason::kOldSpace,
-                                    size);
-    }
+    heap_->CheckConcurrentMarking(Thread::Current(), GCReason::kOldSpace, size);
   }
 
   intptr_t page_size_in_words = LargePageSizeInWordsFor(size);
@@ -585,10 +582,6 @@
 }
 
 void PageSpace::UpdateMaxCapacityLocked() {
-  if (heap_ == nullptr) {
-    // Some unit tests.
-    return;
-  }
   ASSERT(heap_ != nullptr);
   ASSERT(heap_->isolate_group() != nullptr);
   auto isolate_group = heap_->isolate_group();
@@ -597,10 +590,6 @@
 }
 
 void PageSpace::UpdateMaxUsed() {
-  if (heap_ == nullptr) {
-    // Some unit tests.
-    return;
-  }
   ASSERT(heap_ != nullptr);
   ASSERT(heap_->isolate_group() != nullptr);
   auto isolate_group = heap_->isolate_group();
diff --git a/runtime/vm/heap/pages_test.cc b/runtime/vm/heap/pages_test.cc
deleted file mode 100644
index 385a9ae..0000000
--- a/runtime/vm/heap/pages_test.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-#include "vm/heap/pages.h"
-#include "platform/assert.h"
-#include "vm/unit_test.h"
-
-namespace dart {
-
-TEST_CASE(Pages) {
-  PageSpace* space = new PageSpace(nullptr, 4 * MBInWords);
-  EXPECT(!space->Contains(reinterpret_cast<uword>(&space)));
-  uword block = space->TryAllocate(8 * kWordSize);
-  EXPECT(block != 0);
-  uword total = 0;
-  while (total < 2 * MB) {
-    const intptr_t kBlockSize = 16 * kWordSize;
-    uword new_block = space->TryAllocate(kBlockSize);
-    EXPECT(block != 0);
-    EXPECT(block != new_block);
-    EXPECT(space->IsValidAddress(new_block));
-    block = new_block;
-    total += kBlockSize;
-  }
-  // Allocate a large block.
-  uword large_block = space->TryAllocate(1 * MB);
-  EXPECT(large_block != 0);
-  EXPECT(block != large_block);
-  EXPECT(space->IsValidAddress(large_block));
-  delete space;
-}
-
-}  // namespace dart
diff --git a/runtime/vm/heap/scavenger.cc b/runtime/vm/heap/scavenger.cc
index aba049d..d2e0f3e 100644
--- a/runtime/vm/heap/scavenger.cc
+++ b/runtime/vm/heap/scavenger.cc
@@ -817,6 +817,8 @@
       external_size_(0),
       failed_to_promote_(false),
       abort_(false) {
+  ASSERT(heap != nullptr);
+
   // Verify assumptions about the first word in objects which the scavenger is
   // going to use for forwarding pointers.
   ASSERT(Object::tags_offset() == 0);
@@ -1358,10 +1360,6 @@
 }
 
 void Scavenger::UpdateMaxHeapCapacity() {
-  if (heap_ == nullptr) {
-    // Some unit tests.
-    return;
-  }
   ASSERT(to_ != nullptr);
   ASSERT(heap_ != nullptr);
   auto isolate_group = heap_->isolate_group();
@@ -1371,10 +1369,6 @@
 }
 
 void Scavenger::UpdateMaxHeapUsage() {
-  if (heap_ == nullptr) {
-    // Some unit tests.
-    return;
-  }
   ASSERT(to_ != nullptr);
   ASSERT(heap_ != nullptr);
   auto isolate_group = heap_->isolate_group();