blob: 162b1dc74c59f72bb074d096893d8a91d6963400 [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"
Andreas Gampe794ad762015-02-23 08:12:24 -080021#include "base/macros.h"
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020022#include "base/mutex.h"
Andreas Gampecf4035a2014-05-28 22:43:01 -070023#include "stack.h" // StackReference
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010024
25namespace art {
26
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020027namespace mirror {
28class ArtMethod;
29class Throwable;
30} // namespace mirror
31class Context;
32class Thread;
33class ThrowLocation;
34class ShadowFrame;
35
Elliott Hughes956af0f2014-12-11 14:34:28 -080036// Manages exception delivery for Quick backend.
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020037class QuickExceptionHandler {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010038 public:
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020039 QuickExceptionHandler(Thread* self, bool is_deoptimization)
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010040 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
41
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020042 ~QuickExceptionHandler() {
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010043 LOG(FATAL) << "UNREACHABLE"; // Expected to take long jump.
Ian Rogers2c4257b2014-10-24 14:20:06 -070044 UNREACHABLE();
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010045 }
46
Sebastien Hertz9f102032014-05-23 08:59:42 +020047 void FindCatch(const ThrowLocation& throw_location, mirror::Throwable* exception,
48 bool is_exception_reported)
Sebastien Hertzfd3077e2014-04-23 10:32:43 +020049 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_);
Andreas Gampe794ad762015-02-23 08:12:24 -080052 NO_RETURN void DoLongJump() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010053
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
Ian Rogers5cf98192014-05-29 21:31:50 -070062 mirror::ArtMethod* GetHandlerMethod() const {
63 return handler_method_;
64 }
65
66 void SetHandlerMethod(mirror::ArtMethod* handler_quick_method) {
67 handler_method_ = handler_quick_method;
68 }
69
70 uint32_t GetHandlerDexPc() const {
71 return handler_dex_pc_;
72 }
73
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010074 void SetHandlerDexPc(uint32_t dex_pc) {
75 handler_dex_pc_ = dex_pc;
76 }
77
78 void SetClearException(bool clear_exception) {
79 clear_exception_ = clear_exception;
80 }
81
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -070082 void SetHandlerFrameDepth(size_t frame_depth) {
83 handler_frame_depth_ = frame_depth;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010084 }
85
86 private:
87 Thread* const self_;
88 Context* const context_;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010089 const bool is_deoptimization_;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010090 // Is method tracing active?
91 const bool method_tracing_active_;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010092 // Quick frame with found handler or last frame if no handler found.
Andreas Gampecf4035a2014-05-28 22:43:01 -070093 StackReference<mirror::ArtMethod>* handler_quick_frame_;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010094 // PC to branch to for the handler.
95 uintptr_t handler_quick_frame_pc_;
Ian Rogers5cf98192014-05-29 21:31:50 -070096 // The handler method to report to the debugger.
97 mirror::ArtMethod* handler_method_;
98 // The handler's dex PC, zero implies an uncaught exception.
Sebastien Hertzd45a1f52014-01-09 14:56:54 +010099 uint32_t handler_dex_pc_;
100 // Should the exception be cleared as the catch block has no move-exception?
101 bool clear_exception_;
Hiroshi Yamauchi649278c2014-08-13 11:12:22 -0700102 // Frame depth of the catch handler or the upcall.
103 size_t handler_frame_depth_;
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100104
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200105 DISALLOW_COPY_AND_ASSIGN(QuickExceptionHandler);
Sebastien Hertzd45a1f52014-01-09 14:56:54 +0100106};
107
108} // namespace art
Sebastien Hertzfd3077e2014-04-23 10:32:43 +0200109#endif // ART_RUNTIME_QUICK_EXCEPTION_HANDLER_H_