Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 17 | #include "transaction.h" |
| 18 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method-inl.h" |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 21 | #include "class_linker-inl.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 22 | #include "common_runtime_test.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 23 | #include "dex/dex_file.h" |
Andreas Gampe | 8e0f043 | 2018-10-24 13:38:03 -0700 | [diff] [blame] | 24 | #include "mirror/array-alloc-inl.h" |
Andreas Gampe | 70f5fd0 | 2018-10-24 19:58:37 -0700 | [diff] [blame] | 25 | #include "mirror/class-alloc-inl.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 26 | #include "scoped_thread_state_change-inl.h" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 30 | class TransactionTest : public CommonRuntimeTest { |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 31 | protected: |
Vladimir Marko | 483c41a | 2021-11-12 12:45:23 +0000 | [diff] [blame] | 32 | TransactionTest() { |
| 33 | this->use_boot_image_ = true; // We need the boot image for this test. |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 34 | } |
| 35 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 36 | // Tests failing class initialization due to native call with transaction rollback. |
| 37 | void testTransactionAbort(const char* tested_class_signature) { |
| 38 | ScopedObjectAccess soa(Thread::Current()); |
| 39 | jobject jclass_loader = LoadDex("Transaction"); |
| 40 | StackHandleScope<2> hs(soa.Self()); |
| 41 | Handle<mirror::ClassLoader> class_loader( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 42 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(jclass_loader))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 43 | ASSERT_TRUE(class_loader != nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 44 | |
Sebastien Hertz | 2fd7e69 | 2015-04-02 11:11:19 +0200 | [diff] [blame] | 45 | // Load and initialize java.lang.ExceptionInInitializerError and the exception class used |
| 46 | // to abort transaction so they can be thrown during class initialization if the transaction |
| 47 | // aborts. |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 48 | MutableHandle<mirror::Class> h_klass( |
| 49 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), |
| 50 | "Ljava/lang/ExceptionInInitializerError;"))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 51 | ASSERT_TRUE(h_klass != nullptr); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 52 | class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true); |
| 53 | ASSERT_TRUE(h_klass->IsInitialized()); |
| 54 | |
Sebastien Hertz | 2fd7e69 | 2015-04-02 11:11:19 +0200 | [diff] [blame] | 55 | h_klass.Assign(class_linker_->FindSystemClass(soa.Self(), |
Vladimir Marko | 0685b98 | 2021-03-25 11:59:22 +0000 | [diff] [blame] | 56 | Transaction::kAbortExceptionDescriptor)); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 57 | ASSERT_TRUE(h_klass != nullptr); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 58 | class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true); |
| 59 | ASSERT_TRUE(h_klass->IsInitialized()); |
| 60 | |
| 61 | // Load and verify utility class. |
| 62 | h_klass.Assign(class_linker_->FindClass(soa.Self(), "LTransaction$AbortHelperClass;", |
| 63 | class_loader)); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 64 | ASSERT_TRUE(h_klass != nullptr); |
Nicolas Geoffray | 5b0b2e1 | 2021-03-19 14:48:40 +0000 | [diff] [blame] | 65 | class_linker_->VerifyClass(soa.Self(), /* verifier_deps= */ nullptr, h_klass); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 66 | ASSERT_TRUE(h_klass->IsVerified()); |
| 67 | |
| 68 | // Load and verify tested class. |
| 69 | h_klass.Assign(class_linker_->FindClass(soa.Self(), tested_class_signature, class_loader)); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 70 | ASSERT_TRUE(h_klass != nullptr); |
Nicolas Geoffray | 5b0b2e1 | 2021-03-19 14:48:40 +0000 | [diff] [blame] | 71 | class_linker_->VerifyClass(soa.Self(), /* verifier_deps= */ nullptr, h_klass); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 72 | ASSERT_TRUE(h_klass->IsVerified()); |
| 73 | |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 74 | ClassStatus old_status = h_klass->GetStatus(); |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 75 | LockWord old_lock_word = h_klass->GetLockWord(false); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 76 | |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 77 | EnterTransactionMode(); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 78 | bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 79 | ASSERT_TRUE(IsTransactionAborted()); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 80 | ASSERT_FALSE(success); |
| 81 | ASSERT_TRUE(h_klass->IsErroneous()); |
| 82 | ASSERT_TRUE(soa.Self()->IsExceptionPending()); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 83 | |
| 84 | // Check class's monitor get back to its original state without rolling back changes. |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 85 | LockWord new_lock_word = h_klass->GetLockWord(false); |
| 86 | EXPECT_TRUE(LockWord::Equal<false>(old_lock_word, new_lock_word)); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 87 | |
| 88 | // Check class status is rolled back properly. |
| 89 | soa.Self()->ClearException(); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 90 | RollbackAndExitTransactionMode(); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 91 | ASSERT_EQ(old_status, h_klass->GetStatus()); |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | // Tests object's class is preserved after transaction rollback. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 96 | TEST_F(TransactionTest, Object_class) { |
| 97 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 98 | StackHandleScope<2> hs(soa.Self()); |
| 99 | Handle<mirror::Class> h_klass( |
| 100 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 101 | ASSERT_TRUE(h_klass != nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 102 | |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 103 | EnterTransactionMode(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 104 | Handle<mirror::Object> h_obj(hs.NewHandle(h_klass->AllocObject(soa.Self()))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 105 | ASSERT_TRUE(h_obj != nullptr); |
Vladimir Marko | dfc0de7 | 2019-04-01 10:57:55 +0100 | [diff] [blame] | 106 | ASSERT_OBJ_PTR_EQ(h_obj->GetClass(), h_klass.Get()); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 107 | // Rolling back transaction's changes must not clear the Object::class field. |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 108 | RollbackAndExitTransactionMode(); |
Vladimir Marko | dfc0de7 | 2019-04-01 10:57:55 +0100 | [diff] [blame] | 109 | EXPECT_OBJ_PTR_EQ(h_obj->GetClass(), h_klass.Get()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 112 | // Tests object's monitor state is preserved after transaction rollback. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 113 | TEST_F(TransactionTest, Object_monitor) { |
| 114 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 115 | StackHandleScope<2> hs(soa.Self()); |
| 116 | Handle<mirror::Class> h_klass( |
| 117 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 118 | ASSERT_TRUE(h_klass != nullptr); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 119 | Handle<mirror::Object> h_obj(hs.NewHandle(h_klass->AllocObject(soa.Self()))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 120 | ASSERT_TRUE(h_obj != nullptr); |
Vladimir Marko | dfc0de7 | 2019-04-01 10:57:55 +0100 | [diff] [blame] | 121 | ASSERT_OBJ_PTR_EQ(h_obj->GetClass(), h_klass.Get()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 122 | |
| 123 | // Lock object's monitor outside the transaction. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 124 | h_obj->MonitorEnter(soa.Self()); |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 125 | LockWord old_lock_word = h_obj->GetLockWord(false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 126 | |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 127 | EnterTransactionMode(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 128 | // Unlock object's monitor inside the transaction. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 129 | h_obj->MonitorExit(soa.Self()); |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 130 | LockWord new_lock_word = h_obj->GetLockWord(false); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 131 | // Rolling back transaction's changes must not change monitor's state. |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 132 | RollbackAndExitTransactionMode(); |
Chang Xing | 16d1dd8 | 2017-07-20 17:56:26 -0700 | [diff] [blame] | 133 | |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 134 | LockWord aborted_lock_word = h_obj->GetLockWord(false); |
| 135 | EXPECT_FALSE(LockWord::Equal<false>(old_lock_word, new_lock_word)); |
| 136 | EXPECT_TRUE(LockWord::Equal<false>(aborted_lock_word, new_lock_word)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 139 | // Tests array's length is preserved after transaction rollback. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 140 | TEST_F(TransactionTest, Array_length) { |
| 141 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 142 | StackHandleScope<2> hs(soa.Self()); |
| 143 | Handle<mirror::Class> h_klass( |
| 144 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/Object;"))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 145 | ASSERT_TRUE(h_klass != nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 146 | |
| 147 | constexpr int32_t kArraySize = 2; |
| 148 | |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 149 | EnterTransactionMode(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 150 | |
| 151 | // Allocate an array during transaction. |
Vladimir Marko | 9b81ac3 | 2019-05-16 16:47:08 +0100 | [diff] [blame] | 152 | Handle<mirror::Array> h_obj = hs.NewHandle( |
| 153 | mirror::Array::Alloc(soa.Self(), |
| 154 | h_klass.Get(), |
| 155 | kArraySize, |
| 156 | h_klass->GetComponentSizeShift(), |
| 157 | Runtime::Current()->GetHeap()->GetCurrentAllocator())); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 158 | ASSERT_TRUE(h_obj != nullptr); |
Vladimir Marko | dfc0de7 | 2019-04-01 10:57:55 +0100 | [diff] [blame] | 159 | ASSERT_OBJ_PTR_EQ(h_obj->GetClass(), h_klass.Get()); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 160 | RollbackAndExitTransactionMode(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 161 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 162 | // Rolling back transaction's changes must not reset array's length. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 163 | EXPECT_EQ(h_obj->GetLength(), kArraySize); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 166 | // Tests static fields are reset to their default value after transaction rollback. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 167 | TEST_F(TransactionTest, StaticFieldsTest) { |
| 168 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 169 | StackHandleScope<4> hs(soa.Self()); |
| 170 | Handle<mirror::ClassLoader> class_loader( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 171 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(LoadDex("Transaction")))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 172 | ASSERT_TRUE(class_loader != nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 173 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 174 | Handle<mirror::Class> h_klass( |
| 175 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LStaticFieldsTest;", class_loader))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 176 | ASSERT_TRUE(h_klass != nullptr); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 177 | bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true); |
| 178 | ASSERT_TRUE(success); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 179 | ASSERT_TRUE(h_klass->IsInitialized()); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 180 | ASSERT_FALSE(soa.Self()->IsExceptionPending()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 181 | |
| 182 | // Lookup fields. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 183 | ArtField* booleanField = h_klass->FindDeclaredStaticField("booleanField", "Z"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 184 | ASSERT_TRUE(booleanField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 185 | ASSERT_EQ(booleanField->GetTypeAsPrimitiveType(), Primitive::kPrimBoolean); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 186 | ASSERT_EQ(booleanField->GetBoolean(h_klass.Get()), false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 187 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 188 | ArtField* byteField = h_klass->FindDeclaredStaticField("byteField", "B"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 189 | ASSERT_TRUE(byteField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 190 | ASSERT_EQ(byteField->GetTypeAsPrimitiveType(), Primitive::kPrimByte); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 191 | ASSERT_EQ(byteField->GetByte(h_klass.Get()), 0); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 192 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 193 | ArtField* charField = h_klass->FindDeclaredStaticField("charField", "C"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 194 | ASSERT_TRUE(charField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 195 | ASSERT_EQ(charField->GetTypeAsPrimitiveType(), Primitive::kPrimChar); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 196 | ASSERT_EQ(charField->GetChar(h_klass.Get()), 0u); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 197 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 198 | ArtField* shortField = h_klass->FindDeclaredStaticField("shortField", "S"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 199 | ASSERT_TRUE(shortField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 200 | ASSERT_EQ(shortField->GetTypeAsPrimitiveType(), Primitive::kPrimShort); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 201 | ASSERT_EQ(shortField->GetShort(h_klass.Get()), 0); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 202 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 203 | ArtField* intField = h_klass->FindDeclaredStaticField("intField", "I"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 204 | ASSERT_TRUE(intField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 205 | ASSERT_EQ(intField->GetTypeAsPrimitiveType(), Primitive::kPrimInt); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 206 | ASSERT_EQ(intField->GetInt(h_klass.Get()), 0); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 207 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 208 | ArtField* longField = h_klass->FindDeclaredStaticField("longField", "J"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 209 | ASSERT_TRUE(longField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 210 | ASSERT_EQ(longField->GetTypeAsPrimitiveType(), Primitive::kPrimLong); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 211 | ASSERT_EQ(longField->GetLong(h_klass.Get()), static_cast<int64_t>(0)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 212 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 213 | ArtField* floatField = h_klass->FindDeclaredStaticField("floatField", "F"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 214 | ASSERT_TRUE(floatField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 215 | ASSERT_EQ(floatField->GetTypeAsPrimitiveType(), Primitive::kPrimFloat); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 216 | ASSERT_FLOAT_EQ(floatField->GetFloat(h_klass.Get()), static_cast<float>(0.0f)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 217 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 218 | ArtField* doubleField = h_klass->FindDeclaredStaticField("doubleField", "D"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 219 | ASSERT_TRUE(doubleField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 220 | ASSERT_EQ(doubleField->GetTypeAsPrimitiveType(), Primitive::kPrimDouble); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 221 | ASSERT_DOUBLE_EQ(doubleField->GetDouble(h_klass.Get()), static_cast<double>(0.0)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 222 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 223 | ArtField* objectField = h_klass->FindDeclaredStaticField("objectField", |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 224 | "Ljava/lang/Object;"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 225 | ASSERT_TRUE(objectField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 226 | ASSERT_EQ(objectField->GetTypeAsPrimitiveType(), Primitive::kPrimNot); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 227 | ASSERT_EQ(objectField->GetObject(h_klass.Get()), nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 228 | |
| 229 | // Create a java.lang.Object instance to set objectField. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 230 | Handle<mirror::Class> object_klass( |
| 231 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 232 | ASSERT_TRUE(object_klass != nullptr); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 233 | Handle<mirror::Object> h_obj(hs.NewHandle(h_klass->AllocObject(soa.Self()))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 234 | ASSERT_TRUE(h_obj != nullptr); |
Vladimir Marko | dfc0de7 | 2019-04-01 10:57:55 +0100 | [diff] [blame] | 235 | ASSERT_OBJ_PTR_EQ(h_obj->GetClass(), h_klass.Get()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 236 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 237 | // Modify fields inside transaction then rollback changes. |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 238 | EnterTransactionMode(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 239 | booleanField->SetBoolean<true>(h_klass.Get(), true); |
| 240 | byteField->SetByte<true>(h_klass.Get(), 1); |
| 241 | charField->SetChar<true>(h_klass.Get(), 1u); |
| 242 | shortField->SetShort<true>(h_klass.Get(), 1); |
| 243 | intField->SetInt<true>(h_klass.Get(), 1); |
| 244 | longField->SetLong<true>(h_klass.Get(), 1); |
| 245 | floatField->SetFloat<true>(h_klass.Get(), 1.0); |
| 246 | doubleField->SetDouble<true>(h_klass.Get(), 1.0); |
| 247 | objectField->SetObject<true>(h_klass.Get(), h_obj.Get()); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 248 | RollbackAndExitTransactionMode(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 249 | |
| 250 | // Check values have properly been restored to their original (default) value. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 251 | EXPECT_EQ(booleanField->GetBoolean(h_klass.Get()), false); |
| 252 | EXPECT_EQ(byteField->GetByte(h_klass.Get()), 0); |
| 253 | EXPECT_EQ(charField->GetChar(h_klass.Get()), 0u); |
| 254 | EXPECT_EQ(shortField->GetShort(h_klass.Get()), 0); |
| 255 | EXPECT_EQ(intField->GetInt(h_klass.Get()), 0); |
| 256 | EXPECT_EQ(longField->GetLong(h_klass.Get()), static_cast<int64_t>(0)); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 257 | EXPECT_FLOAT_EQ(floatField->GetFloat(h_klass.Get()), static_cast<float>(0.0f)); |
| 258 | EXPECT_DOUBLE_EQ(doubleField->GetDouble(h_klass.Get()), static_cast<double>(0.0)); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 259 | EXPECT_EQ(objectField->GetObject(h_klass.Get()), nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 260 | } |
| 261 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 262 | // Tests instance fields are reset to their default value after transaction rollback. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 263 | TEST_F(TransactionTest, InstanceFieldsTest) { |
| 264 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 265 | StackHandleScope<5> hs(soa.Self()); |
| 266 | Handle<mirror::ClassLoader> class_loader( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 267 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(LoadDex("Transaction")))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 268 | ASSERT_TRUE(class_loader != nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 269 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 270 | Handle<mirror::Class> h_klass( |
| 271 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LInstanceFieldsTest;", class_loader))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 272 | ASSERT_TRUE(h_klass != nullptr); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 273 | bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true); |
| 274 | ASSERT_TRUE(success); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 275 | ASSERT_TRUE(h_klass->IsInitialized()); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 276 | ASSERT_FALSE(soa.Self()->IsExceptionPending()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 277 | |
| 278 | // Allocate an InstanceFieldTest object. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 279 | Handle<mirror::Object> h_instance(hs.NewHandle(h_klass->AllocObject(soa.Self()))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 280 | ASSERT_TRUE(h_instance != nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 281 | |
| 282 | // Lookup fields. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 283 | ArtField* booleanField = h_klass->FindDeclaredInstanceField("booleanField", "Z"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 284 | ASSERT_TRUE(booleanField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 285 | ASSERT_EQ(booleanField->GetTypeAsPrimitiveType(), Primitive::kPrimBoolean); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 286 | ASSERT_EQ(booleanField->GetBoolean(h_instance.Get()), false); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 287 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 288 | ArtField* byteField = h_klass->FindDeclaredInstanceField("byteField", "B"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 289 | ASSERT_TRUE(byteField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 290 | ASSERT_EQ(byteField->GetTypeAsPrimitiveType(), Primitive::kPrimByte); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 291 | ASSERT_EQ(byteField->GetByte(h_instance.Get()), 0); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 292 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 293 | ArtField* charField = h_klass->FindDeclaredInstanceField("charField", "C"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 294 | ASSERT_TRUE(charField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 295 | ASSERT_EQ(charField->GetTypeAsPrimitiveType(), Primitive::kPrimChar); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 296 | ASSERT_EQ(charField->GetChar(h_instance.Get()), 0u); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 297 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 298 | ArtField* shortField = h_klass->FindDeclaredInstanceField("shortField", "S"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 299 | ASSERT_TRUE(shortField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 300 | ASSERT_EQ(shortField->GetTypeAsPrimitiveType(), Primitive::kPrimShort); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 301 | ASSERT_EQ(shortField->GetShort(h_instance.Get()), 0); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 302 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 303 | ArtField* intField = h_klass->FindDeclaredInstanceField("intField", "I"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 304 | ASSERT_TRUE(intField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 305 | ASSERT_EQ(intField->GetTypeAsPrimitiveType(), Primitive::kPrimInt); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 306 | ASSERT_EQ(intField->GetInt(h_instance.Get()), 0); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 307 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 308 | ArtField* longField = h_klass->FindDeclaredInstanceField("longField", "J"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 309 | ASSERT_TRUE(longField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 310 | ASSERT_EQ(longField->GetTypeAsPrimitiveType(), Primitive::kPrimLong); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 311 | ASSERT_EQ(longField->GetLong(h_instance.Get()), static_cast<int64_t>(0)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 312 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 313 | ArtField* floatField = h_klass->FindDeclaredInstanceField("floatField", "F"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 314 | ASSERT_TRUE(floatField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 315 | ASSERT_EQ(floatField->GetTypeAsPrimitiveType(), Primitive::kPrimFloat); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 316 | ASSERT_FLOAT_EQ(floatField->GetFloat(h_instance.Get()), static_cast<float>(0.0f)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 317 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 318 | ArtField* doubleField = h_klass->FindDeclaredInstanceField("doubleField", "D"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 319 | ASSERT_TRUE(doubleField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 320 | ASSERT_EQ(doubleField->GetTypeAsPrimitiveType(), Primitive::kPrimDouble); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 321 | ASSERT_DOUBLE_EQ(doubleField->GetDouble(h_instance.Get()), static_cast<double>(0.0)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 322 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 323 | ArtField* objectField = h_klass->FindDeclaredInstanceField("objectField", |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 324 | "Ljava/lang/Object;"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 325 | ASSERT_TRUE(objectField != nullptr); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 326 | ASSERT_EQ(objectField->GetTypeAsPrimitiveType(), Primitive::kPrimNot); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 327 | ASSERT_EQ(objectField->GetObject(h_instance.Get()), nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 328 | |
| 329 | // Create a java.lang.Object instance to set objectField. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 330 | Handle<mirror::Class> object_klass( |
| 331 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 332 | ASSERT_TRUE(object_klass != nullptr); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 333 | Handle<mirror::Object> h_obj(hs.NewHandle(h_klass->AllocObject(soa.Self()))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 334 | ASSERT_TRUE(h_obj != nullptr); |
Vladimir Marko | dfc0de7 | 2019-04-01 10:57:55 +0100 | [diff] [blame] | 335 | ASSERT_OBJ_PTR_EQ(h_obj->GetClass(), h_klass.Get()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 336 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 337 | // Modify fields inside transaction then rollback changes. |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 338 | EnterTransactionMode(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 339 | booleanField->SetBoolean<true>(h_instance.Get(), true); |
| 340 | byteField->SetByte<true>(h_instance.Get(), 1); |
| 341 | charField->SetChar<true>(h_instance.Get(), 1u); |
| 342 | shortField->SetShort<true>(h_instance.Get(), 1); |
| 343 | intField->SetInt<true>(h_instance.Get(), 1); |
| 344 | longField->SetLong<true>(h_instance.Get(), 1); |
| 345 | floatField->SetFloat<true>(h_instance.Get(), 1.0); |
| 346 | doubleField->SetDouble<true>(h_instance.Get(), 1.0); |
| 347 | objectField->SetObject<true>(h_instance.Get(), h_obj.Get()); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 348 | RollbackAndExitTransactionMode(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 349 | |
| 350 | // Check values have properly been restored to their original (default) value. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 351 | EXPECT_EQ(booleanField->GetBoolean(h_instance.Get()), false); |
| 352 | EXPECT_EQ(byteField->GetByte(h_instance.Get()), 0); |
| 353 | EXPECT_EQ(charField->GetChar(h_instance.Get()), 0u); |
| 354 | EXPECT_EQ(shortField->GetShort(h_instance.Get()), 0); |
| 355 | EXPECT_EQ(intField->GetInt(h_instance.Get()), 0); |
| 356 | EXPECT_EQ(longField->GetLong(h_instance.Get()), static_cast<int64_t>(0)); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 357 | EXPECT_FLOAT_EQ(floatField->GetFloat(h_instance.Get()), static_cast<float>(0.0f)); |
| 358 | EXPECT_DOUBLE_EQ(doubleField->GetDouble(h_instance.Get()), static_cast<double>(0.0)); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 359 | EXPECT_EQ(objectField->GetObject(h_instance.Get()), nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 360 | } |
| 361 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 362 | // Tests static array fields are reset to their default value after transaction rollback. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 363 | TEST_F(TransactionTest, StaticArrayFieldsTest) { |
| 364 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 365 | StackHandleScope<13> hs(soa.Self()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 366 | Handle<mirror::ClassLoader> class_loader( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 367 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(LoadDex("Transaction")))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 368 | ASSERT_TRUE(class_loader != nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 369 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 370 | Handle<mirror::Class> h_klass( |
| 371 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LStaticArrayFieldsTest;", class_loader))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 372 | ASSERT_TRUE(h_klass != nullptr); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 373 | bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true); |
| 374 | ASSERT_TRUE(success); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 375 | ASSERT_TRUE(h_klass->IsInitialized()); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 376 | ASSERT_FALSE(soa.Self()->IsExceptionPending()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 377 | |
| 378 | // Lookup fields. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 379 | ArtField* booleanArrayField = h_klass->FindDeclaredStaticField("booleanArrayField", "[Z"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 380 | ASSERT_TRUE(booleanArrayField != nullptr); |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 381 | Handle<mirror::BooleanArray> booleanArray = hs.NewHandle( |
| 382 | booleanArrayField->GetObject(h_klass.Get())->AsBooleanArray()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 383 | ASSERT_TRUE(booleanArray != nullptr); |
| 384 | ASSERT_EQ(booleanArray->GetLength(), 1); |
| 385 | ASSERT_EQ(booleanArray->GetWithoutChecks(0), false); |
| 386 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 387 | ArtField* byteArrayField = h_klass->FindDeclaredStaticField("byteArrayField", "[B"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 388 | ASSERT_TRUE(byteArrayField != nullptr); |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 389 | Handle<mirror::ByteArray> byteArray = |
| 390 | hs.NewHandle(byteArrayField->GetObject(h_klass.Get())->AsByteArray()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 391 | ASSERT_TRUE(byteArray != nullptr); |
| 392 | ASSERT_EQ(byteArray->GetLength(), 1); |
| 393 | ASSERT_EQ(byteArray->GetWithoutChecks(0), 0); |
| 394 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 395 | ArtField* charArrayField = h_klass->FindDeclaredStaticField("charArrayField", "[C"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 396 | ASSERT_TRUE(charArrayField != nullptr); |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 397 | Handle<mirror::CharArray> charArray = |
| 398 | hs.NewHandle(charArrayField->GetObject(h_klass.Get())->AsCharArray()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 399 | ASSERT_TRUE(charArray != nullptr); |
| 400 | ASSERT_EQ(charArray->GetLength(), 1); |
| 401 | ASSERT_EQ(charArray->GetWithoutChecks(0), 0u); |
| 402 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 403 | ArtField* shortArrayField = h_klass->FindDeclaredStaticField("shortArrayField", "[S"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 404 | ASSERT_TRUE(shortArrayField != nullptr); |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 405 | Handle<mirror::ShortArray> shortArray = |
| 406 | hs.NewHandle(shortArrayField->GetObject(h_klass.Get())->AsShortArray()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 407 | ASSERT_TRUE(shortArray != nullptr); |
| 408 | ASSERT_EQ(shortArray->GetLength(), 1); |
| 409 | ASSERT_EQ(shortArray->GetWithoutChecks(0), 0); |
| 410 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 411 | ArtField* intArrayField = h_klass->FindDeclaredStaticField("intArrayField", "[I"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 412 | ASSERT_TRUE(intArrayField != nullptr); |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 413 | Handle<mirror::IntArray> intArray = |
| 414 | hs.NewHandle(intArrayField->GetObject(h_klass.Get())->AsIntArray()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 415 | ASSERT_TRUE(intArray != nullptr); |
| 416 | ASSERT_EQ(intArray->GetLength(), 1); |
| 417 | ASSERT_EQ(intArray->GetWithoutChecks(0), 0); |
| 418 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 419 | ArtField* longArrayField = h_klass->FindDeclaredStaticField("longArrayField", "[J"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 420 | ASSERT_TRUE(longArrayField != nullptr); |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 421 | Handle<mirror::LongArray> longArray = |
| 422 | hs.NewHandle(longArrayField->GetObject(h_klass.Get())->AsLongArray()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 423 | ASSERT_TRUE(longArray != nullptr); |
| 424 | ASSERT_EQ(longArray->GetLength(), 1); |
| 425 | ASSERT_EQ(longArray->GetWithoutChecks(0), static_cast<int64_t>(0)); |
| 426 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 427 | ArtField* floatArrayField = h_klass->FindDeclaredStaticField("floatArrayField", "[F"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 428 | ASSERT_TRUE(floatArrayField != nullptr); |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 429 | Handle<mirror::FloatArray> floatArray = |
| 430 | hs.NewHandle(floatArrayField->GetObject(h_klass.Get())->AsFloatArray()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 431 | ASSERT_TRUE(floatArray != nullptr); |
| 432 | ASSERT_EQ(floatArray->GetLength(), 1); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 433 | ASSERT_FLOAT_EQ(floatArray->GetWithoutChecks(0), static_cast<float>(0.0f)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 434 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 435 | ArtField* doubleArrayField = h_klass->FindDeclaredStaticField("doubleArrayField", "[D"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 436 | ASSERT_TRUE(doubleArrayField != nullptr); |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 437 | Handle<mirror::DoubleArray> doubleArray = |
| 438 | hs.NewHandle(doubleArrayField->GetObject(h_klass.Get())->AsDoubleArray()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 439 | ASSERT_TRUE(doubleArray != nullptr); |
| 440 | ASSERT_EQ(doubleArray->GetLength(), 1); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 441 | ASSERT_DOUBLE_EQ(doubleArray->GetWithoutChecks(0), static_cast<double>(0.0f)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 442 | |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 443 | ArtField* objectArrayField = |
| 444 | h_klass->FindDeclaredStaticField("objectArrayField", "[Ljava/lang/Object;"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 445 | ASSERT_TRUE(objectArrayField != nullptr); |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 446 | Handle<mirror::ObjectArray<mirror::Object>> objectArray = |
| 447 | hs.NewHandle(objectArrayField->GetObject(h_klass.Get())->AsObjectArray<mirror::Object>()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 448 | ASSERT_TRUE(objectArray != nullptr); |
| 449 | ASSERT_EQ(objectArray->GetLength(), 1); |
| 450 | ASSERT_EQ(objectArray->GetWithoutChecks(0), nullptr); |
| 451 | |
| 452 | // Create a java.lang.Object instance to set objectField. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 453 | Handle<mirror::Class> object_klass( |
| 454 | hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 455 | ASSERT_TRUE(object_klass != nullptr); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 456 | Handle<mirror::Object> h_obj(hs.NewHandle(h_klass->AllocObject(soa.Self()))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 457 | ASSERT_TRUE(h_obj != nullptr); |
Vladimir Marko | dfc0de7 | 2019-04-01 10:57:55 +0100 | [diff] [blame] | 458 | ASSERT_OBJ_PTR_EQ(h_obj->GetClass(), h_klass.Get()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 459 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 460 | // Modify fields inside transaction then rollback changes. |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 461 | EnterTransactionMode(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 462 | booleanArray->SetWithoutChecks<true>(0, true); |
| 463 | byteArray->SetWithoutChecks<true>(0, 1); |
| 464 | charArray->SetWithoutChecks<true>(0, 1u); |
| 465 | shortArray->SetWithoutChecks<true>(0, 1); |
| 466 | intArray->SetWithoutChecks<true>(0, 1); |
| 467 | longArray->SetWithoutChecks<true>(0, 1); |
| 468 | floatArray->SetWithoutChecks<true>(0, 1.0); |
| 469 | doubleArray->SetWithoutChecks<true>(0, 1.0); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 470 | objectArray->SetWithoutChecks<true>(0, h_obj.Get()); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 471 | RollbackAndExitTransactionMode(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 472 | |
| 473 | // Check values have properly been restored to their original (default) value. |
| 474 | EXPECT_EQ(booleanArray->GetWithoutChecks(0), false); |
| 475 | EXPECT_EQ(byteArray->GetWithoutChecks(0), 0); |
| 476 | EXPECT_EQ(charArray->GetWithoutChecks(0), 0u); |
| 477 | EXPECT_EQ(shortArray->GetWithoutChecks(0), 0); |
| 478 | EXPECT_EQ(intArray->GetWithoutChecks(0), 0); |
| 479 | EXPECT_EQ(longArray->GetWithoutChecks(0), static_cast<int64_t>(0)); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 480 | EXPECT_FLOAT_EQ(floatArray->GetWithoutChecks(0), static_cast<float>(0.0f)); |
| 481 | EXPECT_DOUBLE_EQ(doubleArray->GetWithoutChecks(0), static_cast<double>(0.0f)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 482 | EXPECT_EQ(objectArray->GetWithoutChecks(0), nullptr); |
| 483 | } |
| 484 | |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 485 | // Tests rolling back interned strings and resolved strings. |
| 486 | TEST_F(TransactionTest, ResolveString) { |
| 487 | ScopedObjectAccess soa(Thread::Current()); |
| 488 | StackHandleScope<3> hs(soa.Self()); |
| 489 | Handle<mirror::ClassLoader> class_loader( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 490 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(LoadDex("Transaction")))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 491 | ASSERT_TRUE(class_loader != nullptr); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 492 | |
| 493 | Handle<mirror::Class> h_klass( |
| 494 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LTransaction$ResolveString;", |
| 495 | class_loader))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 496 | ASSERT_TRUE(h_klass != nullptr); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 497 | |
| 498 | Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(h_klass->GetDexCache())); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 499 | ASSERT_TRUE(h_dex_cache != nullptr); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 500 | const DexFile* const dex_file = h_dex_cache->GetDexFile(); |
| 501 | ASSERT_TRUE(dex_file != nullptr); |
| 502 | |
| 503 | // Go search the dex file to find the string id of our string. |
| 504 | static const char* kResolvedString = "ResolvedString"; |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 505 | const dex::StringId* string_id = dex_file->FindStringId(kResolvedString); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 506 | ASSERT_TRUE(string_id != nullptr); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 507 | dex::StringIndex string_idx = dex_file->GetIndexForStringId(*string_id); |
| 508 | ASSERT_TRUE(string_idx.IsValid()); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 509 | // String should only get resolved by the initializer. |
Vladimir Marko | a64b52d | 2017-12-08 16:27:49 +0000 | [diff] [blame] | 510 | EXPECT_TRUE(class_linker_->LookupString(string_idx, h_dex_cache.Get()) == nullptr); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 511 | EXPECT_TRUE(h_dex_cache->GetResolvedString(string_idx) == nullptr); |
| 512 | // Do the transaction, then roll back. |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 513 | EnterTransactionMode(); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 514 | bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true); |
| 515 | ASSERT_TRUE(success); |
| 516 | ASSERT_TRUE(h_klass->IsInitialized()); |
| 517 | // Make sure the string got resolved by the transaction. |
| 518 | { |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 519 | ObjPtr<mirror::String> s = |
Vladimir Marko | a64b52d | 2017-12-08 16:27:49 +0000 | [diff] [blame] | 520 | class_linker_->LookupString(string_idx, h_dex_cache.Get()); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 521 | ASSERT_TRUE(s != nullptr); |
| 522 | EXPECT_STREQ(s->ToModifiedUtf8().c_str(), kResolvedString); |
Vladimir Marko | bcf1752 | 2018-06-01 13:14:32 +0100 | [diff] [blame] | 523 | EXPECT_OBJ_PTR_EQ(s, h_dex_cache->GetResolvedString(string_idx)); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 524 | } |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 525 | RollbackAndExitTransactionMode(); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 526 | // Check that the string did not stay resolved. |
Vladimir Marko | a64b52d | 2017-12-08 16:27:49 +0000 | [diff] [blame] | 527 | EXPECT_TRUE(class_linker_->LookupString(string_idx, h_dex_cache.Get()) == nullptr); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 528 | EXPECT_TRUE(h_dex_cache->GetResolvedString(string_idx) == nullptr); |
| 529 | ASSERT_FALSE(h_klass->IsInitialized()); |
| 530 | ASSERT_FALSE(soa.Self()->IsExceptionPending()); |
| 531 | } |
| 532 | |
Vladimir Marko | e9a4a60 | 2021-06-22 16:33:34 +0100 | [diff] [blame] | 533 | // Tests rolling back resolved method types in dex cache. |
| 534 | TEST_F(TransactionTest, ResolveMethodType) { |
| 535 | ScopedObjectAccess soa(Thread::Current()); |
| 536 | StackHandleScope<3> hs(soa.Self()); |
| 537 | Handle<mirror::ClassLoader> class_loader( |
| 538 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(LoadDex("Transaction")))); |
| 539 | ASSERT_TRUE(class_loader != nullptr); |
| 540 | |
| 541 | Handle<mirror::Class> h_klass( |
| 542 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LTransaction;", class_loader))); |
| 543 | ASSERT_TRUE(h_klass != nullptr); |
| 544 | |
| 545 | Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(h_klass->GetDexCache())); |
| 546 | ASSERT_TRUE(h_dex_cache != nullptr); |
| 547 | const DexFile* const dex_file = h_dex_cache->GetDexFile(); |
| 548 | ASSERT_TRUE(dex_file != nullptr); |
| 549 | |
| 550 | ASSERT_NE(dex_file->NumProtoIds(), 0u); |
| 551 | dex::ProtoIndex proto_index(0u); |
| 552 | ASSERT_TRUE(h_dex_cache->GetResolvedMethodType(proto_index) == nullptr); |
| 553 | |
| 554 | // Do the transaction, then roll back. |
| 555 | EnterTransactionMode(); |
| 556 | ObjPtr<mirror::MethodType> method_type = |
| 557 | class_linker_->ResolveMethodType(soa.Self(), proto_index, h_dex_cache, class_loader); |
| 558 | ASSERT_TRUE(method_type != nullptr); |
| 559 | // Make sure the method type was recorded in the dex cache. |
| 560 | ASSERT_TRUE(h_dex_cache->GetResolvedMethodType(proto_index) == method_type); |
| 561 | RollbackAndExitTransactionMode(); |
| 562 | // Check that the method type was removed from the dex cache. |
| 563 | ASSERT_TRUE(h_dex_cache->GetResolvedMethodType(proto_index) == nullptr); |
| 564 | } |
| 565 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 566 | // Tests successful class initialization without class initializer. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 567 | TEST_F(TransactionTest, EmptyClass) { |
| 568 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 569 | StackHandleScope<2> hs(soa.Self()); |
| 570 | Handle<mirror::ClassLoader> class_loader( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 571 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(LoadDex("Transaction")))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 572 | ASSERT_TRUE(class_loader != nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 573 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 574 | Handle<mirror::Class> h_klass( |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 575 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LTransaction$EmptyStatic;", |
| 576 | class_loader))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 577 | ASSERT_TRUE(h_klass != nullptr); |
Nicolas Geoffray | 5b0b2e1 | 2021-03-19 14:48:40 +0000 | [diff] [blame] | 578 | class_linker_->VerifyClass(soa.Self(), /* verifier_deps= */ nullptr, h_klass); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 579 | ASSERT_TRUE(h_klass->IsVerified()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 580 | |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 581 | EnterTransactionMode(); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 582 | bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 583 | ExitTransactionMode(); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 584 | ASSERT_TRUE(success); |
| 585 | ASSERT_TRUE(h_klass->IsInitialized()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 586 | ASSERT_FALSE(soa.Self()->IsExceptionPending()); |
| 587 | } |
| 588 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 589 | // Tests successful class initialization with class initializer. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 590 | TEST_F(TransactionTest, StaticFieldClass) { |
| 591 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 592 | StackHandleScope<2> hs(soa.Self()); |
| 593 | Handle<mirror::ClassLoader> class_loader( |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 594 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(LoadDex("Transaction")))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 595 | ASSERT_TRUE(class_loader != nullptr); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 596 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 597 | Handle<mirror::Class> h_klass( |
| 598 | hs.NewHandle(class_linker_->FindClass(soa.Self(), "LTransaction$StaticFieldClass;", |
| 599 | class_loader))); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 600 | ASSERT_TRUE(h_klass != nullptr); |
Nicolas Geoffray | 5b0b2e1 | 2021-03-19 14:48:40 +0000 | [diff] [blame] | 601 | class_linker_->VerifyClass(soa.Self(), /* verifier_deps= */ nullptr, h_klass); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 602 | ASSERT_TRUE(h_klass->IsVerified()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 603 | |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 604 | EnterTransactionMode(); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 605 | bool success = class_linker_->EnsureInitialized(soa.Self(), h_klass, true, true); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 606 | ExitTransactionMode(); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 607 | ASSERT_TRUE(success); |
| 608 | ASSERT_TRUE(h_klass->IsInitialized()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 609 | ASSERT_FALSE(soa.Self()->IsExceptionPending()); |
| 610 | } |
| 611 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 612 | // Tests failing class initialization due to native call. |
| 613 | TEST_F(TransactionTest, NativeCallAbortClass) { |
| 614 | testTransactionAbort("LTransaction$NativeCallAbortClass;"); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 615 | } |
| 616 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 617 | // Tests failing class initialization due to native call in a "synchronized" statement |
| 618 | // (which must catch any exception, do the monitor-exit then re-throw the caught exception). |
| 619 | TEST_F(TransactionTest, SynchronizedNativeCallAbortClass) { |
| 620 | testTransactionAbort("LTransaction$SynchronizedNativeCallAbortClass;"); |
| 621 | } |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 622 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 623 | // Tests failing class initialization due to native call, even if an "all" catch handler |
| 624 | // catches the exception thrown when aborting the transaction. |
| 625 | TEST_F(TransactionTest, CatchNativeCallAbortClass) { |
| 626 | testTransactionAbort("LTransaction$CatchNativeCallAbortClass;"); |
| 627 | } |
| 628 | |
| 629 | // Tests failing class initialization with multiple transaction aborts. |
| 630 | TEST_F(TransactionTest, MultipleNativeCallAbortClass) { |
| 631 | testTransactionAbort("LTransaction$MultipleNativeCallAbortClass;"); |
| 632 | } |
| 633 | |
Vladimir Marko | 0685b98 | 2021-03-25 11:59:22 +0000 | [diff] [blame] | 634 | // Tests failing class initialization due to Class.forName() not finding the class, |
| 635 | // even if an "all" catch handler catches the exception thrown when aborting the transaction. |
| 636 | TEST_F(TransactionTest, CatchClassForNameAbortClass) { |
| 637 | testTransactionAbort("LTransaction$CatchClassForNameAbortClass;"); |
| 638 | } |
| 639 | |
| 640 | // Same as CatchClassForNameAbortClass but the class initializer tries to do the work twice. |
| 641 | // This would trigger a DCHECK() if we continued executing bytecode with an aborted transaction. |
| 642 | TEST_F(TransactionTest, CatchClassForNameAbortClassTwice) { |
| 643 | testTransactionAbort("LTransaction$CatchClassForNameAbortClassTwice;"); |
| 644 | } |
| 645 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 646 | // Tests failing class initialization due to allocating instance of finalizable class. |
| 647 | TEST_F(TransactionTest, FinalizableAbortClass) { |
| 648 | testTransactionAbort("LTransaction$FinalizableAbortClass;"); |
| 649 | } |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 650 | |
| 651 | TEST_F(TransactionTest, Constraints) { |
| 652 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 653 | StackHandleScope<11> hs(soa.Self()); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 654 | Handle<mirror::ClassLoader> class_loader( |
| 655 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(LoadDex("Transaction")))); |
| 656 | |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 657 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 658 | Handle<mirror::Class> boolean_class = hs.NewHandle( |
| 659 | class_linker_->FindClass(soa.Self(), "Ljava/lang/Boolean;", class_loader)); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 660 | ASSERT_TRUE(boolean_class != nullptr); |
| 661 | ASSERT_TRUE(heap->ObjectIsInBootImageSpace(boolean_class.Get())); |
Vladimir Marko | e300c4e | 2021-06-08 16:00:05 +0100 | [diff] [blame] | 662 | ArtField* true_field = boolean_class->FindDeclaredStaticField("TRUE", "Ljava/lang/Boolean;"); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 663 | ASSERT_TRUE(true_field != nullptr); |
| 664 | ASSERT_TRUE(true_field->IsStatic()); |
| 665 | Handle<mirror::Object> true_value = hs.NewHandle(true_field->GetObject(boolean_class.Get())); |
| 666 | ASSERT_TRUE(true_value != nullptr); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 667 | ASSERT_TRUE(heap->ObjectIsInBootImageSpace(true_value.Get())); |
Vladimir Marko | e300c4e | 2021-06-08 16:00:05 +0100 | [diff] [blame] | 668 | ArtField* value_field = boolean_class->FindDeclaredInstanceField("value", "Z"); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 669 | ASSERT_TRUE(value_field != nullptr); |
| 670 | ASSERT_FALSE(value_field->IsStatic()); |
| 671 | |
| 672 | Handle<mirror::Class> static_field_class(hs.NewHandle( |
| 673 | class_linker_->FindClass(soa.Self(), "LTransaction$StaticFieldClass;", class_loader))); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 674 | ASSERT_TRUE(static_field_class != nullptr); |
| 675 | ASSERT_FALSE(heap->ObjectIsInBootImageSpace(static_field_class.Get())); |
Vladimir Marko | e300c4e | 2021-06-08 16:00:05 +0100 | [diff] [blame] | 676 | ArtField* int_field = static_field_class->FindDeclaredStaticField("intField", "I"); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 677 | ASSERT_TRUE(int_field != nullptr); |
| 678 | |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 679 | Handle<mirror::Class> static_fields_test_class(hs.NewHandle( |
| 680 | class_linker_->FindClass(soa.Self(), "LStaticFieldsTest;", class_loader))); |
| 681 | ASSERT_TRUE(static_fields_test_class != nullptr); |
| 682 | ASSERT_FALSE(heap->ObjectIsInBootImageSpace(static_fields_test_class.Get())); |
| 683 | ArtField* static_fields_test_int_field = |
Vladimir Marko | e300c4e | 2021-06-08 16:00:05 +0100 | [diff] [blame] | 684 | static_fields_test_class->FindDeclaredStaticField("intField", "I"); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 685 | ASSERT_TRUE(static_fields_test_int_field != nullptr); |
| 686 | |
| 687 | Handle<mirror::Class> instance_fields_test_class(hs.NewHandle( |
| 688 | class_linker_->FindClass(soa.Self(), "LInstanceFieldsTest;", class_loader))); |
| 689 | ASSERT_TRUE(instance_fields_test_class != nullptr); |
| 690 | ASSERT_FALSE(heap->ObjectIsInBootImageSpace(instance_fields_test_class.Get())); |
| 691 | ArtField* instance_fields_test_int_field = |
Vladimir Marko | e300c4e | 2021-06-08 16:00:05 +0100 | [diff] [blame] | 692 | instance_fields_test_class->FindDeclaredInstanceField("intField", "I"); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 693 | ASSERT_TRUE(instance_fields_test_int_field != nullptr); |
| 694 | Handle<mirror::Object> instance_fields_test_object = hs.NewHandle( |
| 695 | instance_fields_test_class->Alloc(soa.Self(), heap->GetCurrentAllocator())); |
| 696 | ASSERT_TRUE(instance_fields_test_object != nullptr); |
| 697 | ASSERT_FALSE(heap->ObjectIsInBootImageSpace(instance_fields_test_object.Get())); |
| 698 | |
Vladimir Marko | a982cd6 | 2020-08-17 14:13:57 +0000 | [diff] [blame] | 699 | // The `long[].class` should be in the boot image but `long[][][].class` should not. |
| 700 | // (We have seen `long[][].class` both present and missing from the boot image, |
| 701 | // depending on the libcore code, so we do not use it for this test.) |
| 702 | Handle<mirror::Class> long_array_dim3_class = hs.NewHandle( |
| 703 | class_linker_->FindClass(soa.Self(), "[[[J", class_loader)); |
| 704 | ASSERT_TRUE(long_array_dim3_class != nullptr); |
| 705 | ASSERT_FALSE(heap->ObjectIsInBootImageSpace(long_array_dim3_class.Get())); |
| 706 | ASSERT_TRUE(heap->ObjectIsInBootImageSpace( |
| 707 | long_array_dim3_class->GetComponentType()->GetComponentType())); |
| 708 | Handle<mirror::Array> long_array_dim3 = hs.NewHandle(mirror::Array::Alloc( |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 709 | soa.Self(), |
Vladimir Marko | a982cd6 | 2020-08-17 14:13:57 +0000 | [diff] [blame] | 710 | long_array_dim3_class.Get(), |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 711 | /*component_count=*/ 1, |
Vladimir Marko | a982cd6 | 2020-08-17 14:13:57 +0000 | [diff] [blame] | 712 | long_array_dim3_class->GetComponentSizeShift(), |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 713 | heap->GetCurrentAllocator())); |
Vladimir Marko | a982cd6 | 2020-08-17 14:13:57 +0000 | [diff] [blame] | 714 | ASSERT_TRUE(long_array_dim3 != nullptr); |
| 715 | ASSERT_FALSE(heap->ObjectIsInBootImageSpace(long_array_dim3.Get())); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 716 | Handle<mirror::Array> long_array = hs.NewHandle(mirror::Array::Alloc( |
| 717 | soa.Self(), |
Vladimir Marko | a982cd6 | 2020-08-17 14:13:57 +0000 | [diff] [blame] | 718 | long_array_dim3_class->GetComponentType()->GetComponentType(), |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 719 | /*component_count=*/ 1, |
Vladimir Marko | a982cd6 | 2020-08-17 14:13:57 +0000 | [diff] [blame] | 720 | long_array_dim3_class->GetComponentType()->GetComponentType()->GetComponentSizeShift(), |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 721 | heap->GetCurrentAllocator())); |
| 722 | ASSERT_TRUE(long_array != nullptr); |
| 723 | ASSERT_FALSE(heap->ObjectIsInBootImageSpace(long_array.Get())); |
| 724 | |
| 725 | // Use the Array's IfTable as an array from the boot image. |
| 726 | Handle<mirror::ObjectArray<mirror::Object>> array_iftable = |
Vladimir Marko | a982cd6 | 2020-08-17 14:13:57 +0000 | [diff] [blame] | 727 | hs.NewHandle(long_array_dim3_class->GetIfTable()); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 728 | ASSERT_TRUE(array_iftable != nullptr); |
| 729 | ASSERT_TRUE(heap->ObjectIsInBootImageSpace(array_iftable.Get())); |
Vladimir Marko | 149cdda | 2019-11-12 15:02:51 +0000 | [diff] [blame] | 730 | |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 731 | // Test non-strict transaction. |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 732 | ArenaPool* arena_pool = Runtime::Current()->GetArenaPool(); |
| 733 | Transaction transaction( |
| 734 | /*strict=*/ false, /*root=*/ nullptr, /*arena_stack=*/ nullptr, arena_pool); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 735 | // Static field in boot image. |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 736 | EXPECT_TRUE(transaction.WriteConstraint(boolean_class.Get())); |
| 737 | EXPECT_FALSE(transaction.ReadConstraint(boolean_class.Get())); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 738 | // Instance field or array element in boot image. |
| 739 | // Do not check ReadConstraint(), it expects only static fields (checks for class object). |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 740 | EXPECT_TRUE(transaction.WriteConstraint(true_value.Get())); |
| 741 | EXPECT_TRUE(transaction.WriteConstraint(array_iftable.Get())); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 742 | // Static field not in boot image. |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 743 | EXPECT_FALSE(transaction.WriteConstraint(static_fields_test_class.Get())); |
| 744 | EXPECT_FALSE(transaction.ReadConstraint(static_fields_test_class.Get())); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 745 | // Instance field or array element not in boot image. |
| 746 | // Do not check ReadConstraint(), it expects only static fields (checks for class object). |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 747 | EXPECT_FALSE(transaction.WriteConstraint(instance_fields_test_object.Get())); |
| 748 | EXPECT_FALSE(transaction.WriteConstraint(long_array_dim3.Get())); |
Vladimir Marko | 149cdda | 2019-11-12 15:02:51 +0000 | [diff] [blame] | 749 | // Write value constraints. |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 750 | EXPECT_FALSE(transaction.WriteValueConstraint(static_fields_test_class.Get())); |
| 751 | EXPECT_FALSE(transaction.WriteValueConstraint(instance_fields_test_object.Get())); |
| 752 | EXPECT_TRUE(transaction.WriteValueConstraint(long_array_dim3->GetClass())); |
| 753 | EXPECT_TRUE(transaction.WriteValueConstraint(long_array_dim3.Get())); |
| 754 | EXPECT_FALSE(transaction.WriteValueConstraint(long_array->GetClass())); |
| 755 | EXPECT_FALSE(transaction.WriteValueConstraint(long_array.Get())); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 756 | |
| 757 | // Test strict transaction. |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 758 | Transaction strict_transaction( |
| 759 | /*strict=*/ true, /*root=*/ static_field_class.Get(), /*arena_stack=*/ nullptr, arena_pool); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 760 | // Static field in boot image. |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 761 | EXPECT_TRUE(strict_transaction.WriteConstraint(boolean_class.Get())); |
| 762 | EXPECT_TRUE(strict_transaction.ReadConstraint(boolean_class.Get())); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 763 | // Instance field or array element in boot image. |
| 764 | // Do not check ReadConstraint(), it expects only static fields (checks for class object). |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 765 | EXPECT_TRUE(strict_transaction.WriteConstraint(true_value.Get())); |
| 766 | EXPECT_TRUE(strict_transaction.WriteConstraint(array_iftable.Get())); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 767 | // Static field in another class not in boot image. |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 768 | EXPECT_TRUE(strict_transaction.WriteConstraint(static_fields_test_class.Get())); |
| 769 | EXPECT_TRUE(strict_transaction.ReadConstraint(static_fields_test_class.Get())); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 770 | // Instance field or array element not in boot image. |
| 771 | // Do not check ReadConstraint(), it expects only static fields (checks for class object). |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 772 | EXPECT_FALSE(strict_transaction.WriteConstraint(instance_fields_test_object.Get())); |
| 773 | EXPECT_FALSE(strict_transaction.WriteConstraint(long_array_dim3.Get())); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 774 | // Static field in the same class. |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 775 | EXPECT_FALSE(strict_transaction.WriteConstraint(static_field_class.Get())); |
| 776 | EXPECT_FALSE(strict_transaction.ReadConstraint(static_field_class.Get())); |
Vladimir Marko | 149cdda | 2019-11-12 15:02:51 +0000 | [diff] [blame] | 777 | // Write value constraints. |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 778 | EXPECT_FALSE(strict_transaction.WriteValueConstraint(static_fields_test_class.Get())); |
| 779 | EXPECT_FALSE(strict_transaction.WriteValueConstraint(instance_fields_test_object.Get())); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 780 | // TODO: The following may be revised, see a TODO in Transaction::WriteValueConstraint(). |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 781 | EXPECT_FALSE(strict_transaction.WriteValueConstraint(long_array_dim3->GetClass())); |
| 782 | EXPECT_FALSE(strict_transaction.WriteValueConstraint(long_array_dim3.Get())); |
| 783 | EXPECT_FALSE(strict_transaction.WriteValueConstraint(long_array->GetClass())); |
| 784 | EXPECT_FALSE(strict_transaction.WriteValueConstraint(long_array.Get())); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 785 | } |
| 786 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 787 | } // namespace art |