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