blob: ebbafe2580883ebe36fd08b972f392e79f3b048c [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#ifndef ART_RUNTIME_CATCH_FINDER_H_
18#define ART_RUNTIME_CATCH_FINDER_H_
19
20#include "mirror/art_method-inl.h"
21#include "thread.h"
22
23namespace art {
24
25static constexpr bool kDebugExceptionDelivery = false;
26static constexpr size_t kInvalidFrameId = 0xffffffff;
27
28// Manages exception delivery for Quick backend. Not used by Portable backend.
29class CatchFinder {
30 public:
31 CatchFinder(Thread* self, const ThrowLocation& throw_location, mirror::Throwable* exception,
32 bool is_deoptimization)
33 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
34
35 ~CatchFinder() {
36 LOG(FATAL) << "UNREACHABLE"; // Expected to take long jump.
37 }
38
39 void FindCatch() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
40 void UpdateInstrumentationStack() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
41 void DoLongJump() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
42
43 void SetHandlerQuickFrame(mirror::ArtMethod** handler_quick_frame) {
44 handler_quick_frame_ = handler_quick_frame;
45 }
46
47 void SetHandlerQuickFramePc(uintptr_t handler_quick_frame_pc) {
48 handler_quick_frame_pc_ = handler_quick_frame_pc;
49 }
50
51 void SetHandlerDexPc(uint32_t dex_pc) {
52 handler_dex_pc_ = dex_pc;
53 }
54
55 void SetClearException(bool clear_exception) {
56 clear_exception_ = clear_exception;
57 }
58
59 void SetTopShadowFrame(ShadowFrame* top_shadow_frame) {
60 top_shadow_frame_ = top_shadow_frame;
61 }
62
63 void SetHandlerFrameId(size_t frame_id) {
64 handler_frame_id_ = frame_id;
65 }
66
67 private:
68 Thread* const self_;
69 Context* const context_;
70 mirror::Throwable* const exception_;
71 const bool is_deoptimization_;
72 // Location of the throw.
73 const ThrowLocation& throw_location_;
74 // Is method tracing active?
75 const bool method_tracing_active_;
76 // Support for nesting no thread suspension checks.
77 const char* last_no_assert_suspension_cause_;
78 // Quick frame with found handler or last frame if no handler found.
79 mirror::ArtMethod** handler_quick_frame_;
80 // PC to branch to for the handler.
81 uintptr_t handler_quick_frame_pc_;
82 // Associated dex PC.
83 uint32_t handler_dex_pc_;
84 // Should the exception be cleared as the catch block has no move-exception?
85 bool clear_exception_;
86 // Deoptimization top shadow frame.
87 ShadowFrame* top_shadow_frame_;
88 // Frame id of the catch handler or the upcall.
89 size_t handler_frame_id_;
90
91 DISALLOW_COPY_AND_ASSIGN(CatchFinder);
92};
93
94} // namespace art
95#endif // ART_RUNTIME_CATCH_FINDER_H_