Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_STACK_H_ |
| 18 | #define ART_RUNTIME_STACK_H_ |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 19 | |
David Srbecky | cffa254 | 2019-07-01 15:31:41 +0100 | [diff] [blame] | 20 | #include <optional> |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 22 | #include <string> |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 23 | |
Andreas Gampe | 7fbc4a5 | 2018-11-28 08:26:47 -0800 | [diff] [blame] | 24 | #include "base/locks.h" |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 25 | #include "base/macros.h" |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 26 | #include "obj_ptr.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 27 | #include "quick/quick_method_frame_info.h" |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 28 | #include "stack_map.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 29 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 30 | namespace art { |
| 31 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | namespace mirror { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 33 | class Object; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | } // namespace mirror |
| 35 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 36 | class ArtMethod; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | class Context; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 38 | class HandleScope; |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 39 | class OatQuickMethodHeader; |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 40 | class ShadowFrame; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 41 | class Thread; |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 42 | union JValue; |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 43 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 44 | // The kind of vreg being accessed in calls to Set/GetVReg. |
| 45 | enum VRegKind { |
| 46 | kReferenceVReg, |
| 47 | kIntVReg, |
| 48 | kFloatVReg, |
| 49 | kLongLoVReg, |
| 50 | kLongHiVReg, |
| 51 | kDoubleLoVReg, |
| 52 | kDoubleHiVReg, |
| 53 | kConstant, |
| 54 | kImpreciseConstant, |
| 55 | kUndefined, |
| 56 | }; |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 57 | std::ostream& operator<<(std::ostream& os, VRegKind rhs); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 58 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 59 | // Size in bytes of the should_deoptimize flag on stack. |
| 60 | // We just need 4 bytes for our purpose regardless of the architecture. Frame size |
| 61 | // calculation will automatically do alignment for the final frame size. |
| 62 | static constexpr size_t kShouldDeoptimizeFlagSize = 4; |
| 63 | |
Andreas Gampe | 36a296f | 2017-06-13 14:11:11 -0700 | [diff] [blame] | 64 | /* |
| 65 | * Our current stack layout. |
| 66 | * The Dalvik registers come first, followed by the |
| 67 | * Method*, followed by other special temporaries if any, followed by |
| 68 | * regular compiler temporary. As of now we only have the Method* as |
| 69 | * as a special compiler temporary. |
| 70 | * A compiler temporary can be thought of as a virtual register that |
| 71 | * does not exist in the dex but holds intermediate values to help |
| 72 | * optimizations and code generation. A special compiler temporary is |
| 73 | * one whose location in frame is well known while non-special ones |
| 74 | * do not have a requirement on location in frame as long as code |
| 75 | * generator itself knows how to access them. |
| 76 | * |
| 77 | * TODO: Update this documentation? |
| 78 | * |
| 79 | * +-------------------------------+ |
| 80 | * | IN[ins-1] | {Note: resides in caller's frame} |
| 81 | * | . | |
| 82 | * | IN[0] | |
| 83 | * | caller's ArtMethod | ... ArtMethod* |
| 84 | * +===============================+ {Note: start of callee's frame} |
| 85 | * | core callee-save spill | {variable sized} |
| 86 | * +-------------------------------+ |
| 87 | * | fp callee-save spill | |
| 88 | * +-------------------------------+ |
| 89 | * | filler word | {For compatibility, if V[locals-1] used as wide |
| 90 | * +-------------------------------+ |
| 91 | * | V[locals-1] | |
| 92 | * | V[locals-2] | |
| 93 | * | . | |
| 94 | * | . | ... (reg == 2) |
| 95 | * | V[1] | ... (reg == 1) |
| 96 | * | V[0] | ... (reg == 0) <---- "locals_start" |
| 97 | * +-------------------------------+ |
| 98 | * | stack alignment padding | {0 to (kStackAlignWords-1) of padding} |
| 99 | * +-------------------------------+ |
| 100 | * | Compiler temp region | ... (reg >= max_num_special_temps) |
| 101 | * | . | |
| 102 | * | . | |
| 103 | * | V[max_num_special_temps + 1] | |
| 104 | * | V[max_num_special_temps + 0] | |
| 105 | * +-------------------------------+ |
| 106 | * | OUT[outs-1] | |
| 107 | * | OUT[outs-2] | |
| 108 | * | . | |
| 109 | * | OUT[0] | |
| 110 | * | ArtMethod* | ... (reg == num_total_code_regs == special_temp_value) <<== sp, 16-byte aligned |
| 111 | * +===============================+ |
| 112 | */ |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 113 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 114 | class StackVisitor { |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 115 | public: |
| 116 | // This enum defines a flag to control whether inlined frames are included |
| 117 | // when walking the stack. |
| 118 | enum class StackWalkKind { |
| 119 | kIncludeInlinedFrames, |
| 120 | kSkipInlinedFrames, |
| 121 | }; |
| 122 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 123 | protected: |
Hiroshi Yamauchi | 02f365f | 2017-02-03 15:06:00 -0800 | [diff] [blame] | 124 | StackVisitor(Thread* thread, |
| 125 | Context* context, |
| 126 | StackWalkKind walk_kind, |
| 127 | bool check_suspended = true); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 128 | |
Nicolas Geoffray | 6624d58 | 2020-09-01 15:02:00 +0100 | [diff] [blame] | 129 | bool GetRegisterIfAccessible(uint32_t reg, DexRegisterLocation::Kind kind, uint32_t* val) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 130 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 3385650 | 2015-10-20 15:52:58 +0100 | [diff] [blame] | 131 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 132 | public: |
| 133 | virtual ~StackVisitor() {} |
Andreas Gampe | 6db6b4d | 2017-06-12 16:36:33 -0700 | [diff] [blame] | 134 | StackVisitor(const StackVisitor&) = default; |
| 135 | StackVisitor(StackVisitor&&) = default; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 136 | |
| 137 | // Return 'true' if we should continue to visit more frames, 'false' to stop. |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 138 | virtual bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 139 | |
Andreas Gampe | 585da95 | 2016-12-02 14:52:29 -0800 | [diff] [blame] | 140 | enum class CountTransitions { |
| 141 | kYes, |
| 142 | kNo, |
| 143 | }; |
| 144 | |
| 145 | template <CountTransitions kCount = CountTransitions::kYes> |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 146 | void WalkStack(bool include_transitions = false) REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 147 | |
Andreas Gampe | c7d878d | 2018-11-19 18:42:06 +0000 | [diff] [blame] | 148 | // Convenience helper function to walk the stack with a lambda as a visitor. |
| 149 | template <CountTransitions kCountTransitions = CountTransitions::kYes, |
| 150 | typename T> |
| 151 | ALWAYS_INLINE static void WalkStack(const T& fn, |
| 152 | Thread* thread, |
| 153 | Context* context, |
| 154 | StackWalkKind walk_kind, |
| 155 | bool check_suspended = true, |
| 156 | bool include_transitions = false) |
| 157 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 158 | class LambdaStackVisitor : public StackVisitor { |
| 159 | public: |
| 160 | LambdaStackVisitor(const T& fn, |
| 161 | Thread* thread, |
| 162 | Context* context, |
| 163 | StackWalkKind walk_kind, |
| 164 | bool check_suspended = true) |
| 165 | : StackVisitor(thread, context, walk_kind, check_suspended), fn_(fn) {} |
| 166 | |
| 167 | bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) { |
| 168 | return fn_(this); |
| 169 | } |
| 170 | |
| 171 | private: |
| 172 | T fn_; |
| 173 | }; |
| 174 | LambdaStackVisitor visitor(fn, thread, context, walk_kind, check_suspended); |
| 175 | visitor.template WalkStack<kCountTransitions>(include_transitions); |
| 176 | } |
| 177 | |
Sebastien Hertz | 26f7286 | 2015-09-15 09:52:07 +0200 | [diff] [blame] | 178 | Thread* GetThread() const { |
| 179 | return thread_; |
| 180 | } |
| 181 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 182 | ArtMethod* GetMethod() const REQUIRES_SHARED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 92d1a66 | 2014-05-15 21:43:59 -0700 | [diff] [blame] | 183 | |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 184 | // Sets this stack frame's method pointer. This requires a full lock of the MutatorLock. This |
| 185 | // doesn't work with inlined methods. |
| 186 | void SetMethod(ArtMethod* method) REQUIRES(Locks::mutator_lock_); |
| 187 | |
Nicolas Geoffray | ccc6197 | 2015-10-01 14:34:20 +0100 | [diff] [blame] | 188 | ArtMethod* GetOuterMethod() const { |
| 189 | return *GetCurrentQuickFrame(); |
| 190 | } |
| 191 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 192 | bool IsShadowFrame() const { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 193 | return cur_shadow_frame_ != nullptr; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 196 | uint32_t GetDexPc(bool abort_on_failure = true) const REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 197 | |
Vladimir Marko | abedfca | 2019-05-23 14:07:47 +0100 | [diff] [blame] | 198 | ObjPtr<mirror::Object> GetThisObject() const REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 199 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 200 | size_t GetNativePcOffset() const REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 201 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 202 | // Returns the height of the stack in the managed stack frames, including transitions. |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 203 | size_t GetFrameHeight() REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 204 | return GetNumFrames() - cur_depth_ - 1; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 207 | // Returns a frame ID for JDWP use, starting from 1. |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 208 | size_t GetFrameId() REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 209 | return GetFrameHeight() + 1; |
| 210 | } |
| 211 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 212 | size_t GetNumFrames() REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 213 | if (num_frames_ == 0) { |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 214 | num_frames_ = ComputeNumFrames(thread_, walk_kind_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 215 | } |
| 216 | return num_frames_; |
| 217 | } |
| 218 | |
Andreas Gampe | 140da3b | 2016-11-08 16:01:00 -0800 | [diff] [blame] | 219 | size_t GetFrameDepth() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 649278c | 2014-08-13 11:12:22 -0700 | [diff] [blame] | 220 | return cur_depth_; |
| 221 | } |
| 222 | |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 223 | // Get the method and dex pc immediately after the one that's currently being visited. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 224 | bool GetNextMethodAndDexPc(ArtMethod** next_method, uint32_t* next_dex_pc) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 225 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 226 | |
David Srbecky | cffa254 | 2019-07-01 15:31:41 +0100 | [diff] [blame] | 227 | bool GetVReg(ArtMethod* m, |
| 228 | uint16_t vreg, |
| 229 | VRegKind kind, |
| 230 | uint32_t* val, |
| 231 | std::optional<DexRegisterLocation> location = |
| 232 | std::optional<DexRegisterLocation>()) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 233 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 234 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 235 | bool GetVRegPair(ArtMethod* m, uint16_t vreg, VRegKind kind_lo, VRegKind kind_hi, |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 236 | uint64_t* val) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 237 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 238 | |
Mingyao Yang | 636b925 | 2015-07-31 16:40:24 -0700 | [diff] [blame] | 239 | // Values will be set in debugger shadow frames. Debugger will make sure deoptimization |
| 240 | // is triggered to make the values effective. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 241 | bool SetVReg(ArtMethod* m, uint16_t vreg, uint32_t new_value, VRegKind kind) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 242 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 243 | |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 244 | // Values will be set in debugger shadow frames. Debugger will make sure deoptimization |
| 245 | // is triggered to make the values effective. |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 246 | bool SetVRegReference(ArtMethod* m, uint16_t vreg, ObjPtr<mirror::Object> new_value) |
| 247 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 248 | |
| 249 | // Values will be set in debugger shadow frames. Debugger will make sure deoptimization |
| 250 | // is triggered to make the values effective. |
Mingyao Yang | 636b925 | 2015-07-31 16:40:24 -0700 | [diff] [blame] | 251 | bool SetVRegPair(ArtMethod* m, |
| 252 | uint16_t vreg, |
| 253 | uint64_t new_value, |
| 254 | VRegKind kind_lo, |
| 255 | VRegKind kind_hi) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 256 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 257 | |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 258 | uintptr_t* GetGPRAddress(uint32_t reg) const; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 259 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 260 | uintptr_t GetReturnPc() const REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | e91e795 | 2020-01-23 10:15:56 +0000 | [diff] [blame] | 261 | uintptr_t GetReturnPcAddr() const REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 262 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 263 | void SetReturnPc(uintptr_t new_ret_pc) REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 264 | |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 265 | bool IsInInlinedFrame() const { |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 266 | return !current_inline_frames_.empty(); |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 267 | } |
| 268 | |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 269 | InlineInfo GetCurrentInlinedFrame() const { |
| 270 | return current_inline_frames_.back(); |
David Brazdil | efc3f02 | 2015-10-28 12:19:06 -0500 | [diff] [blame] | 271 | } |
| 272 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 273 | uintptr_t GetCurrentQuickFramePc() const { |
| 274 | return cur_quick_frame_pc_; |
| 275 | } |
| 276 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 277 | ArtMethod** GetCurrentQuickFrame() const { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 278 | return cur_quick_frame_; |
| 279 | } |
| 280 | |
| 281 | ShadowFrame* GetCurrentShadowFrame() const { |
| 282 | return cur_shadow_frame_; |
| 283 | } |
| 284 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 285 | std::string DescribeLocation() const REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 286 | |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 287 | static size_t ComputeNumFrames(Thread* thread, StackWalkKind walk_kind) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 288 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 289 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 290 | static void DescribeStack(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 291 | |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 292 | const OatQuickMethodHeader* GetCurrentOatQuickMethodHeader() const { |
| 293 | return cur_oat_quick_method_header_; |
| 294 | } |
| 295 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 296 | QuickMethodFrameInfo GetCurrentQuickFrameInfo() const REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 297 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 298 | private: |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 299 | // Private constructor known in the case that num_frames_ has already been computed. |
Hiroshi Yamauchi | 02f365f | 2017-02-03 15:06:00 -0800 | [diff] [blame] | 300 | StackVisitor(Thread* thread, |
| 301 | Context* context, |
| 302 | StackWalkKind walk_kind, |
| 303 | size_t num_frames, |
| 304 | bool check_suspended = true) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 305 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 306 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 307 | bool IsAccessibleRegister(uint32_t reg, bool is_float) const { |
| 308 | return is_float ? IsAccessibleFPR(reg) : IsAccessibleGPR(reg); |
| 309 | } |
| 310 | uintptr_t GetRegister(uint32_t reg, bool is_float) const { |
| 311 | DCHECK(IsAccessibleRegister(reg, is_float)); |
| 312 | return is_float ? GetFPR(reg) : GetGPR(reg); |
| 313 | } |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 314 | |
| 315 | bool IsAccessibleGPR(uint32_t reg) const; |
| 316 | uintptr_t GetGPR(uint32_t reg) const; |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 317 | |
| 318 | bool IsAccessibleFPR(uint32_t reg) const; |
| 319 | uintptr_t GetFPR(uint32_t reg) const; |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 320 | |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 321 | bool GetVRegFromDebuggerShadowFrame(uint16_t vreg, VRegKind kind, uint32_t* val) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 322 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 6624d58 | 2020-09-01 15:02:00 +0100 | [diff] [blame] | 323 | bool GetVRegFromOptimizedCode(ArtMethod* m, |
| 324 | uint16_t vreg, |
| 325 | VRegKind kind, |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 326 | uint32_t* val) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 327 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 328 | |
Nicolas Geoffray | 6624d58 | 2020-09-01 15:02:00 +0100 | [diff] [blame] | 329 | bool GetVRegPairFromDebuggerShadowFrame(uint16_t vreg, |
| 330 | VRegKind kind_lo, |
| 331 | VRegKind kind_hi, |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 332 | uint64_t* val) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 333 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 6624d58 | 2020-09-01 15:02:00 +0100 | [diff] [blame] | 334 | bool GetVRegPairFromOptimizedCode(ArtMethod* m, |
| 335 | uint16_t vreg, |
| 336 | VRegKind kind_lo, |
| 337 | VRegKind kind_hi, |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 338 | uint64_t* val) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 339 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 6624d58 | 2020-09-01 15:02:00 +0100 | [diff] [blame] | 340 | bool GetVRegFromOptimizedCode(DexRegisterLocation location, uint32_t* val) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 341 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 342 | |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 343 | ShadowFrame* PrepareSetVReg(ArtMethod* m, uint16_t vreg, bool wide) |
| 344 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 345 | |
Orion Hodson | 6aaa49d | 2020-07-28 15:53:04 +0100 | [diff] [blame] | 346 | void ValidateFrame() const REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 347 | |
David Srbecky | 145a18a | 2019-06-03 14:35:22 +0100 | [diff] [blame] | 348 | ALWAYS_INLINE CodeInfo* GetCurrentInlineInfo() const; |
| 349 | ALWAYS_INLINE StackMap* GetCurrentStackMap() const; |
| 350 | |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 351 | Thread* const thread_; |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 352 | const StackWalkKind walk_kind_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 353 | ShadowFrame* cur_shadow_frame_; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 354 | ArtMethod** cur_quick_frame_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 355 | uintptr_t cur_quick_frame_pc_; |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 356 | const OatQuickMethodHeader* cur_oat_quick_method_header_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 357 | // Lazily computed, number of frames in the stack. |
| 358 | size_t num_frames_; |
| 359 | // Depth of the frame we're currently at. |
| 360 | size_t cur_depth_; |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 361 | // Current inlined frames of the method we are currently at. |
| 362 | // We keep poping frames from the end as we visit the frames. |
| 363 | BitTableRange<InlineInfo> current_inline_frames_; |
Brian Carlstrom | 0cd7ec2 | 2013-07-17 23:40:20 -0700 | [diff] [blame] | 364 | |
David Srbecky | 145a18a | 2019-06-03 14:35:22 +0100 | [diff] [blame] | 365 | // Cache the most recently decoded inline info data. |
| 366 | // The 'current_inline_frames_' refers to this data, so we need to keep it alive anyway. |
| 367 | // Marked mutable since the cache fields are updated from const getters. |
| 368 | mutable std::pair<const OatQuickMethodHeader*, CodeInfo> cur_inline_info_; |
| 369 | mutable std::pair<uintptr_t, StackMap> cur_stack_map_; |
| 370 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 371 | protected: |
| 372 | Context* const context_; |
Hiroshi Yamauchi | 02f365f | 2017-02-03 15:06:00 -0800 | [diff] [blame] | 373 | const bool check_suspended_; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 374 | }; |
| 375 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 376 | } // namespace art |
| 377 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 378 | #endif // ART_RUNTIME_STACK_H_ |