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
2304ba674b914f24f2baf42769401cff43f8261abd6Mingyao Yang  // Update the code of a method respecting any installed stubs from debugger.
2314ba674b914f24f2baf42769401cff43f8261abd6Mingyao Yang  void UpdateMethodsCodeFromDebugger(ArtMethod* method, const void* quick_code)
2324ba674b914f24f2baf42769401cff43f8261abd6Mingyao Yang      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
2334ba674b914f24f2baf42769401cff43f8261abd6Mingyao Yang
23462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Get the quick code for the given method. More efficient than asking the class linker as it
23562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // will short-cut to GetCode if instrumentation and static method resolution stubs aren't
23662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // installed.
237e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  const void* GetQuickCodeFor(ArtMethod* method, size_t pointer_size) const
23890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
23962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
24062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void ForceInterpretOnly() {
24162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    interpret_only_ = true;
24262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    forced_interpret_only_ = true;
24362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
24462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
245ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  // Called by ArtMethod::Invoke to determine dispatch mechanism.
24662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool InterpretOnly() const {
24762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    return interpret_only_;
24862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
24962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
250563b47cc142e477da244539b1d63070425e7fd78Hiroshi Yamauchi  bool IsForcedInterpretOnly() const {
251563b47cc142e477da244539b1d63070425e7fd78Hiroshi Yamauchi    return forced_interpret_only_;
252563b47cc142e477da244539b1d63070425e7fd78Hiroshi Yamauchi  }
253563b47cc142e477da244539b1d63070425e7fd78Hiroshi Yamauchi
2546ea1a0e2168c8d9b6d97c075c73a72d84080f45bMingyao Yang  // Code is in boot image oat file which isn't compiled as debuggable.
2556ea1a0e2168c8d9b6d97c075c73a72d84080f45bMingyao Yang  // Need debug version (interpreter or jitted) if that's the case.
2566ea1a0e2168c8d9b6d97c075c73a72d84080f45bMingyao Yang  bool NeedDebugVersionForBootImageCode(ArtMethod* method, const void* code) const
2576ea1a0e2168c8d9b6d97c075c73a72d84080f45bMingyao Yang      SHARED_REQUIRES(Locks::mutator_lock_);
2586ea1a0e2168c8d9b6d97c075c73a72d84080f45bMingyao Yang
25962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool AreExitStubsInstalled() const {
26062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    return instrumentation_stubs_installed_;
26162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
26262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
26390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasMethodEntryListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
26474109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    return have_method_entry_listeners_;
26574109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz  }
26674109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz
26790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasMethodExitListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
26874109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    return have_method_exit_listeners_;
26974109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz  }
27074109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz
27190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasMethodUnwindListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
2720462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz    return have_method_unwind_listeners_;
2730462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  }
2740462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz
27590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasDexPcListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
27674109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    return have_dex_pc_listeners_;
27774109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz  }
27874109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz
27990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasFieldReadListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
2803f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    return have_field_read_listeners_;
2813f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  }
2823f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
28390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasFieldWriteListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
2843f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    return have_field_write_listeners_;
2853f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  }
2863f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
28790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool HasExceptionCaughtListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
2889f1020305292a21fd14a402b189c765a125226abSebastien Hertz    return have_exception_caught_listeners_;
2899f1020305292a21fd14a402b189c765a125226abSebastien Hertz  }
2909f1020305292a21fd14a402b189c765a125226abSebastien Hertz
29181f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  bool HasBranchListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
29281f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray    return have_branch_listeners_;
293e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier  }
294e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier
2955550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  bool HasInvokeVirtualOrInterfaceListeners() const SHARED_REQUIRES(Locks::mutator_lock_) {
2965550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray    return have_invoke_virtual_or_interface_listeners_;
2975550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  }
2985550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray
29990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  bool IsActive() const SHARED_REQUIRES(Locks::mutator_lock_) {
300ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz    return have_dex_pc_listeners_ || have_method_entry_listeners_ || have_method_exit_listeners_ ||
30142cd43fa593e8f0427eb0ec158bef08814a6180bSebastien Hertz        have_field_read_listeners_ || have_field_write_listeners_ ||
302fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee        have_exception_caught_listeners_ || have_method_unwind_listeners_ ||
303fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee        have_branch_listeners_ || have_invoke_virtual_or_interface_listeners_;
304fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee  }
305fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee
306fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee  // Any instrumentation *other* than what is needed for Jit profiling active?
307fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee  bool NonJitProfilingActive() const SHARED_REQUIRES(Locks::mutator_lock_) {
308fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee    return have_dex_pc_listeners_ || have_method_exit_listeners_ ||
309fd522f9039befff986701ff05054ffdd1be1dd33Bill Buzbee        have_field_read_listeners_ || have_field_write_listeners_ ||
3101d011d9306fd4ff57d72411775d415a86f5ed398Bill Buzbee        have_exception_caught_listeners_ || have_method_unwind_listeners_ ||
3111d011d9306fd4ff57d72411775d415a86f5ed398Bill Buzbee        have_branch_listeners_;
312ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz  }
313ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz
31462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Inform listeners that a method has been entered. A dex PC is provided as we may install
31562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // listeners into executing code and get method enter events for methods already on the stack.
31662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void MethodEnterEvent(Thread* thread, mirror::Object* this_object,
317e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                        ArtMethod* method, uint32_t dex_pc) const
31890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
31974109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    if (UNLIKELY(HasMethodEntryListeners())) {
32062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers      MethodEnterEventImpl(thread, this_object, method, dex_pc);
32162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    }
32262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
32362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
32462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Inform listeners that a method has been exited.
32562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void MethodExitEvent(Thread* thread, mirror::Object* this_object,
326e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                       ArtMethod* method, uint32_t dex_pc,
32762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                       const JValue& return_value) const
32890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
32974109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    if (UNLIKELY(HasMethodExitListeners())) {
33062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers      MethodExitEventImpl(thread, this_object, method, dex_pc, return_value);
33162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    }
33262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
33362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
33462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Inform listeners that a method has been exited due to an exception.
33562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void MethodUnwindEvent(Thread* thread, mirror::Object* this_object,
336e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                         ArtMethod* method, uint32_t dex_pc) const
33790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
33862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
33962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Inform listeners that the dex pc has moved (only supported by the interpreter).
34062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void DexPcMovedEvent(Thread* thread, mirror::Object* this_object,
341e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                       ArtMethod* method, uint32_t dex_pc) const
34290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
34374109f6683096de494b1457fa6d5b0ac33b4c98cSebastien Hertz    if (UNLIKELY(HasDexPcListeners())) {
34462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers      DexPcMovedEventImpl(thread, this_object, method, dex_pc);
34562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers    }
34662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
347725a957985171d712d5c048cc3d00ff14968784bjeffhao
34881f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  // Inform listeners that a branch has been taken (only supported by the interpreter).
34981f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  void Branch(Thread* thread, ArtMethod* method, uint32_t dex_pc, int32_t offset) const
35090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
35181f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray    if (UNLIKELY(HasBranchListeners())) {
35281f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray      BranchImpl(thread, method, dex_pc, offset);
353e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier    }
354e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier  }
355e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier
3563f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // Inform listeners that we read a field (only supported by the interpreter).
3573f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  void FieldReadEvent(Thread* thread, mirror::Object* this_object,
358e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                      ArtMethod* method, uint32_t dex_pc,
359c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier                      ArtField* field) const
36090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
3613f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    if (UNLIKELY(HasFieldReadListeners())) {
3623f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz      FieldReadEventImpl(thread, this_object, method, dex_pc, field);
3633f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    }
3643f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  }
3653f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
3663f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // Inform listeners that we write a field (only supported by the interpreter).
3673f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  void FieldWriteEvent(Thread* thread, mirror::Object* this_object,
368e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                       ArtMethod* method, uint32_t dex_pc,
369c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier                       ArtField* field, const JValue& field_value) const
37090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) {
3713f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    if (UNLIKELY(HasFieldWriteListeners())) {
3723f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz      FieldWriteEventImpl(thread, this_object, method, dex_pc, field, field_value);
3733f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz    }
3743f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  }
3753f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
3765550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  void InvokeVirtualOrInterface(Thread* thread,
3775550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                mirror::Object* this_object,
3785550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                ArtMethod* caller,
3795550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                uint32_t dex_pc,
3805550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                ArtMethod* callee) const
3815550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray      SHARED_REQUIRES(Locks::mutator_lock_) {
3825550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray    if (UNLIKELY(HasInvokeVirtualOrInterfaceListeners())) {
3835550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray      InvokeVirtualOrInterfaceImpl(thread, this_object, caller, dex_pc, callee);
3845550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray    }
3855550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  }
3865550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray
38762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Inform listeners that an exception was caught.
38814691c5e786e8c2c5734f687e4c96217340771beNicolas Geoffray  void ExceptionCaughtEvent(Thread* thread, mirror::Throwable* exception_object) const
38990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
390725a957985171d712d5c048cc3d00ff14968784bjeffhao
39162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Called when an instrumented method is entered. The intended link register (lr) is saved so
39262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // that returning causes a branch to the method exit stub. Generates method enter events.
39362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void PushInstrumentationStackFrame(Thread* self, mirror::Object* this_object,
394e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                                     ArtMethod* method, uintptr_t lr,
3959a916d3c0d0574d106c764e737c67b52988d6139Jeff Hao                                     bool interpreter_entry)
39690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
397725a957985171d712d5c048cc3d00ff14968784bjeffhao
39862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Called when an instrumented method is exited. Removes the pushed instrumentation frame
39962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // returning the intended link register. Generates method exit events.
400d58342caa97108ba413bad467c285c0377f138f5Andreas Gampe  TwoWordReturn PopInstrumentationStackFrame(Thread* self, uintptr_t* return_pc,
401d58342caa97108ba413bad467c285c0377f138f5Andreas Gampe                                             uint64_t gpr_result, uint64_t fpr_result)
40290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
403725a957985171d712d5c048cc3d00ff14968784bjeffhao
40462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Pops an instrumentation frame from the current thread and generate an unwind event.
40562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void PopMethodForUnwind(Thread* self, bool is_deoptimization) const
40690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
40762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
40862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Call back for configure stubs.
40990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  void InstallStubsForClass(mirror::Class* klass) SHARED_REQUIRES(Locks::mutator_lock_)
41090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      REQUIRES(!deoptimized_methods_lock_);
411725a957985171d712d5c048cc3d00ff14968784bjeffhao
412e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  void InstallStubsForMethod(ArtMethod* method)
41390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
414138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
41599170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang  // Install instrumentation exit stub on every method of the stack of the given thread.
41699170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang  // This is used by the debugger to cause a deoptimization of the thread's stack after updating
41799170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang  // local variable(s).
41899170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang  void InstrumentThreadStack(Thread* thread)
41999170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang      SHARED_REQUIRES(Locks::mutator_lock_)
42099170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang      REQUIRES(!Locks::thread_list_lock_);
42199170c636dfae4908b102347cfe9f92bad1881ccMingyao Yang
422b2feaafd89813af69c65da95e0b51b1a4cecaf0bSebastien Hertz  static size_t ComputeFrameId(Thread* self,
423b2feaafd89813af69c65da95e0b51b1a4cecaf0bSebastien Hertz                               size_t frame_depth,
424b2feaafd89813af69c65da95e0b51b1a4cecaf0bSebastien Hertz                               size_t inlined_frames_before_frame)
425b2feaafd89813af69c65da95e0b51b1a4cecaf0bSebastien Hertz      SHARED_REQUIRES(Locks::mutator_lock_);
426b2feaafd89813af69c65da95e0b51b1a4cecaf0bSebastien Hertz
427eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier  // Does not hold lock, used to check if someone changed from not instrumented to instrumented
428eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier  // during a GC suspend point.
429eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier  bool AllocEntrypointsInstrumented() const SHARED_REQUIRES(Locks::mutator_lock_) {
43050e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier    return alloc_entrypoints_instrumented_;
431eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier  }
432eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier
433725a957985171d712d5c048cc3d00ff14968784bjeffhao private:
4340462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  InstrumentationLevel GetCurrentInstrumentationLevel() const;
4350462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz
43662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Does the job of installing or removing instrumentation code within methods.
4370462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // In order to support multiple clients using instrumentation at the same time,
4380462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // the caller must pass a unique key (a string) identifying it so we remind which
4390462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // instrumentation level it needs. Therefore the current instrumentation level
4400462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // becomes the highest instrumentation level required by a client.
4410462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  void ConfigureStubs(const char* key, InstrumentationLevel desired_instrumentation_level)
442aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_)
443aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier      REQUIRES(!deoptimized_methods_lock_,
444aa5168291c46f9b418d989bccf2d8e09338a83e6Mathieu Chartier               !Locks::thread_list_lock_,
44590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier               !Locks::classlinker_classes_lock_);
44662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
44790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  void UpdateInterpreterHandlerTable() REQUIRES(Locks::mutator_lock_) {
4481452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee    /*
4491452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     * TUNING: Dalvik's mterp stashes the actual current handler table base in a
4501452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     * tls field.  For Arm, this enables all suspend, debug & tracing checks to be
4511452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     * collapsed into a single conditionally-executed ldw instruction.
4521452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     * Move to Dalvik-style handler-table management for both the goto interpreter and
4531452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     * mterp.
4541452bee8f06b9f76a333ddf4760e4beaa82f8099buzbee     */
455ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz    interpreter_handler_table_ = IsActive() ? kAlternativeHandlerTable : kMainHandlerTable;
456ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz  }
457ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz
458661974a5561e5ccdfbac8cb5d8df8b7e6f3483b8Mathieu Chartier  // No thread safety analysis to get around SetQuickAllocEntryPointsInstrumented requiring
459661974a5561e5ccdfbac8cb5d8df8b7e6f3483b8Mathieu Chartier  // exclusive access to mutator lock which you can't get if the runtime isn't started.
4609ef78b59da51080882e47505896b420977fd79aeMathieu Chartier  void SetEntrypointsInstrumented(bool instrumented) NO_THREAD_SAFETY_ANALYSIS;
461661974a5561e5ccdfbac8cb5d8df8b7e6f3483b8Mathieu Chartier
46262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void MethodEnterEventImpl(Thread* thread, mirror::Object* this_object,
463e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                            ArtMethod* method, uint32_t dex_pc) const
46490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
46562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void MethodExitEventImpl(Thread* thread, mirror::Object* this_object,
466e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                           ArtMethod* method,
46762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                           uint32_t dex_pc, const JValue& return_value) const
46890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
46962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  void DexPcMovedEventImpl(Thread* thread, mirror::Object* this_object,
470e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                           ArtMethod* method, uint32_t dex_pc) const
47190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
47281f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  void BranchImpl(Thread* thread, ArtMethod* method, uint32_t dex_pc, int32_t offset) const
47390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
4745550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  void InvokeVirtualOrInterfaceImpl(Thread* thread,
4755550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                    mirror::Object* this_object,
4765550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                    ArtMethod* caller,
4775550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                    uint32_t dex_pc,
4785550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray                                    ArtMethod* callee) const
4795550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray      SHARED_REQUIRES(Locks::mutator_lock_);
4803f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  void FieldReadEventImpl(Thread* thread, mirror::Object* this_object,
481e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                           ArtMethod* method, uint32_t dex_pc,
482c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier                           ArtField* field) const
48390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
4843f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  void FieldWriteEventImpl(Thread* thread, mirror::Object* this_object,
485e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                           ArtMethod* method, uint32_t dex_pc,
486c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier                           ArtField* field, const JValue& field_value) const
48790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
48862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
489799eb3a5555254427db269921042419bc30d4d86Hiroshi Yamauchi  // Read barrier-aware utility functions for accessing deoptimized_methods_
490e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  bool AddDeoptimizedMethod(ArtMethod* method)
49190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(deoptimized_methods_lock_);
492e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  bool IsDeoptimizedMethod(ArtMethod* method)
49390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_, deoptimized_methods_lock_);
494e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  bool RemoveDeoptimizedMethod(ArtMethod* method)
49590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(deoptimized_methods_lock_);
496e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  ArtMethod* BeginDeoptimizedMethod()
49790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_, deoptimized_methods_lock_);
498799eb3a5555254427db269921042419bc30d4d86Hiroshi Yamauchi  bool IsDeoptimizedMethodsEmpty() const
49990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_, deoptimized_methods_lock_);
5004ba674b914f24f2baf42769401cff43f8261abd6Mingyao Yang  void UpdateMethodsCodeImpl(ArtMethod* method, const void* quick_code)
5014ba674b914f24f2baf42769401cff43f8261abd6Mingyao Yang      SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
5024ba674b914f24f2baf42769401cff43f8261abd6Mingyao Yang
503799eb3a5555254427db269921042419bc30d4d86Hiroshi Yamauchi
504ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  // Have we hijacked ArtMethod::code_ so that it calls instrumentation/interpreter code?
50562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool instrumentation_stubs_installed_;
50662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
507ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  // Have we hijacked ArtMethod::code_ to reference the enter/exit stubs?
50862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool entry_exit_stubs_installed_;
50962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
510ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom  // Have we hijacked ArtMethod::code_ to reference the enter interpreter stub?
51162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool interpreter_stubs_installed_;
51262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
51362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we need the fidelity of events that we only get from running within the interpreter?
51462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool interpret_only_;
515725a957985171d712d5c048cc3d00ff14968784bjeffhao
51662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Did the runtime request we only run in the interpreter? ie -Xint mode.
51762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  bool forced_interpret_only_;
518725a957985171d712d5c048cc3d00ff14968784bjeffhao
51962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we have any listeners for method entry events? Short-cut to avoid taking the
52062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // instrumentation_lock_.
521ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_);
52262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
52362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we have any listeners for method exit events? Short-cut to avoid taking the
52462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // instrumentation_lock_.
525ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_);
52662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
52762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we have any listeners for method unwind events? Short-cut to avoid taking the
52862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // instrumentation_lock_.
529ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_);
53062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
53162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we have any listeners for dex move events? Short-cut to avoid taking the
53262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // instrumentation_lock_.
533ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_);
53462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
5353f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // Do we have any listeners for field read events? Short-cut to avoid taking the
5363f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // instrumentation_lock_.
537ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_field_read_listeners_ GUARDED_BY(Locks::mutator_lock_);
5383f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
5393f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // Do we have any listeners for field write events? Short-cut to avoid taking the
5403f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz  // instrumentation_lock_.
541ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_field_write_listeners_ GUARDED_BY(Locks::mutator_lock_);
5423f52eafe5577b8489f90dc8ed5981b3455206147Sebastien Hertz
54362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Do we have any exception caught listeners? Short-cut to avoid taking the instrumentation_lock_.
544ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  bool have_exception_caught_listeners_ GUARDED_BY(Locks::mutator_lock_);
54562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
54681f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  // Do we have any branch listeners? Short-cut to avoid taking the instrumentation_lock_.
54781f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  bool have_branch_listeners_ GUARDED_BY(Locks::mutator_lock_);
548e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier
5495550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  // Do we have any invoke listeners? Short-cut to avoid taking the instrumentation_lock_.
5505550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  bool have_invoke_virtual_or_interface_listeners_ GUARDED_BY(Locks::mutator_lock_);
5515550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray
5520462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // Contains the instrumentation level required by each client of the instrumentation identified
5530462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  // by a string key.
5540462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  typedef SafeMap<const char*, InstrumentationLevel> InstrumentationLevelTable;
5550462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  InstrumentationLevelTable requested_instrumentation_levels_ GUARDED_BY(Locks::mutator_lock_);
5560462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz
55762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // The event listeners, written to with the mutator_lock_ exclusively held.
558514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // Mutators must be able to iterate over these lists concurrently, that is, with listeners being
559514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // added or removed while iterating. The modifying thread holds exclusive lock,
560514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // so other threads cannot iterate (i.e. read the data of the list) at the same time but they
561514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // do keep iterators that need to remain valid. This is the reason these listeners are std::list
562514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // and not for example std::vector: the existing storage for a std::list does not move.
563514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // Note that mutators cannot make a copy of these lists before iterating, as the instrumentation
564514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // listeners can also be deleted concurrently.
565514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // As a result, these lists are never trimmed. That's acceptable given the low number of
566514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  // listeners we have.
56762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  std::list<InstrumentationListener*> method_entry_listeners_ GUARDED_BY(Locks::mutator_lock_);
56862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  std::list<InstrumentationListener*> method_exit_listeners_ GUARDED_BY(Locks::mutator_lock_);
56962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  std::list<InstrumentationListener*> method_unwind_listeners_ GUARDED_BY(Locks::mutator_lock_);
57081f0f953c4bb159997046c962d44cb1898b1778dNicolas Geoffray  std::list<InstrumentationListener*> branch_listeners_ GUARDED_BY(Locks::mutator_lock_);
5715550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray  std::list<InstrumentationListener*> invoke_virtual_or_interface_listeners_
5725550ca8bcc742b109d77e62f3a0877c667d894d3Nicolas Geoffray      GUARDED_BY(Locks::mutator_lock_);
573514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  std::list<InstrumentationListener*> dex_pc_listeners_ GUARDED_BY(Locks::mutator_lock_);
574514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  std::list<InstrumentationListener*> field_read_listeners_ GUARDED_BY(Locks::mutator_lock_);
575514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  std::list<InstrumentationListener*> field_write_listeners_ GUARDED_BY(Locks::mutator_lock_);
576514a616fd434212815bdd49cc1e2786817395969Nicolas Geoffray  std::list<InstrumentationListener*> exception_caught_listeners_ GUARDED_BY(Locks::mutator_lock_);
577725a957985171d712d5c048cc3d00ff14968784bjeffhao
578138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // The set of methods being deoptimized (by the debugger) which must be executed with interpreter
579138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  // only.
5803b05e9ba874449dbff65b01b8781001f7d93eea6Mathieu Chartier  mutable ReaderWriterMutex deoptimized_methods_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
581e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  std::unordered_set<ArtMethod*> deoptimized_methods_ GUARDED_BY(deoptimized_methods_lock_);
58211d40c250ec86c784cf76b8c31e1cf9285d555dcSebastien Hertz  bool deoptimization_enabled_;
583138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz
584fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers  // Current interpreter handler table. This is updated each time the thread state flags are
585fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers  // modified.
586ed2be1725fb79075892b1a9103487c9d9a95b350Sebastien Hertz  InterpreterHandlerTable interpreter_handler_table_ GUARDED_BY(Locks::mutator_lock_);
587ee1997a3b83334985e757f369c09e111b121661bSebastien Hertz
588fa82427c68b09f4aedbee319dc71579afbfc66f5Ian Rogers  // Greater than 0 if quick alloc entry points instrumented.
589eebc3af4453f5c1fb5fd80c710cfd49566080d28Mathieu Chartier  size_t quick_alloc_entry_points_instrumentation_counter_;
59050e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier
59150e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier  // alloc_entrypoints_instrumented_ is only updated with all the threads suspended, this is done
59250e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier  // to prevent races with the GC where the GC relies on thread suspension only see
59350e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier  // alloc_entrypoints_instrumented_ change during suspend points.
59450e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier  bool alloc_entrypoints_instrumented_;
59550e933188d993c6eb67560db1fcad67ba1d182e1Mathieu Chartier
5960462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz  friend class InstrumentationTest;  // For GetCurrentInstrumentationLevel and ConfigureStubs.
5970462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertz
598725a957985171d712d5c048cc3d00ff14968784bjeffhao  DISALLOW_COPY_AND_ASSIGN(Instrumentation);
599725a957985171d712d5c048cc3d00ff14968784bjeffhao};
6006a3c1fcb4ba42ad4d5d142c17a3712a6ddd3866fIan Rogersstd::ostream& operator<<(std::ostream& os, const Instrumentation::InstrumentationEvent& rhs);
6010462c4c87c39db6cfcd338f323844738109ac3c9Sebastien Hertzstd::ostream& operator<<(std::ostream& os, const Instrumentation::InstrumentationLevel& rhs);
602725a957985171d712d5c048cc3d00ff14968784bjeffhao
60362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers// An element in the instrumentation side stack maintained in art::Thread.
60462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogersstruct InstrumentationStackFrame {
605e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  InstrumentationStackFrame(mirror::Object* this_object, ArtMethod* method,
6069a916d3c0d0574d106c764e737c67b52988d6139Jeff Hao                            uintptr_t return_pc, size_t frame_id, bool interpreter_entry)
6079a916d3c0d0574d106c764e737c67b52988d6139Jeff Hao      : this_object_(this_object), method_(method), return_pc_(return_pc), frame_id_(frame_id),
6089a916d3c0d0574d106c764e737c67b52988d6139Jeff Hao        interpreter_entry_(interpreter_entry) {
60962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  }
61062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
61190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  std::string Dump() const SHARED_REQUIRES(Locks::mutator_lock_);
61262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
61362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  mirror::Object* this_object_;
614e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier  ArtMethod* method_;
615138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  uintptr_t return_pc_;
616138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  size_t frame_id_;
617138dbfc3336e379d74d157086f69a0fbe830089bSebastien Hertz  bool interpreter_entry_;
61862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers};
61962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers
62062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers}  // namespace instrumentation
621725a957985171d712d5c048cc3d00ff14968784bjeffhao}  // namespace art
622725a957985171d712d5c048cc3d00ff14968784bjeffhao
623fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif  // ART_RUNTIME_INSTRUMENTATION_H_
624