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