[vm/compiler] Remove non-background optizable bit

The background compiler no longer has bailouts due to something that
cannot be done on BG compiler and has to be done on mutator (was
originally introduced in [0])

All optimizing compilations can happen on the BG thread. Class
finalization and other things no longer cause a bailout on BG
compiler.

If e.g. invalidated field guards cause a compilation to be discarded, it
can be retried on BG compiler.

[0] https://dart-review.googlesource.com/c/sdk/+/54886

Closes https://github.com/dart-lang/sdk/issues/45136

TEST=Fixes flaky hits of an assertion.

Change-Id: I50313dbedf96b8dec205acdb8c1ed5731d00433b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/187901
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
diff --git a/runtime/vm/compiler/jit/compiler.cc b/runtime/vm/compiler/jit/compiler.cc
index 9372d86..6a32a25 100644
--- a/runtime/vm/compiler/jit/compiler.cc
+++ b/runtime/vm/compiler/jit/compiler.cc
@@ -694,8 +694,6 @@
                                        intptr_t osr_id) {
   ASSERT(!FLAG_precompiled_mode);
   ASSERT(!optimized || function.WasCompiled() || function.ForceOptimize());
-  ASSERT(function.is_background_optimizable() ||
-         !Compiler::IsBackgroundCompilation());
   if (function.ForceOptimize()) optimized = true;
   LongJumpScope jump;
   if (setjmp(*jump.Set()) == 0) {
@@ -744,18 +742,13 @@
         if (error.ptr() == Object::background_compilation_error().ptr()) {
           if (FLAG_trace_compiler) {
             THR_Print(
-                "--> disabling background optimizations for '%s' (will "
-                "try to re-compile on isolate thread again)\n",
+                "--> discarding background compilation for '%s' (will "
+                "try to re-compile again later)\n",
                 function.ToFullyQualifiedCString());
           }
 
-          // Ensure we don't attempt to re-compile the function on the
-          // background compiler.
-          function.set_is_background_optimizable(false);
-
-          // Trigger another optimization soon on the main thread.
-          function.SetUsageCounter(
-              optimized ? FLAG_optimization_counter_threshold : 0);
+          // Trigger another optimization pass soon.
+          function.SetUsageCounter(FLAG_optimization_counter_threshold - 100);
           return Error::null();
         } else if (error.IsLanguageError() &&
                    LanguageError::Cast(error).kind() == Report::kBailout) {
@@ -1171,8 +1164,7 @@
             // the background queue (unless it was passed to foreground).
             if ((!old.HasOptimizedCode() && old.IsOptimizable()) ||
                 FLAG_stress_test_background_compilation) {
-              if (old.is_background_optimizable() &&
-                  Compiler::CanOptimizeFunction(thread, old)) {
+              if (Compiler::CanOptimizeFunction(thread, old)) {
                 QueueElement* repeat_qelem = new QueueElement(old);
                 function_queue()->Add(repeat_qelem);
               }
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 9d1c052..0c844ca 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -8719,7 +8719,6 @@
   NOT_IN_PRECOMPILED(result.set_inlining_depth(0));
   NOT_IN_PRECOMPILED(result.set_kernel_offset(0));
   result.set_is_optimizable(is_native ? false : true);
-  result.set_is_background_optimizable(is_native ? false : true);
   result.set_is_inlinable(true);
   result.reset_unboxed_parameters_and_return();
   result.SetInstructionsSafe(StubCode::LazyCompile());
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index 326cc5b..38f7766 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -3655,18 +3655,6 @@
         value, untag()->packed_fields_));
   }
 
-  // Indicates whether this function can be optimized on the background compiler
-  // thread.
-  bool is_background_optimizable() const {
-    return UntaggedFunction::PackedBackgroundOptimizable::decode(
-        untag()->packed_fields_);
-  }
-
-  void set_is_background_optimizable(bool value) const {
-    set_packed_fields(UntaggedFunction::PackedBackgroundOptimizable::update(
-        value, untag()->packed_fields_));
-  }
-
   enum KindTagBits {
     kKindTagPos = 0,
     kKindTagSize = 5,
diff --git a/runtime/vm/raw_object.h b/runtime/vm/raw_object.h
index 21fe968..0ba396b 100644
--- a/runtime/vm/raw_object.h
+++ b/runtime/vm/raw_object.h
@@ -1148,7 +1148,6 @@
   // TODO(regis): Split packed_fields_ in 2 uint32_t if max values are too low.
 
   static constexpr intptr_t kMaxOptimizableBits = 1;
-  static constexpr intptr_t kMaxBackgroundOptimizableBits = 1;
   static constexpr intptr_t kMaxTypeParametersBits = 7;
   static constexpr intptr_t kMaxHasNamedOptionalParametersBits = 1;
   static constexpr intptr_t kMaxFixedParametersBits = 10;
@@ -1156,13 +1155,8 @@
 
   typedef BitField<uint32_t, bool, 0, kMaxOptimizableBits> PackedOptimizable;
   typedef BitField<uint32_t,
-                   bool,
-                   PackedOptimizable::kNextBit,
-                   kMaxBackgroundOptimizableBits>
-      PackedBackgroundOptimizable;
-  typedef BitField<uint32_t,
                    uint8_t,
-                   PackedBackgroundOptimizable::kNextBit,
+                   PackedOptimizable::kNextBit,
                    kMaxTypeParametersBits>
       PackedNumTypeParameters;
   typedef BitField<uint32_t,
diff --git a/runtime/vm/runtime_entry.cc b/runtime/vm/runtime_entry.cc
index e70e70a..130f9dd 100644
--- a/runtime/vm/runtime_entry.cc
+++ b/runtime/vm/runtime_entry.cc
@@ -2775,8 +2775,7 @@
   if (Compiler::CanOptimizeFunction(thread, function)) {
     auto isolate_group = thread->isolate_group();
     if (FLAG_background_compilation) {
-      if (function.is_background_optimizable() &&
-          isolate_group->background_compiler()->EnqueueCompilation(function)) {
+      if (isolate_group->background_compiler()->EnqueueCompilation(function)) {
         // Reduce the chance of triggering a compilation while the function is
         // being compiled in the background. INT32_MIN should ensure that it
         // takes long time to trigger a compilation.