Don't allow heap transitions if the runtime is shutting down.

Bug: 14254222
Change-Id: I97ac988a96b56a8dc1eec018bf3ef7a691f04745
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 502da12..517c748 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1432,6 +1432,11 @@
       if (collector_type == collector_type_) {
         return;
       }
+      if (Runtime::Current()->IsShuttingDown(self)) {
+        // Don't allow heap transitions to happen if the runtime is shutting down since these can
+        // cause objects to get finalized.
+        return;
+      }
       // GC can be disabled if someone has a used GetPrimitiveArrayCritical but not yet released.
       if (!copying_transition || disable_moving_gc_count_ == 0) {
         // TODO: Not hard code in semi-space collector?