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 | #ifndef ART_RUNTIME_TRANSACTION_H_ |
| 18 | #define ART_RUNTIME_TRANSACTION_H_ |
| 19 | |
| 20 | #include "base/macros.h" |
| 21 | #include "base/mutex.h" |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 22 | #include "base/safe_map.h" |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 23 | #include "base/value_object.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 24 | #include "dex/dex_file_types.h" |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 25 | #include "dex/primitive.h" |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 26 | #include "gc_root.h" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 27 | #include "offsets.h" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 28 | |
| 29 | #include <list> |
| 30 | #include <map> |
| 31 | |
| 32 | namespace art { |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 33 | namespace gc { |
| 34 | class Heap; |
| 35 | } // namespace gc |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 36 | namespace mirror { |
| 37 | class Array; |
Chang Xing | cade5c3 | 2017-07-20 17:56:26 -0700 | [diff] [blame] | 38 | class Class; |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 39 | class DexCache; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 40 | class Object; |
| 41 | class String; |
Andreas Gampe | deae7db | 2017-05-30 09:56:41 -0700 | [diff] [blame] | 42 | } // namespace mirror |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 43 | class InternTable; |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 44 | template<class MirrorType> class ObjPtr; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 45 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 46 | class Transaction final { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 47 | public: |
Sebastien Hertz | 2fd7e69 | 2015-04-02 11:11:19 +0200 | [diff] [blame] | 48 | static constexpr const char* kAbortExceptionDescriptor = "dalvik.system.TransactionAbortError"; |
| 49 | static constexpr const char* kAbortExceptionSignature = "Ldalvik/system/TransactionAbortError;"; |
| 50 | |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 51 | Transaction(bool strict, mirror::Class* root); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 52 | ~Transaction(); |
| 53 | |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 54 | void Abort(const std::string& abort_message) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 55 | REQUIRES(!log_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 56 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | b81e1cd | 2015-04-28 12:31:41 +0200 | [diff] [blame] | 57 | void ThrowAbortError(Thread* self, const std::string* abort_message) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 58 | REQUIRES(!log_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 59 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 60 | bool IsAborted() REQUIRES(!log_lock_); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 61 | |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 62 | // If the transaction is rollbacking. Transactions will set this flag when they start rollbacking, |
| 63 | // because the nested transaction should be disabled when rollbacking to restore the memory. |
| 64 | bool IsRollingBack(); |
| 65 | |
Chang Xing | 5a906fc | 2017-07-26 15:01:16 -0700 | [diff] [blame] | 66 | // If the transaction is in strict mode, then all access of static fields will be constrained, |
| 67 | // one class's clinit will not be allowed to read or modify another class's static fields, unless |
| 68 | // the transaction is aborted. |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 69 | bool IsStrict() { |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 70 | return strict_; |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 71 | } |
Chang Xing | 5a906fc | 2017-07-26 15:01:16 -0700 | [diff] [blame] | 72 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 73 | // Record object field changes. |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 74 | void RecordWriteFieldBoolean(mirror::Object* obj, |
| 75 | MemberOffset field_offset, |
| 76 | uint8_t value, |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 77 | bool is_volatile) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 78 | REQUIRES(!log_lock_); |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 79 | void RecordWriteFieldByte(mirror::Object* obj, |
| 80 | MemberOffset field_offset, |
| 81 | int8_t value, |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 82 | bool is_volatile) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 83 | REQUIRES(!log_lock_); |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 84 | void RecordWriteFieldChar(mirror::Object* obj, |
| 85 | MemberOffset field_offset, |
| 86 | uint16_t value, |
| 87 | bool is_volatile) |
| 88 | REQUIRES(!log_lock_); |
| 89 | void RecordWriteFieldShort(mirror::Object* obj, |
| 90 | MemberOffset field_offset, |
| 91 | int16_t value, |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 92 | bool is_volatile) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 93 | REQUIRES(!log_lock_); |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 94 | void RecordWriteField32(mirror::Object* obj, |
| 95 | MemberOffset field_offset, |
| 96 | uint32_t value, |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 97 | bool is_volatile) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 98 | REQUIRES(!log_lock_); |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 99 | void RecordWriteField64(mirror::Object* obj, |
| 100 | MemberOffset field_offset, |
| 101 | uint64_t value, |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 102 | bool is_volatile) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 103 | REQUIRES(!log_lock_); |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 104 | void RecordWriteFieldReference(mirror::Object* obj, |
| 105 | MemberOffset field_offset, |
| 106 | mirror::Object* value, |
| 107 | bool is_volatile) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 108 | REQUIRES(!log_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 109 | |
| 110 | // Record array change. |
| 111 | void RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 112 | REQUIRES(!log_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 113 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 114 | |
| 115 | // Record intern string table changes. |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 116 | void RecordStrongStringInsertion(ObjPtr<mirror::String> s) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 117 | REQUIRES(Locks::intern_table_lock_) |
| 118 | REQUIRES(!log_lock_); |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 119 | void RecordWeakStringInsertion(ObjPtr<mirror::String> s) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 120 | REQUIRES(Locks::intern_table_lock_) |
| 121 | REQUIRES(!log_lock_); |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 122 | void RecordStrongStringRemoval(ObjPtr<mirror::String> s) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 123 | REQUIRES(Locks::intern_table_lock_) |
| 124 | REQUIRES(!log_lock_); |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 125 | void RecordWeakStringRemoval(ObjPtr<mirror::String> s) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 126 | REQUIRES(Locks::intern_table_lock_) |
| 127 | REQUIRES(!log_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 128 | |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 129 | // Record resolve string. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 130 | void RecordResolveString(ObjPtr<mirror::DexCache> dex_cache, dex::StringIndex string_idx) |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 131 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 132 | REQUIRES(!log_lock_); |
| 133 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 134 | // Abort transaction by undoing all recorded changes. |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 135 | void Rollback() |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 136 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 137 | REQUIRES(!log_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 138 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 139 | void VisitRoots(RootVisitor* visitor) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 140 | REQUIRES(!log_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 141 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 142 | |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 143 | bool ReadConstraint(Thread* self, ObjPtr<mirror::Object> obj) |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 144 | REQUIRES(!log_lock_) |
| 145 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 146 | |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 147 | bool WriteConstraint(Thread* self, ObjPtr<mirror::Object> obj) |
Chang Xing | bd208d8 | 2017-07-12 14:53:17 -0700 | [diff] [blame] | 148 | REQUIRES(!log_lock_) |
| 149 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 150 | |
Vladimir Marko | 149cdda | 2019-11-12 15:02:51 +0000 | [diff] [blame] | 151 | bool WriteValueConstraint(Thread* self, ObjPtr<mirror::Object> value) |
| 152 | REQUIRES(!log_lock_) |
| 153 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 154 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 155 | private: |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 156 | class ObjectLog : public ValueObject { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 157 | public: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 158 | void LogBooleanValue(MemberOffset offset, uint8_t value, bool is_volatile); |
| 159 | void LogByteValue(MemberOffset offset, int8_t value, bool is_volatile); |
| 160 | void LogCharValue(MemberOffset offset, uint16_t value, bool is_volatile); |
| 161 | void LogShortValue(MemberOffset offset, int16_t value, bool is_volatile); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 162 | void Log32BitsValue(MemberOffset offset, uint32_t value, bool is_volatile); |
| 163 | void Log64BitsValue(MemberOffset offset, uint64_t value, bool is_volatile); |
| 164 | void LogReferenceValue(MemberOffset offset, mirror::Object* obj, bool is_volatile); |
| 165 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 166 | void Undo(mirror::Object* obj) const REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 167 | void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 168 | |
| 169 | size_t Size() const { |
| 170 | return field_values_.size(); |
| 171 | } |
| 172 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 173 | ObjectLog() = default; |
| 174 | ObjectLog(ObjectLog&& log) = default; |
| 175 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 176 | private: |
| 177 | enum FieldValueKind { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 178 | kBoolean, |
| 179 | kByte, |
| 180 | kChar, |
| 181 | kShort, |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 182 | k32Bits, |
| 183 | k64Bits, |
| 184 | kReference |
| 185 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 186 | struct FieldValue : public ValueObject { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 187 | // TODO use JValue instead ? |
| 188 | uint64_t value; |
| 189 | FieldValueKind kind; |
| 190 | bool is_volatile; |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 191 | |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 192 | FieldValue() : value(0), kind(FieldValueKind::kBoolean), is_volatile(false) {} |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 193 | FieldValue(FieldValue&& log) = default; |
| 194 | |
| 195 | private: |
| 196 | DISALLOW_COPY_AND_ASSIGN(FieldValue); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 197 | }; |
| 198 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 199 | void LogValue(FieldValueKind kind, MemberOffset offset, uint64_t value, bool is_volatile); |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 200 | void UndoFieldWrite(mirror::Object* obj, |
| 201 | MemberOffset field_offset, |
| 202 | const FieldValue& field_value) const REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 203 | |
| 204 | // Maps field's offset to its value. |
| 205 | std::map<uint32_t, FieldValue> field_values_; |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 206 | |
| 207 | DISALLOW_COPY_AND_ASSIGN(ObjectLog); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 208 | }; |
| 209 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 210 | class ArrayLog : public ValueObject { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 211 | public: |
| 212 | void LogValue(size_t index, uint64_t value); |
| 213 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 214 | void Undo(mirror::Array* obj) const REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 215 | |
| 216 | size_t Size() const { |
| 217 | return array_values_.size(); |
| 218 | } |
| 219 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 220 | ArrayLog() = default; |
| 221 | ArrayLog(ArrayLog&& log) = default; |
| 222 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 223 | private: |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 224 | void UndoArrayWrite(mirror::Array* array, |
| 225 | Primitive::Type array_type, |
| 226 | size_t index, |
| 227 | uint64_t value) const REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 228 | |
| 229 | // Maps index to value. |
| 230 | // TODO use JValue instead ? |
| 231 | std::map<size_t, uint64_t> array_values_; |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 232 | |
| 233 | DISALLOW_COPY_AND_ASSIGN(ArrayLog); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 234 | }; |
| 235 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 236 | class InternStringLog : public ValueObject { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 237 | public: |
| 238 | enum StringKind { |
| 239 | kStrongString, |
| 240 | kWeakString |
| 241 | }; |
| 242 | enum StringOp { |
| 243 | kInsert, |
| 244 | kRemove |
| 245 | }; |
Mathieu Chartier | 9e86809 | 2016-10-31 14:58:04 -0700 | [diff] [blame] | 246 | InternStringLog(ObjPtr<mirror::String> s, StringKind kind, StringOp op); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 247 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 248 | void Undo(InternTable* intern_table) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 249 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 250 | REQUIRES(Locks::intern_table_lock_); |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 251 | void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 252 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 253 | InternStringLog() = default; |
| 254 | InternStringLog(InternStringLog&& log) = default; |
| 255 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 256 | private: |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 257 | mutable GcRoot<mirror::String> str_; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 258 | const StringKind string_kind_; |
| 259 | const StringOp string_op_; |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 260 | |
| 261 | DISALLOW_COPY_AND_ASSIGN(InternStringLog); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 262 | }; |
| 263 | |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 264 | class ResolveStringLog : public ValueObject { |
| 265 | public: |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 266 | ResolveStringLog(ObjPtr<mirror::DexCache> dex_cache, dex::StringIndex string_idx); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 267 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 268 | void Undo() const REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 269 | |
| 270 | void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_); |
| 271 | |
| 272 | private: |
| 273 | GcRoot<mirror::DexCache> dex_cache_; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 274 | const dex::StringIndex string_idx_; |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 275 | |
| 276 | DISALLOW_COPY_AND_ASSIGN(ResolveStringLog); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 277 | }; |
| 278 | |
Mathieu Chartier | 38e954c | 2017-02-03 16:06:35 -0800 | [diff] [blame] | 279 | void LogInternedString(InternStringLog&& log) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 280 | REQUIRES(Locks::intern_table_lock_) |
| 281 | REQUIRES(!log_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 282 | |
| 283 | void UndoObjectModifications() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 284 | REQUIRES(log_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 285 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 286 | void UndoArrayModifications() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 287 | REQUIRES(log_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 288 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 289 | void UndoInternStringTableModifications() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 290 | REQUIRES(Locks::intern_table_lock_) |
| 291 | REQUIRES(log_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 292 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 293 | void UndoResolveStringModifications() |
| 294 | REQUIRES(log_lock_) |
| 295 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 296 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 297 | void VisitObjectLogs(RootVisitor* visitor) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 298 | REQUIRES(log_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 299 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 300 | void VisitArrayLogs(RootVisitor* visitor) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 301 | REQUIRES(log_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 302 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 303 | void VisitInternStringLogs(RootVisitor* visitor) |
| 304 | REQUIRES(log_lock_) |
| 305 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 306 | void VisitResolveStringLogs(RootVisitor* visitor) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 307 | REQUIRES(log_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 308 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 309 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 310 | const std::string& GetAbortMessage() REQUIRES(!log_lock_); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 311 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 312 | Mutex log_lock_ ACQUIRED_AFTER(Locks::intern_table_lock_); |
| 313 | std::map<mirror::Object*, ObjectLog> object_logs_ GUARDED_BY(log_lock_); |
| 314 | std::map<mirror::Array*, ArrayLog> array_logs_ GUARDED_BY(log_lock_); |
| 315 | std::list<InternStringLog> intern_string_logs_ GUARDED_BY(log_lock_); |
Mathieu Chartier | bb816d6 | 2016-09-07 10:17:46 -0700 | [diff] [blame] | 316 | std::list<ResolveStringLog> resolve_string_logs_ GUARDED_BY(log_lock_); |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 317 | bool aborted_ GUARDED_BY(log_lock_); |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 318 | bool rolling_back_; // Single thread, no race. |
Vladimir Marko | 672c080 | 2019-07-26 13:03:13 +0100 | [diff] [blame] | 319 | gc::Heap* const heap_; |
Vladimir Marko | 4d7b689 | 2020-01-16 17:06:35 +0000 | [diff] [blame] | 320 | const bool strict_; |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 321 | std::string abort_message_ GUARDED_BY(log_lock_); |
Chang Xing | cade5c3 | 2017-07-20 17:56:26 -0700 | [diff] [blame] | 322 | mirror::Class* root_ GUARDED_BY(log_lock_); |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 323 | const char* assert_no_new_records_reason_ GUARDED_BY(log_lock_); |
| 324 | |
| 325 | friend class ScopedAssertNoNewTransactionRecords; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 326 | |
| 327 | DISALLOW_COPY_AND_ASSIGN(Transaction); |
| 328 | }; |
| 329 | |
Vladimir Marko | b68bb7a | 2020-03-17 10:55:25 +0000 | [diff] [blame] | 330 | class ScopedAssertNoNewTransactionRecords { |
| 331 | public: |
| 332 | explicit ScopedAssertNoNewTransactionRecords(const char* reason) |
| 333 | : transaction_(kIsDebugBuild ? InstallAssertion(reason) : nullptr) {} |
| 334 | |
| 335 | ~ScopedAssertNoNewTransactionRecords() { |
| 336 | if (kIsDebugBuild && transaction_ != nullptr) { |
| 337 | RemoveAssertion(transaction_); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | private: |
| 342 | static Transaction* InstallAssertion(const char* reason); |
| 343 | static void RemoveAssertion(Transaction* transaction); |
| 344 | |
| 345 | Transaction* transaction_; |
| 346 | }; |
| 347 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 348 | } // namespace art |
| 349 | |
| 350 | #endif // ART_RUNTIME_TRANSACTION_H_ |