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