blob: cf7271b3f811b230c0d06d6087cfe10a9f6ac2ab [file] [log] [blame]
jeffhao725a9572012-11-13 18:20:12 -08001/*
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 Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_INSTRUMENTATION_H_
18#define ART_RUNTIME_INSTRUMENTATION_H_
jeffhao725a9572012-11-13 18:20:12 -080019
Ian Rogersef7d42f2014-01-06 12:55:46 -080020#include "atomic.h"
Elliott Hughes76160052012-12-12 16:31:20 -080021#include "base/macros.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080022#include "base/mutex.h"
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070023#include "object_callbacks.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024
25#include <stdint.h>
Sebastien Hertz138dbfc2013-12-04 18:15:25 +010026#include <set>
Ian Rogers62d6c772013-02-27 08:32:07 -080027#include <list>
jeffhao725a9572012-11-13 18:20:12 -080028
29namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030namespace mirror {
Brian Carlstromea46f952013-07-30 01:26:50 -070031 class ArtMethod;
32 class Class;
33 class Object;
34 class Throwable;
Ian Rogers62d6c772013-02-27 08:32:07 -080035} // namespace mirror
36union JValue;
jeffhao725a9572012-11-13 18:20:12 -080037class Thread;
Ian Rogers62d6c772013-02-27 08:32:07 -080038class ThrowLocation;
jeffhao725a9572012-11-13 18:20:12 -080039
Ian Rogers62d6c772013-02-27 08:32:07 -080040namespace instrumentation {
jeffhao725a9572012-11-13 18:20:12 -080041
Sebastien Hertzee1997a2013-09-19 14:47:09 +020042// Interpreter handler tables.
43enum InterpreterHandlerTable {
44 kMainHandlerTable = 0, // Main handler table: no suspend check, no instrumentation.
45 kAlternativeHandlerTable = 1, // Alternative handler table: suspend check and/or instrumentation
46 // enabled.
47 kNumHandlerTables
48};
49
Ian Rogers62d6c772013-02-27 08:32:07 -080050// Instrumentation event listener API. Registered listeners will get the appropriate call back for
51// the events they are listening for. The call backs supply the thread, method and dex_pc the event
52// occurred upon. The thread may or may not be Thread::Current().
53struct InstrumentationListener {
54 InstrumentationListener() {}
55 virtual ~InstrumentationListener() {}
56
57 // Call-back for when a method is entered.
58 virtual void MethodEntered(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -080059 mirror::ArtMethod* method,
Ian Rogers62d6c772013-02-27 08:32:07 -080060 uint32_t dex_pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
61
62 // Call-back for when a method is exited.
63 // TODO: its likely passing the return value would be useful, however, we may need to get and
64 // parse the shorty to determine what kind of register holds the result.
65 virtual void MethodExited(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -080066 mirror::ArtMethod* method, uint32_t dex_pc,
Ian Rogers62d6c772013-02-27 08:32:07 -080067 const JValue& return_value)
68 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
69
70 // Call-back for when a method is popped due to an exception throw. A method will either cause a
71 // MethodExited call-back or a MethodUnwind call-back when its activation is removed.
Sebastien Hertz51db44a2013-11-19 10:00:29 +010072 virtual void MethodUnwind(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -080073 mirror::ArtMethod* method, uint32_t dex_pc)
Sebastien Hertz51db44a2013-11-19 10:00:29 +010074 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
Ian Rogers62d6c772013-02-27 08:32:07 -080075
76 // Call-back for when the dex pc moves in a method.
77 virtual void DexPcMoved(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -080078 mirror::ArtMethod* method, uint32_t new_dex_pc)
Ian Rogers62d6c772013-02-27 08:32:07 -080079 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
80
81 // Call-back when an exception is caught.
82 virtual void ExceptionCaught(Thread* thread, const ThrowLocation& throw_location,
Brian Carlstromea46f952013-07-30 01:26:50 -070083 mirror::ArtMethod* catch_method, uint32_t catch_dex_pc,
Ian Rogers62d6c772013-02-27 08:32:07 -080084 mirror::Throwable* exception_object)
85 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
jeffhao725a9572012-11-13 18:20:12 -080086};
87
Ian Rogers62d6c772013-02-27 08:32:07 -080088// Instrumentation is a catch-all for when extra information is required from the runtime. The
89// typical use for instrumentation is for profiling and debugging. Instrumentation may add stubs
90// to method entry and exit, it may also force execution to be switched to the interpreter and
91// trigger deoptimization.
jeffhao725a9572012-11-13 18:20:12 -080092class Instrumentation {
93 public:
Ian Rogers62d6c772013-02-27 08:32:07 -080094 enum InstrumentationEvent {
95 kMethodEntered = 1,
96 kMethodExited = 2,
97 kMethodUnwind = 4,
98 kDexPcMoved = 8,
99 kExceptionCaught = 16
100 };
jeffhao725a9572012-11-13 18:20:12 -0800101
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700102 Instrumentation();
jeffhao725a9572012-11-13 18:20:12 -0800103
Ian Rogers62d6c772013-02-27 08:32:07 -0800104 // Add a listener to be notified of the masked together sent of instrumentation events. This
105 // suspend the runtime to install stubs. You are expected to hold the mutator lock as a proxy
106 // for saying you should have suspended all threads (installing stubs while threads are running
107 // will break).
108 void AddListener(InstrumentationListener* listener, uint32_t events)
109 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_)
110 LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::classlinker_classes_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800111
Ian Rogers62d6c772013-02-27 08:32:07 -0800112 // Removes a listener possibly removing instrumentation stubs.
113 void RemoveListener(InstrumentationListener* listener, uint32_t events)
114 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_)
115 LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::classlinker_classes_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800116
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100117 // Deoptimization.
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700118 void EnableDeoptimization() EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_)
119 LOCKS_EXCLUDED(deoptimized_methods_lock_);
120 void DisableDeoptimization() EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_)
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100121 LOCKS_EXCLUDED(deoptimized_methods_lock_);
Sebastien Hertz11d40c22014-02-19 18:00:17 +0100122 bool ShouldNotifyMethodEnterExitEvents() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100123
124 // Executes everything with interpreter.
125 void DeoptimizeEverything()
126 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_)
127 LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::classlinker_classes_lock_);
128
129 // Executes everything with compiled code (or interpreter if there is no code).
130 void UndeoptimizeEverything()
131 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_)
132 LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::classlinker_classes_lock_);
133
134 // Deoptimize a method by forcing its execution with the interpreter. Nevertheless, a static
135 // method (except a class initializer) set to the resolution trampoline will be deoptimized only
136 // once its declaring class is initialized.
137 void Deoptimize(mirror::ArtMethod* method)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700138 LOCKS_EXCLUDED(Locks::thread_list_lock_, deoptimized_methods_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100139 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
140
141 // Undeoptimze the method by restoring its entrypoints. Nevertheless, a static method
142 // (except a class initializer) set to the resolution trampoline will be updated only once its
143 // declaring class is initialized.
144 void Undeoptimize(mirror::ArtMethod* method)
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100145 LOCKS_EXCLUDED(Locks::thread_list_lock_, deoptimized_methods_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100146 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
147
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700148 bool IsDeoptimized(mirror::ArtMethod* method) const LOCKS_EXCLUDED(deoptimized_methods_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100149
150 // Enable method tracing by installing instrumentation entry/exit stubs.
151 void EnableMethodTracing()
152 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_)
153 LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::classlinker_classes_lock_);
154
155 // Disable method tracing by uninstalling instrumentation entry/exit stubs.
156 void DisableMethodTracing()
157 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_)
158 LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::classlinker_classes_lock_);
159
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200160 InterpreterHandlerTable GetInterpreterHandlerTable() const {
161 return interpreter_handler_table_;
162 }
163
Mathieu Chartierd8891782014-03-02 13:28:37 -0800164 void InstrumentQuickAllocEntryPoints() LOCKS_EXCLUDED(Locks::thread_list_lock_,
165 Locks::runtime_shutdown_lock_);
166 void UninstrumentQuickAllocEntryPoints() LOCKS_EXCLUDED(Locks::thread_list_lock_,
167 Locks::runtime_shutdown_lock_);
168 void ResetQuickAllocEntryPoints() EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_);
Ian Rogersfa824272013-11-05 16:12:57 -0800169
Ian Rogers62d6c772013-02-27 08:32:07 -0800170 // Update the code of a method respecting any installed stubs.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800171 void UpdateMethodsCode(mirror::ArtMethod* method, const void* quick_code,
172 const void* portable_code, bool have_portable_code) const
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100173 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800174
175 // Get the quick code for the given method. More efficient than asking the class linker as it
176 // will short-cut to GetCode if instrumentation and static method resolution stubs aren't
177 // installed.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800178 const void* GetQuickCodeFor(mirror::ArtMethod* method) const
Ian Rogers62d6c772013-02-27 08:32:07 -0800179 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
180
181 void ForceInterpretOnly() {
182 interpret_only_ = true;
183 forced_interpret_only_ = true;
184 }
185
Brian Carlstromea46f952013-07-30 01:26:50 -0700186 // Called by ArtMethod::Invoke to determine dispatch mechanism.
Ian Rogers62d6c772013-02-27 08:32:07 -0800187 bool InterpretOnly() const {
188 return interpret_only_;
189 }
190
Hiroshi Yamauchi563b47c2014-02-28 17:18:37 -0800191 bool IsForcedInterpretOnly() const {
192 return forced_interpret_only_;
193 }
194
Ian Rogers62d6c772013-02-27 08:32:07 -0800195 bool ShouldPortableCodeDeoptimize() const {
196 return instrumentation_stubs_installed_;
197 }
198
199 bool AreExitStubsInstalled() const {
200 return instrumentation_stubs_installed_;
201 }
202
Sebastien Hertz74109f62013-06-07 17:40:09 +0200203 bool HasMethodEntryListeners() const {
204 return have_method_entry_listeners_;
205 }
206
207 bool HasMethodExitListeners() const {
208 return have_method_exit_listeners_;
209 }
210
211 bool HasDexPcListeners() const {
212 return have_dex_pc_listeners_;
213 }
214
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200215 bool IsActive() const {
216 return have_dex_pc_listeners_ || have_method_entry_listeners_ || have_method_exit_listeners_ ||
217 have_exception_caught_listeners_ || have_method_unwind_listeners_;
218 }
219
Ian Rogers62d6c772013-02-27 08:32:07 -0800220 // Inform listeners that a method has been entered. A dex PC is provided as we may install
221 // listeners into executing code and get method enter events for methods already on the stack.
222 void MethodEnterEvent(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800223 mirror::ArtMethod* method, uint32_t dex_pc) const
Ian Rogers62d6c772013-02-27 08:32:07 -0800224 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz74109f62013-06-07 17:40:09 +0200225 if (UNLIKELY(HasMethodEntryListeners())) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800226 MethodEnterEventImpl(thread, this_object, method, dex_pc);
227 }
228 }
229
230 // Inform listeners that a method has been exited.
231 void MethodExitEvent(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800232 mirror::ArtMethod* method, uint32_t dex_pc,
Ian Rogers62d6c772013-02-27 08:32:07 -0800233 const JValue& return_value) const
234 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz74109f62013-06-07 17:40:09 +0200235 if (UNLIKELY(HasMethodExitListeners())) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800236 MethodExitEventImpl(thread, this_object, method, dex_pc, return_value);
237 }
238 }
239
240 // Inform listeners that a method has been exited due to an exception.
241 void MethodUnwindEvent(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800242 mirror::ArtMethod* method, uint32_t dex_pc) const
Ian Rogers62d6c772013-02-27 08:32:07 -0800243 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
244
245 // Inform listeners that the dex pc has moved (only supported by the interpreter).
246 void DexPcMovedEvent(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800247 mirror::ArtMethod* method, uint32_t dex_pc) const
Ian Rogers62d6c772013-02-27 08:32:07 -0800248 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz74109f62013-06-07 17:40:09 +0200249 if (UNLIKELY(HasDexPcListeners())) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800250 DexPcMovedEventImpl(thread, this_object, method, dex_pc);
251 }
252 }
253
254 // Inform listeners that an exception was caught.
255 void ExceptionCaughtEvent(Thread* thread, const ThrowLocation& throw_location,
Brian Carlstromea46f952013-07-30 01:26:50 -0700256 mirror::ArtMethod* catch_method, uint32_t catch_dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200257 mirror::Throwable* exception_object) const
Ian Rogers62d6c772013-02-27 08:32:07 -0800258 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
259
260 // Called when an instrumented method is entered. The intended link register (lr) is saved so
261 // that returning causes a branch to the method exit stub. Generates method enter events.
262 void PushInstrumentationStackFrame(Thread* self, mirror::Object* this_object,
Brian Carlstromea46f952013-07-30 01:26:50 -0700263 mirror::ArtMethod* method, uintptr_t lr,
Jeff Hao9a916d32013-06-27 18:45:37 -0700264 bool interpreter_entry)
Ian Rogers62d6c772013-02-27 08:32:07 -0800265 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
266
267 // Called when an instrumented method is exited. Removes the pushed instrumentation frame
268 // returning the intended link register. Generates method exit events.
269 uint64_t PopInstrumentationStackFrame(Thread* self, uintptr_t* return_pc, uint64_t gpr_result,
270 uint64_t fpr_result)
271 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
272
273 // Pops an instrumentation frame from the current thread and generate an unwind event.
274 void PopMethodForUnwind(Thread* self, bool is_deoptimization) const
275 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
276
277 // Call back for configure stubs.
278 bool InstallStubsForClass(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800279
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100280 void InstallStubsForMethod(mirror::ArtMethod* method)
281 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
282
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700283 void VisitRoots(RootCallback* callback, void* arg) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
284 LOCKS_EXCLUDED(deoptimized_methods_lock_);
285
jeffhao725a9572012-11-13 18:20:12 -0800286 private:
Ian Rogers62d6c772013-02-27 08:32:07 -0800287 // Does the job of installing or removing instrumentation code within methods.
288 void ConfigureStubs(bool require_entry_exit_stubs, bool require_interpreter)
289 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700290 LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::classlinker_classes_lock_,
291 deoptimized_methods_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800292
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200293 void UpdateInterpreterHandlerTable() {
294 interpreter_handler_table_ = IsActive() ? kAlternativeHandlerTable : kMainHandlerTable;
295 }
296
Mathieu Chartier661974a2014-01-09 11:23:53 -0800297 // No thread safety analysis to get around SetQuickAllocEntryPointsInstrumented requiring
298 // exclusive access to mutator lock which you can't get if the runtime isn't started.
299 void SetEntrypointsInstrumented(bool instrumented) NO_THREAD_SAFETY_ANALYSIS;
300
Ian Rogers62d6c772013-02-27 08:32:07 -0800301 void MethodEnterEventImpl(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800302 mirror::ArtMethod* method, uint32_t dex_pc) const
Ian Rogers62d6c772013-02-27 08:32:07 -0800303 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
304 void MethodExitEventImpl(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800305 mirror::ArtMethod* method,
Ian Rogers62d6c772013-02-27 08:32:07 -0800306 uint32_t dex_pc, const JValue& return_value) const
307 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
308 void DexPcMovedEventImpl(Thread* thread, mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800309 mirror::ArtMethod* method, uint32_t dex_pc) const
Ian Rogers62d6c772013-02-27 08:32:07 -0800310 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800311
Brian Carlstromea46f952013-07-30 01:26:50 -0700312 // Have we hijacked ArtMethod::code_ so that it calls instrumentation/interpreter code?
Ian Rogers62d6c772013-02-27 08:32:07 -0800313 bool instrumentation_stubs_installed_;
314
Brian Carlstromea46f952013-07-30 01:26:50 -0700315 // Have we hijacked ArtMethod::code_ to reference the enter/exit stubs?
Ian Rogers62d6c772013-02-27 08:32:07 -0800316 bool entry_exit_stubs_installed_;
317
Brian Carlstromea46f952013-07-30 01:26:50 -0700318 // Have we hijacked ArtMethod::code_ to reference the enter interpreter stub?
Ian Rogers62d6c772013-02-27 08:32:07 -0800319 bool interpreter_stubs_installed_;
320
321 // Do we need the fidelity of events that we only get from running within the interpreter?
322 bool interpret_only_;
323
324 // Did the runtime request we only run in the interpreter? ie -Xint mode.
325 bool forced_interpret_only_;
326
327 // Do we have any listeners for method entry events? Short-cut to avoid taking the
328 // instrumentation_lock_.
329 bool have_method_entry_listeners_;
330
331 // Do we have any listeners for method exit events? Short-cut to avoid taking the
332 // instrumentation_lock_.
333 bool have_method_exit_listeners_;
334
335 // Do we have any listeners for method unwind events? Short-cut to avoid taking the
336 // instrumentation_lock_.
337 bool have_method_unwind_listeners_;
338
339 // Do we have any listeners for dex move events? Short-cut to avoid taking the
340 // instrumentation_lock_.
341 bool have_dex_pc_listeners_;
342
343 // Do we have any exception caught listeners? Short-cut to avoid taking the instrumentation_lock_.
344 bool have_exception_caught_listeners_;
345
346 // The event listeners, written to with the mutator_lock_ exclusively held.
347 std::list<InstrumentationListener*> method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_);
348 std::list<InstrumentationListener*> method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_);
349 std::list<InstrumentationListener*> method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_);
350 std::list<InstrumentationListener*> dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_);
351 std::list<InstrumentationListener*> exception_caught_listeners_ GUARDED_BY(Locks::mutator_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800352
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100353 // The set of methods being deoptimized (by the debugger) which must be executed with interpreter
354 // only.
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700355 mutable ReaderWriterMutex deoptimized_methods_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
356 std::set<mirror::ArtMethod*> deoptimized_methods_ GUARDED_BY(deoptimized_methods_lock_);
Sebastien Hertz11d40c22014-02-19 18:00:17 +0100357 bool deoptimization_enabled_;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100358
Ian Rogersfa824272013-11-05 16:12:57 -0800359 // Current interpreter handler table. This is updated each time the thread state flags are
360 // modified.
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200361 InterpreterHandlerTable interpreter_handler_table_;
362
Ian Rogersfa824272013-11-05 16:12:57 -0800363 // Greater than 0 if quick alloc entry points instrumented.
364 // TODO: The access and changes to this is racy and should be guarded by a lock.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800365 AtomicInteger quick_alloc_entry_points_instrumentation_counter_;
Ian Rogersfa824272013-11-05 16:12:57 -0800366
jeffhao725a9572012-11-13 18:20:12 -0800367 DISALLOW_COPY_AND_ASSIGN(Instrumentation);
368};
369
Ian Rogers62d6c772013-02-27 08:32:07 -0800370// An element in the instrumentation side stack maintained in art::Thread.
371struct InstrumentationStackFrame {
Brian Carlstromea46f952013-07-30 01:26:50 -0700372 InstrumentationStackFrame(mirror::Object* this_object, mirror::ArtMethod* method,
Jeff Hao9a916d32013-06-27 18:45:37 -0700373 uintptr_t return_pc, size_t frame_id, bool interpreter_entry)
374 : this_object_(this_object), method_(method), return_pc_(return_pc), frame_id_(frame_id),
375 interpreter_entry_(interpreter_entry) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800376 }
377
378 std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
379
380 mirror::Object* this_object_;
Brian Carlstromea46f952013-07-30 01:26:50 -0700381 mirror::ArtMethod* method_;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100382 uintptr_t return_pc_;
383 size_t frame_id_;
384 bool interpreter_entry_;
Ian Rogers62d6c772013-02-27 08:32:07 -0800385};
386
387} // namespace instrumentation
jeffhao725a9572012-11-13 18:20:12 -0800388} // namespace art
389
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700390#endif // ART_RUNTIME_INSTRUMENTATION_H_