Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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_INTERPRETER_SHADOW_FRAME_H_ |
| 18 | #define ART_RUNTIME_INTERPRETER_SHADOW_FRAME_H_ |
| 19 | |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 20 | #include <cstdint> |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 21 | #include <cstring> |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 22 | #include <string> |
| 23 | |
Andreas Gampe | 7fbc4a5 | 2018-11-28 08:26:47 -0800 | [diff] [blame] | 24 | #include "base/locks.h" |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 25 | #include "base/macros.h" |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 26 | #include "lock_count_data.h" |
| 27 | #include "read_barrier.h" |
| 28 | #include "stack_reference.h" |
| 29 | #include "verify_object.h" |
| 30 | |
| 31 | namespace art { |
| 32 | |
| 33 | namespace mirror { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 34 | class Object; |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 35 | } // namespace mirror |
| 36 | |
| 37 | class ArtMethod; |
| 38 | class ShadowFrame; |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 39 | template<class MirrorType> class ObjPtr; |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 40 | class Thread; |
| 41 | union JValue; |
| 42 | |
| 43 | // Forward declaration. Just calls the destructor. |
| 44 | struct ShadowFrameDeleter; |
| 45 | using ShadowFrameAllocaUniquePtr = std::unique_ptr<ShadowFrame, ShadowFrameDeleter>; |
| 46 | |
| 47 | // ShadowFrame has 2 possible layouts: |
| 48 | // - interpreter - separate VRegs and reference arrays. References are in the reference array. |
| 49 | // - JNI - just VRegs, but where every VReg holds a reference. |
| 50 | class ShadowFrame { |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 51 | private: |
| 52 | // Used to keep track of extra state the shadowframe has. |
| 53 | enum class FrameFlags : uint32_t { |
| 54 | // We have been requested to notify when this frame gets popped. |
| 55 | kNotifyFramePop = 1 << 0, |
| 56 | // We have been asked to pop this frame off the stack as soon as possible. |
| 57 | kForcePopFrame = 1 << 1, |
| 58 | // We have been asked to re-execute the last instruction. |
| 59 | kForceRetryInst = 1 << 2, |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 60 | // Mark that we expect the next frame to retry the last instruction (used by instrumentation and |
| 61 | // debuggers to keep track of required events) |
| 62 | kSkipMethodExitEvents = 1 << 3, |
David Srbecky | 8d335b6 | 2019-06-06 14:25:42 +0100 | [diff] [blame] | 63 | // Used to suppress exception events caused by other instrumentation events. |
| 64 | kSkipNextExceptionEvent = 1 << 4, |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 67 | public: |
| 68 | // Compute size of ShadowFrame in bytes assuming it has a reference array. |
| 69 | static size_t ComputeSize(uint32_t num_vregs) { |
| 70 | return sizeof(ShadowFrame) + (sizeof(uint32_t) * num_vregs) + |
| 71 | (sizeof(StackReference<mirror::Object>) * num_vregs); |
| 72 | } |
| 73 | |
| 74 | // Create ShadowFrame in heap for deoptimization. |
| 75 | static ShadowFrame* CreateDeoptimizedFrame(uint32_t num_vregs, ShadowFrame* link, |
| 76 | ArtMethod* method, uint32_t dex_pc) { |
| 77 | uint8_t* memory = new uint8_t[ComputeSize(num_vregs)]; |
| 78 | return CreateShadowFrameImpl(num_vregs, link, method, dex_pc, memory); |
| 79 | } |
| 80 | |
| 81 | // Delete a ShadowFrame allocated on the heap for deoptimization. |
| 82 | static void DeleteDeoptimizedFrame(ShadowFrame* sf) { |
| 83 | sf->~ShadowFrame(); // Explicitly destruct. |
| 84 | uint8_t* memory = reinterpret_cast<uint8_t*>(sf); |
| 85 | delete[] memory; |
| 86 | } |
| 87 | |
| 88 | // Create a shadow frame in a fresh alloca. This needs to be in the context of the caller. |
| 89 | // Inlining doesn't work, the compiler will still undo the alloca. So this needs to be a macro. |
| 90 | #define CREATE_SHADOW_FRAME(num_vregs, link, method, dex_pc) ({ \ |
| 91 | size_t frame_size = ShadowFrame::ComputeSize(num_vregs); \ |
| 92 | void* alloca_mem = alloca(frame_size); \ |
| 93 | ShadowFrameAllocaUniquePtr( \ |
| 94 | ShadowFrame::CreateShadowFrameImpl((num_vregs), (link), (method), (dex_pc), \ |
| 95 | (alloca_mem))); \ |
| 96 | }) |
| 97 | |
| 98 | ~ShadowFrame() {} |
| 99 | |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 100 | uint32_t NumberOfVRegs() const { |
| 101 | return number_of_vregs_; |
| 102 | } |
| 103 | |
| 104 | uint32_t GetDexPC() const { |
David Srbecky | e81f10a | 2019-07-04 10:00:12 +0000 | [diff] [blame] | 105 | return (dex_pc_ptr_ == nullptr) ? dex_pc_ : dex_pc_ptr_ - dex_instructions_; |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | int16_t GetCachedHotnessCountdown() const { |
| 109 | return cached_hotness_countdown_; |
| 110 | } |
| 111 | |
| 112 | void SetCachedHotnessCountdown(int16_t cached_hotness_countdown) { |
| 113 | cached_hotness_countdown_ = cached_hotness_countdown; |
| 114 | } |
| 115 | |
| 116 | int16_t GetHotnessCountdown() const { |
| 117 | return hotness_countdown_; |
| 118 | } |
| 119 | |
| 120 | void SetHotnessCountdown(int16_t hotness_countdown) { |
| 121 | hotness_countdown_ = hotness_countdown; |
| 122 | } |
| 123 | |
| 124 | void SetDexPC(uint32_t dex_pc) { |
David Srbecky | e81f10a | 2019-07-04 10:00:12 +0000 | [diff] [blame] | 125 | dex_pc_ = dex_pc; |
| 126 | dex_pc_ptr_ = nullptr; |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | ShadowFrame* GetLink() const { |
| 130 | return link_; |
| 131 | } |
| 132 | |
| 133 | void SetLink(ShadowFrame* frame) { |
| 134 | DCHECK_NE(this, frame); |
| 135 | link_ = frame; |
| 136 | } |
| 137 | |
| 138 | int32_t GetVReg(size_t i) const { |
| 139 | DCHECK_LT(i, NumberOfVRegs()); |
| 140 | const uint32_t* vreg = &vregs_[i]; |
| 141 | return *reinterpret_cast<const int32_t*>(vreg); |
| 142 | } |
| 143 | |
| 144 | // Shorts are extended to Ints in VRegs. Interpreter intrinsics needs them as shorts. |
| 145 | int16_t GetVRegShort(size_t i) const { |
| 146 | return static_cast<int16_t>(GetVReg(i)); |
| 147 | } |
| 148 | |
| 149 | uint32_t* GetVRegAddr(size_t i) { |
| 150 | return &vregs_[i]; |
| 151 | } |
| 152 | |
| 153 | uint32_t* GetShadowRefAddr(size_t i) { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 154 | DCHECK_LT(i, NumberOfVRegs()); |
| 155 | return &vregs_[i + NumberOfVRegs()]; |
| 156 | } |
| 157 | |
Mathieu Chartier | fc9555d | 2017-11-05 16:32:19 -0800 | [diff] [blame] | 158 | const uint16_t* GetDexInstructions() const { |
| 159 | return dex_instructions_; |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | float GetVRegFloat(size_t i) const { |
| 163 | DCHECK_LT(i, NumberOfVRegs()); |
| 164 | // NOTE: Strict-aliasing? |
| 165 | const uint32_t* vreg = &vregs_[i]; |
| 166 | return *reinterpret_cast<const float*>(vreg); |
| 167 | } |
| 168 | |
| 169 | int64_t GetVRegLong(size_t i) const { |
David Srbecky | b8e5ad1 | 2018-08-31 07:02:02 +0100 | [diff] [blame] | 170 | DCHECK_LT(i + 1, NumberOfVRegs()); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 171 | const uint32_t* vreg = &vregs_[i]; |
| 172 | typedef const int64_t unaligned_int64 __attribute__ ((aligned (4))); |
| 173 | return *reinterpret_cast<unaligned_int64*>(vreg); |
| 174 | } |
| 175 | |
| 176 | double GetVRegDouble(size_t i) const { |
David Srbecky | b8e5ad1 | 2018-08-31 07:02:02 +0100 | [diff] [blame] | 177 | DCHECK_LT(i + 1, NumberOfVRegs()); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 178 | const uint32_t* vreg = &vregs_[i]; |
| 179 | typedef const double unaligned_double __attribute__ ((aligned (4))); |
| 180 | return *reinterpret_cast<unaligned_double*>(vreg); |
| 181 | } |
| 182 | |
| 183 | // Look up the reference given its virtual register number. |
| 184 | // If this returns non-null then this does not mean the vreg is currently a reference |
| 185 | // on non-moving collectors. Check that the raw reg with GetVReg is equal to this if not certain. |
| 186 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 187 | mirror::Object* GetVRegReference(size_t i) const REQUIRES_SHARED(Locks::mutator_lock_) { |
| 188 | DCHECK_LT(i, NumberOfVRegs()); |
| 189 | mirror::Object* ref; |
Nicolas Geoffray | 4cbfadc | 2018-10-10 16:09:43 +0100 | [diff] [blame] | 190 | ref = References()[i].AsMirrorPtr(); |
Roland Levillain | a78f5b6 | 2017-09-29 13:50:44 +0100 | [diff] [blame] | 191 | ReadBarrier::MaybeAssertToSpaceInvariant(ref); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 192 | if (kVerifyFlags & kVerifyReads) { |
| 193 | VerifyObject(ref); |
| 194 | } |
| 195 | return ref; |
| 196 | } |
| 197 | |
| 198 | // Get view of vregs as range of consecutive arguments starting at i. |
| 199 | uint32_t* GetVRegArgs(size_t i) { |
| 200 | return &vregs_[i]; |
| 201 | } |
| 202 | |
| 203 | void SetVReg(size_t i, int32_t val) { |
| 204 | DCHECK_LT(i, NumberOfVRegs()); |
| 205 | uint32_t* vreg = &vregs_[i]; |
| 206 | *reinterpret_cast<int32_t*>(vreg) = val; |
| 207 | // This is needed for moving collectors since these can update the vreg references if they |
| 208 | // happen to agree with references in the reference array. |
David Srbecky | 4d71e55 | 2019-07-01 16:06:14 +0100 | [diff] [blame] | 209 | References()[i].Clear(); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void SetVRegFloat(size_t i, float val) { |
| 213 | DCHECK_LT(i, NumberOfVRegs()); |
| 214 | uint32_t* vreg = &vregs_[i]; |
| 215 | *reinterpret_cast<float*>(vreg) = val; |
| 216 | // This is needed for moving collectors since these can update the vreg references if they |
| 217 | // happen to agree with references in the reference array. |
David Srbecky | 4d71e55 | 2019-07-01 16:06:14 +0100 | [diff] [blame] | 218 | References()[i].Clear(); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void SetVRegLong(size_t i, int64_t val) { |
David Srbecky | b8e5ad1 | 2018-08-31 07:02:02 +0100 | [diff] [blame] | 222 | DCHECK_LT(i + 1, NumberOfVRegs()); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 223 | uint32_t* vreg = &vregs_[i]; |
| 224 | typedef int64_t unaligned_int64 __attribute__ ((aligned (4))); |
| 225 | *reinterpret_cast<unaligned_int64*>(vreg) = val; |
| 226 | // This is needed for moving collectors since these can update the vreg references if they |
| 227 | // happen to agree with references in the reference array. |
David Srbecky | 4d71e55 | 2019-07-01 16:06:14 +0100 | [diff] [blame] | 228 | References()[i].Clear(); |
| 229 | References()[i + 1].Clear(); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | void SetVRegDouble(size_t i, double val) { |
David Srbecky | b8e5ad1 | 2018-08-31 07:02:02 +0100 | [diff] [blame] | 233 | DCHECK_LT(i + 1, NumberOfVRegs()); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 234 | uint32_t* vreg = &vregs_[i]; |
| 235 | typedef double unaligned_double __attribute__ ((aligned (4))); |
| 236 | *reinterpret_cast<unaligned_double*>(vreg) = val; |
| 237 | // This is needed for moving collectors since these can update the vreg references if they |
| 238 | // happen to agree with references in the reference array. |
David Srbecky | 4d71e55 | 2019-07-01 16:06:14 +0100 | [diff] [blame] | 239 | References()[i].Clear(); |
| 240 | References()[i + 1].Clear(); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 244 | void SetVRegReference(size_t i, ObjPtr<mirror::Object> val) |
| 245 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 246 | |
| 247 | void SetMethod(ArtMethod* method) REQUIRES(Locks::mutator_lock_) { |
| 248 | DCHECK(method != nullptr); |
| 249 | DCHECK(method_ != nullptr); |
| 250 | method_ = method; |
| 251 | } |
| 252 | |
| 253 | ArtMethod* GetMethod() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| 254 | DCHECK(method_ != nullptr); |
| 255 | return method_; |
| 256 | } |
| 257 | |
| 258 | mirror::Object* GetThisObject() const REQUIRES_SHARED(Locks::mutator_lock_); |
| 259 | |
| 260 | mirror::Object* GetThisObject(uint16_t num_ins) const REQUIRES_SHARED(Locks::mutator_lock_); |
| 261 | |
| 262 | bool Contains(StackReference<mirror::Object>* shadow_frame_entry_obj) const { |
David Srbecky | 4d71e55 | 2019-07-01 16:06:14 +0100 | [diff] [blame] | 263 | return ((&References()[0] <= shadow_frame_entry_obj) && |
| 264 | (shadow_frame_entry_obj <= (&References()[NumberOfVRegs() - 1]))); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | LockCountData& GetLockCountData() { |
| 268 | return lock_count_data_; |
| 269 | } |
| 270 | |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 271 | static constexpr size_t LockCountDataOffset() { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 272 | return OFFSETOF_MEMBER(ShadowFrame, lock_count_data_); |
| 273 | } |
| 274 | |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 275 | static constexpr size_t LinkOffset() { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 276 | return OFFSETOF_MEMBER(ShadowFrame, link_); |
| 277 | } |
| 278 | |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 279 | static constexpr size_t MethodOffset() { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 280 | return OFFSETOF_MEMBER(ShadowFrame, method_); |
| 281 | } |
| 282 | |
David Srbecky | e81f10a | 2019-07-04 10:00:12 +0000 | [diff] [blame] | 283 | static constexpr size_t DexPCOffset() { |
| 284 | return OFFSETOF_MEMBER(ShadowFrame, dex_pc_); |
| 285 | } |
| 286 | |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 287 | static constexpr size_t NumberOfVRegsOffset() { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 288 | return OFFSETOF_MEMBER(ShadowFrame, number_of_vregs_); |
| 289 | } |
| 290 | |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 291 | static constexpr size_t VRegsOffset() { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 292 | return OFFSETOF_MEMBER(ShadowFrame, vregs_); |
| 293 | } |
| 294 | |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 295 | static constexpr size_t ResultRegisterOffset() { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 296 | return OFFSETOF_MEMBER(ShadowFrame, result_register_); |
| 297 | } |
| 298 | |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 299 | static constexpr size_t DexPCPtrOffset() { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 300 | return OFFSETOF_MEMBER(ShadowFrame, dex_pc_ptr_); |
| 301 | } |
| 302 | |
David Srbecky | e81f10a | 2019-07-04 10:00:12 +0000 | [diff] [blame] | 303 | static constexpr size_t DexInstructionsOffset() { |
| 304 | return OFFSETOF_MEMBER(ShadowFrame, dex_instructions_); |
| 305 | } |
| 306 | |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 307 | static constexpr size_t CachedHotnessCountdownOffset() { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 308 | return OFFSETOF_MEMBER(ShadowFrame, cached_hotness_countdown_); |
| 309 | } |
| 310 | |
David Srbecky | 56de89a | 2018-10-01 15:32:20 +0100 | [diff] [blame] | 311 | static constexpr size_t HotnessCountdownOffset() { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 312 | return OFFSETOF_MEMBER(ShadowFrame, hotness_countdown_); |
| 313 | } |
| 314 | |
| 315 | // Create ShadowFrame for interpreter using provided memory. |
| 316 | static ShadowFrame* CreateShadowFrameImpl(uint32_t num_vregs, |
| 317 | ShadowFrame* link, |
| 318 | ArtMethod* method, |
| 319 | uint32_t dex_pc, |
| 320 | void* memory) { |
David Srbecky | 4d71e55 | 2019-07-01 16:06:14 +0100 | [diff] [blame] | 321 | return new (memory) ShadowFrame(num_vregs, link, method, dex_pc); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | const uint16_t* GetDexPCPtr() { |
| 325 | return dex_pc_ptr_; |
| 326 | } |
| 327 | |
| 328 | void SetDexPCPtr(uint16_t* dex_pc_ptr) { |
| 329 | dex_pc_ptr_ = dex_pc_ptr; |
| 330 | } |
| 331 | |
| 332 | JValue* GetResultRegister() { |
| 333 | return result_register_; |
| 334 | } |
| 335 | |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 336 | bool NeedsNotifyPop() const { |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 337 | return GetFrameFlag(FrameFlags::kNotifyFramePop); |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | void SetNotifyPop(bool notify) { |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 341 | UpdateFrameFlag(notify, FrameFlags::kNotifyFramePop); |
| 342 | } |
| 343 | |
| 344 | bool GetForcePopFrame() const { |
| 345 | return GetFrameFlag(FrameFlags::kForcePopFrame); |
| 346 | } |
| 347 | |
| 348 | void SetForcePopFrame(bool enable) { |
| 349 | UpdateFrameFlag(enable, FrameFlags::kForcePopFrame); |
| 350 | } |
| 351 | |
| 352 | bool GetForceRetryInstruction() const { |
| 353 | return GetFrameFlag(FrameFlags::kForceRetryInst); |
| 354 | } |
| 355 | |
| 356 | void SetForceRetryInstruction(bool enable) { |
| 357 | UpdateFrameFlag(enable, FrameFlags::kForceRetryInst); |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 360 | bool GetSkipMethodExitEvents() const { |
| 361 | return GetFrameFlag(FrameFlags::kSkipMethodExitEvents); |
| 362 | } |
| 363 | |
| 364 | void SetSkipMethodExitEvents(bool enable) { |
| 365 | UpdateFrameFlag(enable, FrameFlags::kSkipMethodExitEvents); |
| 366 | } |
| 367 | |
David Srbecky | 8d335b6 | 2019-06-06 14:25:42 +0100 | [diff] [blame] | 368 | bool GetSkipNextExceptionEvent() const { |
| 369 | return GetFrameFlag(FrameFlags::kSkipNextExceptionEvent); |
| 370 | } |
| 371 | |
| 372 | void SetSkipNextExceptionEvent(bool enable) { |
| 373 | UpdateFrameFlag(enable, FrameFlags::kSkipNextExceptionEvent); |
| 374 | } |
| 375 | |
Nicolas Geoffray | 893147c | 2018-10-29 14:49:30 +0000 | [diff] [blame] | 376 | void CheckConsistentVRegs() const { |
| 377 | if (kIsDebugBuild) { |
| 378 | // A shadow frame visible to GC requires the following rule: for a given vreg, |
| 379 | // its vreg reference equivalent should be the same, or null. |
| 380 | for (uint32_t i = 0; i < NumberOfVRegs(); ++i) { |
| 381 | int32_t reference_value = References()[i].AsVRegValue(); |
| 382 | CHECK((GetVReg(i) == reference_value) || (reference_value == 0)); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 387 | private: |
David Srbecky | 4d71e55 | 2019-07-01 16:06:14 +0100 | [diff] [blame] | 388 | ShadowFrame(uint32_t num_vregs, ShadowFrame* link, ArtMethod* method, uint32_t dex_pc) |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 389 | : link_(link), |
| 390 | method_(method), |
| 391 | result_register_(nullptr), |
David Srbecky | e81f10a | 2019-07-04 10:00:12 +0000 | [diff] [blame] | 392 | dex_pc_ptr_(nullptr), |
| 393 | dex_instructions_(nullptr), |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 394 | number_of_vregs_(num_vregs), |
David Srbecky | e81f10a | 2019-07-04 10:00:12 +0000 | [diff] [blame] | 395 | dex_pc_(dex_pc), |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 396 | cached_hotness_countdown_(0), |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 397 | hotness_countdown_(0), |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 398 | frame_flags_(0) { |
David Srbecky | 4d71e55 | 2019-07-01 16:06:14 +0100 | [diff] [blame] | 399 | memset(vregs_, 0, num_vregs * (sizeof(uint32_t) + sizeof(StackReference<mirror::Object>))); |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 402 | void UpdateFrameFlag(bool enable, FrameFlags flag) { |
| 403 | if (enable) { |
| 404 | frame_flags_ |= static_cast<uint32_t>(flag); |
| 405 | } else { |
| 406 | frame_flags_ &= ~static_cast<uint32_t>(flag); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | bool GetFrameFlag(FrameFlags flag) const { |
| 411 | return (frame_flags_ & static_cast<uint32_t>(flag)) != 0; |
| 412 | } |
| 413 | |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 414 | const StackReference<mirror::Object>* References() const { |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 415 | const uint32_t* vreg_end = &vregs_[NumberOfVRegs()]; |
| 416 | return reinterpret_cast<const StackReference<mirror::Object>*>(vreg_end); |
| 417 | } |
| 418 | |
| 419 | StackReference<mirror::Object>* References() { |
| 420 | return const_cast<StackReference<mirror::Object>*>( |
| 421 | const_cast<const ShadowFrame*>(this)->References()); |
| 422 | } |
| 423 | |
| 424 | // Link to previous shadow frame or null. |
| 425 | ShadowFrame* link_; |
| 426 | ArtMethod* method_; |
| 427 | JValue* result_register_; |
| 428 | const uint16_t* dex_pc_ptr_; |
David Srbecky | e81f10a | 2019-07-04 10:00:12 +0000 | [diff] [blame] | 429 | // Dex instruction base of the code item. |
| 430 | const uint16_t* dex_instructions_; |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 431 | LockCountData lock_count_data_; // This may contain GC roots when lock counting is active. |
| 432 | const uint32_t number_of_vregs_; |
David Srbecky | e81f10a | 2019-07-04 10:00:12 +0000 | [diff] [blame] | 433 | uint32_t dex_pc_; |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 434 | int16_t cached_hotness_countdown_; |
| 435 | int16_t hotness_countdown_; |
Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 436 | |
| 437 | // This is a set of ShadowFrame::FrameFlags which denote special states this frame is in. |
| 438 | // NB alignment requires that this field takes 4 bytes no matter its size. Only 3 bits are |
| 439 | // currently used. |
| 440 | uint32_t frame_flags_; |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 441 | |
| 442 | // This is a two-part array: |
| 443 | // - [0..number_of_vregs) holds the raw virtual registers, and each element here is always 4 |
| 444 | // bytes. |
| 445 | // - [number_of_vregs..number_of_vregs*2) holds only reference registers. Each element here is |
| 446 | // ptr-sized. |
| 447 | // In other words when a primitive is stored in vX, the second (reference) part of the array will |
| 448 | // be null. When a reference is stored in vX, the second (reference) part of the array will be a |
| 449 | // copy of vX. |
| 450 | uint32_t vregs_[0]; |
| 451 | |
| 452 | DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame); |
| 453 | }; |
| 454 | |
| 455 | struct ShadowFrameDeleter { |
| 456 | inline void operator()(ShadowFrame* frame) { |
| 457 | if (frame != nullptr) { |
| 458 | frame->~ShadowFrame(); |
| 459 | } |
| 460 | } |
| 461 | }; |
| 462 | |
| 463 | } // namespace art |
| 464 | |
| 465 | #endif // ART_RUNTIME_INTERPRETER_SHADOW_FRAME_H_ |