[VM] Do not use the contents of the megamorphic miss code in stack_frame

The megamorphic miss stub might not be initialized at the point in time
when we access it.

Fixes https://github.com/dart-lang/sdk/issues/35405

Change-Id: If20622bd4f3b14d6ece5a8de6f006d7081d6cf76
Reviewed-on: https://dart-review.googlesource.com/c/87322
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
diff --git a/runtime/vm/stack_frame.cc b/runtime/vm/stack_frame.cc
index cc94c15..e0302ab 100644
--- a/runtime/vm/stack_frame.cc
+++ b/runtime/vm/stack_frame.cc
@@ -91,16 +91,9 @@
     auto rct = isolate->reverse_pc_lookup_cache();
     code = rct->Lookup(pc());
 
-    // All stub codes have a `null` owner except for the megamorphic miss
-    // stub. So if it's neither of those, we are know it must be a
-    // precompiled dart frame.
-    RawObject* owner = code.owner();
-    if (owner != Object::null()) {
-      if (code.raw() ==
-          Isolate::Current()->object_store()->megamorphic_miss_code()) {
-        return true;
-      }
-    }
+    const intptr_t cid = code.owner()->GetClassId();
+    ASSERT(cid == kNullCid || cid == kClassCid || cid == kFunctionCid);
+    return cid == kFunctionCid;
   }
   return false;
 }
@@ -113,37 +106,13 @@
     auto rct = isolate->reverse_pc_lookup_cache();
     code = rct->Lookup(pc());
 
-    // All stub codes have a `null` owner except for the megamorphic miss stub.
-    // So if it's either of those, we are know it must be a precompiled stub
-    // frame.
-    RawObject* owner = code.owner();
-    if (owner == Object::null()) {
-      return true;
-    }
-
-    if (code.raw() ==
-        Isolate::Current()->object_store()->megamorphic_miss_code()) {
-      return true;
-    }
+    const intptr_t cid = code.owner()->GetClassId();
+    ASSERT(cid == kNullCid || cid == kClassCid || cid == kFunctionCid);
+    return cid == kNullCid || cid == kClassCid;
   }
   return false;
 }
 
-bool StackFrame::IsDartFrame(bool validate) const {
-  ASSERT(!validate || IsValid());
-
-  if (IsEntryFrame() || IsExitFrame()) return false;
-
-  // Even though the megamorphic miss stub is a stub, we consider it as a
-  // dart frame for all practical purposes.
-  const bool is_megamorphic_miss_stub = Code::ContainsInstructionAt(
-      thread_->isolate()->object_store()->megamorphic_miss_code(), pc_);
-
-  if (is_megamorphic_miss_stub) return true;
-
-  return !IsStubFrame();
-}
-
 bool StackFrame::IsStubFrame() const {
   if (is_interpreted()) {
     return false;
diff --git a/runtime/vm/stack_frame.h b/runtime/vm/stack_frame.h
index 9b6b67a..c8b59b9 100644
--- a/runtime/vm/stack_frame.h
+++ b/runtime/vm/stack_frame.h
@@ -165,7 +165,10 @@
   bool IsBareInstructionsStubFrame() const;
 
   // Frame type.
-  virtual bool IsDartFrame(bool validate = true) const;
+  virtual bool IsDartFrame(bool validate = true) const {
+    ASSERT(!validate || IsValid());
+    return !(IsEntryFrame() || IsExitFrame() || IsStubFrame());
+  }
   virtual bool IsStubFrame() const;
   virtual bool IsEntryFrame() const { return false; }
   virtual bool IsExitFrame() const { return false; }
diff --git a/tests/language_2/language_2_kernel.status b/tests/language_2/language_2_kernel.status
index 4ce61f3..44cc68f 100644
--- a/tests/language_2/language_2_kernel.status
+++ b/tests/language_2/language_2_kernel.status
@@ -240,9 +240,6 @@
 vm/debug_break_enabled_vm_test/none: CompileTimeError # KernelVM bug: Bad test using extended break syntax.
 vm/regress_27201_test: CompileTimeError # Fasta/KernelVM bug: Deferred loading kernel issue 30273.
 
-[ $arch == ia32 && $compiler == dartk && $system == windows ]
-deferred_optimized_test: Pass, Crash # Issue 35405 (Flaky failure).
-
 [ $builder_tag == obfuscated && $compiler == dartkp ]
 generic_function_dcall_test/01: SkipByDesign # Prints type names
 invocation_mirror_test: RuntimeError # Issue 34911