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" |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 21 | #include "heap.h" |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 22 | #include "jni.h" |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 23 | #include "macros.h" |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 24 | #include "oat/runtime/context.h" |
| 25 | #include "trace.h" |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 26 | |
| 27 | #include <stdint.h> |
| 28 | |
| 29 | namespace art { |
| 30 | |
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; |
| 33 | class ShadowFrame; |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 34 | class StackIndirectReferenceTable; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 35 | class ScopedObjectAccess; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 36 | class Thread; |
| 37 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 38 | class ShadowFrame { |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 39 | public: |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 40 | // Number of references contained within this shadow frame |
| 41 | uint32_t NumberOfReferences() const { |
| 42 | return number_of_references_; |
| 43 | } |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 44 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 45 | void SetNumberOfReferences(uint32_t number_of_references) { |
| 46 | number_of_references_ = number_of_references; |
| 47 | } |
| 48 | |
| 49 | // Caller dex pc |
| 50 | uint32_t GetDexPC() const { |
| 51 | return dex_pc_; |
| 52 | } |
| 53 | |
| 54 | void SetDexPC(uint32_t dex_pc) { |
| 55 | dex_pc_ = dex_pc; |
| 56 | } |
| 57 | |
| 58 | // Link to previous shadow frame or NULL |
| 59 | ShadowFrame* GetLink() const { |
| 60 | return link_; |
| 61 | } |
| 62 | |
| 63 | void SetLink(ShadowFrame* frame) { |
| 64 | DCHECK_NE(this, frame); |
| 65 | link_ = frame; |
| 66 | } |
| 67 | |
| 68 | Object* GetReference(size_t i) const { |
| 69 | DCHECK_LT(i, number_of_references_); |
| 70 | return references_[i]; |
| 71 | } |
| 72 | |
| 73 | void SetReference(size_t i, Object* object) { |
| 74 | DCHECK_LT(i, number_of_references_); |
| 75 | references_[i] = object; |
| 76 | } |
Elliott Hughes | 91bf6cd | 2012-02-14 17:27:48 -0800 | [diff] [blame] | 77 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 78 | AbstractMethod* GetMethod() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 79 | DCHECK_NE(method_, static_cast<void*>(NULL)); |
| 80 | return method_; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 83 | void SetMethod(AbstractMethod* method) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 84 | DCHECK_NE(method, static_cast<void*>(NULL)); |
| 85 | method_ = method; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 88 | bool Contains(Object** shadow_frame_entry) const { |
| 89 | return ((&references_[0] <= shadow_frame_entry) && |
| 90 | (shadow_frame_entry <= (&references_[number_of_references_ - 1]))); |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 93 | void VisitRoots(Heap::RootVisitor* visitor, void* arg) { |
| 94 | size_t num_refs = NumberOfReferences(); |
| 95 | for (size_t j = 0; j < num_refs; j++) { |
| 96 | Object* object = GetReference(j); |
| 97 | if (object != NULL) { |
| 98 | visitor(object, arg); |
| 99 | } |
| 100 | } |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 103 | // Offset of link within shadow frame |
| 104 | static size_t LinkOffset() { |
| 105 | return OFFSETOF_MEMBER(ShadowFrame, link_); |
| 106 | } |
| 107 | |
| 108 | // Offset of method within shadow frame |
| 109 | static size_t MethodOffset() { |
| 110 | return OFFSETOF_MEMBER(ShadowFrame, method_); |
| 111 | } |
| 112 | |
| 113 | // Offset of dex pc within shadow frame |
| 114 | static size_t DexPCOffset() { |
| 115 | return OFFSETOF_MEMBER(ShadowFrame, dex_pc_); |
| 116 | } |
| 117 | |
| 118 | // Offset of length within shadow frame |
| 119 | static size_t NumberOfReferencesOffset() { |
| 120 | return OFFSETOF_MEMBER(ShadowFrame, number_of_references_); |
| 121 | } |
| 122 | |
| 123 | // Offset of references within shadow frame |
| 124 | static size_t ReferencesOffset() { |
| 125 | return OFFSETOF_MEMBER(ShadowFrame, references_); |
| 126 | } |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 127 | |
| 128 | private: |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 129 | // ShadowFrame should be allocated by the generated code directly. |
| 130 | // We should not create new shadow stack in the runtime support function. |
| 131 | ~ShadowFrame() {} |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 132 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 133 | uint32_t number_of_references_; |
| 134 | ShadowFrame* link_; |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 135 | AbstractMethod* method_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 136 | uint32_t dex_pc_; |
| 137 | Object* references_[]; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 138 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 139 | DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame); |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 142 | // The managed stack is used to record fragments of managed code stacks. Managed code stacks |
| 143 | // may either be shadow frames or lists of frames using fixed frame sizes. Transition records are |
| 144 | // necessary for transitions between code using different frame layouts and transitions into native |
| 145 | // code. |
| 146 | class PACKED ManagedStack { |
| 147 | public: |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 148 | ManagedStack() |
| 149 | : 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] | 150 | |
| 151 | void PushManagedStackFragment(ManagedStack* fragment) { |
| 152 | // Copy this top fragment into given fragment. |
| 153 | memcpy(fragment, this, sizeof(ManagedStack)); |
| 154 | // Clear this fragment, which has become the top. |
| 155 | memset(this, 0, sizeof(ManagedStack)); |
| 156 | // Link our top fragment onto the given fragment. |
| 157 | link_ = fragment; |
| 158 | } |
| 159 | |
| 160 | void PopManagedStackFragment(const ManagedStack& fragment) { |
| 161 | DCHECK(&fragment == link_); |
| 162 | // Copy this given fragment back to the top. |
| 163 | memcpy(this, &fragment, sizeof(ManagedStack)); |
| 164 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 165 | |
| 166 | ManagedStack* GetLink() const { |
| 167 | return link_; |
| 168 | } |
| 169 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 170 | AbstractMethod** GetTopQuickFrame() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 171 | return top_quick_frame_; |
| 172 | } |
| 173 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 174 | void SetTopQuickFrame(AbstractMethod** top) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 175 | top_quick_frame_ = top; |
| 176 | } |
| 177 | |
| 178 | uintptr_t GetTopQuickFramePc() const { |
| 179 | return top_quick_frame_pc_; |
| 180 | } |
| 181 | |
| 182 | void SetTopQuickFramePc(uintptr_t pc) { |
| 183 | top_quick_frame_pc_ = pc; |
| 184 | } |
| 185 | |
| 186 | static size_t TopQuickFrameOffset() { |
| 187 | return OFFSETOF_MEMBER(ManagedStack, top_quick_frame_); |
| 188 | } |
| 189 | |
| 190 | static size_t TopQuickFramePcOffset() { |
| 191 | return OFFSETOF_MEMBER(ManagedStack, top_quick_frame_pc_); |
| 192 | } |
| 193 | |
| 194 | ShadowFrame* PushShadowFrame(ShadowFrame* new_top_frame) { |
| 195 | ShadowFrame* old_frame = top_shadow_frame_; |
| 196 | top_shadow_frame_ = new_top_frame; |
| 197 | new_top_frame->SetLink(old_frame); |
| 198 | return old_frame; |
| 199 | } |
| 200 | |
| 201 | ShadowFrame* PopShadowFrame() { |
| 202 | CHECK(top_shadow_frame_ != NULL); |
| 203 | ShadowFrame* frame = top_shadow_frame_; |
| 204 | top_shadow_frame_ = frame->GetLink(); |
| 205 | return frame; |
| 206 | } |
| 207 | |
| 208 | ShadowFrame* GetTopShadowFrame() const { |
| 209 | return top_shadow_frame_; |
| 210 | } |
| 211 | |
| 212 | static size_t TopShadowFrameOffset() { |
| 213 | return OFFSETOF_MEMBER(ManagedStack, top_shadow_frame_); |
| 214 | } |
| 215 | |
| 216 | size_t NumShadowFrameReferences() const; |
| 217 | |
| 218 | bool ShadowFramesContain(Object** shadow_frame_entry) const; |
| 219 | |
| 220 | private: |
| 221 | ManagedStack* link_; |
| 222 | ShadowFrame* top_shadow_frame_; |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 223 | AbstractMethod** top_quick_frame_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 224 | uintptr_t top_quick_frame_pc_; |
| 225 | }; |
| 226 | |
| 227 | class StackVisitor { |
| 228 | protected: |
| 229 | StackVisitor(const ManagedStack* stack, const std::vector<TraceStackFrame>* trace_stack, |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 230 | Context* context) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 231 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | ca19066 | 2012-06-26 15:45:57 -0700 | [diff] [blame] | 232 | : stack_start_(stack), trace_stack_(trace_stack), cur_shadow_frame_(NULL), |
| 233 | cur_quick_frame_(NULL), cur_quick_frame_pc_(0), num_frames_(0), cur_depth_(0), |
| 234 | context_(context) {} |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 235 | |
| 236 | public: |
| 237 | virtual ~StackVisitor() {} |
| 238 | |
| 239 | // 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] | 240 | virtual bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 241 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 242 | void WalkStack(bool include_transitions = false) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 243 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 244 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 245 | AbstractMethod* GetMethod() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 246 | if (cur_shadow_frame_ != NULL) { |
| 247 | return cur_shadow_frame_->GetMethod(); |
| 248 | } else if (cur_quick_frame_ != NULL) { |
| 249 | return *cur_quick_frame_; |
| 250 | } else { |
| 251 | return NULL; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | bool IsShadowFrame() const { |
| 256 | return cur_shadow_frame_ != NULL; |
| 257 | } |
| 258 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 259 | uint32_t GetDexPc() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 260 | |
| 261 | size_t GetNativePcOffset() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 262 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 263 | uintptr_t LoadCalleeSave(int num, size_t frame_size) const { |
| 264 | // Callee saves are held at the top of the frame |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 265 | AbstractMethod* method = GetMethod(); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 266 | DCHECK(method != NULL); |
| 267 | byte* save_addr = |
| 268 | reinterpret_cast<byte*>(cur_quick_frame_) + frame_size - ((num + 1) * kPointerSize); |
| 269 | #if defined(__i386__) |
| 270 | save_addr -= kPointerSize; // account for return address |
| 271 | #endif |
| 272 | return *reinterpret_cast<uintptr_t*>(save_addr); |
| 273 | } |
| 274 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 275 | // 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] | 276 | size_t GetFrameHeight() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 277 | return GetNumFrames() - cur_depth_; |
| 278 | } |
| 279 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 280 | // Returns a frame ID for JDWP use, starting from 1. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 281 | size_t GetFrameId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 282 | return GetFrameHeight() + 1; |
| 283 | } |
| 284 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 285 | size_t GetNumFrames() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 286 | if (num_frames_ == 0) { |
| 287 | num_frames_ = ComputeNumFrames(); |
| 288 | } |
| 289 | return num_frames_; |
| 290 | } |
| 291 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 292 | uint32_t GetVReg(AbstractMethod* m, int vreg) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 293 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 294 | void SetVReg(AbstractMethod* m, int vreg, uint32_t new_value) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 295 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 296 | |
| 297 | uintptr_t GetGPR(uint32_t reg) const; |
| 298 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 299 | uint32_t GetVReg(AbstractMethod** cur_quick_frame, const DexFile::CodeItem* code_item, |
Ian Rogers | 0ec569a | 2012-07-01 16:43:46 -0700 | [diff] [blame] | 300 | uint32_t core_spills, uint32_t fp_spills, size_t frame_size, int vreg) const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 301 | int offset = GetVRegOffset(code_item, core_spills, fp_spills, frame_size, vreg); |
Ian Rogers | 0ec569a | 2012-07-01 16:43:46 -0700 | [diff] [blame] | 302 | DCHECK_EQ(cur_quick_frame, GetCurrentQuickFrame()); |
| 303 | byte* vreg_addr = reinterpret_cast<byte*>(cur_quick_frame) + offset; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 304 | return *reinterpret_cast<uint32_t*>(vreg_addr); |
| 305 | } |
| 306 | |
| 307 | uintptr_t GetReturnPc() const; |
| 308 | |
| 309 | void SetReturnPc(uintptr_t new_ret_pc); |
| 310 | |
| 311 | /* |
| 312 | * Return sp-relative offset for a Dalvik virtual register, compiler |
| 313 | * spill or Method* in bytes using Method*. |
| 314 | * Note that (reg >= 0) refers to a Dalvik register, (reg == -2) |
| 315 | * denotes Method* and (reg <= -3) denotes a compiler temp. |
| 316 | * |
| 317 | * +------------------------+ |
| 318 | * | IN[ins-1] | {Note: resides in caller's frame} |
| 319 | * | . | |
| 320 | * | IN[0] | |
| 321 | * | caller's Method* | |
| 322 | * +========================+ {Note: start of callee's frame} |
| 323 | * | core callee-save spill | {variable sized} |
| 324 | * +------------------------+ |
| 325 | * | fp callee-save spill | |
| 326 | * +------------------------+ |
| 327 | * | filler word | {For compatibility, if V[locals-1] used as wide |
| 328 | * +------------------------+ |
| 329 | * | V[locals-1] | |
| 330 | * | V[locals-2] | |
| 331 | * | . | |
| 332 | * | . | ... (reg == 2) |
| 333 | * | V[1] | ... (reg == 1) |
| 334 | * | V[0] | ... (reg == 0) <---- "locals_start" |
| 335 | * +------------------------+ |
| 336 | * | Compiler temps | ... (reg == -2) |
| 337 | * | | ... (reg == -3) |
| 338 | * | | ... (reg == -4) |
| 339 | * +------------------------+ |
| 340 | * | stack alignment padding| {0 to (kStackAlignWords-1) of padding} |
| 341 | * +------------------------+ |
| 342 | * | OUT[outs-1] | |
| 343 | * | OUT[outs-2] | |
| 344 | * | . | |
| 345 | * | OUT[0] | |
| 346 | * | curMethod* | ... (reg == -1) <<== sp, 16-byte aligned |
| 347 | * +========================+ |
| 348 | */ |
| 349 | static int GetVRegOffset(const DexFile::CodeItem* code_item, |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame^] | 350 | uint32_t core_spills, uint32_t fp_spills, |
| 351 | size_t frame_size, int reg) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 352 | DCHECK_EQ(frame_size & (kStackAlignment - 1), 0U); |
| 353 | int num_spills = __builtin_popcount(core_spills) + __builtin_popcount(fp_spills) + 1; // Filler. |
| 354 | int num_ins = code_item->ins_size_; |
| 355 | int num_regs = code_item->registers_size_ - num_ins; |
| 356 | int locals_start = frame_size - ((num_spills + num_regs) * sizeof(uint32_t)); |
| 357 | if (reg == -2) { |
| 358 | return 0; // Method* |
| 359 | } else if (reg <= -3) { |
| 360 | return locals_start - ((reg + 1) * sizeof(uint32_t)); // Compiler temp. |
| 361 | } else if (reg < num_regs) { |
| 362 | return locals_start + (reg * sizeof(uint32_t)); // Dalvik local reg. |
| 363 | } else { |
| 364 | return frame_size + ((reg - num_regs) * sizeof(uint32_t)) + sizeof(uint32_t); // Dalvik in. |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | uintptr_t GetCurrentQuickFramePc() const { |
| 369 | return cur_quick_frame_pc_; |
| 370 | } |
| 371 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 372 | AbstractMethod** GetCurrentQuickFrame() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 373 | return cur_quick_frame_; |
| 374 | } |
| 375 | |
| 376 | ShadowFrame* GetCurrentShadowFrame() const { |
| 377 | return cur_shadow_frame_; |
| 378 | } |
| 379 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 380 | StackIndirectReferenceTable* GetCurrentSirt() const { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 381 | AbstractMethod** sp = GetCurrentQuickFrame(); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 382 | ++sp; // Skip Method*; SIRT comes next; |
| 383 | return reinterpret_cast<StackIndirectReferenceTable*>(sp); |
| 384 | } |
| 385 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 386 | private: |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 387 | size_t ComputeNumFrames() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 388 | |
| 389 | TraceStackFrame GetTraceStackFrame(uint32_t depth) const { |
| 390 | return trace_stack_->at(trace_stack_->size() - depth - 1); |
| 391 | } |
| 392 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 393 | void SanityCheckFrame() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 394 | |
| 395 | const ManagedStack* const stack_start_; |
| 396 | const std::vector<TraceStackFrame>* const trace_stack_; |
| 397 | ShadowFrame* cur_shadow_frame_; |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 398 | AbstractMethod** cur_quick_frame_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 399 | uintptr_t cur_quick_frame_pc_; |
| 400 | // Lazily computed, number of frames in the stack. |
| 401 | size_t num_frames_; |
| 402 | // Depth of the frame we're currently at. |
| 403 | size_t cur_depth_; |
| 404 | protected: |
| 405 | Context* const context_; |
| 406 | }; |
| 407 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 408 | } // namespace art |
| 409 | |
| 410 | #endif // ART_SRC_STACK_H_ |