blob: 5bbf003e5db736c19edb8406893776ae36389a0c [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 Rogersd582fa42014-11-05 23:46:43 -080023#include "arch/instruction_set.h"
Ian Rogerse63db272014-07-15 15:36:11 -070024#include "dex_file.h"
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -080025#include "gc_root.h"
Ian Rogerse63db272014-07-15 15:36:11 -070026#include "mirror/object_reference.h"
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080027#include "read_barrier.h"
Ian Rogerse63db272014-07-15 15:36:11 -070028#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 Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034} // namespace mirror
35
Mathieu Chartiere401d142015-04-22 13:56:20 -070036class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037class Context;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070038class HandleScope;
Nicolas Geoffray57f61612015-05-15 13:20:41 +010039class InlineInfo;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070040class ScopedObjectAccess;
Nicolas Geoffray57f61612015-05-15 13:20:41 +010041class ShadowFrame;
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000042class StackVisitor;
Elliott Hughes68e76522011-10-05 13:22:16 -070043class Thread;
44
Ian Rogers2bcb4a42012-11-08 10:39:18 -080045// The kind of vreg being accessed in calls to Set/GetVReg.
46enum VRegKind {
47 kReferenceVReg,
48 kIntVReg,
49 kFloatVReg,
50 kLongLoVReg,
51 kLongHiVReg,
52 kDoubleLoVReg,
53 kDoubleHiVReg,
54 kConstant,
55 kImpreciseConstant,
56 kUndefined,
57};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070058std::ostream& operator<<(std::ostream& os, const VRegKind& rhs);
Ian Rogers2bcb4a42012-11-08 10:39:18 -080059
Ian Rogersef7d42f2014-01-06 12:55:46 -080060// A reference from the shadow stack to a MirrorType object within the Java heap.
61template<class MirrorType>
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070062class MANAGED StackReference : public mirror::CompressedReference<MirrorType> {
Ian Rogersef7d42f2014-01-06 12:55:46 -080063};
64
Elliott Hughes956af0f2014-12-11 14:34:28 -080065// ShadowFrame has 2 possible layouts:
Mathieu Chartier67022432012-11-29 18:04:50 -080066// - interpreter - separate VRegs and reference arrays. References are in the reference array.
67// - JNI - just VRegs, but where every VReg holds a reference.
Ian Rogers0399dde2012-06-06 17:09:28 -070068class ShadowFrame {
Elliott Hughes68e76522011-10-05 13:22:16 -070069 public:
Ian Rogersef7d42f2014-01-06 12:55:46 -080070 // Compute size of ShadowFrame in bytes assuming it has a reference array.
Jeff Hao66135192013-05-14 11:02:41 -070071 static size_t ComputeSize(uint32_t num_vregs) {
72 return sizeof(ShadowFrame) + (sizeof(uint32_t) * num_vregs) +
Ian Rogersef7d42f2014-01-06 12:55:46 -080073 (sizeof(StackReference<mirror::Object>) * num_vregs);
Jeff Hao66135192013-05-14 11:02:41 -070074 }
75
76 // Create ShadowFrame in heap for deoptimization.
Christopher Ferris241a9582015-04-27 15:19:41 -070077 static ShadowFrame* CreateDeoptimizedFrame(uint32_t num_vregs, ShadowFrame* link,
Mathieu Chartiere401d142015-04-22 13:56:20 -070078 ArtMethod* method, uint32_t dex_pc) {
Jeff Hao66135192013-05-14 11:02:41 -070079 uint8_t* memory = new uint8_t[ComputeSize(num_vregs)];
Sebastien Hertzc61124b2013-09-10 11:44:19 +020080 return Create(num_vregs, link, method, dex_pc, memory);
Jeff Hao66135192013-05-14 11:02:41 -070081 }
82
Christopher Ferris241a9582015-04-27 15:19:41 -070083 // Delete a ShadowFrame allocated on the heap for deoptimization.
84 static void DeleteDeoptimizedFrame(ShadowFrame* sf) {
85 uint8_t* memory = reinterpret_cast<uint8_t*>(sf);
86 delete[] memory;
87 }
88
Jeff Hao66135192013-05-14 11:02:41 -070089 // Create ShadowFrame for interpreter using provided memory.
90 static ShadowFrame* Create(uint32_t num_vregs, ShadowFrame* link,
Mathieu Chartiere401d142015-04-22 13:56:20 -070091 ArtMethod* method, uint32_t dex_pc, void* memory) {
TDYa127ce4cc0d2012-11-18 16:59:53 -080092 ShadowFrame* sf = new (memory) ShadowFrame(num_vregs, link, method, dex_pc, true);
93 return sf;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -070094 }
95 ~ShadowFrame() {}
96
Igor Murashkinc449e8b2015-06-10 15:56:42 -070097 // TODO(iam): Clean references array up since they're always there,
98 // we don't need to do conditionals.
TDYa127ce4cc0d2012-11-18 16:59:53 -080099 bool HasReferenceArray() const {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700100 return true;
Ian Rogers0399dde2012-06-06 17:09:28 -0700101 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700102
TDYa127ce4cc0d2012-11-18 16:59:53 -0800103 uint32_t NumberOfVRegs() const {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700104 return number_of_vregs_;
Ian Rogers5438ad82012-10-15 17:22:44 -0700105 }
106
Ian Rogers0399dde2012-06-06 17:09:28 -0700107 uint32_t GetDexPC() const {
108 return dex_pc_;
109 }
110
111 void SetDexPC(uint32_t dex_pc) {
112 dex_pc_ = dex_pc;
113 }
114
Ian Rogers0399dde2012-06-06 17:09:28 -0700115 ShadowFrame* GetLink() const {
116 return link_;
117 }
118
119 void SetLink(ShadowFrame* frame) {
120 DCHECK_NE(this, frame);
121 link_ = frame;
122 }
123
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700124 int32_t GetVReg(size_t i) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800125 DCHECK_LT(i, NumberOfVRegs());
126 const uint32_t* vreg = &vregs_[i];
127 return *reinterpret_cast<const int32_t*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700128 }
129
130 float GetVRegFloat(size_t i) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800131 DCHECK_LT(i, NumberOfVRegs());
132 // NOTE: Strict-aliasing?
133 const uint32_t* vreg = &vregs_[i];
134 return *reinterpret_cast<const float*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700135 }
136
137 int64_t GetVRegLong(size_t i) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200138 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800139 const uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700140 // Alignment attribute required for GCC 4.8
141 typedef const int64_t unaligned_int64 __attribute__ ((aligned (4)));
142 return *reinterpret_cast<unaligned_int64*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700143 }
144
145 double GetVRegDouble(size_t i) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200146 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800147 const uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700148 // Alignment attribute required for GCC 4.8
149 typedef const double unaligned_double __attribute__ ((aligned (4)));
150 return *reinterpret_cast<unaligned_double*>(vreg);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800151 }
152
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700153 // Look up the reference given its virtual register number.
154 // If this returns non-null then this does not mean the vreg is currently a reference
155 // on non-moving collectors. Check that the raw reg with GetVReg is equal to this if not certain.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800156 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700157 mirror::Object* GetVRegReference(size_t i) const SHARED_REQUIRES(Locks::mutator_lock_) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800158 DCHECK_LT(i, NumberOfVRegs());
Mathieu Chartier4e305412014-02-19 10:54:44 -0800159 mirror::Object* ref;
TDYa127ce4cc0d2012-11-18 16:59:53 -0800160 if (HasReferenceArray()) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800161 ref = References()[i].AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800162 } else {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800163 const uint32_t* vreg_ptr = &vregs_[i];
Mathieu Chartier4e305412014-02-19 10:54:44 -0800164 ref = reinterpret_cast<const StackReference<mirror::Object>*>(vreg_ptr)->AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800165 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800166 if (kUseReadBarrier) {
167 ReadBarrier::AssertToSpaceInvariant(ref);
168 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800169 if (kVerifyFlags & kVerifyReads) {
170 VerifyObject(ref);
171 }
172 return ref;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700173 }
174
Jeff Hao16743632013-05-08 10:59:04 -0700175 // Get view of vregs as range of consecutive arguments starting at i.
176 uint32_t* GetVRegArgs(size_t i) {
177 return &vregs_[i];
178 }
179
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700180 void SetVReg(size_t i, int32_t val) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800181 DCHECK_LT(i, NumberOfVRegs());
182 uint32_t* vreg = &vregs_[i];
183 *reinterpret_cast<int32_t*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700184 // This is needed for moving collectors since these can update the vreg references if they
185 // happen to agree with references in the reference array.
186 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800187 References()[i].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700188 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700189 }
190
191 void SetVRegFloat(size_t i, float val) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800192 DCHECK_LT(i, NumberOfVRegs());
193 uint32_t* vreg = &vregs_[i];
194 *reinterpret_cast<float*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700195 // This is needed for moving collectors since these can update the vreg references if they
196 // happen to agree with references in the reference array.
197 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800198 References()[i].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700199 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700200 }
201
202 void SetVRegLong(size_t i, int64_t val) {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200203 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800204 uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700205 // Alignment attribute required for GCC 4.8
206 typedef int64_t unaligned_int64 __attribute__ ((aligned (4)));
207 *reinterpret_cast<unaligned_int64*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700208 // This is needed for moving collectors since these can update the vreg references if they
209 // happen to agree with references in the reference array.
210 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800211 References()[i].Clear();
212 References()[i + 1].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700213 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700214 }
215
216 void SetVRegDouble(size_t i, double val) {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200217 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800218 uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700219 // Alignment attribute required for GCC 4.8
220 typedef double unaligned_double __attribute__ ((aligned (4)));
221 *reinterpret_cast<unaligned_double*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700222 // This is needed for moving collectors since these can update the vreg references if they
223 // happen to agree with references in the reference array.
224 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800225 References()[i].Clear();
226 References()[i + 1].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700227 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700228 }
229
Mathieu Chartier4e305412014-02-19 10:54:44 -0800230 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700231 void SetVRegReference(size_t i, mirror::Object* val) SHARED_REQUIRES(Locks::mutator_lock_) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800232 DCHECK_LT(i, NumberOfVRegs());
Mathieu Chartier4e305412014-02-19 10:54:44 -0800233 if (kVerifyFlags & kVerifyWrites) {
234 VerifyObject(val);
235 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800236 if (kUseReadBarrier) {
237 ReadBarrier::AssertToSpaceInvariant(val);
238 }
TDYa127ce4cc0d2012-11-18 16:59:53 -0800239 uint32_t* vreg = &vregs_[i];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800240 reinterpret_cast<StackReference<mirror::Object>*>(vreg)->Assign(val);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800241 if (HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800242 References()[i].Assign(val);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800243 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700244 }
245
Mathieu Chartier90443472015-07-16 20:32:27 -0700246 ArtMethod* GetMethod() const SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800247 DCHECK(method_ != nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700248 return method_;
Elliott Hughes68e76522011-10-05 13:22:16 -0700249 }
250
Mathieu Chartier90443472015-07-16 20:32:27 -0700251 mirror::Object* GetThisObject() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800252
Mathieu Chartier90443472015-07-16 20:32:27 -0700253 mirror::Object* GetThisObject(uint16_t num_ins) const SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Haoe701f482013-05-24 11:50:49 -0700254
Ian Rogersef7d42f2014-01-06 12:55:46 -0800255 bool Contains(StackReference<mirror::Object>* shadow_frame_entry_obj) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800256 if (HasReferenceArray()) {
257 return ((&References()[0] <= shadow_frame_entry_obj) &&
258 (shadow_frame_entry_obj <= (&References()[NumberOfVRegs() - 1])));
259 } else {
260 uint32_t* shadow_frame_entry = reinterpret_cast<uint32_t*>(shadow_frame_entry_obj);
261 return ((&vregs_[0] <= shadow_frame_entry) &&
262 (shadow_frame_entry <= (&vregs_[NumberOfVRegs() - 1])));
Ian Rogers0399dde2012-06-06 17:09:28 -0700263 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700264 }
265
Ian Rogers0399dde2012-06-06 17:09:28 -0700266 static size_t LinkOffset() {
267 return OFFSETOF_MEMBER(ShadowFrame, link_);
268 }
269
Ian Rogers0399dde2012-06-06 17:09:28 -0700270 static size_t MethodOffset() {
271 return OFFSETOF_MEMBER(ShadowFrame, method_);
272 }
273
Ian Rogers0399dde2012-06-06 17:09:28 -0700274 static size_t DexPCOffset() {
275 return OFFSETOF_MEMBER(ShadowFrame, dex_pc_);
276 }
277
Ian Rogers5438ad82012-10-15 17:22:44 -0700278 static size_t NumberOfVRegsOffset() {
279 return OFFSETOF_MEMBER(ShadowFrame, number_of_vregs_);
280 }
281
TDYa127ce4cc0d2012-11-18 16:59:53 -0800282 static size_t VRegsOffset() {
283 return OFFSETOF_MEMBER(ShadowFrame, vregs_);
Ian Rogers5438ad82012-10-15 17:22:44 -0700284 }
285
Elliott Hughes68e76522011-10-05 13:22:16 -0700286 private:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700287 ShadowFrame(uint32_t num_vregs, ShadowFrame* link, ArtMethod* method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800288 uint32_t dex_pc, bool has_reference_array)
TDYa127ce4cc0d2012-11-18 16:59:53 -0800289 : number_of_vregs_(num_vregs), link_(link), method_(method), dex_pc_(dex_pc) {
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700290 // TODO(iam): Remove this parameter, it's an an artifact of portable removal
291 DCHECK(has_reference_array);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800292 if (has_reference_array) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800293 memset(vregs_, 0, num_vregs * (sizeof(uint32_t) + sizeof(StackReference<mirror::Object>)));
Mathieu Chartier67022432012-11-29 18:04:50 -0800294 } else {
Jeff Haoe701f482013-05-24 11:50:49 -0700295 memset(vregs_, 0, num_vregs * sizeof(uint32_t));
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700296 }
297 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700298
Ian Rogersef7d42f2014-01-06 12:55:46 -0800299 const StackReference<mirror::Object>* References() const {
Mathieu Chartier67022432012-11-29 18:04:50 -0800300 DCHECK(HasReferenceArray());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800301 const uint32_t* vreg_end = &vregs_[NumberOfVRegs()];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800302 return reinterpret_cast<const StackReference<mirror::Object>*>(vreg_end);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800303 }
304
Ian Rogersef7d42f2014-01-06 12:55:46 -0800305 StackReference<mirror::Object>* References() {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700306 return const_cast<StackReference<mirror::Object>*>(
307 const_cast<const ShadowFrame*>(this)->References());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800308 }
309
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700310 const uint32_t number_of_vregs_;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700311 // Link to previous shadow frame or null.
Ian Rogers0399dde2012-06-06 17:09:28 -0700312 ShadowFrame* link_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700313 ArtMethod* method_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700314 uint32_t dex_pc_;
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700315
316 // This is a two-part array:
317 // - [0..number_of_vregs) holds the raw virtual registers, and each element here is always 4
318 // bytes.
319 // - [number_of_vregs..number_of_vregs*2) holds only reference registers. Each element here is
320 // ptr-sized.
321 // In other words when a primitive is stored in vX, the second (reference) part of the array will
322 // be null. When a reference is stored in vX, the second (reference) part of the array will be a
323 // copy of vX.
TDYa127ce4cc0d2012-11-18 16:59:53 -0800324 uint32_t vregs_[0];
Elliott Hughes68e76522011-10-05 13:22:16 -0700325
Ian Rogers0399dde2012-06-06 17:09:28 -0700326 DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame);
Elliott Hughes68e76522011-10-05 13:22:16 -0700327};
328
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800329class JavaFrameRootInfo : public RootInfo {
330 public:
331 JavaFrameRootInfo(uint32_t thread_id, const StackVisitor* stack_visitor, size_t vreg)
332 : RootInfo(kRootJavaFrame, thread_id), stack_visitor_(stack_visitor), vreg_(vreg) {
333 }
334 virtual void Describe(std::ostream& os) const OVERRIDE
Mathieu Chartier90443472015-07-16 20:32:27 -0700335 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800336
337 private:
338 const StackVisitor* const stack_visitor_;
339 const size_t vreg_;
340};
341
Ian Rogers0399dde2012-06-06 17:09:28 -0700342// The managed stack is used to record fragments of managed code stacks. Managed code stacks
343// may either be shadow frames or lists of frames using fixed frame sizes. Transition records are
344// necessary for transitions between code using different frame layouts and transitions into native
345// code.
Ian Rogersdf1ce912012-11-27 17:07:11 -0800346class PACKED(4) ManagedStack {
Ian Rogers0399dde2012-06-06 17:09:28 -0700347 public:
Ian Rogersca190662012-06-26 15:45:57 -0700348 ManagedStack()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700349 : top_quick_frame_(nullptr), link_(nullptr), top_shadow_frame_(nullptr) {}
Ian Rogers81d425b2012-09-27 16:03:43 -0700350
351 void PushManagedStackFragment(ManagedStack* fragment) {
352 // Copy this top fragment into given fragment.
353 memcpy(fragment, this, sizeof(ManagedStack));
354 // Clear this fragment, which has become the top.
355 memset(this, 0, sizeof(ManagedStack));
356 // Link our top fragment onto the given fragment.
357 link_ = fragment;
358 }
359
360 void PopManagedStackFragment(const ManagedStack& fragment) {
361 DCHECK(&fragment == link_);
362 // Copy this given fragment back to the top.
363 memcpy(this, &fragment, sizeof(ManagedStack));
364 }
Ian Rogers0399dde2012-06-06 17:09:28 -0700365
366 ManagedStack* GetLink() const {
367 return link_;
368 }
369
Mathieu Chartiere401d142015-04-22 13:56:20 -0700370 ArtMethod** GetTopQuickFrame() const {
Ian Rogers0399dde2012-06-06 17:09:28 -0700371 return top_quick_frame_;
372 }
373
Mathieu Chartiere401d142015-04-22 13:56:20 -0700374 void SetTopQuickFrame(ArtMethod** top) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700375 DCHECK(top_shadow_frame_ == nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700376 top_quick_frame_ = top;
377 }
378
Ian Rogers0399dde2012-06-06 17:09:28 -0700379 static size_t TopQuickFrameOffset() {
380 return OFFSETOF_MEMBER(ManagedStack, top_quick_frame_);
381 }
382
Ian Rogers0399dde2012-06-06 17:09:28 -0700383 ShadowFrame* PushShadowFrame(ShadowFrame* new_top_frame) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700384 DCHECK(top_quick_frame_ == nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700385 ShadowFrame* old_frame = top_shadow_frame_;
386 top_shadow_frame_ = new_top_frame;
387 new_top_frame->SetLink(old_frame);
388 return old_frame;
389 }
390
391 ShadowFrame* PopShadowFrame() {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700392 DCHECK(top_quick_frame_ == nullptr);
393 CHECK(top_shadow_frame_ != nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700394 ShadowFrame* frame = top_shadow_frame_;
395 top_shadow_frame_ = frame->GetLink();
396 return frame;
397 }
398
399 ShadowFrame* GetTopShadowFrame() const {
400 return top_shadow_frame_;
401 }
402
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800403 void SetTopShadowFrame(ShadowFrame* top) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700404 DCHECK(top_quick_frame_ == nullptr);
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800405 top_shadow_frame_ = top;
406 }
407
Ian Rogers0399dde2012-06-06 17:09:28 -0700408 static size_t TopShadowFrameOffset() {
409 return OFFSETOF_MEMBER(ManagedStack, top_shadow_frame_);
410 }
411
Mathieu Chartier90443472015-07-16 20:32:27 -0700412 size_t NumJniShadowFrameReferences() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700413
Ian Rogersef7d42f2014-01-06 12:55:46 -0800414 bool ShadowFramesContain(StackReference<mirror::Object>* shadow_frame_entry) const;
Ian Rogers0399dde2012-06-06 17:09:28 -0700415
416 private:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700417 ArtMethod** top_quick_frame_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700418 ManagedStack* link_;
419 ShadowFrame* top_shadow_frame_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700420};
421
422class StackVisitor {
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100423 public:
424 // This enum defines a flag to control whether inlined frames are included
425 // when walking the stack.
426 enum class StackWalkKind {
427 kIncludeInlinedFrames,
428 kSkipInlinedFrames,
429 };
430
Ian Rogers0399dde2012-06-06 17:09:28 -0700431 protected:
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100432 StackVisitor(Thread* thread, Context* context, StackWalkKind walk_kind)
Mathieu Chartier90443472015-07-16 20:32:27 -0700433 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700434
435 public:
436 virtual ~StackVisitor() {}
437
438 // Return 'true' if we should continue to visit more frames, 'false' to stop.
Mathieu Chartier90443472015-07-16 20:32:27 -0700439 virtual bool VisitFrame() SHARED_REQUIRES(Locks::mutator_lock_) = 0;
Ian Rogers0399dde2012-06-06 17:09:28 -0700440
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700441 void WalkStack(bool include_transitions = false)
Mathieu Chartier90443472015-07-16 20:32:27 -0700442 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700443
Sebastien Hertz26f72862015-09-15 09:52:07 +0200444 Thread* GetThread() const {
445 return thread_;
446 }
447
Mathieu Chartier90443472015-07-16 20:32:27 -0700448 ArtMethod* GetMethod() const SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi92d1a662014-05-15 21:43:59 -0700449
Ian Rogers0399dde2012-06-06 17:09:28 -0700450 bool IsShadowFrame() const {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800451 return cur_shadow_frame_ != nullptr;
Ian Rogers0399dde2012-06-06 17:09:28 -0700452 }
453
Mathieu Chartier90443472015-07-16 20:32:27 -0700454 uint32_t GetDexPc(bool abort_on_failure = true) const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0c7abda2012-09-19 13:33:42 -0700455
Mathieu Chartier90443472015-07-16 20:32:27 -0700456 mirror::Object* GetThisObject() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800457
Mathieu Chartier90443472015-07-16 20:32:27 -0700458 size_t GetNativePcOffset() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0c7abda2012-09-19 13:33:42 -0700459
Ian Rogersef7d42f2014-01-06 12:55:46 -0800460 uintptr_t* CalleeSaveAddress(int num, size_t frame_size) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700461 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700462 // Callee saves are held at the top of the frame
Ian Rogersef7d42f2014-01-06 12:55:46 -0800463 DCHECK(GetMethod() != nullptr);
Ian Rogers13735952014-10-08 12:43:28 -0700464 uint8_t* save_addr =
465 reinterpret_cast<uint8_t*>(cur_quick_frame_) + frame_size - ((num + 1) * sizeof(void*));
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800466#if defined(__i386__) || defined(__x86_64__)
Ian Rogers13735952014-10-08 12:43:28 -0700467 save_addr -= sizeof(void*); // account for return address
Ian Rogers0399dde2012-06-06 17:09:28 -0700468#endif
Mathieu Chartier67022432012-11-29 18:04:50 -0800469 return reinterpret_cast<uintptr_t*>(save_addr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700470 }
471
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700472 // Returns the height of the stack in the managed stack frames, including transitions.
Mathieu Chartier90443472015-07-16 20:32:27 -0700473 size_t GetFrameHeight() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800474 return GetNumFrames() - cur_depth_ - 1;
Ian Rogers0399dde2012-06-06 17:09:28 -0700475 }
476
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700477 // Returns a frame ID for JDWP use, starting from 1.
Mathieu Chartier90443472015-07-16 20:32:27 -0700478 size_t GetFrameId() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700479 return GetFrameHeight() + 1;
480 }
481
Mathieu Chartier90443472015-07-16 20:32:27 -0700482 size_t GetNumFrames() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700483 if (num_frames_ == 0) {
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100484 num_frames_ = ComputeNumFrames(thread_, walk_kind_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700485 }
486 return num_frames_;
487 }
488
Mathieu Chartier90443472015-07-16 20:32:27 -0700489 size_t GetFrameDepth() SHARED_REQUIRES(Locks::mutator_lock_) {
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -0700490 return cur_depth_;
491 }
492
Ian Rogers5cf98192014-05-29 21:31:50 -0700493 // Get the method and dex pc immediately after the one that's currently being visited.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700494 bool GetNextMethodAndDexPc(ArtMethod** next_method, uint32_t* next_dex_pc)
Mathieu Chartier90443472015-07-16 20:32:27 -0700495 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers5cf98192014-05-29 21:31:50 -0700496
Mathieu Chartiere401d142015-04-22 13:56:20 -0700497 bool IsReferenceVReg(ArtMethod* m, uint16_t vreg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700498 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier50030ef2015-05-08 14:19:26 -0700499
Mathieu Chartiere401d142015-04-22 13:56:20 -0700500 bool GetVReg(ArtMethod* m, uint16_t vreg, VRegKind kind, uint32_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700501 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700502
Mathieu Chartiere401d142015-04-22 13:56:20 -0700503 bool GetVRegPair(ArtMethod* m, uint16_t vreg, VRegKind kind_lo, VRegKind kind_hi,
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200504 uint64_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700505 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200506
Mathieu Chartiere401d142015-04-22 13:56:20 -0700507 bool SetVReg(ArtMethod* m, uint16_t vreg, uint32_t new_value, VRegKind kind)
Mathieu Chartier90443472015-07-16 20:32:27 -0700508 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700509
Mathieu Chartiere401d142015-04-22 13:56:20 -0700510 bool SetVRegPair(ArtMethod* m, uint16_t vreg, uint64_t new_value,
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200511 VRegKind kind_lo, VRegKind kind_hi)
Mathieu Chartier90443472015-07-16 20:32:27 -0700512 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200513
Mathieu Chartier815873e2014-02-13 18:02:13 -0800514 uintptr_t* GetGPRAddress(uint32_t reg) const;
Ian Rogers0399dde2012-06-06 17:09:28 -0700515
Mathieu Chartier423d2a32013-09-12 17:33:56 -0700516 // This is a fast-path for getting/setting values in a quick frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700517 uint32_t* GetVRegAddrFromQuickCode(ArtMethod** cur_quick_frame,
Nicolas Geoffray15b9d522015-03-12 15:05:13 +0000518 const DexFile::CodeItem* code_item,
519 uint32_t core_spills, uint32_t fp_spills, size_t frame_size,
520 uint16_t vreg) const {
521 int offset = GetVRegOffsetFromQuickCode(
522 code_item, core_spills, fp_spills, frame_size, vreg, kRuntimeISA);
Ian Rogers0ec569a2012-07-01 16:43:46 -0700523 DCHECK_EQ(cur_quick_frame, GetCurrentQuickFrame());
Ian Rogers13735952014-10-08 12:43:28 -0700524 uint8_t* vreg_addr = reinterpret_cast<uint8_t*>(cur_quick_frame) + offset;
Mathieu Chartier423d2a32013-09-12 17:33:56 -0700525 return reinterpret_cast<uint32_t*>(vreg_addr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700526 }
527
Mathieu Chartier90443472015-07-16 20:32:27 -0700528 uintptr_t GetReturnPc() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700529
Mathieu Chartier90443472015-07-16 20:32:27 -0700530 void SetReturnPc(uintptr_t new_ret_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700531
532 /*
533 * Return sp-relative offset for a Dalvik virtual register, compiler
534 * spill or Method* in bytes using Method*.
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700535 * Note that (reg == -1) denotes an invalid Dalvik register. For the
536 * positive values, the Dalvik registers come first, followed by the
537 * Method*, followed by other special temporaries if any, followed by
538 * regular compiler temporary. As of now we only have the Method* as
539 * as a special compiler temporary.
540 * A compiler temporary can be thought of as a virtual register that
541 * does not exist in the dex but holds intermediate values to help
542 * optimizations and code generation. A special compiler temporary is
543 * one whose location in frame is well known while non-special ones
544 * do not have a requirement on location in frame as long as code
545 * generator itself knows how to access them.
Ian Rogers0399dde2012-06-06 17:09:28 -0700546 *
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700547 * +-------------------------------+
548 * | IN[ins-1] | {Note: resides in caller's frame}
549 * | . |
550 * | IN[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700551 * | caller's ArtMethod | ... ArtMethod*
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700552 * +===============================+ {Note: start of callee's frame}
553 * | core callee-save spill | {variable sized}
554 * +-------------------------------+
555 * | fp callee-save spill |
556 * +-------------------------------+
557 * | filler word | {For compatibility, if V[locals-1] used as wide
558 * +-------------------------------+
559 * | V[locals-1] |
560 * | V[locals-2] |
561 * | . |
562 * | . | ... (reg == 2)
563 * | V[1] | ... (reg == 1)
564 * | V[0] | ... (reg == 0) <---- "locals_start"
565 * +-------------------------------+
566 * | stack alignment padding | {0 to (kStackAlignWords-1) of padding}
567 * +-------------------------------+
568 * | Compiler temp region | ... (reg >= max_num_special_temps)
569 * | . |
570 * | . |
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700571 * | V[max_num_special_temps + 1] |
572 * | V[max_num_special_temps + 0] |
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700573 * +-------------------------------+
574 * | OUT[outs-1] |
575 * | OUT[outs-2] |
576 * | . |
577 * | OUT[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700578 * | ArtMethod* | ... (reg == num_total_code_regs == special_temp_value) <<== sp, 16-byte aligned
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700579 * +===============================+
Ian Rogers0399dde2012-06-06 17:09:28 -0700580 */
Nicolas Geoffray15b9d522015-03-12 15:05:13 +0000581 static int GetVRegOffsetFromQuickCode(const DexFile::CodeItem* code_item,
582 uint32_t core_spills, uint32_t fp_spills,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700583 size_t frame_size, int reg, InstructionSet isa);
Ian Rogers0399dde2012-06-06 17:09:28 -0700584
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000585 static int GetOutVROffset(uint16_t out_num, InstructionSet isa) {
buzbee82818642014-06-04 15:35:41 -0700586 // According to stack model, the first out is above the Method referernce.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700587 return InstructionSetPointerSize(isa) + out_num * sizeof(uint32_t);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800588 }
589
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100590 bool IsInInlinedFrame() const {
Nicolas Geoffray57f61612015-05-15 13:20:41 +0100591 return current_inlining_depth_ != 0;
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100592 }
593
Ian Rogers0399dde2012-06-06 17:09:28 -0700594 uintptr_t GetCurrentQuickFramePc() const {
595 return cur_quick_frame_pc_;
596 }
597
Mathieu Chartiere401d142015-04-22 13:56:20 -0700598 ArtMethod** GetCurrentQuickFrame() const {
Ian Rogers0399dde2012-06-06 17:09:28 -0700599 return cur_quick_frame_;
600 }
601
602 ShadowFrame* GetCurrentShadowFrame() const {
603 return cur_shadow_frame_;
604 }
605
Mathieu Chartiere401d142015-04-22 13:56:20 -0700606 HandleScope* GetCurrentHandleScope(size_t pointer_size) const {
607 ArtMethod** sp = GetCurrentQuickFrame();
608 // Skip ArtMethod*; handle scope comes next;
609 return reinterpret_cast<HandleScope*>(reinterpret_cast<uintptr_t>(sp) + pointer_size);
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700610 }
611
Mathieu Chartier90443472015-07-16 20:32:27 -0700612 std::string DescribeLocation() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers40e3bac2012-11-20 00:09:14 -0800613
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100614 static size_t ComputeNumFrames(Thread* thread, StackWalkKind walk_kind)
Mathieu Chartier90443472015-07-16 20:32:27 -0700615 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers306057f2012-11-26 12:45:53 -0800616
Mathieu Chartier90443472015-07-16 20:32:27 -0700617 static void DescribeStack(Thread* thread) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers306057f2012-11-26 12:45:53 -0800618
Ian Rogers0399dde2012-06-06 17:09:28 -0700619 private:
Ian Rogers5cf98192014-05-29 21:31:50 -0700620 // Private constructor known in the case that num_frames_ has already been computed.
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100621 StackVisitor(Thread* thread, Context* context, StackWalkKind walk_kind, size_t num_frames)
Mathieu Chartier90443472015-07-16 20:32:27 -0700622 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers5cf98192014-05-29 21:31:50 -0700623
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +0100624 bool IsAccessibleRegister(uint32_t reg, bool is_float) const {
625 return is_float ? IsAccessibleFPR(reg) : IsAccessibleGPR(reg);
626 }
627 uintptr_t GetRegister(uint32_t reg, bool is_float) const {
628 DCHECK(IsAccessibleRegister(reg, is_float));
629 return is_float ? GetFPR(reg) : GetGPR(reg);
630 }
631 void SetRegister(uint32_t reg, uintptr_t value, bool is_float) {
632 DCHECK(IsAccessibleRegister(reg, is_float));
633 if (is_float) {
634 SetFPR(reg, value);
635 } else {
636 SetGPR(reg, value);
637 }
638 }
639
640 bool IsAccessibleGPR(uint32_t reg) const;
641 uintptr_t GetGPR(uint32_t reg) const;
642 void SetGPR(uint32_t reg, uintptr_t value);
643
644 bool IsAccessibleFPR(uint32_t reg) const;
645 uintptr_t GetFPR(uint32_t reg) const;
646 void SetFPR(uint32_t reg, uintptr_t value);
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200647
Mathieu Chartiere401d142015-04-22 13:56:20 -0700648 bool GetVRegFromQuickCode(ArtMethod* m, uint16_t vreg, VRegKind kind,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100649 uint32_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700650 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700651 bool GetVRegFromOptimizedCode(ArtMethod* m, uint16_t vreg, VRegKind kind,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100652 uint32_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700653 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100654 bool GetRegisterIfAccessible(uint32_t reg, VRegKind kind, uint32_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700655 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100656
Mathieu Chartiere401d142015-04-22 13:56:20 -0700657 bool GetVRegPairFromQuickCode(ArtMethod* m, uint16_t vreg, VRegKind kind_lo,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100658 VRegKind kind_hi, uint64_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700659 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700660 bool GetVRegPairFromOptimizedCode(ArtMethod* m, uint16_t vreg,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100661 VRegKind kind_lo, VRegKind kind_hi,
662 uint64_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700663 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100664 bool GetRegisterPairIfAccessible(uint32_t reg_lo, uint32_t reg_hi, VRegKind kind_lo,
665 uint64_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700666 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100667
Mathieu Chartiere401d142015-04-22 13:56:20 -0700668 bool SetVRegFromQuickCode(ArtMethod* m, uint16_t vreg, uint32_t new_value,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100669 VRegKind kind)
Mathieu Chartier90443472015-07-16 20:32:27 -0700670 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100671 bool SetRegisterIfAccessible(uint32_t reg, uint32_t new_value, VRegKind kind)
Mathieu Chartier90443472015-07-16 20:32:27 -0700672 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100673
Mathieu Chartiere401d142015-04-22 13:56:20 -0700674 bool SetVRegPairFromQuickCode(ArtMethod* m, uint16_t vreg, uint64_t new_value,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100675 VRegKind kind_lo, VRegKind kind_hi)
Mathieu Chartier90443472015-07-16 20:32:27 -0700676 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100677 bool SetRegisterPairIfAccessible(uint32_t reg_lo, uint32_t reg_hi, uint64_t new_value,
678 bool is_float)
Mathieu Chartier90443472015-07-16 20:32:27 -0700679 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100680
Mathieu Chartier90443472015-07-16 20:32:27 -0700681 void SanityCheckFrame() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700682
Mathieu Chartier90443472015-07-16 20:32:27 -0700683 InlineInfo GetCurrentInlineInfo() const SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray57f61612015-05-15 13:20:41 +0100684
Ian Rogers7a22fa62013-01-23 12:16:16 -0800685 Thread* const thread_;
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100686 const StackWalkKind walk_kind_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700687 ShadowFrame* cur_shadow_frame_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700688 ArtMethod** cur_quick_frame_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700689 uintptr_t cur_quick_frame_pc_;
690 // Lazily computed, number of frames in the stack.
691 size_t num_frames_;
692 // Depth of the frame we're currently at.
693 size_t cur_depth_;
Nicolas Geoffray57f61612015-05-15 13:20:41 +0100694 // Current inlining depth of the method we are currently at.
695 // 0 if there is no inlined frame.
696 size_t current_inlining_depth_;
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700697
Ian Rogers0399dde2012-06-06 17:09:28 -0700698 protected:
699 Context* const context_;
700};
701
Elliott Hughes68e76522011-10-05 13:22:16 -0700702} // namespace art
703
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700704#endif // ART_RUNTIME_STACK_H_