Move transaction creation to runtime

Move the transaction creation to runtime instead of passing a pointer to
runtime when EnterTransactionMode. Because later there will be more
places to create transaction so this makes the code cleaner and more
compact.

Test: make test-art-host -j64
Change-Id: I971edf3110eb6634b6e0f7f56256be04517a5281
diff --git a/runtime/transaction_test.cc b/runtime/transaction_test.cc
index 9206292..e52dd08 100644
--- a/runtime/transaction_test.cc
+++ b/runtime/transaction_test.cc
@@ -69,14 +69,12 @@
     mirror::Class::Status old_status = h_klass->GetStatus();
     LockWord old_lock_word = h_klass->GetLockWord(false);
 
-    Transaction transaction;
-    Runtime::Current()->EnterTransactionMode(&transaction);
+    Runtime::Current()->EnterTransactionMode();
     bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true);
-    Runtime::Current()->ExitTransactionMode();
+    ASSERT_TRUE(Runtime::Current()->IsTransactionAborted());
     ASSERT_FALSE(success);
     ASSERT_TRUE(h_klass->IsErroneous());
     ASSERT_TRUE(soa.Self()->IsExceptionPending());
-    ASSERT_TRUE(transaction.IsAborted());
 
     // Check class's monitor get back to its original state without rolling back changes.
     LockWord new_lock_word = h_klass->GetLockWord(false);
@@ -84,7 +82,7 @@
 
     // Check class status is rolled back properly.
     soa.Self()->ClearException();
-    transaction.Rollback();
+    Runtime::Current()->RollbackAndExitTransactionMode();
     ASSERT_EQ(old_status, h_klass->GetStatus());
   }
 };
@@ -97,15 +95,12 @@
       hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;")));
   ASSERT_TRUE(h_klass != nullptr);
 
-  Transaction transaction;
-  Runtime::Current()->EnterTransactionMode(&transaction);
+  Runtime::Current()->EnterTransactionMode();
   Handle<mirror::Object> h_obj(hs.NewHandle(h_klass->AllocObject(soa.Self())));
   ASSERT_TRUE(h_obj != nullptr);
   ASSERT_EQ(h_obj->GetClass(), h_klass.Get());
-  Runtime::Current()->ExitTransactionMode();
-
   // Rolling back transaction's changes must not clear the Object::class field.
-  transaction.Rollback();
+  Runtime::Current()->RollbackAndExitTransactionMode();
   EXPECT_EQ(h_obj->GetClass(), h_klass.Get());
 }
 
@@ -124,15 +119,13 @@
   h_obj->MonitorEnter(soa.Self());
   LockWord old_lock_word = h_obj->GetLockWord(false);
 
-  Transaction transaction;
-  Runtime::Current()->EnterTransactionMode(&transaction);
+  Runtime::Current()->EnterTransactionMode();
   // Unlock object's monitor inside the transaction.
   h_obj->MonitorExit(soa.Self());
   LockWord new_lock_word = h_obj->GetLockWord(false);
-  Runtime::Current()->ExitTransactionMode();
-
   // Rolling back transaction's changes must not change monitor's state.
-  transaction.Rollback();
+  Runtime::Current()->RollbackAndExitTransactionMode();
+
   LockWord aborted_lock_word = h_obj->GetLockWord(false);
   EXPECT_FALSE(LockWord::Equal<false>(old_lock_word, new_lock_word));
   EXPECT_TRUE(LockWord::Equal<false>(aborted_lock_word, new_lock_word));
@@ -148,8 +141,7 @@
 
   constexpr int32_t kArraySize = 2;
 
-  Transaction transaction;
-  Runtime::Current()->EnterTransactionMode(&transaction);
+  Runtime::Current()->EnterTransactionMode();
 
   // Allocate an array during transaction.
   Handle<mirror::Array> h_obj(
@@ -159,10 +151,9 @@
                                      Runtime::Current()->GetHeap()->GetCurrentAllocator())));
   ASSERT_TRUE(h_obj != nullptr);
   ASSERT_EQ(h_obj->GetClass(), h_klass.Get());
-  Runtime::Current()->ExitTransactionMode();
+  Runtime::Current()->RollbackAndExitTransactionMode();
 
   // Rolling back transaction's changes must not reset array's length.
-  transaction.Rollback();
   EXPECT_EQ(h_obj->GetLength(), kArraySize);
 }
 
@@ -238,8 +229,7 @@
   ASSERT_EQ(h_obj->GetClass(), h_klass.Get());
 
   // Modify fields inside transaction then rollback changes.
-  Transaction transaction;
-  Runtime::Current()->EnterTransactionMode(&transaction);
+  Runtime::Current()->EnterTransactionMode();
   booleanField->SetBoolean<true>(h_klass.Get(), true);
   byteField->SetByte<true>(h_klass.Get(), 1);
   charField->SetChar<true>(h_klass.Get(), 1u);
@@ -249,8 +239,7 @@
   floatField->SetFloat<true>(h_klass.Get(), 1.0);
   doubleField->SetDouble<true>(h_klass.Get(), 1.0);
   objectField->SetObject<true>(h_klass.Get(), h_obj.Get());
-  Runtime::Current()->ExitTransactionMode();
-  transaction.Rollback();
+  Runtime::Current()->RollbackAndExitTransactionMode();
 
   // Check values have properly been restored to their original (default) value.
   EXPECT_EQ(booleanField->GetBoolean(h_klass.Get()), false);
@@ -340,8 +329,7 @@
   ASSERT_EQ(h_obj->GetClass(), h_klass.Get());
 
   // Modify fields inside transaction then rollback changes.
-  Transaction transaction;
-  Runtime::Current()->EnterTransactionMode(&transaction);
+  Runtime::Current()->EnterTransactionMode();
   booleanField->SetBoolean<true>(h_instance.Get(), true);
   byteField->SetByte<true>(h_instance.Get(), 1);
   charField->SetChar<true>(h_instance.Get(), 1u);
@@ -351,8 +339,7 @@
   floatField->SetFloat<true>(h_instance.Get(), 1.0);
   doubleField->SetDouble<true>(h_instance.Get(), 1.0);
   objectField->SetObject<true>(h_instance.Get(), h_obj.Get());
-  Runtime::Current()->ExitTransactionMode();
-  transaction.Rollback();
+  Runtime::Current()->RollbackAndExitTransactionMode();
 
   // Check values have properly been restored to their original (default) value.
   EXPECT_EQ(booleanField->GetBoolean(h_instance.Get()), false);
@@ -457,8 +444,7 @@
   ASSERT_EQ(h_obj->GetClass(), h_klass.Get());
 
   // Modify fields inside transaction then rollback changes.
-  Transaction transaction;
-  Runtime::Current()->EnterTransactionMode(&transaction);
+  Runtime::Current()->EnterTransactionMode();
   booleanArray->SetWithoutChecks<true>(0, true);
   byteArray->SetWithoutChecks<true>(0, 1);
   charArray->SetWithoutChecks<true>(0, 1u);
@@ -468,8 +454,7 @@
   floatArray->SetWithoutChecks<true>(0, 1.0);
   doubleArray->SetWithoutChecks<true>(0, 1.0);
   objectArray->SetWithoutChecks<true>(0, h_obj.Get());
-  Runtime::Current()->ExitTransactionMode();
-  transaction.Rollback();
+  Runtime::Current()->RollbackAndExitTransactionMode();
 
   // Check values have properly been restored to their original (default) value.
   EXPECT_EQ(booleanArray->GetWithoutChecks(0), false);
@@ -511,8 +496,7 @@
   EXPECT_TRUE(class_linker_->LookupString(*dex_file, string_idx, h_dex_cache.Get()) == nullptr);
   EXPECT_TRUE(h_dex_cache->GetResolvedString(string_idx) == nullptr);
   // Do the transaction, then roll back.
-  Transaction transaction;
-  Runtime::Current()->EnterTransactionMode(&transaction);
+  Runtime::Current()->EnterTransactionMode();
   bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true);
   ASSERT_TRUE(success);
   ASSERT_TRUE(h_klass->IsInitialized());
@@ -523,8 +507,7 @@
     EXPECT_STREQ(s->ToModifiedUtf8().c_str(), kResolvedString);
     EXPECT_EQ(s, h_dex_cache->GetResolvedString(string_idx));
   }
-  Runtime::Current()->ExitTransactionMode();
-  transaction.Rollback();
+  Runtime::Current()->RollbackAndExitTransactionMode();
   // Check that the string did not stay resolved.
   EXPECT_TRUE(class_linker_->LookupString(*dex_file, string_idx, h_dex_cache.Get()) == nullptr);
   EXPECT_TRUE(h_dex_cache->GetResolvedString(string_idx) == nullptr);
@@ -547,8 +530,7 @@
   class_linker_->VerifyClass(soa.Self(), h_klass);
   ASSERT_TRUE(h_klass->IsVerified());
 
-  Transaction transaction;
-  Runtime::Current()->EnterTransactionMode(&transaction);
+  Runtime::Current()->EnterTransactionMode();
   bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true);
   Runtime::Current()->ExitTransactionMode();
   ASSERT_TRUE(success);
@@ -571,8 +553,7 @@
   class_linker_->VerifyClass(soa.Self(), h_klass);
   ASSERT_TRUE(h_klass->IsVerified());
 
-  Transaction transaction;
-  Runtime::Current()->EnterTransactionMode(&transaction);
+  Runtime::Current()->EnterTransactionMode();
   bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true);
   Runtime::Current()->ExitTransactionMode();
   ASSERT_TRUE(success);