Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_STACK_H_ |
| 18 | #define ART_RUNTIME_STACK_H_ |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 19 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 20 | #include "dex_file.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 21 | #include "instrumentation.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "base/macros.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 23 | #include "arch/context.h" |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 24 | |
| 25 | #include <stdint.h> |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 26 | #include <string> |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | namespace mirror { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 31 | class ArtMethod; |
| 32 | class Object; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | } // namespace mirror |
| 34 | |
| 35 | class Context; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 36 | class ShadowFrame; |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 37 | class StackIndirectReferenceTable; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 38 | class ScopedObjectAccess; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 39 | class Thread; |
| 40 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 41 | // The kind of vreg being accessed in calls to Set/GetVReg. |
| 42 | enum VRegKind { |
| 43 | kReferenceVReg, |
| 44 | kIntVReg, |
| 45 | kFloatVReg, |
| 46 | kLongLoVReg, |
| 47 | kLongHiVReg, |
| 48 | kDoubleLoVReg, |
| 49 | kDoubleHiVReg, |
| 50 | kConstant, |
| 51 | kImpreciseConstant, |
| 52 | kUndefined, |
| 53 | }; |
| 54 | |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 55 | // ShadowFrame has 3 possible layouts: |
| 56 | // - portable - a unified array of VRegs and references. Precise references need GC maps. |
| 57 | // - interpreter - separate VRegs and reference arrays. References are in the reference array. |
| 58 | // - JNI - just VRegs, but where every VReg holds a reference. |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 59 | class ShadowFrame { |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 60 | public: |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 61 | // Compute size of ShadowFrame in bytes. |
| 62 | static size_t ComputeSize(uint32_t num_vregs) { |
| 63 | return sizeof(ShadowFrame) + (sizeof(uint32_t) * num_vregs) + |
| 64 | (sizeof(mirror::Object*) * num_vregs); |
| 65 | } |
| 66 | |
| 67 | // Create ShadowFrame in heap for deoptimization. |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 68 | static ShadowFrame* Create(uint32_t num_vregs, ShadowFrame* link, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 69 | mirror::ArtMethod* method, uint32_t dex_pc) { |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 70 | uint8_t* memory = new uint8_t[ComputeSize(num_vregs)]; |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 71 | return Create(num_vregs, link, method, dex_pc, memory); |
Jeff Hao | 6613519 | 2013-05-14 11:02:41 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | // Create ShadowFrame for interpreter using provided memory. |
| 75 | static ShadowFrame* Create(uint32_t num_vregs, ShadowFrame* link, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 76 | mirror::ArtMethod* method, uint32_t dex_pc, void* memory) { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 77 | ShadowFrame* sf = new (memory) ShadowFrame(num_vregs, link, method, dex_pc, true); |
| 78 | return sf; |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 79 | } |
| 80 | ~ShadowFrame() {} |
| 81 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 82 | bool HasReferenceArray() const { |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 83 | #if defined(ART_USE_PORTABLE_COMPILER) |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 84 | return (number_of_vregs_ & kHasReferenceArray) != 0; |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 85 | #else |
| 86 | return true; |
| 87 | #endif |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 88 | } |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 89 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 90 | uint32_t NumberOfVRegs() const { |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 91 | #if defined(ART_USE_PORTABLE_COMPILER) |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 92 | return number_of_vregs_ & ~kHasReferenceArray; |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 93 | #else |
| 94 | return number_of_vregs_; |
| 95 | #endif |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 96 | } |
| 97 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 98 | void SetNumberOfVRegs(uint32_t number_of_vregs) { |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 99 | #if defined(ART_USE_PORTABLE_COMPILER) |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 100 | number_of_vregs_ = number_of_vregs | (number_of_vregs_ & kHasReferenceArray); |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 101 | #else |
| 102 | UNUSED(number_of_vregs); |
| 103 | UNIMPLEMENTED(FATAL) << "Should only be called when portable is enabled"; |
| 104 | #endif |
Ian Rogers | 5438ad8 | 2012-10-15 17:22:44 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 107 | uint32_t GetDexPC() const { |
| 108 | return dex_pc_; |
| 109 | } |
| 110 | |
| 111 | void SetDexPC(uint32_t dex_pc) { |
| 112 | dex_pc_ = dex_pc; |
| 113 | } |
| 114 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 115 | ShadowFrame* GetLink() const { |
| 116 | return link_; |
| 117 | } |
| 118 | |
| 119 | void SetLink(ShadowFrame* frame) { |
| 120 | DCHECK_NE(this, frame); |
| 121 | link_ = frame; |
| 122 | } |
| 123 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 124 | int32_t GetVReg(size_t i) const { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 125 | DCHECK_LT(i, NumberOfVRegs()); |
| 126 | const uint32_t* vreg = &vregs_[i]; |
| 127 | return *reinterpret_cast<const int32_t*>(vreg); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | float GetVRegFloat(size_t i) const { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 131 | DCHECK_LT(i, NumberOfVRegs()); |
| 132 | // NOTE: Strict-aliasing? |
| 133 | const uint32_t* vreg = &vregs_[i]; |
| 134 | return *reinterpret_cast<const float*>(vreg); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | int64_t GetVRegLong(size_t i) const { |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 138 | DCHECK_LT(i, NumberOfVRegs()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 139 | const uint32_t* vreg = &vregs_[i]; |
Jeff Hao | e47637c | 2013-09-19 15:13:16 -0700 | [diff] [blame] | 140 | // Alignment attribute required for GCC 4.8 |
| 141 | typedef const int64_t unaligned_int64 __attribute__ ((aligned (4))); |
| 142 | return *reinterpret_cast<unaligned_int64*>(vreg); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | double GetVRegDouble(size_t i) const { |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 146 | DCHECK_LT(i, NumberOfVRegs()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 147 | const uint32_t* vreg = &vregs_[i]; |
Jeff Hao | e47637c | 2013-09-19 15:13:16 -0700 | [diff] [blame] | 148 | // Alignment attribute required for GCC 4.8 |
| 149 | typedef const double unaligned_double __attribute__ ((aligned (4))); |
| 150 | return *reinterpret_cast<unaligned_double*>(vreg); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame^] | 153 | template <bool kChecked = false> |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 154 | mirror::Object* GetVRegReference(size_t i) const { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 155 | DCHECK_LT(i, NumberOfVRegs()); |
| 156 | if (HasReferenceArray()) { |
Mathieu Chartier | 423d2a3 | 2013-09-12 17:33:56 -0700 | [diff] [blame] | 157 | mirror::Object* ref = References()[i]; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame^] | 158 | if (kChecked) { |
| 159 | CHECK(VerifyReference(ref)) << "VReg " << i << "(" << ref |
| 160 | << ") is in protected space, reference array " << true; |
| 161 | } |
Mathieu Chartier | 423d2a3 | 2013-09-12 17:33:56 -0700 | [diff] [blame] | 162 | // If the vreg reference is not equal to the vreg then the vreg reference is stale. |
| 163 | if (reinterpret_cast<uint32_t>(ref) != vregs_[i]) { |
| 164 | return nullptr; |
| 165 | } |
| 166 | return ref; |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 167 | } else { |
| 168 | const uint32_t* vreg = &vregs_[i]; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame^] | 169 | mirror::Object* ref = *reinterpret_cast<mirror::Object* const*>(vreg); |
| 170 | if (kChecked) { |
| 171 | CHECK(VerifyReference(ref)) << "VReg " << i |
| 172 | << "(" << ref << ") is in protected space, reference array " << false; |
| 173 | } |
| 174 | return ref; |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 175 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Jeff Hao | 1674363 | 2013-05-08 10:59:04 -0700 | [diff] [blame] | 178 | // Get view of vregs as range of consecutive arguments starting at i. |
| 179 | uint32_t* GetVRegArgs(size_t i) { |
| 180 | return &vregs_[i]; |
| 181 | } |
| 182 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 183 | void SetVReg(size_t i, int32_t val) { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 184 | DCHECK_LT(i, NumberOfVRegs()); |
| 185 | uint32_t* vreg = &vregs_[i]; |
| 186 | *reinterpret_cast<int32_t*>(vreg) = val; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame^] | 187 | // This is needed for moving collectors since these can update the vreg references if they |
| 188 | // happen to agree with references in the reference array. |
| 189 | if (kMovingCollector && HasReferenceArray()) { |
| 190 | References()[i] = nullptr; |
| 191 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void SetVRegFloat(size_t i, float val) { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 195 | DCHECK_LT(i, NumberOfVRegs()); |
| 196 | uint32_t* vreg = &vregs_[i]; |
| 197 | *reinterpret_cast<float*>(vreg) = val; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame^] | 198 | // This is needed for moving collectors since these can update the vreg references if they |
| 199 | // happen to agree with references in the reference array. |
| 200 | if (kMovingCollector && HasReferenceArray()) { |
| 201 | References()[i] = nullptr; |
| 202 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void SetVRegLong(size_t i, int64_t val) { |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 206 | DCHECK_LT(i, NumberOfVRegs()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 207 | uint32_t* vreg = &vregs_[i]; |
Jeff Hao | e47637c | 2013-09-19 15:13:16 -0700 | [diff] [blame] | 208 | // Alignment attribute required for GCC 4.8 |
| 209 | typedef int64_t unaligned_int64 __attribute__ ((aligned (4))); |
| 210 | *reinterpret_cast<unaligned_int64*>(vreg) = val; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame^] | 211 | // This is needed for moving collectors since these can update the vreg references if they |
| 212 | // happen to agree with references in the reference array. |
| 213 | if (kMovingCollector && HasReferenceArray()) { |
| 214 | References()[i] = nullptr; |
| 215 | References()[i + 1] = nullptr; |
| 216 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | void SetVRegDouble(size_t i, double val) { |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 220 | DCHECK_LT(i, NumberOfVRegs()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 221 | uint32_t* vreg = &vregs_[i]; |
Jeff Hao | e47637c | 2013-09-19 15:13:16 -0700 | [diff] [blame] | 222 | // Alignment attribute required for GCC 4.8 |
| 223 | typedef double unaligned_double __attribute__ ((aligned (4))); |
| 224 | *reinterpret_cast<unaligned_double*>(vreg) = val; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame^] | 225 | // This is needed for moving collectors since these can update the vreg references if they |
| 226 | // happen to agree with references in the reference array. |
| 227 | if (kMovingCollector && HasReferenceArray()) { |
| 228 | References()[i] = nullptr; |
| 229 | References()[i + 1] = nullptr; |
| 230 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 233 | void SetVRegReference(size_t i, mirror::Object* val) { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 234 | DCHECK_LT(i, NumberOfVRegs()); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame^] | 235 | DCHECK(!kMovingCollector || VerifyReference(val)) |
| 236 | << "VReg " << i << "(" << val << ") is in protected space"; |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 237 | uint32_t* vreg = &vregs_[i]; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 238 | *reinterpret_cast<mirror::Object**>(vreg) = val; |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 239 | if (HasReferenceArray()) { |
| 240 | References()[i] = val; |
| 241 | } |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 244 | mirror::ArtMethod* GetMethod() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 245 | DCHECK_NE(method_, static_cast<void*>(NULL)); |
| 246 | return method_; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 249 | mirror::Object* GetThisObject() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 250 | |
Jeff Hao | e701f48 | 2013-05-24 11:50:49 -0700 | [diff] [blame] | 251 | mirror::Object* GetThisObject(uint16_t num_ins) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 252 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 253 | ThrowLocation GetCurrentLocationForThrow() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 254 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 255 | void SetMethod(mirror::ArtMethod* method) { |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 256 | #if defined(ART_USE_PORTABLE_COMPILER) |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 257 | DCHECK_NE(method, static_cast<void*>(NULL)); |
| 258 | method_ = method; |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 259 | #else |
| 260 | UNUSED(method); |
| 261 | UNIMPLEMENTED(FATAL) << "Should only be called when portable is enabled"; |
| 262 | #endif |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 265 | bool Contains(mirror::Object** shadow_frame_entry_obj) const { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 266 | if (HasReferenceArray()) { |
| 267 | return ((&References()[0] <= shadow_frame_entry_obj) && |
| 268 | (shadow_frame_entry_obj <= (&References()[NumberOfVRegs() - 1]))); |
| 269 | } else { |
| 270 | uint32_t* shadow_frame_entry = reinterpret_cast<uint32_t*>(shadow_frame_entry_obj); |
| 271 | return ((&vregs_[0] <= shadow_frame_entry) && |
| 272 | (shadow_frame_entry <= (&vregs_[NumberOfVRegs() - 1]))); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 273 | } |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 276 | static size_t LinkOffset() { |
| 277 | return OFFSETOF_MEMBER(ShadowFrame, link_); |
| 278 | } |
| 279 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 280 | static size_t MethodOffset() { |
| 281 | return OFFSETOF_MEMBER(ShadowFrame, method_); |
| 282 | } |
| 283 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 284 | static size_t DexPCOffset() { |
| 285 | return OFFSETOF_MEMBER(ShadowFrame, dex_pc_); |
| 286 | } |
| 287 | |
Ian Rogers | 5438ad8 | 2012-10-15 17:22:44 -0700 | [diff] [blame] | 288 | static size_t NumberOfVRegsOffset() { |
| 289 | return OFFSETOF_MEMBER(ShadowFrame, number_of_vregs_); |
| 290 | } |
| 291 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 292 | static size_t VRegsOffset() { |
| 293 | return OFFSETOF_MEMBER(ShadowFrame, vregs_); |
Ian Rogers | 5438ad8 | 2012-10-15 17:22:44 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 296 | private: |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 297 | ShadowFrame(uint32_t num_vregs, ShadowFrame* link, mirror::ArtMethod* method, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 298 | uint32_t dex_pc, bool has_reference_array) |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 299 | : number_of_vregs_(num_vregs), link_(link), method_(method), dex_pc_(dex_pc) { |
| 300 | if (has_reference_array) { |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 301 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 302 | CHECK_LT(num_vregs, static_cast<uint32_t>(kHasReferenceArray)); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 303 | number_of_vregs_ |= kHasReferenceArray; |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 304 | #endif |
Jeff Hao | e701f48 | 2013-05-24 11:50:49 -0700 | [diff] [blame] | 305 | memset(vregs_, 0, num_vregs * (sizeof(uint32_t) + sizeof(mirror::Object*))); |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 306 | } else { |
Jeff Hao | e701f48 | 2013-05-24 11:50:49 -0700 | [diff] [blame] | 307 | memset(vregs_, 0, num_vregs * sizeof(uint32_t)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 308 | } |
| 309 | } |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 310 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 311 | mirror::Object* const* References() const { |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 312 | DCHECK(HasReferenceArray()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 313 | const uint32_t* vreg_end = &vregs_[NumberOfVRegs()]; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 314 | return reinterpret_cast<mirror::Object* const*>(vreg_end); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 315 | } |
| 316 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame^] | 317 | bool VerifyReference(const mirror::Object* val) const; |
| 318 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 319 | mirror::Object** References() { |
| 320 | return const_cast<mirror::Object**>(const_cast<const ShadowFrame*>(this)->References()); |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 323 | #if defined(ART_USE_PORTABLE_COMPILER) |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 324 | enum ShadowFrameFlag { |
| 325 | kHasReferenceArray = 1ul << 31 |
| 326 | }; |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 327 | // TODO: make const in the portable case. |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 328 | uint32_t number_of_vregs_; |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 329 | #else |
| 330 | const uint32_t number_of_vregs_; |
| 331 | #endif |
Ian Rogers | 5438ad8 | 2012-10-15 17:22:44 -0700 | [diff] [blame] | 332 | // Link to previous shadow frame or NULL. |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 333 | ShadowFrame* link_; |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 334 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 335 | // TODO: make const in the portable case. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 336 | mirror::ArtMethod* method_; |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 337 | #else |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 338 | mirror::ArtMethod* const method_; |
Ian Rogers | 8a01a3a | 2013-05-06 13:25:44 -0700 | [diff] [blame] | 339 | #endif |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 340 | uint32_t dex_pc_; |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 341 | uint32_t vregs_[0]; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 342 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 343 | DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame); |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 344 | }; |
| 345 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 346 | // The managed stack is used to record fragments of managed code stacks. Managed code stacks |
| 347 | // may either be shadow frames or lists of frames using fixed frame sizes. Transition records are |
| 348 | // necessary for transitions between code using different frame layouts and transitions into native |
| 349 | // code. |
Ian Rogers | df1ce91 | 2012-11-27 17:07:11 -0800 | [diff] [blame] | 350 | class PACKED(4) ManagedStack { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 351 | public: |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 352 | ManagedStack() |
| 353 | : link_(NULL), top_shadow_frame_(NULL), top_quick_frame_(NULL), top_quick_frame_pc_(0) {} |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 354 | |
| 355 | void PushManagedStackFragment(ManagedStack* fragment) { |
| 356 | // Copy this top fragment into given fragment. |
| 357 | memcpy(fragment, this, sizeof(ManagedStack)); |
| 358 | // Clear this fragment, which has become the top. |
| 359 | memset(this, 0, sizeof(ManagedStack)); |
| 360 | // Link our top fragment onto the given fragment. |
| 361 | link_ = fragment; |
| 362 | } |
| 363 | |
| 364 | void PopManagedStackFragment(const ManagedStack& fragment) { |
| 365 | DCHECK(&fragment == link_); |
| 366 | // Copy this given fragment back to the top. |
| 367 | memcpy(this, &fragment, sizeof(ManagedStack)); |
| 368 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 369 | |
| 370 | ManagedStack* GetLink() const { |
| 371 | return link_; |
| 372 | } |
| 373 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 374 | mirror::ArtMethod** GetTopQuickFrame() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 375 | return top_quick_frame_; |
| 376 | } |
| 377 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 378 | void SetTopQuickFrame(mirror::ArtMethod** top) { |
Sebastien Hertz | a7b0c42 | 2013-04-05 16:19:39 +0200 | [diff] [blame] | 379 | DCHECK(top_shadow_frame_ == NULL); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 380 | top_quick_frame_ = top; |
| 381 | } |
| 382 | |
| 383 | uintptr_t GetTopQuickFramePc() const { |
| 384 | return top_quick_frame_pc_; |
| 385 | } |
| 386 | |
| 387 | void SetTopQuickFramePc(uintptr_t pc) { |
Sebastien Hertz | a7b0c42 | 2013-04-05 16:19:39 +0200 | [diff] [blame] | 388 | DCHECK(top_shadow_frame_ == NULL); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 389 | top_quick_frame_pc_ = pc; |
| 390 | } |
| 391 | |
| 392 | static size_t TopQuickFrameOffset() { |
| 393 | return OFFSETOF_MEMBER(ManagedStack, top_quick_frame_); |
| 394 | } |
| 395 | |
| 396 | static size_t TopQuickFramePcOffset() { |
| 397 | return OFFSETOF_MEMBER(ManagedStack, top_quick_frame_pc_); |
| 398 | } |
| 399 | |
| 400 | ShadowFrame* PushShadowFrame(ShadowFrame* new_top_frame) { |
Sebastien Hertz | a7b0c42 | 2013-04-05 16:19:39 +0200 | [diff] [blame] | 401 | DCHECK(top_quick_frame_ == NULL); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 402 | ShadowFrame* old_frame = top_shadow_frame_; |
| 403 | top_shadow_frame_ = new_top_frame; |
| 404 | new_top_frame->SetLink(old_frame); |
| 405 | return old_frame; |
| 406 | } |
| 407 | |
| 408 | ShadowFrame* PopShadowFrame() { |
Sebastien Hertz | a7b0c42 | 2013-04-05 16:19:39 +0200 | [diff] [blame] | 409 | DCHECK(top_quick_frame_ == NULL); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 410 | CHECK(top_shadow_frame_ != NULL); |
| 411 | ShadowFrame* frame = top_shadow_frame_; |
| 412 | top_shadow_frame_ = frame->GetLink(); |
| 413 | return frame; |
| 414 | } |
| 415 | |
| 416 | ShadowFrame* GetTopShadowFrame() const { |
| 417 | return top_shadow_frame_; |
| 418 | } |
| 419 | |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 420 | void SetTopShadowFrame(ShadowFrame* top) { |
Sebastien Hertz | a7b0c42 | 2013-04-05 16:19:39 +0200 | [diff] [blame] | 421 | DCHECK(top_quick_frame_ == NULL); |
Jeff Hao | 11ffc2d | 2013-02-01 11:52:17 -0800 | [diff] [blame] | 422 | top_shadow_frame_ = top; |
| 423 | } |
| 424 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 425 | static size_t TopShadowFrameOffset() { |
| 426 | return OFFSETOF_MEMBER(ManagedStack, top_shadow_frame_); |
| 427 | } |
| 428 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 429 | size_t NumJniShadowFrameReferences() const; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 430 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 431 | bool ShadowFramesContain(mirror::Object** shadow_frame_entry) const; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 432 | |
| 433 | private: |
| 434 | ManagedStack* link_; |
| 435 | ShadowFrame* top_shadow_frame_; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 436 | mirror::ArtMethod** top_quick_frame_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 437 | uintptr_t top_quick_frame_pc_; |
| 438 | }; |
| 439 | |
| 440 | class StackVisitor { |
| 441 | protected: |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 442 | StackVisitor(Thread* thread, Context* context) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 443 | |
| 444 | public: |
| 445 | virtual ~StackVisitor() {} |
| 446 | |
| 447 | // Return 'true' if we should continue to visit more frames, 'false' to stop. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 448 | virtual bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 449 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 450 | void WalkStack(bool include_transitions = false) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 451 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 452 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 453 | mirror::ArtMethod* GetMethod() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 454 | if (cur_shadow_frame_ != NULL) { |
| 455 | return cur_shadow_frame_->GetMethod(); |
| 456 | } else if (cur_quick_frame_ != NULL) { |
| 457 | return *cur_quick_frame_; |
| 458 | } else { |
| 459 | return NULL; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | bool IsShadowFrame() const { |
| 464 | return cur_shadow_frame_ != NULL; |
| 465 | } |
| 466 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 467 | uint32_t GetDexPc() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 468 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 469 | mirror::Object* GetThisObject() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 470 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 471 | size_t GetNativePcOffset() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 472 | |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 473 | uintptr_t* CalleeSaveAddress(int num, size_t frame_size) const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 474 | // Callee saves are held at the top of the frame |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 475 | DCHECK(GetMethod() != NULL); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 476 | byte* save_addr = |
| 477 | reinterpret_cast<byte*>(cur_quick_frame_) + frame_size - ((num + 1) * kPointerSize); |
| 478 | #if defined(__i386__) |
| 479 | save_addr -= kPointerSize; // account for return address |
| 480 | #endif |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 481 | return reinterpret_cast<uintptr_t*>(save_addr); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 484 | // Returns the height of the stack in the managed stack frames, including transitions. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 485 | size_t GetFrameHeight() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 486 | return GetNumFrames() - cur_depth_ - 1; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 489 | // Returns a frame ID for JDWP use, starting from 1. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 490 | size_t GetFrameId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 491 | return GetFrameHeight() + 1; |
| 492 | } |
| 493 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 494 | size_t GetNumFrames() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 495 | if (num_frames_ == 0) { |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 496 | num_frames_ = ComputeNumFrames(thread_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 497 | } |
| 498 | return num_frames_; |
| 499 | } |
| 500 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 501 | uint32_t GetVReg(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind) const |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 502 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 503 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 504 | void SetVReg(mirror::ArtMethod* m, uint16_t vreg, uint32_t new_value, VRegKind kind) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 505 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 506 | |
| 507 | uintptr_t GetGPR(uint32_t reg) const; |
Mathieu Chartier | 6702243 | 2012-11-29 18:04:50 -0800 | [diff] [blame] | 508 | void SetGPR(uint32_t reg, uintptr_t value); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 509 | |
Mathieu Chartier | 423d2a3 | 2013-09-12 17:33:56 -0700 | [diff] [blame] | 510 | // This is a fast-path for getting/setting values in a quick frame. |
| 511 | uint32_t* GetVRegAddr(mirror::ArtMethod** cur_quick_frame, const DexFile::CodeItem* code_item, |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 512 | uint32_t core_spills, uint32_t fp_spills, size_t frame_size, |
| 513 | uint16_t vreg) const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 514 | int offset = GetVRegOffset(code_item, core_spills, fp_spills, frame_size, vreg); |
Ian Rogers | 0ec569a | 2012-07-01 16:43:46 -0700 | [diff] [blame] | 515 | DCHECK_EQ(cur_quick_frame, GetCurrentQuickFrame()); |
| 516 | byte* vreg_addr = reinterpret_cast<byte*>(cur_quick_frame) + offset; |
Mathieu Chartier | 423d2a3 | 2013-09-12 17:33:56 -0700 | [diff] [blame] | 517 | return reinterpret_cast<uint32_t*>(vreg_addr); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | uintptr_t GetReturnPc() const; |
| 521 | |
| 522 | void SetReturnPc(uintptr_t new_ret_pc); |
| 523 | |
| 524 | /* |
| 525 | * Return sp-relative offset for a Dalvik virtual register, compiler |
| 526 | * spill or Method* in bytes using Method*. |
| 527 | * Note that (reg >= 0) refers to a Dalvik register, (reg == -2) |
| 528 | * denotes Method* and (reg <= -3) denotes a compiler temp. |
| 529 | * |
| 530 | * +------------------------+ |
| 531 | * | IN[ins-1] | {Note: resides in caller's frame} |
| 532 | * | . | |
| 533 | * | IN[0] | |
| 534 | * | caller's Method* | |
| 535 | * +========================+ {Note: start of callee's frame} |
| 536 | * | core callee-save spill | {variable sized} |
| 537 | * +------------------------+ |
| 538 | * | fp callee-save spill | |
| 539 | * +------------------------+ |
| 540 | * | filler word | {For compatibility, if V[locals-1] used as wide |
| 541 | * +------------------------+ |
| 542 | * | V[locals-1] | |
| 543 | * | V[locals-2] | |
| 544 | * | . | |
| 545 | * | . | ... (reg == 2) |
| 546 | * | V[1] | ... (reg == 1) |
| 547 | * | V[0] | ... (reg == 0) <---- "locals_start" |
| 548 | * +------------------------+ |
| 549 | * | Compiler temps | ... (reg == -2) |
| 550 | * | | ... (reg == -3) |
| 551 | * | | ... (reg == -4) |
| 552 | * +------------------------+ |
| 553 | * | stack alignment padding| {0 to (kStackAlignWords-1) of padding} |
| 554 | * +------------------------+ |
| 555 | * | OUT[outs-1] | |
| 556 | * | OUT[outs-2] | |
| 557 | * | . | |
| 558 | * | OUT[0] | |
| 559 | * | curMethod* | ... (reg == -1) <<== sp, 16-byte aligned |
| 560 | * +========================+ |
| 561 | */ |
| 562 | static int GetVRegOffset(const DexFile::CodeItem* code_item, |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 563 | uint32_t core_spills, uint32_t fp_spills, |
| 564 | size_t frame_size, int reg) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 565 | DCHECK_EQ(frame_size & (kStackAlignment - 1), 0U); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 566 | int num_spills = __builtin_popcount(core_spills) + __builtin_popcount(fp_spills) + 1; // Filler. |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 567 | int num_ins = code_item->ins_size_; |
| 568 | int num_regs = code_item->registers_size_ - num_ins; |
| 569 | int locals_start = frame_size - ((num_spills + num_regs) * sizeof(uint32_t)); |
| 570 | if (reg == -2) { |
| 571 | return 0; // Method* |
| 572 | } else if (reg <= -3) { |
| 573 | return locals_start - ((reg + 1) * sizeof(uint32_t)); // Compiler temp. |
| 574 | } else if (reg < num_regs) { |
| 575 | return locals_start + (reg * sizeof(uint32_t)); // Dalvik local reg. |
| 576 | } else { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 577 | return frame_size + ((reg - num_regs) * sizeof(uint32_t)) + sizeof(uint32_t); // Dalvik in. |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
| 581 | uintptr_t GetCurrentQuickFramePc() const { |
| 582 | return cur_quick_frame_pc_; |
| 583 | } |
| 584 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 585 | mirror::ArtMethod** GetCurrentQuickFrame() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 586 | return cur_quick_frame_; |
| 587 | } |
| 588 | |
| 589 | ShadowFrame* GetCurrentShadowFrame() const { |
| 590 | return cur_shadow_frame_; |
| 591 | } |
| 592 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 593 | StackIndirectReferenceTable* GetCurrentSirt() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 594 | mirror::ArtMethod** sp = GetCurrentQuickFrame(); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 595 | ++sp; // Skip Method*; SIRT comes next; |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 596 | return reinterpret_cast<StackIndirectReferenceTable*>(sp); |
| 597 | } |
| 598 | |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 599 | std::string DescribeLocation() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 600 | |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 601 | static size_t ComputeNumFrames(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 602 | |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 603 | static void DescribeStack(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 604 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 605 | private: |
Sebastien Hertz | 74e256b | 2013-10-04 10:40:37 +0200 | [diff] [blame] | 606 | instrumentation::InstrumentationStackFrame& GetInstrumentationStackFrame(uint32_t depth) const; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 607 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 608 | void SanityCheckFrame() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 609 | |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 610 | Thread* const thread_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 611 | ShadowFrame* cur_shadow_frame_; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 612 | mirror::ArtMethod** cur_quick_frame_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 613 | uintptr_t cur_quick_frame_pc_; |
| 614 | // Lazily computed, number of frames in the stack. |
| 615 | size_t num_frames_; |
| 616 | // Depth of the frame we're currently at. |
| 617 | size_t cur_depth_; |
Brian Carlstrom | 0cd7ec2 | 2013-07-17 23:40:20 -0700 | [diff] [blame] | 618 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 619 | protected: |
| 620 | Context* const context_; |
| 621 | }; |
| 622 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 623 | } // namespace art |
| 624 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 625 | #endif // ART_RUNTIME_STACK_H_ |