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