instrumentation.h revision 1d011d9306fd4ff57d72411775d415a86f5ed398
1725a957985171d712d5c048cc3d00ff14968784bjeffhao/*
2725a957985171d712d5c048cc3d00ff14968784bjeffhao * Copyright (C) 2011 The Android Open Source Project
3725a957985171d712d5c048cc3d00ff14968784bjeffhao *
4725a957985171d712d5c048cc3d00ff14968784bjeffhao * Licensed under the Apache License, Version 2.0 (the "License");
5725a957985171d712d5c048cc3d00ff14968784bjeffhao * you may not use this file except in compliance with the License.
6725a957985171d712d5c048cc3d00ff14968784bjeffhao * You may obtain a copy of the License at
7725a957985171d712d5c048cc3d00ff14968784bjeffhao *
8725a957985171d712d5c048cc3d00ff14968784bjeffhao *      http://www.apache.org/licenses/LICENSE-2.0
9725a957985171d712d5c048cc3d00ff14968784bjeffhao *
10725a957985171d712d5c048cc3d00ff14968784bjeffhao * Unless required by applicable law or agreed to in writing, software
11725a957985171d712d5c048cc3d00ff14968784bjeffhao * distributed under the License is distributed on an "AS IS" BASIS,
12725a957985171d712d5c048cc3d00ff14968784bjeffhao * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13725a957985171d712d5c048cc3d00ff14968784bjeffhao * See the License for the specific language governing permissions and
14725a957985171d712d5c048cc3d00ff14968784bjeffhao * limitations under the License.
15725a957985171d712d5c048cc3d00ff14968784bjeffhao */
16725a957985171d712d5c048cc3d00ff14968784bjeffhao
17fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#ifndef ART_RUNTIME_INSTRUMENTATION_H_
18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_RUNTIME_INSTRUMENTATION_H_
19725a957985171d712d5c048cc3d00ff14968784bjeffhao
20576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers#include <stdint.h>
21576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers#include <list>
22e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier#include <unordered_set>
23576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers
24d582fa4ea62083a7598dded5b82dc2198b3daac7Ian Rogers#include "arch/instruction_set.h"
25761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes#include "base/macros.h"
26719d1a33f6569864f529e5a3fff59e7bca97aad0Ian Rogers#include "base/mutex.h"
2794f7b49578b6aaa80de8ffed230648d601393905Hiroshi Yamauchi#include "gc_root.h"
280462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz#include "safe_map.h"
292dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers
30725a957985171d712d5c048cc3d00ff14968784bjeffhaonamespace art {
312dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersnamespace mirror {
32ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  class Class;
33ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  class Object;
34ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  class Throwable;
3562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers}  // namespace mirror
36c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartierclass ArtField;
37e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartierclass ArtMethod;
3862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogersunion JValue;
39725a957985171d712d5c048cc3d00ff14968784bjeffhaoclass Thread;
40725a957985171d712d5c048cc3d00ff14968784bjeffhao
4162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogersnamespace instrumentation {
42725a957985171d712d5c048cc3d00ff14968784bjeffhao
43ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz// Interpreter handler tables.
44ee1997a3b83334985e757f369c09e111b121661bSebastien Hertzenum InterpreterHandlerTable {
45ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz  kMainHandlerTable = 0,          // Main handler table: no suspend check, no instrumentation.
46ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz  kAlternativeHandlerTable = 1,   // Alternative handler table: suspend check and/or instrumentation
47ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz                                  // enabled.
48ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz  kNumHandlerTables
49ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz};
50ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz
5140da286d3207d88ed8ff3f5caac4873874603428Andreas Gampe// Do we want to deoptimize for method entry and exit listeners or just try to intercept
5240da286d3207d88ed8ff3f5caac4873874603428Andreas Gampe// invocations? Deoptimization forces all code to run in the interpreter and considerably hurts the
5340da286d3207d88ed8ff3f5caac4873874603428Andreas Gampe// application's performance.
5440da286d3207d88ed8ff3f5caac4873874603428Andreas Gampestatic constexpr bool kDeoptimizeForAccurateMethodEntryExitListeners = true;
5540da286d3207d88ed8ff3f5caac4873874603428Andreas Gampe
5662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers// Instrumentation event listener API. Registered listeners will get the appropriate call back for
5762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers// the events they are listening for. The call backs supply the thread, method and dex_pc the event
5862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers// occurred upon. The thread may or may not be Thread::Current().
5962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogersstruct InstrumentationListener {
6062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  InstrumentationListener() {}
6162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  virtual ~InstrumentationListener() {}
6262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
6362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Call-back for when a method is entered.
6462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  virtual void MethodEntered(Thread* thread, mirror::Object* this_object,
65e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                             ArtMethod* method,
6690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier                             uint32_t dex_pc) SHARED_REQUIRES(Locks::mutator_lock_) = 0;
6762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
6862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Call-back for when a method is exited.
6962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  virtual void MethodExited(Thread* thread, mirror::Object* this_object,
70e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                            ArtMethod* method, uint32_t dex_pc,
7162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                            const JValue& return_value)
7290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) = 0;
7362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
7462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Call-back for when a method is popped due to an exception throw. A method will either cause a
7562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // MethodExited call-back or a MethodUnwind call-back when its activation is removed.
7651db44a194bafc3810a41164a8b39614f10e79dfSebastien Hertz  virtual void MethodUnwind(Thread* thread, mirror::Object* this_object,
77e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                            ArtMethod* method, uint32_t dex_pc)
7890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) = 0;
7962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
8062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Call-back for when the dex pc moves in a method.
8162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  virtual void DexPcMoved(Thread* thread, mirror::Object* this_object,
82e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                          ArtMethod* method, uint32_t new_dex_pc)
8390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) = 0;
8462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
853f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // Call-back for when we read from a field.
86e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  virtual void FieldRead(Thread* thread, mirror::Object* this_object, ArtMethod* method,
87c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier                         uint32_t dex_pc, ArtField* field) = 0;
883f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
893f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // Call-back for when we write into a field.
90e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  virtual void FieldWritten(Thread* thread, mirror::Object* this_object, ArtMethod* method,
91c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier                            uint32_t dex_pc, ArtField* field, const JValue& field_value) = 0;
923f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
9362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Call-back when an exception is caught.
9414691c5e786e8c2c5734f687e4c96217340771beNicolas Geoffray  virtual void ExceptionCaught(Thread* thread, mirror::Throwable* exception_object)
9590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) = 0;
96e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier
9781f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  // Call-back for when we execute a branch.
9881f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  virtual void Branch(Thread* thread,
9981f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray                      ArtMethod* method,
10081f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray                      uint32_t dex_pc,
10181f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray                      int32_t dex_pc_offset)
10290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) = 0;
1035550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray
1045550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  // Call-back for when we get an invokevirtual or an invokeinterface.
1055550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  virtual void InvokeVirtualOrInterface(Thread* thread,
1065550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                        mirror::Object* this_object,
1075550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                        ArtMethod* caller,
1085550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                        uint32_t dex_pc,
1095550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                        ArtMethod* callee)
1103fdb3fec5c36127d8568b2f89698906ba4b68576Mathieu Chartier      REQUIRES(Roles::uninterruptible_)
1115550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray      SHARED_REQUIRES(Locks::mutator_lock_) = 0;
112725a957985171d712d5c048cc3d00ff14968784bjeffhao};
113725a957985171d712d5c048cc3d00ff14968784bjeffhao
11462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers// Instrumentation is a catch-all for when extra information is required from the runtime. The
11562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers// typical use for instrumentation is for profiling and debugging. Instrumentation may add stubs
11662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers// to method entry and exit, it may also force execution to be switched to the interpreter and
11762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers// trigger deoptimization.
118725a957985171d712d5c048cc3d00ff14968784bjeffhaoclass Instrumentation {
119725a957985171d712d5c048cc3d00ff14968784bjeffhao public:
12062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  enum InstrumentationEvent {
121e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier    kMethodEntered = 0x1,
122e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier    kMethodExited = 0x2,
123e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier    kMethodUnwind = 0x4,
124e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier    kDexPcMoved = 0x8,
125e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier    kFieldRead = 0x10,
126e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier    kFieldWritten = 0x20,
127e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier    kExceptionCaught = 0x40,
12881f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray    kBranch = 0x80,
1295550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray    kInvokeVirtualOrInterface = 0x100,
13062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  };
13162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
1320462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  enum class InstrumentationLevel {
1330462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz    kInstrumentNothing,                   // execute without instrumentation
1340462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz    kInstrumentWithInstrumentationStubs,  // execute with instrumentation entry/exit stubs
1350462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz    kInstrumentWithInterpreter            // execute with interpreter
1360462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  };
1370462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz
1383b05e9ba874449dbff65b01b8781001f7d93eea6Mathieu Chartier  Instrumentation();
13962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
14062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Add a listener to be notified of the masked together sent of instrumentation events. This
14162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // suspend the runtime to install stubs. You are expected to hold the mutator lock as a proxy
14262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // for saying you should have suspended all threads (installing stubs while threads are running
14362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // will break).
14462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void AddListener(InstrumentationListener* listener, uint32_t events)
14590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::classlinker_classes_lock_);
14662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
14762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Removes a listener possibly removing instrumentation stubs.
14862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void RemoveListener(InstrumentationListener* listener, uint32_t events)
14990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::classlinker_classes_lock_);
15062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
151138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // Deoptimization.
152a76a6d4cb3dedec909bd927f20bc0ab23198a337Sebastien Hertz  void EnableDeoptimization()
153aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(Locks::mutator_lock_)
154aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(!deoptimized_methods_lock_);
155aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier  // Calls UndeoptimizeEverything which may visit class linker classes through ConfigureStubs.
1560462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  void DisableDeoptimization(const char* key)
157aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
158aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(!deoptimized_methods_lock_);
159aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier
160a76a6d4cb3dedec909bd927f20bc0ab23198a337Sebastien Hertz  bool AreAllMethodsDeoptimized() const {
161a76a6d4cb3dedec909bd927f20bc0ab23198a337Sebastien Hertz    return interpreter_stubs_installed_;
162a76a6d4cb3dedec909bd927f20bc0ab23198a337Sebastien Hertz  }
16390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool ShouldNotifyMethodEnterExitEvents() const SHARED_REQUIRES(Locks::mutator_lock_);
164138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
165138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // Executes everything with interpreter.
1660462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  void DeoptimizeEverything(const char* key)
167aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
168aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(!Locks::thread_list_lock_,
169aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier               !Locks::classlinker_classes_lock_,
17090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier               !deoptimized_methods_lock_);
171138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
172aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier  // Executes everything with compiled code (or interpreter if there is no code). May visit class
173aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier  // linker classes through ConfigureStubs.
1740462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  void UndeoptimizeEverything(const char* key)
175aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
176aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(!Locks::thread_list_lock_,
177aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier               !Locks::classlinker_classes_lock_,
17890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier               !deoptimized_methods_lock_);
179138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
180138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // Deoptimize a method by forcing its execution with the interpreter. Nevertheless, a static
181138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // method (except a class initializer) set to the resolution trampoline will be deoptimized only
182138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // once its declaring class is initialized.
183e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  void Deoptimize(ArtMethod* method)
18490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !deoptimized_methods_lock_);
185138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
186138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // Undeoptimze the method by restoring its entrypoints. Nevertheless, a static method
187138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // (except a class initializer) set to the resolution trampoline will be updated only once its
188138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // declaring class is initialized.
189e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  void Undeoptimize(ArtMethod* method)
19090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !deoptimized_methods_lock_);
191138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
1920462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // Indicates whether the method has been deoptimized so it is executed with the interpreter.
193e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  bool IsDeoptimized(ArtMethod* method)
19490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      REQUIRES(!deoptimized_methods_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
195138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
1960462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // Enable method tracing by installing instrumentation entry/exit stubs or interpreter.
1970462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  void EnableMethodTracing(const char* key,
1980462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz                           bool needs_interpreter = kDeoptimizeForAccurateMethodEntryExitListeners)
199aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
200aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(!Locks::thread_list_lock_,
201aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier               !Locks::classlinker_classes_lock_,
20290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier               !deoptimized_methods_lock_);
203138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
2040462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // Disable method tracing by uninstalling instrumentation entry/exit stubs or interpreter.
2050462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  void DisableMethodTracing(const char* key)
206aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
207aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(!Locks::thread_list_lock_,
208aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier               !Locks::classlinker_classes_lock_,
20990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier               !deoptimized_methods_lock_);
210138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
211ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  InterpreterHandlerTable GetInterpreterHandlerTable() const
21290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
213ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz    return interpreter_handler_table_;
214ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz  }
215ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz
21690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  void InstrumentQuickAllocEntryPoints() REQUIRES(!Locks::instrument_entrypoints_lock_);
21790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  void UninstrumentQuickAllocEntryPoints() REQUIRES(!Locks::instrument_entrypoints_lock_);
2189ef78b59da51080882e47505896b420977fd79aeMathieu Chartier  void InstrumentQuickAllocEntryPointsLocked()
21990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      REQUIRES(Locks::instrument_entrypoints_lock_, !Locks::thread_list_lock_,
22090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier               !Locks::runtime_shutdown_lock_);
2219ef78b59da51080882e47505896b420977fd79aeMathieu Chartier  void UninstrumentQuickAllocEntryPointsLocked()
22290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      REQUIRES(Locks::instrument_entrypoints_lock_, !Locks::thread_list_lock_,
22390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier               !Locks::runtime_shutdown_lock_);
22490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  void ResetQuickAllocEntryPoints() REQUIRES(Locks::runtime_shutdown_lock_);
225fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers
22662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Update the code of a method respecting any installed stubs.
227e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  void UpdateMethodsCode(ArtMethod* method, const void* quick_code)
22890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
22962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
23062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Get the quick code for the given method. More efficient than asking the class linker as it
23162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // will short-cut to GetCode if instrumentation and static method resolution stubs aren't
23262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // installed.
233e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  const void* GetQuickCodeFor(ArtMethod* method, size_t pointer_size) const
23490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
23562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
23662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void ForceInterpretOnly() {
23762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    interpret_only_ = true;
23862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    forced_interpret_only_ = true;
23962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
24062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
241ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  // Called by ArtMethod::Invoke to determine dispatch mechanism.
24262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool InterpretOnly() const {
24362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    return interpret_only_;
24462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
24562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
246563b47cc142e477da244539b1d63070425e7fd78Hiroshi Yamauchi  bool IsForcedInterpretOnly() const {
247563b47cc142e477da244539b1d63070425e7fd78Hiroshi Yamauchi    return forced_interpret_only_;
248563b47cc142e477da244539b1d63070425e7fd78Hiroshi Yamauchi  }
249563b47cc142e477da244539b1d63070425e7fd78Hiroshi Yamauchi
2506ea1a0e2168c8d9b6d97c075c73a72d84080f45bMingyao Yang  // Code is in boot image oat file which isn't compiled as debuggable.
2516ea1a0e2168c8d9b6d97c075c73a72d84080f45bMingyao Yang  // Need debug version (interpreter or jitted) if that's the case.
2526ea1a0e2168c8d9b6d97c075c73a72d84080f45bMingyao Yang  bool NeedDebugVersionForBootImageCode(ArtMethod* method, const void* code) const
2536ea1a0e2168c8d9b6d97c075c73a72d84080f45bMingyao Yang      SHARED_REQUIRES(Locks::mutator_lock_);
2546ea1a0e2168c8d9b6d97c075c73a72d84080f45bMingyao Yang
25562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool AreExitStubsInstalled() const {
25662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    return instrumentation_stubs_installed_;
25762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
25862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
25990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasMethodEntryListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
26074109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    return have_method_entry_listeners_;
26174109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz  }
26274109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz
26390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasMethodExitListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
26474109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    return have_method_exit_listeners_;
26574109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz  }
26674109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz
26790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasMethodUnwindListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
2680462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz    return have_method_unwind_listeners_;
2690462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  }
2700462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz
27190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasDexPcListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
27274109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    return have_dex_pc_listeners_;
27374109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz  }
27474109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz
27590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasFieldReadListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
2763f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    return have_field_read_listeners_;
2773f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  }
2783f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
27990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasFieldWriteListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
2803f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    return have_field_write_listeners_;
2813f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  }
2823f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
28390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasExceptionCaughtListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
2849f1020305292a21fd14a402b189c765a125226abSebastien Hertz    return have_exception_caught_listeners_;
2859f1020305292a21fd14a402b189c765a125226abSebastien Hertz  }
2869f1020305292a21fd14a402b189c765a125226abSebastien Hertz
28781f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  bool HasBranchListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
28881f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray    return have_branch_listeners_;
289e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier  }
290e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier
2915550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  bool HasInvokeVirtualOrInterfaceListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
2925550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray    return have_invoke_virtual_or_interface_listeners_;
2935550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  }
2945550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray
29590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool IsActive() const SHARED_REQUIRES(Locks::mutator_lock_) {
296ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz    return have_dex_pc_listeners_ || have_method_entry_listeners_ || have_method_exit_listeners_ ||
29742cd43fa593e8f0427eb0ec158bef08814a6180bSebastien Hertz        have_field_read_listeners_ || have_field_write_listeners_ ||
298fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee        have_exception_caught_listeners_ || have_method_unwind_listeners_ ||
299fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee        have_branch_listeners_ || have_invoke_virtual_or_interface_listeners_;
300fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee  }
301fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee
302fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee  // Any instrumentation *other* than what is needed for Jit profiling active?
303fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee  bool NonJitProfilingActive() const SHARED_REQUIRES(Locks::mutator_lock_) {
304fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee    return have_dex_pc_listeners_ || have_method_exit_listeners_ ||
305fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee        have_field_read_listeners_ || have_field_write_listeners_ ||
3061d011d9306fd4ff57d72411775d415a86f5ed398Bill Buzbee        have_exception_caught_listeners_ || have_method_unwind_listeners_ ||
3071d011d9306fd4ff57d72411775d415a86f5ed398Bill Buzbee        have_branch_listeners_;
308ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz  }
309ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz
31062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Inform listeners that a method has been entered. A dex PC is provided as we may install
31162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // listeners into executing code and get method enter events for methods already on the stack.
31262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void MethodEnterEvent(Thread* thread, mirror::Object* this_object,
313e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                        ArtMethod* method, uint32_t dex_pc) const
31490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
31574109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    if (UNLIKELY(HasMethodEntryListeners())) {
31662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers      MethodEnterEventImpl(thread, this_object, method, dex_pc);
31762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    }
31862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
31962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
32062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Inform listeners that a method has been exited.
32162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void MethodExitEvent(Thread* thread, mirror::Object* this_object,
322e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                       ArtMethod* method, uint32_t dex_pc,
32362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                       const JValue& return_value) const
32490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
32574109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    if (UNLIKELY(HasMethodExitListeners())) {
32662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers      MethodExitEventImpl(thread, this_object, method, dex_pc, return_value);
32762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    }
32862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
32962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
33062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Inform listeners that a method has been exited due to an exception.
33162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void MethodUnwindEvent(Thread* thread, mirror::Object* this_object,
332e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                         ArtMethod* method, uint32_t dex_pc) const
33390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
33462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
33562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Inform listeners that the dex pc has moved (only supported by the interpreter).
33662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void DexPcMovedEvent(Thread* thread, mirror::Object* this_object,
337e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                       ArtMethod* method, uint32_t dex_pc) const
33890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
33974109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    if (UNLIKELY(HasDexPcListeners())) {
34062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers      DexPcMovedEventImpl(thread, this_object, method, dex_pc);
34162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    }
34262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
343725a957985171d712d5c048cc3d00ff14968784bjeffhao
34481f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  // Inform listeners that a branch has been taken (only supported by the interpreter).
34581f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  void Branch(Thread* thread, ArtMethod* method, uint32_t dex_pc, int32_t offset) const
34690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
34781f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray    if (UNLIKELY(HasBranchListeners())) {
34881f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray      BranchImpl(thread, method, dex_pc, offset);
349e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier    }
350e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier  }
351e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier
3523f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // Inform listeners that we read a field (only supported by the interpreter).
3533f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  void FieldReadEvent(Thread* thread, mirror::Object* this_object,
354e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                      ArtMethod* method, uint32_t dex_pc,
355c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier                      ArtField* field) const
35690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
3573f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    if (UNLIKELY(HasFieldReadListeners())) {
3583f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz      FieldReadEventImpl(thread, this_object, method, dex_pc, field);
3593f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    }
3603f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  }
3613f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
3623f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // Inform listeners that we write a field (only supported by the interpreter).
3633f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  void FieldWriteEvent(Thread* thread, mirror::Object* this_object,
364e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                       ArtMethod* method, uint32_t dex_pc,
365c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier                       ArtField* field, const JValue& field_value) const
36690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
3673f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    if (UNLIKELY(HasFieldWriteListeners())) {
3683f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz      FieldWriteEventImpl(thread, this_object, method, dex_pc, field, field_value);
3693f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    }
3703f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  }
3713f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
3725550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  void InvokeVirtualOrInterface(Thread* thread,
3735550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                mirror::Object* this_object,
3745550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                ArtMethod* caller,
3755550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                uint32_t dex_pc,
3765550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                ArtMethod* callee) const
3775550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray      SHARED_REQUIRES(Locks::mutator_lock_) {
3785550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray    if (UNLIKELY(HasInvokeVirtualOrInterfaceListeners())) {
3795550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray      InvokeVirtualOrInterfaceImpl(thread, this_object, caller, dex_pc, callee);
3805550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray    }
3815550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  }
3825550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray
38362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Inform listeners that an exception was caught.
38414691c5e786e8c2c5734f687e4c96217340771beNicolas Geoffray  void ExceptionCaughtEvent(Thread* thread, mirror::Throwable* exception_object) const
38590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
386725a957985171d712d5c048cc3d00ff14968784bjeffhao
38762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Called when an instrumented method is entered. The intended link register (lr) is saved so
38862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // that returning causes a branch to the method exit stub. Generates method enter events.
38962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void PushInstrumentationStackFrame(Thread* self, mirror::Object* this_object,
390e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                                     ArtMethod* method, uintptr_t lr,
3919a916d3c0d0574d106c764e737c67b52988d6139Jeff Hao                                     bool interpreter_entry)
39290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
393725a957985171d712d5c048cc3d00ff14968784bjeffhao
39462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Called when an instrumented method is exited. Removes the pushed instrumentation frame
39562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // returning the intended link register. Generates method exit events.
396d58342caa97108ba413bad467c285c0377f138f5Andreas Gampe  TwoWordReturn PopInstrumentationStackFrame(Thread* self, uintptr_t* return_pc,
397d58342caa97108ba413bad467c285c0377f138f5Andreas Gampe                                             uint64_t gpr_result, uint64_t fpr_result)
39890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
399725a957985171d712d5c048cc3d00ff14968784bjeffhao
40062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Pops an instrumentation frame from the current thread and generate an unwind event.
40162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void PopMethodForUnwind(Thread* self, bool is_deoptimization) const
40290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
40362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
40462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Call back for configure stubs.
40590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  void InstallStubsForClass(mirror::Class* klass) SHARED_REQUIRES(Locks::mutator_lock_)
40690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      REQUIRES(!deoptimized_methods_lock_);
407725a957985171d712d5c048cc3d00ff14968784bjeffhao
408e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  void InstallStubsForMethod(ArtMethod* method)
40990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
410138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
41199170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang  // Install instrumentation exit stub on every method of the stack of the given thread.
41299170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang  // This is used by the debugger to cause a deoptimization of the thread's stack after updating
41399170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang  // local variable(s).
41499170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang  void InstrumentThreadStack(Thread* thread)
41599170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang      SHARED_REQUIRES(Locks::mutator_lock_)
41699170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang      REQUIRES(!Locks::thread_list_lock_);
41799170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang
418b2feaafd89813af69c65da95e0b51b1a4cecaf0bSebastien Hertz  static size_t ComputeFrameId(Thread* self,
419b2feaafd89813af69c65da95e0b51b1a4cecaf0bSebastien Hertz                               size_t frame_depth,
420b2feaafd89813af69c65da95e0b51b1a4cecaf0bSebastien Hertz                               size_t inlined_frames_before_frame)
421b2feaafd89813af69c65da95e0b51b1a4cecaf0bSebastien Hertz      SHARED_REQUIRES(Locks::mutator_lock_);
422b2feaafd89813af69c65da95e0b51b1a4cecaf0bSebastien Hertz
423eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier  // Does not hold lock, used to check if someone changed from not instrumented to instrumented
424eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier  // during a GC suspend point.
425eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier  bool AllocEntrypointsInstrumented() const SHARED_REQUIRES(Locks::mutator_lock_) {
42650e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier    return alloc_entrypoints_instrumented_;
427eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier  }
428eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier
429725a957985171d712d5c048cc3d00ff14968784bjeffhao private:
4300462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  InstrumentationLevel GetCurrentInstrumentationLevel() const;
4310462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz
43262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Does the job of installing or removing instrumentation code within methods.
4330462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // In order to support multiple clients using instrumentation at the same time,
4340462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // the caller must pass a unique key (a string) identifying it so we remind which
4350462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // instrumentation level it needs. Therefore the current instrumentation level
4360462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // becomes the highest instrumentation level required by a client.
4370462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  void ConfigureStubs(const char* key, InstrumentationLevel desired_instrumentation_level)
438aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
439aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(!deoptimized_methods_lock_,
440aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier               !Locks::thread_list_lock_,
44190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier               !Locks::classlinker_classes_lock_);
44262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
44390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  void UpdateInterpreterHandlerTable() REQUIRES(Locks::mutator_lock_) {
4441452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee    /*
4451452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     * TUNING: Dalvik's mterp stashes the actual current handler table base in a
4461452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     * tls field.  For Arm, this enables all suspend, debug & tracing checks to be
4471452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     * collapsed into a single conditionally-executed ldw instruction.
4481452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     * Move to Dalvik-style handler-table management for both the goto interpreter and
4491452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     * mterp.
4501452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     */
451ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz    interpreter_handler_table_ = IsActive() ? kAlternativeHandlerTable : kMainHandlerTable;
452ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz  }
453ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz
454661974a5561e5ccdfbac8cb5d8df8b7e6f3483b8Mathieu Chartier  // No thread safety analysis to get around SetQuickAllocEntryPointsInstrumented requiring
455661974a5561e5ccdfbac8cb5d8df8b7e6f3483b8Mathieu Chartier  // exclusive access to mutator lock which you can't get if the runtime isn't started.
4569ef78b59da51080882e47505896b420977fd79aeMathieu Chartier  void SetEntrypointsInstrumented(bool instrumented) NO_THREAD_SAFETY_ANALYSIS;
457661974a5561e5ccdfbac8cb5d8df8b7e6f3483b8Mathieu Chartier
45862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void MethodEnterEventImpl(Thread* thread, mirror::Object* this_object,
459e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                            ArtMethod* method, uint32_t dex_pc) const
46090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
46162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void MethodExitEventImpl(Thread* thread, mirror::Object* this_object,
462e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                           ArtMethod* method,
46362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                           uint32_t dex_pc, const JValue& return_value) const
46490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
46562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void DexPcMovedEventImpl(Thread* thread, mirror::Object* this_object,
466e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                           ArtMethod* method, uint32_t dex_pc) const
46790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
46881f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  void BranchImpl(Thread* thread, ArtMethod* method, uint32_t dex_pc, int32_t offset) const
46990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
4705550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  void InvokeVirtualOrInterfaceImpl(Thread* thread,
4715550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                    mirror::Object* this_object,
4725550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                    ArtMethod* caller,
4735550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                    uint32_t dex_pc,
4745550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                    ArtMethod* callee) const
4755550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray      SHARED_REQUIRES(Locks::mutator_lock_);
4763f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  void FieldReadEventImpl(Thread* thread, mirror::Object* this_object,
477e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                           ArtMethod* method, uint32_t dex_pc,
478c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier                           ArtField* field) const
47990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
4803f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  void FieldWriteEventImpl(Thread* thread, mirror::Object* this_object,
481e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                           ArtMethod* method, uint32_t dex_pc,
482c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier                           ArtField* field, const JValue& field_value) const
48390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
48462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
485799eb3a5555254427db269921042419bc30d4d86Hiroshi Yamauchi  // Read barrier-aware utility functions for accessing deoptimized_methods_
486e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  bool AddDeoptimizedMethod(ArtMethod* method)
48790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(deoptimized_methods_lock_);
488e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  bool IsDeoptimizedMethod(ArtMethod* method)
48990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_, deoptimized_methods_lock_);
490e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  bool RemoveDeoptimizedMethod(ArtMethod* method)
49190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(deoptimized_methods_lock_);
492e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  ArtMethod* BeginDeoptimizedMethod()
49390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_, deoptimized_methods_lock_);
494799eb3a5555254427db269921042419bc30d4d86Hiroshi Yamauchi  bool IsDeoptimizedMethodsEmpty() const
49590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_, deoptimized_methods_lock_);
496799eb3a5555254427db269921042419bc30d4d86Hiroshi Yamauchi
497ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  // Have we hijacked ArtMethod::code_ so that it calls instrumentation/interpreter code?
49862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool instrumentation_stubs_installed_;
49962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
500ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  // Have we hijacked ArtMethod::code_ to reference the enter/exit stubs?
50162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool entry_exit_stubs_installed_;
50262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
503ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  // Have we hijacked ArtMethod::code_ to reference the enter interpreter stub?
50462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool interpreter_stubs_installed_;
50562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
50662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we need the fidelity of events that we only get from running within the interpreter?
50762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool interpret_only_;
508725a957985171d712d5c048cc3d00ff14968784bjeffhao
50962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Did the runtime request we only run in the interpreter? ie -Xint mode.
51062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool forced_interpret_only_;
511725a957985171d712d5c048cc3d00ff14968784bjeffhao
51262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we have any listeners for method entry events? Short-cut to avoid taking the
51362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // instrumentation_lock_.
514ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_);
51562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
51662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we have any listeners for method exit events? Short-cut to avoid taking the
51762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // instrumentation_lock_.
518ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_);
51962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
52062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we have any listeners for method unwind events? Short-cut to avoid taking the
52162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // instrumentation_lock_.
522ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_);
52362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
52462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we have any listeners for dex move events? Short-cut to avoid taking the
52562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // instrumentation_lock_.
526ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_);
52762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
5283f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // Do we have any listeners for field read events? Short-cut to avoid taking the
5293f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // instrumentation_lock_.
530ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_field_read_listeners_ GUARDED_BY(Locks::mutator_lock_);
5313f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
5323f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // Do we have any listeners for field write events? Short-cut to avoid taking the
5333f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // instrumentation_lock_.
534ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_field_write_listeners_ GUARDED_BY(Locks::mutator_lock_);
5353f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
53662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we have any exception caught listeners? Short-cut to avoid taking the instrumentation_lock_.
537ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_exception_caught_listeners_ GUARDED_BY(Locks::mutator_lock_);
53862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
53981f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  // Do we have any branch listeners? Short-cut to avoid taking the instrumentation_lock_.
54081f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  bool have_branch_listeners_ GUARDED_BY(Locks::mutator_lock_);
541e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier
5425550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  // Do we have any invoke listeners? Short-cut to avoid taking the instrumentation_lock_.
5435550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  bool have_invoke_virtual_or_interface_listeners_ GUARDED_BY(Locks::mutator_lock_);
5445550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray
5450462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // Contains the instrumentation level required by each client of the instrumentation identified
5460462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // by a string key.
5470462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  typedef SafeMap<const char*, InstrumentationLevel> InstrumentationLevelTable;
5480462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  InstrumentationLevelTable requested_instrumentation_levels_ GUARDED_BY(Locks::mutator_lock_);
5490462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz
55062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // The event listeners, written to with the mutator_lock_ exclusively held.
551514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // Mutators must be able to iterate over these lists concurrently, that is, with listeners being
552514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // added or removed while iterating. The modifying thread holds exclusive lock,
553514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // so other threads cannot iterate (i.e. read the data of the list) at the same time but they
554514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // do keep iterators that need to remain valid. This is the reason these listeners are std::list
555514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // and not for example std::vector: the existing storage for a std::list does not move.
556514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // Note that mutators cannot make a copy of these lists before iterating, as the instrumentation
557514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // listeners can also be deleted concurrently.
558514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // As a result, these lists are never trimmed. That's acceptable given the low number of
559514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // listeners we have.
56062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  std::list<InstrumentationListener*> method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_);
56162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  std::list<InstrumentationListener*> method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_);
56262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  std::list<InstrumentationListener*> method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_);
56381f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  std::list<InstrumentationListener*> branch_listeners_ GUARDED_BY(Locks::mutator_lock_);
5645550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  std::list<InstrumentationListener*> invoke_virtual_or_interface_listeners_
5655550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray      GUARDED_BY(Locks::mutator_lock_);
566514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  std::list<InstrumentationListener*> dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_);
567514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  std::list<InstrumentationListener*> field_read_listeners_ GUARDED_BY(Locks::mutator_lock_);
568514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  std::list<InstrumentationListener*> field_write_listeners_ GUARDED_BY(Locks::mutator_lock_);
569514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  std::list<InstrumentationListener*> exception_caught_listeners_ GUARDED_BY(Locks::mutator_lock_);
570725a957985171d712d5c048cc3d00ff14968784bjeffhao
571138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // The set of methods being deoptimized (by the debugger) which must be executed with interpreter
572138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // only.
5733b05e9ba874449dbff65b01b8781001f7d93eea6Mathieu Chartier  mutable ReaderWriterMutex deoptimized_methods_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
574e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  std::unordered_set<ArtMethod*> deoptimized_methods_ GUARDED_BY(deoptimized_methods_lock_);
57511d40c250ec86c784cf76b8c31e1cf9285d555dcSebastien Hertz  bool deoptimization_enabled_;
576138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
577fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers  // Current interpreter handler table. This is updated each time the thread state flags are
578fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers  // modified.
579ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  InterpreterHandlerTable interpreter_handler_table_ GUARDED_BY(Locks::mutator_lock_);
580ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz
581fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers  // Greater than 0 if quick alloc entry points instrumented.
582eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier  size_t quick_alloc_entry_points_instrumentation_counter_;
58350e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier
58450e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier  // alloc_entrypoints_instrumented_ is only updated with all the threads suspended, this is done
58550e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier  // to prevent races with the GC where the GC relies on thread suspension only see
58650e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier  // alloc_entrypoints_instrumented_ change during suspend points.
58750e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier  bool alloc_entrypoints_instrumented_;
58850e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier
5890462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  friend class InstrumentationTest;  // For GetCurrentInstrumentationLevel and ConfigureStubs.
5900462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz
591725a957985171d712d5c048cc3d00ff14968784bjeffhao  DISALLOW_COPY_AND_ASSIGN(Instrumentation);
592725a957985171d712d5c048cc3d00ff14968784bjeffhao};
5936a3c1fcb4ba42ad4d5d142c17a3712a6ddd3866fIan Rogersstd::ostream& operator<<(std::ostream& os, const Instrumentation::InstrumentationEvent& rhs);
5940462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertzstd::ostream& operator<<(std::ostream& os, const Instrumentation::InstrumentationLevel& rhs);
595725a957985171d712d5c048cc3d00ff14968784bjeffhao
59662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers// An element in the instrumentation side stack maintained in art::Thread.
59762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogersstruct InstrumentationStackFrame {
598e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  InstrumentationStackFrame(mirror::Object* this_object, ArtMethod* method,
5999a916d3c0d0574d106c764e737c67b52988d6139Jeff Hao                            uintptr_t return_pc, size_t frame_id, bool interpreter_entry)
6009a916d3c0d0574d106c764e737c67b52988d6139Jeff Hao      : this_object_(this_object), method_(method), return_pc_(return_pc), frame_id_(frame_id),
6019a916d3c0d0574d106c764e737c67b52988d6139Jeff Hao        interpreter_entry_(interpreter_entry) {
60262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
60362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
60490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  std::string Dump() const SHARED_REQUIRES(Locks::mutator_lock_);
60562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
60662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  mirror::Object* this_object_;
607e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  ArtMethod* method_;
608138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  uintptr_t return_pc_;
609138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  size_t frame_id_;
610138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  bool interpreter_entry_;
61162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers};
61262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
61362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers}  // namespace instrumentation
614725a957985171d712d5c048cc3d00ff14968784bjeffhao}  // namespace art
615725a957985171d712d5c048cc3d00ff14968784bjeffhao
616fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif  // ART_RUNTIME_INSTRUMENTATION_H_
617