[vm, compiler] Do not constant fold if the result is a new-space object.

Bug: IA32 opt-counter language/async_star_test
Change-Id: Id09cb477ecd81750baa8bddc142a8ee38376dc76
Reviewed-on: https://dart-review.googlesource.com/72241
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/vm/compiler/backend/il.cc b/runtime/vm/compiler/backend/il.cc
index 88cec81..4d5b307 100644
--- a/runtime/vm/compiler/backend/il.cc
+++ b/runtime/vm/compiler/backend/il.cc
@@ -1002,6 +1002,7 @@
   // Check that the value is not an incorrect Integer representation.
   ASSERT(!value.IsMint() || !Smi::IsValid(Mint::Cast(value).AsInt64Value()));
   ASSERT(!value.IsField() || Field::Cast(value).IsOriginal());
+  ASSERT(value.IsSmi() || value.IsOld());
 }
 
 bool ConstantInstr::AttributesEqual(Instruction* other) const {
@@ -2678,7 +2679,9 @@
   if (instance()->BindsToConstant()) {
     Object& result = Object::Handle();
     if (Evaluate(instance()->BoundConstant(), &result)) {
-      return flow_graph->GetConstant(result);
+      if (result.IsSmi() || result.IsOld()) {
+        return flow_graph->GetConstant(result);
+      }
     }
   }
 
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 593ea86..082462e 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -15744,8 +15744,11 @@
       ASSERT(instrs.PayloadStart() <= addr);
       ASSERT((instrs.PayloadStart() + instrs.Size()) > addr);
       const Object* object = *reinterpret_cast<Object**>(addr);
-      instrs.raw()->StorePointer(reinterpret_cast<RawObject**>(addr),
-                                 object->raw());
+      ASSERT(object->IsOld());
+      // N.B. The pointer is embedded in the Instructions object, but visited
+      // through the Code object.
+      code.raw()->StorePointer(reinterpret_cast<RawObject**>(addr),
+                               object->raw());
     }
 
     // Hook up Code and Instructions objects.