Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 1 | /* |
| 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 Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_QUICK_EXCEPTION_HANDLER_H_ |
| 18 | #define ART_RUNTIME_QUICK_EXCEPTION_HANDLER_H_ |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 19 | |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 20 | #include "base/logging.h" |
Andreas Gampe | 794ad76 | 2015-02-23 08:12:24 -0800 | [diff] [blame] | 21 | #include "base/macros.h" |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 22 | #include "base/mutex.h" |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 23 | #include "stack.h" // StackReference |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 27 | namespace mirror { |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 28 | class Throwable; |
| 29 | } // namespace mirror |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 30 | class ArtMethod; |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 31 | class Context; |
| 32 | class Thread; |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 33 | class ShadowFrame; |
| 34 | |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 35 | // Manages exception delivery for Quick backend. |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 36 | class QuickExceptionHandler { |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 37 | public: |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 38 | QuickExceptionHandler(Thread* self, bool is_deoptimization) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 39 | SHARED_REQUIRES(Locks::mutator_lock_); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 40 | |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 41 | NO_RETURN ~QuickExceptionHandler() { |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 42 | LOG(FATAL) << "UNREACHABLE"; // Expected to take long jump. |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 43 | UNREACHABLE(); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 46 | void FindCatch(mirror::Throwable* exception) SHARED_REQUIRES(Locks::mutator_lock_); |
| 47 | void DeoptimizeStack() SHARED_REQUIRES(Locks::mutator_lock_); |
| 48 | void UpdateInstrumentationStack() SHARED_REQUIRES(Locks::mutator_lock_); |
| 49 | NO_RETURN void DoLongJump() SHARED_REQUIRES(Locks::mutator_lock_); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 50 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 51 | void SetHandlerQuickFrame(ArtMethod** handler_quick_frame) { |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 52 | handler_quick_frame_ = handler_quick_frame; |
| 53 | } |
| 54 | |
| 55 | void SetHandlerQuickFramePc(uintptr_t handler_quick_frame_pc) { |
| 56 | handler_quick_frame_pc_ = handler_quick_frame_pc; |
| 57 | } |
| 58 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 59 | ArtMethod* GetHandlerMethod() const { |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 60 | return handler_method_; |
| 61 | } |
| 62 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 63 | void SetHandlerMethod(ArtMethod* handler_quick_method) { |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 64 | handler_method_ = handler_quick_method; |
| 65 | } |
| 66 | |
| 67 | uint32_t GetHandlerDexPc() const { |
| 68 | return handler_dex_pc_; |
| 69 | } |
| 70 | |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 71 | void SetHandlerDexPc(uint32_t dex_pc) { |
| 72 | handler_dex_pc_ = dex_pc; |
| 73 | } |
| 74 | |
| 75 | void SetClearException(bool clear_exception) { |
| 76 | clear_exception_ = clear_exception; |
| 77 | } |
| 78 | |
Hiroshi Yamauchi | 649278c | 2014-08-13 11:12:22 -0700 | [diff] [blame] | 79 | void SetHandlerFrameDepth(size_t frame_depth) { |
| 80 | handler_frame_depth_ = frame_depth; |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | private: |
| 84 | Thread* const self_; |
| 85 | Context* const context_; |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 86 | const bool is_deoptimization_; |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 87 | // Is method tracing active? |
| 88 | const bool method_tracing_active_; |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 89 | // Quick frame with found handler or last frame if no handler found. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 90 | ArtMethod** handler_quick_frame_; |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 91 | // PC to branch to for the handler. |
| 92 | uintptr_t handler_quick_frame_pc_; |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 93 | // The handler method to report to the debugger. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 94 | ArtMethod* handler_method_; |
Ian Rogers | 5cf9819 | 2014-05-29 21:31:50 -0700 | [diff] [blame] | 95 | // The handler's dex PC, zero implies an uncaught exception. |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 96 | uint32_t handler_dex_pc_; |
| 97 | // Should the exception be cleared as the catch block has no move-exception? |
| 98 | bool clear_exception_; |
Hiroshi Yamauchi | 649278c | 2014-08-13 11:12:22 -0700 | [diff] [blame] | 99 | // Frame depth of the catch handler or the upcall. |
| 100 | size_t handler_frame_depth_; |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 101 | |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 102 | DISALLOW_COPY_AND_ASSIGN(QuickExceptionHandler); |
Sebastien Hertz | d45a1f5 | 2014-01-09 14:56:54 +0100 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | } // namespace art |
Sebastien Hertz | fd3077e | 2014-04-23 10:32:43 +0200 | [diff] [blame] | 106 | #endif // ART_RUNTIME_QUICK_EXCEPTION_HANDLER_H_ |