blob: 8d10a97b68d063a5db1c45af3d8336dae9a499fc [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"
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010022#include "sirt_ref.h"
23#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;
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020053 uint32_t found_dex_pc = method->FindCatchBlock(to_find_, dex_pc, &clear_exception);
54 exception_handler_->SetClearException(clear_exception);
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010055 if (found_dex_pc != DexFile::kDexNoIndex) {
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020056 exception_handler_->SetHandlerDexPc(found_dex_pc);
57 exception_handler_->SetHandlerQuickFramePc(method->ToNativePc(found_dex_pc));
58 exception_handler_->SetHandlerQuickFrame(GetCurrentQuickFrame());
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010059 return false; // End stack walk.
60 }
61 }
62 return true; // Continue stack walk.
63}
64
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010065} // namespace art