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