blob: 55b330a48ef21146999d0f347bd66f460ff9b672 [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
17#include "catch_block_stack_visitor.h"
18
19#include "dex_instruction.h"
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020020#include "mirror/art_method-inl.h"
21#include "quick_exception_handler.h"
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070022#include "handle_scope-inl.h"
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010023#include "verifier/method_verifier.h"
24
25namespace art {
26
27bool CatchBlockStackVisitor::VisitFrame() {
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020028 exception_handler_->SetHandlerFrameId(GetFrameId());
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010029 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 Hertzfd3077e2014-04-23 10:32:43 +020032 exception_handler_->SetHandlerQuickFramePc(GetCurrentQuickFramePc());
33 exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame());
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010034 return false; // End stack walk.
35 } else {
36 if (method->IsRuntimeMethod()) {
37 // Ignore callee save method.
38 DCHECK(method->IsCalleeSaveMethod());
39 return true;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010040 } else {
41 return HandleTryItems(method);
42 }
43 }
44}
45
46bool CatchBlockStackVisitor::HandleTryItems(mirror::ArtMethod* method) {
47 uint32_t dex_pc = DexFile::kDexNoIndex;
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020048 if (!method->IsNative()) {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010049 dex_pc = GetDexPc();
50 }
51 if (dex_pc != DexFile::kDexNoIndex) {
52 bool clear_exception = false;
Andreas Gampe72b3e432014-05-13 21:42:05 -070053 bool exc_changed = false;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070054 StackHandleScope<1> hs(Thread::Current());
55 Handle<mirror::Class> to_find(hs.NewHandle((*exception_)->GetClass()));
Andreas Gampe72b3e432014-05-13 21:42:05 -070056 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 Hertzfd3077e2014-04-23 10:32:43 +020064 exception_handler_->SetClearException(clear_exception);
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010065 if (found_dex_pc != DexFile::kDexNoIndex) {
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020066 exception_handler_->SetHandlerDexPc(found_dex_pc);
67 exception_handler_->SetHandlerQuickFramePc(method->ToNativePc(found_dex_pc));
68 exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame());
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010069 return false; // End stack walk.
70 }
71 }
72 return true; // Continue stack walk.
73}
74
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010075} // namespace art