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