blob: 2597ebd5c72ebcda8cc3a0f35c24a6c48981b109 [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
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020017#ifndef ART_RUNTIME_QUICK_EXCEPTION_HANDLER_H_
18#define ART_RUNTIME_QUICK_EXCEPTION_HANDLER_H_
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010019
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020020#include "base/logging.h"
21#include "base/mutex.h"
Andreas Gampecf4035a2014-05-28 22:43:01 -070022#include "stack.h" // StackReference
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010023
24namespace art {
25
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020026namespace mirror {
27class ArtMethod;
28class Throwable;
29} // namespace mirror
30class Context;
31class Thread;
32class ThrowLocation;
33class ShadowFrame;
34
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010035static constexpr bool kDebugExceptionDelivery = false;
36static constexpr size_t kInvalidFrameId = 0xffffffff;
37
38// Manages exception delivery for Quick backend. Not used by Portable backend.
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020039class QuickExceptionHandler {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010040 public:
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020041 QuickExceptionHandler(Thread* self, bool is_deoptimization)
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010042 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
43
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020044 ~QuickExceptionHandler() {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010045 LOG(FATAL) << "UNREACHABLE"; // Expected to take long jump.
46 }
47
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020048 void FindCatch(const ThrowLocation& throw_location, mirror::Throwable* exception)
49 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
50 void DeoptimizeStack() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010051 void UpdateInstrumentationStack() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
52 void DoLongJump() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
53
Andreas Gampecf4035a2014-05-28 22:43:01 -070054 void SetHandlerQuickFrame(StackReference<mirror::ArtMethod>* handler_quick_frame) {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010055 handler_quick_frame_ = handler_quick_frame;
56 }
57
58 void SetHandlerQuickFramePc(uintptr_t handler_quick_frame_pc) {
59 handler_quick_frame_pc_ = handler_quick_frame_pc;
60 }
61
62 void SetHandlerDexPc(uint32_t dex_pc) {
63 handler_dex_pc_ = dex_pc;
64 }
65
66 void SetClearException(bool clear_exception) {
67 clear_exception_ = clear_exception;
68 }
69
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010070 void SetHandlerFrameId(size_t frame_id) {
71 handler_frame_id_ = frame_id;
72 }
73
74 private:
75 Thread* const self_;
76 Context* const context_;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010077 const bool is_deoptimization_;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010078 // Is method tracing active?
79 const bool method_tracing_active_;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010080 // Quick frame with found handler or last frame if no handler found.
Andreas Gampecf4035a2014-05-28 22:43:01 -070081 StackReference<mirror::ArtMethod>* handler_quick_frame_;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010082 // PC to branch to for the handler.
83 uintptr_t handler_quick_frame_pc_;
84 // Associated dex PC.
85 uint32_t handler_dex_pc_;
86 // Should the exception be cleared as the catch block has no move-exception?
87 bool clear_exception_;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010088 // Frame id of the catch handler or the upcall.
89 size_t handler_frame_id_;
90
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020091 DISALLOW_COPY_AND_ASSIGN(QuickExceptionHandler);
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010092};
93
94} // namespace art
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020095#endif // ART_RUNTIME_QUICK_EXCEPTION_HANDLER_H_