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 | |
| 387 | // Any instrumentation *other* than what is needed for Jit profiling active? |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 388 | bool NonJitProfilingActive() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Bill Buzbee | fd522f9 | 2016-02-11 22:37:42 +0000 | [diff] [blame] | 389 | return have_dex_pc_listeners_ || have_method_exit_listeners_ || |
| 390 | have_field_read_listeners_ || have_field_write_listeners_ || |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 391 | have_exception_thrown_listeners_ || have_method_unwind_listeners_ || |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 392 | have_branch_listeners_ || have_watched_frame_pop_listeners_ || |
| 393 | have_exception_handled_listeners_; |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 396 | // Inform listeners that a method has been entered. A dex PC is provided as we may install |
| 397 | // listeners into executing code and get method enter events for methods already on the stack. |
| 398 | void MethodEnterEvent(Thread* thread, mirror::Object* this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 399 | ArtMethod* method, uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 400 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 401 | if (UNLIKELY(HasMethodEntryListeners())) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 402 | MethodEnterEventImpl(thread, this_object, method, dex_pc); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | // Inform listeners that a method has been exited. |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 407 | void MethodExitEvent(Thread* thread, |
| 408 | mirror::Object* this_object, |
| 409 | ArtMethod* method, |
| 410 | uint32_t dex_pc, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 411 | const JValue& return_value) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 412 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 413 | if (UNLIKELY(HasMethodExitListeners())) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 414 | MethodExitEventImpl(thread, this_object, method, dex_pc, return_value); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | // Inform listeners that a method has been exited due to an exception. |
| 419 | void MethodUnwindEvent(Thread* thread, mirror::Object* this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 420 | ArtMethod* method, uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 421 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 422 | |
| 423 | // Inform listeners that the dex pc has moved (only supported by the interpreter). |
| 424 | void DexPcMovedEvent(Thread* thread, mirror::Object* this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 425 | ArtMethod* method, uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 426 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 427 | if (UNLIKELY(HasDexPcListeners())) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 428 | DexPcMovedEventImpl(thread, this_object, method, dex_pc); |
| 429 | } |
| 430 | } |
| 431 | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 432 | // Inform listeners that a branch has been taken (only supported by the interpreter). |
| 433 | 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] | 434 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 435 | if (UNLIKELY(HasBranchListeners())) { |
| 436 | BranchImpl(thread, method, dex_pc, offset); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 440 | // Inform listeners that we read a field (only supported by the interpreter). |
| 441 | void FieldReadEvent(Thread* thread, mirror::Object* this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 442 | ArtMethod* method, uint32_t dex_pc, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 443 | ArtField* field) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 444 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 445 | if (UNLIKELY(HasFieldReadListeners())) { |
| 446 | FieldReadEventImpl(thread, this_object, method, dex_pc, field); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | // Inform listeners that we write a field (only supported by the interpreter). |
| 451 | void FieldWriteEvent(Thread* thread, mirror::Object* this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 452 | ArtMethod* method, uint32_t dex_pc, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 453 | ArtField* field, const JValue& field_value) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 454 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 455 | if (UNLIKELY(HasFieldWriteListeners())) { |
| 456 | FieldWriteEventImpl(thread, this_object, method, dex_pc, field, field_value); |
| 457 | } |
| 458 | } |
| 459 | |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 460 | // Inform listeners that a branch has been taken (only supported by the interpreter). |
| 461 | void WatchedFramePopped(Thread* thread, const ShadowFrame& frame) const |
| 462 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 463 | if (UNLIKELY(HasWatchedFramePopListeners())) { |
| 464 | WatchedFramePopImpl(thread, frame); |
| 465 | } |
| 466 | } |
| 467 | |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 468 | // Inform listeners that an exception was thrown. |
| 469 | void ExceptionThrownEvent(Thread* thread, mirror::Throwable* exception_object) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 470 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 471 | |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 472 | // Inform listeners that an exception has been handled. This is not sent for native code or for |
| 473 | // exceptions which reach the end of the thread's stack. |
| 474 | void ExceptionHandledEvent(Thread* thread, mirror::Throwable* exception_object) const |
| 475 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 476 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 477 | // Called when an instrumented method is entered. The intended link register (lr) is saved so |
| 478 | // that returning causes a branch to the method exit stub. Generates method enter events. |
| 479 | void PushInstrumentationStackFrame(Thread* self, mirror::Object* this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 480 | ArtMethod* method, uintptr_t lr, |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 481 | bool interpreter_entry) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 482 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 483 | |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 484 | DeoptimizationMethodType GetDeoptimizationMethodType(ArtMethod* method) |
| 485 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 486 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 487 | // Called when an instrumented method is exited. Removes the pushed instrumentation frame |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 488 | // returning the intended link register. Generates method exit events. The gpr_result and |
| 489 | // fpr_result pointers are pointers to the locations where the integer/pointer and floating point |
| 490 | // result values of the function are stored. Both pointers must always be valid but the values |
| 491 | // held there will only be meaningful if interpreted as the appropriate type given the function |
| 492 | // being returned from. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 493 | TwoWordReturn PopInstrumentationStackFrame(Thread* self, uintptr_t* return_pc, |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 494 | uint64_t* gpr_result, uint64_t* fpr_result) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 495 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 496 | |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 497 | // Pops nframes instrumentation frames from the current thread. Returns the return pc for the last |
| 498 | // instrumentation frame that's popped. |
| 499 | uintptr_t PopFramesForDeoptimization(Thread* self, size_t nframes) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 500 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 501 | |
| 502 | // Call back for configure stubs. |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 503 | void InstallStubsForClass(mirror::Class* klass) REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 504 | REQUIRES(!deoptimized_methods_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 505 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 506 | void InstallStubsForMethod(ArtMethod* method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 507 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 508 | |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 509 | // Install instrumentation exit stub on every method of the stack of the given thread. |
| 510 | // This is used by the debugger to cause a deoptimization of the thread's stack after updating |
| 511 | // local variable(s). |
| 512 | void InstrumentThreadStack(Thread* thread) |
Alex Light | 3ae8253 | 2017-07-26 13:59:07 -0700 | [diff] [blame] | 513 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 514 | |
Sebastien Hertz | b2feaaf | 2015-10-12 13:40:10 +0000 | [diff] [blame] | 515 | static size_t ComputeFrameId(Thread* self, |
| 516 | size_t frame_depth, |
| 517 | size_t inlined_frames_before_frame) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 518 | REQUIRES_SHARED(Locks::mutator_lock_); |
Sebastien Hertz | b2feaaf | 2015-10-12 13:40:10 +0000 | [diff] [blame] | 519 | |
Mathieu Chartier | eebc3af | 2016-02-29 18:13:38 -0800 | [diff] [blame] | 520 | // Does not hold lock, used to check if someone changed from not instrumented to instrumented |
| 521 | // during a GC suspend point. |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 522 | bool AllocEntrypointsInstrumented() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 50e9331 | 2016-03-16 11:25:29 -0700 | [diff] [blame] | 523 | return alloc_entrypoints_instrumented_; |
Mathieu Chartier | eebc3af | 2016-02-29 18:13:38 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 526 | InstrumentationLevel GetCurrentInstrumentationLevel() const; |
| 527 | |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 528 | private: |
| 529 | // Returns true if moving to the given instrumentation level requires the installation of stubs. |
| 530 | // False otherwise. |
| 531 | bool RequiresInstrumentationInstallation(InstrumentationLevel new_level) const; |
| 532 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 533 | // Does the job of installing or removing instrumentation code within methods. |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 534 | // In order to support multiple clients using instrumentation at the same time, |
| 535 | // the caller must pass a unique key (a string) identifying it so we remind which |
| 536 | // instrumentation level it needs. Therefore the current instrumentation level |
| 537 | // becomes the highest instrumentation level required by a client. |
| 538 | void ConfigureStubs(const char* key, InstrumentationLevel desired_instrumentation_level) |
Mathieu Chartier | aa51682 | 2015-10-02 15:53:37 -0700 | [diff] [blame] | 539 | REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_) |
| 540 | REQUIRES(!deoptimized_methods_lock_, |
| 541 | !Locks::thread_list_lock_, |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 542 | !Locks::classlinker_classes_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 543 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 544 | void UpdateInterpreterHandlerTable() REQUIRES(Locks::mutator_lock_) { |
buzbee | 1452bee | 2015-03-06 14:43:04 -0800 | [diff] [blame] | 545 | /* |
| 546 | * TUNING: Dalvik's mterp stashes the actual current handler table base in a |
| 547 | * tls field. For Arm, this enables all suspend, debug & tracing checks to be |
| 548 | * collapsed into a single conditionally-executed ldw instruction. |
| 549 | * Move to Dalvik-style handler-table management for both the goto interpreter and |
| 550 | * mterp. |
| 551 | */ |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 552 | interpreter_handler_table_ = IsActive() ? kAlternativeHandlerTable : kMainHandlerTable; |
| 553 | } |
| 554 | |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 555 | // No thread safety analysis to get around SetQuickAllocEntryPointsInstrumented requiring |
| 556 | // 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] | 557 | void SetEntrypointsInstrumented(bool instrumented) NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 558 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 559 | void MethodEnterEventImpl(Thread* thread, |
| 560 | ObjPtr<mirror::Object> this_object, |
| 561 | ArtMethod* method, |
| 562 | uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 563 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 564 | void MethodExitEventImpl(Thread* thread, |
| 565 | ObjPtr<mirror::Object> this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 566 | ArtMethod* method, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 567 | uint32_t dex_pc, |
| 568 | const JValue& return_value) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 569 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 570 | void DexPcMovedEventImpl(Thread* thread, |
| 571 | ObjPtr<mirror::Object> this_object, |
| 572 | ArtMethod* method, |
| 573 | uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 574 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 575 | 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] | 576 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 577 | void WatchedFramePopImpl(Thread* thread, const ShadowFrame& frame) const |
| 578 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 579 | void FieldReadEventImpl(Thread* thread, |
| 580 | ObjPtr<mirror::Object> this_object, |
| 581 | ArtMethod* method, |
| 582 | uint32_t dex_pc, |
| 583 | ArtField* field) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 584 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 585 | void FieldWriteEventImpl(Thread* thread, |
| 586 | ObjPtr<mirror::Object> this_object, |
| 587 | ArtMethod* method, |
| 588 | uint32_t dex_pc, |
| 589 | ArtField* field, |
| 590 | const JValue& field_value) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 591 | REQUIRES_SHARED(Locks::mutator_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 592 | |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 593 | // Read barrier-aware utility functions for accessing deoptimized_methods_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 594 | bool AddDeoptimizedMethod(ArtMethod* method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 595 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(deoptimized_methods_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 596 | bool IsDeoptimizedMethod(ArtMethod* method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 597 | REQUIRES_SHARED(Locks::mutator_lock_, deoptimized_methods_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 598 | bool RemoveDeoptimizedMethod(ArtMethod* method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 599 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(deoptimized_methods_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 600 | ArtMethod* BeginDeoptimizedMethod() |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 601 | REQUIRES_SHARED(Locks::mutator_lock_, deoptimized_methods_lock_); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 602 | bool IsDeoptimizedMethodsEmpty() const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 603 | REQUIRES_SHARED(Locks::mutator_lock_, deoptimized_methods_lock_); |
Mingyao Yang | 3fd448a | 2016-05-10 14:30:41 -0700 | [diff] [blame] | 604 | void UpdateMethodsCodeImpl(ArtMethod* method, const void* quick_code) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 605 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_); |
Mingyao Yang | 3fd448a | 2016-05-10 14:30:41 -0700 | [diff] [blame] | 606 | |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 607 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 608 | // Have we hijacked ArtMethod::code_ so that it calls instrumentation/interpreter code? |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 609 | bool instrumentation_stubs_installed_; |
| 610 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 611 | // Have we hijacked ArtMethod::code_ to reference the enter/exit stubs? |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 612 | bool entry_exit_stubs_installed_; |
| 613 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 614 | // Have we hijacked ArtMethod::code_ to reference the enter interpreter stub? |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 615 | bool interpreter_stubs_installed_; |
| 616 | |
| 617 | // Do we need the fidelity of events that we only get from running within the interpreter? |
| 618 | bool interpret_only_; |
| 619 | |
| 620 | // Did the runtime request we only run in the interpreter? ie -Xint mode. |
| 621 | bool forced_interpret_only_; |
| 622 | |
| 623 | // Do we have any listeners for method entry events? Short-cut to avoid taking the |
| 624 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 625 | bool have_method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 626 | |
| 627 | // Do we have any listeners for method exit events? Short-cut to avoid taking the |
| 628 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 629 | bool have_method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 630 | |
| 631 | // Do we have any listeners for method unwind events? Short-cut to avoid taking the |
| 632 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 633 | bool have_method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 634 | |
| 635 | // Do we have any listeners for dex move events? Short-cut to avoid taking the |
| 636 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 637 | bool have_dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 638 | |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 639 | // Do we have any listeners for field read events? Short-cut to avoid taking the |
| 640 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 641 | bool have_field_read_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 642 | |
| 643 | // Do we have any listeners for field write events? Short-cut to avoid taking the |
| 644 | // instrumentation_lock_. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 645 | bool have_field_write_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 646 | |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 647 | // Do we have any exception thrown listeners? Short-cut to avoid taking the instrumentation_lock_. |
| 648 | bool have_exception_thrown_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 649 | |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 650 | // Do we have any frame pop listeners? Short-cut to avoid taking the instrumentation_lock_. |
| 651 | bool have_watched_frame_pop_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 652 | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 653 | // Do we have any branch listeners? Short-cut to avoid taking the instrumentation_lock_. |
| 654 | bool have_branch_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 655 | |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 656 | // Do we have any exception handled listeners? Short-cut to avoid taking the |
| 657 | // instrumentation_lock_. |
| 658 | bool have_exception_handled_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 659 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 660 | // Contains the instrumentation level required by each client of the instrumentation identified |
| 661 | // by a string key. |
| 662 | typedef SafeMap<const char*, InstrumentationLevel> InstrumentationLevelTable; |
| 663 | InstrumentationLevelTable requested_instrumentation_levels_ GUARDED_BY(Locks::mutator_lock_); |
| 664 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 665 | // The event listeners, written to with the mutator_lock_ exclusively held. |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 666 | // Mutators must be able to iterate over these lists concurrently, that is, with listeners being |
| 667 | // added or removed while iterating. The modifying thread holds exclusive lock, |
| 668 | // so other threads cannot iterate (i.e. read the data of the list) at the same time but they |
| 669 | // do keep iterators that need to remain valid. This is the reason these listeners are std::list |
| 670 | // and not for example std::vector: the existing storage for a std::list does not move. |
| 671 | // Note that mutators cannot make a copy of these lists before iterating, as the instrumentation |
| 672 | // listeners can also be deleted concurrently. |
| 673 | // As a result, these lists are never trimmed. That's acceptable given the low number of |
| 674 | // listeners we have. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 675 | std::list<InstrumentationListener*> method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 676 | std::list<InstrumentationListener*> method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 677 | std::list<InstrumentationListener*> method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 678 | std::list<InstrumentationListener*> branch_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 679 | std::list<InstrumentationListener*> dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 680 | std::list<InstrumentationListener*> field_read_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 681 | std::list<InstrumentationListener*> field_write_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 682 | std::list<InstrumentationListener*> exception_thrown_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 683 | std::list<InstrumentationListener*> watched_frame_pop_listeners_ GUARDED_BY(Locks::mutator_lock_); |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 684 | std::list<InstrumentationListener*> exception_handled_listeners_ GUARDED_BY(Locks::mutator_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 685 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 686 | // The set of methods being deoptimized (by the debugger) which must be executed with interpreter |
| 687 | // only. |
Alex Light | 3e36a9c | 2018-06-19 09:45:05 -0700 | [diff] [blame] | 688 | mutable ReaderWriterMutex deoptimized_methods_lock_ BOTTOM_MUTEX_ACQUIRED_AFTER; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 689 | std::unordered_set<ArtMethod*> deoptimized_methods_ GUARDED_BY(deoptimized_methods_lock_); |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 690 | bool deoptimization_enabled_; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 691 | |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 692 | // Current interpreter handler table. This is updated each time the thread state flags are |
| 693 | // modified. |
Sebastien Hertz | ed2be17 | 2014-08-19 15:33:43 +0200 | [diff] [blame] | 694 | InterpreterHandlerTable interpreter_handler_table_ GUARDED_BY(Locks::mutator_lock_); |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 695 | |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 696 | // Greater than 0 if quick alloc entry points instrumented. |
Mathieu Chartier | eebc3af | 2016-02-29 18:13:38 -0800 | [diff] [blame] | 697 | size_t quick_alloc_entry_points_instrumentation_counter_; |
Mathieu Chartier | 50e9331 | 2016-03-16 11:25:29 -0700 | [diff] [blame] | 698 | |
| 699 | // alloc_entrypoints_instrumented_ is only updated with all the threads suspended, this is done |
| 700 | // to prevent races with the GC where the GC relies on thread suspension only see |
| 701 | // alloc_entrypoints_instrumented_ change during suspend points. |
| 702 | bool alloc_entrypoints_instrumented_; |
| 703 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 704 | friend class InstrumentationTest; // For GetCurrentInstrumentationLevel and ConfigureStubs. |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 705 | friend class InstrumentationStackPopper; // For popping instrumentation frames. |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 706 | |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 707 | DISALLOW_COPY_AND_ASSIGN(Instrumentation); |
| 708 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 709 | std::ostream& operator<<(std::ostream& os, const Instrumentation::InstrumentationEvent& rhs); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 710 | std::ostream& operator<<(std::ostream& os, const Instrumentation::InstrumentationLevel& rhs); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 711 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 712 | // An element in the instrumentation side stack maintained in art::Thread. |
| 713 | struct InstrumentationStackFrame { |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 714 | InstrumentationStackFrame(mirror::Object* this_object, |
| 715 | ArtMethod* method, |
| 716 | uintptr_t return_pc, |
| 717 | size_t frame_id, |
| 718 | bool interpreter_entry) |
| 719 | : this_object_(this_object), |
| 720 | method_(method), |
| 721 | return_pc_(return_pc), |
| 722 | frame_id_(frame_id), |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 723 | interpreter_entry_(interpreter_entry) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 724 | } |
| 725 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 726 | std::string Dump() const REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 727 | |
| 728 | mirror::Object* this_object_; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 729 | ArtMethod* method_; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 730 | uintptr_t return_pc_; |
| 731 | size_t frame_id_; |
| 732 | bool interpreter_entry_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 733 | }; |
| 734 | |
| 735 | } // namespace instrumentation |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 736 | } // namespace art |
| 737 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 738 | #endif // ART_RUNTIME_INSTRUMENTATION_H_ |