jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_INSTRUMENTATION_H_ |
| 18 | #define ART_RUNTIME_INSTRUMENTATION_H_ |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 19 | |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 20 | #include <functional> |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 22 | #include <list> |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 23 | #include <memory> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 24 | #include <unordered_set> |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 25 | #include <optional> |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 26 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 27 | #include "arch/instruction_set.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 28 | #include "base/enums.h" |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 29 | #include "base/locks.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 30 | #include "base/macros.h" |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 31 | #include "base/safe_map.h" |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 32 | #include "gc_root.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 34 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | namespace mirror { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 36 | class Class; |
| 37 | class Object; |
| 38 | class Throwable; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 39 | } // namespace mirror |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 40 | class ArtField; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 41 | class ArtMethod; |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 42 | template <typename T> class Handle; |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 43 | template <typename T> class MutableHandle; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 44 | union JValue; |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 45 | class SHARED_LOCKABLE ReaderWriterMutex; |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 46 | class ShadowFrame; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 47 | class Thread; |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 48 | enum class DeoptimizationMethodType; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 49 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 50 | namespace instrumentation { |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 51 | |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 52 | // Interpreter handler tables. |
| 53 | enum InterpreterHandlerTable { |
| 54 | kMainHandlerTable = 0, // Main handler table: no suspend check, no instrumentation. |
| 55 | kAlternativeHandlerTable = 1, // Alternative handler table: suspend check and/or instrumentation |
| 56 | // enabled. |
| 57 | kNumHandlerTables |
| 58 | }; |
| 59 | |
Andreas Gampe | 40da286 | 2015-02-27 12:49:04 -0800 | [diff] [blame] | 60 | // Do we want to deoptimize for method entry and exit listeners or just try to intercept |
| 61 | // invocations? Deoptimization forces all code to run in the interpreter and considerably hurts the |
| 62 | // application's performance. |
| 63 | static constexpr bool kDeoptimizeForAccurateMethodEntryExitListeners = true; |
| 64 | |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 65 | // an optional frame is either Some(const ShadowFrame& current_frame) or None depending on if the |
| 66 | // method being exited has a shadow-frame associed with the current stack frame. In cases where |
| 67 | // there is no shadow-frame associated with this stack frame this will be None. |
| 68 | using OptionalFrame = std::optional<std::reference_wrapper<const ShadowFrame>>; |
| 69 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 70 | // Instrumentation event listener API. Registered listeners will get the appropriate call back for |
| 71 | // the events they are listening for. The call backs supply the thread, method and dex_pc the event |
| 72 | // occurred upon. The thread may or may not be Thread::Current(). |
| 73 | struct InstrumentationListener { |
| 74 | InstrumentationListener() {} |
| 75 | virtual ~InstrumentationListener() {} |
| 76 | |
| 77 | // Call-back for when a method is entered. |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 78 | virtual void MethodEntered(Thread* thread, |
| 79 | Handle<mirror::Object> this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 80 | ArtMethod* method, |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 81 | uint32_t dex_pc) REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 82 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 83 | virtual void MethodExited(Thread* thread, |
| 84 | Handle<mirror::Object> this_object, |
| 85 | ArtMethod* method, |
| 86 | uint32_t dex_pc, |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 87 | OptionalFrame frame, |
| 88 | MutableHandle<mirror::Object>& return_value) |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 89 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 90 | |
| 91 | // Call-back for when a method is exited. The implementor should either handler-ize the return |
| 92 | // value (if appropriate) or use the alternate MethodExited callback instead if they need to |
| 93 | // go through a suspend point. |
| 94 | virtual void MethodExited(Thread* thread, |
| 95 | Handle<mirror::Object> this_object, |
| 96 | ArtMethod* method, |
| 97 | uint32_t dex_pc, |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 98 | OptionalFrame frame, |
| 99 | JValue& return_value) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 100 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 101 | |
| 102 | // Call-back for when a method is popped due to an exception throw. A method will either cause a |
| 103 | // MethodExited call-back or a MethodUnwind call-back when its activation is removed. |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 104 | virtual void MethodUnwind(Thread* thread, |
| 105 | Handle<mirror::Object> this_object, |
| 106 | ArtMethod* method, |
| 107 | uint32_t dex_pc) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 108 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 109 | |
| 110 | // Call-back for when the dex pc moves in a method. |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 111 | virtual void DexPcMoved(Thread* thread, |
| 112 | Handle<mirror::Object> this_object, |
| 113 | ArtMethod* method, |
| 114 | uint32_t new_dex_pc) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 115 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 116 | |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 117 | // Call-back for when we read from a field. |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 118 | virtual void FieldRead(Thread* thread, |
| 119 | Handle<mirror::Object> this_object, |
| 120 | ArtMethod* method, |
| 121 | uint32_t dex_pc, |
| 122 | ArtField* field) = 0; |
| 123 | |
| 124 | virtual void FieldWritten(Thread* thread, |
| 125 | Handle<mirror::Object> this_object, |
| 126 | ArtMethod* method, |
| 127 | uint32_t dex_pc, |
| 128 | ArtField* field, |
| 129 | Handle<mirror::Object> field_value) |
| 130 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 131 | |
| 132 | // Call-back for when we write into a field. |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 133 | virtual void FieldWritten(Thread* thread, |
| 134 | Handle<mirror::Object> this_object, |
| 135 | ArtMethod* method, |
| 136 | uint32_t dex_pc, |
| 137 | ArtField* field, |
| 138 | const JValue& field_value) |
| 139 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 140 | |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 141 | // Call-back when an exception is thrown. |
| 142 | virtual void ExceptionThrown(Thread* thread, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 143 | Handle<mirror::Throwable> exception_object) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 144 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 145 | |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 146 | // Call-back when an exception is caught/handled by java code. |
| 147 | virtual void ExceptionHandled(Thread* thread, Handle<mirror::Throwable> exception_object) |
| 148 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
| 149 | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 150 | // Call-back for when we execute a branch. |
| 151 | virtual void Branch(Thread* thread, |
| 152 | ArtMethod* method, |
| 153 | uint32_t dex_pc, |
| 154 | int32_t dex_pc_offset) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 155 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 156 | |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 157 | // Call-back when a shadow_frame with the needs_notify_pop_ boolean set is popped off the stack by |
| 158 | // either return or exceptions. Normally instrumentation listeners should ensure that there are |
| 159 | // shadow-frames by deoptimizing stacks. |
| 160 | virtual void WatchedFramePop(Thread* thread ATTRIBUTE_UNUSED, |
| 161 | const ShadowFrame& frame ATTRIBUTE_UNUSED) |
Alex Light | 05f4774 | 2017-09-14 00:34:44 +0000 | [diff] [blame] | 162 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 163 | }; |
| 164 | |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 165 | class Instrumentation; |
| 166 | // A helper to send instrumentation events while popping the stack in a safe way. |
| 167 | class InstrumentationStackPopper { |
| 168 | public: |
| 169 | explicit InstrumentationStackPopper(Thread* self); |
| 170 | ~InstrumentationStackPopper() REQUIRES_SHARED(Locks::mutator_lock_); |
| 171 | |
Nicolas Geoffray | e91e795 | 2020-01-23 10:15:56 +0000 | [diff] [blame] | 172 | // Increase the number of frames being popped up to `stack_pointer`. Return true if the |
| 173 | // frames were popped without any exceptions, false otherwise. The exception that caused |
| 174 | // the pop is 'exception'. |
| 175 | bool PopFramesTo(uintptr_t stack_pointer, /*in-out*/MutableHandle<mirror::Throwable>& exception) |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 176 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 177 | |
| 178 | private: |
| 179 | Thread* self_; |
| 180 | Instrumentation* instrumentation_; |
Nicolas Geoffray | e91e795 | 2020-01-23 10:15:56 +0000 | [diff] [blame] | 181 | // The stack pointer limit for frames to pop. |
| 182 | uintptr_t pop_until_; |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 185 | // Instrumentation is a catch-all for when extra information is required from the runtime. The |
| 186 | // typical use for instrumentation is for profiling and debugging. Instrumentation may add stubs |
| 187 | // to method entry and exit, it may also force execution to be switched to the interpreter and |
| 188 | // trigger deoptimization. |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 189 | class Instrumentation { |
| 190 | public: |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 191 | enum InstrumentationEvent { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 192 | kMethodEntered = 0x1, |
| 193 | kMethodExited = 0x2, |
| 194 | kMethodUnwind = 0x4, |
| 195 | kDexPcMoved = 0x8, |
| 196 | kFieldRead = 0x10, |
| 197 | kFieldWritten = 0x20, |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 198 | kExceptionThrown = 0x40, |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 199 | kBranch = 0x80, |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 200 | kWatchedFramePop = 0x200, |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 201 | kExceptionHandled = 0x400, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 202 | }; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 203 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 204 | enum class InstrumentationLevel { |
| 205 | kInstrumentNothing, // execute without instrumentation |
| 206 | kInstrumentWithInstrumentationStubs, // execute with instrumentation entry/exit stubs |
| 207 | kInstrumentWithInterpreter // execute with interpreter |
| 208 | }; |
| 209 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 210 | Instrumentation(); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 211 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 212 | // Add a listener to be notified of the masked together sent of instrumentation events. This |
| 213 | // suspend the runtime to install stubs. You are expected to hold the mutator lock as a proxy |
| 214 | // for saying you should have suspended all threads (installing stubs while threads are running |
| 215 | // will break). |
| 216 | void AddListener(InstrumentationListener* listener, uint32_t events) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 217 | REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::classlinker_classes_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 218 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 219 | // Removes a listener possibly removing instrumentation stubs. |
| 220 | void RemoveListener(InstrumentationListener* listener, uint32_t events) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 221 | REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::classlinker_classes_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 222 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 223 | // Deoptimization. |
Sebastien Hertz | a76a6d4 | 2014-03-20 16:40:17 +0100 | [diff] [blame] | 224 | void EnableDeoptimization() |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 225 | REQUIRES(Locks::mutator_lock_) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 226 | REQUIRES(!GetDeoptimizedMethodsLock()); |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 227 | // Calls UndeoptimizeEverything which may visit class linker classes through ConfigureStubs. |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 228 | void DisableDeoptimization(const char* key) |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 229 | REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 230 | REQUIRES(!GetDeoptimizedMethodsLock()); |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 231 | |
Sebastien Hertz | a76a6d4 | 2014-03-20 16:40:17 +0100 | [diff] [blame] | 232 | bool AreAllMethodsDeoptimized() const { |
| 233 | return interpreter_stubs_installed_; |
| 234 | } |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 235 | bool ShouldNotifyMethodEnterExitEvents() const REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 236 | |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 237 | bool CanDeoptimize() { |
| 238 | return deoptimization_enabled_; |
| 239 | } |
| 240 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 241 | // Executes everything with interpreter. |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 242 | void DeoptimizeEverything(const char* key) |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 243 | REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_) |
| 244 | REQUIRES(!Locks::thread_list_lock_, |
| 245 | !Locks::classlinker_classes_lock_, |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 246 | !GetDeoptimizedMethodsLock()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 247 | |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 248 | // Executes everything with compiled code (or interpreter if there is no code). May visit class |
| 249 | // linker classes through ConfigureStubs. |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 250 | void UndeoptimizeEverything(const char* key) |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 251 | REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_) |
| 252 | REQUIRES(!Locks::thread_list_lock_, |
| 253 | !Locks::classlinker_classes_lock_, |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 254 | !GetDeoptimizedMethodsLock()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 255 | |
| 256 | // Deoptimize a method by forcing its execution with the interpreter. Nevertheless, a static |
| 257 | // method (except a class initializer) set to the resolution trampoline will be deoptimized only |
| 258 | // once its declaring class is initialized. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 259 | void Deoptimize(ArtMethod* method) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 260 | REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !GetDeoptimizedMethodsLock()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 261 | |
| 262 | // Undeoptimze the method by restoring its entrypoints. Nevertheless, a static method |
| 263 | // (except a class initializer) set to the resolution trampoline will be updated only once its |
| 264 | // declaring class is initialized. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 265 | void Undeoptimize(ArtMethod* method) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 266 | REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !GetDeoptimizedMethodsLock()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 267 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 268 | // Indicates whether the method has been deoptimized so it is executed with the interpreter. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 269 | bool IsDeoptimized(ArtMethod* method) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 270 | REQUIRES(!GetDeoptimizedMethodsLock()) REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 271 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 272 | // Enable method tracing by installing instrumentation entry/exit stubs or interpreter. |
| 273 | void EnableMethodTracing(const char* key, |
| 274 | bool needs_interpreter = kDeoptimizeForAccurateMethodEntryExitListeners) |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 275 | REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_) |
| 276 | REQUIRES(!Locks::thread_list_lock_, |
| 277 | !Locks::classlinker_classes_lock_, |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 278 | !GetDeoptimizedMethodsLock()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 279 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 280 | // Disable method tracing by uninstalling instrumentation entry/exit stubs or interpreter. |
| 281 | void DisableMethodTracing(const char* key) |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 282 | REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_) |
| 283 | REQUIRES(!Locks::thread_list_lock_, |
| 284 | !Locks::classlinker_classes_lock_, |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 285 | !GetDeoptimizedMethodsLock()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 286 | |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 287 | InterpreterHandlerTable GetInterpreterHandlerTable() const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 288 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 289 | return interpreter_handler_table_; |
| 290 | } |
| 291 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 292 | void InstrumentQuickAllocEntryPoints() REQUIRES(!Locks::instrument_entrypoints_lock_); |
| 293 | void UninstrumentQuickAllocEntryPoints() REQUIRES(!Locks::instrument_entrypoints_lock_); |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 294 | void InstrumentQuickAllocEntryPointsLocked() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 295 | REQUIRES(Locks::instrument_entrypoints_lock_, !Locks::thread_list_lock_, |
| 296 | !Locks::runtime_shutdown_lock_); |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 297 | void UninstrumentQuickAllocEntryPointsLocked() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 298 | REQUIRES(Locks::instrument_entrypoints_lock_, !Locks::thread_list_lock_, |
| 299 | !Locks::runtime_shutdown_lock_); |
| 300 | void ResetQuickAllocEntryPoints() REQUIRES(Locks::runtime_shutdown_lock_); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 301 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 302 | // Update the code of a method respecting any installed stubs. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 303 | void UpdateMethodsCode(ArtMethod* method, const void* quick_code) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 304 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!GetDeoptimizedMethodsLock()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 305 | |
Nicolas Geoffray | a6e0e7d | 2018-01-26 13:16:50 +0000 | [diff] [blame] | 306 | // Update the code of a native method to a JITed stub. |
| 307 | void UpdateNativeMethodsCodeToJitCode(ArtMethod* method, const void* quick_code) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 308 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!GetDeoptimizedMethodsLock()); |
Nicolas Geoffray | a6e0e7d | 2018-01-26 13:16:50 +0000 | [diff] [blame] | 309 | |
Alex Light | 0a5ec3d | 2017-07-25 16:50:26 -0700 | [diff] [blame] | 310 | // Update the code of a method to the interpreter respecting any installed stubs from debugger. |
| 311 | void UpdateMethodsCodeToInterpreterEntryPoint(ArtMethod* method) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 312 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!GetDeoptimizedMethodsLock()); |
Alex Light | 0a5ec3d | 2017-07-25 16:50:26 -0700 | [diff] [blame] | 313 | |
Mingyao Yang | 3fd448a | 2016-05-10 14:30:41 -0700 | [diff] [blame] | 314 | // Update the code of a method respecting any installed stubs from debugger. |
Nicolas Geoffray | a0619e2 | 2016-12-20 13:57:43 +0000 | [diff] [blame] | 315 | void UpdateMethodsCodeForJavaDebuggable(ArtMethod* method, const void* quick_code) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 316 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!GetDeoptimizedMethodsLock()); |
Mingyao Yang | 3fd448a | 2016-05-10 14:30:41 -0700 | [diff] [blame] | 317 | |
Alex Light | 2d441b1 | 2018-06-08 15:33:21 -0700 | [diff] [blame] | 318 | // Return the code that we can execute for an invoke including from the JIT. |
| 319 | const void* GetCodeForInvoke(ArtMethod* method) const |
| 320 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 321 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 322 | // Get the quick code for the given method. More efficient than asking the class linker as it |
| 323 | // will short-cut to GetCode if instrumentation and static method resolution stubs aren't |
| 324 | // installed. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 325 | const void* GetQuickCodeFor(ArtMethod* method, PointerSize pointer_size) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 326 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 327 | |
| 328 | void ForceInterpretOnly() { |
| 329 | interpret_only_ = true; |
| 330 | forced_interpret_only_ = true; |
| 331 | } |
| 332 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 333 | // Called by ArtMethod::Invoke to determine dispatch mechanism. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 334 | bool InterpretOnly() const { |
| 335 | return interpret_only_; |
| 336 | } |
| 337 | |
Hiroshi Yamauchi | 563b47c | 2014-02-28 17:18:37 -0800 | [diff] [blame] | 338 | bool IsForcedInterpretOnly() const { |
| 339 | return forced_interpret_only_; |
| 340 | } |
| 341 | |
Mingyao Yang | 6ea1a0e | 2016-01-29 12:12:49 -0800 | [diff] [blame] | 342 | // Code is in boot image oat file which isn't compiled as debuggable. |
| 343 | // Need debug version (interpreter or jitted) if that's the case. |
Nicolas Geoffray | a0619e2 | 2016-12-20 13:57:43 +0000 | [diff] [blame] | 344 | bool NeedDebugVersionFor(ArtMethod* method) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 345 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mingyao Yang | 6ea1a0e | 2016-01-29 12:12:49 -0800 | [diff] [blame] | 346 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 347 | bool AreExitStubsInstalled() const { |
| 348 | return instrumentation_stubs_installed_; |
| 349 | } |
| 350 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 351 | bool HasMethodEntryListeners() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 352 | return have_method_entry_listeners_; |
| 353 | } |
| 354 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 355 | bool HasMethodExitListeners() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 356 | return have_method_exit_listeners_; |
| 357 | } |
| 358 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 359 | bool HasMethodUnwindListeners() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 360 | return have_method_unwind_listeners_; |
| 361 | } |
| 362 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 363 | bool HasDexPcListeners() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 364 | return have_dex_pc_listeners_; |
| 365 | } |
| 366 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 367 | bool HasFieldReadListeners() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 368 | return have_field_read_listeners_; |
| 369 | } |
| 370 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 371 | bool HasFieldWriteListeners() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 372 | return have_field_write_listeners_; |
| 373 | } |
| 374 | |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 375 | bool HasExceptionThrownListeners() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| 376 | return have_exception_thrown_listeners_; |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 377 | } |
| 378 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 379 | bool HasBranchListeners() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 380 | return have_branch_listeners_; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 383 | bool HasWatchedFramePopListeners() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| 384 | return have_watched_frame_pop_listeners_; |
| 385 | } |
| 386 | |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 387 | bool HasExceptionHandledListeners() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| 388 | return have_exception_handled_listeners_; |
| 389 | } |
| 390 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 391 | bool IsActive() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 392 | return have_dex_pc_listeners_ || have_method_entry_listeners_ || have_method_exit_listeners_ || |
Sebastien Hertz | 42cd43f | 2014-05-13 14:15:41 +0200 | [diff] [blame] | 393 | have_field_read_listeners_ || have_field_write_listeners_ || |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 394 | have_exception_thrown_listeners_ || have_method_unwind_listeners_ || |
David Srbecky | 99f9733 | 2018-10-03 15:44:24 +0100 | [diff] [blame] | 395 | have_branch_listeners_ || have_watched_frame_pop_listeners_ || |
| 396 | have_exception_handled_listeners_; |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 399 | // Inform listeners that a method has been entered. A dex PC is provided as we may install |
| 400 | // listeners into executing code and get method enter events for methods already on the stack. |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 401 | void MethodEnterEvent(Thread* thread, |
| 402 | ObjPtr<mirror::Object> this_object, |
| 403 | ArtMethod* method, |
| 404 | uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 405 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 406 | if (UNLIKELY(HasMethodEntryListeners())) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 407 | MethodEnterEventImpl(thread, this_object, method, dex_pc); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | // Inform listeners that a method has been exited. |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 412 | template<typename T> |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 413 | void MethodExitEvent(Thread* thread, |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 414 | ObjPtr<mirror::Object> this_object, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 415 | ArtMethod* method, |
| 416 | uint32_t dex_pc, |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 417 | OptionalFrame frame, |
| 418 | T& return_value) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 419 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 420 | if (UNLIKELY(HasMethodExitListeners())) { |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 421 | MethodExitEventImpl(thread, this_object, method, dex_pc, frame, return_value); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
| 425 | // Inform listeners that a method has been exited due to an exception. |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 426 | void MethodUnwindEvent(Thread* thread, |
| 427 | ObjPtr<mirror::Object> this_object, |
| 428 | ArtMethod* method, |
| 429 | uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 430 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 431 | |
| 432 | // Inform listeners that the dex pc has moved (only supported by the interpreter). |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 433 | void DexPcMovedEvent(Thread* thread, |
| 434 | ObjPtr<mirror::Object> this_object, |
| 435 | ArtMethod* method, |
| 436 | uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 437 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 438 | if (UNLIKELY(HasDexPcListeners())) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 439 | DexPcMovedEventImpl(thread, this_object, method, dex_pc); |
| 440 | } |
| 441 | } |
| 442 | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 443 | // Inform listeners that a branch has been taken (only supported by the interpreter). |
| 444 | void Branch(Thread* thread, ArtMethod* method, uint32_t dex_pc, int32_t offset) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 445 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 446 | if (UNLIKELY(HasBranchListeners())) { |
| 447 | BranchImpl(thread, method, dex_pc, offset); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 451 | // Inform listeners that we read a field (only supported by the interpreter). |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 452 | void FieldReadEvent(Thread* thread, |
| 453 | ObjPtr<mirror::Object> this_object, |
| 454 | ArtMethod* method, |
| 455 | uint32_t dex_pc, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 456 | ArtField* field) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 457 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 458 | if (UNLIKELY(HasFieldReadListeners())) { |
| 459 | FieldReadEventImpl(thread, this_object, method, dex_pc, field); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | // Inform listeners that we write a field (only supported by the interpreter). |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 464 | void FieldWriteEvent(Thread* thread, |
| 465 | ObjPtr<mirror::Object> this_object, |
| 466 | ArtMethod* method, |
| 467 | uint32_t dex_pc, |
| 468 | ArtField* field, |
| 469 | const JValue& field_value) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 470 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 471 | if (UNLIKELY(HasFieldWriteListeners())) { |
| 472 | FieldWriteEventImpl(thread, this_object, method, dex_pc, field, field_value); |
| 473 | } |
| 474 | } |
| 475 | |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 476 | // Inform listeners that a branch has been taken (only supported by the interpreter). |
| 477 | void WatchedFramePopped(Thread* thread, const ShadowFrame& frame) const |
| 478 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 479 | if (UNLIKELY(HasWatchedFramePopListeners())) { |
| 480 | WatchedFramePopImpl(thread, frame); |
| 481 | } |
| 482 | } |
| 483 | |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 484 | // Inform listeners that an exception was thrown. |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 485 | void ExceptionThrownEvent(Thread* thread, ObjPtr<mirror::Throwable> exception_object) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 486 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 487 | |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 488 | // Inform listeners that an exception has been handled. This is not sent for native code or for |
| 489 | // exceptions which reach the end of the thread's stack. |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 490 | void ExceptionHandledEvent(Thread* thread, ObjPtr<mirror::Throwable> exception_object) const |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 491 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 492 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 493 | // Called when an instrumented method is entered. The intended link register (lr) is saved so |
| 494 | // that returning causes a branch to the method exit stub. Generates method enter events. |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 495 | void PushInstrumentationStackFrame(Thread* self, |
| 496 | ObjPtr<mirror::Object> this_object, |
| 497 | ArtMethod* method, |
Nicolas Geoffray | e91e795 | 2020-01-23 10:15:56 +0000 | [diff] [blame] | 498 | uintptr_t stack_pointer, |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 499 | uintptr_t lr, |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 500 | bool interpreter_entry) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 501 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 502 | |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 503 | DeoptimizationMethodType GetDeoptimizationMethodType(ArtMethod* method) |
| 504 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 505 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 506 | // Called when an instrumented method is exited. Removes the pushed instrumentation frame |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 507 | // returning the intended link register. Generates method exit events. The gpr_result and |
| 508 | // fpr_result pointers are pointers to the locations where the integer/pointer and floating point |
| 509 | // result values of the function are stored. Both pointers must always be valid but the values |
| 510 | // held there will only be meaningful if interpreted as the appropriate type given the function |
| 511 | // being returned from. |
Nicolas Geoffray | e91e795 | 2020-01-23 10:15:56 +0000 | [diff] [blame] | 512 | TwoWordReturn PopInstrumentationStackFrame(Thread* self, |
| 513 | uintptr_t* return_pc_addr, |
| 514 | uint64_t* gpr_result, |
| 515 | uint64_t* fpr_result) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 516 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!GetDeoptimizedMethodsLock()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 517 | |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 518 | // Pops nframes instrumentation frames from the current thread. Returns the return pc for the last |
| 519 | // instrumentation frame that's popped. |
Nicolas Geoffray | e91e795 | 2020-01-23 10:15:56 +0000 | [diff] [blame] | 520 | uintptr_t PopFramesForDeoptimization(Thread* self, uintptr_t stack_pointer) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 521 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 522 | |
| 523 | // Call back for configure stubs. |
Vladimir Marko | 19711d4 | 2019-04-12 14:05:34 +0100 | [diff] [blame] | 524 | void InstallStubsForClass(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 525 | REQUIRES(!GetDeoptimizedMethodsLock()); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 526 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 527 | void InstallStubsForMethod(ArtMethod* method) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 528 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!GetDeoptimizedMethodsLock()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 529 | |
Alex Light | 4060786 | 2019-05-06 18:16:24 +0000 | [diff] [blame] | 530 | // Sets up instrumentation to allow single thread deoptimization using ForceInterpreterCount. |
| 531 | void EnableSingleThreadDeopt() |
| 532 | REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_) |
| 533 | REQUIRES(!Locks::thread_list_lock_, |
| 534 | !Locks::classlinker_classes_lock_, |
| 535 | !GetDeoptimizedMethodsLock()); |
| 536 | |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 537 | // Install instrumentation exit stub on every method of the stack of the given thread. |
| 538 | // This is used by the debugger to cause a deoptimization of the thread's stack after updating |
| 539 | // local variable(s). |
| 540 | void InstrumentThreadStack(Thread* thread) |
Nicolas Geoffray | e91e795 | 2020-01-23 10:15:56 +0000 | [diff] [blame] | 541 | REQUIRES(Locks::mutator_lock_); |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 542 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 543 | // Force all currently running frames to be deoptimized back to interpreter. This should only be |
| 544 | // used in cases where basically all compiled code has been invalidated. |
| 545 | void DeoptimizeAllThreadFrames() REQUIRES(art::Locks::mutator_lock_); |
| 546 | |
Sebastien Hertz | b2feaaf | 2015-10-12 13:40:10 +0000 | [diff] [blame] | 547 | static size_t ComputeFrameId(Thread* self, |
| 548 | size_t frame_depth, |
| 549 | size_t inlined_frames_before_frame) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 550 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | b2feaaf | 2015-10-12 13:40:10 +0000 | [diff] [blame] | 551 | |
Mathieu Chartier | eebc3af | 2016-02-29 18:13:38 -0800 | [diff] [blame] | 552 | // Does not hold lock, used to check if someone changed from not instrumented to instrumented |
| 553 | // during a GC suspend point. |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 554 | bool AllocEntrypointsInstrumented() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 50e9331 | 2016-03-16 11:25:29 -0700 | [diff] [blame] | 555 | return alloc_entrypoints_instrumented_; |
Mathieu Chartier | eebc3af | 2016-02-29 18:13:38 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 558 | InstrumentationLevel GetCurrentInstrumentationLevel() const; |
| 559 | |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 560 | private: |
| 561 | // Returns true if moving to the given instrumentation level requires the installation of stubs. |
| 562 | // False otherwise. |
| 563 | bool RequiresInstrumentationInstallation(InstrumentationLevel new_level) const; |
| 564 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 565 | // Does the job of installing or removing instrumentation code within methods. |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 566 | // In order to support multiple clients using instrumentation at the same time, |
| 567 | // the caller must pass a unique key (a string) identifying it so we remind which |
| 568 | // instrumentation level it needs. Therefore the current instrumentation level |
| 569 | // becomes the highest instrumentation level required by a client. |
| 570 | void ConfigureStubs(const char* key, InstrumentationLevel desired_instrumentation_level) |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 571 | REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 572 | REQUIRES(!GetDeoptimizedMethodsLock(), |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 573 | !Locks::thread_list_lock_, |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 574 | !Locks::classlinker_classes_lock_); |
Alex Light | 4060786 | 2019-05-06 18:16:24 +0000 | [diff] [blame] | 575 | void UpdateStubs() REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_) |
| 576 | REQUIRES(!GetDeoptimizedMethodsLock(), |
| 577 | !Locks::thread_list_lock_, |
| 578 | !Locks::classlinker_classes_lock_); |
| 579 | void UpdateInstrumentationLevels(InstrumentationLevel level) |
| 580 | REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_) |
| 581 | REQUIRES(!GetDeoptimizedMethodsLock(), |
| 582 | !Locks::thread_list_lock_, |
| 583 | !Locks::classlinker_classes_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 584 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 585 | void UpdateInterpreterHandlerTable() REQUIRES(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 586 | /* |
| 587 | * TUNING: Dalvik's mterp stashes the actual current handler table base in a |
| 588 | * tls field. For Arm, this enables all suspend, debug & tracing checks to be |
| 589 | * collapsed into a single conditionally-executed ldw instruction. |
| 590 | * Move to Dalvik-style handler-table management for both the goto interpreter and |
| 591 | * mterp. |
| 592 | */ |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 593 | interpreter_handler_table_ = IsActive() ? kAlternativeHandlerTable : kMainHandlerTable; |
| 594 | } |
| 595 | |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 596 | // No thread safety analysis to get around SetQuickAllocEntryPointsInstrumented requiring |
| 597 | // exclusive access to mutator lock which you can't get if the runtime isn't started. |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 598 | void SetEntrypointsInstrumented(bool instrumented) NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 599 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 600 | void MethodEnterEventImpl(Thread* thread, |
| 601 | ObjPtr<mirror::Object> this_object, |
| 602 | ArtMethod* method, |
| 603 | uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 604 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 605 | template <typename T> |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 606 | void MethodExitEventImpl(Thread* thread, |
| 607 | ObjPtr<mirror::Object> this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 608 | ArtMethod* method, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 609 | uint32_t dex_pc, |
Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 610 | OptionalFrame frame, |
| 611 | T& return_value) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 612 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 613 | void DexPcMovedEventImpl(Thread* thread, |
| 614 | ObjPtr<mirror::Object> this_object, |
| 615 | ArtMethod* method, |
| 616 | uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 617 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 618 | void BranchImpl(Thread* thread, ArtMethod* method, uint32_t dex_pc, int32_t offset) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 619 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 620 | void WatchedFramePopImpl(Thread* thread, const ShadowFrame& frame) const |
| 621 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 622 | void FieldReadEventImpl(Thread* thread, |
| 623 | ObjPtr<mirror::Object> this_object, |
| 624 | ArtMethod* method, |
| 625 | uint32_t dex_pc, |
| 626 | ArtField* field) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 627 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 628 | void FieldWriteEventImpl(Thread* thread, |
| 629 | ObjPtr<mirror::Object> this_object, |
| 630 | ArtMethod* method, |
| 631 | uint32_t dex_pc, |
| 632 | ArtField* field, |
| 633 | const JValue& field_value) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 634 | REQUIRES_SHARED(Locks::mutator_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 635 | |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 636 | // Read barrier-aware utility functions for accessing deoptimized_methods_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 637 | bool AddDeoptimizedMethod(ArtMethod* method) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 638 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(GetDeoptimizedMethodsLock()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 639 | bool IsDeoptimizedMethod(ArtMethod* method) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 640 | REQUIRES_SHARED(Locks::mutator_lock_, GetDeoptimizedMethodsLock()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 641 | bool RemoveDeoptimizedMethod(ArtMethod* method) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 642 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(GetDeoptimizedMethodsLock()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 643 | ArtMethod* BeginDeoptimizedMethod() |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 644 | REQUIRES_SHARED(Locks::mutator_lock_, GetDeoptimizedMethodsLock()); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 645 | bool IsDeoptimizedMethodsEmpty() const |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 646 | REQUIRES_SHARED(Locks::mutator_lock_, GetDeoptimizedMethodsLock()); |
Mingyao Yang | 3fd448a | 2016-05-10 14:30:41 -0700 | [diff] [blame] | 647 | void UpdateMethodsCodeImpl(ArtMethod* method, const void* quick_code) |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 648 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!GetDeoptimizedMethodsLock()); |
Mingyao Yang | 3fd448a | 2016-05-10 14:30:41 -0700 | [diff] [blame] | 649 | |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 650 | ReaderWriterMutex* GetDeoptimizedMethodsLock() const { |
| 651 | return deoptimized_methods_lock_.get(); |
| 652 | } |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 653 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 654 | // A counter that's incremented every time a DeoptimizeAllFrames. We check each |
| 655 | // InstrumentationStackFrames creation id against this number and if they differ we deopt even if |
| 656 | // we could otherwise continue running. |
| 657 | uint64_t current_force_deopt_id_ GUARDED_BY(Locks::mutator_lock_); |
| 658 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 659 | // Have we hijacked ArtMethod::code_ so that it calls instrumentation/interpreter code? |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 660 | bool instrumentation_stubs_installed_; |
| 661 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 662 | // Have we hijacked ArtMethod::code_ to reference the enter/exit stubs? |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 663 | bool entry_exit_stubs_installed_; |
| 664 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 665 | // Have we hijacked ArtMethod::code_ to reference the enter interpreter stub? |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 666 | bool interpreter_stubs_installed_; |
| 667 | |
| 668 | // Do we need the fidelity of events that we only get from running within the interpreter? |
| 669 | bool interpret_only_; |
| 670 | |
| 671 | // Did the runtime request we only run in the interpreter? ie -Xint mode. |
| 672 | bool forced_interpret_only_; |
| 673 | |
| 674 | // Do we have any listeners for method entry events? Short-cut to avoid taking the |
| 675 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 676 | bool have_method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 677 | |
| 678 | // Do we have any listeners for method exit events? Short-cut to avoid taking the |
| 679 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 680 | bool have_method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 681 | |
| 682 | // Do we have any listeners for method unwind events? Short-cut to avoid taking the |
| 683 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 684 | bool have_method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 685 | |
| 686 | // Do we have any listeners for dex move events? Short-cut to avoid taking the |
| 687 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 688 | bool have_dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 689 | |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 690 | // Do we have any listeners for field read events? Short-cut to avoid taking the |
| 691 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 692 | bool have_field_read_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 693 | |
| 694 | // Do we have any listeners for field write events? Short-cut to avoid taking the |
| 695 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 696 | bool have_field_write_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 697 | |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 698 | // Do we have any exception thrown listeners? Short-cut to avoid taking the instrumentation_lock_. |
| 699 | bool have_exception_thrown_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 700 | |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 701 | // Do we have any frame pop listeners? Short-cut to avoid taking the instrumentation_lock_. |
| 702 | bool have_watched_frame_pop_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 703 | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 704 | // Do we have any branch listeners? Short-cut to avoid taking the instrumentation_lock_. |
| 705 | bool have_branch_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 706 | |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 707 | // Do we have any exception handled listeners? Short-cut to avoid taking the |
| 708 | // instrumentation_lock_. |
| 709 | bool have_exception_handled_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 710 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 711 | // Contains the instrumentation level required by each client of the instrumentation identified |
| 712 | // by a string key. |
| 713 | typedef SafeMap<const char*, InstrumentationLevel> InstrumentationLevelTable; |
| 714 | InstrumentationLevelTable requested_instrumentation_levels_ GUARDED_BY(Locks::mutator_lock_); |
| 715 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 716 | // The event listeners, written to with the mutator_lock_ exclusively held. |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 717 | // Mutators must be able to iterate over these lists concurrently, that is, with listeners being |
| 718 | // added or removed while iterating. The modifying thread holds exclusive lock, |
| 719 | // so other threads cannot iterate (i.e. read the data of the list) at the same time but they |
| 720 | // do keep iterators that need to remain valid. This is the reason these listeners are std::list |
| 721 | // and not for example std::vector: the existing storage for a std::list does not move. |
| 722 | // Note that mutators cannot make a copy of these lists before iterating, as the instrumentation |
| 723 | // listeners can also be deleted concurrently. |
| 724 | // As a result, these lists are never trimmed. That's acceptable given the low number of |
| 725 | // listeners we have. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 726 | std::list<InstrumentationListener*> method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 727 | std::list<InstrumentationListener*> method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 728 | std::list<InstrumentationListener*> method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 729 | std::list<InstrumentationListener*> branch_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 730 | std::list<InstrumentationListener*> dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 731 | std::list<InstrumentationListener*> field_read_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 732 | std::list<InstrumentationListener*> field_write_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 733 | std::list<InstrumentationListener*> exception_thrown_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 734 | std::list<InstrumentationListener*> watched_frame_pop_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 735 | std::list<InstrumentationListener*> exception_handled_listeners_ GUARDED_BY(Locks::mutator_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 736 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 737 | // The set of methods being deoptimized (by the debugger) which must be executed with interpreter |
| 738 | // only. |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame] | 739 | mutable std::unique_ptr<ReaderWriterMutex> deoptimized_methods_lock_ BOTTOM_MUTEX_ACQUIRED_AFTER; |
| 740 | std::unordered_set<ArtMethod*> deoptimized_methods_ GUARDED_BY(GetDeoptimizedMethodsLock()); |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 741 | bool deoptimization_enabled_; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 742 | |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 743 | // Current interpreter handler table. This is updated each time the thread state flags are |
| 744 | // modified. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 745 | InterpreterHandlerTable interpreter_handler_table_ GUARDED_BY(Locks::mutator_lock_); |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 746 | |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 747 | // Greater than 0 if quick alloc entry points instrumented. |
Mathieu Chartier | eebc3af | 2016-02-29 18:13:38 -0800 | [diff] [blame] | 748 | size_t quick_alloc_entry_points_instrumentation_counter_; |
Mathieu Chartier | 50e9331 | 2016-03-16 11:25:29 -0700 | [diff] [blame] | 749 | |
| 750 | // alloc_entrypoints_instrumented_ is only updated with all the threads suspended, this is done |
| 751 | // to prevent races with the GC where the GC relies on thread suspension only see |
| 752 | // alloc_entrypoints_instrumented_ change during suspend points. |
| 753 | bool alloc_entrypoints_instrumented_; |
| 754 | |
Alex Light | 4060786 | 2019-05-06 18:16:24 +0000 | [diff] [blame] | 755 | // If we can use instrumentation trampolines. After the first time we instrument something with |
| 756 | // the interpreter we can no longer use trampolines because it can lead to stack corruption. |
| 757 | // TODO Figure out a way to remove the need for this. |
| 758 | bool can_use_instrumentation_trampolines_; |
| 759 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 760 | friend class InstrumentationTest; // For GetCurrentInstrumentationLevel and ConfigureStubs. |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 761 | friend class InstrumentationStackPopper; // For popping instrumentation frames. |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 762 | friend void InstrumentationInstallStack(Thread*, void*); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 763 | |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 764 | DISALLOW_COPY_AND_ASSIGN(Instrumentation); |
| 765 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 766 | std::ostream& operator<<(std::ostream& os, const Instrumentation::InstrumentationEvent& rhs); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 767 | std::ostream& operator<<(std::ostream& os, const Instrumentation::InstrumentationLevel& rhs); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 768 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 769 | // An element in the instrumentation side stack maintained in art::Thread. |
| 770 | struct InstrumentationStackFrame { |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 771 | InstrumentationStackFrame(mirror::Object* this_object, |
| 772 | ArtMethod* method, |
| 773 | uintptr_t return_pc, |
| 774 | size_t frame_id, |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 775 | bool interpreter_entry, |
| 776 | uint64_t force_deopt_id) |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 777 | : this_object_(this_object), |
| 778 | method_(method), |
| 779 | return_pc_(return_pc), |
| 780 | frame_id_(frame_id), |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 781 | interpreter_entry_(interpreter_entry), |
| 782 | force_deopt_id_(force_deopt_id) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 783 | } |
| 784 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 785 | std::string Dump() const REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 786 | |
| 787 | mirror::Object* this_object_; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 788 | ArtMethod* method_; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 789 | uintptr_t return_pc_; |
| 790 | size_t frame_id_; |
| 791 | bool interpreter_entry_; |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 792 | uint64_t force_deopt_id_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 793 | }; |
| 794 | |
| 795 | } // namespace instrumentation |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 796 | } // namespace art |
| 797 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 798 | #endif // ART_RUNTIME_INSTRUMENTATION_H_ |