blob: 90732e1ccac7dfd9dcddbc2764839391df144de7 [file] [log] [blame]
Sebastien Hertzd45a1f52014-01-09 14:56:54 +01001/*
2 * Copyright (C) 2014 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
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020017#include "quick_exception_handler.h"
18
Ian Rogerse63db272014-07-15 15:36:11 -070019#include "arch/context.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method-inl.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070021#include "base/enums.h"
Andreas Gampe170331f2017-12-07 18:41:03 -080022#include "base/logging.h" // For VLOG_IS_ON.
Nicolas Geoffray62e7c092019-01-08 09:43:01 +000023#include "base/systrace.h"
David Sehr9e734c72018-01-04 17:56:19 -080024#include "dex/dex_file_types.h"
25#include "dex/dex_instruction.h"
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020026#include "entrypoints/entrypoint_utils.h"
Andreas Gampe639bdd12015-06-03 11:22:45 -070027#include "entrypoints/quick/quick_entrypoints_enum.h"
Ian Rogers6f3dbba2014-10-14 17:41:57 -070028#include "entrypoints/runtime_asm_entrypoints.h"
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070029#include "handle_scope-inl.h"
Vladimir Marko6ec2a1b2018-05-22 15:33:48 +010030#include "interpreter/shadow_frame-inl.h"
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +000031#include "jit/jit.h"
32#include "jit/jit_code_cache.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070033#include "mirror/class-inl.h"
34#include "mirror/class_loader.h"
35#include "mirror/throwable.h"
Nicolas Geoffray013d1ee2019-12-04 16:18:15 +000036#include "nterp_helpers.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010037#include "oat_quick_method_header.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010038#include "stack.h"
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010039#include "stack_map.h"
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010040
41namespace art {
42
Ian Rogers5cf98192014-05-29 21:31:50 -070043static constexpr bool kDebugExceptionDelivery = false;
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -070044static constexpr size_t kInvalidFrameDepth = 0xffffffff;
Ian Rogers5cf98192014-05-29 21:31:50 -070045
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020046QuickExceptionHandler::QuickExceptionHandler(Thread* self, bool is_deoptimization)
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010047 : self_(self),
48 context_(self->GetLongJumpContext()),
49 is_deoptimization_(is_deoptimization),
50 method_tracing_active_(is_deoptimization ||
51 Runtime::Current()->GetInstrumentation()->AreExitStubsInstalled()),
52 handler_quick_frame_(nullptr),
53 handler_quick_frame_pc_(0),
54 handler_method_header_(nullptr),
55 handler_quick_arg0_(0),
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010056 handler_dex_pc_(0),
57 clear_exception_(false),
Mingyao Yangf711f2c2016-05-23 12:29:39 -070058 handler_frame_depth_(kInvalidFrameDepth),
59 full_fragment_done_(false) {}
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010060
Sebastien Hertz520633b2015-09-08 17:03:36 +020061// Finds catch handler.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010062class CatchBlockStackVisitor final : public StackVisitor {
Ian Rogers5cf98192014-05-29 21:31:50 -070063 public:
Alex Light2c8206f2018-06-08 14:51:09 -070064 CatchBlockStackVisitor(Thread* self,
65 Context* context,
66 Handle<mirror::Throwable>* exception,
67 QuickExceptionHandler* exception_handler,
68 uint32_t skip_frames)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070069 REQUIRES_SHARED(Locks::mutator_lock_)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010070 : StackVisitor(self, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010071 exception_(exception),
Alex Light2c8206f2018-06-08 14:51:09 -070072 exception_handler_(exception_handler),
73 skip_frames_(skip_frames) {
Ian Rogers5cf98192014-05-29 21:31:50 -070074 }
75
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010076 bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070077 ArtMethod* method = GetMethod();
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -070078 exception_handler_->SetHandlerFrameDepth(GetFrameDepth());
Ian Rogers5cf98192014-05-29 21:31:50 -070079 if (method == nullptr) {
Alex Light2c8206f2018-06-08 14:51:09 -070080 DCHECK_EQ(skip_frames_, 0u)
81 << "We tried to skip an upcall! We should have returned to the upcall to finish delivery";
Ian Rogers5cf98192014-05-29 21:31:50 -070082 // This is the upcall, we remember the frame and last pc so that we may long jump to them.
83 exception_handler_->SetHandlerQuickFramePc(GetCurrentQuickFramePc());
84 exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame());
Ian Rogers5cf98192014-05-29 21:31:50 -070085 return false; // End stack walk.
86 }
Alex Light2c8206f2018-06-08 14:51:09 -070087 if (skip_frames_ != 0) {
88 skip_frames_--;
89 return true;
90 }
Ian Rogers5cf98192014-05-29 21:31:50 -070091 if (method->IsRuntimeMethod()) {
92 // Ignore callee save method.
93 DCHECK(method->IsCalleeSaveMethod());
94 return true;
95 }
Mathieu Chartiere401d142015-04-22 13:56:20 -070096 return HandleTryItems(method);
Ian Rogers5cf98192014-05-29 21:31:50 -070097 }
98
99 private:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700100 bool HandleTryItems(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700101 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampee2abbc62017-09-15 11:59:26 -0700102 uint32_t dex_pc = dex::kDexNoIndex;
Ian Rogers5cf98192014-05-29 21:31:50 -0700103 if (!method->IsNative()) {
104 dex_pc = GetDexPc();
105 }
Andreas Gampee2abbc62017-09-15 11:59:26 -0700106 if (dex_pc != dex::kDexNoIndex) {
Ian Rogers5cf98192014-05-29 21:31:50 -0700107 bool clear_exception = false;
Sebastien Hertz26f72862015-09-15 09:52:07 +0200108 StackHandleScope<1> hs(GetThread());
Ian Rogers5cf98192014-05-29 21:31:50 -0700109 Handle<mirror::Class> to_find(hs.NewHandle((*exception_)->GetClass()));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700110 uint32_t found_dex_pc = method->FindCatchBlock(to_find, dex_pc, &clear_exception);
Ian Rogers5cf98192014-05-29 21:31:50 -0700111 exception_handler_->SetClearException(clear_exception);
Andreas Gampee2abbc62017-09-15 11:59:26 -0700112 if (found_dex_pc != dex::kDexNoIndex) {
Ian Rogers5cf98192014-05-29 21:31:50 -0700113 exception_handler_->SetHandlerDexPc(found_dex_pc);
David Brazdil72f7b882015-09-15 17:00:52 +0100114 exception_handler_->SetHandlerQuickFramePc(
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100115 GetCurrentOatQuickMethodHeader()->ToNativeQuickPc(
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700116 method, found_dex_pc, /* is_for_catch_handler= */ true));
Ian Rogers5cf98192014-05-29 21:31:50 -0700117 exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame());
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100118 exception_handler_->SetHandlerMethodHeader(GetCurrentOatQuickMethodHeader());
Ian Rogers5cf98192014-05-29 21:31:50 -0700119 return false; // End stack walk.
Mingyao Yang99170c62015-07-06 11:10:37 -0700120 } else if (UNLIKELY(GetThread()->HasDebuggerShadowFrames())) {
121 // We are going to unwind this frame. Did we prepare a shadow frame for debugging?
122 size_t frame_id = GetFrameId();
123 ShadowFrame* frame = GetThread()->FindDebuggerShadowFrame(frame_id);
124 if (frame != nullptr) {
125 // We will not execute this shadow frame so we can safely deallocate it.
126 GetThread()->RemoveDebuggerShadowFrameMapping(frame_id);
127 ShadowFrame::DeleteDeoptimizedFrame(frame);
128 }
Ian Rogers5cf98192014-05-29 21:31:50 -0700129 }
130 }
131 return true; // Continue stack walk.
132 }
133
Ian Rogers5cf98192014-05-29 21:31:50 -0700134 // The exception we're looking for the catch block of.
135 Handle<mirror::Throwable>* exception_;
136 // The quick exception handler we're visiting for.
137 QuickExceptionHandler* const exception_handler_;
Alex Light2c8206f2018-06-08 14:51:09 -0700138 // The number of frames to skip searching for catches in.
139 uint32_t skip_frames_;
Ian Rogers5cf98192014-05-29 21:31:50 -0700140
141 DISALLOW_COPY_AND_ASSIGN(CatchBlockStackVisitor);
142};
143
Alex Light2c8206f2018-06-08 14:51:09 -0700144// Finds the appropriate exception catch after calling all method exit instrumentation functions.
145// Note that this might change the exception being thrown.
Mathieu Chartierf5769e12017-01-10 15:54:41 -0800146void QuickExceptionHandler::FindCatch(ObjPtr<mirror::Throwable> exception) {
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200147 DCHECK(!is_deoptimization_);
Alex Light2c8206f2018-06-08 14:51:09 -0700148 instrumentation::InstrumentationStackPopper popper(self_);
149 // The number of total frames we have so far popped.
150 uint32_t already_popped = 0;
151 bool popped_to_top = true;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700152 StackHandleScope<1> hs(self_);
Alex Light2c8206f2018-06-08 14:51:09 -0700153 MutableHandle<mirror::Throwable> exception_ref(hs.NewHandle(exception));
154 // Sending the instrumentation events (done by the InstrumentationStackPopper) can cause new
155 // exceptions to be thrown which will override the current exception. Therefore we need to perform
156 // the search for a catch in a loop until we have successfully popped all the way to a catch or
157 // the top of the stack.
158 do {
159 if (kDebugExceptionDelivery) {
160 ObjPtr<mirror::String> msg = exception_ref->GetDetailMessage();
161 std::string str_msg(msg != nullptr ? msg->ToModifiedUtf8() : "");
162 self_->DumpStack(LOG_STREAM(INFO) << "Delivering exception: " << exception_ref->PrettyTypeOf()
163 << ": " << str_msg << "\n");
Ian Rogers5cf98192014-05-29 21:31:50 -0700164 }
Alex Light2c8206f2018-06-08 14:51:09 -0700165
166 // Walk the stack to find catch handler.
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700167 CatchBlockStackVisitor visitor(self_, context_,
168 &exception_ref,
169 this,
170 /*skip_frames=*/already_popped);
Alex Light2c8206f2018-06-08 14:51:09 -0700171 visitor.WalkStack(true);
172 uint32_t new_pop_count = handler_frame_depth_;
173 DCHECK_GE(new_pop_count, already_popped);
174 already_popped = new_pop_count;
175
Alex Light2c8206f2018-06-08 14:51:09 -0700176 if (kDebugExceptionDelivery) {
177 if (*handler_quick_frame_ == nullptr) {
178 LOG(INFO) << "Handler is upcall";
179 }
Nicolas Geoffray51ad7fe2020-02-04 12:46:47 +0000180 if (GetHandlerMethod() != nullptr) {
181 const DexFile* dex_file = GetHandlerMethod()->GetDexFile();
182 int line_number =
183 annotations::GetLineNumFromPC(dex_file, GetHandlerMethod(), handler_dex_pc_);
184 LOG(INFO) << "Handler: " << GetHandlerMethod()->PrettyMethod() << " (line: "
Alex Light2c8206f2018-06-08 14:51:09 -0700185 << line_number << ")";
186 }
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100187 }
Alex Light2c8206f2018-06-08 14:51:09 -0700188 // Exception was cleared as part of delivery.
189 DCHECK(!self_->IsExceptionPending());
190 // If the handler is in optimized code, we need to set the catch environment.
191 if (*handler_quick_frame_ != nullptr &&
192 handler_method_header_ != nullptr &&
193 handler_method_header_->IsOptimized()) {
194 SetCatchEnvironmentForOptimizedHandler(&visitor);
195 }
Nicolas Geoffraye91e7952020-01-23 10:15:56 +0000196 popped_to_top =
197 popper.PopFramesTo(reinterpret_cast<uintptr_t>(handler_quick_frame_), exception_ref);
Alex Light2c8206f2018-06-08 14:51:09 -0700198 } while (!popped_to_top);
Roland Levillainb77b6982017-06-08 18:03:48 +0100199 if (!clear_exception_) {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100200 // Put exception back in root set with clear throw location.
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000201 self_->SetException(exception_ref.Get());
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100202 }
David Brazdil77a48ae2015-09-15 12:34:04 +0000203}
204
205static VRegKind ToVRegKind(DexRegisterLocation::Kind kind) {
206 // Slightly hacky since we cannot map DexRegisterLocationKind and VRegKind
207 // one to one. However, StackVisitor::GetVRegFromOptimizedCode only needs to
208 // distinguish between core/FPU registers and low/high bits on 64-bit.
209 switch (kind) {
210 case DexRegisterLocation::Kind::kConstant:
211 case DexRegisterLocation::Kind::kInStack:
212 // VRegKind is ignored.
213 return VRegKind::kUndefined;
214
215 case DexRegisterLocation::Kind::kInRegister:
216 // Selects core register. For 64-bit registers, selects low 32 bits.
217 return VRegKind::kLongLoVReg;
218
219 case DexRegisterLocation::Kind::kInRegisterHigh:
220 // Selects core register. For 64-bit registers, selects high 32 bits.
221 return VRegKind::kLongHiVReg;
222
223 case DexRegisterLocation::Kind::kInFpuRegister:
224 // Selects FPU register. For 64-bit registers, selects low 32 bits.
225 return VRegKind::kDoubleLoVReg;
226
227 case DexRegisterLocation::Kind::kInFpuRegisterHigh:
228 // Selects FPU register. For 64-bit registers, selects high 32 bits.
229 return VRegKind::kDoubleHiVReg;
230
231 default:
David Srbecky7dc11782016-02-25 13:23:56 +0000232 LOG(FATAL) << "Unexpected vreg location " << kind;
David Brazdil77a48ae2015-09-15 12:34:04 +0000233 UNREACHABLE();
234 }
235}
236
237void QuickExceptionHandler::SetCatchEnvironmentForOptimizedHandler(StackVisitor* stack_visitor) {
238 DCHECK(!is_deoptimization_);
239 DCHECK(*handler_quick_frame_ != nullptr) << "Method should not be called on upcall exceptions";
Nicolas Geoffray51ad7fe2020-02-04 12:46:47 +0000240 DCHECK(GetHandlerMethod() != nullptr && handler_method_header_->IsOptimized());
David Brazdil77a48ae2015-09-15 12:34:04 +0000241
242 if (kDebugExceptionDelivery) {
Andreas Gampe3fec9ac2016-09-13 10:47:28 -0700243 self_->DumpStack(LOG_STREAM(INFO) << "Setting catch phis: ");
David Brazdil77a48ae2015-09-15 12:34:04 +0000244 }
245
Nicolas Geoffray51ad7fe2020-02-04 12:46:47 +0000246 CodeItemDataAccessor accessor(GetHandlerMethod()->DexInstructionData());
Mathieu Chartier808c7a52017-12-15 11:19:33 -0800247 const size_t number_of_vregs = accessor.RegistersSize();
David Srbecky052f8ca2018-04-26 15:42:54 +0100248 CodeInfo code_info(handler_method_header_);
David Brazdil77a48ae2015-09-15 12:34:04 +0000249
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000250 // Find stack map of the catch block.
David Srbecky052f8ca2018-04-26 15:42:54 +0100251 StackMap catch_stack_map = code_info.GetCatchStackMapForDexPc(GetHandlerDexPc());
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000252 DCHECK(catch_stack_map.IsValid());
David Srbeckyfd89b072018-06-03 12:00:22 +0100253 DexRegisterMap catch_vreg_map = code_info.GetDexRegisterMapOf(catch_stack_map);
Artem Serov2808be82018-12-20 19:15:11 +0000254 DCHECK_EQ(catch_vreg_map.size(), number_of_vregs);
255
David Srbeckyfd89b072018-06-03 12:00:22 +0100256 if (!catch_vreg_map.HasAnyLiveDexRegisters()) {
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000257 return;
258 }
259
David Brazdil77a48ae2015-09-15 12:34:04 +0000260 // Find stack map of the throwing instruction.
261 StackMap throw_stack_map =
David Srbecky052f8ca2018-04-26 15:42:54 +0100262 code_info.GetStackMapForNativePcOffset(stack_visitor->GetNativePcOffset());
David Brazdil77a48ae2015-09-15 12:34:04 +0000263 DCHECK(throw_stack_map.IsValid());
David Srbeckyfd89b072018-06-03 12:00:22 +0100264 DexRegisterMap throw_vreg_map = code_info.GetDexRegisterMapOf(throw_stack_map);
265 DCHECK_EQ(throw_vreg_map.size(), number_of_vregs);
David Brazdil77a48ae2015-09-15 12:34:04 +0000266
267 // Copy values between them.
268 for (uint16_t vreg = 0; vreg < number_of_vregs; ++vreg) {
David Srbeckye1402122018-06-13 18:20:45 +0100269 DexRegisterLocation::Kind catch_location = catch_vreg_map[vreg].GetKind();
David Brazdil77a48ae2015-09-15 12:34:04 +0000270 if (catch_location == DexRegisterLocation::Kind::kNone) {
271 continue;
272 }
273 DCHECK(catch_location == DexRegisterLocation::Kind::kInStack);
274
275 // Get vreg value from its current location.
276 uint32_t vreg_value;
David Srbeckye1402122018-06-13 18:20:45 +0100277 VRegKind vreg_kind = ToVRegKind(throw_vreg_map[vreg].GetKind());
David Srbeckycffa2542019-07-01 15:31:41 +0100278 bool get_vreg_success =
279 stack_visitor->GetVReg(stack_visitor->GetMethod(),
280 vreg,
281 vreg_kind,
282 &vreg_value,
283 throw_vreg_map[vreg]);
David Brazdil77a48ae2015-09-15 12:34:04 +0000284 CHECK(get_vreg_success) << "VReg " << vreg << " was optimized out ("
David Sehr709b0702016-10-13 09:12:37 -0700285 << "method=" << ArtMethod::PrettyMethod(stack_visitor->GetMethod())
286 << ", dex_pc=" << stack_visitor->GetDexPc() << ", "
David Brazdil77a48ae2015-09-15 12:34:04 +0000287 << "native_pc_offset=" << stack_visitor->GetNativePcOffset() << ")";
288
289 // Copy value to the catch phi's stack slot.
David Srbeckye1402122018-06-13 18:20:45 +0100290 int32_t slot_offset = catch_vreg_map[vreg].GetStackOffsetInBytes();
David Brazdil77a48ae2015-09-15 12:34:04 +0000291 ArtMethod** frame_top = stack_visitor->GetCurrentQuickFrame();
292 uint8_t* slot_address = reinterpret_cast<uint8_t*>(frame_top) + slot_offset;
293 uint32_t* slot_ptr = reinterpret_cast<uint32_t*>(slot_address);
294 *slot_ptr = vreg_value;
295 }
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200296}
297
Ian Rogers5cf98192014-05-29 21:31:50 -0700298// Prepares deoptimization.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100299class DeoptimizeStackVisitor final : public StackVisitor {
Ian Rogers5cf98192014-05-29 21:31:50 -0700300 public:
Andreas Gampe639bdd12015-06-03 11:22:45 -0700301 DeoptimizeStackVisitor(Thread* self,
302 Context* context,
303 QuickExceptionHandler* exception_handler,
304 bool single_frame)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700305 REQUIRES_SHARED(Locks::mutator_lock_)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100306 : StackVisitor(self, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100307 exception_handler_(exception_handler),
Mingyao Yang1f2d3ba2015-05-18 12:12:50 -0700308 prev_shadow_frame_(nullptr),
Andreas Gampe639bdd12015-06-03 11:22:45 -0700309 stacked_shadow_frame_pushed_(false),
310 single_frame_deopt_(single_frame),
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100311 single_frame_done_(false),
Nicolas Geoffrayb52de242016-02-19 12:43:12 +0000312 single_frame_deopt_method_(nullptr),
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700313 single_frame_deopt_quick_method_header_(nullptr),
314 callee_method_(nullptr) {
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100315 }
316
317 ArtMethod* GetSingleFrameDeoptMethod() const {
318 return single_frame_deopt_method_;
Ian Rogers5cf98192014-05-29 21:31:50 -0700319 }
320
Nicolas Geoffrayb52de242016-02-19 12:43:12 +0000321 const OatQuickMethodHeader* GetSingleFrameDeoptQuickMethodHeader() const {
322 return single_frame_deopt_quick_method_header_;
323 }
324
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700325 void FinishStackWalk() REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700326 // This is the upcall, or the next full frame in single-frame deopt, or the
327 // code isn't deoptimizeable. We remember the frame and last pc so that we
328 // may long jump to them.
329 exception_handler_->SetHandlerQuickFramePc(GetCurrentQuickFramePc());
330 exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame());
331 exception_handler_->SetHandlerMethodHeader(GetCurrentOatQuickMethodHeader());
332 if (!stacked_shadow_frame_pushed_) {
333 // In case there is no deoptimized shadow frame for this upcall, we still
334 // need to push a nullptr to the stack since there is always a matching pop after
335 // the long jump.
336 GetThread()->PushStackedShadowFrame(nullptr,
337 StackedShadowFrameType::kDeoptimizationShadowFrame);
338 stacked_shadow_frame_pushed_ = true;
339 }
340 if (GetMethod() == nullptr) {
341 exception_handler_->SetFullFragmentDone(true);
342 } else {
David Sehr709b0702016-10-13 09:12:37 -0700343 CHECK(callee_method_ != nullptr) << GetMethod()->PrettyMethod(false);
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700344 exception_handler_->SetHandlerQuickArg0(reinterpret_cast<uintptr_t>(callee_method_));
345 }
346 }
347
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100348 bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) {
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -0700349 exception_handler_->SetHandlerFrameDepth(GetFrameDepth());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700350 ArtMethod* method = GetMethod();
Alex Light0aa7a5a2018-10-10 15:58:14 +0000351 VLOG(deopt) << "Deoptimizing stack: depth: " << GetFrameDepth()
352 << " at method " << ArtMethod::PrettyMethod(method);
Andreas Gampe639bdd12015-06-03 11:22:45 -0700353 if (method == nullptr || single_frame_done_) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700354 FinishStackWalk();
Ian Rogers5cf98192014-05-29 21:31:50 -0700355 return false; // End stack walk.
356 } else if (method->IsRuntimeMethod()) {
357 // Ignore callee save method.
358 DCHECK(method->IsCalleeSaveMethod());
359 return true;
Sebastien Hertz520633b2015-09-08 17:03:36 +0200360 } else if (method->IsNative()) {
361 // If we return from JNI with a pending exception and want to deoptimize, we need to skip
362 // the native method.
363 // The top method is a runtime method, the native method comes next.
364 CHECK_EQ(GetFrameDepth(), 1U);
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700365 callee_method_ = method;
Sebastien Hertz520633b2015-09-08 17:03:36 +0200366 return true;
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700367 } else if (!single_frame_deopt_ &&
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000368 !Runtime::Current()->IsAsyncDeoptimizeable(GetCurrentQuickFramePc())) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700369 // We hit some code that's not deoptimizeable. However, Single-frame deoptimization triggered
370 // from compiled code is always allowed since HDeoptimize always saves the full environment.
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000371 LOG(WARNING) << "Got request to deoptimize un-deoptimizable method "
372 << method->PrettyMethod();
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700373 FinishStackWalk();
374 return false; // End stack walk.
Ian Rogers5cf98192014-05-29 21:31:50 -0700375 } else {
Nicolas Geoffray33856502015-10-20 15:52:58 +0100376 // Check if a shadow frame already exists for debugger's set-local-value purpose.
377 const size_t frame_id = GetFrameId();
378 ShadowFrame* new_frame = GetThread()->FindDebuggerShadowFrame(frame_id);
379 const bool* updated_vregs;
David Sehr0225f8e2018-01-31 08:52:24 +0000380 CodeItemDataAccessor accessor(method->DexInstructionData());
Mathieu Chartier808c7a52017-12-15 11:19:33 -0800381 const size_t num_regs = accessor.RegistersSize();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100382 if (new_frame == nullptr) {
383 new_frame = ShadowFrame::CreateDeoptimizedFrame(num_regs, nullptr, method, GetDexPc());
384 updated_vregs = nullptr;
385 } else {
386 updated_vregs = GetThread()->GetUpdatedVRegFlags(frame_id);
387 DCHECK(updated_vregs != nullptr);
388 }
Nicolas Geoffray00391822019-12-10 10:17:23 +0000389 if (GetCurrentOatQuickMethodHeader()->IsNterpMethodHeader()) {
390 HandleNterpDeoptimization(method, new_frame, updated_vregs);
391 } else {
392 HandleOptimizingDeoptimization(method, new_frame, updated_vregs);
393 }
Nicolas Geoffray33856502015-10-20 15:52:58 +0100394 if (updated_vregs != nullptr) {
395 // Calling Thread::RemoveDebuggerShadowFrameMapping will also delete the updated_vregs
396 // array so this must come after we processed the frame.
397 GetThread()->RemoveDebuggerShadowFrameMapping(frame_id);
398 DCHECK(GetThread()->FindDebuggerShadowFrame(frame_id) == nullptr);
399 }
400 if (prev_shadow_frame_ != nullptr) {
401 prev_shadow_frame_->SetLink(new_frame);
402 } else {
403 // Will be popped after the long jump after DeoptimizeStack(),
404 // right before interpreter::EnterInterpreterFromDeoptimize().
405 stacked_shadow_frame_pushed_ = true;
406 GetThread()->PushStackedShadowFrame(
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700407 new_frame, StackedShadowFrameType::kDeoptimizationShadowFrame);
Nicolas Geoffray33856502015-10-20 15:52:58 +0100408 }
409 prev_shadow_frame_ = new_frame;
410
Andreas Gampe639bdd12015-06-03 11:22:45 -0700411 if (single_frame_deopt_ && !IsInInlinedFrame()) {
412 // Single-frame deopt ends at the first non-inlined frame and needs to store that method.
Andreas Gampe639bdd12015-06-03 11:22:45 -0700413 single_frame_done_ = true;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100414 single_frame_deopt_method_ = method;
Nicolas Geoffrayb52de242016-02-19 12:43:12 +0000415 single_frame_deopt_quick_method_header_ = GetCurrentOatQuickMethodHeader();
Andreas Gampe639bdd12015-06-03 11:22:45 -0700416 }
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700417 callee_method_ = method;
Andreas Gampe639bdd12015-06-03 11:22:45 -0700418 return true;
Ian Rogers5cf98192014-05-29 21:31:50 -0700419 }
420 }
421
422 private:
Nicolas Geoffray00391822019-12-10 10:17:23 +0000423 void HandleNterpDeoptimization(ArtMethod* m,
424 ShadowFrame* new_frame,
425 const bool* updated_vregs)
426 REQUIRES_SHARED(Locks::mutator_lock_) {
427 ArtMethod** cur_quick_frame = GetCurrentQuickFrame();
428 StackReference<mirror::Object>* vreg_ref_base =
429 reinterpret_cast<StackReference<mirror::Object>*>(NterpGetReferenceArray(cur_quick_frame));
430 int32_t* vreg_int_base =
431 reinterpret_cast<int32_t*>(NterpGetRegistersArray(cur_quick_frame));
432 CodeItemDataAccessor accessor(m->DexInstructionData());
433 const uint16_t num_regs = accessor.RegistersSize();
434 // An nterp frame has two arrays: a dex register array and a reference array
435 // that shadows the dex register array but only containing references
436 // (non-reference dex registers have nulls). See nterp_helpers.cc.
437 for (size_t reg = 0; reg < num_regs; ++reg) {
438 if (updated_vregs != nullptr && updated_vregs[reg]) {
439 // Keep the value set by debugger.
440 continue;
441 }
442 StackReference<mirror::Object>* ref_addr = vreg_ref_base + reg;
443 mirror::Object* ref = ref_addr->AsMirrorPtr();
444 if (ref != nullptr) {
445 new_frame->SetVRegReference(reg, ref);
446 } else {
447 new_frame->SetVReg(reg, vreg_int_base[reg]);
448 }
449 }
450 }
451
Nicolas Geoffray33856502015-10-20 15:52:58 +0100452 void HandleOptimizingDeoptimization(ArtMethod* m,
453 ShadowFrame* new_frame,
454 const bool* updated_vregs)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700455 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray33856502015-10-20 15:52:58 +0100456 const OatQuickMethodHeader* method_header = GetCurrentOatQuickMethodHeader();
David Srbecky052f8ca2018-04-26 15:42:54 +0100457 CodeInfo code_info(method_header);
Nicolas Geoffray33856502015-10-20 15:52:58 +0100458 uintptr_t native_pc_offset = method_header->NativeQuickPcOffset(GetCurrentQuickFramePc());
David Srbecky052f8ca2018-04-26 15:42:54 +0100459 StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset);
David Sehr0225f8e2018-01-31 08:52:24 +0000460 CodeItemDataAccessor accessor(m->DexInstructionData());
Mathieu Chartier808c7a52017-12-15 11:19:33 -0800461 const size_t number_of_vregs = accessor.RegistersSize();
David Srbecky052f8ca2018-04-26 15:42:54 +0100462 uint32_t register_mask = code_info.GetRegisterMaskOf(stack_map);
463 BitMemoryRegion stack_mask = code_info.GetStackMaskOf(stack_map);
David Brazdilefc3f022015-10-28 12:19:06 -0500464 DexRegisterMap vreg_map = IsInInlinedFrame()
David Srbecky93bd3612018-07-02 19:30:18 +0100465 ? code_info.GetInlineDexRegisterMapOf(stack_map, GetCurrentInlinedFrame())
David Srbeckyfd89b072018-06-03 12:00:22 +0100466 : code_info.GetDexRegisterMapOf(stack_map);
Artem Serov2808be82018-12-20 19:15:11 +0000467
468 DCHECK_EQ(vreg_map.size(), number_of_vregs);
David Srbeckyfd89b072018-06-03 12:00:22 +0100469 if (vreg_map.empty()) {
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000470 return;
471 }
472
Nicolas Geoffray33856502015-10-20 15:52:58 +0100473 for (uint16_t vreg = 0; vreg < number_of_vregs; ++vreg) {
474 if (updated_vregs != nullptr && updated_vregs[vreg]) {
475 // Keep the value set by debugger.
476 continue;
477 }
478
David Srbeckye1402122018-06-13 18:20:45 +0100479 DexRegisterLocation::Kind location = vreg_map[vreg].GetKind();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100480 static constexpr uint32_t kDeadValue = 0xEBADDE09;
481 uint32_t value = kDeadValue;
482 bool is_reference = false;
483
484 switch (location) {
485 case DexRegisterLocation::Kind::kInStack: {
David Srbeckye1402122018-06-13 18:20:45 +0100486 const int32_t offset = vreg_map[vreg].GetStackOffsetInBytes();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100487 const uint8_t* addr = reinterpret_cast<const uint8_t*>(GetCurrentQuickFrame()) + offset;
488 value = *reinterpret_cast<const uint32_t*>(addr);
489 uint32_t bit = (offset >> 2);
David Srbecky4b59d102018-05-29 21:46:10 +0000490 if (bit < stack_mask.size_in_bits() && stack_mask.LoadBit(bit)) {
Nicolas Geoffray33856502015-10-20 15:52:58 +0100491 is_reference = true;
492 }
493 break;
494 }
495 case DexRegisterLocation::Kind::kInRegister:
496 case DexRegisterLocation::Kind::kInRegisterHigh:
497 case DexRegisterLocation::Kind::kInFpuRegister:
498 case DexRegisterLocation::Kind::kInFpuRegisterHigh: {
David Srbeckye1402122018-06-13 18:20:45 +0100499 uint32_t reg = vreg_map[vreg].GetMachineRegister();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100500 bool result = GetRegisterIfAccessible(reg, ToVRegKind(location), &value);
501 CHECK(result);
502 if (location == DexRegisterLocation::Kind::kInRegister) {
503 if (((1u << reg) & register_mask) != 0) {
504 is_reference = true;
505 }
506 }
507 break;
508 }
509 case DexRegisterLocation::Kind::kConstant: {
David Srbeckye1402122018-06-13 18:20:45 +0100510 value = vreg_map[vreg].GetConstant();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100511 if (value == 0) {
512 // Make it a reference for extra safety.
513 is_reference = true;
514 }
515 break;
516 }
517 case DexRegisterLocation::Kind::kNone: {
518 break;
519 }
520 default: {
David Srbeckye1402122018-06-13 18:20:45 +0100521 LOG(FATAL) << "Unexpected location kind " << vreg_map[vreg].GetKind();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100522 UNREACHABLE();
523 }
524 }
525 if (is_reference) {
526 new_frame->SetVRegReference(vreg, reinterpret_cast<mirror::Object*>(value));
527 } else {
528 new_frame->SetVReg(vreg, value);
529 }
530 }
531 }
532
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200533 static VRegKind GetVRegKind(uint16_t reg, const std::vector<int32_t>& kinds) {
Vladimir Marko35d5b8a2018-07-03 09:18:32 +0100534 return static_cast<VRegKind>(kinds[reg * 2]);
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200535 }
536
Ian Rogers5cf98192014-05-29 21:31:50 -0700537 QuickExceptionHandler* const exception_handler_;
538 ShadowFrame* prev_shadow_frame_;
Mingyao Yang1f2d3ba2015-05-18 12:12:50 -0700539 bool stacked_shadow_frame_pushed_;
Andreas Gampe639bdd12015-06-03 11:22:45 -0700540 const bool single_frame_deopt_;
541 bool single_frame_done_;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100542 ArtMethod* single_frame_deopt_method_;
Nicolas Geoffrayb52de242016-02-19 12:43:12 +0000543 const OatQuickMethodHeader* single_frame_deopt_quick_method_header_;
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700544 ArtMethod* callee_method_;
Ian Rogers5cf98192014-05-29 21:31:50 -0700545
546 DISALLOW_COPY_AND_ASSIGN(DeoptimizeStackVisitor);
547};
548
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700549void QuickExceptionHandler::PrepareForLongJumpToInvokeStubOrInterpreterBridge() {
550 if (full_fragment_done_) {
551 // Restore deoptimization exception. When returning from the invoke stub,
552 // ArtMethod::Invoke() will see the special exception to know deoptimization
553 // is needed.
554 self_->SetException(Thread::GetDeoptimizationException());
555 } else {
556 // PC needs to be of the quick-to-interpreter bridge.
557 int32_t offset;
Andreas Gampe542451c2016-07-26 09:02:02 -0700558 offset = GetThreadOffset<kRuntimePointerSize>(kQuickQuickToInterpreterBridge).Int32Value();
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700559 handler_quick_frame_pc_ = *reinterpret_cast<uintptr_t*>(
560 reinterpret_cast<uint8_t*>(self_) + offset);
561 }
562}
563
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200564void QuickExceptionHandler::DeoptimizeStack() {
565 DCHECK(is_deoptimization_);
Ian Rogers5cf98192014-05-29 21:31:50 -0700566 if (kDebugExceptionDelivery) {
Andreas Gampe3fec9ac2016-09-13 10:47:28 -0700567 self_->DumpStack(LOG_STREAM(INFO) << "Deoptimizing: ");
Ian Rogers5cf98192014-05-29 21:31:50 -0700568 }
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200569
Andreas Gampe639bdd12015-06-03 11:22:45 -0700570 DeoptimizeStackVisitor visitor(self_, context_, this, false);
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200571 visitor.WalkStack(true);
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700572 PrepareForLongJumpToInvokeStubOrInterpreterBridge();
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100573}
574
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100575void QuickExceptionHandler::DeoptimizeSingleFrame(DeoptimizationKind kind) {
Andreas Gampe639bdd12015-06-03 11:22:45 -0700576 DCHECK(is_deoptimization_);
577
Andreas Gampe639bdd12015-06-03 11:22:45 -0700578 DeoptimizeStackVisitor visitor(self_, context_, this, true);
579 visitor.WalkStack(true);
580
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +0000581 // Compiled code made an explicit deoptimization.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100582 ArtMethod* deopt_method = visitor.GetSingleFrameDeoptMethod();
Nicolas Geoffray62e7c092019-01-08 09:43:01 +0000583 SCOPED_TRACE << "Deoptimizing "
584 << deopt_method->PrettyMethod()
585 << ": " << GetDeoptimizationKindName(kind);
586
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100587 DCHECK(deopt_method != nullptr);
Nicolas Geoffray646d6382017-08-09 10:50:00 +0100588 if (VLOG_IS_ON(deopt) || kDebugExceptionDelivery) {
589 LOG(INFO) << "Single-frame deopting: "
590 << deopt_method->PrettyMethod()
591 << " due to "
592 << GetDeoptimizationKindName(kind);
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700593 DumpFramesWithType(self_, /* details= */ true);
Nicolas Geoffray646d6382017-08-09 10:50:00 +0100594 }
Calin Juravleffc87072016-04-20 14:22:09 +0100595 if (Runtime::Current()->UseJitCompilation()) {
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +0000596 Runtime::Current()->GetJit()->GetCodeCache()->InvalidateCompiledCodeFor(
Nicolas Geoffrayb52de242016-02-19 12:43:12 +0000597 deopt_method, visitor.GetSingleFrameDeoptQuickMethodHeader());
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +0000598 } else {
599 // Transfer the code to interpreter.
600 Runtime::Current()->GetInstrumentation()->UpdateMethodsCode(
601 deopt_method, GetQuickToInterpreterBridge());
602 }
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100603
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700604 PrepareForLongJumpToInvokeStubOrInterpreterBridge();
Andreas Gampe639bdd12015-06-03 11:22:45 -0700605}
606
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700607void QuickExceptionHandler::DeoptimizePartialFragmentFixup(uintptr_t return_pc) {
608 // At this point, the instrumentation stack has been updated. We need to install
609 // the real return pc on stack, in case instrumentation stub is stored there,
610 // so that the interpreter bridge code can return to the right place.
611 if (return_pc != 0) {
612 uintptr_t* pc_addr = reinterpret_cast<uintptr_t*>(handler_quick_frame_);
613 CHECK(pc_addr != nullptr);
614 pc_addr--;
615 *reinterpret_cast<uintptr_t*>(pc_addr) = return_pc;
616 }
Andreas Gampe639bdd12015-06-03 11:22:45 -0700617
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700618 // Architecture-dependent work. This is to get the LR right for x86 and x86-64.
Andreas Gampe639bdd12015-06-03 11:22:45 -0700619 if (kRuntimeISA == InstructionSet::kX86 || kRuntimeISA == InstructionSet::kX86_64) {
620 // On x86, the return address is on the stack, so just reuse it. Otherwise we would have to
621 // change how longjump works.
622 handler_quick_frame_ = reinterpret_cast<ArtMethod**>(
623 reinterpret_cast<uintptr_t>(handler_quick_frame_) - sizeof(void*));
624 }
625}
626
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700627uintptr_t QuickExceptionHandler::UpdateInstrumentationStack() {
Alex Light2c8206f2018-06-08 14:51:09 -0700628 DCHECK(is_deoptimization_) << "Non-deoptimization handlers should use FindCatch";
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700629 uintptr_t return_pc = 0;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100630 if (method_tracing_active_) {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100631 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Nicolas Geoffraye91e7952020-01-23 10:15:56 +0000632 return_pc = instrumentation->PopFramesForDeoptimization(
633 self_, reinterpret_cast<uintptr_t>(handler_quick_frame_));
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100634 }
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700635 return return_pc;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100636}
637
Andreas Gampe639bdd12015-06-03 11:22:45 -0700638void QuickExceptionHandler::DoLongJump(bool smash_caller_saves) {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100639 // Place context back on thread so it will be available when we continue.
640 self_->ReleaseLongJumpContext(context_);
641 context_->SetSP(reinterpret_cast<uintptr_t>(handler_quick_frame_));
642 CHECK_NE(handler_quick_frame_pc_, 0u);
643 context_->SetPC(handler_quick_frame_pc_);
Andreas Gampe639bdd12015-06-03 11:22:45 -0700644 context_->SetArg0(handler_quick_arg0_);
645 if (smash_caller_saves) {
646 context_->SmashCallerSaves();
647 }
Nicolas Geoffray51ad7fe2020-02-04 12:46:47 +0000648 if (!is_deoptimization_ &&
Nicolas Geoffray013d1ee2019-12-04 16:18:15 +0000649 handler_method_header_ != nullptr &&
650 handler_method_header_->IsNterpMethodHeader()) {
651 context_->SetNterpDexPC(reinterpret_cast<uintptr_t>(
Nicolas Geoffray51ad7fe2020-02-04 12:46:47 +0000652 GetHandlerMethod()->DexInstructions().Insns() + handler_dex_pc_));
Nicolas Geoffray013d1ee2019-12-04 16:18:15 +0000653 }
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100654 context_->DoLongJump();
Andreas Gampe794ad762015-02-23 08:12:24 -0800655 UNREACHABLE();
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100656}
657
Andreas Gampe639bdd12015-06-03 11:22:45 -0700658void QuickExceptionHandler::DumpFramesWithType(Thread* self, bool details) {
Andreas Gampec7d878d2018-11-19 18:42:06 +0000659 StackVisitor::WalkStack(
660 [&](const art::StackVisitor* stack_visitor) REQUIRES_SHARED(Locks::mutator_lock_) {
661 ArtMethod* method = stack_visitor->GetMethod();
662 if (details) {
663 LOG(INFO) << "|> pc = " << std::hex << stack_visitor->GetCurrentQuickFramePc();
664 LOG(INFO) << "|> addr = " << std::hex
665 << reinterpret_cast<uintptr_t>(stack_visitor->GetCurrentQuickFrame());
666 if (stack_visitor->GetCurrentQuickFrame() != nullptr && method != nullptr) {
667 LOG(INFO) << "|> ret = " << std::hex << stack_visitor->GetReturnPc();
668 }
669 }
670 if (method == nullptr) {
671 // Transition, do go on, we want to unwind over bridges, all the way.
672 if (details) {
673 LOG(INFO) << "N <transition>";
674 }
675 return true;
676 } else if (method->IsRuntimeMethod()) {
677 if (details) {
678 LOG(INFO) << "R " << method->PrettyMethod(true);
679 }
680 return true;
681 } else {
682 bool is_shadow = stack_visitor->GetCurrentShadowFrame() != nullptr;
683 LOG(INFO) << (is_shadow ? "S" : "Q")
684 << ((!is_shadow && stack_visitor->IsInInlinedFrame()) ? "i" : " ")
685 << " "
686 << method->PrettyMethod(true);
687 return true; // Go on.
688 }
689 },
690 self,
691 /* context= */ nullptr,
692 art::StackVisitor::StackWalkKind::kIncludeInlinedFrames);
Andreas Gampe639bdd12015-06-03 11:22:45 -0700693}
694
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100695} // namespace art