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 | |
| 17 | #include "catch_block_stack_visitor.h" |
| 18 | |
| 19 | #include "dex_instruction.h" |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 20 | #include "mirror/art_method-inl.h" |
| 21 | #include "quick_exception_handler.h" |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 22 | #include "handle_scope-inl.h" |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 23 | #include "verifier/method_verifier.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | bool CatchBlockStackVisitor::VisitFrame() { |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 28 | exception_handler_->SetHandlerFrameId(GetFrameId()); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 29 | mirror::ArtMethod* method = GetMethod(); |
| 30 | if (method == nullptr) { |
| 31 | // This is the upcall, we remember the frame and last pc so that we may long jump to them. |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 32 | exception_handler_->SetHandlerQuickFramePc(GetCurrentQuickFramePc()); |
| 33 | exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame()); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 34 | return false; // End stack walk. |
| 35 | } else { |
| 36 | if (method->IsRuntimeMethod()) { |
| 37 | // Ignore callee save method. |
| 38 | DCHECK(method->IsCalleeSaveMethod()); |
| 39 | return true; |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 40 | } else { |
| 41 | return HandleTryItems(method); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | bool CatchBlockStackVisitor::HandleTryItems(mirror::ArtMethod* method) { |
| 47 | uint32_t dex_pc = DexFile::kDexNoIndex; |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 48 | if (!method->IsNative()) { |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 49 | dex_pc = GetDexPc(); |
| 50 | } |
| 51 | if (dex_pc != DexFile::kDexNoIndex) { |
| 52 | bool clear_exception = false; |
Andreas Gampe | 72b3e43 | 2014-05-13 21:42:05 -0700 | [diff] [blame] | 53 | bool exc_changed = false; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 54 | StackHandleScope<1> hs(Thread::Current()); |
| 55 | Handle<mirror::Class> to_find(hs.NewHandle((*exception_)->GetClass())); |
Andreas Gampe | 72b3e43 | 2014-05-13 21:42:05 -0700 | [diff] [blame] | 56 | uint32_t found_dex_pc = method->FindCatchBlock(to_find, dex_pc, &clear_exception, |
| 57 | &exc_changed); |
| 58 | if (UNLIKELY(exc_changed)) { |
| 59 | DCHECK_EQ(DexFile::kDexNoIndex, found_dex_pc); |
| 60 | exception_->Assign(self_->GetException(nullptr)); // TODO: Throw location? |
| 61 | // There is a new context installed, delete it. |
| 62 | delete self_->GetLongJumpContext(); |
| 63 | } |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 64 | exception_handler_->SetClearException(clear_exception); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 65 | if (found_dex_pc != DexFile::kDexNoIndex) { |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 66 | exception_handler_->SetHandlerDexPc(found_dex_pc); |
| 67 | exception_handler_->SetHandlerQuickFramePc(method->ToNativePc(found_dex_pc)); |
| 68 | exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame()); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 69 | return false; // End stack walk. |
| 70 | } |
| 71 | } |
| 72 | return true; // Continue stack walk. |
| 73 | } |
| 74 | |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 75 | } // namespace art |