blob: 292c745090e16db43712ff2acbca1c5ae36903fb [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
Andreas Gampeb3025922015-09-01 14:45:00 -070065// Forward declaration. Just calls the destructor.
66struct ShadowFrameDeleter;
67using ShadowFrameAllocaUniquePtr = std::unique_ptr<ShadowFrame, ShadowFrameDeleter>;
68
Elliott Hughes956af0f2014-12-11 14:34:28 -080069// ShadowFrame has 2 possible layouts:
Mathieu Chartier67022432012-11-29 18:04:50 -080070// - interpreter - separate VRegs and reference arrays. References are in the reference array.
71// - JNI - just VRegs, but where every VReg holds a reference.
Ian Rogers0399dde2012-06-06 17:09:28 -070072class ShadowFrame {
Elliott Hughes68e76522011-10-05 13:22:16 -070073 public:
Ian Rogersef7d42f2014-01-06 12:55:46 -080074 // Compute size of ShadowFrame in bytes assuming it has a reference array.
Jeff Hao66135192013-05-14 11:02:41 -070075 static size_t ComputeSize(uint32_t num_vregs) {
76 return sizeof(ShadowFrame) + (sizeof(uint32_t) * num_vregs) +
Ian Rogersef7d42f2014-01-06 12:55:46 -080077 (sizeof(StackReference<mirror::Object>) * num_vregs);
Jeff Hao66135192013-05-14 11:02:41 -070078 }
79
80 // Create ShadowFrame in heap for deoptimization.
Christopher Ferris241a9582015-04-27 15:19:41 -070081 static ShadowFrame* CreateDeoptimizedFrame(uint32_t num_vregs, ShadowFrame* link,
Mathieu Chartiere401d142015-04-22 13:56:20 -070082 ArtMethod* method, uint32_t dex_pc) {
Jeff Hao66135192013-05-14 11:02:41 -070083 uint8_t* memory = new uint8_t[ComputeSize(num_vregs)];
Andreas Gampeb3025922015-09-01 14:45:00 -070084 return CreateShadowFrameImpl(num_vregs, link, method, dex_pc, memory);
Jeff Hao66135192013-05-14 11:02:41 -070085 }
86
Christopher Ferris241a9582015-04-27 15:19:41 -070087 // Delete a ShadowFrame allocated on the heap for deoptimization.
88 static void DeleteDeoptimizedFrame(ShadowFrame* sf) {
Andreas Gampeb3025922015-09-01 14:45:00 -070089 sf->~ShadowFrame(); // Explicitly destruct.
Christopher Ferris241a9582015-04-27 15:19:41 -070090 uint8_t* memory = reinterpret_cast<uint8_t*>(sf);
91 delete[] memory;
92 }
93
Andreas Gampeb3025922015-09-01 14:45:00 -070094 // Create a shadow frame in a fresh alloca. This needs to be in the context of the caller.
95 // Inlining doesn't work, the compiler will still undo the alloca. So this needs to be a macro.
96#define CREATE_SHADOW_FRAME(num_vregs, link, method, dex_pc) ({ \
97 size_t frame_size = ShadowFrame::ComputeSize(num_vregs); \
98 void* alloca_mem = alloca(frame_size); \
99 ShadowFrameAllocaUniquePtr( \
100 ShadowFrame::CreateShadowFrameImpl((num_vregs), (link), (method), (dex_pc), \
101 (alloca_mem))); \
102 })
103
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700104 ~ShadowFrame() {}
105
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700106 // TODO(iam): Clean references array up since they're always there,
107 // we don't need to do conditionals.
TDYa127ce4cc0d2012-11-18 16:59:53 -0800108 bool HasReferenceArray() const {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700109 return true;
Ian Rogers0399dde2012-06-06 17:09:28 -0700110 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700111
TDYa127ce4cc0d2012-11-18 16:59:53 -0800112 uint32_t NumberOfVRegs() const {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700113 return number_of_vregs_;
Ian Rogers5438ad82012-10-15 17:22:44 -0700114 }
115
Ian Rogers0399dde2012-06-06 17:09:28 -0700116 uint32_t GetDexPC() const {
117 return dex_pc_;
118 }
119
120 void SetDexPC(uint32_t dex_pc) {
121 dex_pc_ = dex_pc;
122 }
123
Ian Rogers0399dde2012-06-06 17:09:28 -0700124 ShadowFrame* GetLink() const {
125 return link_;
126 }
127
128 void SetLink(ShadowFrame* frame) {
129 DCHECK_NE(this, frame);
130 link_ = frame;
131 }
132
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700133 int32_t GetVReg(size_t i) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800134 DCHECK_LT(i, NumberOfVRegs());
135 const uint32_t* vreg = &vregs_[i];
136 return *reinterpret_cast<const int32_t*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700137 }
138
139 float GetVRegFloat(size_t i) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800140 DCHECK_LT(i, NumberOfVRegs());
141 // NOTE: Strict-aliasing?
142 const uint32_t* vreg = &vregs_[i];
143 return *reinterpret_cast<const float*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700144 }
145
146 int64_t GetVRegLong(size_t i) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200147 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800148 const uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700149 // Alignment attribute required for GCC 4.8
150 typedef const int64_t unaligned_int64 __attribute__ ((aligned (4)));
151 return *reinterpret_cast<unaligned_int64*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700152 }
153
154 double GetVRegDouble(size_t i) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200155 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800156 const uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700157 // Alignment attribute required for GCC 4.8
158 typedef const double unaligned_double __attribute__ ((aligned (4)));
159 return *reinterpret_cast<unaligned_double*>(vreg);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800160 }
161
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700162 // Look up the reference given its virtual register number.
163 // If this returns non-null then this does not mean the vreg is currently a reference
164 // 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 -0800165 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700166 mirror::Object* GetVRegReference(size_t i) const SHARED_REQUIRES(Locks::mutator_lock_) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800167 DCHECK_LT(i, NumberOfVRegs());
Mathieu Chartier4e305412014-02-19 10:54:44 -0800168 mirror::Object* ref;
TDYa127ce4cc0d2012-11-18 16:59:53 -0800169 if (HasReferenceArray()) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800170 ref = References()[i].AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800171 } else {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800172 const uint32_t* vreg_ptr = &vregs_[i];
Mathieu Chartier4e305412014-02-19 10:54:44 -0800173 ref = reinterpret_cast<const StackReference<mirror::Object>*>(vreg_ptr)->AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800174 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800175 if (kUseReadBarrier) {
176 ReadBarrier::AssertToSpaceInvariant(ref);
177 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800178 if (kVerifyFlags & kVerifyReads) {
179 VerifyObject(ref);
180 }
181 return ref;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700182 }
183
Jeff Hao16743632013-05-08 10:59:04 -0700184 // Get view of vregs as range of consecutive arguments starting at i.
185 uint32_t* GetVRegArgs(size_t i) {
186 return &vregs_[i];
187 }
188
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700189 void SetVReg(size_t i, int32_t val) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800190 DCHECK_LT(i, NumberOfVRegs());
191 uint32_t* vreg = &vregs_[i];
192 *reinterpret_cast<int32_t*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700193 // This is needed for moving collectors since these can update the vreg references if they
194 // happen to agree with references in the reference array.
195 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800196 References()[i].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700197 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700198 }
199
200 void SetVRegFloat(size_t i, float val) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800201 DCHECK_LT(i, NumberOfVRegs());
202 uint32_t* vreg = &vregs_[i];
203 *reinterpret_cast<float*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700204 // This is needed for moving collectors since these can update the vreg references if they
205 // happen to agree with references in the reference array.
206 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800207 References()[i].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700208 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700209 }
210
211 void SetVRegLong(size_t i, int64_t val) {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200212 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800213 uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700214 // Alignment attribute required for GCC 4.8
215 typedef int64_t unaligned_int64 __attribute__ ((aligned (4)));
216 *reinterpret_cast<unaligned_int64*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700217 // This is needed for moving collectors since these can update the vreg references if they
218 // happen to agree with references in the reference array.
219 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800220 References()[i].Clear();
221 References()[i + 1].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700222 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700223 }
224
225 void SetVRegDouble(size_t i, double val) {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200226 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800227 uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700228 // Alignment attribute required for GCC 4.8
229 typedef double unaligned_double __attribute__ ((aligned (4)));
230 *reinterpret_cast<unaligned_double*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700231 // This is needed for moving collectors since these can update the vreg references if they
232 // happen to agree with references in the reference array.
233 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800234 References()[i].Clear();
235 References()[i + 1].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700236 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700237 }
238
Mathieu Chartier4e305412014-02-19 10:54:44 -0800239 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700240 void SetVRegReference(size_t i, mirror::Object* val) SHARED_REQUIRES(Locks::mutator_lock_) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800241 DCHECK_LT(i, NumberOfVRegs());
Mathieu Chartier4e305412014-02-19 10:54:44 -0800242 if (kVerifyFlags & kVerifyWrites) {
243 VerifyObject(val);
244 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800245 if (kUseReadBarrier) {
246 ReadBarrier::AssertToSpaceInvariant(val);
247 }
TDYa127ce4cc0d2012-11-18 16:59:53 -0800248 uint32_t* vreg = &vregs_[i];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800249 reinterpret_cast<StackReference<mirror::Object>*>(vreg)->Assign(val);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800250 if (HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800251 References()[i].Assign(val);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800252 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700253 }
254
Mathieu Chartier90443472015-07-16 20:32:27 -0700255 ArtMethod* GetMethod() const SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800256 DCHECK(method_ != nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700257 return method_;
Elliott Hughes68e76522011-10-05 13:22:16 -0700258 }
259
Mathieu Chartier90443472015-07-16 20:32:27 -0700260 mirror::Object* GetThisObject() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800261
Mathieu Chartier90443472015-07-16 20:32:27 -0700262 mirror::Object* GetThisObject(uint16_t num_ins) const SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Haoe701f482013-05-24 11:50:49 -0700263
Ian Rogersef7d42f2014-01-06 12:55:46 -0800264 bool Contains(StackReference<mirror::Object>* shadow_frame_entry_obj) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800265 if (HasReferenceArray()) {
266 return ((&References()[0] <= shadow_frame_entry_obj) &&
267 (shadow_frame_entry_obj <= (&References()[NumberOfVRegs() - 1])));
268 } else {
269 uint32_t* shadow_frame_entry = reinterpret_cast<uint32_t*>(shadow_frame_entry_obj);
270 return ((&vregs_[0] <= shadow_frame_entry) &&
271 (shadow_frame_entry <= (&vregs_[NumberOfVRegs() - 1])));
Ian Rogers0399dde2012-06-06 17:09:28 -0700272 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700273 }
274
Ian Rogers0399dde2012-06-06 17:09:28 -0700275 static size_t LinkOffset() {
276 return OFFSETOF_MEMBER(ShadowFrame, link_);
277 }
278
Ian Rogers0399dde2012-06-06 17:09:28 -0700279 static size_t MethodOffset() {
280 return OFFSETOF_MEMBER(ShadowFrame, method_);
281 }
282
Ian Rogers0399dde2012-06-06 17:09:28 -0700283 static size_t DexPCOffset() {
284 return OFFSETOF_MEMBER(ShadowFrame, dex_pc_);
285 }
286
Ian Rogers5438ad82012-10-15 17:22:44 -0700287 static size_t NumberOfVRegsOffset() {
288 return OFFSETOF_MEMBER(ShadowFrame, number_of_vregs_);
289 }
290
TDYa127ce4cc0d2012-11-18 16:59:53 -0800291 static size_t VRegsOffset() {
292 return OFFSETOF_MEMBER(ShadowFrame, vregs_);
Ian Rogers5438ad82012-10-15 17:22:44 -0700293 }
294
Andreas Gampeb3025922015-09-01 14:45:00 -0700295 // Create ShadowFrame for interpreter using provided memory.
296 static ShadowFrame* CreateShadowFrameImpl(uint32_t num_vregs,
297 ShadowFrame* link,
298 ArtMethod* method,
299 uint32_t dex_pc,
300 void* memory) {
301 return new (memory) ShadowFrame(num_vregs, link, method, dex_pc, true);
302 }
303
Elliott Hughes68e76522011-10-05 13:22:16 -0700304 private:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700305 ShadowFrame(uint32_t num_vregs, ShadowFrame* link, ArtMethod* method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306 uint32_t dex_pc, bool has_reference_array)
TDYa127ce4cc0d2012-11-18 16:59:53 -0800307 : number_of_vregs_(num_vregs), link_(link), method_(method), dex_pc_(dex_pc) {
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700308 // TODO(iam): Remove this parameter, it's an an artifact of portable removal
309 DCHECK(has_reference_array);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800310 if (has_reference_array) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800311 memset(vregs_, 0, num_vregs * (sizeof(uint32_t) + sizeof(StackReference<mirror::Object>)));
Mathieu Chartier67022432012-11-29 18:04:50 -0800312 } else {
Jeff Haoe701f482013-05-24 11:50:49 -0700313 memset(vregs_, 0, num_vregs * sizeof(uint32_t));
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700314 }
315 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700316
Ian Rogersef7d42f2014-01-06 12:55:46 -0800317 const StackReference<mirror::Object>* References() const {
Mathieu Chartier67022432012-11-29 18:04:50 -0800318 DCHECK(HasReferenceArray());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800319 const uint32_t* vreg_end = &vregs_[NumberOfVRegs()];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800320 return reinterpret_cast<const StackReference<mirror::Object>*>(vreg_end);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800321 }
322
Ian Rogersef7d42f2014-01-06 12:55:46 -0800323 StackReference<mirror::Object>* References() {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700324 return const_cast<StackReference<mirror::Object>*>(
325 const_cast<const ShadowFrame*>(this)->References());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800326 }
327
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700328 const uint32_t number_of_vregs_;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700329 // Link to previous shadow frame or null.
Ian Rogers0399dde2012-06-06 17:09:28 -0700330 ShadowFrame* link_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700331 ArtMethod* method_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700332 uint32_t dex_pc_;
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700333
334 // This is a two-part array:
335 // - [0..number_of_vregs) holds the raw virtual registers, and each element here is always 4
336 // bytes.
337 // - [number_of_vregs..number_of_vregs*2) holds only reference registers. Each element here is
338 // ptr-sized.
339 // In other words when a primitive is stored in vX, the second (reference) part of the array will
340 // be null. When a reference is stored in vX, the second (reference) part of the array will be a
341 // copy of vX.
TDYa127ce4cc0d2012-11-18 16:59:53 -0800342 uint32_t vregs_[0];
Elliott Hughes68e76522011-10-05 13:22:16 -0700343
Ian Rogers0399dde2012-06-06 17:09:28 -0700344 DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame);
Elliott Hughes68e76522011-10-05 13:22:16 -0700345};
346
Andreas Gampeb3025922015-09-01 14:45:00 -0700347struct ShadowFrameDeleter {
348 inline void operator()(ShadowFrame* frame) {
349 if (frame != nullptr) {
350 frame->~ShadowFrame();
351 }
352 }
353};
354
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800355class JavaFrameRootInfo : public RootInfo {
356 public:
357 JavaFrameRootInfo(uint32_t thread_id, const StackVisitor* stack_visitor, size_t vreg)
358 : RootInfo(kRootJavaFrame, thread_id), stack_visitor_(stack_visitor), vreg_(vreg) {
359 }
360 virtual void Describe(std::ostream& os) const OVERRIDE
Mathieu Chartier90443472015-07-16 20:32:27 -0700361 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800362
363 private:
364 const StackVisitor* const stack_visitor_;
365 const size_t vreg_;
366};
367
Ian Rogers0399dde2012-06-06 17:09:28 -0700368// The managed stack is used to record fragments of managed code stacks. Managed code stacks
369// may either be shadow frames or lists of frames using fixed frame sizes. Transition records are
370// necessary for transitions between code using different frame layouts and transitions into native
371// code.
Ian Rogersdf1ce912012-11-27 17:07:11 -0800372class PACKED(4) ManagedStack {
Ian Rogers0399dde2012-06-06 17:09:28 -0700373 public:
Ian Rogersca190662012-06-26 15:45:57 -0700374 ManagedStack()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700375 : top_quick_frame_(nullptr), link_(nullptr), top_shadow_frame_(nullptr) {}
Ian Rogers81d425b2012-09-27 16:03:43 -0700376
377 void PushManagedStackFragment(ManagedStack* fragment) {
378 // Copy this top fragment into given fragment.
379 memcpy(fragment, this, sizeof(ManagedStack));
380 // Clear this fragment, which has become the top.
381 memset(this, 0, sizeof(ManagedStack));
382 // Link our top fragment onto the given fragment.
383 link_ = fragment;
384 }
385
386 void PopManagedStackFragment(const ManagedStack& fragment) {
387 DCHECK(&fragment == link_);
388 // Copy this given fragment back to the top.
389 memcpy(this, &fragment, sizeof(ManagedStack));
390 }
Ian Rogers0399dde2012-06-06 17:09:28 -0700391
392 ManagedStack* GetLink() const {
393 return link_;
394 }
395
Mathieu Chartiere401d142015-04-22 13:56:20 -0700396 ArtMethod** GetTopQuickFrame() const {
Ian Rogers0399dde2012-06-06 17:09:28 -0700397 return top_quick_frame_;
398 }
399
Mathieu Chartiere401d142015-04-22 13:56:20 -0700400 void SetTopQuickFrame(ArtMethod** top) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700401 DCHECK(top_shadow_frame_ == nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700402 top_quick_frame_ = top;
403 }
404
Ian Rogers0399dde2012-06-06 17:09:28 -0700405 static size_t TopQuickFrameOffset() {
406 return OFFSETOF_MEMBER(ManagedStack, top_quick_frame_);
407 }
408
Ian Rogers0399dde2012-06-06 17:09:28 -0700409 ShadowFrame* PushShadowFrame(ShadowFrame* new_top_frame) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700410 DCHECK(top_quick_frame_ == nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700411 ShadowFrame* old_frame = top_shadow_frame_;
412 top_shadow_frame_ = new_top_frame;
413 new_top_frame->SetLink(old_frame);
414 return old_frame;
415 }
416
417 ShadowFrame* PopShadowFrame() {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700418 DCHECK(top_quick_frame_ == nullptr);
419 CHECK(top_shadow_frame_ != nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700420 ShadowFrame* frame = top_shadow_frame_;
421 top_shadow_frame_ = frame->GetLink();
422 return frame;
423 }
424
425 ShadowFrame* GetTopShadowFrame() const {
426 return top_shadow_frame_;
427 }
428
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800429 void SetTopShadowFrame(ShadowFrame* top) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700430 DCHECK(top_quick_frame_ == nullptr);
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800431 top_shadow_frame_ = top;
432 }
433
Ian Rogers0399dde2012-06-06 17:09:28 -0700434 static size_t TopShadowFrameOffset() {
435 return OFFSETOF_MEMBER(ManagedStack, top_shadow_frame_);
436 }
437
Mathieu Chartier90443472015-07-16 20:32:27 -0700438 size_t NumJniShadowFrameReferences() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700439
Ian Rogersef7d42f2014-01-06 12:55:46 -0800440 bool ShadowFramesContain(StackReference<mirror::Object>* shadow_frame_entry) const;
Ian Rogers0399dde2012-06-06 17:09:28 -0700441
442 private:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700443 ArtMethod** top_quick_frame_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700444 ManagedStack* link_;
445 ShadowFrame* top_shadow_frame_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700446};
447
448class StackVisitor {
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100449 public:
450 // This enum defines a flag to control whether inlined frames are included
451 // when walking the stack.
452 enum class StackWalkKind {
453 kIncludeInlinedFrames,
454 kSkipInlinedFrames,
455 };
456
Ian Rogers0399dde2012-06-06 17:09:28 -0700457 protected:
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100458 StackVisitor(Thread* thread, Context* context, StackWalkKind walk_kind)
Mathieu Chartier90443472015-07-16 20:32:27 -0700459 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700460
461 public:
462 virtual ~StackVisitor() {}
463
464 // Return 'true' if we should continue to visit more frames, 'false' to stop.
Mathieu Chartier90443472015-07-16 20:32:27 -0700465 virtual bool VisitFrame() SHARED_REQUIRES(Locks::mutator_lock_) = 0;
Ian Rogers0399dde2012-06-06 17:09:28 -0700466
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700467 void WalkStack(bool include_transitions = false)
Mathieu Chartier90443472015-07-16 20:32:27 -0700468 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700469
Sebastien Hertz26f72862015-09-15 09:52:07 +0200470 Thread* GetThread() const {
471 return thread_;
472 }
473
Mathieu Chartier90443472015-07-16 20:32:27 -0700474 ArtMethod* GetMethod() const SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi92d1a662014-05-15 21:43:59 -0700475
Ian Rogers0399dde2012-06-06 17:09:28 -0700476 bool IsShadowFrame() const {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800477 return cur_shadow_frame_ != nullptr;
Ian Rogers0399dde2012-06-06 17:09:28 -0700478 }
479
Mathieu Chartier90443472015-07-16 20:32:27 -0700480 uint32_t GetDexPc(bool abort_on_failure = true) const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0c7abda2012-09-19 13:33:42 -0700481
Mathieu Chartier90443472015-07-16 20:32:27 -0700482 mirror::Object* GetThisObject() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800483
Mathieu Chartier90443472015-07-16 20:32:27 -0700484 size_t GetNativePcOffset() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0c7abda2012-09-19 13:33:42 -0700485
Ian Rogersef7d42f2014-01-06 12:55:46 -0800486 uintptr_t* CalleeSaveAddress(int num, size_t frame_size) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700487 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700488 // Callee saves are held at the top of the frame
Ian Rogersef7d42f2014-01-06 12:55:46 -0800489 DCHECK(GetMethod() != nullptr);
Ian Rogers13735952014-10-08 12:43:28 -0700490 uint8_t* save_addr =
491 reinterpret_cast<uint8_t*>(cur_quick_frame_) + frame_size - ((num + 1) * sizeof(void*));
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800492#if defined(__i386__) || defined(__x86_64__)
Ian Rogers13735952014-10-08 12:43:28 -0700493 save_addr -= sizeof(void*); // account for return address
Ian Rogers0399dde2012-06-06 17:09:28 -0700494#endif
Mathieu Chartier67022432012-11-29 18:04:50 -0800495 return reinterpret_cast<uintptr_t*>(save_addr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700496 }
497
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700498 // Returns the height of the stack in the managed stack frames, including transitions.
Mathieu Chartier90443472015-07-16 20:32:27 -0700499 size_t GetFrameHeight() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800500 return GetNumFrames() - cur_depth_ - 1;
Ian Rogers0399dde2012-06-06 17:09:28 -0700501 }
502
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700503 // Returns a frame ID for JDWP use, starting from 1.
Mathieu Chartier90443472015-07-16 20:32:27 -0700504 size_t GetFrameId() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700505 return GetFrameHeight() + 1;
506 }
507
Mathieu Chartier90443472015-07-16 20:32:27 -0700508 size_t GetNumFrames() SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700509 if (num_frames_ == 0) {
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100510 num_frames_ = ComputeNumFrames(thread_, walk_kind_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700511 }
512 return num_frames_;
513 }
514
Mathieu Chartier90443472015-07-16 20:32:27 -0700515 size_t GetFrameDepth() SHARED_REQUIRES(Locks::mutator_lock_) {
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -0700516 return cur_depth_;
517 }
518
Ian Rogers5cf98192014-05-29 21:31:50 -0700519 // Get the method and dex pc immediately after the one that's currently being visited.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700520 bool GetNextMethodAndDexPc(ArtMethod** next_method, uint32_t* next_dex_pc)
Mathieu Chartier90443472015-07-16 20:32:27 -0700521 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers5cf98192014-05-29 21:31:50 -0700522
Mathieu Chartiere401d142015-04-22 13:56:20 -0700523 bool IsReferenceVReg(ArtMethod* m, uint16_t vreg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700524 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier50030ef2015-05-08 14:19:26 -0700525
Mathieu Chartiere401d142015-04-22 13:56:20 -0700526 bool GetVReg(ArtMethod* m, uint16_t vreg, VRegKind kind, uint32_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700527 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700528
Mathieu Chartiere401d142015-04-22 13:56:20 -0700529 bool GetVRegPair(ArtMethod* m, uint16_t vreg, VRegKind kind_lo, VRegKind kind_hi,
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200530 uint64_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700531 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200532
Mathieu Chartiere401d142015-04-22 13:56:20 -0700533 bool SetVReg(ArtMethod* m, uint16_t vreg, uint32_t new_value, VRegKind kind)
Mathieu Chartier90443472015-07-16 20:32:27 -0700534 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700535
Mingyao Yang99170c62015-07-06 11:10:37 -0700536 // Values will be set in debugger shadow frames. Debugger will make sure deoptimization
537 // is triggered to make the values effective.
538 bool SetVRegFromDebugger(ArtMethod* m, uint16_t vreg, uint32_t new_value, VRegKind kind)
539 SHARED_REQUIRES(Locks::mutator_lock_);
540
Mathieu Chartiere401d142015-04-22 13:56:20 -0700541 bool SetVRegPair(ArtMethod* m, uint16_t vreg, uint64_t new_value,
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200542 VRegKind kind_lo, VRegKind kind_hi)
Mathieu Chartier90443472015-07-16 20:32:27 -0700543 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200544
Mingyao Yang99170c62015-07-06 11:10:37 -0700545 // Values will be set in debugger shadow frames. Debugger will make sure deoptimization
546 // is triggered to make the values effective.
547 bool SetVRegPairFromDebugger(ArtMethod* m, uint16_t vreg, uint64_t new_value,
548 VRegKind kind_lo, VRegKind kind_hi)
549 SHARED_REQUIRES(Locks::mutator_lock_);
550
Mathieu Chartier815873e2014-02-13 18:02:13 -0800551 uintptr_t* GetGPRAddress(uint32_t reg) const;
Ian Rogers0399dde2012-06-06 17:09:28 -0700552
Mathieu Chartier423d2a32013-09-12 17:33:56 -0700553 // This is a fast-path for getting/setting values in a quick frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700554 uint32_t* GetVRegAddrFromQuickCode(ArtMethod** cur_quick_frame,
Nicolas Geoffray15b9d522015-03-12 15:05:13 +0000555 const DexFile::CodeItem* code_item,
556 uint32_t core_spills, uint32_t fp_spills, size_t frame_size,
557 uint16_t vreg) const {
558 int offset = GetVRegOffsetFromQuickCode(
559 code_item, core_spills, fp_spills, frame_size, vreg, kRuntimeISA);
Ian Rogers0ec569a2012-07-01 16:43:46 -0700560 DCHECK_EQ(cur_quick_frame, GetCurrentQuickFrame());
Ian Rogers13735952014-10-08 12:43:28 -0700561 uint8_t* vreg_addr = reinterpret_cast<uint8_t*>(cur_quick_frame) + offset;
Mathieu Chartier423d2a32013-09-12 17:33:56 -0700562 return reinterpret_cast<uint32_t*>(vreg_addr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700563 }
564
Mathieu Chartier90443472015-07-16 20:32:27 -0700565 uintptr_t GetReturnPc() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700566
Mathieu Chartier90443472015-07-16 20:32:27 -0700567 void SetReturnPc(uintptr_t new_ret_pc) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700568
569 /*
570 * Return sp-relative offset for a Dalvik virtual register, compiler
571 * spill or Method* in bytes using Method*.
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700572 * Note that (reg == -1) denotes an invalid Dalvik register. For the
573 * positive values, the Dalvik registers come first, followed by the
574 * Method*, followed by other special temporaries if any, followed by
575 * regular compiler temporary. As of now we only have the Method* as
576 * as a special compiler temporary.
577 * A compiler temporary can be thought of as a virtual register that
578 * does not exist in the dex but holds intermediate values to help
579 * optimizations and code generation. A special compiler temporary is
580 * one whose location in frame is well known while non-special ones
581 * do not have a requirement on location in frame as long as code
582 * generator itself knows how to access them.
Ian Rogers0399dde2012-06-06 17:09:28 -0700583 *
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700584 * +-------------------------------+
585 * | IN[ins-1] | {Note: resides in caller's frame}
586 * | . |
587 * | IN[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700588 * | caller's ArtMethod | ... ArtMethod*
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700589 * +===============================+ {Note: start of callee's frame}
590 * | core callee-save spill | {variable sized}
591 * +-------------------------------+
592 * | fp callee-save spill |
593 * +-------------------------------+
594 * | filler word | {For compatibility, if V[locals-1] used as wide
595 * +-------------------------------+
596 * | V[locals-1] |
597 * | V[locals-2] |
598 * | . |
599 * | . | ... (reg == 2)
600 * | V[1] | ... (reg == 1)
601 * | V[0] | ... (reg == 0) <---- "locals_start"
602 * +-------------------------------+
603 * | stack alignment padding | {0 to (kStackAlignWords-1) of padding}
604 * +-------------------------------+
605 * | Compiler temp region | ... (reg >= max_num_special_temps)
606 * | . |
607 * | . |
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700608 * | V[max_num_special_temps + 1] |
609 * | V[max_num_special_temps + 0] |
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700610 * +-------------------------------+
611 * | OUT[outs-1] |
612 * | OUT[outs-2] |
613 * | . |
614 * | OUT[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700615 * | ArtMethod* | ... (reg == num_total_code_regs == special_temp_value) <<== sp, 16-byte aligned
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700616 * +===============================+
Ian Rogers0399dde2012-06-06 17:09:28 -0700617 */
Nicolas Geoffray15b9d522015-03-12 15:05:13 +0000618 static int GetVRegOffsetFromQuickCode(const DexFile::CodeItem* code_item,
619 uint32_t core_spills, uint32_t fp_spills,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700620 size_t frame_size, int reg, InstructionSet isa);
Ian Rogers0399dde2012-06-06 17:09:28 -0700621
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000622 static int GetOutVROffset(uint16_t out_num, InstructionSet isa) {
buzbee82818642014-06-04 15:35:41 -0700623 // According to stack model, the first out is above the Method referernce.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700624 return InstructionSetPointerSize(isa) + out_num * sizeof(uint32_t);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800625 }
626
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100627 bool IsInInlinedFrame() const {
Nicolas Geoffray57f61612015-05-15 13:20:41 +0100628 return current_inlining_depth_ != 0;
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100629 }
630
Ian Rogers0399dde2012-06-06 17:09:28 -0700631 uintptr_t GetCurrentQuickFramePc() const {
632 return cur_quick_frame_pc_;
633 }
634
Mathieu Chartiere401d142015-04-22 13:56:20 -0700635 ArtMethod** GetCurrentQuickFrame() const {
Ian Rogers0399dde2012-06-06 17:09:28 -0700636 return cur_quick_frame_;
637 }
638
639 ShadowFrame* GetCurrentShadowFrame() const {
640 return cur_shadow_frame_;
641 }
642
Mathieu Chartiere401d142015-04-22 13:56:20 -0700643 HandleScope* GetCurrentHandleScope(size_t pointer_size) const {
644 ArtMethod** sp = GetCurrentQuickFrame();
645 // Skip ArtMethod*; handle scope comes next;
646 return reinterpret_cast<HandleScope*>(reinterpret_cast<uintptr_t>(sp) + pointer_size);
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700647 }
648
Mathieu Chartier90443472015-07-16 20:32:27 -0700649 std::string DescribeLocation() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers40e3bac2012-11-20 00:09:14 -0800650
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100651 static size_t ComputeNumFrames(Thread* thread, StackWalkKind walk_kind)
Mathieu Chartier90443472015-07-16 20:32:27 -0700652 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers306057f2012-11-26 12:45:53 -0800653
Mathieu Chartier90443472015-07-16 20:32:27 -0700654 static void DescribeStack(Thread* thread) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers306057f2012-11-26 12:45:53 -0800655
Ian Rogers0399dde2012-06-06 17:09:28 -0700656 private:
Ian Rogers5cf98192014-05-29 21:31:50 -0700657 // Private constructor known in the case that num_frames_ has already been computed.
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100658 StackVisitor(Thread* thread, Context* context, StackWalkKind walk_kind, size_t num_frames)
Mathieu Chartier90443472015-07-16 20:32:27 -0700659 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers5cf98192014-05-29 21:31:50 -0700660
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +0100661 bool IsAccessibleRegister(uint32_t reg, bool is_float) const {
662 return is_float ? IsAccessibleFPR(reg) : IsAccessibleGPR(reg);
663 }
664 uintptr_t GetRegister(uint32_t reg, bool is_float) const {
665 DCHECK(IsAccessibleRegister(reg, is_float));
666 return is_float ? GetFPR(reg) : GetGPR(reg);
667 }
668 void SetRegister(uint32_t reg, uintptr_t value, bool is_float) {
669 DCHECK(IsAccessibleRegister(reg, is_float));
670 if (is_float) {
671 SetFPR(reg, value);
672 } else {
673 SetGPR(reg, value);
674 }
675 }
676
677 bool IsAccessibleGPR(uint32_t reg) const;
678 uintptr_t GetGPR(uint32_t reg) const;
679 void SetGPR(uint32_t reg, uintptr_t value);
680
681 bool IsAccessibleFPR(uint32_t reg) const;
682 uintptr_t GetFPR(uint32_t reg) const;
683 void SetFPR(uint32_t reg, uintptr_t value);
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200684
Mingyao Yang99170c62015-07-06 11:10:37 -0700685 bool GetVRegFromDebuggerShadowFrame(uint16_t vreg, VRegKind kind, uint32_t* val) const
686 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700687 bool GetVRegFromQuickCode(ArtMethod* m, uint16_t vreg, VRegKind kind,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100688 uint32_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700689 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700690 bool GetVRegFromOptimizedCode(ArtMethod* m, uint16_t vreg, VRegKind kind,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100691 uint32_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700692 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100693 bool GetRegisterIfAccessible(uint32_t reg, VRegKind kind, uint32_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700694 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100695
Mingyao Yang99170c62015-07-06 11:10:37 -0700696 bool GetVRegPairFromDebuggerShadowFrame(uint16_t vreg, VRegKind kind_lo, VRegKind kind_hi,
697 uint64_t* val) const
698 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700699 bool GetVRegPairFromQuickCode(ArtMethod* m, uint16_t vreg, VRegKind kind_lo,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100700 VRegKind kind_hi, uint64_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700701 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700702 bool GetVRegPairFromOptimizedCode(ArtMethod* m, uint16_t vreg,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100703 VRegKind kind_lo, VRegKind kind_hi,
704 uint64_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700705 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100706 bool GetRegisterPairIfAccessible(uint32_t reg_lo, uint32_t reg_hi, VRegKind kind_lo,
707 uint64_t* val) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700708 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100709
Mathieu Chartiere401d142015-04-22 13:56:20 -0700710 bool SetVRegFromQuickCode(ArtMethod* m, uint16_t vreg, uint32_t new_value,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100711 VRegKind kind)
Mathieu Chartier90443472015-07-16 20:32:27 -0700712 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100713 bool SetRegisterIfAccessible(uint32_t reg, uint32_t new_value, VRegKind kind)
Mathieu Chartier90443472015-07-16 20:32:27 -0700714 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100715
Mathieu Chartiere401d142015-04-22 13:56:20 -0700716 bool SetVRegPairFromQuickCode(ArtMethod* m, uint16_t vreg, uint64_t new_value,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100717 VRegKind kind_lo, VRegKind kind_hi)
Mathieu Chartier90443472015-07-16 20:32:27 -0700718 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100719 bool SetRegisterPairIfAccessible(uint32_t reg_lo, uint32_t reg_hi, uint64_t new_value,
720 bool is_float)
Mathieu Chartier90443472015-07-16 20:32:27 -0700721 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100722
Mathieu Chartier90443472015-07-16 20:32:27 -0700723 void SanityCheckFrame() const SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700724
Mathieu Chartier90443472015-07-16 20:32:27 -0700725 InlineInfo GetCurrentInlineInfo() const SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray57f61612015-05-15 13:20:41 +0100726
Ian Rogers7a22fa62013-01-23 12:16:16 -0800727 Thread* const thread_;
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100728 const StackWalkKind walk_kind_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700729 ShadowFrame* cur_shadow_frame_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700730 ArtMethod** cur_quick_frame_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700731 uintptr_t cur_quick_frame_pc_;
732 // Lazily computed, number of frames in the stack.
733 size_t num_frames_;
734 // Depth of the frame we're currently at.
735 size_t cur_depth_;
Nicolas Geoffray57f61612015-05-15 13:20:41 +0100736 // Current inlining depth of the method we are currently at.
737 // 0 if there is no inlined frame.
738 size_t current_inlining_depth_;
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700739
Ian Rogers0399dde2012-06-06 17:09:28 -0700740 protected:
741 Context* const context_;
742};
743
Elliott Hughes68e76522011-10-05 13:22:16 -0700744} // namespace art
745
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700746#endif // ART_RUNTIME_STACK_H_