blob: fd86f5d2b191e900945f1653f4e7d93c63a8520e [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"
Andreas Gampe03ec9302015-08-27 17:41:47 -070024#include "base/macros.h"
25#include "base/mutex.h"
Ian Rogerse63db272014-07-15 15:36:11 -070026#include "dex_file.h"
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -080027#include "gc_root.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010028#include "quick/quick_method_frame_info.h"
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -080029#include "read_barrier.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010030#include "stack_reference.h"
Ian Rogerse63db272014-07-15 15:36:11 -070031#include "verify_object.h"
32
Elliott Hughes68e76522011-10-05 13:22:16 -070033namespace art {
34
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035namespace mirror {
Brian Carlstromea46f952013-07-30 01:26:50 -070036 class Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037} // namespace mirror
38
Mathieu Chartiere401d142015-04-22 13:56:20 -070039class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040class Context;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070041class HandleScope;
Nicolas Geoffray57f61612015-05-15 13:20:41 +010042class InlineInfo;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010043class OatQuickMethodHeader;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070044class ScopedObjectAccess;
Nicolas Geoffray57f61612015-05-15 13:20:41 +010045class ShadowFrame;
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000046class StackVisitor;
Elliott Hughes68e76522011-10-05 13:22:16 -070047class Thread;
Vladimir Marko3a21e382016-09-02 12:38:38 +010048union JValue;
Elliott Hughes68e76522011-10-05 13:22:16 -070049
Ian Rogers2bcb4a42012-11-08 10:39:18 -080050// The kind of vreg being accessed in calls to Set/GetVReg.
51enum VRegKind {
52 kReferenceVReg,
53 kIntVReg,
54 kFloatVReg,
55 kLongLoVReg,
56 kLongHiVReg,
57 kDoubleLoVReg,
58 kDoubleHiVReg,
59 kConstant,
60 kImpreciseConstant,
61 kUndefined,
62};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070063std::ostream& operator<<(std::ostream& os, const VRegKind& rhs);
Ian Rogers2bcb4a42012-11-08 10:39:18 -080064
Andreas Gampeb3025922015-09-01 14:45:00 -070065// Forward declaration. Just calls the destructor.
66struct ShadowFrameDeleter;
67using ShadowFrameAllocaUniquePtr = std::unique_ptr<ShadowFrame, ShadowFrameDeleter>;
68
Mingyao Yang063fc772016-08-02 11:02:54 -070069// Size in bytes of the should_deoptimize flag on stack.
70// We just need 4 bytes for our purpose regardless of the architecture. Frame size
71// calculation will automatically do alignment for the final frame size.
72static constexpr size_t kShouldDeoptimizeFlagSize = 4;
73
Andreas Gampe03ec9302015-08-27 17:41:47 -070074// Counting locks by storing object pointers into a vector. Duplicate entries mark recursive locks.
75// The vector will be visited with the ShadowFrame during GC (so all the locked-on objects are
76// thread roots).
77// Note: implementation is split so that the call sites may be optimized to no-ops in case no
78// lock counting is necessary. The actual implementation is in the cc file to avoid
79// dependencies.
80class LockCountData {
81 public:
82 // Add the given object to the list of monitors, that is, objects that have been locked. This
83 // will not throw (but be skipped if there is an exception pending on entry).
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070084 void AddMonitor(Thread* self, mirror::Object* obj) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe03ec9302015-08-27 17:41:47 -070085
86 // Try to remove the given object from the monitor list, indicating an unlock operation.
87 // This will throw an IllegalMonitorStateException (clearing any already pending exception), in
88 // case that there wasn't a lock recorded for the object.
Andreas Gampe03ec9302015-08-27 17:41:47 -070089 void RemoveMonitorOrThrow(Thread* self,
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070090 const mirror::Object* obj) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe03ec9302015-08-27 17:41:47 -070091
92 // Check whether all acquired monitors have been released. This will potentially throw an
93 // IllegalMonitorStateException, clearing any already pending exception. Returns true if the
94 // check shows that everything is OK wrt/ lock counting, false otherwise.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070095 bool CheckAllMonitorsReleasedOrThrow(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe03ec9302015-08-27 17:41:47 -070096
97 template <typename T, typename... Args>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070098 void VisitMonitors(T visitor, Args&&... args) REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe03ec9302015-08-27 17:41:47 -070099 if (monitors_ != nullptr) {
100 // Visitors may change the Object*. Be careful with the foreach loop.
101 for (mirror::Object*& obj : *monitors_) {
102 visitor(/* inout */ &obj, std::forward<Args>(args)...);
103 }
104 }
105 }
106
107 private:
Andreas Gampe03ec9302015-08-27 17:41:47 -0700108 // Stores references to the locked-on objects. As noted, this should be visited during thread
109 // marking.
110 std::unique_ptr<std::vector<mirror::Object*>> monitors_;
111};
112
Elliott Hughes956af0f2014-12-11 14:34:28 -0800113// ShadowFrame has 2 possible layouts:
Mathieu Chartier67022432012-11-29 18:04:50 -0800114// - interpreter - separate VRegs and reference arrays. References are in the reference array.
115// - JNI - just VRegs, but where every VReg holds a reference.
Ian Rogers0399dde2012-06-06 17:09:28 -0700116class ShadowFrame {
Elliott Hughes68e76522011-10-05 13:22:16 -0700117 public:
Ian Rogersef7d42f2014-01-06 12:55:46 -0800118 // Compute size of ShadowFrame in bytes assuming it has a reference array.
Jeff Hao66135192013-05-14 11:02:41 -0700119 static size_t ComputeSize(uint32_t num_vregs) {
120 return sizeof(ShadowFrame) + (sizeof(uint32_t) * num_vregs) +
Ian Rogersef7d42f2014-01-06 12:55:46 -0800121 (sizeof(StackReference<mirror::Object>) * num_vregs);
Jeff Hao66135192013-05-14 11:02:41 -0700122 }
123
124 // Create ShadowFrame in heap for deoptimization.
Christopher Ferris241a9582015-04-27 15:19:41 -0700125 static ShadowFrame* CreateDeoptimizedFrame(uint32_t num_vregs, ShadowFrame* link,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700126 ArtMethod* method, uint32_t dex_pc) {
Jeff Hao66135192013-05-14 11:02:41 -0700127 uint8_t* memory = new uint8_t[ComputeSize(num_vregs)];
Andreas Gampeb3025922015-09-01 14:45:00 -0700128 return CreateShadowFrameImpl(num_vregs, link, method, dex_pc, memory);
Jeff Hao66135192013-05-14 11:02:41 -0700129 }
130
Christopher Ferris241a9582015-04-27 15:19:41 -0700131 // Delete a ShadowFrame allocated on the heap for deoptimization.
132 static void DeleteDeoptimizedFrame(ShadowFrame* sf) {
Andreas Gampeb3025922015-09-01 14:45:00 -0700133 sf->~ShadowFrame(); // Explicitly destruct.
Christopher Ferris241a9582015-04-27 15:19:41 -0700134 uint8_t* memory = reinterpret_cast<uint8_t*>(sf);
135 delete[] memory;
136 }
137
Andreas Gampeb3025922015-09-01 14:45:00 -0700138 // Create a shadow frame in a fresh alloca. This needs to be in the context of the caller.
139 // Inlining doesn't work, the compiler will still undo the alloca. So this needs to be a macro.
140#define CREATE_SHADOW_FRAME(num_vregs, link, method, dex_pc) ({ \
141 size_t frame_size = ShadowFrame::ComputeSize(num_vregs); \
142 void* alloca_mem = alloca(frame_size); \
143 ShadowFrameAllocaUniquePtr( \
144 ShadowFrame::CreateShadowFrameImpl((num_vregs), (link), (method), (dex_pc), \
145 (alloca_mem))); \
146 })
147
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700148 ~ShadowFrame() {}
149
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700150 // TODO(iam): Clean references array up since they're always there,
151 // we don't need to do conditionals.
TDYa127ce4cc0d2012-11-18 16:59:53 -0800152 bool HasReferenceArray() const {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700153 return true;
Ian Rogers0399dde2012-06-06 17:09:28 -0700154 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700155
TDYa127ce4cc0d2012-11-18 16:59:53 -0800156 uint32_t NumberOfVRegs() const {
Ian Rogers8a01a3a2013-05-06 13:25:44 -0700157 return number_of_vregs_;
Ian Rogers5438ad82012-10-15 17:22:44 -0700158 }
159
Ian Rogers0399dde2012-06-06 17:09:28 -0700160 uint32_t GetDexPC() const {
buzbee1452bee2015-03-06 14:43:04 -0800161 return (dex_pc_ptr_ == nullptr) ? dex_pc_ : dex_pc_ptr_ - code_item_->insns_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700162 }
163
Bill Buzbee1d011d92016-04-04 16:59:29 +0000164 int16_t GetCachedHotnessCountdown() const {
165 return cached_hotness_countdown_;
166 }
167
168 void SetCachedHotnessCountdown(int16_t cached_hotness_countdown) {
169 cached_hotness_countdown_ = cached_hotness_countdown;
170 }
171
172 int16_t GetHotnessCountdown() const {
173 return hotness_countdown_;
174 }
175
176 void SetHotnessCountdown(int16_t hotness_countdown) {
177 hotness_countdown_ = hotness_countdown;
178 }
179
Ian Rogers0399dde2012-06-06 17:09:28 -0700180 void SetDexPC(uint32_t dex_pc) {
181 dex_pc_ = dex_pc;
buzbee1452bee2015-03-06 14:43:04 -0800182 dex_pc_ptr_ = nullptr;
Ian Rogers0399dde2012-06-06 17:09:28 -0700183 }
184
Ian Rogers0399dde2012-06-06 17:09:28 -0700185 ShadowFrame* GetLink() const {
186 return link_;
187 }
188
189 void SetLink(ShadowFrame* frame) {
190 DCHECK_NE(this, frame);
191 link_ = frame;
192 }
193
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700194 int32_t GetVReg(size_t i) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800195 DCHECK_LT(i, NumberOfVRegs());
196 const uint32_t* vreg = &vregs_[i];
197 return *reinterpret_cast<const int32_t*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700198 }
199
buzbee31afbec2017-03-14 15:30:19 -0700200 // Shorts are extended to Ints in VRegs. Interpreter intrinsics needs them as shorts.
201 int16_t GetVRegShort(size_t i) const {
202 return static_cast<int16_t>(GetVReg(i));
203 }
204
buzbee1452bee2015-03-06 14:43:04 -0800205 uint32_t* GetVRegAddr(size_t i) {
206 return &vregs_[i];
207 }
208
209 uint32_t* GetShadowRefAddr(size_t i) {
210 DCHECK(HasReferenceArray());
211 DCHECK_LT(i, NumberOfVRegs());
212 return &vregs_[i + NumberOfVRegs()];
213 }
214
215 void SetCodeItem(const DexFile::CodeItem* code_item) {
216 code_item_ = code_item;
217 }
218
Bill Buzbeed47fd902016-07-07 14:42:43 +0000219 const DexFile::CodeItem* GetCodeItem() const {
220 return code_item_;
221 }
222
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700223 float GetVRegFloat(size_t i) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800224 DCHECK_LT(i, NumberOfVRegs());
225 // NOTE: Strict-aliasing?
226 const uint32_t* vreg = &vregs_[i];
227 return *reinterpret_cast<const float*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700228 }
229
230 int64_t GetVRegLong(size_t i) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200231 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800232 const uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700233 typedef const int64_t unaligned_int64 __attribute__ ((aligned (4)));
234 return *reinterpret_cast<unaligned_int64*>(vreg);
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700235 }
236
237 double GetVRegDouble(size_t i) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200238 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800239 const uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700240 typedef const double unaligned_double __attribute__ ((aligned (4)));
241 return *reinterpret_cast<unaligned_double*>(vreg);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800242 }
243
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700244 // Look up the reference given its virtual register number.
245 // If this returns non-null then this does not mean the vreg is currently a reference
246 // 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 -0800247 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700248 mirror::Object* GetVRegReference(size_t i) const REQUIRES_SHARED(Locks::mutator_lock_) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800249 DCHECK_LT(i, NumberOfVRegs());
Mathieu Chartier4e305412014-02-19 10:54:44 -0800250 mirror::Object* ref;
TDYa127ce4cc0d2012-11-18 16:59:53 -0800251 if (HasReferenceArray()) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800252 ref = References()[i].AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800253 } else {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800254 const uint32_t* vreg_ptr = &vregs_[i];
Mathieu Chartier4e305412014-02-19 10:54:44 -0800255 ref = reinterpret_cast<const StackReference<mirror::Object>*>(vreg_ptr)->AsMirrorPtr();
TDYa127ce4cc0d2012-11-18 16:59:53 -0800256 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800257 if (kUseReadBarrier) {
258 ReadBarrier::AssertToSpaceInvariant(ref);
259 }
Mathieu Chartier4e305412014-02-19 10:54:44 -0800260 if (kVerifyFlags & kVerifyReads) {
261 VerifyObject(ref);
262 }
263 return ref;
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700264 }
265
Jeff Hao16743632013-05-08 10:59:04 -0700266 // Get view of vregs as range of consecutive arguments starting at i.
267 uint32_t* GetVRegArgs(size_t i) {
268 return &vregs_[i];
269 }
270
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700271 void SetVReg(size_t i, int32_t val) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800272 DCHECK_LT(i, NumberOfVRegs());
273 uint32_t* vreg = &vregs_[i];
274 *reinterpret_cast<int32_t*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700275 // This is needed for moving collectors since these can update the vreg references if they
276 // happen to agree with references in the reference array.
277 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800278 References()[i].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700279 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700280 }
281
282 void SetVRegFloat(size_t i, float val) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800283 DCHECK_LT(i, NumberOfVRegs());
284 uint32_t* vreg = &vregs_[i];
285 *reinterpret_cast<float*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700286 // This is needed for moving collectors since these can update the vreg references if they
287 // happen to agree with references in the reference array.
288 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800289 References()[i].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700290 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700291 }
292
293 void SetVRegLong(size_t i, int64_t val) {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200294 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800295 uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700296 typedef int64_t unaligned_int64 __attribute__ ((aligned (4)));
297 *reinterpret_cast<unaligned_int64*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700298 // This is needed for moving collectors since these can update the vreg references if they
299 // happen to agree with references in the reference array.
300 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800301 References()[i].Clear();
302 References()[i + 1].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700303 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700304 }
305
306 void SetVRegDouble(size_t i, double val) {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200307 DCHECK_LT(i, NumberOfVRegs());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800308 uint32_t* vreg = &vregs_[i];
Jeff Haoe47637c2013-09-19 15:13:16 -0700309 typedef double unaligned_double __attribute__ ((aligned (4)));
310 *reinterpret_cast<unaligned_double*>(vreg) = val;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700311 // This is needed for moving collectors since these can update the vreg references if they
312 // happen to agree with references in the reference array.
313 if (kMovingCollector && HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800314 References()[i].Clear();
315 References()[i + 1].Clear();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700316 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700317 }
318
Mathieu Chartier4e305412014-02-19 10:54:44 -0800319 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700320 void SetVRegReference(size_t i, mirror::Object* val) REQUIRES_SHARED(Locks::mutator_lock_) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800321 DCHECK_LT(i, NumberOfVRegs());
Mathieu Chartier4e305412014-02-19 10:54:44 -0800322 if (kVerifyFlags & kVerifyWrites) {
323 VerifyObject(val);
324 }
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800325 if (kUseReadBarrier) {
326 ReadBarrier::AssertToSpaceInvariant(val);
327 }
TDYa127ce4cc0d2012-11-18 16:59:53 -0800328 uint32_t* vreg = &vregs_[i];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800329 reinterpret_cast<StackReference<mirror::Object>*>(vreg)->Assign(val);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800330 if (HasReferenceArray()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800331 References()[i].Assign(val);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800332 }
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700333 }
334
Alex Lightdba61482016-12-21 08:20:29 -0800335 void SetMethod(ArtMethod* method) REQUIRES(Locks::mutator_lock_) {
336 DCHECK(method != nullptr);
337 DCHECK(method_ != nullptr);
338 method_ = method;
339 }
340
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700341 ArtMethod* GetMethod() const REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800342 DCHECK(method_ != nullptr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700343 return method_;
Elliott Hughes68e76522011-10-05 13:22:16 -0700344 }
345
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700346 mirror::Object* GetThisObject() const REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800347
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700348 mirror::Object* GetThisObject(uint16_t num_ins) const REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Haoe701f482013-05-24 11:50:49 -0700349
Ian Rogersef7d42f2014-01-06 12:55:46 -0800350 bool Contains(StackReference<mirror::Object>* shadow_frame_entry_obj) const {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800351 if (HasReferenceArray()) {
352 return ((&References()[0] <= shadow_frame_entry_obj) &&
353 (shadow_frame_entry_obj <= (&References()[NumberOfVRegs() - 1])));
354 } else {
355 uint32_t* shadow_frame_entry = reinterpret_cast<uint32_t*>(shadow_frame_entry_obj);
356 return ((&vregs_[0] <= shadow_frame_entry) &&
357 (shadow_frame_entry <= (&vregs_[NumberOfVRegs() - 1])));
Ian Rogers0399dde2012-06-06 17:09:28 -0700358 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700359 }
360
Andreas Gampe03ec9302015-08-27 17:41:47 -0700361 LockCountData& GetLockCountData() {
362 return lock_count_data_;
363 }
364
buzbee1452bee2015-03-06 14:43:04 -0800365 static size_t LockCountDataOffset() {
366 return OFFSETOF_MEMBER(ShadowFrame, lock_count_data_);
367 }
368
Ian Rogers0399dde2012-06-06 17:09:28 -0700369 static size_t LinkOffset() {
370 return OFFSETOF_MEMBER(ShadowFrame, link_);
371 }
372
Ian Rogers0399dde2012-06-06 17:09:28 -0700373 static size_t MethodOffset() {
374 return OFFSETOF_MEMBER(ShadowFrame, method_);
375 }
376
Ian Rogers0399dde2012-06-06 17:09:28 -0700377 static size_t DexPCOffset() {
378 return OFFSETOF_MEMBER(ShadowFrame, dex_pc_);
379 }
380
Ian Rogers5438ad82012-10-15 17:22:44 -0700381 static size_t NumberOfVRegsOffset() {
382 return OFFSETOF_MEMBER(ShadowFrame, number_of_vregs_);
383 }
384
TDYa127ce4cc0d2012-11-18 16:59:53 -0800385 static size_t VRegsOffset() {
386 return OFFSETOF_MEMBER(ShadowFrame, vregs_);
Ian Rogers5438ad82012-10-15 17:22:44 -0700387 }
388
buzbee1452bee2015-03-06 14:43:04 -0800389 static size_t ResultRegisterOffset() {
390 return OFFSETOF_MEMBER(ShadowFrame, result_register_);
391 }
392
393 static size_t DexPCPtrOffset() {
394 return OFFSETOF_MEMBER(ShadowFrame, dex_pc_ptr_);
395 }
396
397 static size_t CodeItemOffset() {
398 return OFFSETOF_MEMBER(ShadowFrame, code_item_);
399 }
400
Bill Buzbee1d011d92016-04-04 16:59:29 +0000401 static size_t CachedHotnessCountdownOffset() {
402 return OFFSETOF_MEMBER(ShadowFrame, cached_hotness_countdown_);
403 }
404
405 static size_t HotnessCountdownOffset() {
406 return OFFSETOF_MEMBER(ShadowFrame, hotness_countdown_);
407 }
408
Andreas Gampeb3025922015-09-01 14:45:00 -0700409 // Create ShadowFrame for interpreter using provided memory.
410 static ShadowFrame* CreateShadowFrameImpl(uint32_t num_vregs,
411 ShadowFrame* link,
412 ArtMethod* method,
413 uint32_t dex_pc,
414 void* memory) {
415 return new (memory) ShadowFrame(num_vregs, link, method, dex_pc, true);
416 }
417
Bill Buzbee1d011d92016-04-04 16:59:29 +0000418 const uint16_t* GetDexPCPtr() {
buzbee1452bee2015-03-06 14:43:04 -0800419 return dex_pc_ptr_;
420 }
421
Bill Buzbeed47fd902016-07-07 14:42:43 +0000422 void SetDexPCPtr(uint16_t* dex_pc_ptr) {
423 dex_pc_ptr_ = dex_pc_ptr;
424 }
425
buzbee1452bee2015-03-06 14:43:04 -0800426 JValue* GetResultRegister() {
427 return result_register_;
428 }
429
Elliott Hughes68e76522011-10-05 13:22:16 -0700430 private:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700431 ShadowFrame(uint32_t num_vregs, ShadowFrame* link, ArtMethod* method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800432 uint32_t dex_pc, bool has_reference_array)
Andreas Gamped9911ee2017-03-27 13:27:24 -0700433 : link_(link),
434 method_(method),
435 result_register_(nullptr),
436 dex_pc_ptr_(nullptr),
437 code_item_(nullptr),
438 number_of_vregs_(num_vregs),
439 dex_pc_(dex_pc),
440 cached_hotness_countdown_(0),
441 hotness_countdown_(0) {
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700442 // TODO(iam): Remove this parameter, it's an an artifact of portable removal
443 DCHECK(has_reference_array);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800444 if (has_reference_array) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800445 memset(vregs_, 0, num_vregs * (sizeof(uint32_t) + sizeof(StackReference<mirror::Object>)));
Mathieu Chartier67022432012-11-29 18:04:50 -0800446 } else {
Jeff Haoe701f482013-05-24 11:50:49 -0700447 memset(vregs_, 0, num_vregs * sizeof(uint32_t));
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700448 }
449 }
Elliott Hughes68e76522011-10-05 13:22:16 -0700450
Ian Rogersef7d42f2014-01-06 12:55:46 -0800451 const StackReference<mirror::Object>* References() const {
Mathieu Chartier67022432012-11-29 18:04:50 -0800452 DCHECK(HasReferenceArray());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800453 const uint32_t* vreg_end = &vregs_[NumberOfVRegs()];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800454 return reinterpret_cast<const StackReference<mirror::Object>*>(vreg_end);
TDYa127ce4cc0d2012-11-18 16:59:53 -0800455 }
456
Ian Rogersef7d42f2014-01-06 12:55:46 -0800457 StackReference<mirror::Object>* References() {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700458 return const_cast<StackReference<mirror::Object>*>(
459 const_cast<const ShadowFrame*>(this)->References());
TDYa127ce4cc0d2012-11-18 16:59:53 -0800460 }
461
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700462 // Link to previous shadow frame or null.
Ian Rogers0399dde2012-06-06 17:09:28 -0700463 ShadowFrame* link_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700464 ArtMethod* method_;
buzbee1452bee2015-03-06 14:43:04 -0800465 JValue* result_register_;
Bill Buzbee1d011d92016-04-04 16:59:29 +0000466 const uint16_t* dex_pc_ptr_;
buzbee1452bee2015-03-06 14:43:04 -0800467 const DexFile::CodeItem* code_item_;
Andreas Gampe03ec9302015-08-27 17:41:47 -0700468 LockCountData lock_count_data_; // This may contain GC roots when lock counting is active.
buzbee1452bee2015-03-06 14:43:04 -0800469 const uint32_t number_of_vregs_;
470 uint32_t dex_pc_;
Bill Buzbee1d011d92016-04-04 16:59:29 +0000471 int16_t cached_hotness_countdown_;
472 int16_t hotness_countdown_;
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700473
474 // This is a two-part array:
475 // - [0..number_of_vregs) holds the raw virtual registers, and each element here is always 4
476 // bytes.
477 // - [number_of_vregs..number_of_vregs*2) holds only reference registers. Each element here is
478 // ptr-sized.
479 // In other words when a primitive is stored in vX, the second (reference) part of the array will
480 // be null. When a reference is stored in vX, the second (reference) part of the array will be a
481 // copy of vX.
TDYa127ce4cc0d2012-11-18 16:59:53 -0800482 uint32_t vregs_[0];
Elliott Hughes68e76522011-10-05 13:22:16 -0700483
Ian Rogers0399dde2012-06-06 17:09:28 -0700484 DISALLOW_IMPLICIT_CONSTRUCTORS(ShadowFrame);
Elliott Hughes68e76522011-10-05 13:22:16 -0700485};
486
Andreas Gampeb3025922015-09-01 14:45:00 -0700487struct ShadowFrameDeleter {
488 inline void operator()(ShadowFrame* frame) {
489 if (frame != nullptr) {
490 frame->~ShadowFrame();
491 }
492 }
493};
494
Andreas Gampe140da3b2016-11-08 16:01:00 -0800495class JavaFrameRootInfo FINAL : public RootInfo {
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800496 public:
497 JavaFrameRootInfo(uint32_t thread_id, const StackVisitor* stack_visitor, size_t vreg)
498 : RootInfo(kRootJavaFrame, thread_id), stack_visitor_(stack_visitor), vreg_(vreg) {
499 }
Andreas Gampe140da3b2016-11-08 16:01:00 -0800500 void Describe(std::ostream& os) const OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700501 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800502
Andreas Gampe140da3b2016-11-08 16:01:00 -0800503 size_t GetVReg() const {
504 return vreg_;
505 }
506 const StackVisitor* GetVisitor() const {
507 return stack_visitor_;
508 }
509
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -0800510 private:
511 const StackVisitor* const stack_visitor_;
512 const size_t vreg_;
513};
514
Ian Rogers0399dde2012-06-06 17:09:28 -0700515class StackVisitor {
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100516 public:
517 // This enum defines a flag to control whether inlined frames are included
518 // when walking the stack.
519 enum class StackWalkKind {
520 kIncludeInlinedFrames,
521 kSkipInlinedFrames,
522 };
523
Ian Rogers0399dde2012-06-06 17:09:28 -0700524 protected:
Hiroshi Yamauchi02f365f2017-02-03 15:06:00 -0800525 StackVisitor(Thread* thread,
526 Context* context,
527 StackWalkKind walk_kind,
528 bool check_suspended = true);
Ian Rogers0399dde2012-06-06 17:09:28 -0700529
Nicolas Geoffray33856502015-10-20 15:52:58 +0100530 bool GetRegisterIfAccessible(uint32_t reg, VRegKind kind, uint32_t* val) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700531 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray33856502015-10-20 15:52:58 +0100532
Ian Rogers0399dde2012-06-06 17:09:28 -0700533 public:
534 virtual ~StackVisitor() {}
Andreas Gampe6db6b4d2017-06-12 16:36:33 -0700535 StackVisitor(const StackVisitor&) = default;
536 StackVisitor(StackVisitor&&) = default;
Ian Rogers0399dde2012-06-06 17:09:28 -0700537
538 // Return 'true' if we should continue to visit more frames, 'false' to stop.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700539 virtual bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Ian Rogers0399dde2012-06-06 17:09:28 -0700540
Andreas Gampe585da952016-12-02 14:52:29 -0800541 enum class CountTransitions {
542 kYes,
543 kNo,
544 };
545
546 template <CountTransitions kCount = CountTransitions::kYes>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700547 void WalkStack(bool include_transitions = false)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700548 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700549
Sebastien Hertz26f72862015-09-15 09:52:07 +0200550 Thread* GetThread() const {
551 return thread_;
552 }
553
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700554 ArtMethod* GetMethod() const REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi92d1a662014-05-15 21:43:59 -0700555
Alex Lightdba61482016-12-21 08:20:29 -0800556 // Sets this stack frame's method pointer. This requires a full lock of the MutatorLock. This
557 // doesn't work with inlined methods.
558 void SetMethod(ArtMethod* method) REQUIRES(Locks::mutator_lock_);
559
Nicolas Geoffrayccc61972015-10-01 14:34:20 +0100560 ArtMethod* GetOuterMethod() const {
561 return *GetCurrentQuickFrame();
562 }
563
Ian Rogers0399dde2012-06-06 17:09:28 -0700564 bool IsShadowFrame() const {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800565 return cur_shadow_frame_ != nullptr;
Ian Rogers0399dde2012-06-06 17:09:28 -0700566 }
567
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700568 uint32_t GetDexPc(bool abort_on_failure = true) const REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers0c7abda2012-09-19 13:33:42 -0700569
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700570 mirror::Object* GetThisObject() const REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800571
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700572 size_t GetNativePcOffset() const REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers0c7abda2012-09-19 13:33:42 -0700573
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700574 // Returns the height of the stack in the managed stack frames, including transitions.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700575 size_t GetFrameHeight() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800576 return GetNumFrames() - cur_depth_ - 1;
Ian Rogers0399dde2012-06-06 17:09:28 -0700577 }
578
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700579 // Returns a frame ID for JDWP use, starting from 1.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700580 size_t GetFrameId() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700581 return GetFrameHeight() + 1;
582 }
583
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700584 size_t GetNumFrames() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers0399dde2012-06-06 17:09:28 -0700585 if (num_frames_ == 0) {
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100586 num_frames_ = ComputeNumFrames(thread_, walk_kind_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700587 }
588 return num_frames_;
589 }
590
Andreas Gampe140da3b2016-11-08 16:01:00 -0800591 size_t GetFrameDepth() const REQUIRES_SHARED(Locks::mutator_lock_) {
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -0700592 return cur_depth_;
593 }
594
Ian Rogers5cf98192014-05-29 21:31:50 -0700595 // Get the method and dex pc immediately after the one that's currently being visited.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700596 bool GetNextMethodAndDexPc(ArtMethod** next_method, uint32_t* next_dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700597 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers5cf98192014-05-29 21:31:50 -0700598
Mathieu Chartiere401d142015-04-22 13:56:20 -0700599 bool GetVReg(ArtMethod* m, uint16_t vreg, VRegKind kind, uint32_t* val) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700600 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700601
Mathieu Chartiere401d142015-04-22 13:56:20 -0700602 bool GetVRegPair(ArtMethod* m, uint16_t vreg, VRegKind kind_lo, VRegKind kind_hi,
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200603 uint64_t* val) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700604 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200605
Mingyao Yang636b9252015-07-31 16:40:24 -0700606 // Values will be set in debugger shadow frames. Debugger will make sure deoptimization
607 // is triggered to make the values effective.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700608 bool SetVReg(ArtMethod* m, uint16_t vreg, uint32_t new_value, VRegKind kind)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700609 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700610
Mingyao Yang99170c62015-07-06 11:10:37 -0700611 // Values will be set in debugger shadow frames. Debugger will make sure deoptimization
612 // is triggered to make the values effective.
Mingyao Yang636b9252015-07-31 16:40:24 -0700613 bool SetVRegPair(ArtMethod* m,
614 uint16_t vreg,
615 uint64_t new_value,
616 VRegKind kind_lo,
617 VRegKind kind_hi)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700618 REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang99170c62015-07-06 11:10:37 -0700619
Mathieu Chartier815873e2014-02-13 18:02:13 -0800620 uintptr_t* GetGPRAddress(uint32_t reg) const;
Ian Rogers0399dde2012-06-06 17:09:28 -0700621
Mathieu Chartier423d2a32013-09-12 17:33:56 -0700622 // This is a fast-path for getting/setting values in a quick frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700623 uint32_t* GetVRegAddrFromQuickCode(ArtMethod** cur_quick_frame,
Nicolas Geoffray15b9d522015-03-12 15:05:13 +0000624 const DexFile::CodeItem* code_item,
625 uint32_t core_spills, uint32_t fp_spills, size_t frame_size,
626 uint16_t vreg) const {
627 int offset = GetVRegOffsetFromQuickCode(
628 code_item, core_spills, fp_spills, frame_size, vreg, kRuntimeISA);
Ian Rogers0ec569a2012-07-01 16:43:46 -0700629 DCHECK_EQ(cur_quick_frame, GetCurrentQuickFrame());
Ian Rogers13735952014-10-08 12:43:28 -0700630 uint8_t* vreg_addr = reinterpret_cast<uint8_t*>(cur_quick_frame) + offset;
Mathieu Chartier423d2a32013-09-12 17:33:56 -0700631 return reinterpret_cast<uint32_t*>(vreg_addr);
Ian Rogers0399dde2012-06-06 17:09:28 -0700632 }
633
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700634 uintptr_t GetReturnPc() const REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700635
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700636 void SetReturnPc(uintptr_t new_ret_pc) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700637
638 /*
639 * Return sp-relative offset for a Dalvik virtual register, compiler
640 * spill or Method* in bytes using Method*.
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700641 * Note that (reg == -1) denotes an invalid Dalvik register. For the
642 * positive values, the Dalvik registers come first, followed by the
643 * Method*, followed by other special temporaries if any, followed by
644 * regular compiler temporary. As of now we only have the Method* as
645 * as a special compiler temporary.
646 * A compiler temporary can be thought of as a virtual register that
647 * does not exist in the dex but holds intermediate values to help
648 * optimizations and code generation. A special compiler temporary is
649 * one whose location in frame is well known while non-special ones
650 * do not have a requirement on location in frame as long as code
651 * generator itself knows how to access them.
Ian Rogers0399dde2012-06-06 17:09:28 -0700652 *
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700653 * +-------------------------------+
654 * | IN[ins-1] | {Note: resides in caller's frame}
655 * | . |
656 * | IN[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700657 * | caller's ArtMethod | ... ArtMethod*
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700658 * +===============================+ {Note: start of callee's frame}
659 * | core callee-save spill | {variable sized}
660 * +-------------------------------+
661 * | fp callee-save spill |
662 * +-------------------------------+
663 * | filler word | {For compatibility, if V[locals-1] used as wide
664 * +-------------------------------+
665 * | V[locals-1] |
666 * | V[locals-2] |
667 * | . |
668 * | . | ... (reg == 2)
669 * | V[1] | ... (reg == 1)
670 * | V[0] | ... (reg == 0) <---- "locals_start"
671 * +-------------------------------+
672 * | stack alignment padding | {0 to (kStackAlignWords-1) of padding}
673 * +-------------------------------+
674 * | Compiler temp region | ... (reg >= max_num_special_temps)
675 * | . |
676 * | . |
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700677 * | V[max_num_special_temps + 1] |
678 * | V[max_num_special_temps + 0] |
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700679 * +-------------------------------+
680 * | OUT[outs-1] |
681 * | OUT[outs-2] |
682 * | . |
683 * | OUT[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700684 * | ArtMethod* | ... (reg == num_total_code_regs == special_temp_value) <<== sp, 16-byte aligned
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700685 * +===============================+
Ian Rogers0399dde2012-06-06 17:09:28 -0700686 */
Nicolas Geoffray15b9d522015-03-12 15:05:13 +0000687 static int GetVRegOffsetFromQuickCode(const DexFile::CodeItem* code_item,
688 uint32_t core_spills, uint32_t fp_spills,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700689 size_t frame_size, int reg, InstructionSet isa);
Ian Rogers0399dde2012-06-06 17:09:28 -0700690
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000691 static int GetOutVROffset(uint16_t out_num, InstructionSet isa) {
buzbee82818642014-06-04 15:35:41 -0700692 // According to stack model, the first out is above the Method referernce.
Andreas Gampe542451c2016-07-26 09:02:02 -0700693 return static_cast<size_t>(InstructionSetPointerSize(isa)) + out_num * sizeof(uint32_t);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800694 }
695
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100696 bool IsInInlinedFrame() const {
Nicolas Geoffray57f61612015-05-15 13:20:41 +0100697 return current_inlining_depth_ != 0;
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100698 }
699
David Brazdilefc3f022015-10-28 12:19:06 -0500700 size_t GetCurrentInliningDepth() const {
701 return current_inlining_depth_;
702 }
703
Ian Rogers0399dde2012-06-06 17:09:28 -0700704 uintptr_t GetCurrentQuickFramePc() const {
705 return cur_quick_frame_pc_;
706 }
707
Mathieu Chartiere401d142015-04-22 13:56:20 -0700708 ArtMethod** GetCurrentQuickFrame() const {
Ian Rogers0399dde2012-06-06 17:09:28 -0700709 return cur_quick_frame_;
710 }
711
712 ShadowFrame* GetCurrentShadowFrame() const {
713 return cur_shadow_frame_;
714 }
715
Mathieu Chartiere401d142015-04-22 13:56:20 -0700716 HandleScope* GetCurrentHandleScope(size_t pointer_size) const {
717 ArtMethod** sp = GetCurrentQuickFrame();
718 // Skip ArtMethod*; handle scope comes next;
719 return reinterpret_cast<HandleScope*>(reinterpret_cast<uintptr_t>(sp) + pointer_size);
Elliott Hughes08fc03a2012-06-26 17:34:00 -0700720 }
721
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700722 std::string DescribeLocation() const REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers40e3bac2012-11-20 00:09:14 -0800723
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100724 static size_t ComputeNumFrames(Thread* thread, StackWalkKind walk_kind)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700725 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers306057f2012-11-26 12:45:53 -0800726
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700727 static void DescribeStack(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers306057f2012-11-26 12:45:53 -0800728
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100729 const OatQuickMethodHeader* GetCurrentOatQuickMethodHeader() const {
730 return cur_oat_quick_method_header_;
731 }
732
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700733 QuickMethodFrameInfo GetCurrentQuickFrameInfo() const REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray6bc43742015-10-12 18:11:10 +0100734
Ian Rogers0399dde2012-06-06 17:09:28 -0700735 private:
Ian Rogers5cf98192014-05-29 21:31:50 -0700736 // Private constructor known in the case that num_frames_ has already been computed.
Hiroshi Yamauchi02f365f2017-02-03 15:06:00 -0800737 StackVisitor(Thread* thread,
738 Context* context,
739 StackWalkKind walk_kind,
740 size_t num_frames,
741 bool check_suspended = true)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700742 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers5cf98192014-05-29 21:31:50 -0700743
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +0100744 bool IsAccessibleRegister(uint32_t reg, bool is_float) const {
745 return is_float ? IsAccessibleFPR(reg) : IsAccessibleGPR(reg);
746 }
747 uintptr_t GetRegister(uint32_t reg, bool is_float) const {
748 DCHECK(IsAccessibleRegister(reg, is_float));
749 return is_float ? GetFPR(reg) : GetGPR(reg);
750 }
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +0100751
752 bool IsAccessibleGPR(uint32_t reg) const;
753 uintptr_t GetGPR(uint32_t reg) const;
Sebastien Hertz96ba8dc2015-01-22 18:57:14 +0100754
755 bool IsAccessibleFPR(uint32_t reg) const;
756 uintptr_t GetFPR(uint32_t reg) const;
Sebastien Hertz0bcb2902014-06-17 15:52:45 +0200757
Mingyao Yang99170c62015-07-06 11:10:37 -0700758 bool GetVRegFromDebuggerShadowFrame(uint16_t vreg, VRegKind kind, uint32_t* val) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700759 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700760 bool GetVRegFromOptimizedCode(ArtMethod* m, uint16_t vreg, VRegKind kind,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100761 uint32_t* val) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700762 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100763
Mingyao Yang99170c62015-07-06 11:10:37 -0700764 bool GetVRegPairFromDebuggerShadowFrame(uint16_t vreg, VRegKind kind_lo, VRegKind kind_hi,
765 uint64_t* val) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700766 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700767 bool GetVRegPairFromOptimizedCode(ArtMethod* m, uint16_t vreg,
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100768 VRegKind kind_lo, VRegKind kind_hi,
769 uint64_t* val) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700770 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100771 bool GetRegisterPairIfAccessible(uint32_t reg_lo, uint32_t reg_hi, VRegKind kind_lo,
772 uint64_t* val) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700773 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100774
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700775 void SanityCheckFrame() const REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers0399dde2012-06-06 17:09:28 -0700776
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700777 InlineInfo GetCurrentInlineInfo() const REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray57f61612015-05-15 13:20:41 +0100778
Ian Rogers7a22fa62013-01-23 12:16:16 -0800779 Thread* const thread_;
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100780 const StackWalkKind walk_kind_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700781 ShadowFrame* cur_shadow_frame_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700782 ArtMethod** cur_quick_frame_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700783 uintptr_t cur_quick_frame_pc_;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100784 const OatQuickMethodHeader* cur_oat_quick_method_header_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700785 // Lazily computed, number of frames in the stack.
786 size_t num_frames_;
787 // Depth of the frame we're currently at.
788 size_t cur_depth_;
Nicolas Geoffray57f61612015-05-15 13:20:41 +0100789 // Current inlining depth of the method we are currently at.
790 // 0 if there is no inlined frame.
791 size_t current_inlining_depth_;
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700792
Ian Rogers0399dde2012-06-06 17:09:28 -0700793 protected:
794 Context* const context_;
Hiroshi Yamauchi02f365f2017-02-03 15:06:00 -0800795 const bool check_suspended_;
Ian Rogers0399dde2012-06-06 17:09:28 -0700796};
797
Elliott Hughes68e76522011-10-05 13:22:16 -0700798} // namespace art
799
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700800#endif // ART_RUNTIME_STACK_H_