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 | |
| 17 | #include "stack.h" |
Alex Light | b096c91 | 2019-09-25 13:33:06 -0700 | [diff] [blame] | 18 | #include <limits> |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 19 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 20 | #include "android-base/stringprintf.h" |
| 21 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 22 | #include "arch/context.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 23 | #include "art_method-inl.h" |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 24 | #include "base/aborting.h" |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 25 | #include "base/callee_save_type.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 26 | #include "base/enums.h" |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 27 | #include "base/hex_dump.h" |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 28 | #include "base/mutex.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 29 | #include "dex/dex_file_types.h" |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 30 | #include "entrypoints/entrypoint_utils-inl.h" |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 31 | #include "entrypoints/quick/callee_save_frame.h" |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 32 | #include "entrypoints/runtime_asm_entrypoints.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | #include "gc/space/image_space.h" |
| 34 | #include "gc/space/space-inl.h" |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 35 | #include "interpreter/shadow_frame-inl.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 36 | #include "jit/jit.h" |
| 37 | #include "jit/jit_code_cache.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 38 | #include "linear_alloc.h" |
Andreas Gampe | 513061a | 2017-06-01 09:17:34 -0700 | [diff] [blame] | 39 | #include "managed_stack.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 40 | #include "mirror/class-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 41 | #include "mirror/object-inl.h" |
| 42 | #include "mirror/object_array-inl.h" |
Nicolas Geoffray | 013d1ee | 2019-12-04 16:18:15 +0000 | [diff] [blame] | 43 | #include "nterp_helpers.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 44 | #include "oat_quick_method_header.h" |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 45 | #include "obj_ptr-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 46 | #include "quick/quick_method_frame_info.h" |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 47 | #include "runtime.h" |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 48 | #include "thread.h" |
Elliott Hughes | bfe487b | 2011-10-26 15:48:55 -0700 | [diff] [blame] | 49 | #include "thread_list.h" |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 50 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 51 | namespace art { |
| 52 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 53 | using android::base::StringPrintf; |
| 54 | |
Mathieu Chartier | 8405bfd | 2016-02-05 12:00:49 -0800 | [diff] [blame] | 55 | static constexpr bool kDebugStackWalk = false; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 56 | |
Hiroshi Yamauchi | 02f365f | 2017-02-03 15:06:00 -0800 | [diff] [blame] | 57 | StackVisitor::StackVisitor(Thread* thread, |
| 58 | Context* context, |
| 59 | StackWalkKind walk_kind, |
| 60 | bool check_suspended) |
| 61 | : StackVisitor(thread, context, walk_kind, 0, check_suspended) {} |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 62 | |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 63 | StackVisitor::StackVisitor(Thread* thread, |
| 64 | Context* context, |
| 65 | StackWalkKind walk_kind, |
Hiroshi Yamauchi | 02f365f | 2017-02-03 15:06:00 -0800 | [diff] [blame] | 66 | size_t num_frames, |
| 67 | bool check_suspended) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 68 | : thread_(thread), |
| 69 | walk_kind_(walk_kind), |
| 70 | cur_shadow_frame_(nullptr), |
| 71 | cur_quick_frame_(nullptr), |
| 72 | cur_quick_frame_pc_(0), |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 73 | cur_oat_quick_method_header_(nullptr), |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 74 | num_frames_(num_frames), |
| 75 | cur_depth_(0), |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 76 | walk_started_(false), |
David Srbecky | 145a18a | 2019-06-03 14:35:22 +0100 | [diff] [blame] | 77 | cur_inline_info_(nullptr, CodeInfo()), |
| 78 | cur_stack_map_(0, StackMap()), |
Hiroshi Yamauchi | 02f365f | 2017-02-03 15:06:00 -0800 | [diff] [blame] | 79 | context_(context), |
| 80 | check_suspended_(check_suspended) { |
| 81 | if (check_suspended_) { |
| 82 | DCHECK(thread == Thread::Current() || thread->IsSuspended()) << *thread; |
| 83 | } |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 84 | } |
| 85 | |
David Srbecky | 145a18a | 2019-06-03 14:35:22 +0100 | [diff] [blame] | 86 | CodeInfo* StackVisitor::GetCurrentInlineInfo() const { |
| 87 | DCHECK(!(*cur_quick_frame_)->IsNative()); |
| 88 | const OatQuickMethodHeader* header = GetCurrentOatQuickMethodHeader(); |
| 89 | if (cur_inline_info_.first != header) { |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 90 | cur_inline_info_ = std::make_pair(header, CodeInfo::DecodeInlineInfoOnly(header)); |
David Srbecky | 145a18a | 2019-06-03 14:35:22 +0100 | [diff] [blame] | 91 | } |
| 92 | return &cur_inline_info_.second; |
| 93 | } |
| 94 | |
| 95 | StackMap* StackVisitor::GetCurrentStackMap() const { |
| 96 | DCHECK(!(*cur_quick_frame_)->IsNative()); |
| 97 | const OatQuickMethodHeader* header = GetCurrentOatQuickMethodHeader(); |
| 98 | if (cur_stack_map_.first != cur_quick_frame_pc_) { |
| 99 | uint32_t pc = header->NativeQuickPcOffset(cur_quick_frame_pc_); |
| 100 | cur_stack_map_ = std::make_pair(cur_quick_frame_pc_, |
| 101 | GetCurrentInlineInfo()->GetStackMapForNativePcOffset(pc)); |
| 102 | } |
| 103 | return &cur_stack_map_.second; |
| 104 | } |
| 105 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 106 | ArtMethod* StackVisitor::GetMethod() const { |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 107 | if (cur_shadow_frame_ != nullptr) { |
| 108 | return cur_shadow_frame_->GetMethod(); |
| 109 | } else if (cur_quick_frame_ != nullptr) { |
| 110 | if (IsInInlinedFrame()) { |
David Srbecky | 145a18a | 2019-06-03 14:35:22 +0100 | [diff] [blame] | 111 | CodeInfo* code_info = GetCurrentInlineInfo(); |
Mathieu Chartier | 45bf250 | 2016-03-31 11:07:09 -0700 | [diff] [blame] | 112 | DCHECK(walk_kind_ != StackWalkKind::kSkipInlinedFrames); |
David Srbecky | 145a18a | 2019-06-03 14:35:22 +0100 | [diff] [blame] | 113 | return GetResolvedMethod(*GetCurrentQuickFrame(), *code_info, current_inline_frames_); |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 114 | } else { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 115 | return *cur_quick_frame_; |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 116 | } |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 117 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 118 | return nullptr; |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 121 | uint32_t StackVisitor::GetDexPc(bool abort_on_failure) const { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 122 | if (cur_shadow_frame_ != nullptr) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 123 | return cur_shadow_frame_->GetDexPC(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 124 | } else if (cur_quick_frame_ != nullptr) { |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 125 | if (IsInInlinedFrame()) { |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 126 | return current_inline_frames_.back().GetDexPc(); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 127 | } else if (cur_oat_quick_method_header_ == nullptr) { |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 128 | return dex::kDexNoIndex; |
Nicolas Geoffray | 013d1ee | 2019-12-04 16:18:15 +0000 | [diff] [blame] | 129 | } else if ((*GetCurrentQuickFrame())->IsNative()) { |
| 130 | return cur_oat_quick_method_header_->ToDexPc( |
| 131 | GetCurrentQuickFrame(), cur_quick_frame_pc_, abort_on_failure); |
| 132 | } else if (cur_oat_quick_method_header_->IsOptimized()) { |
David Srbecky | 145a18a | 2019-06-03 14:35:22 +0100 | [diff] [blame] | 133 | StackMap* stack_map = GetCurrentStackMap(); |
| 134 | DCHECK(stack_map->IsValid()); |
| 135 | return stack_map->GetDexPc(); |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 136 | } else { |
Nicolas Geoffray | 013d1ee | 2019-12-04 16:18:15 +0000 | [diff] [blame] | 137 | DCHECK(cur_oat_quick_method_header_->IsNterpMethodHeader()); |
| 138 | return NterpGetDexPC(cur_quick_frame_); |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 139 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 140 | } else { |
| 141 | return 0; |
| 142 | } |
| 143 | } |
| 144 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 145 | extern "C" mirror::Object* artQuickGetProxyThisObject(ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 146 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | a836bc9 | 2014-11-25 16:30:53 +0100 | [diff] [blame] | 147 | |
Vladimir Marko | abedfca | 2019-05-23 14:07:47 +0100 | [diff] [blame] | 148 | ObjPtr<mirror::Object> StackVisitor::GetThisObject() const { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 149 | DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 150 | ArtMethod* m = GetMethod(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 151 | if (m->IsStatic()) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 152 | return nullptr; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 153 | } else if (m->IsNative()) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 154 | if (cur_quick_frame_ != nullptr) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 155 | HandleScope* hs = reinterpret_cast<HandleScope*>( |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 156 | reinterpret_cast<char*>(cur_quick_frame_) + sizeof(ArtMethod*)); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 157 | return hs->GetReference(0); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 158 | } else { |
| 159 | return cur_shadow_frame_->GetVRegReference(0); |
| 160 | } |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 161 | } else if (m->IsProxyMethod()) { |
Sebastien Hertz | a836bc9 | 2014-11-25 16:30:53 +0100 | [diff] [blame] | 162 | if (cur_quick_frame_ != nullptr) { |
| 163 | return artQuickGetProxyThisObject(cur_quick_frame_); |
| 164 | } else { |
| 165 | return cur_shadow_frame_->GetVRegReference(0); |
| 166 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 167 | } else { |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 168 | CodeItemDataAccessor accessor(m->DexInstructionData()); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 169 | if (!accessor.HasCodeItem()) { |
Ian Rogers | e0dcd46 | 2014-03-08 15:21:04 -0800 | [diff] [blame] | 170 | UNIMPLEMENTED(ERROR) << "Failed to determine this object of abstract or proxy method: " |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 171 | << ArtMethod::PrettyMethod(m); |
Ian Rogers | e0dcd46 | 2014-03-08 15:21:04 -0800 | [diff] [blame] | 172 | return nullptr; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 173 | } else { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 174 | uint16_t reg = accessor.RegistersSize() - accessor.InsSize(); |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 175 | uint32_t value = 0; |
Nicolas Geoffray | 4cbfadc | 2018-10-10 16:09:43 +0100 | [diff] [blame] | 176 | if (!GetVReg(m, reg, kReferenceVReg, &value)) { |
| 177 | return nullptr; |
| 178 | } |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 179 | return reinterpret_cast<mirror::Object*>(value); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 184 | size_t StackVisitor::GetNativePcOffset() const { |
| 185 | DCHECK(!IsShadowFrame()); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 186 | return GetCurrentOatQuickMethodHeader()->NativeQuickPcOffset(cur_quick_frame_pc_); |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 189 | bool StackVisitor::GetVRegFromDebuggerShadowFrame(uint16_t vreg, |
| 190 | VRegKind kind, |
| 191 | uint32_t* val) const { |
| 192 | size_t frame_id = const_cast<StackVisitor*>(this)->GetFrameId(); |
| 193 | ShadowFrame* shadow_frame = thread_->FindDebuggerShadowFrame(frame_id); |
| 194 | if (shadow_frame != nullptr) { |
| 195 | bool* updated_vreg_flags = thread_->GetUpdatedVRegFlags(frame_id); |
| 196 | DCHECK(updated_vreg_flags != nullptr); |
| 197 | if (updated_vreg_flags[vreg]) { |
| 198 | // Value is set by the debugger. |
| 199 | if (kind == kReferenceVReg) { |
| 200 | *val = static_cast<uint32_t>(reinterpret_cast<uintptr_t>( |
| 201 | shadow_frame->GetVRegReference(vreg))); |
| 202 | } else { |
| 203 | *val = shadow_frame->GetVReg(vreg); |
| 204 | } |
| 205 | return true; |
| 206 | } |
| 207 | } |
| 208 | // No value is set by the debugger. |
| 209 | return false; |
| 210 | } |
| 211 | |
David Srbecky | cffa254 | 2019-07-01 15:31:41 +0100 | [diff] [blame] | 212 | bool StackVisitor::GetVReg(ArtMethod* m, |
| 213 | uint16_t vreg, |
| 214 | VRegKind kind, |
| 215 | uint32_t* val, |
| 216 | std::optional<DexRegisterLocation> location) const { |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 217 | if (cur_quick_frame_ != nullptr) { |
| 218 | DCHECK(context_ != nullptr); // You can't reliably read registers without a context. |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 219 | DCHECK(m == GetMethod()); |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 220 | // Check if there is value set by the debugger. |
| 221 | if (GetVRegFromDebuggerShadowFrame(vreg, kind, val)) { |
| 222 | return true; |
| 223 | } |
Nicolas Geoffray | d7651b1 | 2019-12-18 14:57:30 +0000 | [diff] [blame] | 224 | bool result = false; |
Nicolas Geoffray | 013d1ee | 2019-12-04 16:18:15 +0000 | [diff] [blame] | 225 | if (cur_oat_quick_method_header_->IsNterpMethodHeader()) { |
Nicolas Geoffray | d7651b1 | 2019-12-18 14:57:30 +0000 | [diff] [blame] | 226 | result = true; |
| 227 | *val = (kind == kReferenceVReg) |
| 228 | ? NterpGetVRegReference(cur_quick_frame_, vreg) |
| 229 | : NterpGetVReg(cur_quick_frame_, vreg); |
| 230 | } else { |
| 231 | DCHECK(cur_oat_quick_method_header_->IsOptimized()); |
| 232 | if (location.has_value() && kind != kReferenceVReg) { |
| 233 | uint32_t val2 = *val; |
| 234 | // The caller already known the register location, so we can use the faster overload |
| 235 | // which does not decode the stack maps. |
| 236 | result = GetVRegFromOptimizedCode(location.value(), kind, val); |
| 237 | // Compare to the slower overload. |
| 238 | DCHECK_EQ(result, GetVRegFromOptimizedCode(m, vreg, kind, &val2)); |
| 239 | DCHECK_EQ(*val, val2); |
| 240 | } else { |
| 241 | result = GetVRegFromOptimizedCode(m, vreg, kind, val); |
| 242 | } |
Nicolas Geoffray | 013d1ee | 2019-12-04 16:18:15 +0000 | [diff] [blame] | 243 | } |
Alex Light | b096c91 | 2019-09-25 13:33:06 -0700 | [diff] [blame] | 244 | if (kind == kReferenceVReg) { |
| 245 | // Perform a read barrier in case we are in a different thread and GC is ongoing. |
| 246 | mirror::Object* out = reinterpret_cast<mirror::Object*>(static_cast<uintptr_t>(*val)); |
| 247 | uintptr_t ptr_out = reinterpret_cast<uintptr_t>(GcRoot<mirror::Object>(out).Read()); |
| 248 | DCHECK_LT(ptr_out, std::numeric_limits<uint32_t>::max()); |
| 249 | *val = static_cast<uint32_t>(ptr_out); |
| 250 | } |
Nicolas Geoffray | d7651b1 | 2019-12-18 14:57:30 +0000 | [diff] [blame] | 251 | return result; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 252 | } else { |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 253 | DCHECK(cur_shadow_frame_ != nullptr); |
Sebastien Hertz | 0968744 | 2015-11-17 10:35:39 +0100 | [diff] [blame] | 254 | if (kind == kReferenceVReg) { |
| 255 | *val = static_cast<uint32_t>(reinterpret_cast<uintptr_t>( |
| 256 | cur_shadow_frame_->GetVRegReference(vreg))); |
| 257 | } else { |
| 258 | *val = cur_shadow_frame_->GetVReg(vreg); |
| 259 | } |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 260 | return true; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 264 | bool StackVisitor::GetVRegFromOptimizedCode(ArtMethod* m, uint16_t vreg, VRegKind kind, |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 265 | uint32_t* val) const { |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 266 | DCHECK_EQ(m, GetMethod()); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 267 | // Can't be null or how would we compile its instructions? |
| 268 | DCHECK(m->GetCodeItem() != nullptr) << m->PrettyMethod(); |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 269 | CodeItemDataAccessor accessor(m->DexInstructionData()); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 270 | uint16_t number_of_dex_registers = accessor.RegistersSize(); |
| 271 | DCHECK_LT(vreg, number_of_dex_registers); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 272 | const OatQuickMethodHeader* method_header = GetCurrentOatQuickMethodHeader(); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 273 | CodeInfo code_info(method_header); |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 274 | |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 275 | uint32_t native_pc_offset = method_header->NativeQuickPcOffset(cur_quick_frame_pc_); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 276 | StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset); |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 277 | DCHECK(stack_map.IsValid()); |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 278 | |
| 279 | DexRegisterMap dex_register_map = IsInInlinedFrame() |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 280 | ? code_info.GetInlineDexRegisterMapOf(stack_map, current_inline_frames_.back()) |
David Srbecky | fd89b07 | 2018-06-03 12:00:22 +0100 | [diff] [blame] | 281 | : code_info.GetDexRegisterMapOf(stack_map); |
| 282 | if (dex_register_map.empty()) { |
Nicolas Geoffray | 012fc4e | 2016-01-08 15:58:19 +0000 | [diff] [blame] | 283 | return false; |
| 284 | } |
David Srbecky | fd89b07 | 2018-06-03 12:00:22 +0100 | [diff] [blame] | 285 | DCHECK_EQ(dex_register_map.size(), number_of_dex_registers); |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 286 | DexRegisterLocation::Kind location_kind = dex_register_map[vreg].GetKind(); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 287 | switch (location_kind) { |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 288 | case DexRegisterLocation::Kind::kInStack: { |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 289 | const int32_t offset = dex_register_map[vreg].GetStackOffsetInBytes(); |
Nicolas Geoffray | 4cbfadc | 2018-10-10 16:09:43 +0100 | [diff] [blame] | 290 | BitMemoryRegion stack_mask = code_info.GetStackMaskOf(stack_map); |
| 291 | if (kind == kReferenceVReg && !stack_mask.LoadBit(offset / kFrameSlotSize)) { |
| 292 | return false; |
| 293 | } |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 294 | const uint8_t* addr = reinterpret_cast<const uint8_t*>(cur_quick_frame_) + offset; |
| 295 | *val = *reinterpret_cast<const uint32_t*>(addr); |
| 296 | return true; |
| 297 | } |
Nicolas Geoffray | 4cbfadc | 2018-10-10 16:09:43 +0100 | [diff] [blame] | 298 | case DexRegisterLocation::Kind::kInRegister: { |
| 299 | uint32_t register_mask = code_info.GetRegisterMaskOf(stack_map); |
| 300 | uint32_t reg = dex_register_map[vreg].GetMachineRegister(); |
| 301 | if (kind == kReferenceVReg && !(register_mask & (1 << reg))) { |
| 302 | return false; |
| 303 | } |
| 304 | return GetRegisterIfAccessible(reg, kind, val); |
| 305 | } |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 306 | case DexRegisterLocation::Kind::kInRegisterHigh: |
| 307 | case DexRegisterLocation::Kind::kInFpuRegister: |
| 308 | case DexRegisterLocation::Kind::kInFpuRegisterHigh: { |
Nicolas Geoffray | 4cbfadc | 2018-10-10 16:09:43 +0100 | [diff] [blame] | 309 | if (kind == kReferenceVReg) { |
| 310 | return false; |
| 311 | } |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 312 | uint32_t reg = dex_register_map[vreg].GetMachineRegister(); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 313 | return GetRegisterIfAccessible(reg, kind, val); |
| 314 | } |
Nicolas Geoffray | 4cbfadc | 2018-10-10 16:09:43 +0100 | [diff] [blame] | 315 | case DexRegisterLocation::Kind::kConstant: { |
| 316 | uint32_t result = dex_register_map[vreg].GetConstant(); |
| 317 | if (kind == kReferenceVReg && result != 0) { |
| 318 | return false; |
| 319 | } |
| 320 | *val = result; |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 321 | return true; |
Nicolas Geoffray | 4cbfadc | 2018-10-10 16:09:43 +0100 | [diff] [blame] | 322 | } |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 323 | case DexRegisterLocation::Kind::kNone: |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 324 | return false; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 325 | default: |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 326 | LOG(FATAL) << "Unexpected location kind " << dex_register_map[vreg].GetKind(); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 327 | UNREACHABLE(); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 328 | } |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 329 | } |
| 330 | |
David Srbecky | cffa254 | 2019-07-01 15:31:41 +0100 | [diff] [blame] | 331 | bool StackVisitor::GetVRegFromOptimizedCode(DexRegisterLocation location, |
| 332 | VRegKind kind, |
| 333 | uint32_t* val) const { |
| 334 | switch (location.GetKind()) { |
| 335 | case DexRegisterLocation::Kind::kInvalid: |
| 336 | break; |
| 337 | case DexRegisterLocation::Kind::kInStack: { |
| 338 | const uint8_t* sp = reinterpret_cast<const uint8_t*>(cur_quick_frame_); |
| 339 | *val = *reinterpret_cast<const uint32_t*>(sp + location.GetStackOffsetInBytes()); |
| 340 | return true; |
| 341 | } |
| 342 | case DexRegisterLocation::Kind::kInRegister: |
| 343 | case DexRegisterLocation::Kind::kInRegisterHigh: |
| 344 | case DexRegisterLocation::Kind::kInFpuRegister: |
| 345 | case DexRegisterLocation::Kind::kInFpuRegisterHigh: |
| 346 | return GetRegisterIfAccessible(location.GetMachineRegister(), kind, val); |
| 347 | case DexRegisterLocation::Kind::kConstant: |
| 348 | *val = location.GetConstant(); |
| 349 | return true; |
| 350 | case DexRegisterLocation::Kind::kNone: |
| 351 | return false; |
| 352 | } |
| 353 | LOG(FATAL) << "Unexpected location kind " << location.GetKind(); |
| 354 | UNREACHABLE(); |
| 355 | } |
| 356 | |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 357 | bool StackVisitor::GetRegisterIfAccessible(uint32_t reg, VRegKind kind, uint32_t* val) const { |
| 358 | const bool is_float = (kind == kFloatVReg) || (kind == kDoubleLoVReg) || (kind == kDoubleHiVReg); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 359 | |
Vladimir Marko | 239d6ea | 2016-09-05 10:44:04 +0100 | [diff] [blame] | 360 | if (kRuntimeISA == InstructionSet::kX86 && is_float) { |
| 361 | // X86 float registers are 64-bit and each XMM register is provided as two separate |
| 362 | // 32-bit registers by the context. |
| 363 | reg = (kind == kDoubleHiVReg) ? (2 * reg + 1) : (2 * reg); |
| 364 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 365 | |
Goran Jakovljevic | 986660c | 2015-12-10 11:44:50 +0100 | [diff] [blame] | 366 | // MIPS32 float registers are used as 64-bit (for MIPS32r2 it is pair |
| 367 | // F(2n)-F(2n+1), and for MIPS32r6 it is 64-bit register F(2n)). When |
| 368 | // accessing upper 32-bits from double, reg + 1 should be used. |
| 369 | if ((kRuntimeISA == InstructionSet::kMips) && (kind == kDoubleHiVReg)) { |
| 370 | DCHECK_ALIGNED(reg, 2); |
| 371 | reg++; |
| 372 | } |
| 373 | |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 374 | if (!IsAccessibleRegister(reg, is_float)) { |
| 375 | return false; |
| 376 | } |
| 377 | uintptr_t ptr_val = GetRegister(reg, is_float); |
| 378 | const bool target64 = Is64BitInstructionSet(kRuntimeISA); |
| 379 | if (target64) { |
| 380 | const bool wide_lo = (kind == kLongLoVReg) || (kind == kDoubleLoVReg); |
| 381 | const bool wide_hi = (kind == kLongHiVReg) || (kind == kDoubleHiVReg); |
| 382 | int64_t value_long = static_cast<int64_t>(ptr_val); |
| 383 | if (wide_lo) { |
| 384 | ptr_val = static_cast<uintptr_t>(Low32Bits(value_long)); |
| 385 | } else if (wide_hi) { |
| 386 | ptr_val = static_cast<uintptr_t>(High32Bits(value_long)); |
| 387 | } |
| 388 | } |
| 389 | *val = ptr_val; |
| 390 | return true; |
| 391 | } |
| 392 | |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 393 | bool StackVisitor::GetVRegPairFromDebuggerShadowFrame(uint16_t vreg, |
| 394 | VRegKind kind_lo, |
| 395 | VRegKind kind_hi, |
| 396 | uint64_t* val) const { |
| 397 | uint32_t low_32bits; |
| 398 | uint32_t high_32bits; |
| 399 | bool success = GetVRegFromDebuggerShadowFrame(vreg, kind_lo, &low_32bits); |
| 400 | success &= GetVRegFromDebuggerShadowFrame(vreg + 1, kind_hi, &high_32bits); |
| 401 | if (success) { |
| 402 | *val = (static_cast<uint64_t>(high_32bits) << 32) | static_cast<uint64_t>(low_32bits); |
| 403 | } |
| 404 | return success; |
| 405 | } |
| 406 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 407 | bool StackVisitor::GetVRegPair(ArtMethod* m, uint16_t vreg, VRegKind kind_lo, |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 408 | VRegKind kind_hi, uint64_t* val) const { |
| 409 | if (kind_lo == kLongLoVReg) { |
| 410 | DCHECK_EQ(kind_hi, kLongHiVReg); |
| 411 | } else if (kind_lo == kDoubleLoVReg) { |
| 412 | DCHECK_EQ(kind_hi, kDoubleHiVReg); |
| 413 | } else { |
| 414 | LOG(FATAL) << "Expected long or double: kind_lo=" << kind_lo << ", kind_hi=" << kind_hi; |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 415 | UNREACHABLE(); |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 416 | } |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 417 | // Check if there is value set by the debugger. |
| 418 | if (GetVRegPairFromDebuggerShadowFrame(vreg, kind_lo, kind_hi, val)) { |
| 419 | return true; |
| 420 | } |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 421 | if (cur_quick_frame_ != nullptr) { |
| 422 | DCHECK(context_ != nullptr); // You can't reliably read registers without a context. |
| 423 | DCHECK(m == GetMethod()); |
Vladimir Marko | 9d07e3d | 2016-03-31 12:02:28 +0100 | [diff] [blame] | 424 | DCHECK(cur_oat_quick_method_header_->IsOptimized()); |
| 425 | return GetVRegPairFromOptimizedCode(m, vreg, kind_lo, kind_hi, val); |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 426 | } else { |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 427 | DCHECK(cur_shadow_frame_ != nullptr); |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 428 | *val = cur_shadow_frame_->GetVRegLong(vreg); |
| 429 | return true; |
| 430 | } |
| 431 | } |
| 432 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 433 | bool StackVisitor::GetVRegPairFromOptimizedCode(ArtMethod* m, uint16_t vreg, |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 434 | VRegKind kind_lo, VRegKind kind_hi, |
| 435 | uint64_t* val) const { |
| 436 | uint32_t low_32bits; |
| 437 | uint32_t high_32bits; |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 438 | bool success = GetVRegFromOptimizedCode(m, vreg, kind_lo, &low_32bits); |
| 439 | success &= GetVRegFromOptimizedCode(m, vreg + 1, kind_hi, &high_32bits); |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 440 | if (success) { |
| 441 | *val = (static_cast<uint64_t>(high_32bits) << 32) | static_cast<uint64_t>(low_32bits); |
| 442 | } |
| 443 | return success; |
| 444 | } |
| 445 | |
| 446 | bool StackVisitor::GetRegisterPairIfAccessible(uint32_t reg_lo, uint32_t reg_hi, |
| 447 | VRegKind kind_lo, uint64_t* val) const { |
| 448 | const bool is_float = (kind_lo == kDoubleLoVReg); |
| 449 | if (!IsAccessibleRegister(reg_lo, is_float) || !IsAccessibleRegister(reg_hi, is_float)) { |
| 450 | return false; |
| 451 | } |
| 452 | uintptr_t ptr_val_lo = GetRegister(reg_lo, is_float); |
| 453 | uintptr_t ptr_val_hi = GetRegister(reg_hi, is_float); |
| 454 | bool target64 = Is64BitInstructionSet(kRuntimeISA); |
| 455 | if (target64) { |
| 456 | int64_t value_long_lo = static_cast<int64_t>(ptr_val_lo); |
| 457 | int64_t value_long_hi = static_cast<int64_t>(ptr_val_hi); |
| 458 | ptr_val_lo = static_cast<uintptr_t>(Low32Bits(value_long_lo)); |
| 459 | ptr_val_hi = static_cast<uintptr_t>(High32Bits(value_long_hi)); |
| 460 | } |
| 461 | *val = (static_cast<uint64_t>(ptr_val_hi) << 32) | static_cast<uint32_t>(ptr_val_lo); |
| 462 | return true; |
| 463 | } |
| 464 | |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 465 | ShadowFrame* StackVisitor::PrepareSetVReg(ArtMethod* m, uint16_t vreg, bool wide) { |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 466 | CodeItemDataAccessor accessor(m->DexInstructionData()); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 467 | if (!accessor.HasCodeItem()) { |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 468 | return nullptr; |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 469 | } |
| 470 | ShadowFrame* shadow_frame = GetCurrentShadowFrame(); |
| 471 | if (shadow_frame == nullptr) { |
| 472 | // This is a compiled frame: we must prepare and update a shadow frame that will |
| 473 | // be executed by the interpreter after deoptimization of the stack. |
| 474 | const size_t frame_id = GetFrameId(); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 475 | const uint16_t num_regs = accessor.RegistersSize(); |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 476 | shadow_frame = thread_->FindOrCreateDebuggerShadowFrame(frame_id, num_regs, m, GetDexPc()); |
| 477 | CHECK(shadow_frame != nullptr); |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 478 | // Remember the vreg(s) has been set for debugging and must not be overwritten by the |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 479 | // original value during deoptimization of the stack. |
| 480 | thread_->GetUpdatedVRegFlags(frame_id)[vreg] = true; |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 481 | if (wide) { |
| 482 | thread_->GetUpdatedVRegFlags(frame_id)[vreg + 1] = true; |
| 483 | } |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 484 | } |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 485 | return shadow_frame; |
| 486 | } |
| 487 | |
| 488 | bool StackVisitor::SetVReg(ArtMethod* m, uint16_t vreg, uint32_t new_value, VRegKind kind) { |
| 489 | DCHECK(kind == kIntVReg || kind == kFloatVReg); |
| 490 | ShadowFrame* shadow_frame = PrepareSetVReg(m, vreg, /* wide= */ false); |
| 491 | if (shadow_frame == nullptr) { |
| 492 | return false; |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 493 | } |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 494 | shadow_frame->SetVReg(vreg, new_value); |
| 495 | return true; |
| 496 | } |
| 497 | |
| 498 | bool StackVisitor::SetVRegReference(ArtMethod* m, uint16_t vreg, ObjPtr<mirror::Object> new_value) { |
| 499 | ShadowFrame* shadow_frame = PrepareSetVReg(m, vreg, /* wide= */ false); |
| 500 | if (shadow_frame == nullptr) { |
| 501 | return false; |
| 502 | } |
| 503 | shadow_frame->SetVRegReference(vreg, new_value); |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 504 | return true; |
| 505 | } |
| 506 | |
Mingyao Yang | 636b925 | 2015-07-31 16:40:24 -0700 | [diff] [blame] | 507 | bool StackVisitor::SetVRegPair(ArtMethod* m, |
| 508 | uint16_t vreg, |
| 509 | uint64_t new_value, |
| 510 | VRegKind kind_lo, |
| 511 | VRegKind kind_hi) { |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 512 | if (kind_lo == kLongLoVReg) { |
| 513 | DCHECK_EQ(kind_hi, kLongHiVReg); |
| 514 | } else if (kind_lo == kDoubleLoVReg) { |
| 515 | DCHECK_EQ(kind_hi, kDoubleHiVReg); |
| 516 | } else { |
| 517 | LOG(FATAL) << "Expected long or double: kind_lo=" << kind_lo << ", kind_hi=" << kind_hi; |
| 518 | UNREACHABLE(); |
| 519 | } |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 520 | ShadowFrame* shadow_frame = PrepareSetVReg(m, vreg, /* wide= */ true); |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 521 | if (shadow_frame == nullptr) { |
Vladimir Marko | 439d126 | 2019-04-12 14:45:07 +0100 | [diff] [blame] | 522 | return false; |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 523 | } |
| 524 | shadow_frame->SetVRegLong(vreg, new_value); |
| 525 | return true; |
| 526 | } |
| 527 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 528 | bool StackVisitor::IsAccessibleGPR(uint32_t reg) const { |
| 529 | DCHECK(context_ != nullptr); |
| 530 | return context_->IsAccessibleGPR(reg); |
| 531 | } |
| 532 | |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 533 | uintptr_t* StackVisitor::GetGPRAddress(uint32_t reg) const { |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 534 | DCHECK(cur_quick_frame_ != nullptr) << "This is a quick frame routine"; |
| 535 | DCHECK(context_ != nullptr); |
Mathieu Chartier | 815873e | 2014-02-13 18:02:13 -0800 | [diff] [blame] | 536 | return context_->GetGPRAddress(reg); |
| 537 | } |
| 538 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 539 | uintptr_t StackVisitor::GetGPR(uint32_t reg) const { |
| 540 | DCHECK(cur_quick_frame_ != nullptr) << "This is a quick frame routine"; |
| 541 | DCHECK(context_ != nullptr); |
| 542 | return context_->GetGPR(reg); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 545 | bool StackVisitor::IsAccessibleFPR(uint32_t reg) const { |
| 546 | DCHECK(context_ != nullptr); |
| 547 | return context_->IsAccessibleFPR(reg); |
Sebastien Hertz | 0bcb290 | 2014-06-17 15:52:45 +0200 | [diff] [blame] | 548 | } |
| 549 | |
Sebastien Hertz | 96ba8dc | 2015-01-22 18:57:14 +0100 | [diff] [blame] | 550 | uintptr_t StackVisitor::GetFPR(uint32_t reg) const { |
| 551 | DCHECK(cur_quick_frame_ != nullptr) << "This is a quick frame routine"; |
| 552 | DCHECK(context_ != nullptr); |
| 553 | return context_->GetFPR(reg); |
| 554 | } |
| 555 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 556 | uintptr_t StackVisitor::GetReturnPc() const { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 557 | uint8_t* sp = reinterpret_cast<uint8_t*>(GetCurrentQuickFrame()); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 558 | DCHECK(sp != nullptr); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 559 | uint8_t* pc_addr = sp + GetCurrentQuickFrameInfo().GetReturnPcOffset(); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 560 | return *reinterpret_cast<uintptr_t*>(pc_addr); |
| 561 | } |
| 562 | |
| 563 | void StackVisitor::SetReturnPc(uintptr_t new_ret_pc) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 564 | uint8_t* sp = reinterpret_cast<uint8_t*>(GetCurrentQuickFrame()); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 565 | CHECK(sp != nullptr); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 566 | uint8_t* pc_addr = sp + GetCurrentQuickFrameInfo().GetReturnPcOffset(); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 567 | *reinterpret_cast<uintptr_t*>(pc_addr) = new_ret_pc; |
| 568 | } |
| 569 | |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 570 | size_t StackVisitor::ComputeNumFrames(Thread* thread, StackWalkKind walk_kind) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 571 | struct NumFramesVisitor : public StackVisitor { |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 572 | NumFramesVisitor(Thread* thread_in, StackWalkKind walk_kind_in) |
| 573 | : StackVisitor(thread_in, nullptr, walk_kind_in), frames(0) {} |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 574 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 575 | bool VisitFrame() override { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 576 | frames++; |
| 577 | return true; |
| 578 | } |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 579 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 580 | size_t frames; |
| 581 | }; |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 582 | NumFramesVisitor visitor(thread, walk_kind); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 583 | visitor.WalkStack(true); |
| 584 | return visitor.frames; |
| 585 | } |
| 586 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 587 | bool StackVisitor::GetNextMethodAndDexPc(ArtMethod** next_method, uint32_t* next_dex_pc) { |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 588 | struct HasMoreFramesVisitor : public StackVisitor { |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 589 | HasMoreFramesVisitor(Thread* thread, |
| 590 | StackWalkKind walk_kind, |
| 591 | size_t num_frames, |
| 592 | size_t frame_height) |
| 593 | : StackVisitor(thread, nullptr, walk_kind, num_frames), |
| 594 | frame_height_(frame_height), |
| 595 | found_frame_(false), |
| 596 | has_more_frames_(false), |
| 597 | next_method_(nullptr), |
| 598 | next_dex_pc_(0) { |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 601 | bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 602 | if (found_frame_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 603 | ArtMethod* method = GetMethod(); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 604 | if (method != nullptr && !method->IsRuntimeMethod()) { |
| 605 | has_more_frames_ = true; |
| 606 | next_method_ = method; |
| 607 | next_dex_pc_ = GetDexPc(); |
| 608 | return false; // End stack walk once next method is found. |
| 609 | } |
| 610 | } else if (GetFrameHeight() == frame_height_) { |
| 611 | found_frame_ = true; |
| 612 | } |
| 613 | return true; |
| 614 | } |
| 615 | |
| 616 | size_t frame_height_; |
| 617 | bool found_frame_; |
| 618 | bool has_more_frames_; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 619 | ArtMethod* next_method_; |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 620 | uint32_t next_dex_pc_; |
| 621 | }; |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 622 | HasMoreFramesVisitor visitor(thread_, walk_kind_, GetNumFrames(), GetFrameHeight()); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 623 | visitor.WalkStack(true); |
| 624 | *next_method = visitor.next_method_; |
| 625 | *next_dex_pc = visitor.next_dex_pc_; |
| 626 | return visitor.has_more_frames_; |
| 627 | } |
| 628 | |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 629 | void StackVisitor::DescribeStack(Thread* thread) { |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 630 | struct DescribeStackVisitor : public StackVisitor { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 631 | explicit DescribeStackVisitor(Thread* thread_in) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 632 | : StackVisitor(thread_in, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {} |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 633 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 634 | bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 635 | LOG(INFO) << "Frame Id=" << GetFrameId() << " " << DescribeLocation(); |
| 636 | return true; |
| 637 | } |
| 638 | }; |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 639 | DescribeStackVisitor visitor(thread); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 640 | visitor.WalkStack(true); |
| 641 | } |
| 642 | |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 643 | std::string StackVisitor::DescribeLocation() const { |
| 644 | std::string result("Visiting method '"); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 645 | ArtMethod* m = GetMethod(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 646 | if (m == nullptr) { |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 647 | return "upcall"; |
| 648 | } |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 649 | result += m->PrettyMethod(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 650 | result += StringPrintf("' at dex PC 0x%04x", GetDexPc()); |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 651 | if (!IsShadowFrame()) { |
| 652 | result += StringPrintf(" (native PC %p)", reinterpret_cast<void*>(GetCurrentQuickFramePc())); |
| 653 | } |
| 654 | return result; |
| 655 | } |
| 656 | |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 657 | void StackVisitor::SetMethod(ArtMethod* method) { |
| 658 | DCHECK(GetMethod() != nullptr); |
| 659 | if (cur_shadow_frame_ != nullptr) { |
| 660 | cur_shadow_frame_->SetMethod(method); |
| 661 | } else { |
| 662 | DCHECK(cur_quick_frame_ != nullptr); |
Nicolas Geoffray | 226805d | 2018-12-14 10:59:02 +0000 | [diff] [blame] | 663 | CHECK(!IsInInlinedFrame()) << "We do not support setting inlined method's ArtMethod: " |
| 664 | << GetMethod()->PrettyMethod() << " is inlined into " |
| 665 | << GetOuterMethod()->PrettyMethod(); |
Alex Light | 1ebe4fe | 2017-01-30 14:57:11 -0800 | [diff] [blame] | 666 | *cur_quick_frame_ = method; |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 670 | static void AssertPcIsWithinQuickCode(ArtMethod* method, uintptr_t pc) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 671 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 672 | if (method->IsNative() || method->IsRuntimeMethod() || method->IsProxyMethod()) { |
| 673 | return; |
| 674 | } |
| 675 | |
| 676 | if (pc == reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc())) { |
| 677 | return; |
| 678 | } |
| 679 | |
Mingyao Yang | 88ca8ba | 2017-05-23 14:21:07 -0700 | [diff] [blame] | 680 | Runtime* runtime = Runtime::Current(); |
| 681 | if (runtime->UseJitCompilation() && |
| 682 | runtime->GetJit()->GetCodeCache()->ContainsPc(reinterpret_cast<const void*>(pc))) { |
| 683 | return; |
| 684 | } |
| 685 | |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 686 | const void* code = method->GetEntryPointFromQuickCompiledCode(); |
Alex Light | db01a09 | 2017-04-03 15:39:55 -0700 | [diff] [blame] | 687 | if (code == GetQuickInstrumentationEntryPoint() || code == GetInvokeObsoleteMethodStub()) { |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 688 | return; |
| 689 | } |
| 690 | |
| 691 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 692 | if (class_linker->IsQuickToInterpreterBridge(code) || |
| 693 | class_linker->IsQuickResolutionStub(code)) { |
| 694 | return; |
| 695 | } |
| 696 | |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 697 | if (runtime->UseJitCompilation() && runtime->GetJit()->GetCodeCache()->ContainsPc(code)) { |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 698 | return; |
| 699 | } |
| 700 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 701 | uint32_t code_size = OatQuickMethodHeader::FromEntryPoint(code)->GetCodeSize(); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 702 | uintptr_t code_start = reinterpret_cast<uintptr_t>(code); |
| 703 | CHECK(code_start <= pc && pc <= (code_start + code_size)) |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 704 | << method->PrettyMethod() |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 705 | << " pc=" << std::hex << pc |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 706 | << " code_start=" << code_start |
| 707 | << " code_size=" << code_size; |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 708 | } |
| 709 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 710 | void StackVisitor::SanityCheckFrame() const { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 711 | if (kIsDebugBuild) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 712 | ArtMethod* method = GetMethod(); |
Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 713 | ObjPtr<mirror::Class> declaring_class = method->GetDeclaringClass(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 714 | // Runtime methods have null declaring class. |
| 715 | if (!method->IsRuntimeMethod()) { |
| 716 | CHECK(declaring_class != nullptr); |
| 717 | CHECK_EQ(declaring_class->GetClass(), declaring_class->GetClass()->GetClass()) |
| 718 | << declaring_class; |
| 719 | } else { |
| 720 | CHECK(declaring_class == nullptr); |
| 721 | } |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 722 | Runtime* const runtime = Runtime::Current(); |
| 723 | LinearAlloc* const linear_alloc = runtime->GetLinearAlloc(); |
| 724 | if (!linear_alloc->Contains(method)) { |
| 725 | // Check class linker linear allocs. |
Nicolas Geoffray | 48b40cc | 2017-08-07 16:52:40 +0100 | [diff] [blame] | 726 | // We get the canonical method as copied methods may have their declaring |
| 727 | // class from another class loader. |
Ulya Trafimovich | 819b362 | 2019-12-12 17:59:10 +0000 | [diff] [blame] | 728 | const PointerSize ptrSize = runtime->GetClassLinker()->GetImagePointerSize(); |
| 729 | ArtMethod* canonical = method->GetCanonicalMethod(ptrSize); |
Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 730 | ObjPtr<mirror::Class> klass = canonical->GetDeclaringClass(); |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 731 | LinearAlloc* const class_linear_alloc = (klass != nullptr) |
Mathieu Chartier | 5b83050 | 2016-03-02 10:30:23 -0800 | [diff] [blame] | 732 | ? runtime->GetClassLinker()->GetAllocatorForClassLoader(klass->GetClassLoader()) |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 733 | : linear_alloc; |
Nicolas Geoffray | 48b40cc | 2017-08-07 16:52:40 +0100 | [diff] [blame] | 734 | if (!class_linear_alloc->Contains(canonical)) { |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 735 | // Check image space. |
| 736 | bool in_image = false; |
| 737 | for (auto& space : runtime->GetHeap()->GetContinuousSpaces()) { |
| 738 | if (space->IsImageSpace()) { |
| 739 | auto* image_space = space->AsImageSpace(); |
| 740 | const auto& header = image_space->GetImageHeader(); |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 741 | const ImageSection& methods = header.GetMethodsSection(); |
| 742 | const ImageSection& runtime_methods = header.GetRuntimeMethodsSection(); |
Nicolas Geoffray | 48b40cc | 2017-08-07 16:52:40 +0100 | [diff] [blame] | 743 | const size_t offset = reinterpret_cast<const uint8_t*>(canonical) - image_space->Begin(); |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 744 | if (methods.Contains(offset) || runtime_methods.Contains(offset)) { |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 745 | in_image = true; |
| 746 | break; |
| 747 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 748 | } |
| 749 | } |
Nicolas Geoffray | 48b40cc | 2017-08-07 16:52:40 +0100 | [diff] [blame] | 750 | CHECK(in_image) << canonical->PrettyMethod() << " not in linear alloc or image"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 751 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 752 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 753 | if (cur_quick_frame_ != nullptr) { |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 754 | AssertPcIsWithinQuickCode(method, cur_quick_frame_pc_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 755 | // Frame sanity. |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 756 | size_t frame_size = GetCurrentQuickFrameInfo().FrameSizeInBytes(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 757 | CHECK_NE(frame_size, 0u); |
Nicolas Geoffray | 0039182 | 2019-12-10 10:17:23 +0000 | [diff] [blame] | 758 | // For compiled code, we could try to have a rough guess at an upper size we expect |
| 759 | // to see for a frame: |
Andreas Gampe | 5b417b9 | 2014-03-10 14:18:35 -0700 | [diff] [blame] | 760 | // 256 registers |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 761 | // 2 words HandleScope overhead |
Andreas Gampe | 5b417b9 | 2014-03-10 14:18:35 -0700 | [diff] [blame] | 762 | // 3+3 register spills |
Brian Carlstrom | ed08bd4 | 2014-03-19 18:34:17 -0700 | [diff] [blame] | 763 | // const size_t kMaxExpectedFrameSize = (256 + 2 + 3 + 3) * sizeof(word); |
Nicolas Geoffray | 0039182 | 2019-12-10 10:17:23 +0000 | [diff] [blame] | 764 | const size_t kMaxExpectedFrameSize = interpreter::kMaxNterpFrame; |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 765 | CHECK_LE(frame_size, kMaxExpectedFrameSize) << method->PrettyMethod(); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 766 | size_t return_pc_offset = GetCurrentQuickFrameInfo().GetReturnPcOffset(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 767 | CHECK_LT(return_pc_offset, frame_size); |
| 768 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 769 | } |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 770 | } |
| 771 | |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 772 | // Counts the number of references in the parameter list of the corresponding method. |
| 773 | // Note: Thus does _not_ include "this" for non-static methods. |
| 774 | static uint32_t GetNumberOfReferenceArgsWithoutReceiver(ArtMethod* method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 775 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 776 | uint32_t shorty_len; |
| 777 | const char* shorty = method->GetShorty(&shorty_len); |
| 778 | uint32_t refs = 0; |
| 779 | for (uint32_t i = 1; i < shorty_len ; ++i) { |
| 780 | if (shorty[i] == 'L') { |
| 781 | refs++; |
| 782 | } |
| 783 | } |
| 784 | return refs; |
| 785 | } |
| 786 | |
| 787 | QuickMethodFrameInfo StackVisitor::GetCurrentQuickFrameInfo() const { |
| 788 | if (cur_oat_quick_method_header_ != nullptr) { |
Nicolas Geoffray | 013d1ee | 2019-12-04 16:18:15 +0000 | [diff] [blame] | 789 | if (cur_oat_quick_method_header_->IsOptimized()) { |
| 790 | return cur_oat_quick_method_header_->GetFrameInfo(); |
| 791 | } else { |
| 792 | DCHECK(cur_oat_quick_method_header_->IsNterpMethodHeader()); |
| 793 | return NterpFrameInfo(cur_quick_frame_); |
| 794 | } |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | ArtMethod* method = GetMethod(); |
| 798 | Runtime* runtime = Runtime::Current(); |
| 799 | |
| 800 | if (method->IsAbstract()) { |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 801 | return RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveRefsAndArgs); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | // This goes before IsProxyMethod since runtime methods have a null declaring class. |
| 805 | if (method->IsRuntimeMethod()) { |
| 806 | return runtime->GetRuntimeMethodFrameInfo(method); |
| 807 | } |
| 808 | |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 809 | if (method->IsProxyMethod()) { |
Nicolas Geoffray | 22cf3d3 | 2015-11-02 11:57:11 +0000 | [diff] [blame] | 810 | // There is only one direct method of a proxy class: the constructor. A direct method is |
| 811 | // cloned from the original java.lang.reflect.Proxy and is executed as usual quick |
| 812 | // compiled method without any stubs. Therefore the method must have a OatQuickMethodHeader. |
| 813 | DCHECK(!method->IsDirect() && !method->IsConstructor()) |
| 814 | << "Constructors of proxy classes must have a OatQuickMethodHeader"; |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 815 | return RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveRefsAndArgs); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 816 | } |
| 817 | |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 818 | // The only remaining case is if the method is native and uses the generic JNI stub, |
| 819 | // called either directly or through some (resolution, instrumentation) trampoline. |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 820 | DCHECK(method->IsNative()); |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 821 | if (kIsDebugBuild) { |
| 822 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 823 | const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(method, |
| 824 | kRuntimePointerSize); |
| 825 | CHECK(class_linker->IsQuickGenericJniStub(entry_point) || |
| 826 | // The current entrypoint (after filtering out trampolines) may have changed |
| 827 | // from GenericJNI to JIT-compiled stub since we have entered this frame. |
| 828 | (runtime->GetJit() != nullptr && |
| 829 | runtime->GetJit()->GetCodeCache()->ContainsPc(entry_point))) << method->PrettyMethod(); |
| 830 | } |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 831 | // Generic JNI frame. |
| 832 | uint32_t handle_refs = GetNumberOfReferenceArgsWithoutReceiver(method) + 1; |
| 833 | size_t scope_size = HandleScope::SizeOf(handle_refs); |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 834 | constexpr QuickMethodFrameInfo callee_info = |
| 835 | RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveRefsAndArgs); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 836 | |
| 837 | // Callee saves + handle scope + method ref + alignment |
| 838 | // Note: -sizeof(void*) since callee-save frame stores a whole method pointer. |
| 839 | size_t frame_size = RoundUp( |
| 840 | callee_info.FrameSizeInBytes() - sizeof(void*) + sizeof(ArtMethod*) + scope_size, |
| 841 | kStackAlignment); |
| 842 | return QuickMethodFrameInfo(frame_size, callee_info.CoreSpillMask(), callee_info.FpSpillMask()); |
| 843 | } |
| 844 | |
Andreas Gampe | 585da95 | 2016-12-02 14:52:29 -0800 | [diff] [blame] | 845 | template <StackVisitor::CountTransitions kCount> |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 846 | void StackVisitor::WalkStack(bool include_transitions) { |
Hiroshi Yamauchi | 02f365f | 2017-02-03 15:06:00 -0800 | [diff] [blame] | 847 | if (check_suspended_) { |
| 848 | DCHECK(thread_ == Thread::Current() || thread_->IsSuspended()); |
| 849 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 850 | CHECK_EQ(cur_depth_, 0U); |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 851 | CHECK(!walk_started_); |
| 852 | walk_started_ = true; |
| 853 | bool retry = false; |
| 854 | size_t depth; |
| 855 | bool skip_to_depth = false; |
| 856 | uint64_t current_sequence_number; |
| 857 | Thread* self = Thread::Current(); |
| 858 | // If the instrumentation stack changes due to DeoptimizeThreadStack or similar while we are |
| 859 | // running this stack-walk we need to restart and try again. |
| 860 | // |
| 861 | // This is because when we perform DeoptimizeThreadStack we replace the return-pc of the threads |
| 862 | // stack-frames with a trampoline, the actual return-address is placed in the threads |
| 863 | // InstrumentationStack. The instrumentation code will fill up this stack as it goes. Since there |
| 864 | // is no good way to map instrumentation stack frames to real ones (or vice versa) and we need to |
| 865 | // know which instrumentation stack frame we are on in order to find the real return-pc using that |
| 866 | // the next stack-frame's size we instead simply keep track of how many instrumentation frames we |
| 867 | // have used (as instrumentation_stack_depth). Each time we need a new instrumentation frame we |
| 868 | // simply increment this value. This works well enough but if InstrumentationInstallStack is |
| 869 | // called concurrently the InstrumentationStack might have frames inserted prior to the point this |
| 870 | // StackVisitor is currently at. This would cause the visitor to get the incorrect |
| 871 | // instrumentation_frame and start incorrectly walking the stack. |
| 872 | // |
| 873 | // To prevent this we keep track of when the last update that changes the indexs of |
| 874 | // instrumentation frames occurs and restart the stack walk if that changes. To simplify the |
| 875 | // process of building stack walkers we also keep track of how many times we have called |
| 876 | // VisitFrame and skip that many calls. This prevents any frames from being visited more than once |
| 877 | // per 'WalkStack' call. |
| 878 | do { |
| 879 | retry = false; |
| 880 | depth = 0; |
| 881 | // Keep track of how far in the stack-walk we are, making sure to also keep track of whether |
| 882 | // we've skipped enough to resume calling 'VisitFrame' after a retry. |
| 883 | auto increment_depth = [&]() { |
| 884 | DCHECK_LE(depth, cur_depth_); |
| 885 | ++depth; |
| 886 | if (skip_to_depth && depth == cur_depth_) { |
| 887 | skip_to_depth = false; |
| 888 | } else if (!skip_to_depth) { |
| 889 | ++cur_depth_; |
| 890 | } |
| 891 | }; |
| 892 | // Wait for any current instrumentation installs to finish, Skip this if we are aborting. |
| 893 | if (LIKELY(gAborting == 0)) { |
| 894 | MutexLock mu(self, *GetThread()->GetInstrumentationInstallMutex()); |
| 895 | } |
| 896 | // Get Current install state id. |
| 897 | { |
| 898 | MutexLock mu(self, *GetThread()->GetInstrumentationInstallSequenceNumberMutex()); |
| 899 | current_sequence_number = GetThread()->GetInstrumentationInstallSequenceNumber(); |
| 900 | } |
| 901 | bool exit_stubs_installed = Runtime::Current()->GetInstrumentation()->AreExitStubsInstalled(); |
| 902 | uint32_t instrumentation_stack_depth = 0; |
| 903 | size_t inlined_frames_count = 0; |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 904 | |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 905 | for (const ManagedStack* current_fragment = thread_->GetManagedStack(); |
| 906 | current_fragment != nullptr; |
| 907 | current_fragment = current_fragment->GetLink()) { |
| 908 | cur_shadow_frame_ = current_fragment->GetTopShadowFrame(); |
| 909 | cur_quick_frame_ = current_fragment->GetTopQuickFrame(); |
| 910 | cur_quick_frame_pc_ = 0; |
| 911 | cur_oat_quick_method_header_ = nullptr; |
| 912 | if (cur_quick_frame_ != nullptr) { // Handle quick stack frames. |
| 913 | // Can't be both a shadow and a quick fragment. |
| 914 | DCHECK(current_fragment->GetTopShadowFrame() == nullptr); |
| 915 | ArtMethod* method = *cur_quick_frame_; |
| 916 | DCHECK(method != nullptr); |
| 917 | bool header_retrieved = false; |
| 918 | if (method->IsNative()) { |
| 919 | // We do not have a PC for the first frame, so we cannot simply use |
| 920 | // ArtMethod::GetOatQuickMethodHeader() as we're unable to distinguish there |
| 921 | // between GenericJNI frame and JIT-compiled JNI stub; the entrypoint may have |
| 922 | // changed since the frame was entered. The top quick frame tag indicates |
| 923 | // GenericJNI here, otherwise it's either AOT-compiled or JNI-compiled JNI stub. |
| 924 | if (UNLIKELY(current_fragment->GetTopQuickFrameTag())) { |
| 925 | // The generic JNI does not have any method header. |
| 926 | cur_oat_quick_method_header_ = nullptr; |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 927 | } else { |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 928 | const void* existing_entry_point = method->GetEntryPointFromQuickCompiledCode(); |
| 929 | CHECK(existing_entry_point != nullptr); |
| 930 | Runtime* runtime = Runtime::Current(); |
| 931 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 932 | // Check whether we can quickly get the header from the current entrypoint. |
| 933 | if (!class_linker->IsQuickGenericJniStub(existing_entry_point) && |
| 934 | !class_linker->IsQuickResolutionStub(existing_entry_point) && |
| 935 | existing_entry_point != GetQuickInstrumentationEntryPoint()) { |
| 936 | cur_oat_quick_method_header_ = |
| 937 | OatQuickMethodHeader::FromEntryPoint(existing_entry_point); |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 938 | } else { |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 939 | const void* code = method->GetOatMethodQuickCode(class_linker->GetImagePointerSize()); |
| 940 | if (code != nullptr) { |
| 941 | cur_oat_quick_method_header_ = OatQuickMethodHeader::FromEntryPoint(code); |
| 942 | } else { |
| 943 | // This must be a JITted JNI stub frame. |
| 944 | CHECK(runtime->GetJit() != nullptr); |
| 945 | code = runtime->GetJit()->GetCodeCache()->GetJniStubCode(method); |
| 946 | CHECK(code != nullptr) << method->PrettyMethod(); |
| 947 | cur_oat_quick_method_header_ = OatQuickMethodHeader::FromCodePointer(code); |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | } |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 951 | header_retrieved = true; |
Nicolas Geoffray | 57f6161 | 2015-05-15 13:20:41 +0100 | [diff] [blame] | 952 | } |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 953 | while (method != nullptr) { |
| 954 | if (!header_retrieved) { |
| 955 | cur_oat_quick_method_header_ = method->GetOatQuickMethodHeader(cur_quick_frame_pc_); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 956 | } |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 957 | header_retrieved = false; // Force header retrieval in next iteration. |
| 958 | SanityCheckFrame(); |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame] | 959 | |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 960 | if ((walk_kind_ == StackWalkKind::kIncludeInlinedFrames) && |
| 961 | (cur_oat_quick_method_header_ != nullptr) && |
| 962 | cur_oat_quick_method_header_->IsOptimized() && |
| 963 | !method->IsNative() // JNI methods cannot have any inlined frames. |
| 964 | && CodeInfo::HasInlineInfo(cur_oat_quick_method_header_->GetOptimizedCodeInfoPtr())) { |
| 965 | DCHECK_NE(cur_quick_frame_pc_, 0u); |
| 966 | CodeInfo* code_info = GetCurrentInlineInfo(); |
| 967 | StackMap* stack_map = GetCurrentStackMap(); |
| 968 | if (stack_map->IsValid() && stack_map->HasInlineInfo()) { |
| 969 | DCHECK_EQ(current_inline_frames_.size(), 0u); |
| 970 | for (current_inline_frames_ = code_info->GetInlineInfosOf(*stack_map); |
| 971 | !current_inline_frames_.empty(); |
| 972 | current_inline_frames_.pop_back()) { |
| 973 | if (!skip_to_depth) { |
| 974 | bool should_continue = VisitFrame(); |
| 975 | if (UNLIKELY(!should_continue)) { |
| 976 | return; |
| 977 | } |
| 978 | } |
| 979 | increment_depth(); |
| 980 | inlined_frames_count++; |
| 981 | } |
| 982 | } |
| 983 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 984 | |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 985 | if (!skip_to_depth) { |
| 986 | bool should_continue = VisitFrame(); |
| 987 | if (UNLIKELY(!should_continue)) { |
| 988 | return; |
| 989 | } |
| 990 | } |
| 991 | if (kCount == CountTransitions::kYes || !method->IsRuntimeMethod()) { |
| 992 | increment_depth(); |
| 993 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 994 | |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 995 | // NB This uses cur_oat_quick_frame_info_ (and hence cur_quick_frame_pc_ & the previous |
| 996 | // return_pc_) to determine the frame information. |
| 997 | QuickMethodFrameInfo frame_info = GetCurrentQuickFrameInfo(); |
| 998 | if (context_ != nullptr) { |
| 999 | context_->FillCalleeSaves(reinterpret_cast<uint8_t*>(cur_quick_frame_), frame_info); |
| 1000 | } |
| 1001 | // Compute PC for next stack frame from return PC. |
| 1002 | size_t frame_size = frame_info.FrameSizeInBytes(); |
| 1003 | size_t return_pc_offset = frame_size - sizeof(void*); |
| 1004 | uint8_t* return_pc_addr = reinterpret_cast<uint8_t*>(cur_quick_frame_) + return_pc_offset; |
| 1005 | uintptr_t return_pc = *reinterpret_cast<uintptr_t*>(return_pc_addr); |
| 1006 | |
| 1007 | if (UNLIKELY(exit_stubs_installed || |
| 1008 | reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()) == return_pc)) { |
| 1009 | // While profiling, the return pc is restored from the side stack, except when walking |
| 1010 | // the stack for an exception where the side stack will be unwound in VisitFrame. |
| 1011 | if (reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()) == return_pc) { |
| 1012 | MutexLock mu(self, *GetThread()->GetInstrumentationInstallSequenceNumberMutex()); |
| 1013 | // Instrument-install walks will change the instrumentation-stack but only put things |
| 1014 | // at the end, so we can continue regardless. We hold the InstrumentationInstallMutex |
| 1015 | // so we know nothing can mess up the stack. |
| 1016 | if (!IsStackInstrumentWalk() && |
| 1017 | GetThread()->GetInstrumentationInstallSequenceNumber() != |
| 1018 | current_sequence_number) { |
| 1019 | if (kDebugStackWalk) { |
| 1020 | LOG(INFO) << "Retrying walk from begining due to instrumentation change. " |
| 1021 | << "Skipping to depth " << cur_depth_; |
| 1022 | } |
| 1023 | skip_to_depth = true; |
| 1024 | retry = true; |
| 1025 | // Annoyingly c++ doesn't have a labled continue. If they respected RAII this would |
| 1026 | // be a good time to use goto but as is we'll just break twice. |
| 1027 | break; // From while (method != nullptr) |
| 1028 | } else if (kIsDebugBuild && IsStackInstrumentWalk()) { |
| 1029 | GetThread()->GetInstrumentationInstallMutex()->AssertExclusiveHeld(self); |
| 1030 | } |
| 1031 | CHECK_LT(instrumentation_stack_depth, thread_->GetInstrumentationStack()->size()); |
| 1032 | const instrumentation::InstrumentationStackFrame& instrumentation_frame = |
| 1033 | (*thread_->GetInstrumentationStack())[instrumentation_stack_depth]; |
| 1034 | instrumentation_stack_depth++; |
| 1035 | if (GetMethod() == |
| 1036 | Runtime::Current()->GetCalleeSaveMethod(CalleeSaveType::kSaveAllCalleeSaves)) { |
| 1037 | // Skip runtime save all callee frames which are used to deliver exceptions. |
| 1038 | } else if (instrumentation_frame.interpreter_entry_) { |
| 1039 | ArtMethod* callee = |
| 1040 | Runtime::Current()->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs); |
| 1041 | CHECK_EQ(GetMethod(), callee) |
| 1042 | << "Expected: " << ArtMethod::PrettyMethod(callee) |
| 1043 | << " Found: " << ArtMethod::PrettyMethod(GetMethod()); |
| 1044 | } else { |
| 1045 | // Instrumentation generally doesn't distinguish between a method's obsolete and |
| 1046 | // non-obsolete version. |
| 1047 | CHECK_EQ(instrumentation_frame.method_->GetNonObsoleteMethod(), |
| 1048 | GetMethod()->GetNonObsoleteMethod()) |
| 1049 | << "Expected: " |
| 1050 | << ArtMethod::PrettyMethod( |
| 1051 | instrumentation_frame.method_->GetNonObsoleteMethod()) |
| 1052 | << " Found: " << ArtMethod::PrettyMethod(GetMethod()->GetNonObsoleteMethod()); |
| 1053 | } |
| 1054 | return_pc = instrumentation_frame.return_pc_; |
| 1055 | // TODO It would be nice to do this check but unfortunately it leads to a race since |
| 1056 | // we need to perform a recursive stack-walk to calculate the frame-id. |
| 1057 | // size_t expected_id = instrumentation_frame.frame_id_; |
| 1058 | // if (num_frames_ != 0) { |
| 1059 | // // Check agreement of frame Ids only if num_frames_ is computed to avoid infinite |
| 1060 | // // recursion. |
| 1061 | // size_t frame_id = instrumentation::Instrumentation::ComputeFrameId( |
| 1062 | // thread_, |
| 1063 | // // We already incremented depth but we want to get the last visited frame. |
| 1064 | // depth - 1, |
| 1065 | // inlined_frames_count); |
| 1066 | // CHECK_EQ(expected_id, frame_id); |
| 1067 | // } |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | cur_quick_frame_pc_ = return_pc; |
| 1072 | uint8_t* next_frame = reinterpret_cast<uint8_t*>(cur_quick_frame_) + frame_size; |
| 1073 | cur_quick_frame_ = reinterpret_cast<ArtMethod**>(next_frame); |
| 1074 | |
| 1075 | if (kDebugStackWalk) { |
| 1076 | LOG(INFO) << ArtMethod::PrettyMethod(method) << "@" << method << " size=" << frame_size |
| 1077 | << std::boolalpha << " optimized=" |
| 1078 | << (cur_oat_quick_method_header_ != nullptr && |
| 1079 | cur_oat_quick_method_header_->IsOptimized()) |
| 1080 | << " native=" << method->IsNative() << std::noboolalpha |
| 1081 | << " entrypoints=" << method->GetEntryPointFromQuickCompiledCode() << "," |
| 1082 | << (method->IsNative() ? method->GetEntryPointFromJni() : nullptr) |
| 1083 | << " next=" << *cur_quick_frame_; |
| 1084 | } |
| 1085 | |
| 1086 | method = *cur_quick_frame_; |
Andreas Gampe | f040be6 | 2017-04-14 21:49:33 -0700 | [diff] [blame] | 1087 | } |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 1088 | // We want to start again. Break right now. |
| 1089 | if (retry) { |
| 1090 | break; // From for (const ManagedStack* current_fragment = thread_->GetManagedStack(); |
| 1091 | } |
| 1092 | } else if (cur_shadow_frame_ != nullptr) { |
| 1093 | do { |
| 1094 | SanityCheckFrame(); |
| 1095 | if (!skip_to_depth) { |
| 1096 | bool should_continue = VisitFrame(); |
| 1097 | if (UNLIKELY(!should_continue)) { |
| 1098 | return; |
| 1099 | } |
| 1100 | } |
| 1101 | increment_depth(); |
| 1102 | cur_shadow_frame_ = cur_shadow_frame_->GetLink(); |
| 1103 | } while (cur_shadow_frame_ != nullptr); |
jeffhao | 6641ea1 | 2013-01-02 18:13:42 -0800 | [diff] [blame] | 1104 | } |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 1105 | if (!skip_to_depth && include_transitions) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 1106 | bool should_continue = VisitFrame(); |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 1107 | if (!should_continue) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 1108 | return; |
| 1109 | } |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 1110 | } |
| 1111 | if (kCount == CountTransitions::kYes) { |
| 1112 | increment_depth(); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 1113 | } |
| 1114 | } |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 1115 | if (retry) { |
| 1116 | continue; // Real retry. |
Andreas Gampe | 585da95 | 2016-12-02 14:52:29 -0800 | [diff] [blame] | 1117 | } |
Alex Light | 721e402 | 2020-01-14 14:45:40 -0800 | [diff] [blame^] | 1118 | if (num_frames_ != 0) { |
| 1119 | CHECK_EQ(cur_depth_, num_frames_); |
| 1120 | } |
| 1121 | } while (retry); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
Andreas Gampe | 585da95 | 2016-12-02 14:52:29 -0800 | [diff] [blame] | 1124 | template void StackVisitor::WalkStack<StackVisitor::CountTransitions::kYes>(bool); |
| 1125 | template void StackVisitor::WalkStack<StackVisitor::CountTransitions::kNo>(bool); |
| 1126 | |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 1127 | } // namespace art |