Abort transaction before finalizable allocation...

... instead of aborting after the allocation.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Test: aosp_taimen-userdebug boots.
Test: run-gtests.sh
Test: testrunner.py --target --optimizing
Bug: 26687569
Change-Id: I933b3b940bbd2125f4b5316db8dcf78cb5c8c8fc
diff --git a/runtime/interpreter/interpreter_switch_impl-inl.h b/runtime/interpreter/interpreter_switch_impl-inl.h
index 7ab8864..13aa9e7 100644
--- a/runtime/interpreter/interpreter_switch_impl-inl.h
+++ b/runtime/interpreter/interpreter_switch_impl-inl.h
@@ -828,6 +828,14 @@
                                                      false,
                                                      do_access_check);
     if (LIKELY(c != nullptr)) {
+      // Don't allow finalizable objects to be allocated during a transaction since these can't
+      // be finalized without a started runtime.
+      if (transaction_active && c->IsFinalizable()) {
+        AbortTransactionF(self,
+                          "Allocating finalizable object in transaction: %s",
+                          c->PrettyDescriptor().c_str());
+        HANDLE_PENDING_EXCEPTION();
+      }
       gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator();
       if (UNLIKELY(c->IsStringClass())) {
         obj = mirror::String::AllocEmptyString(self, allocator_type);
@@ -839,13 +847,6 @@
       HANDLE_PENDING_EXCEPTION();
     } else {
       obj->GetClass()->AssertInitializedOrInitializingInThread(self);
-      // Don't allow finalizable objects to be allocated during a transaction since these can't
-      // be finalized without a started runtime.
-      if (transaction_active && obj->GetClass()->IsFinalizable()) {
-        AbortTransactionF(self, "Allocating finalizable object in transaction: %s",
-                          obj->PrettyTypeOf().c_str());
-        HANDLE_PENDING_EXCEPTION();
-      }
       SetVRegReference(A(), obj);
     }
     return true;