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