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 | |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 20 | #include "base/macros.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 21 | #include "locks.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | |
| 23 | #include <stdint.h> |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 24 | #include <list> |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 25 | |
| 26 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | namespace mirror { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 28 | class ArtMethod; |
| 29 | class Class; |
| 30 | class Object; |
| 31 | class Throwable; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 32 | } // namespace mirror |
| 33 | union JValue; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 34 | class Thread; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 35 | class ThrowLocation; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 36 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 37 | namespace instrumentation { |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 38 | |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 39 | // Interpreter handler tables. |
| 40 | enum InterpreterHandlerTable { |
| 41 | kMainHandlerTable = 0, // Main handler table: no suspend check, no instrumentation. |
| 42 | kAlternativeHandlerTable = 1, // Alternative handler table: suspend check and/or instrumentation |
| 43 | // enabled. |
| 44 | kNumHandlerTables |
| 45 | }; |
| 46 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 47 | // Instrumentation event listener API. Registered listeners will get the appropriate call back for |
| 48 | // the events they are listening for. The call backs supply the thread, method and dex_pc the event |
| 49 | // occurred upon. The thread may or may not be Thread::Current(). |
| 50 | struct InstrumentationListener { |
| 51 | InstrumentationListener() {} |
| 52 | virtual ~InstrumentationListener() {} |
| 53 | |
| 54 | // Call-back for when a method is entered. |
| 55 | virtual void MethodEntered(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 56 | const mirror::ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 57 | uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
| 58 | |
| 59 | // Call-back for when a method is exited. |
| 60 | // TODO: its likely passing the return value would be useful, however, we may need to get and |
| 61 | // parse the shorty to determine what kind of register holds the result. |
| 62 | virtual void MethodExited(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 63 | const mirror::ArtMethod* method, uint32_t dex_pc, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 64 | const JValue& return_value) |
| 65 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
| 66 | |
| 67 | // Call-back for when a method is popped due to an exception throw. A method will either cause a |
| 68 | // MethodExited call-back or a MethodUnwind call-back when its activation is removed. |
Sebastien Hertz | 51db44a | 2013-11-19 10:00:29 +0100 | [diff] [blame] | 69 | virtual void MethodUnwind(Thread* thread, mirror::Object* this_object, |
| 70 | const mirror::ArtMethod* method, uint32_t dex_pc) |
| 71 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 72 | |
| 73 | // Call-back for when the dex pc moves in a method. |
| 74 | virtual void DexPcMoved(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 75 | const mirror::ArtMethod* method, uint32_t new_dex_pc) |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 76 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
| 77 | |
| 78 | // Call-back when an exception is caught. |
| 79 | virtual void ExceptionCaught(Thread* thread, const ThrowLocation& throw_location, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 80 | mirror::ArtMethod* catch_method, uint32_t catch_dex_pc, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 81 | mirror::Throwable* exception_object) |
| 82 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 85 | // Instrumentation is a catch-all for when extra information is required from the runtime. The |
| 86 | // typical use for instrumentation is for profiling and debugging. Instrumentation may add stubs |
| 87 | // to method entry and exit, it may also force execution to be switched to the interpreter and |
| 88 | // trigger deoptimization. |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 89 | class Instrumentation { |
| 90 | public: |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 91 | enum InstrumentationEvent { |
| 92 | kMethodEntered = 1, |
| 93 | kMethodExited = 2, |
| 94 | kMethodUnwind = 4, |
| 95 | kDexPcMoved = 8, |
| 96 | kExceptionCaught = 16 |
| 97 | }; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 98 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 99 | Instrumentation() : |
| 100 | instrumentation_stubs_installed_(false), entry_exit_stubs_installed_(false), |
| 101 | interpreter_stubs_installed_(false), |
| 102 | interpret_only_(false), forced_interpret_only_(false), |
| 103 | have_method_entry_listeners_(false), have_method_exit_listeners_(false), |
| 104 | have_method_unwind_listeners_(false), have_dex_pc_listeners_(false), |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 105 | have_exception_caught_listeners_(false), |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 106 | interpreter_handler_table_(kMainHandlerTable), |
| 107 | quick_alloc_entry_points_instrumentation_counter_(0) {} |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 108 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 109 | // Add a listener to be notified of the masked together sent of instrumentation events. This |
| 110 | // suspend the runtime to install stubs. You are expected to hold the mutator lock as a proxy |
| 111 | // for saying you should have suspended all threads (installing stubs while threads are running |
| 112 | // will break). |
| 113 | void AddListener(InstrumentationListener* listener, uint32_t events) |
| 114 | EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 115 | LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::classlinker_classes_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 116 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 117 | // Removes a listener possibly removing instrumentation stubs. |
| 118 | void RemoveListener(InstrumentationListener* listener, uint32_t events) |
| 119 | EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 120 | LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::classlinker_classes_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 121 | |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 122 | InterpreterHandlerTable GetInterpreterHandlerTable() const { |
| 123 | return interpreter_handler_table_; |
| 124 | } |
| 125 | |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 126 | void InstrumentQuickAllocEntryPoints() LOCKS_EXCLUDED(Locks::thread_list_lock_); |
| 127 | void UninstrumentQuickAllocEntryPoints() LOCKS_EXCLUDED(Locks::thread_list_lock_); |
| 128 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 129 | // Update the code of a method respecting any installed stubs. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 130 | void UpdateMethodsCode(mirror::ArtMethod* method, const void* code) const; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 131 | |
| 132 | // Get the quick code for the given method. More efficient than asking the class linker as it |
| 133 | // will short-cut to GetCode if instrumentation and static method resolution stubs aren't |
| 134 | // installed. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 135 | const void* GetQuickCodeFor(const mirror::ArtMethod* method) const |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 136 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 137 | |
| 138 | void ForceInterpretOnly() { |
| 139 | interpret_only_ = true; |
| 140 | forced_interpret_only_ = true; |
| 141 | } |
| 142 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 143 | // Called by ArtMethod::Invoke to determine dispatch mechanism. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 144 | bool InterpretOnly() const { |
| 145 | return interpret_only_; |
| 146 | } |
| 147 | |
| 148 | bool ShouldPortableCodeDeoptimize() const { |
| 149 | return instrumentation_stubs_installed_; |
| 150 | } |
| 151 | |
| 152 | bool AreExitStubsInstalled() const { |
| 153 | return instrumentation_stubs_installed_; |
| 154 | } |
| 155 | |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 156 | bool HasMethodEntryListeners() const { |
| 157 | return have_method_entry_listeners_; |
| 158 | } |
| 159 | |
| 160 | bool HasMethodExitListeners() const { |
| 161 | return have_method_exit_listeners_; |
| 162 | } |
| 163 | |
| 164 | bool HasDexPcListeners() const { |
| 165 | return have_dex_pc_listeners_; |
| 166 | } |
| 167 | |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 168 | bool IsActive() const { |
| 169 | return have_dex_pc_listeners_ || have_method_entry_listeners_ || have_method_exit_listeners_ || |
| 170 | have_exception_caught_listeners_ || have_method_unwind_listeners_; |
| 171 | } |
| 172 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 173 | // Inform listeners that a method has been entered. A dex PC is provided as we may install |
| 174 | // listeners into executing code and get method enter events for methods already on the stack. |
| 175 | void MethodEnterEvent(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 176 | const mirror::ArtMethod* method, uint32_t dex_pc) const |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 177 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 178 | if (UNLIKELY(HasMethodEntryListeners())) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 179 | MethodEnterEventImpl(thread, this_object, method, dex_pc); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // Inform listeners that a method has been exited. |
| 184 | void MethodExitEvent(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 185 | const mirror::ArtMethod* method, uint32_t dex_pc, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 186 | const JValue& return_value) const |
| 187 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 188 | if (UNLIKELY(HasMethodExitListeners())) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 189 | MethodExitEventImpl(thread, this_object, method, dex_pc, return_value); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | // Inform listeners that a method has been exited due to an exception. |
| 194 | void MethodUnwindEvent(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 195 | const mirror::ArtMethod* method, uint32_t dex_pc) const |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 196 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 197 | |
| 198 | // Inform listeners that the dex pc has moved (only supported by the interpreter). |
| 199 | void DexPcMovedEvent(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 200 | const mirror::ArtMethod* method, uint32_t dex_pc) const |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 201 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Sebastien Hertz | 74109f6 | 2013-06-07 17:40:09 +0200 | [diff] [blame] | 202 | if (UNLIKELY(HasDexPcListeners())) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 203 | DexPcMovedEventImpl(thread, this_object, method, dex_pc); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | // Inform listeners that an exception was caught. |
| 208 | void ExceptionCaughtEvent(Thread* thread, const ThrowLocation& throw_location, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 209 | mirror::ArtMethod* catch_method, uint32_t catch_dex_pc, |
Sebastien Hertz | 947ff08 | 2013-09-17 14:10:13 +0200 | [diff] [blame] | 210 | mirror::Throwable* exception_object) const |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 211 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 212 | |
| 213 | // Called when an instrumented method is entered. The intended link register (lr) is saved so |
| 214 | // that returning causes a branch to the method exit stub. Generates method enter events. |
| 215 | void PushInstrumentationStackFrame(Thread* self, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 216 | mirror::ArtMethod* method, uintptr_t lr, |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 217 | bool interpreter_entry) |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 218 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 219 | |
| 220 | // Called when an instrumented method is exited. Removes the pushed instrumentation frame |
| 221 | // returning the intended link register. Generates method exit events. |
| 222 | uint64_t PopInstrumentationStackFrame(Thread* self, uintptr_t* return_pc, uint64_t gpr_result, |
| 223 | uint64_t fpr_result) |
| 224 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 225 | |
| 226 | // Pops an instrumentation frame from the current thread and generate an unwind event. |
| 227 | void PopMethodForUnwind(Thread* self, bool is_deoptimization) const |
| 228 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 229 | |
| 230 | // Call back for configure stubs. |
| 231 | bool InstallStubsForClass(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 232 | |
| 233 | private: |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 234 | // Does the job of installing or removing instrumentation code within methods. |
| 235 | void ConfigureStubs(bool require_entry_exit_stubs, bool require_interpreter) |
| 236 | EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 237 | LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::classlinker_classes_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 238 | |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 239 | void UpdateInterpreterHandlerTable() { |
| 240 | interpreter_handler_table_ = IsActive() ? kAlternativeHandlerTable : kMainHandlerTable; |
| 241 | } |
| 242 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 243 | void MethodEnterEventImpl(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 244 | const mirror::ArtMethod* method, uint32_t dex_pc) const |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 245 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 246 | void MethodExitEventImpl(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 247 | const mirror::ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 248 | uint32_t dex_pc, const JValue& return_value) const |
| 249 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 250 | void DexPcMovedEventImpl(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 251 | const mirror::ArtMethod* method, uint32_t dex_pc) const |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 252 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 253 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 254 | // Have we hijacked ArtMethod::code_ so that it calls instrumentation/interpreter code? |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 255 | bool instrumentation_stubs_installed_; |
| 256 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 257 | // Have we hijacked ArtMethod::code_ to reference the enter/exit stubs? |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 258 | bool entry_exit_stubs_installed_; |
| 259 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 260 | // Have we hijacked ArtMethod::code_ to reference the enter interpreter stub? |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 261 | bool interpreter_stubs_installed_; |
| 262 | |
| 263 | // Do we need the fidelity of events that we only get from running within the interpreter? |
| 264 | bool interpret_only_; |
| 265 | |
| 266 | // Did the runtime request we only run in the interpreter? ie -Xint mode. |
| 267 | bool forced_interpret_only_; |
| 268 | |
| 269 | // Do we have any listeners for method entry events? Short-cut to avoid taking the |
| 270 | // instrumentation_lock_. |
| 271 | bool have_method_entry_listeners_; |
| 272 | |
| 273 | // Do we have any listeners for method exit events? Short-cut to avoid taking the |
| 274 | // instrumentation_lock_. |
| 275 | bool have_method_exit_listeners_; |
| 276 | |
| 277 | // Do we have any listeners for method unwind events? Short-cut to avoid taking the |
| 278 | // instrumentation_lock_. |
| 279 | bool have_method_unwind_listeners_; |
| 280 | |
| 281 | // Do we have any listeners for dex move events? Short-cut to avoid taking the |
| 282 | // instrumentation_lock_. |
| 283 | bool have_dex_pc_listeners_; |
| 284 | |
| 285 | // Do we have any exception caught listeners? Short-cut to avoid taking the instrumentation_lock_. |
| 286 | bool have_exception_caught_listeners_; |
| 287 | |
| 288 | // The event listeners, written to with the mutator_lock_ exclusively held. |
| 289 | std::list<InstrumentationListener*> method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 290 | std::list<InstrumentationListener*> method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 291 | std::list<InstrumentationListener*> method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 292 | std::list<InstrumentationListener*> dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_); |
| 293 | std::list<InstrumentationListener*> exception_caught_listeners_ GUARDED_BY(Locks::mutator_lock_); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 294 | |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 295 | // Current interpreter handler table. This is updated each time the thread state flags are |
| 296 | // modified. |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 297 | InterpreterHandlerTable interpreter_handler_table_; |
| 298 | |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 299 | // Greater than 0 if quick alloc entry points instrumented. |
| 300 | // TODO: The access and changes to this is racy and should be guarded by a lock. |
| 301 | size_t quick_alloc_entry_points_instrumentation_counter_; |
| 302 | |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 303 | DISALLOW_COPY_AND_ASSIGN(Instrumentation); |
| 304 | }; |
| 305 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 306 | // An element in the instrumentation side stack maintained in art::Thread. |
| 307 | struct InstrumentationStackFrame { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 308 | InstrumentationStackFrame(mirror::Object* this_object, mirror::ArtMethod* method, |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 309 | uintptr_t return_pc, size_t frame_id, bool interpreter_entry) |
| 310 | : this_object_(this_object), method_(method), return_pc_(return_pc), frame_id_(frame_id), |
| 311 | interpreter_entry_(interpreter_entry) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 315 | |
| 316 | mirror::Object* this_object_; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 317 | mirror::ArtMethod* method_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 318 | const uintptr_t return_pc_; |
| 319 | const size_t frame_id_; |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 320 | const bool interpreter_entry_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 321 | }; |
| 322 | |
| 323 | } // namespace instrumentation |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 324 | } // namespace art |
| 325 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 326 | #endif // ART_RUNTIME_INSTRUMENTATION_H_ |