[vm/bytecode] Fix sporadic crashes when running with bytecode.

Several tests crashed sporadically as bytecode Code object was not
properly scanned by GC.

Change-Id: I4810c46552a9f1990f1304f7c502b3408df8ed88
Reviewed-on: https://dart-review.googlesource.com/c/78141
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
diff --git a/runtime/vm/compiler/jit/compiler.cc b/runtime/vm/compiler/jit/compiler.cc
index 6704c19..339a85d 100644
--- a/runtime/vm/compiler/jit/compiler.cc
+++ b/runtime/vm/compiler/jit/compiler.cc
@@ -1245,7 +1245,8 @@
 #endif  // !defined(PRODUCT)
 
   // If running with interpreter, do the unoptimized compilation first.
-  const bool optimized = !FLAG_enable_interpreter || function.WasCompiled();
+  const bool optimized = !FLAG_enable_interpreter ||
+                         (function.unoptimized_code() != Object::null());
 
   // If we are in the optimizing in the mutator/Dart thread, then
   // this is either an OSR compilation or background compilation is
diff --git a/runtime/vm/raw_object.cc b/runtime/vm/raw_object.cc
index 41d4e2c..0e69083 100644
--- a/runtime/vm/raw_object.cc
+++ b/runtime/vm/raw_object.cc
@@ -488,6 +488,9 @@
 #else
   visitor->VisitPointers(raw_obj->from(), raw_obj->to_no_code());
 
+  visitor->VisitPointer(
+      reinterpret_cast<RawObject**>(&raw_obj->ptr()->bytecode_));
+
   if (ShouldVisitCode(raw_obj->ptr()->code_)) {
     visitor->VisitPointer(
         reinterpret_cast<RawObject**>(&raw_obj->ptr()->code_));
diff --git a/runtime/vm/runtime_entry.cc b/runtime/vm/runtime_entry.cc
index f3695d3..5c73ecb 100644
--- a/runtime/vm/runtime_entry.cc
+++ b/runtime/vm/runtime_entry.cc
@@ -2156,7 +2156,8 @@
 
   // If running with interpreter, do the unoptimized compilation first.
   const bool unoptimized_compilation =
-      FLAG_enable_interpreter && !function.WasCompiled();
+      FLAG_enable_interpreter &&
+      (function.unoptimized_code() == Object::null());
 
   ASSERT(unoptimized_compilation || function.HasCode());
 
diff --git a/tests/lib_2/lib_2_kernel.status b/tests/lib_2/lib_2_kernel.status
index 7da4efc..963e273 100644
--- a/tests/lib_2/lib_2_kernel.status
+++ b/tests/lib_2/lib_2_kernel.status
@@ -71,11 +71,9 @@
 # The failures below still need to be investigated and possibly fixed, or marked as skipped.
 [ $compiler == dartkb && $strong ]
 convert/streamed_conversion_json_utf8_decode_test: Pass, Timeout # Please triage.
-io/file_lock_test: Pass, Timeout # Please triage.
-isolate/isolate_complex_messages_test: Pass, Crash # Non-canonical type arguments.
-isolate/mandel_isolate_test: Pass, Timeout, Crash # Please triage.
-isolate/spawn_uri_exported_main_test: Pass, RuntimeError # Please triage.
-mirrors/immutable_collections_test: Pass, Crash # Please triage.
+isolate/isolate_complex_messages_test: Pass, Crash # runtime/vm/object.cc: 17395: error: expected: type_arguments.IsNull() || type_arguments.IsCanonical()
+isolate/mandel_isolate_test: Pass, Timeout # Please triage.
+isolate/spawn_uri_exported_main_test: Pass, RuntimeError # Please triage: Expect.fail('Isolate was not spawned successfully.')
 mirrors/invocation_fuzz_test/emptyarray: Skip # Times out, issue 32232
 mirrors/invocation_fuzz_test/false: Skip # Times out, issue 32232
 mirrors/library_uri_io_test: RuntimeError # Platform.script points to dill file.
diff --git a/tests/standalone_2/standalone_2_kernel.status b/tests/standalone_2/standalone_2_kernel.status
index 79293a6..bd1aff3 100644
--- a/tests/standalone_2/standalone_2_kernel.status
+++ b/tests/standalone_2/standalone_2_kernel.status
@@ -53,22 +53,18 @@
 
 # The failures below still need to be investigated and possibly fixed, or marked as skipped.
 [ $compiler == dartkb && $strong ]
-io/dart_std_io_pipe_test: Pass, Crash, Timeout # Trap bytecode encountered.
-io/file_lock_test: Pass, Crash # Trap bytecode encountered.
 io/http_advanced_test: Pass, RuntimeError # Please triage.
 io/http_client_connect_test: Pass, RuntimeError # Please triage.
 io/http_outgoing_size_test: Pass, RuntimeError # Please triage.
-io/http_server_test: Pass, RuntimeError # Please triage.
+io/http_server_test: Pass, RuntimeError # Please triage: NoSuchMethodError: The method 'call' was called on null.
 io/platform_test: RuntimeError # Platform.script points to dill file.
-io/process_sync_test: Pass, Crash # Bytecode compilation.
 io/test_extension_fail_test: RuntimeError # Platform.script points to dill file.
 io/test_extension_test: RuntimeError # Platform.script points to dill file.
-io/web_socket_compression_test: Pass, RuntimeError # Please triage.
+io/web_socket_compression_test: Pass, RuntimeError # Please triage: NoSuchMethodError: The method 'call' was called on null.
 io/web_socket_ping_test: Pass, RuntimeError # Please triage.
 io/web_socket_protocol_test: Pass, RuntimeError # Please triage.
 io/web_socket_typed_data_test: Pass, RuntimeError # Please triage.
 no_lazy_dispatchers_test: SkipByDesign # KBC interpreter doesn't support --no_lazy_dispatchers
-typed_data_isolate_test: Pass, Crash, Timeout # Please triage.
 
 [ $compiler == dartkp && $mode == debug && $runtime == dart_precompiled && $strong ]
 io/compile_all_test: Crash # Issue 32373