Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 1 | /* |
| 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 Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 17 | #include "quick_exception_handler.h" |
| 18 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 19 | #include "arch/context.h" |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 20 | #include "art_code.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method-inl.h" |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 22 | #include "dex_instruction.h" |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 23 | #include "entrypoints/entrypoint_utils.h" |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 25 | #include "entrypoints/runtime_asm_entrypoints.h" |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 26 | #include "handle_scope-inl.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
| 28 | #include "mirror/class_loader.h" |
| 29 | #include "mirror/throwable.h" |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 30 | #include "stack_map.h" |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 31 | #include "verifier/method_verifier.h" |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 35 | static constexpr bool kDebugExceptionDelivery = false; |
Hiroshi Yamauchi | 649278c | 2014-08-13 11:12:22 -0700 | [diff] [blame] | 36 | static constexpr size_t kInvalidFrameDepth = 0xffffffff; |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 37 | |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 38 | QuickExceptionHandler::QuickExceptionHandler(Thread* self, bool is_deoptimization) |
| 39 | : self_(self), context_(self->GetLongJumpContext()), is_deoptimization_(is_deoptimization), |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 40 | method_tracing_active_(is_deoptimization || |
| 41 | Runtime::Current()->GetInstrumentation()->AreExitStubsInstalled()), |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 42 | handler_quick_frame_(nullptr), handler_quick_frame_pc_(0), handler_quick_arg0_(0), |
| 43 | handler_method_(nullptr), handler_dex_pc_(0), clear_exception_(false), |
| 44 | handler_frame_depth_(kInvalidFrameDepth) { |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 45 | } |
| 46 | |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 47 | // Finds catch handler. |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 48 | class CatchBlockStackVisitor FINAL : public StackVisitor { |
| 49 | public: |
| 50 | CatchBlockStackVisitor(Thread* self, Context* context, Handle<mirror::Throwable>* exception, |
| 51 | QuickExceptionHandler* exception_handler) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 52 | SHARED_REQUIRES(Locks::mutator_lock_) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 53 | : StackVisitor(self, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames), |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 54 | exception_(exception), |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 55 | exception_handler_(exception_handler) { |
| 56 | } |
| 57 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 58 | bool VisitFrame() OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 59 | ArtMethod* method = GetMethod(); |
Hiroshi Yamauchi | 649278c | 2014-08-13 11:12:22 -0700 | [diff] [blame] | 60 | exception_handler_->SetHandlerFrameDepth(GetFrameDepth()); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 61 | if (method == nullptr) { |
| 62 | // This is the upcall, we remember the frame and last pc so that we may long jump to them. |
| 63 | exception_handler_->SetHandlerQuickFramePc(GetCurrentQuickFramePc()); |
| 64 | exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame()); |
| 65 | uint32_t next_dex_pc; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 66 | ArtMethod* next_art_method; |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 67 | bool has_next = GetNextMethodAndDexPc(&next_art_method, &next_dex_pc); |
| 68 | // Report the method that did the down call as the handler. |
| 69 | exception_handler_->SetHandlerDexPc(next_dex_pc); |
| 70 | exception_handler_->SetHandlerMethod(next_art_method); |
| 71 | if (!has_next) { |
| 72 | // No next method? Check exception handler is set up for the unhandled exception handler |
| 73 | // case. |
| 74 | DCHECK_EQ(0U, exception_handler_->GetHandlerDexPc()); |
| 75 | DCHECK(nullptr == exception_handler_->GetHandlerMethod()); |
| 76 | } |
| 77 | return false; // End stack walk. |
| 78 | } |
| 79 | if (method->IsRuntimeMethod()) { |
| 80 | // Ignore callee save method. |
| 81 | DCHECK(method->IsCalleeSaveMethod()); |
| 82 | return true; |
| 83 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 84 | return HandleTryItems(method); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | private: |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 88 | bool HandleTryItems(ArtMethod* method) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 89 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 90 | uint32_t dex_pc = DexFile::kDexNoIndex; |
| 91 | if (!method->IsNative()) { |
| 92 | dex_pc = GetDexPc(); |
| 93 | } |
| 94 | if (dex_pc != DexFile::kDexNoIndex) { |
| 95 | bool clear_exception = false; |
Sebastien Hertz | 26f7286 | 2015-09-15 09:52:07 +0200 | [diff] [blame] | 96 | StackHandleScope<1> hs(GetThread()); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 97 | Handle<mirror::Class> to_find(hs.NewHandle((*exception_)->GetClass())); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 98 | uint32_t found_dex_pc = method->FindCatchBlock(to_find, dex_pc, &clear_exception); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 99 | exception_handler_->SetClearException(clear_exception); |
| 100 | if (found_dex_pc != DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 101 | exception_handler_->SetHandlerMethod(method); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 102 | exception_handler_->SetHandlerDexPc(found_dex_pc); |
David Brazdil | 72f7b88 | 2015-09-15 17:00:52 +0100 | [diff] [blame] | 103 | exception_handler_->SetHandlerQuickFramePc( |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 104 | GetCurrentCode().ToNativeQuickPc(found_dex_pc, /* is_catch_handler */ true)); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 105 | exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame()); |
| 106 | return false; // End stack walk. |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 107 | } else if (UNLIKELY(GetThread()->HasDebuggerShadowFrames())) { |
| 108 | // We are going to unwind this frame. Did we prepare a shadow frame for debugging? |
| 109 | size_t frame_id = GetFrameId(); |
| 110 | ShadowFrame* frame = GetThread()->FindDebuggerShadowFrame(frame_id); |
| 111 | if (frame != nullptr) { |
| 112 | // We will not execute this shadow frame so we can safely deallocate it. |
| 113 | GetThread()->RemoveDebuggerShadowFrameMapping(frame_id); |
| 114 | ShadowFrame::DeleteDeoptimizedFrame(frame); |
| 115 | } |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | return true; // Continue stack walk. |
| 119 | } |
| 120 | |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 121 | // The exception we're looking for the catch block of. |
| 122 | Handle<mirror::Throwable>* exception_; |
| 123 | // The quick exception handler we're visiting for. |
| 124 | QuickExceptionHandler* const exception_handler_; |
| 125 | |
| 126 | DISALLOW_COPY_AND_ASSIGN(CatchBlockStackVisitor); |
| 127 | }; |
| 128 | |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 129 | void QuickExceptionHandler::FindCatch(mirror::Throwable* exception) { |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 130 | DCHECK(!is_deoptimization_); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 131 | if (kDebugExceptionDelivery) { |
| 132 | mirror::String* msg = exception->GetDetailMessage(); |
| 133 | std::string str_msg(msg != nullptr ? msg->ToModifiedUtf8() : ""); |
| 134 | self_->DumpStack(LOG(INFO) << "Delivering exception: " << PrettyTypeOf(exception) |
| 135 | << ": " << str_msg << "\n"); |
| 136 | } |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 137 | StackHandleScope<1> hs(self_); |
| 138 | Handle<mirror::Throwable> exception_ref(hs.NewHandle(exception)); |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 139 | |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 140 | // Walk the stack to find catch handler. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 141 | CatchBlockStackVisitor visitor(self_, context_, &exception_ref, this); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 142 | visitor.WalkStack(true); |
| 143 | |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 144 | if (kDebugExceptionDelivery) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 145 | if (*handler_quick_frame_ == nullptr) { |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 146 | LOG(INFO) << "Handler is upcall"; |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 147 | } |
| 148 | if (handler_method_ != nullptr) { |
| 149 | const DexFile& dex_file = *handler_method_->GetDeclaringClass()->GetDexCache()->GetDexFile(); |
| 150 | int line_number = dex_file.GetLineNumFromPC(handler_method_, handler_dex_pc_); |
| 151 | LOG(INFO) << "Handler: " << PrettyMethod(handler_method_) << " (line: " << line_number << ")"; |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | if (clear_exception_) { |
| 155 | // Exception was cleared as part of delivery. |
| 156 | DCHECK(!self_->IsExceptionPending()); |
| 157 | } else { |
| 158 | // Put exception back in root set with clear throw location. |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 159 | self_->SetException(exception_ref.Get()); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 160 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 161 | // If the handler is in optimized code, we need to set the catch environment. |
| 162 | if (*handler_quick_frame_ != nullptr && |
| 163 | handler_method_ != nullptr && |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 164 | ArtCode(handler_quick_frame_).IsOptimized(sizeof(void*))) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 165 | SetCatchEnvironmentForOptimizedHandler(&visitor); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | static VRegKind ToVRegKind(DexRegisterLocation::Kind kind) { |
| 170 | // Slightly hacky since we cannot map DexRegisterLocationKind and VRegKind |
| 171 | // one to one. However, StackVisitor::GetVRegFromOptimizedCode only needs to |
| 172 | // distinguish between core/FPU registers and low/high bits on 64-bit. |
| 173 | switch (kind) { |
| 174 | case DexRegisterLocation::Kind::kConstant: |
| 175 | case DexRegisterLocation::Kind::kInStack: |
| 176 | // VRegKind is ignored. |
| 177 | return VRegKind::kUndefined; |
| 178 | |
| 179 | case DexRegisterLocation::Kind::kInRegister: |
| 180 | // Selects core register. For 64-bit registers, selects low 32 bits. |
| 181 | return VRegKind::kLongLoVReg; |
| 182 | |
| 183 | case DexRegisterLocation::Kind::kInRegisterHigh: |
| 184 | // Selects core register. For 64-bit registers, selects high 32 bits. |
| 185 | return VRegKind::kLongHiVReg; |
| 186 | |
| 187 | case DexRegisterLocation::Kind::kInFpuRegister: |
| 188 | // Selects FPU register. For 64-bit registers, selects low 32 bits. |
| 189 | return VRegKind::kDoubleLoVReg; |
| 190 | |
| 191 | case DexRegisterLocation::Kind::kInFpuRegisterHigh: |
| 192 | // Selects FPU register. For 64-bit registers, selects high 32 bits. |
| 193 | return VRegKind::kDoubleHiVReg; |
| 194 | |
| 195 | default: |
| 196 | LOG(FATAL) << "Unexpected vreg location " |
| 197 | << DexRegisterLocation::PrettyDescriptor(kind); |
| 198 | UNREACHABLE(); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | void QuickExceptionHandler::SetCatchEnvironmentForOptimizedHandler(StackVisitor* stack_visitor) { |
| 203 | DCHECK(!is_deoptimization_); |
| 204 | DCHECK(*handler_quick_frame_ != nullptr) << "Method should not be called on upcall exceptions"; |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 205 | DCHECK(handler_method_ != nullptr && ArtCode(handler_quick_frame_).IsOptimized(sizeof(void*))); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 206 | |
| 207 | if (kDebugExceptionDelivery) { |
| 208 | self_->DumpStack(LOG(INFO) << "Setting catch phis: "); |
| 209 | } |
| 210 | |
| 211 | const size_t number_of_vregs = handler_method_->GetCodeItem()->registers_size_; |
Nicolas Geoffray | 6bc4374 | 2015-10-12 18:11:10 +0100 | [diff] [blame^] | 212 | CodeInfo code_info = ArtCode(handler_quick_frame_).GetOptimizedCodeInfo(); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 213 | StackMapEncoding encoding = code_info.ExtractEncoding(); |
| 214 | |
| 215 | // Find stack map of the throwing instruction. |
| 216 | StackMap throw_stack_map = |
| 217 | code_info.GetStackMapForNativePcOffset(stack_visitor->GetNativePcOffset(), encoding); |
| 218 | DCHECK(throw_stack_map.IsValid()); |
| 219 | DexRegisterMap throw_vreg_map = |
| 220 | code_info.GetDexRegisterMapOf(throw_stack_map, encoding, number_of_vregs); |
| 221 | |
| 222 | // Find stack map of the catch block. |
| 223 | StackMap catch_stack_map = code_info.GetCatchStackMapForDexPc(GetHandlerDexPc(), encoding); |
| 224 | DCHECK(catch_stack_map.IsValid()); |
| 225 | DexRegisterMap catch_vreg_map = |
| 226 | code_info.GetDexRegisterMapOf(catch_stack_map, encoding, number_of_vregs); |
| 227 | |
| 228 | // Copy values between them. |
| 229 | for (uint16_t vreg = 0; vreg < number_of_vregs; ++vreg) { |
| 230 | DexRegisterLocation::Kind catch_location = |
| 231 | catch_vreg_map.GetLocationKind(vreg, number_of_vregs, code_info, encoding); |
| 232 | if (catch_location == DexRegisterLocation::Kind::kNone) { |
| 233 | continue; |
| 234 | } |
| 235 | DCHECK(catch_location == DexRegisterLocation::Kind::kInStack); |
| 236 | |
| 237 | // Get vreg value from its current location. |
| 238 | uint32_t vreg_value; |
| 239 | VRegKind vreg_kind = ToVRegKind(throw_vreg_map.GetLocationKind(vreg, |
| 240 | number_of_vregs, |
| 241 | code_info, |
| 242 | encoding)); |
| 243 | bool get_vreg_success = stack_visitor->GetVReg(stack_visitor->GetMethod(), |
| 244 | vreg, |
| 245 | vreg_kind, |
| 246 | &vreg_value); |
| 247 | CHECK(get_vreg_success) << "VReg " << vreg << " was optimized out (" |
| 248 | << "method=" << PrettyMethod(stack_visitor->GetMethod()) << ", " |
| 249 | << "dex_pc=" << stack_visitor->GetDexPc() << ", " |
| 250 | << "native_pc_offset=" << stack_visitor->GetNativePcOffset() << ")"; |
| 251 | |
| 252 | // Copy value to the catch phi's stack slot. |
| 253 | int32_t slot_offset = catch_vreg_map.GetStackOffsetInBytes(vreg, |
| 254 | number_of_vregs, |
| 255 | code_info, |
| 256 | encoding); |
| 257 | ArtMethod** frame_top = stack_visitor->GetCurrentQuickFrame(); |
| 258 | uint8_t* slot_address = reinterpret_cast<uint8_t*>(frame_top) + slot_offset; |
| 259 | uint32_t* slot_ptr = reinterpret_cast<uint32_t*>(slot_address); |
| 260 | *slot_ptr = vreg_value; |
| 261 | } |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 262 | } |
| 263 | |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 264 | // Prepares deoptimization. |
| 265 | class DeoptimizeStackVisitor FINAL : public StackVisitor { |
| 266 | public: |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 267 | DeoptimizeStackVisitor(Thread* self, |
| 268 | Context* context, |
| 269 | QuickExceptionHandler* exception_handler, |
| 270 | bool single_frame) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 271 | SHARED_REQUIRES(Locks::mutator_lock_) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 272 | : StackVisitor(self, context, StackVisitor::StackWalkKind::kIncludeInlinedFrames), |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 273 | exception_handler_(exception_handler), |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 274 | prev_shadow_frame_(nullptr), |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 275 | stacked_shadow_frame_pushed_(false), |
| 276 | single_frame_deopt_(single_frame), |
| 277 | single_frame_done_(false) { |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 280 | bool VisitFrame() OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 649278c | 2014-08-13 11:12:22 -0700 | [diff] [blame] | 281 | exception_handler_->SetHandlerFrameDepth(GetFrameDepth()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 282 | ArtMethod* method = GetMethod(); |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 283 | if (method == nullptr || single_frame_done_) { |
| 284 | // This is the upcall (or the next full frame in single-frame deopt), we remember the frame |
| 285 | // and last pc so that we may long jump to them. |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 286 | exception_handler_->SetHandlerQuickFramePc(GetCurrentQuickFramePc()); |
| 287 | exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame()); |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 288 | if (!stacked_shadow_frame_pushed_) { |
| 289 | // In case there is no deoptimized shadow frame for this upcall, we still |
| 290 | // need to push a nullptr to the stack since there is always a matching pop after |
| 291 | // the long jump. |
Sebastien Hertz | 26f7286 | 2015-09-15 09:52:07 +0200 | [diff] [blame] | 292 | GetThread()->PushStackedShadowFrame(nullptr, |
| 293 | StackedShadowFrameType::kDeoptimizationShadowFrame); |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 294 | stacked_shadow_frame_pushed_ = true; |
| 295 | } |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 296 | return false; // End stack walk. |
| 297 | } else if (method->IsRuntimeMethod()) { |
| 298 | // Ignore callee save method. |
| 299 | DCHECK(method->IsCalleeSaveMethod()); |
| 300 | return true; |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 301 | } else if (method->IsNative()) { |
| 302 | // If we return from JNI with a pending exception and want to deoptimize, we need to skip |
| 303 | // the native method. |
| 304 | // The top method is a runtime method, the native method comes next. |
| 305 | CHECK_EQ(GetFrameDepth(), 1U); |
| 306 | return true; |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 307 | } else { |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 308 | HandleDeoptimization(method); |
| 309 | if (single_frame_deopt_ && !IsInInlinedFrame()) { |
| 310 | // Single-frame deopt ends at the first non-inlined frame and needs to store that method. |
| 311 | exception_handler_->SetHandlerQuickArg0(reinterpret_cast<uintptr_t>(method)); |
| 312 | single_frame_done_ = true; |
| 313 | } |
| 314 | return true; |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
| 318 | private: |
Sebastien Hertz | c901dd7 | 2014-07-16 11:56:07 +0200 | [diff] [blame] | 319 | static VRegKind GetVRegKind(uint16_t reg, const std::vector<int32_t>& kinds) { |
| 320 | return static_cast<VRegKind>(kinds.at(reg * 2)); |
| 321 | } |
| 322 | |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 323 | void HandleDeoptimization(ArtMethod* m) SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 324 | const DexFile::CodeItem* code_item = m->GetCodeItem(); |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 325 | CHECK(code_item != nullptr) << "No code item for " << PrettyMethod(m); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 326 | uint16_t num_regs = code_item->registers_size_; |
| 327 | uint32_t dex_pc = GetDexPc(); |
Sebastien Hertz | 26f7286 | 2015-09-15 09:52:07 +0200 | [diff] [blame] | 328 | StackHandleScope<2> hs(GetThread()); // Dex cache, class loader and method. |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 329 | mirror::Class* declaring_class = m->GetDeclaringClass(); |
| 330 | Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(declaring_class->GetDexCache())); |
| 331 | Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(declaring_class->GetClassLoader())); |
Sebastien Hertz | 26f7286 | 2015-09-15 09:52:07 +0200 | [diff] [blame] | 332 | verifier::MethodVerifier verifier(GetThread(), h_dex_cache->GetDexFile(), h_dex_cache, |
| 333 | h_class_loader, &m->GetClassDef(), code_item, |
| 334 | m->GetDexMethodIndex(), m, m->GetAccessFlags(), true, true, |
| 335 | true, true); |
Andreas Gampe | 2e04bb2 | 2015-02-10 15:37:27 -0800 | [diff] [blame] | 336 | bool verifier_success = verifier.Verify(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 337 | CHECK(verifier_success) << PrettyMethod(m); |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 338 | // Check if a shadow frame already exists for debugger's set-local-value purpose. |
| 339 | const size_t frame_id = GetFrameId(); |
| 340 | ShadowFrame* new_frame = GetThread()->FindDebuggerShadowFrame(frame_id); |
| 341 | const bool* updated_vregs; |
| 342 | if (new_frame == nullptr) { |
| 343 | new_frame = ShadowFrame::CreateDeoptimizedFrame(num_regs, nullptr, m, dex_pc); |
| 344 | updated_vregs = nullptr; |
| 345 | } else { |
| 346 | updated_vregs = GetThread()->GetUpdatedVRegFlags(frame_id); |
| 347 | DCHECK(updated_vregs != nullptr); |
| 348 | } |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 349 | { |
Sebastien Hertz | 26f7286 | 2015-09-15 09:52:07 +0200 | [diff] [blame] | 350 | ScopedStackedShadowFramePusher pusher(GetThread(), new_frame, |
Sebastien Hertz | f795869 | 2015-06-09 14:09:14 +0200 | [diff] [blame] | 351 | StackedShadowFrameType::kShadowFrameUnderConstruction); |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 352 | const std::vector<int32_t> kinds(verifier.DescribeVRegs(dex_pc)); |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 353 | |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 354 | // Markers for dead values, used when the verifier knows a Dex register is undefined, |
| 355 | // or when the compiler knows the register has not been initialized, or is not used |
| 356 | // anymore in the method. |
| 357 | static constexpr uint32_t kDeadValue = 0xEBADDE09; |
| 358 | static constexpr uint64_t kLongDeadValue = 0xEBADDE09EBADDE09; |
| 359 | for (uint16_t reg = 0; reg < num_regs; ++reg) { |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 360 | if (updated_vregs != nullptr && updated_vregs[reg]) { |
| 361 | // Keep the value set by debugger. |
| 362 | continue; |
| 363 | } |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 364 | VRegKind kind = GetVRegKind(reg, kinds); |
| 365 | switch (kind) { |
| 366 | case kUndefined: |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 367 | new_frame->SetVReg(reg, kDeadValue); |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 368 | break; |
| 369 | case kConstant: |
| 370 | new_frame->SetVReg(reg, kinds.at((reg * 2) + 1)); |
| 371 | break; |
| 372 | case kReferenceVReg: { |
| 373 | uint32_t value = 0; |
| 374 | // Check IsReferenceVReg in case the compiled GC map doesn't agree with the verifier. |
| 375 | // We don't want to copy a stale reference into the shadow frame as a reference. |
| 376 | // b/20736048 |
| 377 | if (GetVReg(m, reg, kind, &value) && IsReferenceVReg(m, reg)) { |
| 378 | new_frame->SetVRegReference(reg, reinterpret_cast<mirror::Object*>(value)); |
| 379 | } else { |
| 380 | new_frame->SetVReg(reg, kDeadValue); |
| 381 | } |
| 382 | break; |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 383 | } |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 384 | case kLongLoVReg: |
| 385 | if (GetVRegKind(reg + 1, kinds) == kLongHiVReg) { |
| 386 | // Treat it as a "long" register pair. |
| 387 | uint64_t value = 0; |
| 388 | if (GetVRegPair(m, reg, kLongLoVReg, kLongHiVReg, &value)) { |
| 389 | new_frame->SetVRegLong(reg, value); |
| 390 | } else { |
| 391 | new_frame->SetVRegLong(reg, kLongDeadValue); |
| 392 | } |
| 393 | } else { |
| 394 | uint32_t value = 0; |
| 395 | if (GetVReg(m, reg, kind, &value)) { |
| 396 | new_frame->SetVReg(reg, value); |
| 397 | } else { |
| 398 | new_frame->SetVReg(reg, kDeadValue); |
| 399 | } |
| 400 | } |
| 401 | break; |
| 402 | case kLongHiVReg: |
| 403 | if (GetVRegKind(reg - 1, kinds) == kLongLoVReg) { |
| 404 | // Nothing to do: we treated it as a "long" register pair. |
| 405 | } else { |
| 406 | uint32_t value = 0; |
| 407 | if (GetVReg(m, reg, kind, &value)) { |
| 408 | new_frame->SetVReg(reg, value); |
| 409 | } else { |
| 410 | new_frame->SetVReg(reg, kDeadValue); |
| 411 | } |
| 412 | } |
| 413 | break; |
| 414 | case kDoubleLoVReg: |
| 415 | if (GetVRegKind(reg + 1, kinds) == kDoubleHiVReg) { |
| 416 | uint64_t value = 0; |
| 417 | if (GetVRegPair(m, reg, kDoubleLoVReg, kDoubleHiVReg, &value)) { |
| 418 | // Treat it as a "double" register pair. |
| 419 | new_frame->SetVRegLong(reg, value); |
| 420 | } else { |
| 421 | new_frame->SetVRegLong(reg, kLongDeadValue); |
| 422 | } |
| 423 | } else { |
| 424 | uint32_t value = 0; |
| 425 | if (GetVReg(m, reg, kind, &value)) { |
| 426 | new_frame->SetVReg(reg, value); |
| 427 | } else { |
| 428 | new_frame->SetVReg(reg, kDeadValue); |
| 429 | } |
| 430 | } |
| 431 | break; |
| 432 | case kDoubleHiVReg: |
| 433 | if (GetVRegKind(reg - 1, kinds) == kDoubleLoVReg) { |
| 434 | // Nothing to do: we treated it as a "double" register pair. |
| 435 | } else { |
| 436 | uint32_t value = 0; |
| 437 | if (GetVReg(m, reg, kind, &value)) { |
| 438 | new_frame->SetVReg(reg, value); |
| 439 | } else { |
| 440 | new_frame->SetVReg(reg, kDeadValue); |
| 441 | } |
| 442 | } |
| 443 | break; |
| 444 | default: |
| 445 | uint32_t value = 0; |
| 446 | if (GetVReg(m, reg, kind, &value)) { |
| 447 | new_frame->SetVReg(reg, value); |
| 448 | } else { |
| 449 | new_frame->SetVReg(reg, kDeadValue); |
| 450 | } |
| 451 | break; |
Nicolas Geoffray | 15b9d52 | 2015-03-12 15:05:13 +0000 | [diff] [blame] | 452 | } |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 453 | } |
| 454 | } |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 455 | if (updated_vregs != nullptr) { |
| 456 | // Calling Thread::RemoveDebuggerShadowFrameMapping will also delete the updated_vregs |
| 457 | // array so this must come after we processed the frame. |
| 458 | GetThread()->RemoveDebuggerShadowFrameMapping(frame_id); |
| 459 | DCHECK(GetThread()->FindDebuggerShadowFrame(frame_id) == nullptr); |
| 460 | } |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 461 | if (prev_shadow_frame_ != nullptr) { |
| 462 | prev_shadow_frame_->SetLink(new_frame); |
| 463 | } else { |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 464 | // Will be popped after the long jump after DeoptimizeStack(), |
| 465 | // right before interpreter::EnterInterpreterFromDeoptimize(). |
| 466 | stacked_shadow_frame_pushed_ = true; |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 467 | GetThread()->PushStackedShadowFrame( |
| 468 | new_frame, |
| 469 | single_frame_deopt_ |
| 470 | ? StackedShadowFrameType::kSingleFrameDeoptimizationShadowFrame |
| 471 | : StackedShadowFrameType::kDeoptimizationShadowFrame); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 472 | } |
| 473 | prev_shadow_frame_ = new_frame; |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 476 | QuickExceptionHandler* const exception_handler_; |
| 477 | ShadowFrame* prev_shadow_frame_; |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 478 | bool stacked_shadow_frame_pushed_; |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 479 | const bool single_frame_deopt_; |
| 480 | bool single_frame_done_; |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 481 | |
| 482 | DISALLOW_COPY_AND_ASSIGN(DeoptimizeStackVisitor); |
| 483 | }; |
| 484 | |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 485 | void QuickExceptionHandler::DeoptimizeStack() { |
| 486 | DCHECK(is_deoptimization_); |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 487 | if (kDebugExceptionDelivery) { |
| 488 | self_->DumpStack(LOG(INFO) << "Deoptimizing: "); |
| 489 | } |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 490 | |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 491 | DeoptimizeStackVisitor visitor(self_, context_, this, false); |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 492 | visitor.WalkStack(true); |
| 493 | |
| 494 | // Restore deoptimization exception |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 495 | self_->SetException(Thread::GetDeoptimizationException()); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 496 | } |
| 497 | |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 498 | void QuickExceptionHandler::DeoptimizeSingleFrame() { |
| 499 | DCHECK(is_deoptimization_); |
| 500 | |
| 501 | if (VLOG_IS_ON(deopt) || kDebugExceptionDelivery) { |
| 502 | LOG(INFO) << "Single-frame deopting:"; |
| 503 | DumpFramesWithType(self_, true); |
| 504 | } |
| 505 | |
| 506 | DeoptimizeStackVisitor visitor(self_, context_, this, true); |
| 507 | visitor.WalkStack(true); |
| 508 | |
| 509 | // PC needs to be of the quick-to-interpreter bridge. |
| 510 | int32_t offset; |
| 511 | #ifdef __LP64__ |
| 512 | offset = GetThreadOffset<8>(kQuickQuickToInterpreterBridge).Int32Value(); |
| 513 | #else |
| 514 | offset = GetThreadOffset<4>(kQuickQuickToInterpreterBridge).Int32Value(); |
| 515 | #endif |
| 516 | handler_quick_frame_pc_ = *reinterpret_cast<uintptr_t*>( |
| 517 | reinterpret_cast<uint8_t*>(self_) + offset); |
| 518 | } |
| 519 | |
| 520 | void QuickExceptionHandler::DeoptimizeSingleFrameArchDependentFixup() { |
| 521 | // Architecture-dependent work. This is to get the LR right for x86 and x86-64. |
| 522 | |
| 523 | if (kRuntimeISA == InstructionSet::kX86 || kRuntimeISA == InstructionSet::kX86_64) { |
| 524 | // On x86, the return address is on the stack, so just reuse it. Otherwise we would have to |
| 525 | // change how longjump works. |
| 526 | handler_quick_frame_ = reinterpret_cast<ArtMethod**>( |
| 527 | reinterpret_cast<uintptr_t>(handler_quick_frame_) - sizeof(void*)); |
| 528 | } |
| 529 | } |
| 530 | |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 531 | // Unwinds all instrumentation stack frame prior to catch handler or upcall. |
| 532 | class InstrumentationStackVisitor : public StackVisitor { |
| 533 | public: |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 534 | InstrumentationStackVisitor(Thread* self, size_t frame_depth) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 535 | SHARED_REQUIRES(Locks::mutator_lock_) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 536 | : StackVisitor(self, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames), |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 537 | frame_depth_(frame_depth), |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 538 | instrumentation_frames_to_pop_(0) { |
Hiroshi Yamauchi | 649278c | 2014-08-13 11:12:22 -0700 | [diff] [blame] | 539 | CHECK_NE(frame_depth_, kInvalidFrameDepth); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 540 | } |
| 541 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 542 | bool VisitFrame() SHARED_REQUIRES(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 649278c | 2014-08-13 11:12:22 -0700 | [diff] [blame] | 543 | size_t current_frame_depth = GetFrameDepth(); |
| 544 | if (current_frame_depth < frame_depth_) { |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 545 | CHECK(GetMethod() != nullptr); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 546 | if (UNLIKELY(reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()) == GetReturnPc())) { |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 547 | if (!IsInInlinedFrame()) { |
| 548 | // We do not count inlined frames, because we do not instrument them. The reason we |
| 549 | // include them in the stack walking is the check against `frame_depth_`, which is |
| 550 | // given to us by a visitor that visits inlined frames. |
| 551 | ++instrumentation_frames_to_pop_; |
| 552 | } |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 553 | } |
| 554 | return true; |
| 555 | } else { |
| 556 | // We reached the frame of the catch handler or the upcall. |
| 557 | return false; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | size_t GetInstrumentationFramesToPop() const { |
| 562 | return instrumentation_frames_to_pop_; |
| 563 | } |
| 564 | |
| 565 | private: |
Hiroshi Yamauchi | 649278c | 2014-08-13 11:12:22 -0700 | [diff] [blame] | 566 | const size_t frame_depth_; |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 567 | size_t instrumentation_frames_to_pop_; |
| 568 | |
| 569 | DISALLOW_COPY_AND_ASSIGN(InstrumentationStackVisitor); |
| 570 | }; |
| 571 | |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 572 | void QuickExceptionHandler::UpdateInstrumentationStack() { |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 573 | if (method_tracing_active_) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 574 | InstrumentationStackVisitor visitor(self_, handler_frame_depth_); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 575 | visitor.WalkStack(true); |
| 576 | |
| 577 | size_t instrumentation_frames_to_pop = visitor.GetInstrumentationFramesToPop(); |
| 578 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 579 | for (size_t i = 0; i < instrumentation_frames_to_pop; ++i) { |
| 580 | instrumentation->PopMethodForUnwind(self_, is_deoptimization_); |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 585 | void QuickExceptionHandler::DoLongJump(bool smash_caller_saves) { |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 586 | // Place context back on thread so it will be available when we continue. |
| 587 | self_->ReleaseLongJumpContext(context_); |
| 588 | context_->SetSP(reinterpret_cast<uintptr_t>(handler_quick_frame_)); |
| 589 | CHECK_NE(handler_quick_frame_pc_, 0u); |
| 590 | context_->SetPC(handler_quick_frame_pc_); |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 591 | context_->SetArg0(handler_quick_arg0_); |
| 592 | if (smash_caller_saves) { |
| 593 | context_->SmashCallerSaves(); |
| 594 | } |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 595 | context_->DoLongJump(); |
Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 596 | UNREACHABLE(); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 597 | } |
| 598 | |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 599 | // Prints out methods with their type of frame. |
| 600 | class DumpFramesWithTypeStackVisitor FINAL : public StackVisitor { |
| 601 | public: |
| 602 | DumpFramesWithTypeStackVisitor(Thread* self, bool show_details = false) |
| 603 | SHARED_REQUIRES(Locks::mutator_lock_) |
| 604 | : StackVisitor(self, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames), |
| 605 | show_details_(show_details) {} |
| 606 | |
| 607 | bool VisitFrame() OVERRIDE SHARED_REQUIRES(Locks::mutator_lock_) { |
| 608 | ArtMethod* method = GetMethod(); |
| 609 | if (show_details_) { |
| 610 | LOG(INFO) << "|> pc = " << std::hex << GetCurrentQuickFramePc(); |
| 611 | LOG(INFO) << "|> addr = " << std::hex << reinterpret_cast<uintptr_t>(GetCurrentQuickFrame()); |
| 612 | if (GetCurrentQuickFrame() != nullptr && method != nullptr) { |
| 613 | LOG(INFO) << "|> ret = " << std::hex << GetReturnPc(); |
| 614 | } |
| 615 | } |
| 616 | if (method == nullptr) { |
| 617 | // Transition, do go on, we want to unwind over bridges, all the way. |
| 618 | if (show_details_) { |
| 619 | LOG(INFO) << "N <transition>"; |
| 620 | } |
| 621 | return true; |
| 622 | } else if (method->IsRuntimeMethod()) { |
| 623 | if (show_details_) { |
| 624 | LOG(INFO) << "R " << PrettyMethod(method, true); |
| 625 | } |
| 626 | return true; |
| 627 | } else { |
| 628 | bool is_shadow = GetCurrentShadowFrame() != nullptr; |
| 629 | LOG(INFO) << (is_shadow ? "S" : "Q") |
| 630 | << ((!is_shadow && IsInInlinedFrame()) ? "i" : " ") |
| 631 | << " " |
| 632 | << PrettyMethod(method, true); |
| 633 | return true; // Go on. |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | private: |
| 638 | bool show_details_; |
| 639 | |
| 640 | DISALLOW_COPY_AND_ASSIGN(DumpFramesWithTypeStackVisitor); |
| 641 | }; |
| 642 | |
| 643 | void QuickExceptionHandler::DumpFramesWithType(Thread* self, bool details) { |
| 644 | DumpFramesWithTypeStackVisitor visitor(self, details); |
| 645 | visitor.WalkStack(true); |
| 646 | } |
| 647 | |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 648 | } // namespace art |