[vm, compiler] Disable unopt megamorphic call specialization.

Bug: https://github.com/dart-lang/sdk/issues/37260
Change-Id: I66a1661da9483529dc96be804863224d9afb9c48
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106006
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/vm/runtime_entry.cc b/runtime/vm/runtime_entry.cc
index f13950a..5cf8613 100644
--- a/runtime/vm/runtime_entry.cc
+++ b/runtime/vm/runtime_entry.cc
@@ -75,6 +75,15 @@
             NULL,
             "Deoptimize in named function on stack overflow checks");
 
+DEFINE_FLAG(bool,
+            unopt_monomorphic_calls,
+            true,
+            "Enable specializing monomorphic calls from unoptimized code.");
+DEFINE_FLAG(bool,
+            unopt_megamorphic_calls,
+            false,
+            "Enable specializing megamorphic calls from unoptimized code.");
+
 DECLARE_FLAG(int, reload_every);
 DECLARE_FLAG(bool, reload_every_optimized);
 DECLARE_FLAG(bool, reload_every_back_off);
@@ -1117,7 +1126,7 @@
   intptr_t num_checks = ic_data.NumberOfChecks();
 
   // Monomorphic call.
-  if (num_checks == 1) {
+  if (FLAG_unopt_monomorphic_calls && (num_checks == 1)) {
     // A call site in the monomorphic state does not load the arguments
     // descriptor, so do not allow transition to this state if the callee
     // needs it.
@@ -1139,7 +1148,8 @@
   }
 
   // Megamorphic call.
-  if (num_checks > FLAG_max_polymorphic_checks) {
+  if (FLAG_unopt_megamorphic_calls &&
+      (num_checks > FLAG_max_polymorphic_checks)) {
     const MegamorphicCache& cache =
         MegamorphicCache::Handle(zone, ic_data.AsMegamorphicCache());
     ic_data.set_is_megamorphic(true);