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