blob: 01071a541fc7b74c2adf57ab1c67f24bbf359ad7 [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 Rogers576ca0c2014-06-06 15:58:22 -070020#include <stdint.h>
Ian Rogers576ca0c2014-06-06 15:58:22 -070021#include <list>
Mathieu Chartiere401d142015-04-22 13:56:20 -070022#include <unordered_set>
Ian Rogers576ca0c2014-06-06 15:58:22 -070023
Ian Rogersd582fa42014-11-05 23:46:43 -080024#include "arch/instruction_set.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070025#include "base/enums.h"
Elliott Hughes76160052012-12-12 16:31:20 -080026#include "base/macros.h"
Ian Rogers719d1a32014-03-06 12:13:39 -080027#include "base/mutex.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070028#include "gc_root.h"
Sebastien Hertz0462c4c2015-04-01 16:34:17 +020029#include "safe_map.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030
jeffhao725a9572012-11-13 18:20:12 -080031namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032namespace mirror {
Brian Carlstromea46f952013-07-30 01:26:50 -070033 class Class;
34 class Object;
35 class Throwable;
Ian Rogers62d6c772013-02-27 08:32:07 -080036} // namespace mirror
Mathieu Chartierc7853442015-03-27 14:35:38 -070037class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070038class ArtMethod;
Ian Rogers62d6c772013-02-27 08:32:07 -080039union JValue;
jeffhao725a9572012-11-13 18:20:12 -080040class Thread;
41
Ian Rogers62d6c772013-02-27 08:32:07 -080042namespace instrumentation {
jeffhao725a9572012-11-13 18:20:12 -080043
Sebastien Hertzee1997a2013-09-19 14:47:09 +020044// Interpreter handler tables.
45enum InterpreterHandlerTable {
46 kMainHandlerTable = 0, // Main handler table: no suspend check, no instrumentation.
47 kAlternativeHandlerTable = 1, // Alternative handler table: suspend check and/or instrumentation
48 // enabled.
49 kNumHandlerTables
50};
51
Andreas Gampe40da2862015-02-27 12:49:04 -080052// Do we want to deoptimize for method entry and exit listeners or just try to intercept
53// invocations? Deoptimization forces all code to run in the interpreter and considerably hurts the
54// application's performance.
55static constexpr bool kDeoptimizeForAccurateMethodEntryExitListeners = true;
56
Ian Rogers62d6c772013-02-27 08:32:07 -080057// Instrumentation event listener API. Registered listeners will get the appropriate call back for
58// the events they are listening for. The call backs supply the thread, method and dex_pc the event
59// occurred upon. The thread may or may not be Thread::Current().
60struct InstrumentationListener {
61 InstrumentationListener() {}
62 virtual ~InstrumentationListener() {}
63
64 // Call-back for when a method is entered.
65 virtual void MethodEntered(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -070066 ArtMethod* method,
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070067 uint32_t dex_pc) REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Ian Rogers62d6c772013-02-27 08:32:07 -080068
69 // Call-back for when a method is exited.
Ian Rogers62d6c772013-02-27 08:32:07 -080070 virtual void MethodExited(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -070071 ArtMethod* method, uint32_t dex_pc,
Ian Rogers62d6c772013-02-27 08:32:07 -080072 const JValue& return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070073 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Ian Rogers62d6c772013-02-27 08:32:07 -080074
75 // Call-back for when a method is popped due to an exception throw. A method will either cause a
76 // MethodExited call-back or a MethodUnwind call-back when its activation is removed.
Sebastien Hertz51db44a2013-11-19 10:00:29 +010077 virtual void MethodUnwind(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -070078 ArtMethod* method, uint32_t dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070079 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Ian Rogers62d6c772013-02-27 08:32:07 -080080
81 // Call-back for when the dex pc moves in a method.
82 virtual void DexPcMoved(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -070083 ArtMethod* method, uint32_t new_dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070084 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Ian Rogers62d6c772013-02-27 08:32:07 -080085
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +020086 // Call-back for when we read from a field.
Mathieu Chartiere401d142015-04-22 13:56:20 -070087 virtual void FieldRead(Thread* thread, mirror::Object* this_object, ArtMethod* method,
Mathieu Chartierc7853442015-03-27 14:35:38 -070088 uint32_t dex_pc, ArtField* field) = 0;
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +020089
90 // Call-back for when we write into a field.
Mathieu Chartiere401d142015-04-22 13:56:20 -070091 virtual void FieldWritten(Thread* thread, mirror::Object* this_object, ArtMethod* method,
Mathieu Chartierc7853442015-03-27 14:35:38 -070092 uint32_t dex_pc, ArtField* field, const JValue& field_value) = 0;
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +020093
Ian Rogers62d6c772013-02-27 08:32:07 -080094 // Call-back when an exception is caught.
Nicolas Geoffray14691c52015-03-05 10:40:17 +000095 virtual void ExceptionCaught(Thread* thread, mirror::Throwable* exception_object)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070096 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080097
Nicolas Geoffray81f0f952016-01-20 16:25:19 +000098 // Call-back for when we execute a branch.
99 virtual void Branch(Thread* thread,
100 ArtMethod* method,
101 uint32_t dex_pc,
102 int32_t dex_pc_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700103 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100104
105 // Call-back for when we get an invokevirtual or an invokeinterface.
106 virtual void InvokeVirtualOrInterface(Thread* thread,
107 mirror::Object* this_object,
108 ArtMethod* caller,
109 uint32_t dex_pc,
110 ArtMethod* callee)
Mathieu Chartier3fdb3fe2016-01-14 10:24:28 -0800111 REQUIRES(Roles::uninterruptible_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700112 REQUIRES_SHARED(Locks::mutator_lock_) = 0;
jeffhao725a9572012-11-13 18:20:12 -0800113};
114
Ian Rogers62d6c772013-02-27 08:32:07 -0800115// Instrumentation is a catch-all for when extra information is required from the runtime. The
116// typical use for instrumentation is for profiling and debugging. Instrumentation may add stubs
117// to method entry and exit, it may also force execution to be switched to the interpreter and
118// trigger deoptimization.
jeffhao725a9572012-11-13 18:20:12 -0800119class Instrumentation {
120 public:
Ian Rogers62d6c772013-02-27 08:32:07 -0800121 enum InstrumentationEvent {
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800122 kMethodEntered = 0x1,
123 kMethodExited = 0x2,
124 kMethodUnwind = 0x4,
125 kDexPcMoved = 0x8,
126 kFieldRead = 0x10,
127 kFieldWritten = 0x20,
128 kExceptionCaught = 0x40,
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000129 kBranch = 0x80,
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100130 kInvokeVirtualOrInterface = 0x100,
Ian Rogers62d6c772013-02-27 08:32:07 -0800131 };
jeffhao725a9572012-11-13 18:20:12 -0800132
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200133 enum class InstrumentationLevel {
134 kInstrumentNothing, // execute without instrumentation
135 kInstrumentWithInstrumentationStubs, // execute with instrumentation entry/exit stubs
136 kInstrumentWithInterpreter // execute with interpreter
137 };
138
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700139 Instrumentation();
jeffhao725a9572012-11-13 18:20:12 -0800140
Ian Rogers62d6c772013-02-27 08:32:07 -0800141 // Add a listener to be notified of the masked together sent of instrumentation events. This
142 // suspend the runtime to install stubs. You are expected to hold the mutator lock as a proxy
143 // for saying you should have suspended all threads (installing stubs while threads are running
144 // will break).
145 void AddListener(InstrumentationListener* listener, uint32_t events)
Mathieu Chartier90443472015-07-16 20:32:27 -0700146 REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::classlinker_classes_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800147
Ian Rogers62d6c772013-02-27 08:32:07 -0800148 // Removes a listener possibly removing instrumentation stubs.
149 void RemoveListener(InstrumentationListener* listener, uint32_t events)
Mathieu Chartier90443472015-07-16 20:32:27 -0700150 REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::classlinker_classes_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800151
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100152 // Deoptimization.
Sebastien Hertza76a6d42014-03-20 16:40:17 +0100153 void EnableDeoptimization()
Mathieu Chartieraa516822015-10-02 15:53:37 -0700154 REQUIRES(Locks::mutator_lock_)
155 REQUIRES(!deoptimized_methods_lock_);
156 // Calls UndeoptimizeEverything which may visit class linker classes through ConfigureStubs.
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200157 void DisableDeoptimization(const char* key)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700158 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
159 REQUIRES(!deoptimized_methods_lock_);
160
Sebastien Hertza76a6d42014-03-20 16:40:17 +0100161 bool AreAllMethodsDeoptimized() const {
162 return interpreter_stubs_installed_;
163 }
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700164 bool ShouldNotifyMethodEnterExitEvents() const REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100165
166 // Executes everything with interpreter.
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200167 void DeoptimizeEverything(const char* key)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700168 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
169 REQUIRES(!Locks::thread_list_lock_,
170 !Locks::classlinker_classes_lock_,
Mathieu Chartier90443472015-07-16 20:32:27 -0700171 !deoptimized_methods_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100172
Mathieu Chartieraa516822015-10-02 15:53:37 -0700173 // Executes everything with compiled code (or interpreter if there is no code). May visit class
174 // linker classes through ConfigureStubs.
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200175 void UndeoptimizeEverything(const char* key)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700176 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
177 REQUIRES(!Locks::thread_list_lock_,
178 !Locks::classlinker_classes_lock_,
Mathieu Chartier90443472015-07-16 20:32:27 -0700179 !deoptimized_methods_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100180
181 // Deoptimize a method by forcing its execution with the interpreter. Nevertheless, a static
182 // method (except a class initializer) set to the resolution trampoline will be deoptimized only
183 // once its declaring class is initialized.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700184 void Deoptimize(ArtMethod* method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700185 REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !deoptimized_methods_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100186
187 // Undeoptimze the method by restoring its entrypoints. Nevertheless, a static method
188 // (except a class initializer) set to the resolution trampoline will be updated only once its
189 // declaring class is initialized.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700190 void Undeoptimize(ArtMethod* method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700191 REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !deoptimized_methods_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100192
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200193 // Indicates whether the method has been deoptimized so it is executed with the interpreter.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700194 bool IsDeoptimized(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700195 REQUIRES(!deoptimized_methods_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100196
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200197 // Enable method tracing by installing instrumentation entry/exit stubs or interpreter.
198 void EnableMethodTracing(const char* key,
199 bool needs_interpreter = kDeoptimizeForAccurateMethodEntryExitListeners)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700200 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
201 REQUIRES(!Locks::thread_list_lock_,
202 !Locks::classlinker_classes_lock_,
Mathieu Chartier90443472015-07-16 20:32:27 -0700203 !deoptimized_methods_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100204
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200205 // Disable method tracing by uninstalling instrumentation entry/exit stubs or interpreter.
206 void DisableMethodTracing(const char* key)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700207 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
208 REQUIRES(!Locks::thread_list_lock_,
209 !Locks::classlinker_classes_lock_,
Mathieu Chartier90443472015-07-16 20:32:27 -0700210 !deoptimized_methods_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100211
Sebastien Hertzed2be172014-08-19 15:33:43 +0200212 InterpreterHandlerTable GetInterpreterHandlerTable() const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700213 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200214 return interpreter_handler_table_;
215 }
216
Mathieu Chartier90443472015-07-16 20:32:27 -0700217 void InstrumentQuickAllocEntryPoints() REQUIRES(!Locks::instrument_entrypoints_lock_);
218 void UninstrumentQuickAllocEntryPoints() REQUIRES(!Locks::instrument_entrypoints_lock_);
Mathieu Chartier9ef78b52014-09-25 17:03:12 -0700219 void InstrumentQuickAllocEntryPointsLocked()
Mathieu Chartier90443472015-07-16 20:32:27 -0700220 REQUIRES(Locks::instrument_entrypoints_lock_, !Locks::thread_list_lock_,
221 !Locks::runtime_shutdown_lock_);
Mathieu Chartier9ef78b52014-09-25 17:03:12 -0700222 void UninstrumentQuickAllocEntryPointsLocked()
Mathieu Chartier90443472015-07-16 20:32:27 -0700223 REQUIRES(Locks::instrument_entrypoints_lock_, !Locks::thread_list_lock_,
224 !Locks::runtime_shutdown_lock_);
225 void ResetQuickAllocEntryPoints() REQUIRES(Locks::runtime_shutdown_lock_);
Ian Rogersfa824272013-11-05 16:12:57 -0800226
Ian Rogers62d6c772013-02-27 08:32:07 -0800227 // Update the code of a method respecting any installed stubs.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700228 void UpdateMethodsCode(ArtMethod* method, const void* quick_code)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700229 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800230
Mingyao Yang3fd448a2016-05-10 14:30:41 -0700231 // Update the code of a method respecting any installed stubs from debugger.
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000232 void UpdateMethodsCodeForJavaDebuggable(ArtMethod* method, const void* quick_code)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700233 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
Mingyao Yang3fd448a2016-05-10 14:30:41 -0700234
Ian Rogers62d6c772013-02-27 08:32:07 -0800235 // Get the quick code for the given method. More efficient than asking the class linker as it
236 // will short-cut to GetCode if instrumentation and static method resolution stubs aren't
237 // installed.
Andreas Gampe542451c2016-07-26 09:02:02 -0700238 const void* GetQuickCodeFor(ArtMethod* method, PointerSize pointer_size) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700239 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800240
241 void ForceInterpretOnly() {
242 interpret_only_ = true;
243 forced_interpret_only_ = true;
244 }
245
Brian Carlstromea46f952013-07-30 01:26:50 -0700246 // Called by ArtMethod::Invoke to determine dispatch mechanism.
Ian Rogers62d6c772013-02-27 08:32:07 -0800247 bool InterpretOnly() const {
248 return interpret_only_;
249 }
250
Hiroshi Yamauchi563b47c2014-02-28 17:18:37 -0800251 bool IsForcedInterpretOnly() const {
252 return forced_interpret_only_;
253 }
254
Mingyao Yang6ea1a0e2016-01-29 12:12:49 -0800255 // Code is in boot image oat file which isn't compiled as debuggable.
256 // Need debug version (interpreter or jitted) if that's the case.
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000257 bool NeedDebugVersionFor(ArtMethod* method) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700258 REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang6ea1a0e2016-01-29 12:12:49 -0800259
Ian Rogers62d6c772013-02-27 08:32:07 -0800260 bool AreExitStubsInstalled() const {
261 return instrumentation_stubs_installed_;
262 }
263
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700264 bool HasMethodEntryListeners() const REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz74109f62013-06-07 17:40:09 +0200265 return have_method_entry_listeners_;
266 }
267
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700268 bool HasMethodExitListeners() const REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz74109f62013-06-07 17:40:09 +0200269 return have_method_exit_listeners_;
270 }
271
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700272 bool HasMethodUnwindListeners() const REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200273 return have_method_unwind_listeners_;
274 }
275
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700276 bool HasDexPcListeners() const REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz74109f62013-06-07 17:40:09 +0200277 return have_dex_pc_listeners_;
278 }
279
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700280 bool HasFieldReadListeners() const REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200281 return have_field_read_listeners_;
282 }
283
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700284 bool HasFieldWriteListeners() const REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200285 return have_field_write_listeners_;
286 }
287
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700288 bool HasExceptionCaughtListeners() const REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz9f102032014-05-23 08:59:42 +0200289 return have_exception_caught_listeners_;
290 }
291
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700292 bool HasBranchListeners() const REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000293 return have_branch_listeners_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800294 }
295
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700296 bool HasInvokeVirtualOrInterfaceListeners() const REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100297 return have_invoke_virtual_or_interface_listeners_;
298 }
299
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700300 bool IsActive() const REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200301 return have_dex_pc_listeners_ || have_method_entry_listeners_ || have_method_exit_listeners_ ||
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200302 have_field_read_listeners_ || have_field_write_listeners_ ||
Bill Buzbeefd522f92016-02-11 22:37:42 +0000303 have_exception_caught_listeners_ || have_method_unwind_listeners_ ||
304 have_branch_listeners_ || have_invoke_virtual_or_interface_listeners_;
305 }
306
307 // Any instrumentation *other* than what is needed for Jit profiling active?
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700308 bool NonJitProfilingActive() const REQUIRES_SHARED(Locks::mutator_lock_) {
Bill Buzbeefd522f92016-02-11 22:37:42 +0000309 return have_dex_pc_listeners_ || have_method_exit_listeners_ ||
310 have_field_read_listeners_ || have_field_write_listeners_ ||
Bill Buzbee1d011d92016-04-04 16:59:29 +0000311 have_exception_caught_listeners_ || have_method_unwind_listeners_ ||
312 have_branch_listeners_;
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200313 }
314
Ian Rogers62d6c772013-02-27 08:32:07 -0800315 // Inform listeners that a method has been entered. A dex PC is provided as we may install
316 // listeners into executing code and get method enter events for methods already on the stack.
317 void MethodEnterEvent(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700318 ArtMethod* method, uint32_t dex_pc) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700319 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz74109f62013-06-07 17:40:09 +0200320 if (UNLIKELY(HasMethodEntryListeners())) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800321 MethodEnterEventImpl(thread, this_object, method, dex_pc);
322 }
323 }
324
325 // Inform listeners that a method has been exited.
326 void MethodExitEvent(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700327 ArtMethod* method, uint32_t dex_pc,
Ian Rogers62d6c772013-02-27 08:32:07 -0800328 const JValue& return_value) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700329 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz74109f62013-06-07 17:40:09 +0200330 if (UNLIKELY(HasMethodExitListeners())) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800331 MethodExitEventImpl(thread, this_object, method, dex_pc, return_value);
332 }
333 }
334
335 // Inform listeners that a method has been exited due to an exception.
336 void MethodUnwindEvent(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700337 ArtMethod* method, uint32_t dex_pc) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700338 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800339
340 // Inform listeners that the dex pc has moved (only supported by the interpreter).
341 void DexPcMovedEvent(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700342 ArtMethod* method, uint32_t dex_pc) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700343 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz74109f62013-06-07 17:40:09 +0200344 if (UNLIKELY(HasDexPcListeners())) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800345 DexPcMovedEventImpl(thread, this_object, method, dex_pc);
346 }
347 }
348
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000349 // Inform listeners that a branch has been taken (only supported by the interpreter).
350 void Branch(Thread* thread, ArtMethod* method, uint32_t dex_pc, int32_t offset) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700351 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000352 if (UNLIKELY(HasBranchListeners())) {
353 BranchImpl(thread, method, dex_pc, offset);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800354 }
355 }
356
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200357 // Inform listeners that we read a field (only supported by the interpreter).
358 void FieldReadEvent(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700359 ArtMethod* method, uint32_t dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700360 ArtField* field) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700361 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200362 if (UNLIKELY(HasFieldReadListeners())) {
363 FieldReadEventImpl(thread, this_object, method, dex_pc, field);
364 }
365 }
366
367 // Inform listeners that we write a field (only supported by the interpreter).
368 void FieldWriteEvent(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700369 ArtMethod* method, uint32_t dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700370 ArtField* field, const JValue& field_value) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700371 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200372 if (UNLIKELY(HasFieldWriteListeners())) {
373 FieldWriteEventImpl(thread, this_object, method, dex_pc, field, field_value);
374 }
375 }
376
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100377 void InvokeVirtualOrInterface(Thread* thread,
378 mirror::Object* this_object,
379 ArtMethod* caller,
380 uint32_t dex_pc,
381 ArtMethod* callee) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700382 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100383 if (UNLIKELY(HasInvokeVirtualOrInterfaceListeners())) {
384 InvokeVirtualOrInterfaceImpl(thread, this_object, caller, dex_pc, callee);
385 }
386 }
387
Ian Rogers62d6c772013-02-27 08:32:07 -0800388 // Inform listeners that an exception was caught.
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000389 void ExceptionCaughtEvent(Thread* thread, mirror::Throwable* exception_object) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700390 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800391
392 // Called when an instrumented method is entered. The intended link register (lr) is saved so
393 // that returning causes a branch to the method exit stub. Generates method enter events.
394 void PushInstrumentationStackFrame(Thread* self, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700395 ArtMethod* method, uintptr_t lr,
Jeff Hao9a916d32013-06-27 18:45:37 -0700396 bool interpreter_entry)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700397 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800398
399 // Called when an instrumented method is exited. Removes the pushed instrumentation frame
400 // returning the intended link register. Generates method exit events.
Andreas Gamped58342c2014-06-05 14:18:08 -0700401 TwoWordReturn PopInstrumentationStackFrame(Thread* self, uintptr_t* return_pc,
402 uint64_t gpr_result, uint64_t fpr_result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700403 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800404
405 // Pops an instrumentation frame from the current thread and generate an unwind event.
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700406 // Returns the return pc for the instrumentation frame that's popped.
407 uintptr_t PopMethodForUnwind(Thread* self, bool is_deoptimization) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700408 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800409
410 // Call back for configure stubs.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700411 void InstallStubsForClass(mirror::Class* klass) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700412 REQUIRES(!deoptimized_methods_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800413
Mathieu Chartiere401d142015-04-22 13:56:20 -0700414 void InstallStubsForMethod(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700415 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100416
Mingyao Yang99170c62015-07-06 11:10:37 -0700417 // Install instrumentation exit stub on every method of the stack of the given thread.
418 // This is used by the debugger to cause a deoptimization of the thread's stack after updating
419 // local variable(s).
420 void InstrumentThreadStack(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700421 REQUIRES_SHARED(Locks::mutator_lock_)
Mingyao Yang99170c62015-07-06 11:10:37 -0700422 REQUIRES(!Locks::thread_list_lock_);
423
Sebastien Hertzb2feaaf2015-10-12 13:40:10 +0000424 static size_t ComputeFrameId(Thread* self,
425 size_t frame_depth,
426 size_t inlined_frames_before_frame)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700427 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzb2feaaf2015-10-12 13:40:10 +0000428
Mathieu Chartiereebc3af2016-02-29 18:13:38 -0800429 // Does not hold lock, used to check if someone changed from not instrumented to instrumented
430 // during a GC suspend point.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700431 bool AllocEntrypointsInstrumented() const REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier50e93312016-03-16 11:25:29 -0700432 return alloc_entrypoints_instrumented_;
Mathieu Chartiereebc3af2016-02-29 18:13:38 -0800433 }
434
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200435 InstrumentationLevel GetCurrentInstrumentationLevel() const;
436
Alex Lightdba61482016-12-21 08:20:29 -0800437 private:
438 // Returns true if moving to the given instrumentation level requires the installation of stubs.
439 // False otherwise.
440 bool RequiresInstrumentationInstallation(InstrumentationLevel new_level) const;
441
Ian Rogers62d6c772013-02-27 08:32:07 -0800442 // Does the job of installing or removing instrumentation code within methods.
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200443 // In order to support multiple clients using instrumentation at the same time,
444 // the caller must pass a unique key (a string) identifying it so we remind which
445 // instrumentation level it needs. Therefore the current instrumentation level
446 // becomes the highest instrumentation level required by a client.
447 void ConfigureStubs(const char* key, InstrumentationLevel desired_instrumentation_level)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700448 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
449 REQUIRES(!deoptimized_methods_lock_,
450 !Locks::thread_list_lock_,
Mathieu Chartier90443472015-07-16 20:32:27 -0700451 !Locks::classlinker_classes_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800452
Mathieu Chartier90443472015-07-16 20:32:27 -0700453 void UpdateInterpreterHandlerTable() REQUIRES(Locks::mutator_lock_) {
buzbee1452bee2015-03-06 14:43:04 -0800454 /*
455 * TUNING: Dalvik's mterp stashes the actual current handler table base in a
456 * tls field. For Arm, this enables all suspend, debug & tracing checks to be
457 * collapsed into a single conditionally-executed ldw instruction.
458 * Move to Dalvik-style handler-table management for both the goto interpreter and
459 * mterp.
460 */
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200461 interpreter_handler_table_ = IsActive() ? kAlternativeHandlerTable : kMainHandlerTable;
462 }
463
Mathieu Chartier661974a2014-01-09 11:23:53 -0800464 // No thread safety analysis to get around SetQuickAllocEntryPointsInstrumented requiring
465 // exclusive access to mutator lock which you can't get if the runtime isn't started.
Mathieu Chartier9ef78b52014-09-25 17:03:12 -0700466 void SetEntrypointsInstrumented(bool instrumented) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier661974a2014-01-09 11:23:53 -0800467
Ian Rogers62d6c772013-02-27 08:32:07 -0800468 void MethodEnterEventImpl(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700469 ArtMethod* method, uint32_t dex_pc) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700470 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800471 void MethodExitEventImpl(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700472 ArtMethod* method,
Ian Rogers62d6c772013-02-27 08:32:07 -0800473 uint32_t dex_pc, const JValue& return_value) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700474 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800475 void DexPcMovedEventImpl(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700476 ArtMethod* method, uint32_t dex_pc) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700477 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000478 void BranchImpl(Thread* thread, ArtMethod* method, uint32_t dex_pc, int32_t offset) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700479 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100480 void InvokeVirtualOrInterfaceImpl(Thread* thread,
481 mirror::Object* this_object,
482 ArtMethod* caller,
483 uint32_t dex_pc,
484 ArtMethod* callee) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700485 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200486 void FieldReadEventImpl(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700487 ArtMethod* method, uint32_t dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700488 ArtField* field) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700489 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200490 void FieldWriteEventImpl(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700491 ArtMethod* method, uint32_t dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700492 ArtField* field, const JValue& field_value) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700493 REQUIRES_SHARED(Locks::mutator_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800494
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700495 // Read barrier-aware utility functions for accessing deoptimized_methods_
Mathieu Chartiere401d142015-04-22 13:56:20 -0700496 bool AddDeoptimizedMethod(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700497 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(deoptimized_methods_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700498 bool IsDeoptimizedMethod(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700499 REQUIRES_SHARED(Locks::mutator_lock_, deoptimized_methods_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700500 bool RemoveDeoptimizedMethod(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700501 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(deoptimized_methods_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700502 ArtMethod* BeginDeoptimizedMethod()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700503 REQUIRES_SHARED(Locks::mutator_lock_, deoptimized_methods_lock_);
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700504 bool IsDeoptimizedMethodsEmpty() const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700505 REQUIRES_SHARED(Locks::mutator_lock_, deoptimized_methods_lock_);
Mingyao Yang3fd448a2016-05-10 14:30:41 -0700506 void UpdateMethodsCodeImpl(ArtMethod* method, const void* quick_code)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700507 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
Mingyao Yang3fd448a2016-05-10 14:30:41 -0700508
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700509
Brian Carlstromea46f952013-07-30 01:26:50 -0700510 // Have we hijacked ArtMethod::code_ so that it calls instrumentation/interpreter code?
Ian Rogers62d6c772013-02-27 08:32:07 -0800511 bool instrumentation_stubs_installed_;
512
Brian Carlstromea46f952013-07-30 01:26:50 -0700513 // Have we hijacked ArtMethod::code_ to reference the enter/exit stubs?
Ian Rogers62d6c772013-02-27 08:32:07 -0800514 bool entry_exit_stubs_installed_;
515
Brian Carlstromea46f952013-07-30 01:26:50 -0700516 // Have we hijacked ArtMethod::code_ to reference the enter interpreter stub?
Ian Rogers62d6c772013-02-27 08:32:07 -0800517 bool interpreter_stubs_installed_;
518
519 // Do we need the fidelity of events that we only get from running within the interpreter?
520 bool interpret_only_;
521
522 // Did the runtime request we only run in the interpreter? ie -Xint mode.
523 bool forced_interpret_only_;
524
525 // Do we have any listeners for method entry events? Short-cut to avoid taking the
526 // instrumentation_lock_.
Sebastien Hertzed2be172014-08-19 15:33:43 +0200527 bool have_method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800528
529 // Do we have any listeners for method exit events? Short-cut to avoid taking the
530 // instrumentation_lock_.
Sebastien Hertzed2be172014-08-19 15:33:43 +0200531 bool have_method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800532
533 // Do we have any listeners for method unwind events? Short-cut to avoid taking the
534 // instrumentation_lock_.
Sebastien Hertzed2be172014-08-19 15:33:43 +0200535 bool have_method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800536
537 // Do we have any listeners for dex move events? Short-cut to avoid taking the
538 // instrumentation_lock_.
Sebastien Hertzed2be172014-08-19 15:33:43 +0200539 bool have_dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800540
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200541 // Do we have any listeners for field read events? Short-cut to avoid taking the
542 // instrumentation_lock_.
Sebastien Hertzed2be172014-08-19 15:33:43 +0200543 bool have_field_read_listeners_ GUARDED_BY(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200544
545 // Do we have any listeners for field write events? Short-cut to avoid taking the
546 // instrumentation_lock_.
Sebastien Hertzed2be172014-08-19 15:33:43 +0200547 bool have_field_write_listeners_ GUARDED_BY(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200548
Ian Rogers62d6c772013-02-27 08:32:07 -0800549 // Do we have any exception caught listeners? Short-cut to avoid taking the instrumentation_lock_.
Sebastien Hertzed2be172014-08-19 15:33:43 +0200550 bool have_exception_caught_listeners_ GUARDED_BY(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800551
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000552 // Do we have any branch listeners? Short-cut to avoid taking the instrumentation_lock_.
553 bool have_branch_listeners_ GUARDED_BY(Locks::mutator_lock_);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800554
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100555 // Do we have any invoke listeners? Short-cut to avoid taking the instrumentation_lock_.
556 bool have_invoke_virtual_or_interface_listeners_ GUARDED_BY(Locks::mutator_lock_);
557
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200558 // Contains the instrumentation level required by each client of the instrumentation identified
559 // by a string key.
560 typedef SafeMap<const char*, InstrumentationLevel> InstrumentationLevelTable;
561 InstrumentationLevelTable requested_instrumentation_levels_ GUARDED_BY(Locks::mutator_lock_);
562
Ian Rogers62d6c772013-02-27 08:32:07 -0800563 // The event listeners, written to with the mutator_lock_ exclusively held.
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000564 // Mutators must be able to iterate over these lists concurrently, that is, with listeners being
565 // added or removed while iterating. The modifying thread holds exclusive lock,
566 // so other threads cannot iterate (i.e. read the data of the list) at the same time but they
567 // do keep iterators that need to remain valid. This is the reason these listeners are std::list
568 // and not for example std::vector: the existing storage for a std::list does not move.
569 // Note that mutators cannot make a copy of these lists before iterating, as the instrumentation
570 // listeners can also be deleted concurrently.
571 // As a result, these lists are never trimmed. That's acceptable given the low number of
572 // listeners we have.
Ian Rogers62d6c772013-02-27 08:32:07 -0800573 std::list<InstrumentationListener*> method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_);
574 std::list<InstrumentationListener*> method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_);
575 std::list<InstrumentationListener*> method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_);
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000576 std::list<InstrumentationListener*> branch_listeners_ GUARDED_BY(Locks::mutator_lock_);
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100577 std::list<InstrumentationListener*> invoke_virtual_or_interface_listeners_
578 GUARDED_BY(Locks::mutator_lock_);
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000579 std::list<InstrumentationListener*> dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_);
580 std::list<InstrumentationListener*> field_read_listeners_ GUARDED_BY(Locks::mutator_lock_);
581 std::list<InstrumentationListener*> field_write_listeners_ GUARDED_BY(Locks::mutator_lock_);
582 std::list<InstrumentationListener*> exception_caught_listeners_ GUARDED_BY(Locks::mutator_lock_);
jeffhao725a9572012-11-13 18:20:12 -0800583
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100584 // The set of methods being deoptimized (by the debugger) which must be executed with interpreter
585 // only.
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700586 mutable ReaderWriterMutex deoptimized_methods_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700587 std::unordered_set<ArtMethod*> deoptimized_methods_ GUARDED_BY(deoptimized_methods_lock_);
Sebastien Hertz11d40c22014-02-19 18:00:17 +0100588 bool deoptimization_enabled_;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100589
Ian Rogersfa824272013-11-05 16:12:57 -0800590 // Current interpreter handler table. This is updated each time the thread state flags are
591 // modified.
Sebastien Hertzed2be172014-08-19 15:33:43 +0200592 InterpreterHandlerTable interpreter_handler_table_ GUARDED_BY(Locks::mutator_lock_);
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200593
Ian Rogersfa824272013-11-05 16:12:57 -0800594 // Greater than 0 if quick alloc entry points instrumented.
Mathieu Chartiereebc3af2016-02-29 18:13:38 -0800595 size_t quick_alloc_entry_points_instrumentation_counter_;
Mathieu Chartier50e93312016-03-16 11:25:29 -0700596
597 // alloc_entrypoints_instrumented_ is only updated with all the threads suspended, this is done
598 // to prevent races with the GC where the GC relies on thread suspension only see
599 // alloc_entrypoints_instrumented_ change during suspend points.
600 bool alloc_entrypoints_instrumented_;
601
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200602 friend class InstrumentationTest; // For GetCurrentInstrumentationLevel and ConfigureStubs.
603
jeffhao725a9572012-11-13 18:20:12 -0800604 DISALLOW_COPY_AND_ASSIGN(Instrumentation);
605};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700606std::ostream& operator<<(std::ostream& os, const Instrumentation::InstrumentationEvent& rhs);
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200607std::ostream& operator<<(std::ostream& os, const Instrumentation::InstrumentationLevel& rhs);
jeffhao725a9572012-11-13 18:20:12 -0800608
Ian Rogers62d6c772013-02-27 08:32:07 -0800609// An element in the instrumentation side stack maintained in art::Thread.
610struct InstrumentationStackFrame {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700611 InstrumentationStackFrame(mirror::Object* this_object, ArtMethod* method,
Jeff Hao9a916d32013-06-27 18:45:37 -0700612 uintptr_t return_pc, size_t frame_id, bool interpreter_entry)
613 : this_object_(this_object), method_(method), return_pc_(return_pc), frame_id_(frame_id),
614 interpreter_entry_(interpreter_entry) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800615 }
616
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700617 std::string Dump() const REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800618
619 mirror::Object* this_object_;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700620 ArtMethod* method_;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100621 uintptr_t return_pc_;
622 size_t frame_id_;
623 bool interpreter_entry_;
Ian Rogers62d6c772013-02-27 08:32:07 -0800624};
625
626} // namespace instrumentation
jeffhao725a9572012-11-13 18:20:12 -0800627} // namespace art
628
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700629#endif // ART_RUNTIME_INSTRUMENTATION_H_