blob: e58caeee79b5b8fad217c8dcbe5f8b82abefe3ec [file] [log] [blame]
Elliott Hughes68e76522011-10-05 13:22:16 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_STACK_H_
18#define ART_RUNTIME_STACK_H_
Elliott Hughes68e76522011-10-05 13:22:16 -070019
Elliott Hughes68e76522011-10-05 13:22:16 -070020#include <stdint.h>
Ian Rogers40e3bac2012-11-20 00:09:14 -080021#include <string>
Elliott Hughes68e76522011-10-05 13:22:16 -070022
Ian Rogerse63db272014-07-15 15:36:11 -070023#include "dex_file.h"
24#include "instruction_set.h"
25#include "mirror/object_reference.h"
26#include "throw_location.h"
27#include "utils.h"
28#include "verify_object.h"
29
Elliott Hughes68e76522011-10-05 13:22:16 -070030namespace art {
31
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032namespace mirror {
Brian Carlstromea46f952013-07-30 01:26:50 -070033 class ArtMethod;
34 class Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035} // namespace mirror
36
37class Context;
Ian Rogers0399dde2012-06-06 17:09:28 -070038class ShadowFrame;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070039class HandleScope;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070040class ScopedObjectAccess;
Elliott Hughes68e76522011-10-05 13:22:16 -070041class Thread;
42
Ian Rogers2bcb4a42012-11-08 10:39:18 -080043// The kind of vreg being accessed in calls to Set/GetVReg.
44enum VRegKind {
45 kReferenceVReg,
46 kIntVReg,
47 kFloatVReg,
48 kLongLoVReg,
49 kLongHiVReg,
50 kDoubleLoVReg,
51 kDoubleHiVReg,
52 kConstant,
53 kImpreciseConstant,
54 kUndefined,
55};
56
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -080057/**
58 * @brief Represents the virtual register numbers that denote special meaning.
59 * @details This is used to make some virtual register numbers to have specific
60 * semantic meaning. This is done so that the compiler can treat all virtual
61 * registers the same way and only special case when needed. For example,
62 * calculating SSA does not care whether a virtual register is a normal one or
63 * a compiler temporary, so it can deal with them in a consistent manner. But,
64 * for example if backend cares about temporaries because it has custom spill
65 * location, then it can special case them only then.
66 */
67enum VRegBaseRegNum : int {
68 /**
69 * @brief Virtual registers originating from dex have number >= 0.
70 */
71 kVRegBaseReg = 0,
72
73 /**
74 * @brief Invalid virtual register number.
75 */
76 kVRegInvalid = -1,
77
78 /**
79 * @brief Used to denote the base register for compiler temporaries.
80 * @details Compiler temporaries are virtual registers not originating
81 * from dex but that are created by compiler. All virtual register numbers
82 * that are <= kVRegTempBaseReg are categorized as compiler temporaries.
83 */
84 kVRegTempBaseReg = -2,
85
86 /**
87 * @brief Base register of temporary that holds the method pointer.
88 * @details This is a special compiler temporary because it has a specific
89 * location on stack.
90 */
91 kVRegMethodPtrBaseReg = kVRegTempBaseReg,
92
93 /**
94 * @brief Base register of non-special compiler temporary.
95 * @details A non-special compiler temporary is one whose spill location
96 * is flexible.
97 */
98 kVRegNonSpecialTempBaseReg = -3,
99};
100
Ian Rogersef7d42f2014-01-06 12:55:46 -0800101// A reference from the shadow stack to a MirrorType object within the Java heap.
102template<class MirrorType>
103class MANAGED StackReference : public mirror::ObjectReference<false, MirrorType> {
104 public:
105 StackReference<MirrorType>() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
106 : mirror::ObjectReference<false, MirrorType>(nullptr) {}
107
108 static StackReference<MirrorType> FromMirrorPtr(MirrorType* p)
109 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
110 return StackReference<MirrorType>(p);
111 }
112
113 private:
114 StackReference<MirrorType>(MirrorType* p) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
115 : mirror::ObjectReference<false, MirrorType>(p) {}
116};
117
Mathieu Chartier67022432012-11-29 18:04:50 -0800118// ShadowFrame has 3 possible layouts:
119// - portable - a unified array of VRegs and references. Precise references need GC maps.
120// - interpreter - separate VRegs and reference arrays. References are in the reference array.
121// - JNI - just VRegs, but where every VReg holds a reference.
Ian Rogers0399dde2012-06-06 17:09:28 -0700122class ShadowFrame {
Elliott Hughes68e76522011-10-05 13:22:16 -0700123 public:
Ian Rogersef7d42f2014-01-06 12:55:46 -0800124 // Compute size of ShadowFrame in bytes assuming it has a reference array.
Jeff Hao66135192013-05-14 11:02:41 -0700125 static size_t ComputeSize(uint32_t num_vregs) {
126 return sizeof(ShadowFrame) + (sizeof(uint32_t) * num_vregs) +
Ian Rogersef7d42f2014-01-06 12:55:46 -0800127 (sizeof(StackReference<mirror::Object>) * num_vregs);
Jeff Hao66135192013-05-14 11:02:41 -0700128 }
129
130 // Create ShadowFrame in heap for deoptimization.
TDYa127ce4cc0d2012-11-18 16:59:53 -0800131 static ShadowFrame* Create(uint32_t num_vregs, ShadowFrame* link,
Brian Carlstromea46f952013-07-30 01:26:50 -0700132 mirror::ArtMethod* method, uint32_t dex_pc) {
Jeff Hao66135192013-05-14 11:02:41 -0700133 uint8_t* memory = new uint8_t[ComputeSize(num_vregs)];
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200134 return Create(num_vregs, link, method, dex_pc, memory);
Jeff Hao66135192013-05-14 11:02:41 -0700135 }
136
137 // Create ShadowFrame for interpreter using provided memory.
138 static ShadowFrame* Create(uint32_t num_vregs, ShadowFrame* link,
Brian Carlstromea46f952013-07-30 01:26:50 -0700139 mirror::ArtMethod* method, uint32_t dex_pc, void* memory) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800140 ShadowFrame* sf = new (memory) ShadowFrame(num_vregs, link, method, dex_pc, true);
141 return sf;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700142 }
143 ~ShadowFrame() {}
144
TDYa127ce4cc0d2012-11-18 16:59:53 -0800145 bool HasReferenceArray() const {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700146#if defined(ART_USE_PORTABLE_COMPILER)
TDYa127ce4cc0d2012-11-18 16:59:53 -0800147 return (number_of_vregs_ & kHasReferenceArray) != 0;
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700148#else
149 return true;
150#endif
Ian Rogers0399dde2012-06-06 17:09:28 -0700151 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700152
TDYa127ce4cc0d2012-11-18 16:59:53 -0800153 uint32_t NumberOfVRegs() const {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700154#if defined(ART_USE_PORTABLE_COMPILER)
TDYa127ce4cc0d2012-11-18 16:59:53 -0800155 return number_of_vregs_ & ~kHasReferenceArray;
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700156#else
157 return number_of_vregs_;
158#endif
Ian Rogers0399dde2012-06-06 17:09:28 -0700159 }
160
TDYa127ce4cc0d2012-11-18 16:59:53 -0800161 void SetNumberOfVRegs(uint32_t number_of_vregs) {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700162#if defined(ART_USE_PORTABLE_COMPILER)
TDYa127ce4cc0d2012-11-18 16:59:53 -0800163 number_of_vregs_ = number_of_vregs | (number_of_vregs_ & kHasReferenceArray);
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700164#else
165 UNUSED(number_of_vregs);
166 UNIMPLEMENTED(FATAL) << "Should only be called when portable is enabled";
167#endif
Ian Rogers5438ad82012-10-15 17:22:44 -0700168 }
169
Ian Rogers0399dde2012-06-06 17:09:28 -0700170 uint32_t GetDexPC() const {
171 return dex_pc_;
172 }
173
174 void SetDexPC(uint32_t dex_pc) {
175 dex_pc_ = dex_pc;
176 }
177
Ian Rogers0399dde2012-06-06 17:09:28 -0700178 ShadowFrame* GetLink() const {
179 return link_;
180 }
181
182 void SetLink(ShadowFrame* frame) {
183 DCHECK_NE(this, frame);
184 link_ = frame;
185 }
186
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700187 int32_t GetVReg(size_t i) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800188 DCHECK_LT(i, NumberOfVRegs());
189 const uint32_t* vreg = &vregs_[i];
190 return *reinterpret_cast<const int32_t*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700191 }
192
193 float GetVRegFloat(size_t i) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800194 DCHECK_LT(i, NumberOfVRegs());
195 // NOTE: Strict-aliasing?
196 const uint32_t* vreg = &vregs_[i];
197 return *reinterpret_cast<const float*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700198 }
199
200 int64_t GetVRegLong(size_t i) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200201 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800202 const uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700203 // Alignment attribute required for GCC 4.8
204 typedef const int64_t unaligned_int64 __attribute__ ((aligned (4)));
205 return *reinterpret_cast<unaligned_int64*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700206 }
207
208 double GetVRegDouble(size_t i) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200209 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800210 const uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700211 // Alignment attribute required for GCC 4.8
212 typedef const double unaligned_double __attribute__ ((aligned (4)));
213 return *reinterpret_cast<unaligned_double*>(vreg);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800214 }
215
Mathieu Chartier4e305412014-02-19 10:54:44 -0800216 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800217 mirror::Object* GetVRegReference(size_t i) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800218 DCHECK_LT(i, NumberOfVRegs());
Mathieu Chartier4e305412014-02-19 10:54:44 -0800219 mirror::Object* ref;
TDYa127ce4cc0d2012-11-18 16:59:53 -0800220 if (HasReferenceArray()) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800221 ref = References()[i].AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800222 } else {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800223 const uint32_t* vreg_ptr = &vregs_[i];
Mathieu Chartier4e305412014-02-19 10:54:44 -0800224 ref = reinterpret_cast<const StackReference<mirror::Object>*>(vreg_ptr)->AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800225 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800226 if (kVerifyFlags & kVerifyReads) {
227 VerifyObject(ref);
228 }
229 return ref;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700230 }
231
Jeff Hao16743632013-05-08 10:59:04 -0700232 // Get view of vregs as range of consecutive arguments starting at i.
233 uint32_t* GetVRegArgs(size_t i) {
234 return &vregs_[i];
235 }
236
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700237 void SetVReg(size_t i, int32_t val) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800238 DCHECK_LT(i, NumberOfVRegs());
239 uint32_t* vreg = &vregs_[i];
240 *reinterpret_cast<int32_t*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700241 // This is needed for moving collectors since these can update the vreg references if they
242 // happen to agree with references in the reference array.
243 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800244 References()[i].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700245 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700246 }
247
248 void SetVRegFloat(size_t i, float val) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800249 DCHECK_LT(i, NumberOfVRegs());
250 uint32_t* vreg = &vregs_[i];
251 *reinterpret_cast<float*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700252 // This is needed for moving collectors since these can update the vreg references if they
253 // happen to agree with references in the reference array.
254 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800255 References()[i].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700256 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700257 }
258
259 void SetVRegLong(size_t i, int64_t val) {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200260 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800261 uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700262 // Alignment attribute required for GCC 4.8
263 typedef int64_t unaligned_int64 __attribute__ ((aligned (4)));
264 *reinterpret_cast<unaligned_int64*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700265 // This is needed for moving collectors since these can update the vreg references if they
266 // happen to agree with references in the reference array.
267 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800268 References()[i].Clear();
269 References()[i + 1].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700270 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700271 }
272
273 void SetVRegDouble(size_t i, double val) {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200274 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800275 uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700276 // Alignment attribute required for GCC 4.8
277 typedef double unaligned_double __attribute__ ((aligned (4)));
278 *reinterpret_cast<unaligned_double*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700279 // This is needed for moving collectors since these can update the vreg references if they
280 // happen to agree with references in the reference array.
281 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800282 References()[i].Clear();
283 References()[i + 1].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700284 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700285 }
286
Mathieu Chartier4e305412014-02-19 10:54:44 -0800287 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800288 void SetVRegReference(size_t i, mirror::Object* val) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800289 DCHECK_LT(i, NumberOfVRegs());
Mathieu Chartier4e305412014-02-19 10:54:44 -0800290 if (kVerifyFlags & kVerifyWrites) {
291 VerifyObject(val);
292 }
TDYa127ce4cc0d2012-11-18 16:59:53 -0800293 uint32_t* vreg = &vregs_[i];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800294 reinterpret_cast<StackReference<mirror::Object>*>(vreg)->Assign(val);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800295 if (HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800296 References()[i].Assign(val);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800297 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700298 }
299
Ian Rogersef7d42f2014-01-06 12:55:46 -0800300 mirror::ArtMethod* GetMethod() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
301 DCHECK(method_ != nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700302 return method_;
Elliott Hughes68e76522011-10-05 13:22:16 -0700303 }
304
Hiroshi Yamauchi92d1a662014-05-15 21:43:59 -0700305 mirror::ArtMethod** GetMethodAddress() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
306 DCHECK(method_ != nullptr);
307 return &method_;
308 }
309
Ian Rogers62d6c772013-02-27 08:32:07 -0800310 mirror::Object* GetThisObject() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
311
Jeff Haoe701f482013-05-24 11:50:49 -0700312 mirror::Object* GetThisObject(uint16_t num_ins) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
313
Ian Rogers62d6c772013-02-27 08:32:07 -0800314 ThrowLocation GetCurrentLocationForThrow() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
315
Brian Carlstromea46f952013-07-30 01:26:50 -0700316 void SetMethod(mirror::ArtMethod* method) {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700317#if defined(ART_USE_PORTABLE_COMPILER)
Ian Rogersef7d42f2014-01-06 12:55:46 -0800318 DCHECK(method != nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700319 method_ = method;
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700320#else
321 UNUSED(method);
322 UNIMPLEMENTED(FATAL) << "Should only be called when portable is enabled";
323#endif
Elliott Hughes68e76522011-10-05 13:22:16 -0700324 }
325
Ian Rogersef7d42f2014-01-06 12:55:46 -0800326 bool Contains(StackReference<mirror::Object>* shadow_frame_entry_obj) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800327 if (HasReferenceArray()) {
328 return ((&References()[0] <= shadow_frame_entry_obj) &&
329 (shadow_frame_entry_obj <= (&References()[NumberOfVRegs() - 1])));
330 } else {
331 uint32_t* shadow_frame_entry = reinterpret_cast<uint32_t*>(shadow_frame_entry_obj);
332 return ((&vregs_[0] <= shadow_frame_entry) &&
333 (shadow_frame_entry <= (&vregs_[NumberOfVRegs() - 1])));
Ian Rogers0399dde2012-06-06 17:09:28 -0700334 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700335 }
336
Ian Rogers0399dde2012-06-06 17:09:28 -0700337 static size_t LinkOffset() {
338 return OFFSETOF_MEMBER(ShadowFrame, link_);
339 }
340
Ian Rogers0399dde2012-06-06 17:09:28 -0700341 static size_t MethodOffset() {
342 return OFFSETOF_MEMBER(ShadowFrame, method_);
343 }
344
Ian Rogers0399dde2012-06-06 17:09:28 -0700345 static size_t DexPCOffset() {
346 return OFFSETOF_MEMBER(ShadowFrame, dex_pc_);
347 }
348
Ian Rogers5438ad82012-10-15 17:22:44 -0700349 static size_t NumberOfVRegsOffset() {
350 return OFFSETOF_MEMBER(ShadowFrame, number_of_vregs_);
351 }
352
TDYa127ce4cc0d2012-11-18 16:59:53 -0800353 static size_t VRegsOffset() {
354 return OFFSETOF_MEMBER(ShadowFrame, vregs_);
Ian Rogers5438ad82012-10-15 17:22:44 -0700355 }
356
Elliott Hughes68e76522011-10-05 13:22:16 -0700357 private:
Brian Carlstromea46f952013-07-30 01:26:50 -0700358 ShadowFrame(uint32_t num_vregs, ShadowFrame* link, mirror::ArtMethod* method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800359 uint32_t dex_pc, bool has_reference_array)
TDYa127ce4cc0d2012-11-18 16:59:53 -0800360 : number_of_vregs_(num_vregs), link_(link), method_(method), dex_pc_(dex_pc) {
361 if (has_reference_array) {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700362#if defined(ART_USE_PORTABLE_COMPILER)
363 CHECK_LT(num_vregs, static_cast<uint32_t>(kHasReferenceArray));
TDYa127ce4cc0d2012-11-18 16:59:53 -0800364 number_of_vregs_ |= kHasReferenceArray;
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700365#endif
Ian Rogersef7d42f2014-01-06 12:55:46 -0800366 memset(vregs_, 0, num_vregs * (sizeof(uint32_t) + sizeof(StackReference<mirror::Object>)));
Mathieu Chartier67022432012-11-29 18:04:50 -0800367 } else {
Jeff Haoe701f482013-05-24 11:50:49 -0700368 memset(vregs_, 0, num_vregs * sizeof(uint32_t));
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700369 }
370 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700371
Ian Rogersef7d42f2014-01-06 12:55:46 -0800372 const StackReference<mirror::Object>* References() const {
Mathieu Chartier67022432012-11-29 18:04:50 -0800373 DCHECK(HasReferenceArray());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800374 const uint32_t* vreg_end = &vregs_[NumberOfVRegs()];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800375 return reinterpret_cast<const StackReference<mirror::Object>*>(vreg_end);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800376 }
377
Ian Rogersef7d42f2014-01-06 12:55:46 -0800378 StackReference<mirror::Object>* References() {
379 return const_cast<StackReference<mirror::Object>*>(const_cast<const ShadowFrame*>(this)->References());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800380 }
381
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700382#if defined(ART_USE_PORTABLE_COMPILER)
TDYa127ce4cc0d2012-11-18 16:59:53 -0800383 enum ShadowFrameFlag {
384 kHasReferenceArray = 1ul << 31
385 };
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700386 // TODO: make const in the portable case.
TDYa127ce4cc0d2012-11-18 16:59:53 -0800387 uint32_t number_of_vregs_;
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700388#else
389 const uint32_t number_of_vregs_;
390#endif
Ian Rogers5438ad82012-10-15 17:22:44 -0700391 // Link to previous shadow frame or NULL.
Ian Rogers0399dde2012-06-06 17:09:28 -0700392 ShadowFrame* link_;
Brian Carlstromea46f952013-07-30 01:26:50 -0700393 mirror::ArtMethod* method_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700394 uint32_t dex_pc_;
TDYa127ce4cc0d2012-11-18 16:59:53 -0800395 uint32_t vregs_[0];
Elliott Hughes68e76522011-10-05 13:22:16 -0700396
Ian Rogers0399dde2012-06-06 17:09:28 -0700397 DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame);
Elliott Hughes68e76522011-10-05 13:22:16 -0700398};
399
Ian Rogers0399dde2012-06-06 17:09:28 -0700400// The managed stack is used to record fragments of managed code stacks. Managed code stacks
401// may either be shadow frames or lists of frames using fixed frame sizes. Transition records are
402// necessary for transitions between code using different frame layouts and transitions into native
403// code.
Ian Rogersdf1ce912012-11-27 17:07:11 -0800404class PACKED(4) ManagedStack {
Ian Rogers0399dde2012-06-06 17:09:28 -0700405 public:
Ian Rogersca190662012-06-26 15:45:57 -0700406 ManagedStack()
407 : link_(NULL), top_shadow_frame_(NULL), top_quick_frame_(NULL), top_quick_frame_pc_(0) {}
Ian Rogers81d425b2012-09-27 16:03:43 -0700408
409 void PushManagedStackFragment(ManagedStack* fragment) {
410 // Copy this top fragment into given fragment.
411 memcpy(fragment, this, sizeof(ManagedStack));
412 // Clear this fragment, which has become the top.
413 memset(this, 0, sizeof(ManagedStack));
414 // Link our top fragment onto the given fragment.
415 link_ = fragment;
416 }
417
418 void PopManagedStackFragment(const ManagedStack& fragment) {
419 DCHECK(&fragment == link_);
420 // Copy this given fragment back to the top.
421 memcpy(this, &fragment, sizeof(ManagedStack));
422 }
Ian Rogers0399dde2012-06-06 17:09:28 -0700423
424 ManagedStack* GetLink() const {
425 return link_;
426 }
427
Andreas Gampecf4035a2014-05-28 22:43:01 -0700428 StackReference<mirror::ArtMethod>* GetTopQuickFrame() const {
Ian Rogers0399dde2012-06-06 17:09:28 -0700429 return top_quick_frame_;
430 }
431
Andreas Gampecf4035a2014-05-28 22:43:01 -0700432 void SetTopQuickFrame(StackReference<mirror::ArtMethod>* top) {
Sebastien Hertza7b0c422013-04-05 16:19:39 +0200433 DCHECK(top_shadow_frame_ == NULL);
Ian Rogers0399dde2012-06-06 17:09:28 -0700434 top_quick_frame_ = top;
435 }
436
437 uintptr_t GetTopQuickFramePc() const {
438 return top_quick_frame_pc_;
439 }
440
441 void SetTopQuickFramePc(uintptr_t pc) {
Sebastien Hertza7b0c422013-04-05 16:19:39 +0200442 DCHECK(top_shadow_frame_ == NULL);
Ian Rogers0399dde2012-06-06 17:09:28 -0700443 top_quick_frame_pc_ = pc;
444 }
445
446 static size_t TopQuickFrameOffset() {
447 return OFFSETOF_MEMBER(ManagedStack, top_quick_frame_);
448 }
449
450 static size_t TopQuickFramePcOffset() {
451 return OFFSETOF_MEMBER(ManagedStack, top_quick_frame_pc_);
452 }
453
454 ShadowFrame* PushShadowFrame(ShadowFrame* new_top_frame) {
Sebastien Hertza7b0c422013-04-05 16:19:39 +0200455 DCHECK(top_quick_frame_ == NULL);
Ian Rogers0399dde2012-06-06 17:09:28 -0700456 ShadowFrame* old_frame = top_shadow_frame_;
457 top_shadow_frame_ = new_top_frame;
458 new_top_frame->SetLink(old_frame);
459 return old_frame;
460 }
461
462 ShadowFrame* PopShadowFrame() {
Sebastien Hertza7b0c422013-04-05 16:19:39 +0200463 DCHECK(top_quick_frame_ == NULL);
Ian Rogers0399dde2012-06-06 17:09:28 -0700464 CHECK(top_shadow_frame_ != NULL);
465 ShadowFrame* frame = top_shadow_frame_;
466 top_shadow_frame_ = frame->GetLink();
467 return frame;
468 }
469
470 ShadowFrame* GetTopShadowFrame() const {
471 return top_shadow_frame_;
472 }
473
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800474 void SetTopShadowFrame(ShadowFrame* top) {
Sebastien Hertza7b0c422013-04-05 16:19:39 +0200475 DCHECK(top_quick_frame_ == NULL);
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800476 top_shadow_frame_ = top;
477 }
478
Ian Rogers0399dde2012-06-06 17:09:28 -0700479 static size_t TopShadowFrameOffset() {
480 return OFFSETOF_MEMBER(ManagedStack, top_shadow_frame_);
481 }
482
Ian Rogersef7d42f2014-01-06 12:55:46 -0800483 size_t NumJniShadowFrameReferences() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700484
Ian Rogersef7d42f2014-01-06 12:55:46 -0800485 bool ShadowFramesContain(StackReference<mirror::Object>* shadow_frame_entry) const;
Ian Rogers0399dde2012-06-06 17:09:28 -0700486
487 private:
488 ManagedStack* link_;
489 ShadowFrame* top_shadow_frame_;
Andreas Gampecf4035a2014-05-28 22:43:01 -0700490 StackReference<mirror::ArtMethod>* top_quick_frame_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700491 uintptr_t top_quick_frame_pc_;
492};
493
494class StackVisitor {
495 protected:
Ian Rogers7a22fa62013-01-23 12:16:16 -0800496 StackVisitor(Thread* thread, Context* context) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700497
498 public:
499 virtual ~StackVisitor() {}
500
501 // Return 'true' if we should continue to visit more frames, 'false' to stop.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700502 virtual bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
Ian Rogers0399dde2012-06-06 17:09:28 -0700503
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700504 void WalkStack(bool include_transitions = false)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700505 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700506
Ian Rogersef7d42f2014-01-06 12:55:46 -0800507 mirror::ArtMethod* GetMethod() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
508 if (cur_shadow_frame_ != nullptr) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700509 return cur_shadow_frame_->GetMethod();
Ian Rogersef7d42f2014-01-06 12:55:46 -0800510 } else if (cur_quick_frame_ != nullptr) {
Andreas Gampecf4035a2014-05-28 22:43:01 -0700511 return cur_quick_frame_->AsMirrorPtr();
Hiroshi Yamauchi92d1a662014-05-15 21:43:59 -0700512 } else {
513 return nullptr;
514 }
515 }
516
Ian Rogers0399dde2012-06-06 17:09:28 -0700517 bool IsShadowFrame() const {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800518 return cur_shadow_frame_ != nullptr;
Ian Rogers0399dde2012-06-06 17:09:28 -0700519 }
520
Dave Allisonb373e092014-02-20 16:06:36 -0800521 uint32_t GetDexPc(bool abort_on_failure = true) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0c7abda2012-09-19 13:33:42 -0700522
Ian Rogers62d6c772013-02-27 08:32:07 -0800523 mirror::Object* GetThisObject() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
524
Ian Rogers0c7abda2012-09-19 13:33:42 -0700525 size_t GetNativePcOffset() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
526
Ian Rogersef7d42f2014-01-06 12:55:46 -0800527 uintptr_t* CalleeSaveAddress(int num, size_t frame_size) const
528 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700529 // Callee saves are held at the top of the frame
Ian Rogersef7d42f2014-01-06 12:55:46 -0800530 DCHECK(GetMethod() != nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700531 byte* save_addr =
532 reinterpret_cast<byte*>(cur_quick_frame_) + frame_size - ((num + 1) * kPointerSize);
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800533#if defined(__i386__) || defined(__x86_64__)
Ian Rogers0399dde2012-06-06 17:09:28 -0700534 save_addr -= kPointerSize; // account for return address
535#endif
Mathieu Chartier67022432012-11-29 18:04:50 -0800536 return reinterpret_cast<uintptr_t*>(save_addr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700537 }
538
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700539 // Returns the height of the stack in the managed stack frames, including transitions.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700540 size_t GetFrameHeight() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800541 return GetNumFrames() - cur_depth_ - 1;
Ian Rogers0399dde2012-06-06 17:09:28 -0700542 }
543
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700544 // Returns a frame ID for JDWP use, starting from 1.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700545 size_t GetFrameId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700546 return GetFrameHeight() + 1;
547 }
548
Ian Rogersb726dcb2012-09-05 08:57:23 -0700549 size_t GetNumFrames() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700550 if (num_frames_ == 0) {
Ian Rogers7a22fa62013-01-23 12:16:16 -0800551 num_frames_ = ComputeNumFrames(thread_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700552 }
553 return num_frames_;
554 }
555
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -0700556 size_t GetFrameDepth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
557 return cur_depth_;
558 }
559
Ian Rogers5cf98192014-05-29 21:31:50 -0700560 // Get the method and dex pc immediately after the one that's currently being visited.
561 bool GetNextMethodAndDexPc(mirror::ArtMethod** next_method, uint32_t* next_dex_pc)
562 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
563
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200564 bool GetVReg(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind, uint32_t* val) const
Ian Rogers2bcb4a42012-11-08 10:39:18 -0800565 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700566
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200567 uint32_t GetVReg(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind) const
568 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
569 uint32_t val;
570 bool success = GetVReg(m, vreg, kind, &val);
571 CHECK(success) << "Failed to read vreg " << vreg << " of kind " << kind;
572 return val;
573 }
574
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200575 bool GetVRegPair(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind_lo, VRegKind kind_hi,
576 uint64_t* val) const
577 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
578
579 uint64_t GetVRegPair(mirror::ArtMethod* m, uint16_t vreg, VRegKind kind_lo,
580 VRegKind kind_hi) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
581 uint64_t val;
582 bool success = GetVRegPair(m, vreg, kind_lo, kind_hi, &val);
583 CHECK(success) << "Failed to read vreg pair " << vreg
584 << " of kind [" << kind_lo << "," << kind_hi << "]";
585 return val;
586 }
587
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200588 bool SetVReg(mirror::ArtMethod* m, uint16_t vreg, uint32_t new_value, VRegKind kind)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700589 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700590
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200591 bool SetVRegPair(mirror::ArtMethod* m, uint16_t vreg, uint64_t new_value,
592 VRegKind kind_lo, VRegKind kind_hi)
593 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
594
Mathieu Chartier815873e2014-02-13 18:02:13 -0800595 uintptr_t* GetGPRAddress(uint32_t reg) const;
Ian Rogers0399dde2012-06-06 17:09:28 -0700596
Mathieu Chartier423d2a32013-09-12 17:33:56 -0700597 // This is a fast-path for getting/setting values in a quick frame.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700598 uint32_t* GetVRegAddr(StackReference<mirror::ArtMethod>* cur_quick_frame,
599 const DexFile::CodeItem* code_item,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800600 uint32_t core_spills, uint32_t fp_spills, size_t frame_size,
601 uint16_t vreg) const {
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000602 int offset = GetVRegOffset(code_item, core_spills, fp_spills, frame_size, vreg, kRuntimeISA);
Ian Rogers0ec569a2012-07-01 16:43:46 -0700603 DCHECK_EQ(cur_quick_frame, GetCurrentQuickFrame());
604 byte* vreg_addr = reinterpret_cast<byte*>(cur_quick_frame) + offset;
Mathieu Chartier423d2a32013-09-12 17:33:56 -0700605 return reinterpret_cast<uint32_t*>(vreg_addr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700606 }
607
Ian Rogersef7d42f2014-01-06 12:55:46 -0800608 uintptr_t GetReturnPc() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700609
Ian Rogersef7d42f2014-01-06 12:55:46 -0800610 void SetReturnPc(uintptr_t new_ret_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700611
612 /*
613 * Return sp-relative offset for a Dalvik virtual register, compiler
614 * spill or Method* in bytes using Method*.
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800615 * Note that (reg >= 0) refers to a Dalvik register, (reg == -1)
616 * denotes an invalid Dalvik register, (reg == -2) denotes Method*
617 * and (reg <= -3) denotes a compiler temporary. A compiler temporary
618 * can be thought of as a virtual register that does not exist in the
619 * dex but holds intermediate values to help optimizations and code
620 * generation. A special compiler temporary is one whose location
621 * in frame is well known while non-special ones do not have a requirement
622 * on location in frame as long as code generator itself knows how
623 * to access them.
Ian Rogers0399dde2012-06-06 17:09:28 -0700624 *
Zheng Xu511c8a62014-06-03 16:22:23 +0800625 * +---------------------------+
626 * | IN[ins-1] | {Note: resides in caller's frame}
627 * | . |
628 * | IN[0] |
629 * | caller's ArtMethod | ... StackReference<ArtMethod>
630 * +===========================+ {Note: start of callee's frame}
631 * | core callee-save spill | {variable sized}
632 * +---------------------------+
633 * | fp callee-save spill |
634 * +---------------------------+
635 * | filler word | {For compatibility, if V[locals-1] used as wide
636 * +---------------------------+
637 * | V[locals-1] |
638 * | V[locals-2] |
639 * | . |
640 * | . | ... (reg == 2)
641 * | V[1] | ... (reg == 1)
642 * | V[0] | ... (reg == 0) <---- "locals_start"
643 * +---------------------------+
644 * | Compiler temp region | ... (reg <= -3)
645 * | |
646 * | |
647 * +---------------------------+
648 * | stack alignment padding | {0 to (kStackAlignWords-1) of padding}
649 * +---------------------------+
650 * | OUT[outs-1] |
651 * | OUT[outs-2] |
652 * | . |
653 * | OUT[0] |
654 * | StackReference<ArtMethod> | ... (reg == -2) <<== sp, 16-byte aligned
655 * +===========================+
Ian Rogers0399dde2012-06-06 17:09:28 -0700656 */
657 static int GetVRegOffset(const DexFile::CodeItem* code_item,
Ian Rogersb23a7722012-10-09 16:54:26 -0700658 uint32_t core_spills, uint32_t fp_spills,
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000659 size_t frame_size, int reg, InstructionSet isa) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700660 DCHECK_EQ(frame_size & (kStackAlignment - 1), 0U);
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800661 DCHECK_NE(reg, static_cast<int>(kVRegInvalid));
Vladimir Marko81949632014-05-02 11:53:22 +0100662 int spill_size = POPCOUNT(core_spills) * GetBytesPerGprSpillLocation(isa)
663 + POPCOUNT(fp_spills) * GetBytesPerFprSpillLocation(isa)
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000664 + sizeof(uint32_t); // Filler.
Ian Rogers0399dde2012-06-06 17:09:28 -0700665 int num_ins = code_item->ins_size_;
666 int num_regs = code_item->registers_size_ - num_ins;
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000667 int locals_start = frame_size - spill_size - num_regs * sizeof(uint32_t);
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800668 if (reg == static_cast<int>(kVRegMethodPtrBaseReg)) {
669 // The current method pointer corresponds to special location on stack.
670 return 0;
671 } else if (reg <= static_cast<int>(kVRegNonSpecialTempBaseReg)) {
672 /*
673 * Special temporaries may have custom locations and the logic above deals with that.
674 * However, non-special temporaries are placed relative to the locals. Since the
675 * virtual register numbers for temporaries "grow" in negative direction, reg number
676 * will always be <= to the temp base reg. Thus, the logic ensures that the first
677 * temp is at offset -4 bytes from locals, the second is at -8 bytes from locals,
678 * and so on.
679 */
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000680 int relative_offset =
681 (reg + std::abs(static_cast<int>(kVRegNonSpecialTempBaseReg)) - 1) * sizeof(uint32_t);
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800682 return locals_start + relative_offset;
683 } else if (reg < num_regs) {
684 return locals_start + (reg * sizeof(uint32_t));
Ian Rogers0399dde2012-06-06 17:09:28 -0700685 } else {
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800686 // Handle ins.
buzbee82818642014-06-04 15:35:41 -0700687 return frame_size + ((reg - num_regs) * sizeof(uint32_t)) +
688 sizeof(StackReference<mirror::ArtMethod>);
Ian Rogers0399dde2012-06-06 17:09:28 -0700689 }
690 }
691
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000692 static int GetOutVROffset(uint16_t out_num, InstructionSet isa) {
buzbee82818642014-06-04 15:35:41 -0700693 // According to stack model, the first out is above the Method referernce.
694 return sizeof(StackReference<mirror::ArtMethod>) + (out_num * sizeof(uint32_t));
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800695 }
696
Ian Rogers0399dde2012-06-06 17:09:28 -0700697 uintptr_t GetCurrentQuickFramePc() const {
698 return cur_quick_frame_pc_;
699 }
700
Andreas Gampecf4035a2014-05-28 22:43:01 -0700701 StackReference<mirror::ArtMethod>* GetCurrentQuickFrame() const {
Ian Rogers0399dde2012-06-06 17:09:28 -0700702 return cur_quick_frame_;
703 }
704
705 ShadowFrame* GetCurrentShadowFrame() const {
706 return cur_shadow_frame_;
707 }
708
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700709 HandleScope* GetCurrentHandleScope() const {
Andreas Gampecf4035a2014-05-28 22:43:01 -0700710 StackReference<mirror::ArtMethod>* sp = GetCurrentQuickFrame();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700711 ++sp; // Skip Method*; handle scope comes next;
712 return reinterpret_cast<HandleScope*>(sp);
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700713 }
714
Ian Rogers40e3bac2012-11-20 00:09:14 -0800715 std::string DescribeLocation() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
716
Ian Rogers7a22fa62013-01-23 12:16:16 -0800717 static size_t ComputeNumFrames(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers306057f2012-11-26 12:45:53 -0800718
Ian Rogers7a22fa62013-01-23 12:16:16 -0800719 static void DescribeStack(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers306057f2012-11-26 12:45:53 -0800720
Ian Rogers0399dde2012-06-06 17:09:28 -0700721 private:
Ian Rogers5cf98192014-05-29 21:31:50 -0700722 // Private constructor known in the case that num_frames_ has already been computed.
723 StackVisitor(Thread* thread, Context* context, size_t num_frames)
724 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
725
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200726 bool GetGPR(uint32_t reg, uintptr_t* val) const;
727 bool SetGPR(uint32_t reg, uintptr_t value);
728 bool GetFPR(uint32_t reg, uintptr_t* val) const;
729 bool SetFPR(uint32_t reg, uintptr_t value);
730
Ian Rogersb726dcb2012-09-05 08:57:23 -0700731 void SanityCheckFrame() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700732
Ian Rogers7a22fa62013-01-23 12:16:16 -0800733 Thread* const thread_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700734 ShadowFrame* cur_shadow_frame_;
Andreas Gampecf4035a2014-05-28 22:43:01 -0700735 StackReference<mirror::ArtMethod>* cur_quick_frame_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700736 uintptr_t cur_quick_frame_pc_;
737 // Lazily computed, number of frames in the stack.
738 size_t num_frames_;
739 // Depth of the frame we're currently at.
740 size_t cur_depth_;
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700741
Ian Rogers0399dde2012-06-06 17:09:28 -0700742 protected:
743 Context* const context_;
744};
745
Elliott Hughes68e76522011-10-05 13:22:16 -0700746} // namespace art
747
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700748#endif // ART_RUNTIME_STACK_H_