[vm/test] Scavenger `WeakProperty` and `WeakReference` unit tests

The new space tests were evacuating new space, letting the scavenger
promote everything and then immediately running the marker.
This did not test the state right after running only the scavenge.

TEST=runtime/vm/object_test.cc

Change-Id: I3272f62a38ff5d38e76c83c831c3742e4951aa56
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233280
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
diff --git a/runtime/vm/object_test.cc b/runtime/vm/object_test.cc
index 1578f69..ac5c703 100644
--- a/runtime/vm/object_test.cc
+++ b/runtime/vm/object_test.cc
@@ -3643,7 +3643,7 @@
     weak.set_key(key);
     weak.set_value(value);
   }
-  GCTestHelper::CollectAllGarbage();
+  GCTestHelper::CollectNewSpace();
   EXPECT(weak.key() != Object::null());
   EXPECT(weak.value() != Object::null());
 }
@@ -3668,7 +3668,7 @@
     weak2.set_key(key2);
     weak2.set_value(value2);
   }
-  GCTestHelper::CollectAllGarbage();
+  GCTestHelper::CollectNewSpace();
   EXPECT(weak1.key() != Object::null());
   EXPECT(weak1.value() != Object::null());
   EXPECT(weak2.key() != Object::null());
@@ -3693,7 +3693,7 @@
     weak2.set_key(key);
     weak2.set_value(value2);
   }
-  GCTestHelper::CollectAllGarbage();
+  GCTestHelper::CollectNewSpace();
   EXPECT(weak1.key() != Object::null());
   EXPECT(weak1.value() != Object::null());
   EXPECT(weak2.key() != Object::null());
@@ -3783,7 +3783,7 @@
     key ^= OneByteString::null();
     value ^= OneByteString::null();
   }
-  GCTestHelper::CollectAllGarbage();
+  GCTestHelper::CollectNewSpace();
   EXPECT(weak.key() == Object::null());
   EXPECT(weak.value() == Object::null());
 }
@@ -3806,7 +3806,7 @@
     weak2.set_key(key);
     weak2.set_value(value2);
   }
-  GCTestHelper::CollectAllGarbage();
+  GCTestHelper::CollectNewSpace();
   EXPECT(weak1.key() == Object::null());
   EXPECT(weak1.value() == Object::null());
   EXPECT(weak2.key() == Object::null());
@@ -3869,7 +3869,13 @@
     weak.set_target(target);
     weak.SetTypeArguments(type_arguments);
   }
-  GCTestHelper::CollectAllGarbage();
+
+  if (space == Heap::kNew) {
+    GCTestHelper::CollectNewSpace();
+  } else {
+    GCTestHelper::CollectAllGarbage();
+  }
+
   EXPECT(weak.target() != Object::null());
   EXPECT(weak.GetTypeArguments() != Object::null());
 }
@@ -3894,7 +3900,13 @@
     weak.set_target(target);
     weak.SetTypeArguments(type_arguments);
   }
-  GCTestHelper::CollectAllGarbage();
+
+  if (space == Heap::kNew) {
+    GCTestHelper::CollectNewSpace();
+  } else {
+    GCTestHelper::CollectAllGarbage();
+  }
+
   EXPECT(weak.target() == Object::null());
   EXPECT(weak.GetTypeArguments() != Object::null());
 }
@@ -3927,7 +3939,13 @@
     weak_property.set_key(key);
     weak_property.set_value(weak_reference);
   }
-  GCTestHelper::CollectAllGarbage();
+
+  if (space == Heap::kNew) {
+    GCTestHelper::CollectNewSpace();
+  } else {
+    GCTestHelper::CollectAllGarbage();
+  }
+
   const auto& weak_reference =
       WeakReference::CheckedHandle(Z, weak_property.value());
   EXPECT(weak_reference.target() == Object::null());
@@ -3964,7 +3982,13 @@
     weak_property.set_key(key);
     weak_property.set_value(weak_reference);
   }
-  GCTestHelper::CollectAllGarbage();
+
+  if (space == Heap::kNew) {
+    GCTestHelper::CollectNewSpace();
+  } else {
+    GCTestHelper::CollectAllGarbage();
+  }
+
   const auto& weak_reference =
       WeakReference::CheckedHandle(Z, weak_property.value());
   EXPECT(weak_reference.target() != Object::null());