blob: 2a6929a523beb09c21cd4b989830e459787b4124 [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"
Alex Light6fc471e2020-03-03 16:51:33 -080018#include <ios>
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020019
Ian Rogerse63db272014-07-15 15:36:11 -070020#include "arch/context.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070021#include "art_method-inl.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070022#include "base/enums.h"
Alex Light6fc471e2020-03-03 16:51:33 -080023#include "base/globals.h"
Andreas Gampe170331f2017-12-07 18:41:03 -080024#include "base/logging.h" // For VLOG_IS_ON.
Nicolas Geoffray62e7c092019-01-08 09:43:01 +000025#include "base/systrace.h"
David Sehr9e734c72018-01-04 17:56:19 -080026#include "dex/dex_file_types.h"
27#include "dex/dex_instruction.h"
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020028#include "entrypoints/entrypoint_utils.h"
Andreas Gampe639bdd12015-06-03 11:22:45 -070029#include "entrypoints/quick/quick_entrypoints_enum.h"
Ian Rogers6f3dbba2014-10-14 17:41:57 -070030#include "entrypoints/runtime_asm_entrypoints.h"
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070031#include "handle_scope-inl.h"
Vladimir Marko6ec2a1b2018-05-22 15:33:48 +010032#include "interpreter/shadow_frame-inl.h"
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +000033#include "jit/jit.h"
34#include "jit/jit_code_cache.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070035#include "mirror/class-inl.h"
36#include "mirror/class_loader.h"
37#include "mirror/throwable.h"
Nicolas Geoffray013d1ee2019-12-04 16:18:15 +000038#include "nterp_helpers.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010039#include "oat_quick_method_header.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010040#include "stack.h"
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010041#include "stack_map.h"
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010042
43namespace art {
44
Ian Rogers5cf98192014-05-29 21:31:50 -070045static constexpr bool kDebugExceptionDelivery = false;
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -070046static constexpr size_t kInvalidFrameDepth = 0xffffffff;
Ian Rogers5cf98192014-05-29 21:31:50 -070047
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020048QuickExceptionHandler::QuickExceptionHandler(Thread* self, bool is_deoptimization)
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010049 : self_(self),
50 context_(self->GetLongJumpContext()),
51 is_deoptimization_(is_deoptimization),
52 method_tracing_active_(is_deoptimization ||
53 Runtime::Current()->GetInstrumentation()->AreExitStubsInstalled()),
54 handler_quick_frame_(nullptr),
55 handler_quick_frame_pc_(0),
56 handler_method_header_(nullptr),
57 handler_quick_arg0_(0),
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010058 handler_dex_pc_(0),
59 clear_exception_(false),
Mingyao Yangf711f2c2016-05-23 12:29:39 -070060 handler_frame_depth_(kInvalidFrameDepth),
61 full_fragment_done_(false) {}
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010062
Sebastien Hertz520633b2015-09-08 17:03:36 +020063// Finds catch handler.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010064class CatchBlockStackVisitor final : public StackVisitor {
Ian Rogers5cf98192014-05-29 21:31:50 -070065 public:
Alex Light2c8206f2018-06-08 14:51:09 -070066 CatchBlockStackVisitor(Thread* self,
67 Context* context,
68 Handle<mirror::Throwable>* exception,
69 QuickExceptionHandler* exception_handler,
70 uint32_t skip_frames)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070071 REQUIRES_SHARED(Locks::mutator_lock_)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010072 : StackVisitor(self, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010073 exception_(exception),
Alex Light2c8206f2018-06-08 14:51:09 -070074 exception_handler_(exception_handler),
75 skip_frames_(skip_frames) {
Ian Rogers5cf98192014-05-29 21:31:50 -070076 }
77
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010078 bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070079 ArtMethod* method = GetMethod();
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -070080 exception_handler_->SetHandlerFrameDepth(GetFrameDepth());
Ian Rogers5cf98192014-05-29 21:31:50 -070081 if (method == nullptr) {
Alex Light2c8206f2018-06-08 14:51:09 -070082 DCHECK_EQ(skip_frames_, 0u)
83 << "We tried to skip an upcall! We should have returned to the upcall to finish delivery";
Ian Rogers5cf98192014-05-29 21:31:50 -070084 // This is the upcall, we remember the frame and last pc so that we may long jump to them.
85 exception_handler_->SetHandlerQuickFramePc(GetCurrentQuickFramePc());
86 exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame());
Ian Rogers5cf98192014-05-29 21:31:50 -070087 return false; // End stack walk.
88 }
Alex Light2c8206f2018-06-08 14:51:09 -070089 if (skip_frames_ != 0) {
90 skip_frames_--;
91 return true;
92 }
Ian Rogers5cf98192014-05-29 21:31:50 -070093 if (method->IsRuntimeMethod()) {
94 // Ignore callee save method.
95 DCHECK(method->IsCalleeSaveMethod());
96 return true;
97 }
Mathieu Chartiere401d142015-04-22 13:56:20 -070098 return HandleTryItems(method);
Ian Rogers5cf98192014-05-29 21:31:50 -070099 }
100
101 private:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700102 bool HandleTryItems(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700103 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampee2abbc62017-09-15 11:59:26 -0700104 uint32_t dex_pc = dex::kDexNoIndex;
Ian Rogers5cf98192014-05-29 21:31:50 -0700105 if (!method->IsNative()) {
106 dex_pc = GetDexPc();
107 }
Andreas Gampee2abbc62017-09-15 11:59:26 -0700108 if (dex_pc != dex::kDexNoIndex) {
Ian Rogers5cf98192014-05-29 21:31:50 -0700109 bool clear_exception = false;
Sebastien Hertz26f72862015-09-15 09:52:07 +0200110 StackHandleScope<1> hs(GetThread());
Ian Rogers5cf98192014-05-29 21:31:50 -0700111 Handle<mirror::Class> to_find(hs.NewHandle((*exception_)->GetClass()));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700112 uint32_t found_dex_pc = method->FindCatchBlock(to_find, dex_pc, &clear_exception);
Ian Rogers5cf98192014-05-29 21:31:50 -0700113 exception_handler_->SetClearException(clear_exception);
Andreas Gampee2abbc62017-09-15 11:59:26 -0700114 if (found_dex_pc != dex::kDexNoIndex) {
Ian Rogers5cf98192014-05-29 21:31:50 -0700115 exception_handler_->SetHandlerDexPc(found_dex_pc);
David Brazdil72f7b882015-09-15 17:00:52 +0100116 exception_handler_->SetHandlerQuickFramePc(
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100117 GetCurrentOatQuickMethodHeader()->ToNativeQuickPc(
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700118 method, found_dex_pc, /* is_for_catch_handler= */ true));
Ian Rogers5cf98192014-05-29 21:31:50 -0700119 exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame());
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100120 exception_handler_->SetHandlerMethodHeader(GetCurrentOatQuickMethodHeader());
Ian Rogers5cf98192014-05-29 21:31:50 -0700121 return false; // End stack walk.
Mingyao Yang99170c62015-07-06 11:10:37 -0700122 } else if (UNLIKELY(GetThread()->HasDebuggerShadowFrames())) {
123 // We are going to unwind this frame. Did we prepare a shadow frame for debugging?
124 size_t frame_id = GetFrameId();
125 ShadowFrame* frame = GetThread()->FindDebuggerShadowFrame(frame_id);
126 if (frame != nullptr) {
127 // We will not execute this shadow frame so we can safely deallocate it.
128 GetThread()->RemoveDebuggerShadowFrameMapping(frame_id);
129 ShadowFrame::DeleteDeoptimizedFrame(frame);
130 }
Ian Rogers5cf98192014-05-29 21:31:50 -0700131 }
132 }
133 return true; // Continue stack walk.
134 }
135
Ian Rogers5cf98192014-05-29 21:31:50 -0700136 // The exception we're looking for the catch block of.
137 Handle<mirror::Throwable>* exception_;
138 // The quick exception handler we're visiting for.
139 QuickExceptionHandler* const exception_handler_;
Alex Light2c8206f2018-06-08 14:51:09 -0700140 // The number of frames to skip searching for catches in.
141 uint32_t skip_frames_;
Ian Rogers5cf98192014-05-29 21:31:50 -0700142
143 DISALLOW_COPY_AND_ASSIGN(CatchBlockStackVisitor);
144};
145
Alex Light2c8206f2018-06-08 14:51:09 -0700146// Finds the appropriate exception catch after calling all method exit instrumentation functions.
147// Note that this might change the exception being thrown.
Mathieu Chartierf5769e12017-01-10 15:54:41 -0800148void QuickExceptionHandler::FindCatch(ObjPtr<mirror::Throwable> exception) {
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200149 DCHECK(!is_deoptimization_);
Alex Light2c8206f2018-06-08 14:51:09 -0700150 instrumentation::InstrumentationStackPopper popper(self_);
151 // The number of total frames we have so far popped.
152 uint32_t already_popped = 0;
153 bool popped_to_top = true;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700154 StackHandleScope<1> hs(self_);
Alex Light2c8206f2018-06-08 14:51:09 -0700155 MutableHandle<mirror::Throwable> exception_ref(hs.NewHandle(exception));
156 // Sending the instrumentation events (done by the InstrumentationStackPopper) can cause new
157 // exceptions to be thrown which will override the current exception. Therefore we need to perform
158 // the search for a catch in a loop until we have successfully popped all the way to a catch or
159 // the top of the stack.
160 do {
161 if (kDebugExceptionDelivery) {
162 ObjPtr<mirror::String> msg = exception_ref->GetDetailMessage();
163 std::string str_msg(msg != nullptr ? msg->ToModifiedUtf8() : "");
164 self_->DumpStack(LOG_STREAM(INFO) << "Delivering exception: " << exception_ref->PrettyTypeOf()
165 << ": " << str_msg << "\n");
Ian Rogers5cf98192014-05-29 21:31:50 -0700166 }
Alex Light2c8206f2018-06-08 14:51:09 -0700167
168 // Walk the stack to find catch handler.
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700169 CatchBlockStackVisitor visitor(self_, context_,
170 &exception_ref,
171 this,
172 /*skip_frames=*/already_popped);
Alex Light2c8206f2018-06-08 14:51:09 -0700173 visitor.WalkStack(true);
174 uint32_t new_pop_count = handler_frame_depth_;
175 DCHECK_GE(new_pop_count, already_popped);
176 already_popped = new_pop_count;
177
Alex Light2c8206f2018-06-08 14:51:09 -0700178 if (kDebugExceptionDelivery) {
179 if (*handler_quick_frame_ == nullptr) {
180 LOG(INFO) << "Handler is upcall";
181 }
Nicolas Geoffray51ad7fe2020-02-04 12:46:47 +0000182 if (GetHandlerMethod() != nullptr) {
183 const DexFile* dex_file = GetHandlerMethod()->GetDexFile();
184 int line_number =
185 annotations::GetLineNumFromPC(dex_file, GetHandlerMethod(), handler_dex_pc_);
186 LOG(INFO) << "Handler: " << GetHandlerMethod()->PrettyMethod() << " (line: "
Alex Light2c8206f2018-06-08 14:51:09 -0700187 << line_number << ")";
188 }
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100189 }
Alex Light2c8206f2018-06-08 14:51:09 -0700190 // Exception was cleared as part of delivery.
191 DCHECK(!self_->IsExceptionPending());
192 // If the handler is in optimized code, we need to set the catch environment.
193 if (*handler_quick_frame_ != nullptr &&
194 handler_method_header_ != nullptr &&
195 handler_method_header_->IsOptimized()) {
196 SetCatchEnvironmentForOptimizedHandler(&visitor);
197 }
Nicolas Geoffraye91e7952020-01-23 10:15:56 +0000198 popped_to_top =
199 popper.PopFramesTo(reinterpret_cast<uintptr_t>(handler_quick_frame_), exception_ref);
Alex Light2c8206f2018-06-08 14:51:09 -0700200 } while (!popped_to_top);
Roland Levillainb77b6982017-06-08 18:03:48 +0100201 if (!clear_exception_) {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100202 // Put exception back in root set with clear throw location.
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000203 self_->SetException(exception_ref.Get());
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100204 }
David Brazdil77a48ae2015-09-15 12:34:04 +0000205}
206
207static VRegKind ToVRegKind(DexRegisterLocation::Kind kind) {
208 // Slightly hacky since we cannot map DexRegisterLocationKind and VRegKind
209 // one to one. However, StackVisitor::GetVRegFromOptimizedCode only needs to
210 // distinguish between core/FPU registers and low/high bits on 64-bit.
211 switch (kind) {
212 case DexRegisterLocation::Kind::kConstant:
213 case DexRegisterLocation::Kind::kInStack:
214 // VRegKind is ignored.
215 return VRegKind::kUndefined;
216
217 case DexRegisterLocation::Kind::kInRegister:
218 // Selects core register. For 64-bit registers, selects low 32 bits.
219 return VRegKind::kLongLoVReg;
220
221 case DexRegisterLocation::Kind::kInRegisterHigh:
222 // Selects core register. For 64-bit registers, selects high 32 bits.
223 return VRegKind::kLongHiVReg;
224
225 case DexRegisterLocation::Kind::kInFpuRegister:
226 // Selects FPU register. For 64-bit registers, selects low 32 bits.
227 return VRegKind::kDoubleLoVReg;
228
229 case DexRegisterLocation::Kind::kInFpuRegisterHigh:
230 // Selects FPU register. For 64-bit registers, selects high 32 bits.
231 return VRegKind::kDoubleHiVReg;
232
233 default:
David Srbecky7dc11782016-02-25 13:23:56 +0000234 LOG(FATAL) << "Unexpected vreg location " << kind;
David Brazdil77a48ae2015-09-15 12:34:04 +0000235 UNREACHABLE();
236 }
237}
238
239void QuickExceptionHandler::SetCatchEnvironmentForOptimizedHandler(StackVisitor* stack_visitor) {
240 DCHECK(!is_deoptimization_);
241 DCHECK(*handler_quick_frame_ != nullptr) << "Method should not be called on upcall exceptions";
Nicolas Geoffray51ad7fe2020-02-04 12:46:47 +0000242 DCHECK(GetHandlerMethod() != nullptr && handler_method_header_->IsOptimized());
David Brazdil77a48ae2015-09-15 12:34:04 +0000243
244 if (kDebugExceptionDelivery) {
Andreas Gampe3fec9ac2016-09-13 10:47:28 -0700245 self_->DumpStack(LOG_STREAM(INFO) << "Setting catch phis: ");
David Brazdil77a48ae2015-09-15 12:34:04 +0000246 }
247
Nicolas Geoffray51ad7fe2020-02-04 12:46:47 +0000248 CodeItemDataAccessor accessor(GetHandlerMethod()->DexInstructionData());
Mathieu Chartier808c7a52017-12-15 11:19:33 -0800249 const size_t number_of_vregs = accessor.RegistersSize();
David Srbecky052f8ca2018-04-26 15:42:54 +0100250 CodeInfo code_info(handler_method_header_);
David Brazdil77a48ae2015-09-15 12:34:04 +0000251
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000252 // Find stack map of the catch block.
David Srbecky052f8ca2018-04-26 15:42:54 +0100253 StackMap catch_stack_map = code_info.GetCatchStackMapForDexPc(GetHandlerDexPc());
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000254 DCHECK(catch_stack_map.IsValid());
David Srbeckyfd89b072018-06-03 12:00:22 +0100255 DexRegisterMap catch_vreg_map = code_info.GetDexRegisterMapOf(catch_stack_map);
Artem Serov2808be82018-12-20 19:15:11 +0000256 DCHECK_EQ(catch_vreg_map.size(), number_of_vregs);
257
David Srbeckyfd89b072018-06-03 12:00:22 +0100258 if (!catch_vreg_map.HasAnyLiveDexRegisters()) {
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000259 return;
260 }
261
David Brazdil77a48ae2015-09-15 12:34:04 +0000262 // Find stack map of the throwing instruction.
263 StackMap throw_stack_map =
David Srbecky052f8ca2018-04-26 15:42:54 +0100264 code_info.GetStackMapForNativePcOffset(stack_visitor->GetNativePcOffset());
David Brazdil77a48ae2015-09-15 12:34:04 +0000265 DCHECK(throw_stack_map.IsValid());
David Srbeckyfd89b072018-06-03 12:00:22 +0100266 DexRegisterMap throw_vreg_map = code_info.GetDexRegisterMapOf(throw_stack_map);
267 DCHECK_EQ(throw_vreg_map.size(), number_of_vregs);
David Brazdil77a48ae2015-09-15 12:34:04 +0000268
269 // Copy values between them.
270 for (uint16_t vreg = 0; vreg < number_of_vregs; ++vreg) {
David Srbeckye1402122018-06-13 18:20:45 +0100271 DexRegisterLocation::Kind catch_location = catch_vreg_map[vreg].GetKind();
David Brazdil77a48ae2015-09-15 12:34:04 +0000272 if (catch_location == DexRegisterLocation::Kind::kNone) {
273 continue;
274 }
275 DCHECK(catch_location == DexRegisterLocation::Kind::kInStack);
276
277 // Get vreg value from its current location.
278 uint32_t vreg_value;
David Srbeckye1402122018-06-13 18:20:45 +0100279 VRegKind vreg_kind = ToVRegKind(throw_vreg_map[vreg].GetKind());
David Srbeckycffa2542019-07-01 15:31:41 +0100280 bool get_vreg_success =
281 stack_visitor->GetVReg(stack_visitor->GetMethod(),
282 vreg,
283 vreg_kind,
284 &vreg_value,
285 throw_vreg_map[vreg]);
David Brazdil77a48ae2015-09-15 12:34:04 +0000286 CHECK(get_vreg_success) << "VReg " << vreg << " was optimized out ("
David Sehr709b0702016-10-13 09:12:37 -0700287 << "method=" << ArtMethod::PrettyMethod(stack_visitor->GetMethod())
288 << ", dex_pc=" << stack_visitor->GetDexPc() << ", "
David Brazdil77a48ae2015-09-15 12:34:04 +0000289 << "native_pc_offset=" << stack_visitor->GetNativePcOffset() << ")";
290
291 // Copy value to the catch phi's stack slot.
David Srbeckye1402122018-06-13 18:20:45 +0100292 int32_t slot_offset = catch_vreg_map[vreg].GetStackOffsetInBytes();
David Brazdil77a48ae2015-09-15 12:34:04 +0000293 ArtMethod** frame_top = stack_visitor->GetCurrentQuickFrame();
294 uint8_t* slot_address = reinterpret_cast<uint8_t*>(frame_top) + slot_offset;
295 uint32_t* slot_ptr = reinterpret_cast<uint32_t*>(slot_address);
296 *slot_ptr = vreg_value;
297 }
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200298}
299
Ian Rogers5cf98192014-05-29 21:31:50 -0700300// Prepares deoptimization.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100301class DeoptimizeStackVisitor final : public StackVisitor {
Ian Rogers5cf98192014-05-29 21:31:50 -0700302 public:
Andreas Gampe639bdd12015-06-03 11:22:45 -0700303 DeoptimizeStackVisitor(Thread* self,
304 Context* context,
305 QuickExceptionHandler* exception_handler,
306 bool single_frame)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700307 REQUIRES_SHARED(Locks::mutator_lock_)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100308 : StackVisitor(self, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100309 exception_handler_(exception_handler),
Mingyao Yang1f2d3ba2015-05-18 12:12:50 -0700310 prev_shadow_frame_(nullptr),
Andreas Gampe639bdd12015-06-03 11:22:45 -0700311 stacked_shadow_frame_pushed_(false),
312 single_frame_deopt_(single_frame),
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100313 single_frame_done_(false),
Nicolas Geoffrayb52de242016-02-19 12:43:12 +0000314 single_frame_deopt_method_(nullptr),
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700315 single_frame_deopt_quick_method_header_(nullptr),
316 callee_method_(nullptr) {
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100317 }
318
319 ArtMethod* GetSingleFrameDeoptMethod() const {
320 return single_frame_deopt_method_;
Ian Rogers5cf98192014-05-29 21:31:50 -0700321 }
322
Nicolas Geoffrayb52de242016-02-19 12:43:12 +0000323 const OatQuickMethodHeader* GetSingleFrameDeoptQuickMethodHeader() const {
324 return single_frame_deopt_quick_method_header_;
325 }
326
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700327 void FinishStackWalk() REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700328 // This is the upcall, or the next full frame in single-frame deopt, or the
329 // code isn't deoptimizeable. We remember the frame and last pc so that we
330 // may long jump to them.
331 exception_handler_->SetHandlerQuickFramePc(GetCurrentQuickFramePc());
332 exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame());
333 exception_handler_->SetHandlerMethodHeader(GetCurrentOatQuickMethodHeader());
334 if (!stacked_shadow_frame_pushed_) {
335 // In case there is no deoptimized shadow frame for this upcall, we still
336 // need to push a nullptr to the stack since there is always a matching pop after
337 // the long jump.
338 GetThread()->PushStackedShadowFrame(nullptr,
339 StackedShadowFrameType::kDeoptimizationShadowFrame);
340 stacked_shadow_frame_pushed_ = true;
341 }
342 if (GetMethod() == nullptr) {
343 exception_handler_->SetFullFragmentDone(true);
344 } else {
David Sehr709b0702016-10-13 09:12:37 -0700345 CHECK(callee_method_ != nullptr) << GetMethod()->PrettyMethod(false);
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700346 exception_handler_->SetHandlerQuickArg0(reinterpret_cast<uintptr_t>(callee_method_));
347 }
348 }
349
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100350 bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) {
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -0700351 exception_handler_->SetHandlerFrameDepth(GetFrameDepth());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700352 ArtMethod* method = GetMethod();
Alex Light0aa7a5a2018-10-10 15:58:14 +0000353 VLOG(deopt) << "Deoptimizing stack: depth: " << GetFrameDepth()
354 << " at method " << ArtMethod::PrettyMethod(method);
Andreas Gampe639bdd12015-06-03 11:22:45 -0700355 if (method == nullptr || single_frame_done_) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700356 FinishStackWalk();
Ian Rogers5cf98192014-05-29 21:31:50 -0700357 return false; // End stack walk.
358 } else if (method->IsRuntimeMethod()) {
359 // Ignore callee save method.
360 DCHECK(method->IsCalleeSaveMethod());
361 return true;
Sebastien Hertz520633b2015-09-08 17:03:36 +0200362 } else if (method->IsNative()) {
363 // If we return from JNI with a pending exception and want to deoptimize, we need to skip
364 // the native method.
365 // The top method is a runtime method, the native method comes next.
366 CHECK_EQ(GetFrameDepth(), 1U);
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700367 callee_method_ = method;
Sebastien Hertz520633b2015-09-08 17:03:36 +0200368 return true;
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700369 } else if (!single_frame_deopt_ &&
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000370 !Runtime::Current()->IsAsyncDeoptimizeable(GetCurrentQuickFramePc())) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700371 // We hit some code that's not deoptimizeable. However, Single-frame deoptimization triggered
372 // from compiled code is always allowed since HDeoptimize always saves the full environment.
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000373 LOG(WARNING) << "Got request to deoptimize un-deoptimizable method "
374 << method->PrettyMethod();
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700375 FinishStackWalk();
376 return false; // End stack walk.
Ian Rogers5cf98192014-05-29 21:31:50 -0700377 } else {
Nicolas Geoffray33856502015-10-20 15:52:58 +0100378 // Check if a shadow frame already exists for debugger's set-local-value purpose.
379 const size_t frame_id = GetFrameId();
380 ShadowFrame* new_frame = GetThread()->FindDebuggerShadowFrame(frame_id);
381 const bool* updated_vregs;
David Sehr0225f8e2018-01-31 08:52:24 +0000382 CodeItemDataAccessor accessor(method->DexInstructionData());
Mathieu Chartier808c7a52017-12-15 11:19:33 -0800383 const size_t num_regs = accessor.RegistersSize();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100384 if (new_frame == nullptr) {
385 new_frame = ShadowFrame::CreateDeoptimizedFrame(num_regs, nullptr, method, GetDexPc());
386 updated_vregs = nullptr;
387 } else {
388 updated_vregs = GetThread()->GetUpdatedVRegFlags(frame_id);
389 DCHECK(updated_vregs != nullptr);
390 }
Nicolas Geoffray00391822019-12-10 10:17:23 +0000391 if (GetCurrentOatQuickMethodHeader()->IsNterpMethodHeader()) {
392 HandleNterpDeoptimization(method, new_frame, updated_vregs);
393 } else {
394 HandleOptimizingDeoptimization(method, new_frame, updated_vregs);
395 }
Nicolas Geoffray33856502015-10-20 15:52:58 +0100396 if (updated_vregs != nullptr) {
397 // Calling Thread::RemoveDebuggerShadowFrameMapping will also delete the updated_vregs
398 // array so this must come after we processed the frame.
399 GetThread()->RemoveDebuggerShadowFrameMapping(frame_id);
400 DCHECK(GetThread()->FindDebuggerShadowFrame(frame_id) == nullptr);
401 }
402 if (prev_shadow_frame_ != nullptr) {
403 prev_shadow_frame_->SetLink(new_frame);
404 } else {
405 // Will be popped after the long jump after DeoptimizeStack(),
406 // right before interpreter::EnterInterpreterFromDeoptimize().
407 stacked_shadow_frame_pushed_ = true;
408 GetThread()->PushStackedShadowFrame(
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700409 new_frame, StackedShadowFrameType::kDeoptimizationShadowFrame);
Nicolas Geoffray33856502015-10-20 15:52:58 +0100410 }
411 prev_shadow_frame_ = new_frame;
412
Andreas Gampe639bdd12015-06-03 11:22:45 -0700413 if (single_frame_deopt_ && !IsInInlinedFrame()) {
414 // Single-frame deopt ends at the first non-inlined frame and needs to store that method.
Andreas Gampe639bdd12015-06-03 11:22:45 -0700415 single_frame_done_ = true;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100416 single_frame_deopt_method_ = method;
Nicolas Geoffrayb52de242016-02-19 12:43:12 +0000417 single_frame_deopt_quick_method_header_ = GetCurrentOatQuickMethodHeader();
Andreas Gampe639bdd12015-06-03 11:22:45 -0700418 }
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700419 callee_method_ = method;
Andreas Gampe639bdd12015-06-03 11:22:45 -0700420 return true;
Ian Rogers5cf98192014-05-29 21:31:50 -0700421 }
422 }
423
424 private:
Nicolas Geoffray00391822019-12-10 10:17:23 +0000425 void HandleNterpDeoptimization(ArtMethod* m,
426 ShadowFrame* new_frame,
427 const bool* updated_vregs)
428 REQUIRES_SHARED(Locks::mutator_lock_) {
429 ArtMethod** cur_quick_frame = GetCurrentQuickFrame();
430 StackReference<mirror::Object>* vreg_ref_base =
431 reinterpret_cast<StackReference<mirror::Object>*>(NterpGetReferenceArray(cur_quick_frame));
432 int32_t* vreg_int_base =
433 reinterpret_cast<int32_t*>(NterpGetRegistersArray(cur_quick_frame));
434 CodeItemDataAccessor accessor(m->DexInstructionData());
435 const uint16_t num_regs = accessor.RegistersSize();
436 // An nterp frame has two arrays: a dex register array and a reference array
437 // that shadows the dex register array but only containing references
438 // (non-reference dex registers have nulls). See nterp_helpers.cc.
439 for (size_t reg = 0; reg < num_regs; ++reg) {
440 if (updated_vregs != nullptr && updated_vregs[reg]) {
441 // Keep the value set by debugger.
442 continue;
443 }
444 StackReference<mirror::Object>* ref_addr = vreg_ref_base + reg;
445 mirror::Object* ref = ref_addr->AsMirrorPtr();
446 if (ref != nullptr) {
447 new_frame->SetVRegReference(reg, ref);
448 } else {
449 new_frame->SetVReg(reg, vreg_int_base[reg]);
450 }
451 }
452 }
453
Nicolas Geoffray33856502015-10-20 15:52:58 +0100454 void HandleOptimizingDeoptimization(ArtMethod* m,
455 ShadowFrame* new_frame,
456 const bool* updated_vregs)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700457 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray33856502015-10-20 15:52:58 +0100458 const OatQuickMethodHeader* method_header = GetCurrentOatQuickMethodHeader();
David Srbecky052f8ca2018-04-26 15:42:54 +0100459 CodeInfo code_info(method_header);
Nicolas Geoffray33856502015-10-20 15:52:58 +0100460 uintptr_t native_pc_offset = method_header->NativeQuickPcOffset(GetCurrentQuickFramePc());
David Srbecky052f8ca2018-04-26 15:42:54 +0100461 StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset);
David Sehr0225f8e2018-01-31 08:52:24 +0000462 CodeItemDataAccessor accessor(m->DexInstructionData());
Mathieu Chartier808c7a52017-12-15 11:19:33 -0800463 const size_t number_of_vregs = accessor.RegistersSize();
David Srbecky052f8ca2018-04-26 15:42:54 +0100464 uint32_t register_mask = code_info.GetRegisterMaskOf(stack_map);
465 BitMemoryRegion stack_mask = code_info.GetStackMaskOf(stack_map);
David Brazdilefc3f022015-10-28 12:19:06 -0500466 DexRegisterMap vreg_map = IsInInlinedFrame()
David Srbecky93bd3612018-07-02 19:30:18 +0100467 ? code_info.GetInlineDexRegisterMapOf(stack_map, GetCurrentInlinedFrame())
David Srbeckyfd89b072018-06-03 12:00:22 +0100468 : code_info.GetDexRegisterMapOf(stack_map);
Artem Serov2808be82018-12-20 19:15:11 +0000469
Alex Light6fc471e2020-03-03 16:51:33 -0800470 if (kIsDebugBuild || UNLIKELY(Runtime::Current()->IsJavaDebuggable())) {
471 CHECK_EQ(vreg_map.size(), number_of_vregs) << *Thread::Current()
472 << "Deopting: " << m->PrettyMethod()
473 << " inlined? "
474 << std::boolalpha << IsInInlinedFrame();
475 }
David Srbeckyfd89b072018-06-03 12:00:22 +0100476 if (vreg_map.empty()) {
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000477 return;
478 }
479
Nicolas Geoffray33856502015-10-20 15:52:58 +0100480 for (uint16_t vreg = 0; vreg < number_of_vregs; ++vreg) {
481 if (updated_vregs != nullptr && updated_vregs[vreg]) {
482 // Keep the value set by debugger.
483 continue;
484 }
485
David Srbeckye1402122018-06-13 18:20:45 +0100486 DexRegisterLocation::Kind location = vreg_map[vreg].GetKind();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100487 static constexpr uint32_t kDeadValue = 0xEBADDE09;
488 uint32_t value = kDeadValue;
489 bool is_reference = false;
490
491 switch (location) {
492 case DexRegisterLocation::Kind::kInStack: {
David Srbeckye1402122018-06-13 18:20:45 +0100493 const int32_t offset = vreg_map[vreg].GetStackOffsetInBytes();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100494 const uint8_t* addr = reinterpret_cast<const uint8_t*>(GetCurrentQuickFrame()) + offset;
495 value = *reinterpret_cast<const uint32_t*>(addr);
496 uint32_t bit = (offset >> 2);
David Srbecky4b59d102018-05-29 21:46:10 +0000497 if (bit < stack_mask.size_in_bits() && stack_mask.LoadBit(bit)) {
Nicolas Geoffray33856502015-10-20 15:52:58 +0100498 is_reference = true;
499 }
500 break;
501 }
502 case DexRegisterLocation::Kind::kInRegister:
503 case DexRegisterLocation::Kind::kInRegisterHigh:
504 case DexRegisterLocation::Kind::kInFpuRegister:
505 case DexRegisterLocation::Kind::kInFpuRegisterHigh: {
David Srbeckye1402122018-06-13 18:20:45 +0100506 uint32_t reg = vreg_map[vreg].GetMachineRegister();
Nicolas Geoffray6624d582020-09-01 15:02:00 +0100507 bool result = GetRegisterIfAccessible(reg, location, &value);
Nicolas Geoffray33856502015-10-20 15:52:58 +0100508 CHECK(result);
509 if (location == DexRegisterLocation::Kind::kInRegister) {
510 if (((1u << reg) & register_mask) != 0) {
511 is_reference = true;
512 }
513 }
514 break;
515 }
516 case DexRegisterLocation::Kind::kConstant: {
David Srbeckye1402122018-06-13 18:20:45 +0100517 value = vreg_map[vreg].GetConstant();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100518 if (value == 0) {
519 // Make it a reference for extra safety.
520 is_reference = true;
521 }
522 break;
523 }
524 case DexRegisterLocation::Kind::kNone: {
525 break;
526 }
527 default: {
David Srbeckye1402122018-06-13 18:20:45 +0100528 LOG(FATAL) << "Unexpected location kind " << vreg_map[vreg].GetKind();
Nicolas Geoffray33856502015-10-20 15:52:58 +0100529 UNREACHABLE();
530 }
531 }
532 if (is_reference) {
533 new_frame->SetVRegReference(vreg, reinterpret_cast<mirror::Object*>(value));
534 } else {
535 new_frame->SetVReg(vreg, value);
536 }
537 }
538 }
539
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200540 static VRegKind GetVRegKind(uint16_t reg, const std::vector<int32_t>& kinds) {
Vladimir Marko35d5b8a2018-07-03 09:18:32 +0100541 return static_cast<VRegKind>(kinds[reg * 2]);
Sebastien Hertzc901dd72014-07-16 11:56:07 +0200542 }
543
Ian Rogers5cf98192014-05-29 21:31:50 -0700544 QuickExceptionHandler* const exception_handler_;
545 ShadowFrame* prev_shadow_frame_;
Mingyao Yang1f2d3ba2015-05-18 12:12:50 -0700546 bool stacked_shadow_frame_pushed_;
Andreas Gampe639bdd12015-06-03 11:22:45 -0700547 const bool single_frame_deopt_;
548 bool single_frame_done_;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100549 ArtMethod* single_frame_deopt_method_;
Nicolas Geoffrayb52de242016-02-19 12:43:12 +0000550 const OatQuickMethodHeader* single_frame_deopt_quick_method_header_;
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700551 ArtMethod* callee_method_;
Ian Rogers5cf98192014-05-29 21:31:50 -0700552
553 DISALLOW_COPY_AND_ASSIGN(DeoptimizeStackVisitor);
554};
555
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700556void QuickExceptionHandler::PrepareForLongJumpToInvokeStubOrInterpreterBridge() {
557 if (full_fragment_done_) {
558 // Restore deoptimization exception. When returning from the invoke stub,
559 // ArtMethod::Invoke() will see the special exception to know deoptimization
560 // is needed.
561 self_->SetException(Thread::GetDeoptimizationException());
562 } else {
563 // PC needs to be of the quick-to-interpreter bridge.
564 int32_t offset;
Andreas Gampe542451c2016-07-26 09:02:02 -0700565 offset = GetThreadOffset<kRuntimePointerSize>(kQuickQuickToInterpreterBridge).Int32Value();
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700566 handler_quick_frame_pc_ = *reinterpret_cast<uintptr_t*>(
567 reinterpret_cast<uint8_t*>(self_) + offset);
568 }
569}
570
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200571void QuickExceptionHandler::DeoptimizeStack() {
572 DCHECK(is_deoptimization_);
Ian Rogers5cf98192014-05-29 21:31:50 -0700573 if (kDebugExceptionDelivery) {
Andreas Gampe3fec9ac2016-09-13 10:47:28 -0700574 self_->DumpStack(LOG_STREAM(INFO) << "Deoptimizing: ");
Ian Rogers5cf98192014-05-29 21:31:50 -0700575 }
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200576
Andreas Gampe639bdd12015-06-03 11:22:45 -0700577 DeoptimizeStackVisitor visitor(self_, context_, this, false);
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200578 visitor.WalkStack(true);
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700579 PrepareForLongJumpToInvokeStubOrInterpreterBridge();
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100580}
581
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +0100582void QuickExceptionHandler::DeoptimizeSingleFrame(DeoptimizationKind kind) {
Andreas Gampe639bdd12015-06-03 11:22:45 -0700583 DCHECK(is_deoptimization_);
584
Andreas Gampe639bdd12015-06-03 11:22:45 -0700585 DeoptimizeStackVisitor visitor(self_, context_, this, true);
586 visitor.WalkStack(true);
587
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +0000588 // Compiled code made an explicit deoptimization.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100589 ArtMethod* deopt_method = visitor.GetSingleFrameDeoptMethod();
Nicolas Geoffray62e7c092019-01-08 09:43:01 +0000590 SCOPED_TRACE << "Deoptimizing "
591 << deopt_method->PrettyMethod()
592 << ": " << GetDeoptimizationKindName(kind);
593
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100594 DCHECK(deopt_method != nullptr);
Nicolas Geoffray646d6382017-08-09 10:50:00 +0100595 if (VLOG_IS_ON(deopt) || kDebugExceptionDelivery) {
596 LOG(INFO) << "Single-frame deopting: "
597 << deopt_method->PrettyMethod()
598 << " due to "
599 << GetDeoptimizationKindName(kind);
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700600 DumpFramesWithType(self_, /* details= */ true);
Nicolas Geoffray646d6382017-08-09 10:50:00 +0100601 }
Mythri Alle5097f832021-11-02 14:52:30 +0000602 // When deoptimizing for debug support the optimized code is still valid and
603 // can be reused when debugging support (like breakpoints) are no longer
604 // needed fot this method.
605 if (Runtime::Current()->UseJitCompilation() && (kind != DeoptimizationKind::kDebugging)) {
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +0000606 Runtime::Current()->GetJit()->GetCodeCache()->InvalidateCompiledCodeFor(
Nicolas Geoffrayb52de242016-02-19 12:43:12 +0000607 deopt_method, visitor.GetSingleFrameDeoptQuickMethodHeader());
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +0000608 } else {
Nicolas Geoffrayc8a694d2022-01-17 17:12:38 +0000609 Runtime::Current()->GetInstrumentation()->InitializeMethodsCode(
610 deopt_method, /*aot_code=*/ nullptr);
Nicolas Geoffrayb88d59e2016-02-17 11:31:49 +0000611 }
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100612
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700613 PrepareForLongJumpToInvokeStubOrInterpreterBridge();
Andreas Gampe639bdd12015-06-03 11:22:45 -0700614}
615
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700616void QuickExceptionHandler::DeoptimizePartialFragmentFixup(uintptr_t return_pc) {
617 // At this point, the instrumentation stack has been updated. We need to install
618 // the real return pc on stack, in case instrumentation stub is stored there,
Mythri Allee1f96382022-01-19 16:44:59 +0000619 // so that the interpreter bridge code can return to the right place. JITed
620 // frames in Java debuggable runtimes may not have an instrumentation stub, so
621 // update the PC only when required.
622 uintptr_t* pc_addr = reinterpret_cast<uintptr_t*>(handler_quick_frame_);
623 CHECK(pc_addr != nullptr);
624 pc_addr--;
625 if (return_pc != 0 &&
626 (*reinterpret_cast<uintptr_t*>(pc_addr)) ==
627 reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc())) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700628 *reinterpret_cast<uintptr_t*>(pc_addr) = return_pc;
629 }
Andreas Gampe639bdd12015-06-03 11:22:45 -0700630
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700631 // Architecture-dependent work. This is to get the LR right for x86 and x86-64.
Andreas Gampe639bdd12015-06-03 11:22:45 -0700632 if (kRuntimeISA == InstructionSet::kX86 || kRuntimeISA == InstructionSet::kX86_64) {
633 // On x86, the return address is on the stack, so just reuse it. Otherwise we would have to
634 // change how longjump works.
635 handler_quick_frame_ = reinterpret_cast<ArtMethod**>(
636 reinterpret_cast<uintptr_t>(handler_quick_frame_) - sizeof(void*));
637 }
638}
639
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700640uintptr_t QuickExceptionHandler::UpdateInstrumentationStack() {
Alex Light2c8206f2018-06-08 14:51:09 -0700641 DCHECK(is_deoptimization_) << "Non-deoptimization handlers should use FindCatch";
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700642 uintptr_t return_pc = 0;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100643 if (method_tracing_active_) {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100644 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Nicolas Geoffraye91e7952020-01-23 10:15:56 +0000645 return_pc = instrumentation->PopFramesForDeoptimization(
646 self_, reinterpret_cast<uintptr_t>(handler_quick_frame_));
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100647 }
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700648 return return_pc;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100649}
650
Andreas Gampe639bdd12015-06-03 11:22:45 -0700651void QuickExceptionHandler::DoLongJump(bool smash_caller_saves) {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100652 // Place context back on thread so it will be available when we continue.
653 self_->ReleaseLongJumpContext(context_);
654 context_->SetSP(reinterpret_cast<uintptr_t>(handler_quick_frame_));
655 CHECK_NE(handler_quick_frame_pc_, 0u);
656 context_->SetPC(handler_quick_frame_pc_);
Andreas Gampe639bdd12015-06-03 11:22:45 -0700657 context_->SetArg0(handler_quick_arg0_);
658 if (smash_caller_saves) {
659 context_->SmashCallerSaves();
660 }
Nicolas Geoffray51ad7fe2020-02-04 12:46:47 +0000661 if (!is_deoptimization_ &&
Nicolas Geoffray013d1ee2019-12-04 16:18:15 +0000662 handler_method_header_ != nullptr &&
663 handler_method_header_->IsNterpMethodHeader()) {
664 context_->SetNterpDexPC(reinterpret_cast<uintptr_t>(
Nicolas Geoffray51ad7fe2020-02-04 12:46:47 +0000665 GetHandlerMethod()->DexInstructions().Insns() + handler_dex_pc_));
Nicolas Geoffray013d1ee2019-12-04 16:18:15 +0000666 }
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100667 context_->DoLongJump();
Andreas Gampe794ad762015-02-23 08:12:24 -0800668 UNREACHABLE();
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100669}
670
Andreas Gampe639bdd12015-06-03 11:22:45 -0700671void QuickExceptionHandler::DumpFramesWithType(Thread* self, bool details) {
Andreas Gampec7d878d2018-11-19 18:42:06 +0000672 StackVisitor::WalkStack(
673 [&](const art::StackVisitor* stack_visitor) REQUIRES_SHARED(Locks::mutator_lock_) {
674 ArtMethod* method = stack_visitor->GetMethod();
675 if (details) {
676 LOG(INFO) << "|> pc = " << std::hex << stack_visitor->GetCurrentQuickFramePc();
677 LOG(INFO) << "|> addr = " << std::hex
678 << reinterpret_cast<uintptr_t>(stack_visitor->GetCurrentQuickFrame());
679 if (stack_visitor->GetCurrentQuickFrame() != nullptr && method != nullptr) {
680 LOG(INFO) << "|> ret = " << std::hex << stack_visitor->GetReturnPc();
681 }
682 }
683 if (method == nullptr) {
684 // Transition, do go on, we want to unwind over bridges, all the way.
685 if (details) {
686 LOG(INFO) << "N <transition>";
687 }
688 return true;
689 } else if (method->IsRuntimeMethod()) {
690 if (details) {
691 LOG(INFO) << "R " << method->PrettyMethod(true);
692 }
693 return true;
694 } else {
695 bool is_shadow = stack_visitor->GetCurrentShadowFrame() != nullptr;
696 LOG(INFO) << (is_shadow ? "S" : "Q")
697 << ((!is_shadow && stack_visitor->IsInInlinedFrame()) ? "i" : " ")
698 << " "
699 << method->PrettyMethod(true);
700 return true; // Go on.
701 }
702 },
703 self,
704 /* context= */ nullptr,
705 art::StackVisitor::StackWalkKind::kIncludeInlinedFrames);
Andreas Gampe639bdd12015-06-03 11:22:45 -0700706}
707
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100708} // namespace art