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