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