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