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