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 | |
| 17 | #include "transaction.h" |
| 18 | |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 19 | #include <android-base/logging.h> |
| 20 | |
Vladimir Marko | 7ed2d38 | 2019-11-25 10:41:53 +0000 | [diff] [blame] | 21 | #include "aot_class_linker.h" |
Andreas Gampe | 88dbad3 | 2018-06-26 19:54:12 -0700 | [diff] [blame] | 22 | #include "base/mutex-inl.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 23 | #include "base/stl_util.h" |
Vladimir Marko | 0685b98 | 2021-03-25 11:59:22 +0000 | [diff] [blame] | 24 | #include "dex/descriptors_names.h" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table-inl.h" |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 26 | #include "gc/heap.h" |
Andreas Gampe | 508fdf3 | 2017-06-05 16:42:13 -0700 | [diff] [blame] | 27 | #include "gc_root-inl.h" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 28 | #include "intern_table.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Andreas Gampe | 508fdf3 | 2017-06-05 16:42:13 -0700 | [diff] [blame] | 30 | #include "mirror/dex_cache-inl.h" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 31 | #include "mirror/object-inl.h" |
| 32 | #include "mirror/object_array-inl.h" |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 33 | #include "obj_ptr-inl.h" |
| 34 | #include "runtime.h" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 35 | |
| 36 | #include <list> |
| 37 | |
| 38 | namespace art { |
| 39 | |
| 40 | // TODO: remove (only used for debugging purpose). |
| 41 | static constexpr bool kEnableTransactionStats = false; |
| 42 | |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 43 | Transaction::Transaction(bool strict, |
| 44 | mirror::Class* root, |
| 45 | ArenaStack* arena_stack, |
| 46 | ArenaPool* arena_pool) |
| 47 | : arena_stack_(std::nullopt), |
| 48 | allocator_(arena_stack != nullptr ? arena_stack : &arena_stack_.emplace(arena_pool)), |
| 49 | object_logs_(std::less<mirror::Object*>(), allocator_.Adapter(kArenaAllocTransaction)), |
| 50 | array_logs_(std::less<mirror::Array*>(), allocator_.Adapter(kArenaAllocTransaction)), |
| 51 | intern_string_logs_(allocator_.Adapter(kArenaAllocTransaction)), |
| 52 | resolve_string_logs_(allocator_.Adapter(kArenaAllocTransaction)), |
| 53 | resolve_method_type_logs_(allocator_.Adapter(kArenaAllocTransaction)), |
| 54 | aborted_(false), |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 55 | rolling_back_(false), |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 56 | heap_(Runtime::Current()->GetHeap()), |
| 57 | strict_(strict), |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 58 | root_(root), |
| 59 | assert_no_new_records_reason_(nullptr) { |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 60 | DCHECK(Runtime::Current()->IsAotCompiler()); |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 61 | DCHECK_NE(arena_stack != nullptr, arena_pool != nullptr); |
Chang Xing | cade5c3 | 2017-07-20 17:56:26 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 64 | Transaction::~Transaction() { |
| 65 | if (kEnableTransactionStats) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 66 | size_t objects_count = object_logs_.size(); |
| 67 | size_t field_values_count = 0; |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 68 | for (const auto& it : object_logs_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 69 | field_values_count += it.second.Size(); |
| 70 | } |
| 71 | size_t array_count = array_logs_.size(); |
| 72 | size_t array_values_count = 0; |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 73 | for (const auto& it : array_logs_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 74 | array_values_count += it.second.Size(); |
| 75 | } |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 76 | size_t intern_string_count = |
| 77 | std::distance(intern_string_logs_.begin(), intern_string_logs_.end()); |
| 78 | size_t resolve_string_count = |
| 79 | std::distance(resolve_string_logs_.begin(), resolve_string_logs_.end()); |
| 80 | size_t resolve_method_type_count = |
| 81 | std::distance(resolve_method_type_logs_.begin(), resolve_method_type_logs_.end()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 82 | LOG(INFO) << "Transaction::~Transaction" |
| 83 | << ": objects_count=" << objects_count |
| 84 | << ", field_values_count=" << field_values_count |
| 85 | << ", array_count=" << array_count |
| 86 | << ", array_values_count=" << array_values_count |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 87 | << ", intern_string_count=" << intern_string_count |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 88 | << ", resolve_string_count=" << resolve_string_count |
| 89 | << ", resolve_method_type_count=" << resolve_method_type_count; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 93 | void Transaction::Abort(const std::string& abort_message) { |
Sebastien Hertz | 2fd7e69 | 2015-04-02 11:11:19 +0200 | [diff] [blame] | 94 | // We may abort more than once if the exception thrown at the time of the |
| 95 | // previous abort has been caught during execution of a class initializer. |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 96 | // We just keep the message of the first abort because it will cause the |
| 97 | // transaction to be rolled back anyway. |
| 98 | if (!aborted_) { |
| 99 | aborted_ = true; |
| 100 | abort_message_ = abort_message; |
| 101 | } |
| 102 | } |
| 103 | |
Sebastien Hertz | b81e1cd | 2015-04-28 12:31:41 +0200 | [diff] [blame] | 104 | void Transaction::ThrowAbortError(Thread* self, const std::string* abort_message) { |
| 105 | const bool rethrow = (abort_message == nullptr); |
Sebastien Hertz | bd9cf9f | 2015-03-03 12:16:13 +0100 | [diff] [blame] | 106 | if (kIsDebugBuild && rethrow) { |
Vladimir Marko | 0685b98 | 2021-03-25 11:59:22 +0000 | [diff] [blame] | 107 | CHECK(IsAborted()) << "Rethrow " << DescriptorToDot(Transaction::kAbortExceptionDescriptor) |
Sebastien Hertz | 2fd7e69 | 2015-04-02 11:11:19 +0200 | [diff] [blame] | 108 | << " while transaction is not aborted"; |
Sebastien Hertz | bd9cf9f | 2015-03-03 12:16:13 +0100 | [diff] [blame] | 109 | } |
Sebastien Hertz | b81e1cd | 2015-04-28 12:31:41 +0200 | [diff] [blame] | 110 | if (rethrow) { |
| 111 | // Rethrow an exception with the earlier abort message stored in the transaction. |
Vladimir Marko | 0685b98 | 2021-03-25 11:59:22 +0000 | [diff] [blame] | 112 | self->ThrowNewWrappedException(Transaction::kAbortExceptionDescriptor, |
Sebastien Hertz | b81e1cd | 2015-04-28 12:31:41 +0200 | [diff] [blame] | 113 | GetAbortMessage().c_str()); |
| 114 | } else { |
| 115 | // Throw an exception with the given abort message. |
Vladimir Marko | 0685b98 | 2021-03-25 11:59:22 +0000 | [diff] [blame] | 116 | self->ThrowNewWrappedException(Transaction::kAbortExceptionDescriptor, |
Sebastien Hertz | b81e1cd | 2015-04-28 12:31:41 +0200 | [diff] [blame] | 117 | abort_message->c_str()); |
| 118 | } |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 121 | const std::string& Transaction::GetAbortMessage() const { |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 122 | return abort_message_; |
| 123 | } |
| 124 | |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 125 | bool Transaction::WriteConstraint(ObjPtr<mirror::Object> obj) const { |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 126 | DCHECK(obj != nullptr); |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 127 | |
| 128 | // Prevent changes in boot image spaces for app or boot image extension. |
| 129 | // For boot image there are no boot image spaces and this condition evaluates to false. |
| 130 | if (heap_->ObjectIsInBootImageSpace(obj)) { |
| 131 | return true; |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 132 | } |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 133 | |
| 134 | // For apps, also prevent writing to other classes. |
| 135 | return IsStrict() && |
| 136 | obj->IsClass() && // no constraint updating instances or arrays |
| 137 | obj != root_; // modifying other classes' static field, fail |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 140 | bool Transaction::WriteValueConstraint(ObjPtr<mirror::Object> value) const { |
Vladimir Marko | 149cdda | 2019-11-12 15:02:51 +0000 | [diff] [blame] | 141 | if (value == nullptr) { |
| 142 | return false; // We can always store null values. |
| 143 | } |
| 144 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
Vladimir Marko | 149cdda | 2019-11-12 15:02:51 +0000 | [diff] [blame] | 145 | if (IsStrict()) { |
| 146 | // TODO: Should we restrict writes the same way as for boot image extension? |
| 147 | return false; |
| 148 | } else if (heap->GetBootImageSpaces().empty()) { |
| 149 | return false; // No constraints for boot image. |
| 150 | } else { |
| 151 | // Boot image extension. |
Vladimir Marko | 149cdda | 2019-11-12 15:02:51 +0000 | [diff] [blame] | 152 | ObjPtr<mirror::Class> klass = value->IsClass() ? value->AsClass() : value->GetClass(); |
Vladimir Marko | 7ed2d38 | 2019-11-25 10:41:53 +0000 | [diff] [blame] | 153 | return !AotClassLinker::CanReferenceInBootImageExtension(klass, heap); |
Vladimir Marko | 149cdda | 2019-11-12 15:02:51 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 157 | bool Transaction::ReadConstraint(ObjPtr<mirror::Object> obj) const { |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 158 | // Read constraints are checked only for static field reads as there are |
| 159 | // no constraints on reading instance fields and array elements. |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 160 | DCHECK(obj->IsClass()); |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 161 | if (IsStrict()) { |
| 162 | return obj != root_; // fail if not self-updating |
| 163 | } else { |
| 164 | // For boot image and boot image extension, allow reading any field. |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 165 | return false; |
| 166 | } |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 169 | inline Transaction::ObjectLog& Transaction::GetOrCreateObjectLog(mirror::Object* obj) { |
| 170 | return object_logs_.GetOrCreate(obj, [&]() { return ObjectLog(&allocator_); }); |
| 171 | } |
| 172 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 173 | void Transaction::RecordWriteFieldBoolean(mirror::Object* obj, |
| 174 | MemberOffset field_offset, |
| 175 | uint8_t value, |
| 176 | bool is_volatile) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 177 | DCHECK(obj != nullptr); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 178 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 179 | ObjectLog& object_log = GetOrCreateObjectLog(obj); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 180 | object_log.LogBooleanValue(field_offset, value, is_volatile); |
| 181 | } |
| 182 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 183 | void Transaction::RecordWriteFieldByte(mirror::Object* obj, |
| 184 | MemberOffset field_offset, |
| 185 | int8_t value, |
| 186 | bool is_volatile) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 187 | DCHECK(obj != nullptr); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 188 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 189 | ObjectLog& object_log = GetOrCreateObjectLog(obj); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 190 | object_log.LogByteValue(field_offset, value, is_volatile); |
| 191 | } |
| 192 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 193 | void Transaction::RecordWriteFieldChar(mirror::Object* obj, |
| 194 | MemberOffset field_offset, |
| 195 | uint16_t value, |
| 196 | bool is_volatile) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 197 | DCHECK(obj != nullptr); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 198 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 199 | ObjectLog& object_log = GetOrCreateObjectLog(obj); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 200 | object_log.LogCharValue(field_offset, value, is_volatile); |
| 201 | } |
| 202 | |
| 203 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 204 | void Transaction::RecordWriteFieldShort(mirror::Object* obj, |
| 205 | MemberOffset field_offset, |
| 206 | int16_t value, |
| 207 | bool is_volatile) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 208 | DCHECK(obj != nullptr); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 209 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 210 | ObjectLog& object_log = GetOrCreateObjectLog(obj); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 211 | object_log.LogShortValue(field_offset, value, is_volatile); |
| 212 | } |
| 213 | |
| 214 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 215 | void Transaction::RecordWriteField32(mirror::Object* obj, |
| 216 | MemberOffset field_offset, |
| 217 | uint32_t value, |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 218 | bool is_volatile) { |
| 219 | DCHECK(obj != nullptr); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 220 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 221 | ObjectLog& object_log = GetOrCreateObjectLog(obj); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 222 | object_log.Log32BitsValue(field_offset, value, is_volatile); |
| 223 | } |
| 224 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 225 | void Transaction::RecordWriteField64(mirror::Object* obj, |
| 226 | MemberOffset field_offset, |
| 227 | uint64_t value, |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 228 | bool is_volatile) { |
| 229 | DCHECK(obj != nullptr); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 230 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 231 | ObjectLog& object_log = GetOrCreateObjectLog(obj); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 232 | object_log.Log64BitsValue(field_offset, value, is_volatile); |
| 233 | } |
| 234 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 235 | void Transaction::RecordWriteFieldReference(mirror::Object* obj, |
| 236 | MemberOffset field_offset, |
| 237 | mirror::Object* value, |
| 238 | bool is_volatile) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 239 | DCHECK(obj != nullptr); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 240 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 241 | ObjectLog& object_log = GetOrCreateObjectLog(obj); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 242 | object_log.LogReferenceValue(field_offset, value, is_volatile); |
| 243 | } |
| 244 | |
| 245 | void Transaction::RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) { |
| 246 | DCHECK(array != nullptr); |
| 247 | DCHECK(array->IsArrayInstance()); |
Sebastien Hertz | ee1d79a | 2014-02-21 15:46:30 +0100 | [diff] [blame] | 248 | DCHECK(!array->IsObjectArray()); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 249 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 250 | ArrayLog& array_log = array_logs_.GetOrCreate(array, [&]() { return ArrayLog(&allocator_); }); |
| 251 | array_log.LogValue(index, value); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 254 | void Transaction::RecordResolveString(ObjPtr<mirror::DexCache> dex_cache, |
| 255 | dex::StringIndex string_idx) { |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 256 | DCHECK(dex_cache != nullptr); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 257 | DCHECK_LT(string_idx.index_, dex_cache->GetDexFile()->NumStringIds()); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 258 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 259 | resolve_string_logs_.emplace_front(dex_cache, string_idx); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Vladimir Marko | e9a4a60 | 2021-06-22 16:33:34 +0100 | [diff] [blame] | 262 | void Transaction::RecordResolveMethodType(ObjPtr<mirror::DexCache> dex_cache, |
| 263 | dex::ProtoIndex proto_idx) { |
| 264 | DCHECK(dex_cache != nullptr); |
| 265 | DCHECK_LT(proto_idx.index_, dex_cache->GetDexFile()->NumProtoIds()); |
Vladimir Marko | e9a4a60 | 2021-06-22 16:33:34 +0100 | [diff] [blame] | 266 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 267 | resolve_method_type_logs_.emplace_front(dex_cache, proto_idx); |
Vladimir Marko | e9a4a60 | 2021-06-22 16:33:34 +0100 | [diff] [blame] | 268 | } |
| 269 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 270 | void Transaction::RecordStrongStringInsertion(ObjPtr<mirror::String> s) { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 271 | InternStringLog log(s, InternStringLog::kStrongString, InternStringLog::kInsert); |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 272 | LogInternedString(std::move(log)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 275 | void Transaction::RecordWeakStringInsertion(ObjPtr<mirror::String> s) { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 276 | InternStringLog log(s, InternStringLog::kWeakString, InternStringLog::kInsert); |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 277 | LogInternedString(std::move(log)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 278 | } |
| 279 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 280 | void Transaction::RecordStrongStringRemoval(ObjPtr<mirror::String> s) { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 281 | InternStringLog log(s, InternStringLog::kStrongString, InternStringLog::kRemove); |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 282 | LogInternedString(std::move(log)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 285 | void Transaction::RecordWeakStringRemoval(ObjPtr<mirror::String> s) { |
Mathieu Chartier | cdfd39f | 2014-08-29 18:16:58 -0700 | [diff] [blame] | 286 | InternStringLog log(s, InternStringLog::kWeakString, InternStringLog::kRemove); |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 287 | LogInternedString(std::move(log)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 288 | } |
| 289 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 290 | void Transaction::LogInternedString(InternStringLog&& log) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 291 | Locks::intern_table_lock_->AssertExclusiveHeld(Thread::Current()); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 292 | DCHECK(assert_no_new_records_reason_ == nullptr) << assert_no_new_records_reason_; |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 293 | intern_string_logs_.push_front(std::move(log)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 294 | } |
| 295 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 296 | void Transaction::Rollback() { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 297 | Thread* self = Thread::Current(); |
| 298 | self->AssertNoPendingException(); |
Vladimir Marko | 24c080f | 2021-07-06 14:04:30 +0100 | [diff] [blame] | 299 | MutexLock mu(self, *Locks::intern_table_lock_); |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 300 | rolling_back_ = true; |
| 301 | CHECK(!Runtime::Current()->IsActiveTransaction()); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 302 | UndoObjectModifications(); |
| 303 | UndoArrayModifications(); |
| 304 | UndoInternStringTableModifications(); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 305 | UndoResolveStringModifications(); |
Vladimir Marko | e9a4a60 | 2021-06-22 16:33:34 +0100 | [diff] [blame] | 306 | UndoResolveMethodTypeModifications(); |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 307 | rolling_back_ = false; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void Transaction::UndoObjectModifications() { |
| 311 | // TODO we may not need to restore objects allocated during this transaction. Or we could directly |
| 312 | // remove them from the heap. |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 313 | for (const auto& it : object_logs_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 314 | it.second.Undo(it.first); |
| 315 | } |
| 316 | object_logs_.clear(); |
| 317 | } |
| 318 | |
| 319 | void Transaction::UndoArrayModifications() { |
| 320 | // TODO we may not need to restore array allocated during this transaction. Or we could directly |
| 321 | // remove them from the heap. |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 322 | for (const auto& it : array_logs_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 323 | it.second.Undo(it.first); |
| 324 | } |
| 325 | array_logs_.clear(); |
| 326 | } |
| 327 | |
| 328 | void Transaction::UndoInternStringTableModifications() { |
| 329 | InternTable* const intern_table = Runtime::Current()->GetInternTable(); |
| 330 | // We want to undo each operation from the most recent to the oldest. List has been filled so the |
| 331 | // most recent operation is at list begin so just have to iterate over it. |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 332 | for (const InternStringLog& string_log : intern_string_logs_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 333 | string_log.Undo(intern_table); |
| 334 | } |
| 335 | intern_string_logs_.clear(); |
| 336 | } |
| 337 | |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 338 | void Transaction::UndoResolveStringModifications() { |
| 339 | for (ResolveStringLog& string_log : resolve_string_logs_) { |
| 340 | string_log.Undo(); |
| 341 | } |
| 342 | resolve_string_logs_.clear(); |
| 343 | } |
| 344 | |
Vladimir Marko | e9a4a60 | 2021-06-22 16:33:34 +0100 | [diff] [blame] | 345 | void Transaction::UndoResolveMethodTypeModifications() { |
| 346 | for (ResolveMethodTypeLog& method_type_log : resolve_method_type_logs_) { |
| 347 | method_type_log.Undo(); |
| 348 | } |
| 349 | resolve_method_type_logs_.clear(); |
| 350 | } |
| 351 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 352 | void Transaction::VisitRoots(RootVisitor* visitor) { |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 353 | // Transactions are used for single-threaded initialization. |
| 354 | // This is the only function that should be called from a different thread, |
| 355 | // namely the GC thread, and it is called with the mutator lock held exclusively, |
| 356 | // so the data structures in the `Transaction` are protected from concurrent use. |
| 357 | DCHECK(Locks::mutator_lock_->IsExclusiveHeld(Thread::Current())); |
| 358 | |
Chang Xing | cade5c3 | 2017-07-20 17:56:26 -0700 | [diff] [blame] | 359 | visitor->VisitRoot(reinterpret_cast<mirror::Object**>(&root_), RootInfo(kRootUnknown)); |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 360 | { |
| 361 | // Create a separate `ArenaStack` for this thread. |
| 362 | ArenaStack arena_stack(Runtime::Current()->GetArenaPool()); |
| 363 | VisitObjectLogs(visitor, &arena_stack); |
| 364 | VisitArrayLogs(visitor, &arena_stack); |
| 365 | } |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 366 | VisitInternStringLogs(visitor); |
| 367 | VisitResolveStringLogs(visitor); |
Vladimir Marko | e9a4a60 | 2021-06-22 16:33:34 +0100 | [diff] [blame] | 368 | VisitResolveMethodTypeLogs(visitor); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 369 | } |
| 370 | |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 371 | template <typename MovingRoots, typename Container> |
| 372 | void UpdateKeys(const MovingRoots& moving_roots, Container& container) { |
| 373 | for (const auto& pair : moving_roots) { |
| 374 | auto* old_root = pair.first; |
| 375 | auto* new_root = pair.second; |
| 376 | auto node = container.extract(old_root); |
| 377 | CHECK(!node.empty()); |
| 378 | node.key() = new_root; |
| 379 | bool inserted = container.insert(std::move(node)).inserted; |
| 380 | CHECK(inserted); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | void Transaction::VisitObjectLogs(RootVisitor* visitor, ArenaStack* arena_stack) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 385 | // List of moving roots. |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 386 | ScopedArenaAllocator allocator(arena_stack); |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 387 | using ObjectPair = std::pair<mirror::Object*, mirror::Object*>; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 388 | ScopedArenaForwardList<ObjectPair> moving_roots(allocator.Adapter(kArenaAllocTransaction)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 389 | |
| 390 | // Visit roots. |
Mathieu Chartier | 5f257b1 | 2017-02-03 14:47:36 -0800 | [diff] [blame] | 391 | for (auto& it : object_logs_) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 392 | it.second.VisitRoots(visitor); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 393 | mirror::Object* old_root = it.first; |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 394 | mirror::Object* new_root = old_root; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 395 | visitor->VisitRoot(&new_root, RootInfo(kRootUnknown)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 396 | if (new_root != old_root) { |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 397 | moving_roots.push_front(std::make_pair(old_root, new_root)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
| 401 | // Update object logs with moving roots. |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 402 | UpdateKeys(moving_roots, object_logs_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 403 | } |
| 404 | |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 405 | void Transaction::VisitArrayLogs(RootVisitor* visitor, ArenaStack* arena_stack) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 406 | // List of moving roots. |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 407 | ScopedArenaAllocator allocator(arena_stack); |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 408 | using ArrayPair = std::pair<mirror::Array*, mirror::Array*>; |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 409 | ScopedArenaForwardList<ArrayPair> moving_roots(allocator.Adapter(kArenaAllocTransaction)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 410 | |
Mathieu Chartier | 5f257b1 | 2017-02-03 14:47:36 -0800 | [diff] [blame] | 411 | for (auto& it : array_logs_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 412 | mirror::Array* old_root = it.first; |
Sebastien Hertz | ee1d79a | 2014-02-21 15:46:30 +0100 | [diff] [blame] | 413 | CHECK(!old_root->IsObjectArray()); |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 414 | mirror::Array* new_root = old_root; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 415 | visitor->VisitRoot(reinterpret_cast<mirror::Object**>(&new_root), RootInfo(kRootUnknown)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 416 | if (new_root != old_root) { |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 417 | moving_roots.push_front(std::make_pair(old_root, new_root)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
| 421 | // Update array logs with moving roots. |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 422 | UpdateKeys(moving_roots, array_logs_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 425 | void Transaction::VisitInternStringLogs(RootVisitor* visitor) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 426 | for (InternStringLog& log : intern_string_logs_) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 427 | log.VisitRoots(visitor); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 431 | void Transaction::VisitResolveStringLogs(RootVisitor* visitor) { |
| 432 | for (ResolveStringLog& log : resolve_string_logs_) { |
| 433 | log.VisitRoots(visitor); |
| 434 | } |
| 435 | } |
| 436 | |
Vladimir Marko | e9a4a60 | 2021-06-22 16:33:34 +0100 | [diff] [blame] | 437 | void Transaction::VisitResolveMethodTypeLogs(RootVisitor* visitor) { |
| 438 | for (ResolveMethodTypeLog& log : resolve_method_type_logs_) { |
| 439 | log.VisitRoots(visitor); |
| 440 | } |
| 441 | } |
| 442 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 443 | void Transaction::ObjectLog::LogBooleanValue(MemberOffset offset, uint8_t value, bool is_volatile) { |
| 444 | LogValue(ObjectLog::kBoolean, offset, value, is_volatile); |
| 445 | } |
| 446 | |
| 447 | void Transaction::ObjectLog::LogByteValue(MemberOffset offset, int8_t value, bool is_volatile) { |
| 448 | LogValue(ObjectLog::kByte, offset, value, is_volatile); |
| 449 | } |
| 450 | |
| 451 | void Transaction::ObjectLog::LogCharValue(MemberOffset offset, uint16_t value, bool is_volatile) { |
| 452 | LogValue(ObjectLog::kChar, offset, value, is_volatile); |
| 453 | } |
| 454 | |
| 455 | void Transaction::ObjectLog::LogShortValue(MemberOffset offset, int16_t value, bool is_volatile) { |
| 456 | LogValue(ObjectLog::kShort, offset, value, is_volatile); |
| 457 | } |
| 458 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 459 | void Transaction::ObjectLog::Log32BitsValue(MemberOffset offset, uint32_t value, bool is_volatile) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 460 | LogValue(ObjectLog::k32Bits, offset, value, is_volatile); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void Transaction::ObjectLog::Log64BitsValue(MemberOffset offset, uint64_t value, bool is_volatile) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 464 | LogValue(ObjectLog::k64Bits, offset, value, is_volatile); |
| 465 | } |
| 466 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 467 | void Transaction::ObjectLog::LogReferenceValue(MemberOffset offset, |
| 468 | mirror::Object* obj, |
| 469 | bool is_volatile) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 470 | LogValue(ObjectLog::kReference, offset, reinterpret_cast<uintptr_t>(obj), is_volatile); |
| 471 | } |
| 472 | |
| 473 | void Transaction::ObjectLog::LogValue(ObjectLog::FieldValueKind kind, |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 474 | MemberOffset offset, |
| 475 | uint64_t value, |
| 476 | bool is_volatile) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 477 | auto it = field_values_.find(offset.Uint32Value()); |
| 478 | if (it == field_values_.end()) { |
| 479 | ObjectLog::FieldValue field_value; |
| 480 | field_value.value = value; |
| 481 | field_value.is_volatile = is_volatile; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 482 | field_value.kind = kind; |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 483 | field_values_.emplace(offset.Uint32Value(), std::move(field_value)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 487 | void Transaction::ObjectLog::Undo(mirror::Object* obj) const { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 488 | for (auto& it : field_values_) { |
| 489 | // Garbage collector needs to access object's class and array's length. So we don't rollback |
| 490 | // these values. |
| 491 | MemberOffset field_offset(it.first); |
| 492 | if (field_offset.Uint32Value() == mirror::Class::ClassOffset().Uint32Value()) { |
| 493 | // Skip Object::class field. |
| 494 | continue; |
| 495 | } |
| 496 | if (obj->IsArrayInstance() && |
| 497 | field_offset.Uint32Value() == mirror::Array::LengthOffset().Uint32Value()) { |
| 498 | // Skip Array::length field. |
| 499 | continue; |
| 500 | } |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 501 | const FieldValue& field_value = it.second; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 502 | UndoFieldWrite(obj, field_offset, field_value); |
| 503 | } |
| 504 | } |
| 505 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 506 | void Transaction::ObjectLog::UndoFieldWrite(mirror::Object* obj, |
| 507 | MemberOffset field_offset, |
| 508 | const FieldValue& field_value) const { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 509 | // TODO We may want to abort a transaction while still being in transaction mode. In this case, |
| 510 | // we'd need to disable the check. |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 511 | constexpr bool kCheckTransaction = false; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 512 | switch (field_value.kind) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 513 | case kBoolean: |
| 514 | if (UNLIKELY(field_value.is_volatile)) { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 515 | obj->SetFieldBooleanVolatile<false, kCheckTransaction>( |
| 516 | field_offset, |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 517 | field_value.value); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 518 | } else { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 519 | obj->SetFieldBoolean<false, kCheckTransaction>( |
| 520 | field_offset, |
Andreas Gampe | 7c5acbb | 2018-09-20 13:54:52 -0700 | [diff] [blame] | 521 | field_value.value); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 522 | } |
| 523 | break; |
| 524 | case kByte: |
| 525 | if (UNLIKELY(field_value.is_volatile)) { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 526 | obj->SetFieldByteVolatile<false, kCheckTransaction>( |
| 527 | field_offset, |
| 528 | static_cast<int8_t>(field_value.value)); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 529 | } else { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 530 | obj->SetFieldByte<false, kCheckTransaction>( |
| 531 | field_offset, |
| 532 | static_cast<int8_t>(field_value.value)); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 533 | } |
| 534 | break; |
| 535 | case kChar: |
| 536 | if (UNLIKELY(field_value.is_volatile)) { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 537 | obj->SetFieldCharVolatile<false, kCheckTransaction>( |
| 538 | field_offset, |
| 539 | static_cast<uint16_t>(field_value.value)); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 540 | } else { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 541 | obj->SetFieldChar<false, kCheckTransaction>( |
| 542 | field_offset, |
| 543 | static_cast<uint16_t>(field_value.value)); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 544 | } |
| 545 | break; |
| 546 | case kShort: |
| 547 | if (UNLIKELY(field_value.is_volatile)) { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 548 | obj->SetFieldShortVolatile<false, kCheckTransaction>( |
| 549 | field_offset, |
| 550 | static_cast<int16_t>(field_value.value)); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 551 | } else { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 552 | obj->SetFieldShort<false, kCheckTransaction>( |
| 553 | field_offset, |
| 554 | static_cast<int16_t>(field_value.value)); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 555 | } |
| 556 | break; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 557 | case k32Bits: |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 558 | if (UNLIKELY(field_value.is_volatile)) { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 559 | obj->SetField32Volatile<false, kCheckTransaction>( |
| 560 | field_offset, |
| 561 | static_cast<uint32_t>(field_value.value)); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 562 | } else { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 563 | obj->SetField32<false, kCheckTransaction>( |
| 564 | field_offset, |
| 565 | static_cast<uint32_t>(field_value.value)); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 566 | } |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 567 | break; |
| 568 | case k64Bits: |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 569 | if (UNLIKELY(field_value.is_volatile)) { |
| 570 | obj->SetField64Volatile<false, kCheckTransaction>(field_offset, field_value.value); |
| 571 | } else { |
| 572 | obj->SetField64<false, kCheckTransaction>(field_offset, field_value.value); |
| 573 | } |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 574 | break; |
| 575 | case kReference: |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 576 | if (UNLIKELY(field_value.is_volatile)) { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 577 | obj->SetFieldObjectVolatile<false, kCheckTransaction>( |
| 578 | field_offset, |
| 579 | reinterpret_cast<mirror::Object*>(field_value.value)); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 580 | } else { |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 581 | obj->SetFieldObject<false, kCheckTransaction>( |
| 582 | field_offset, |
| 583 | reinterpret_cast<mirror::Object*>(field_value.value)); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 584 | } |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 585 | break; |
| 586 | default: |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 587 | LOG(FATAL) << "Unknown value kind " << static_cast<int>(field_value.kind); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 588 | UNREACHABLE(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 592 | void Transaction::ObjectLog::VisitRoots(RootVisitor* visitor) { |
Mathieu Chartier | 5f257b1 | 2017-02-03 14:47:36 -0800 | [diff] [blame] | 593 | for (auto& it : field_values_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 594 | FieldValue& field_value = it.second; |
| 595 | if (field_value.kind == ObjectLog::kReference) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 596 | visitor->VisitRootIfNonNull(reinterpret_cast<mirror::Object**>(&field_value.value), |
| 597 | RootInfo(kRootUnknown)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 602 | void Transaction::InternStringLog::Undo(InternTable* intern_table) const { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 603 | DCHECK(intern_table != nullptr); |
| 604 | switch (string_op_) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 605 | case InternStringLog::kInsert: { |
| 606 | switch (string_kind_) { |
| 607 | case InternStringLog::kStrongString: |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 608 | intern_table->RemoveStrongFromTransaction(str_.Read()); |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 609 | break; |
| 610 | case InternStringLog::kWeakString: |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 611 | intern_table->RemoveWeakFromTransaction(str_.Read()); |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 612 | break; |
| 613 | default: |
| 614 | LOG(FATAL) << "Unknown interned string kind"; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 615 | UNREACHABLE(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 616 | } |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 617 | break; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 618 | } |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 619 | case InternStringLog::kRemove: { |
| 620 | switch (string_kind_) { |
| 621 | case InternStringLog::kStrongString: |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 622 | intern_table->InsertStrongFromTransaction(str_.Read()); |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 623 | break; |
| 624 | case InternStringLog::kWeakString: |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 625 | intern_table->InsertWeakFromTransaction(str_.Read()); |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 626 | break; |
| 627 | default: |
| 628 | LOG(FATAL) << "Unknown interned string kind"; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 629 | UNREACHABLE(); |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 630 | } |
| 631 | break; |
| 632 | } |
| 633 | default: |
| 634 | LOG(FATAL) << "Unknown interned string op"; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 635 | UNREACHABLE(); |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 636 | } |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 637 | } |
| 638 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 639 | void Transaction::InternStringLog::VisitRoots(RootVisitor* visitor) { |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 640 | str_.VisitRoot(visitor, RootInfo(kRootInternedString)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 641 | } |
| 642 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 643 | void Transaction::ResolveStringLog::Undo() const { |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 644 | dex_cache_.Read()->ClearString(string_idx_); |
| 645 | } |
| 646 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 647 | Transaction::ResolveStringLog::ResolveStringLog(ObjPtr<mirror::DexCache> dex_cache, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 648 | dex::StringIndex string_idx) |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 649 | : dex_cache_(dex_cache), |
| 650 | string_idx_(string_idx) { |
| 651 | DCHECK(dex_cache != nullptr); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 652 | DCHECK_LT(string_idx_.index_, dex_cache->GetDexFile()->NumStringIds()); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | void Transaction::ResolveStringLog::VisitRoots(RootVisitor* visitor) { |
| 656 | dex_cache_.VisitRoot(visitor, RootInfo(kRootVMInternal)); |
| 657 | } |
| 658 | |
Vladimir Marko | e9a4a60 | 2021-06-22 16:33:34 +0100 | [diff] [blame] | 659 | void Transaction::ResolveMethodTypeLog::Undo() const { |
| 660 | dex_cache_.Read()->ClearMethodType(proto_idx_); |
| 661 | } |
| 662 | |
| 663 | Transaction::ResolveMethodTypeLog::ResolveMethodTypeLog(ObjPtr<mirror::DexCache> dex_cache, |
| 664 | dex::ProtoIndex proto_idx) |
| 665 | : dex_cache_(dex_cache), |
| 666 | proto_idx_(proto_idx) { |
| 667 | DCHECK(dex_cache != nullptr); |
| 668 | DCHECK_LT(proto_idx_.index_, dex_cache->GetDexFile()->NumProtoIds()); |
| 669 | } |
| 670 | |
| 671 | void Transaction::ResolveMethodTypeLog::VisitRoots(RootVisitor* visitor) { |
| 672 | dex_cache_.VisitRoot(visitor, RootInfo(kRootVMInternal)); |
| 673 | } |
| 674 | |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 675 | Transaction::InternStringLog::InternStringLog(ObjPtr<mirror::String> s, |
| 676 | StringKind kind, |
| 677 | StringOp op) |
| 678 | : str_(s), |
| 679 | string_kind_(kind), |
| 680 | string_op_(op) { |
| 681 | DCHECK(s != nullptr); |
| 682 | } |
| 683 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 684 | void Transaction::ArrayLog::LogValue(size_t index, uint64_t value) { |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 685 | // Add a mapping if there is none yet. |
| 686 | array_values_.FindOrAdd(index, value); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 687 | } |
| 688 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 689 | void Transaction::ArrayLog::Undo(mirror::Array* array) const { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 690 | DCHECK(array != nullptr); |
| 691 | DCHECK(array->IsArrayInstance()); |
| 692 | Primitive::Type type = array->GetClass()->GetComponentType()->GetPrimitiveType(); |
| 693 | for (auto it : array_values_) { |
| 694 | UndoArrayWrite(array, type, it.first, it.second); |
| 695 | } |
| 696 | } |
| 697 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 698 | void Transaction::ArrayLog::UndoArrayWrite(mirror::Array* array, |
| 699 | Primitive::Type array_type, |
| 700 | size_t index, |
| 701 | uint64_t value) const { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 702 | // TODO We may want to abort a transaction while still being in transaction mode. In this case, |
| 703 | // we'd need to disable the check. |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 704 | constexpr bool kCheckTransaction = false; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 705 | switch (array_type) { |
| 706 | case Primitive::kPrimBoolean: |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 707 | array->AsBooleanArray()->SetWithoutChecks<false, kCheckTransaction>( |
| 708 | index, static_cast<uint8_t>(value)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 709 | break; |
| 710 | case Primitive::kPrimByte: |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 711 | array->AsByteArray()->SetWithoutChecks<false, kCheckTransaction>( |
| 712 | index, static_cast<int8_t>(value)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 713 | break; |
| 714 | case Primitive::kPrimChar: |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 715 | array->AsCharArray()->SetWithoutChecks<false, kCheckTransaction>( |
| 716 | index, static_cast<uint16_t>(value)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 717 | break; |
| 718 | case Primitive::kPrimShort: |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 719 | array->AsShortArray()->SetWithoutChecks<false, kCheckTransaction>( |
| 720 | index, static_cast<int16_t>(value)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 721 | break; |
| 722 | case Primitive::kPrimInt: |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 723 | array->AsIntArray()->SetWithoutChecks<false, kCheckTransaction>( |
| 724 | index, static_cast<int32_t>(value)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 725 | break; |
| 726 | case Primitive::kPrimFloat: |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 727 | array->AsFloatArray()->SetWithoutChecks<false, kCheckTransaction>( |
| 728 | index, static_cast<float>(value)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 729 | break; |
| 730 | case Primitive::kPrimLong: |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 731 | array->AsLongArray()->SetWithoutChecks<false, kCheckTransaction>( |
| 732 | index, static_cast<int64_t>(value)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 733 | break; |
| 734 | case Primitive::kPrimDouble: |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 735 | array->AsDoubleArray()->SetWithoutChecks<false, kCheckTransaction>( |
| 736 | index, static_cast<double>(value)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 737 | break; |
Sebastien Hertz | ee1d79a | 2014-02-21 15:46:30 +0100 | [diff] [blame] | 738 | case Primitive::kPrimNot: |
| 739 | LOG(FATAL) << "ObjectArray should be treated as Object"; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 740 | UNREACHABLE(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 741 | default: |
| 742 | LOG(FATAL) << "Unsupported type " << array_type; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 743 | UNREACHABLE(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 747 | Transaction* ScopedAssertNoNewTransactionRecords::InstallAssertion(const char* reason) { |
| 748 | Transaction* transaction = nullptr; |
| 749 | if (kIsDebugBuild && Runtime::Current()->IsActiveTransaction()) { |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 750 | transaction = Runtime::Current()->GetTransaction(); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 751 | if (transaction != nullptr) { |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 752 | CHECK(transaction->assert_no_new_records_reason_ == nullptr) |
| 753 | << "old: " << transaction->assert_no_new_records_reason_ << " new: " << reason; |
| 754 | transaction->assert_no_new_records_reason_ = reason; |
| 755 | } |
| 756 | } |
| 757 | return transaction; |
| 758 | } |
| 759 | |
| 760 | void ScopedAssertNoNewTransactionRecords::RemoveAssertion(Transaction* transaction) { |
| 761 | if (kIsDebugBuild) { |
Vladimir Marko | b6e6792 | 2021-07-06 15:53:07 +0100 | [diff] [blame] | 762 | CHECK(Runtime::Current()->GetTransaction() == transaction); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 763 | CHECK(transaction->assert_no_new_records_reason_ != nullptr); |
| 764 | transaction->assert_no_new_records_reason_ = nullptr; |
| 765 | } |
| 766 | } |
| 767 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 768 | } // namespace art |