blob: b3528d8d42bbb4fbe0115d17d85f9bd48f8bc202 [file] [log] [blame]
jeffhao725a9572012-11-13 18:20:12 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "instrumentation.h"
18
Ian Rogersc7dd2952014-10-21 23:31:19 -070019#include <sstream>
20
Ian Rogerse63db272014-07-15 15:36:11 -070021#include "arch/context.h"
Alex Lightd7661582017-05-01 13:48:16 -070022#include "art_field-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070023#include "art_method-inl.h"
Ian Rogersef7d42f2014-01-06 12:55:46 -080024#include "atomic.h"
Andreas Gampe8228cdf2017-05-30 15:03:54 -070025#include "base/callee_save_type.h"
jeffhao725a9572012-11-13 18:20:12 -080026#include "class_linker.h"
27#include "debugger.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080028#include "dex_file-inl.h"
Mingyao Yang2ee17902017-08-30 11:37:08 -070029#include "dex_instruction-inl.h"
Mathieu Chartierd8891782014-03-02 13:28:37 -080030#include "entrypoints/quick/quick_alloc_entrypoints.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070031#include "entrypoints/quick/quick_entrypoints.h"
Ian Rogers6f3dbba2014-10-14 17:41:57 -070032#include "entrypoints/runtime_asm_entrypoints.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070033#include "gc_root-inl.h"
Sebastien Hertz138dbfc2013-12-04 18:15:25 +010034#include "interpreter/interpreter.h"
Mingyao Yang2ee17902017-08-30 11:37:08 -070035#include "interpreter/interpreter_common.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080036#include "jit/jit.h"
37#include "jit/jit_code_cache.h"
Alex Lightd7661582017-05-01 13:48:16 -070038#include "jvalue-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039#include "mirror/class-inl.h"
40#include "mirror/dex_cache.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070041#include "mirror/object-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070042#include "mirror/object_array-inl.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080043#include "nth_caller_visitor.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010044#include "oat_quick_method_header.h"
jeffhao725a9572012-11-13 18:20:12 -080045#include "thread.h"
46#include "thread_list.h"
jeffhao725a9572012-11-13 18:20:12 -080047
48namespace art {
Ian Rogers62d6c772013-02-27 08:32:07 -080049namespace instrumentation {
jeffhao725a9572012-11-13 18:20:12 -080050
Sebastien Hertz0462c4c2015-04-01 16:34:17 +020051constexpr bool kVerboseInstrumentation = false;
Sebastien Hertz5bfd5c92013-11-15 11:36:07 +010052
Alex Lightd7661582017-05-01 13:48:16 -070053void InstrumentationListener::MethodExited(Thread* thread,
54 Handle<mirror::Object> this_object,
55 ArtMethod* method,
56 uint32_t dex_pc,
57 Handle<mirror::Object> return_value) {
58 DCHECK_EQ(method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetReturnTypePrimitive(),
59 Primitive::kPrimNot);
60 JValue v;
61 v.SetL(return_value.Get());
62 MethodExited(thread, this_object, method, dex_pc, v);
63}
64
65void InstrumentationListener::FieldWritten(Thread* thread,
66 Handle<mirror::Object> this_object,
67 ArtMethod* method,
68 uint32_t dex_pc,
69 ArtField* field,
70 Handle<mirror::Object> field_value) {
71 DCHECK(!field->IsPrimitiveType());
72 JValue v;
73 v.SetL(field_value.Get());
74 FieldWritten(thread, this_object, method, dex_pc, field, v);
75}
76
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +010077// Instrumentation works on non-inlined frames by updating returned PCs
78// of compiled frames.
79static constexpr StackVisitor::StackWalkKind kInstrumentationStackWalk =
80 StackVisitor::StackWalkKind::kSkipInlinedFrames;
81
Mathieu Chartiere0671ce2015-07-28 17:23:28 -070082class InstallStubsClassVisitor : public ClassVisitor {
83 public:
84 explicit InstallStubsClassVisitor(Instrumentation* instrumentation)
85 : instrumentation_(instrumentation) {}
86
Mathieu Chartier28357fa2016-10-18 16:27:40 -070087 bool operator()(ObjPtr<mirror::Class> klass) OVERRIDE REQUIRES(Locks::mutator_lock_) {
88 instrumentation_->InstallStubsForClass(klass.Ptr());
Mathieu Chartiere0671ce2015-07-28 17:23:28 -070089 return true; // we visit all classes.
90 }
91
92 private:
93 Instrumentation* const instrumentation_;
94};
95
Ian Rogers62d6c772013-02-27 08:32:07 -080096
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070097Instrumentation::Instrumentation()
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +000098 : instrumentation_stubs_installed_(false),
99 entry_exit_stubs_installed_(false),
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700100 interpreter_stubs_installed_(false),
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +0000101 interpret_only_(false),
102 forced_interpret_only_(false),
103 have_method_entry_listeners_(false),
104 have_method_exit_listeners_(false),
105 have_method_unwind_listeners_(false),
106 have_dex_pc_listeners_(false),
107 have_field_read_listeners_(false),
108 have_field_write_listeners_(false),
Alex Light6e1607e2017-08-23 10:06:18 -0700109 have_exception_thrown_listeners_(false),
Alex Lighte814f9d2017-07-31 16:14:39 -0700110 have_watched_frame_pop_listeners_(false),
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000111 have_branch_listeners_(false),
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +0000112 have_invoke_virtual_or_interface_listeners_(false),
Mathieu Chartierb8aa1e42016-04-05 14:36:57 -0700113 deoptimized_methods_lock_("deoptimized methods lock", kDeoptimizedMethodsLock),
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700114 deoptimization_enabled_(false),
115 interpreter_handler_table_(kMainHandlerTable),
Mathieu Chartier50e93312016-03-16 11:25:29 -0700116 quick_alloc_entry_points_instrumentation_counter_(0),
117 alloc_entrypoints_instrumented_(false) {
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700118}
119
Sebastien Hertza10aa372015-01-21 17:30:58 +0100120void Instrumentation::InstallStubsForClass(mirror::Class* klass) {
Vladimir Marko72ab6842017-01-20 19:32:50 +0000121 if (!klass->IsResolved()) {
Sebastien Hertza8a697f2015-01-15 12:28:47 +0100122 // We need the class to be resolved to install/uninstall stubs. Otherwise its methods
123 // could not be initialized or linked with regards to class inheritance.
Vladimir Marko72ab6842017-01-20 19:32:50 +0000124 } else if (klass->IsErroneousResolved()) {
125 // We can't execute code in a erroneous class: do nothing.
Sebastien Hertza8a697f2015-01-15 12:28:47 +0100126 } else {
Andreas Gampe542451c2016-07-26 09:02:02 -0700127 for (ArtMethod& method : klass->GetMethods(kRuntimePointerSize)) {
Alex Light51a64d52015-12-17 13:55:59 -0800128 InstallStubsForMethod(&method);
Sebastien Hertza8a697f2015-01-15 12:28:47 +0100129 }
jeffhao725a9572012-11-13 18:20:12 -0800130 }
jeffhao725a9572012-11-13 18:20:12 -0800131}
132
Mathieu Chartiere401d142015-04-22 13:56:20 -0700133static void UpdateEntrypoints(ArtMethod* method, const void* quick_code)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700134 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800135 method->SetEntryPointFromQuickCompiledCode(quick_code);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100136}
137
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000138bool Instrumentation::NeedDebugVersionFor(ArtMethod* method) const REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang6ea1a0e2016-01-29 12:12:49 -0800139 return Dbg::IsDebuggerActive() &&
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000140 Runtime::Current()->IsJavaDebuggable() &&
Mingyao Yang6ea1a0e2016-01-29 12:12:49 -0800141 !method->IsNative() &&
142 !method->IsProxyMethod();
143}
144
Mathieu Chartiere401d142015-04-22 13:56:20 -0700145void Instrumentation::InstallStubsForMethod(ArtMethod* method) {
Alex Light9139e002015-10-09 15:59:48 -0700146 if (!method->IsInvokable() || method->IsProxyMethod()) {
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100147 // Do not change stubs for these methods.
148 return;
149 }
Jeff Hao56802772014-08-19 10:17:36 -0700150 // Don't stub Proxy.<init>. Note that the Proxy class itself is not a proxy class.
151 if (method->IsConstructor() &&
152 method->GetDeclaringClass()->DescriptorEquals("Ljava/lang/reflect/Proxy;")) {
Jeff Haodb8a6642014-08-14 17:18:52 -0700153 return;
154 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800155 const void* new_quick_code;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100156 bool uninstall = !entry_exit_stubs_installed_ && !interpreter_stubs_installed_;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800157 Runtime* const runtime = Runtime::Current();
158 ClassLinker* const class_linker = runtime->GetClassLinker();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100159 bool is_class_initialized = method->GetDeclaringClass()->IsInitialized();
160 if (uninstall) {
161 if ((forced_interpret_only_ || IsDeoptimized(method)) && !method->IsNative()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800162 new_quick_code = GetQuickToInterpreterBridge();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100163 } else if (is_class_initialized || !method->IsStatic() || method->IsConstructor()) {
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000164 if (NeedDebugVersionFor(method)) {
Mingyao Yang6ea1a0e2016-01-29 12:12:49 -0800165 new_quick_code = GetQuickToInterpreterBridge();
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000166 } else {
167 new_quick_code = class_linker->GetQuickOatCodeFor(method);
Mingyao Yang6ea1a0e2016-01-29 12:12:49 -0800168 }
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100169 } else {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700170 new_quick_code = GetQuickResolutionStub();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100171 }
172 } else { // !uninstall
Sebastien Hertzbae182c2013-12-17 10:42:03 +0100173 if ((interpreter_stubs_installed_ || forced_interpret_only_ || IsDeoptimized(method)) &&
174 !method->IsNative()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800175 new_quick_code = GetQuickToInterpreterBridge();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100176 } else {
177 // Do not overwrite resolution trampoline. When the trampoline initializes the method's
178 // class, all its static methods code will be set to the instrumentation entry point.
179 // For more details, see ClassLinker::FixupStaticTrampolines.
180 if (is_class_initialized || !method->IsStatic() || method->IsConstructor()) {
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000181 if (NeedDebugVersionFor(method)) {
Mingyao Yang6ea1a0e2016-01-29 12:12:49 -0800182 // Oat code should not be used. Don't install instrumentation stub and
183 // use interpreter for instrumentation.
184 new_quick_code = GetQuickToInterpreterBridge();
185 } else if (entry_exit_stubs_installed_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800186 new_quick_code = GetQuickInstrumentationEntryPoint();
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000187 } else {
188 new_quick_code = class_linker->GetQuickOatCodeFor(method);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100189 }
190 } else {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700191 new_quick_code = GetQuickResolutionStub();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100192 }
193 }
194 }
Elliott Hughes956af0f2014-12-11 14:34:28 -0800195 UpdateEntrypoints(method, new_quick_code);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100196}
197
Ian Rogers62d6c772013-02-27 08:32:07 -0800198// Places the instrumentation exit pc as the return PC for every quick frame. This also allows
199// deoptimization of quick frames to interpreter frames.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100200// Since we may already have done this previously, we need to push new instrumentation frame before
201// existing instrumentation frames.
Ian Rogers62d6c772013-02-27 08:32:07 -0800202static void InstrumentationInstallStack(Thread* thread, void* arg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700203 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200204 struct InstallStackVisitor FINAL : public StackVisitor {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800205 InstallStackVisitor(Thread* thread_in, Context* context, uintptr_t instrumentation_exit_pc)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100206 : StackVisitor(thread_in, context, kInstrumentationStackWalk),
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800207 instrumentation_stack_(thread_in->GetInstrumentationStack()),
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100208 instrumentation_exit_pc_(instrumentation_exit_pc),
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100209 reached_existing_instrumentation_frames_(false), instrumentation_stack_depth_(0),
210 last_return_pc_(0) {
211 }
jeffhao725a9572012-11-13 18:20:12 -0800212
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700213 bool VisitFrame() OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700214 ArtMethod* m = GetMethod();
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700215 if (m == nullptr) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800216 if (kVerboseInstrumentation) {
217 LOG(INFO) << " Skipping upcall. Frame " << GetFrameId();
218 }
219 last_return_pc_ = 0;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700220 return true; // Ignore upcalls.
Ian Rogers306057f2012-11-26 12:45:53 -0800221 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700222 if (GetCurrentQuickFrame() == nullptr) {
Elliott Hughes956af0f2014-12-11 14:34:28 -0800223 bool interpreter_frame = true;
Sebastien Hertz320deb22014-06-11 19:45:05 +0200224 InstrumentationStackFrame instrumentation_frame(GetThisObject(), m, 0, GetFrameId(),
225 interpreter_frame);
Jeff Haoa15a81b2014-05-27 18:25:47 -0700226 if (kVerboseInstrumentation) {
227 LOG(INFO) << "Pushing shadow frame " << instrumentation_frame.Dump();
228 }
229 shadow_stack_.push_back(instrumentation_frame);
230 return true; // Continue.
231 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800232 uintptr_t return_pc = GetReturnPc();
Sebastien Hertz320deb22014-06-11 19:45:05 +0200233 if (kVerboseInstrumentation) {
234 LOG(INFO) << " Installing exit stub in " << DescribeLocation();
235 }
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100236 if (return_pc == instrumentation_exit_pc_) {
Mingyao Yang2ee17902017-08-30 11:37:08 -0700237 CHECK_LT(instrumentation_stack_depth_, instrumentation_stack_->size());
238
239 if (m->IsRuntimeMethod()) {
240 const InstrumentationStackFrame& frame =
241 instrumentation_stack_->at(instrumentation_stack_depth_);
242 if (frame.interpreter_entry_) {
243 // This instrumentation frame is for an interpreter bridge and is
244 // pushed when executing the instrumented interpreter bridge. So method
245 // enter event must have been reported. However we need to push a DEX pc
246 // into the dex_pcs_ list to match size of instrumentation stack.
247 uint32_t dex_pc = DexFile::kDexNoIndex;
248 dex_pcs_.push_back(dex_pc);
249 last_return_pc_ = frame.return_pc_;
250 ++instrumentation_stack_depth_;
251 return true;
252 }
253 }
254
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100255 // We've reached a frame which has already been installed with instrumentation exit stub.
256 // We should have already installed instrumentation on previous frames.
257 reached_existing_instrumentation_frames_ = true;
258
Daniel Mihalyica1d06c2014-08-18 18:45:31 +0200259 const InstrumentationStackFrame& frame =
260 instrumentation_stack_->at(instrumentation_stack_depth_);
David Sehr709b0702016-10-13 09:12:37 -0700261 CHECK_EQ(m, frame.method_) << "Expected " << ArtMethod::PrettyMethod(m)
262 << ", Found " << ArtMethod::PrettyMethod(frame.method_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100263 return_pc = frame.return_pc_;
264 if (kVerboseInstrumentation) {
265 LOG(INFO) << "Ignoring already instrumented " << frame.Dump();
266 }
267 } else {
268 CHECK_NE(return_pc, 0U);
269 CHECK(!reached_existing_instrumentation_frames_);
Mingyao Yang2ee17902017-08-30 11:37:08 -0700270 InstrumentationStackFrame instrumentation_frame(
271 m->IsRuntimeMethod() ? nullptr : GetThisObject(),
272 m,
273 return_pc,
274 GetFrameId(), // A runtime method still gets a frame id.
275 false);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100276 if (kVerboseInstrumentation) {
277 LOG(INFO) << "Pushing frame " << instrumentation_frame.Dump();
278 }
279
Sebastien Hertz320deb22014-06-11 19:45:05 +0200280 // Insert frame at the right position so we do not corrupt the instrumentation stack.
281 // Instrumentation stack frames are in descending frame id order.
282 auto it = instrumentation_stack_->begin();
283 for (auto end = instrumentation_stack_->end(); it != end; ++it) {
284 const InstrumentationStackFrame& current = *it;
285 if (instrumentation_frame.frame_id_ >= current.frame_id_) {
286 break;
287 }
288 }
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100289 instrumentation_stack_->insert(it, instrumentation_frame);
290 SetReturnPc(instrumentation_exit_pc_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800291 }
Mingyao Yang2ee17902017-08-30 11:37:08 -0700292 uint32_t dex_pc = DexFile::kDexNoIndex;
293 if (last_return_pc_ != 0 &&
294 GetCurrentOatQuickMethodHeader() != nullptr) {
295 dex_pc = GetCurrentOatQuickMethodHeader()->ToDexPc(m, last_return_pc_);
296 }
297 dex_pcs_.push_back(dex_pc);
Ian Rogers62d6c772013-02-27 08:32:07 -0800298 last_return_pc_ = return_pc;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100299 ++instrumentation_stack_depth_;
Ian Rogers306057f2012-11-26 12:45:53 -0800300 return true; // Continue.
301 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800302 std::deque<InstrumentationStackFrame>* const instrumentation_stack_;
Jeff Haoa15a81b2014-05-27 18:25:47 -0700303 std::vector<InstrumentationStackFrame> shadow_stack_;
Ian Rogers62d6c772013-02-27 08:32:07 -0800304 std::vector<uint32_t> dex_pcs_;
Ian Rogers306057f2012-11-26 12:45:53 -0800305 const uintptr_t instrumentation_exit_pc_;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100306 bool reached_existing_instrumentation_frames_;
307 size_t instrumentation_stack_depth_;
Ian Rogers62d6c772013-02-27 08:32:07 -0800308 uintptr_t last_return_pc_;
Ian Rogers306057f2012-11-26 12:45:53 -0800309 };
Ian Rogers62d6c772013-02-27 08:32:07 -0800310 if (kVerboseInstrumentation) {
311 std::string thread_name;
312 thread->GetThreadName(thread_name);
313 LOG(INFO) << "Installing exit stubs in " << thread_name;
Ian Rogers306057f2012-11-26 12:45:53 -0800314 }
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100315
316 Instrumentation* instrumentation = reinterpret_cast<Instrumentation*>(arg);
Ian Rogers700a4022014-05-19 16:49:03 -0700317 std::unique_ptr<Context> context(Context::Create());
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700318 uintptr_t instrumentation_exit_pc = reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc());
Sebastien Hertz11d40c22014-02-19 18:00:17 +0100319 InstallStackVisitor visitor(thread, context.get(), instrumentation_exit_pc);
Ian Rogers62d6c772013-02-27 08:32:07 -0800320 visitor.WalkStack(true);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100321 CHECK_EQ(visitor.dex_pcs_.size(), thread->GetInstrumentationStack()->size());
Ian Rogers62d6c772013-02-27 08:32:07 -0800322
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100323 if (instrumentation->ShouldNotifyMethodEnterExitEvents()) {
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100324 // Create method enter events for all methods currently on the thread's stack. We only do this
325 // if no debugger is attached to prevent from posting events twice.
Jeff Haoa15a81b2014-05-27 18:25:47 -0700326 auto ssi = visitor.shadow_stack_.rbegin();
327 for (auto isi = thread->GetInstrumentationStack()->rbegin(),
328 end = thread->GetInstrumentationStack()->rend(); isi != end; ++isi) {
329 while (ssi != visitor.shadow_stack_.rend() && (*ssi).frame_id_ < (*isi).frame_id_) {
330 instrumentation->MethodEnterEvent(thread, (*ssi).this_object_, (*ssi).method_, 0);
331 ++ssi;
332 }
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100333 uint32_t dex_pc = visitor.dex_pcs_.back();
334 visitor.dex_pcs_.pop_back();
Sebastien Hertz320deb22014-06-11 19:45:05 +0200335 if (!isi->interpreter_entry_) {
336 instrumentation->MethodEnterEvent(thread, (*isi).this_object_, (*isi).method_, dex_pc);
337 }
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100338 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800339 }
340 thread->VerifyStack();
Ian Rogers306057f2012-11-26 12:45:53 -0800341}
342
Mingyao Yang99170c62015-07-06 11:10:37 -0700343void Instrumentation::InstrumentThreadStack(Thread* thread) {
344 instrumentation_stubs_installed_ = true;
345 InstrumentationInstallStack(thread, this);
346}
347
Ian Rogers62d6c772013-02-27 08:32:07 -0800348// Removes the instrumentation exit pc as the return PC for every quick frame.
349static void InstrumentationRestoreStack(Thread* thread, void* arg)
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +0000350 REQUIRES(Locks::mutator_lock_) {
351 Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current());
352
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200353 struct RestoreStackVisitor FINAL : public StackVisitor {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800354 RestoreStackVisitor(Thread* thread_in, uintptr_t instrumentation_exit_pc,
Ian Rogers62d6c772013-02-27 08:32:07 -0800355 Instrumentation* instrumentation)
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +0100356 : StackVisitor(thread_in, nullptr, kInstrumentationStackWalk),
357 thread_(thread_in),
Ian Rogers62d6c772013-02-27 08:32:07 -0800358 instrumentation_exit_pc_(instrumentation_exit_pc),
359 instrumentation_(instrumentation),
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800360 instrumentation_stack_(thread_in->GetInstrumentationStack()),
Ian Rogers62d6c772013-02-27 08:32:07 -0800361 frames_removed_(0) {}
Ian Rogers306057f2012-11-26 12:45:53 -0800362
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700363 bool VisitFrame() OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800364 if (instrumentation_stack_->size() == 0) {
jeffhao725a9572012-11-13 18:20:12 -0800365 return false; // Stop.
366 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700367 ArtMethod* m = GetMethod();
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700368 if (GetCurrentQuickFrame() == nullptr) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800369 if (kVerboseInstrumentation) {
Daniel Mihalyica1d06c2014-08-18 18:45:31 +0200370 LOG(INFO) << " Ignoring a shadow frame. Frame " << GetFrameId()
David Sehr709b0702016-10-13 09:12:37 -0700371 << " Method=" << ArtMethod::PrettyMethod(m);
Ian Rogers62d6c772013-02-27 08:32:07 -0800372 }
373 return true; // Ignore shadow frames.
374 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700375 if (m == nullptr) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800376 if (kVerboseInstrumentation) {
377 LOG(INFO) << " Skipping upcall. Frame " << GetFrameId();
378 }
Ian Rogers306057f2012-11-26 12:45:53 -0800379 return true; // Ignore upcalls.
380 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800381 bool removed_stub = false;
382 // TODO: make this search more efficient?
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100383 const size_t frameId = GetFrameId();
384 for (const InstrumentationStackFrame& instrumentation_frame : *instrumentation_stack_) {
385 if (instrumentation_frame.frame_id_ == frameId) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800386 if (kVerboseInstrumentation) {
387 LOG(INFO) << " Removing exit stub in " << DescribeLocation();
388 }
Jeff Hao9a916d32013-06-27 18:45:37 -0700389 if (instrumentation_frame.interpreter_entry_) {
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700390 CHECK(m == Runtime::Current()->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs));
Jeff Hao9a916d32013-06-27 18:45:37 -0700391 } else {
David Sehr709b0702016-10-13 09:12:37 -0700392 CHECK(m == instrumentation_frame.method_) << ArtMethod::PrettyMethod(m);
Jeff Hao9a916d32013-06-27 18:45:37 -0700393 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800394 SetReturnPc(instrumentation_frame.return_pc_);
Mingyao Yang2ee17902017-08-30 11:37:08 -0700395 if (instrumentation_->ShouldNotifyMethodEnterExitEvents() &&
396 !m->IsRuntimeMethod()) {
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100397 // Create the method exit events. As the methods didn't really exit the result is 0.
398 // We only do this if no debugger is attached to prevent from posting events twice.
399 instrumentation_->MethodExitEvent(thread_, instrumentation_frame.this_object_, m,
400 GetDexPc(), JValue());
401 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800402 frames_removed_++;
403 removed_stub = true;
404 break;
405 }
406 }
407 if (!removed_stub) {
408 if (kVerboseInstrumentation) {
409 LOG(INFO) << " No exit stub in " << DescribeLocation();
Ian Rogers306057f2012-11-26 12:45:53 -0800410 }
jeffhao725a9572012-11-13 18:20:12 -0800411 }
412 return true; // Continue.
413 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800414 Thread* const thread_;
Ian Rogers306057f2012-11-26 12:45:53 -0800415 const uintptr_t instrumentation_exit_pc_;
Ian Rogers62d6c772013-02-27 08:32:07 -0800416 Instrumentation* const instrumentation_;
417 std::deque<instrumentation::InstrumentationStackFrame>* const instrumentation_stack_;
418 size_t frames_removed_;
jeffhao725a9572012-11-13 18:20:12 -0800419 };
Ian Rogers62d6c772013-02-27 08:32:07 -0800420 if (kVerboseInstrumentation) {
421 std::string thread_name;
422 thread->GetThreadName(thread_name);
423 LOG(INFO) << "Removing exit stubs in " << thread_name;
424 }
425 std::deque<instrumentation::InstrumentationStackFrame>* stack = thread->GetInstrumentationStack();
426 if (stack->size() > 0) {
427 Instrumentation* instrumentation = reinterpret_cast<Instrumentation*>(arg);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700428 uintptr_t instrumentation_exit_pc =
429 reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc());
Ian Rogers62d6c772013-02-27 08:32:07 -0800430 RestoreStackVisitor visitor(thread, instrumentation_exit_pc, instrumentation);
431 visitor.WalkStack(true);
432 CHECK_EQ(visitor.frames_removed_, stack->size());
433 while (stack->size() > 0) {
434 stack->pop_front();
435 }
jeffhao725a9572012-11-13 18:20:12 -0800436 }
437}
438
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200439static bool HasEvent(Instrumentation::InstrumentationEvent expected, uint32_t events) {
440 return (events & expected) != 0;
441}
442
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000443static void PotentiallyAddListenerTo(Instrumentation::InstrumentationEvent event,
444 uint32_t events,
445 std::list<InstrumentationListener*>& list,
446 InstrumentationListener* listener,
447 bool* has_listener)
448 REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::classlinker_classes_lock_) {
449 Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current());
450 if (!HasEvent(event, events)) {
451 return;
452 }
453 // If there is a free slot in the list, we insert the listener in that slot.
454 // Otherwise we add it to the end of the list.
455 auto it = std::find(list.begin(), list.end(), nullptr);
456 if (it != list.end()) {
457 *it = listener;
458 } else {
459 list.push_back(listener);
460 }
461 *has_listener = true;
462}
463
Ian Rogers62d6c772013-02-27 08:32:07 -0800464void Instrumentation::AddListener(InstrumentationListener* listener, uint32_t events) {
465 Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current());
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000466 PotentiallyAddListenerTo(kMethodEntered,
467 events,
468 method_entry_listeners_,
469 listener,
470 &have_method_entry_listeners_);
471 PotentiallyAddListenerTo(kMethodExited,
472 events,
473 method_exit_listeners_,
474 listener,
475 &have_method_exit_listeners_);
476 PotentiallyAddListenerTo(kMethodUnwind,
477 events,
478 method_unwind_listeners_,
479 listener,
480 &have_method_unwind_listeners_);
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000481 PotentiallyAddListenerTo(kBranch,
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000482 events,
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000483 branch_listeners_,
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000484 listener,
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000485 &have_branch_listeners_);
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000486 PotentiallyAddListenerTo(kInvokeVirtualOrInterface,
487 events,
488 invoke_virtual_or_interface_listeners_,
489 listener,
490 &have_invoke_virtual_or_interface_listeners_);
491 PotentiallyAddListenerTo(kDexPcMoved,
492 events,
493 dex_pc_listeners_,
494 listener,
495 &have_dex_pc_listeners_);
496 PotentiallyAddListenerTo(kFieldRead,
497 events,
498 field_read_listeners_,
499 listener,
500 &have_field_read_listeners_);
501 PotentiallyAddListenerTo(kFieldWritten,
502 events,
503 field_write_listeners_,
504 listener,
505 &have_field_write_listeners_);
Alex Light6e1607e2017-08-23 10:06:18 -0700506 PotentiallyAddListenerTo(kExceptionThrown,
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000507 events,
Alex Light6e1607e2017-08-23 10:06:18 -0700508 exception_thrown_listeners_,
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000509 listener,
Alex Light6e1607e2017-08-23 10:06:18 -0700510 &have_exception_thrown_listeners_);
Alex Lighte814f9d2017-07-31 16:14:39 -0700511 PotentiallyAddListenerTo(kWatchedFramePop,
512 events,
513 watched_frame_pop_listeners_,
514 listener,
515 &have_watched_frame_pop_listeners_);
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200516 UpdateInterpreterHandlerTable();
jeffhao725a9572012-11-13 18:20:12 -0800517}
518
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000519static void PotentiallyRemoveListenerFrom(Instrumentation::InstrumentationEvent event,
520 uint32_t events,
521 std::list<InstrumentationListener*>& list,
522 InstrumentationListener* listener,
523 bool* has_listener)
524 REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::classlinker_classes_lock_) {
525 Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current());
526 if (!HasEvent(event, events)) {
527 return;
528 }
529 auto it = std::find(list.begin(), list.end(), listener);
530 if (it != list.end()) {
531 // Just update the entry, do not remove from the list. Removing entries in the list
532 // is unsafe when mutators are iterating over it.
533 *it = nullptr;
534 }
535
536 // Check if the list contains any non-null listener, and update 'has_listener'.
537 for (InstrumentationListener* l : list) {
538 if (l != nullptr) {
539 *has_listener = true;
540 return;
541 }
542 }
543 *has_listener = false;
544}
545
Ian Rogers62d6c772013-02-27 08:32:07 -0800546void Instrumentation::RemoveListener(InstrumentationListener* listener, uint32_t events) {
547 Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current());
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000548 PotentiallyRemoveListenerFrom(kMethodEntered,
549 events,
550 method_entry_listeners_,
551 listener,
552 &have_method_entry_listeners_);
553 PotentiallyRemoveListenerFrom(kMethodExited,
554 events,
555 method_exit_listeners_,
556 listener,
557 &have_method_exit_listeners_);
558 PotentiallyRemoveListenerFrom(kMethodUnwind,
559 events,
560 method_unwind_listeners_,
561 listener,
562 &have_method_unwind_listeners_);
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000563 PotentiallyRemoveListenerFrom(kBranch,
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000564 events,
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000565 branch_listeners_,
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000566 listener,
Nicolas Geoffray81f0f952016-01-20 16:25:19 +0000567 &have_branch_listeners_);
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000568 PotentiallyRemoveListenerFrom(kInvokeVirtualOrInterface,
569 events,
570 invoke_virtual_or_interface_listeners_,
571 listener,
572 &have_invoke_virtual_or_interface_listeners_);
573 PotentiallyRemoveListenerFrom(kDexPcMoved,
574 events,
575 dex_pc_listeners_,
576 listener,
577 &have_dex_pc_listeners_);
578 PotentiallyRemoveListenerFrom(kFieldRead,
579 events,
580 field_read_listeners_,
581 listener,
582 &have_field_read_listeners_);
583 PotentiallyRemoveListenerFrom(kFieldWritten,
584 events,
585 field_write_listeners_,
586 listener,
587 &have_field_write_listeners_);
Alex Light6e1607e2017-08-23 10:06:18 -0700588 PotentiallyRemoveListenerFrom(kExceptionThrown,
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000589 events,
Alex Light6e1607e2017-08-23 10:06:18 -0700590 exception_thrown_listeners_,
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000591 listener,
Alex Light6e1607e2017-08-23 10:06:18 -0700592 &have_exception_thrown_listeners_);
Alex Lighte814f9d2017-07-31 16:14:39 -0700593 PotentiallyRemoveListenerFrom(kWatchedFramePop,
594 events,
595 watched_frame_pop_listeners_,
596 listener,
597 &have_watched_frame_pop_listeners_);
Sebastien Hertzee1997a2013-09-19 14:47:09 +0200598 UpdateInterpreterHandlerTable();
jeffhao725a9572012-11-13 18:20:12 -0800599}
600
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200601Instrumentation::InstrumentationLevel Instrumentation::GetCurrentInstrumentationLevel() const {
Alex Light4ba388a2017-01-27 10:26:49 -0800602 if (interpreter_stubs_installed_) {
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200603 return InstrumentationLevel::kInstrumentWithInterpreter;
Ian Rogers62d6c772013-02-27 08:32:07 -0800604 } else if (entry_exit_stubs_installed_) {
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200605 return InstrumentationLevel::kInstrumentWithInstrumentationStubs;
Ian Rogers62d6c772013-02-27 08:32:07 -0800606 } else {
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200607 return InstrumentationLevel::kInstrumentNothing;
Ian Rogers62d6c772013-02-27 08:32:07 -0800608 }
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200609}
610
Alex Lightdba61482016-12-21 08:20:29 -0800611bool Instrumentation::RequiresInstrumentationInstallation(InstrumentationLevel new_level) const {
Alex Light4ba388a2017-01-27 10:26:49 -0800612 // We need to reinstall instrumentation if we go to a different level.
613 return GetCurrentInstrumentationLevel() != new_level;
Alex Lightdba61482016-12-21 08:20:29 -0800614}
615
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200616void Instrumentation::ConfigureStubs(const char* key, InstrumentationLevel desired_level) {
617 // Store the instrumentation level for this key or remove it.
618 if (desired_level == InstrumentationLevel::kInstrumentNothing) {
619 // The client no longer needs instrumentation.
620 requested_instrumentation_levels_.erase(key);
621 } else {
622 // The client needs instrumentation.
623 requested_instrumentation_levels_.Overwrite(key, desired_level);
624 }
625
626 // Look for the highest required instrumentation level.
627 InstrumentationLevel requested_level = InstrumentationLevel::kInstrumentNothing;
628 for (const auto& v : requested_instrumentation_levels_) {
629 requested_level = std::max(requested_level, v.second);
630 }
631
632 interpret_only_ = (requested_level == InstrumentationLevel::kInstrumentWithInterpreter) ||
633 forced_interpret_only_;
634
Alex Lightdba61482016-12-21 08:20:29 -0800635 if (!RequiresInstrumentationInstallation(requested_level)) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800636 // We're already set.
637 return;
638 }
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100639 Thread* const self = Thread::Current();
Ian Rogers62d6c772013-02-27 08:32:07 -0800640 Runtime* runtime = Runtime::Current();
Sebastien Hertza8a697f2015-01-15 12:28:47 +0100641 Locks::mutator_lock_->AssertExclusiveHeld(self);
Ian Rogers62d6c772013-02-27 08:32:07 -0800642 Locks::thread_list_lock_->AssertNotHeld(self);
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200643 if (requested_level > InstrumentationLevel::kInstrumentNothing) {
Alex Light4ba388a2017-01-27 10:26:49 -0800644 if (requested_level == InstrumentationLevel::kInstrumentWithInterpreter) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800645 interpreter_stubs_installed_ = true;
Ian Rogers62d6c772013-02-27 08:32:07 -0800646 entry_exit_stubs_installed_ = true;
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200647 } else {
648 CHECK_EQ(requested_level, InstrumentationLevel::kInstrumentWithInstrumentationStubs);
649 entry_exit_stubs_installed_ = true;
650 interpreter_stubs_installed_ = false;
Ian Rogers62d6c772013-02-27 08:32:07 -0800651 }
Mathieu Chartiere0671ce2015-07-28 17:23:28 -0700652 InstallStubsClassVisitor visitor(this);
653 runtime->GetClassLinker()->VisitClasses(&visitor);
Ian Rogers62d6c772013-02-27 08:32:07 -0800654 instrumentation_stubs_installed_ = true;
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100655 MutexLock mu(self, *Locks::thread_list_lock_);
Ian Rogers62d6c772013-02-27 08:32:07 -0800656 runtime->GetThreadList()->ForEach(InstrumentationInstallStack, this);
657 } else {
658 interpreter_stubs_installed_ = false;
659 entry_exit_stubs_installed_ = false;
Mathieu Chartiere0671ce2015-07-28 17:23:28 -0700660 InstallStubsClassVisitor visitor(this);
661 runtime->GetClassLinker()->VisitClasses(&visitor);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100662 // Restore stack only if there is no method currently deoptimized.
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700663 bool empty;
664 {
665 ReaderMutexLock mu(self, deoptimized_methods_lock_);
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700666 empty = IsDeoptimizedMethodsEmpty(); // Avoid lock violation.
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700667 }
668 if (empty) {
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100669 MutexLock mu(self, *Locks::thread_list_lock_);
670 Runtime::Current()->GetThreadList()->ForEach(InstrumentationRestoreStack, this);
Nicolas Geoffray5a23d2e2015-11-03 18:58:57 +0000671 // Only do this after restoring, as walking the stack when restoring will see
672 // the instrumentation exit pc.
673 instrumentation_stubs_installed_ = false;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100674 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800675 }
jeffhao725a9572012-11-13 18:20:12 -0800676}
677
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200678static void ResetQuickAllocEntryPointsForThread(Thread* thread, void* arg ATTRIBUTE_UNUSED) {
Mathieu Chartier5ace2012016-11-30 10:15:41 -0800679 thread->ResetQuickAllocEntryPointsForThread(kUseReadBarrier && thread->GetIsGcMarking());
Ian Rogersfa824272013-11-05 16:12:57 -0800680}
681
Mathieu Chartier9ef78b52014-09-25 17:03:12 -0700682void Instrumentation::SetEntrypointsInstrumented(bool instrumented) {
683 Thread* self = Thread::Current();
Mathieu Chartier661974a2014-01-09 11:23:53 -0800684 Runtime* runtime = Runtime::Current();
Mathieu Chartier9ef78b52014-09-25 17:03:12 -0700685 Locks::mutator_lock_->AssertNotHeld(self);
686 Locks::instrument_entrypoints_lock_->AssertHeld(self);
687 if (runtime->IsStarted()) {
Mathieu Chartier4f55e222015-09-04 13:26:21 -0700688 ScopedSuspendAll ssa(__FUNCTION__);
Mathieu Chartier9ef78b52014-09-25 17:03:12 -0700689 MutexLock mu(self, *Locks::runtime_shutdown_lock_);
Mathieu Chartier661974a2014-01-09 11:23:53 -0800690 SetQuickAllocEntryPointsInstrumented(instrumented);
691 ResetQuickAllocEntryPoints();
Mathieu Chartier50e93312016-03-16 11:25:29 -0700692 alloc_entrypoints_instrumented_ = instrumented;
Mathieu Chartier4f55e222015-09-04 13:26:21 -0700693 } else {
694 MutexLock mu(self, *Locks::runtime_shutdown_lock_);
695 SetQuickAllocEntryPointsInstrumented(instrumented);
Andreas Gampe157c77e2016-10-17 17:44:41 -0700696
697 // Note: ResetQuickAllocEntryPoints only works when the runtime is started. Manually run the
698 // update for just this thread.
Andreas Gampe162ae502016-10-18 10:03:42 -0700699 // Note: self may be null. One of those paths is setting instrumentation in the Heap
700 // constructor for gcstress mode.
701 if (self != nullptr) {
702 ResetQuickAllocEntryPointsForThread(self, nullptr);
703 }
Andreas Gampe157c77e2016-10-17 17:44:41 -0700704
Mathieu Chartier50e93312016-03-16 11:25:29 -0700705 alloc_entrypoints_instrumented_ = instrumented;
Mathieu Chartier661974a2014-01-09 11:23:53 -0800706 }
707}
708
Mathieu Chartier9ef78b52014-09-25 17:03:12 -0700709void Instrumentation::InstrumentQuickAllocEntryPoints() {
710 MutexLock mu(Thread::Current(), *Locks::instrument_entrypoints_lock_);
711 InstrumentQuickAllocEntryPointsLocked();
Ian Rogersfa824272013-11-05 16:12:57 -0800712}
713
Mathieu Chartier9ef78b52014-09-25 17:03:12 -0700714void Instrumentation::UninstrumentQuickAllocEntryPoints() {
715 MutexLock mu(Thread::Current(), *Locks::instrument_entrypoints_lock_);
716 UninstrumentQuickAllocEntryPointsLocked();
717}
718
719void Instrumentation::InstrumentQuickAllocEntryPointsLocked() {
720 Locks::instrument_entrypoints_lock_->AssertHeld(Thread::Current());
721 if (quick_alloc_entry_points_instrumentation_counter_ == 0) {
722 SetEntrypointsInstrumented(true);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800723 }
Mathieu Chartier9ef78b52014-09-25 17:03:12 -0700724 ++quick_alloc_entry_points_instrumentation_counter_;
Mathieu Chartier9ef78b52014-09-25 17:03:12 -0700725}
726
727void Instrumentation::UninstrumentQuickAllocEntryPointsLocked() {
728 Locks::instrument_entrypoints_lock_->AssertHeld(Thread::Current());
729 CHECK_GT(quick_alloc_entry_points_instrumentation_counter_, 0U);
730 --quick_alloc_entry_points_instrumentation_counter_;
731 if (quick_alloc_entry_points_instrumentation_counter_ == 0) {
732 SetEntrypointsInstrumented(false);
733 }
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800734}
735
736void Instrumentation::ResetQuickAllocEntryPoints() {
737 Runtime* runtime = Runtime::Current();
738 if (runtime->IsStarted()) {
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800739 MutexLock mu(Thread::Current(), *Locks::thread_list_lock_);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700740 runtime->GetThreadList()->ForEach(ResetQuickAllocEntryPointsForThread, nullptr);
Ian Rogersfa824272013-11-05 16:12:57 -0800741 }
742}
743
Mingyao Yang3fd448a2016-05-10 14:30:41 -0700744void Instrumentation::UpdateMethodsCodeImpl(ArtMethod* method, const void* quick_code) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800745 const void* new_quick_code;
Ian Rogers62d6c772013-02-27 08:32:07 -0800746 if (LIKELY(!instrumentation_stubs_installed_)) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800747 new_quick_code = quick_code;
Jeff Hao65d15d92013-07-16 16:39:33 -0700748 } else {
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100749 if ((interpreter_stubs_installed_ || IsDeoptimized(method)) && !method->IsNative()) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800750 new_quick_code = GetQuickToInterpreterBridge();
Jeff Hao65d15d92013-07-16 16:39:33 -0700751 } else {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700752 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700753 if (class_linker->IsQuickResolutionStub(quick_code) ||
754 class_linker->IsQuickToInterpreterBridge(quick_code)) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700755 new_quick_code = quick_code;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700756 } else if (entry_exit_stubs_installed_) {
757 new_quick_code = GetQuickInstrumentationEntryPoint();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700758 } else {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700759 new_quick_code = quick_code;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700760 }
Jeff Hao65d15d92013-07-16 16:39:33 -0700761 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800762 }
Elliott Hughes956af0f2014-12-11 14:34:28 -0800763 UpdateEntrypoints(method, new_quick_code);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100764}
765
Mingyao Yang3fd448a2016-05-10 14:30:41 -0700766void Instrumentation::UpdateMethodsCode(ArtMethod* method, const void* quick_code) {
767 DCHECK(method->GetDeclaringClass()->IsResolved());
768 UpdateMethodsCodeImpl(method, quick_code);
769}
770
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000771void Instrumentation::UpdateMethodsCodeForJavaDebuggable(ArtMethod* method,
772 const void* quick_code) {
773 // When the runtime is set to Java debuggable, we may update the entry points of
774 // all methods of a class to the interpreter bridge. A method's declaring class
775 // might not be in resolved state yet in that case, so we bypass the DCHECK in
776 // UpdateMethodsCode.
Mingyao Yang3fd448a2016-05-10 14:30:41 -0700777 UpdateMethodsCodeImpl(method, quick_code);
778}
779
Mathieu Chartiere401d142015-04-22 13:56:20 -0700780bool Instrumentation::AddDeoptimizedMethod(ArtMethod* method) {
781 if (IsDeoptimizedMethod(method)) {
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700782 // Already in the map. Return.
783 return false;
784 }
785 // Not found. Add it.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700786 deoptimized_methods_.insert(method);
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700787 return true;
788}
789
Mathieu Chartiere401d142015-04-22 13:56:20 -0700790bool Instrumentation::IsDeoptimizedMethod(ArtMethod* method) {
791 return deoptimized_methods_.find(method) != deoptimized_methods_.end();
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700792}
793
Mathieu Chartiere401d142015-04-22 13:56:20 -0700794ArtMethod* Instrumentation::BeginDeoptimizedMethod() {
795 if (deoptimized_methods_.empty()) {
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700796 // Empty.
797 return nullptr;
798 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700799 return *deoptimized_methods_.begin();
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700800}
801
Mathieu Chartiere401d142015-04-22 13:56:20 -0700802bool Instrumentation::RemoveDeoptimizedMethod(ArtMethod* method) {
803 auto it = deoptimized_methods_.find(method);
804 if (it == deoptimized_methods_.end()) {
805 return false;
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700806 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700807 deoptimized_methods_.erase(it);
808 return true;
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700809}
810
811bool Instrumentation::IsDeoptimizedMethodsEmpty() const {
812 return deoptimized_methods_.empty();
813}
814
Mathieu Chartiere401d142015-04-22 13:56:20 -0700815void Instrumentation::Deoptimize(ArtMethod* method) {
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100816 CHECK(!method->IsNative());
817 CHECK(!method->IsProxyMethod());
Alex Light9139e002015-10-09 15:59:48 -0700818 CHECK(method->IsInvokable());
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100819
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700820 Thread* self = Thread::Current();
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700821 {
822 WriterMutexLock mu(self, deoptimized_methods_lock_);
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700823 bool has_not_been_deoptimized = AddDeoptimizedMethod(method);
David Sehr709b0702016-10-13 09:12:37 -0700824 CHECK(has_not_been_deoptimized) << "Method " << ArtMethod::PrettyMethod(method)
Daniel Mihalyica1d06c2014-08-18 18:45:31 +0200825 << " is already deoptimized";
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700826 }
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100827 if (!interpreter_stubs_installed_) {
Elliott Hughes956af0f2014-12-11 14:34:28 -0800828 UpdateEntrypoints(method, GetQuickInstrumentationEntryPoint());
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100829
830 // Install instrumentation exit stub and instrumentation frames. We may already have installed
831 // these previously so it will only cover the newly created frames.
832 instrumentation_stubs_installed_ = true;
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700833 MutexLock mu(self, *Locks::thread_list_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100834 Runtime::Current()->GetThreadList()->ForEach(InstrumentationInstallStack, this);
835 }
836}
837
Mathieu Chartiere401d142015-04-22 13:56:20 -0700838void Instrumentation::Undeoptimize(ArtMethod* method) {
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100839 CHECK(!method->IsNative());
840 CHECK(!method->IsProxyMethod());
Alex Light9139e002015-10-09 15:59:48 -0700841 CHECK(method->IsInvokable());
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100842
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700843 Thread* self = Thread::Current();
844 bool empty;
845 {
846 WriterMutexLock mu(self, deoptimized_methods_lock_);
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700847 bool found_and_erased = RemoveDeoptimizedMethod(method);
David Sehr709b0702016-10-13 09:12:37 -0700848 CHECK(found_and_erased) << "Method " << ArtMethod::PrettyMethod(method)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700849 << " is not deoptimized";
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700850 empty = IsDeoptimizedMethodsEmpty();
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700851 }
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100852
853 // Restore code and possibly stack only if we did not deoptimize everything.
854 if (!interpreter_stubs_installed_) {
855 // Restore its code or resolution trampoline.
856 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Ian Rogersef7d42f2014-01-06 12:55:46 -0800857 if (method->IsStatic() && !method->IsConstructor() &&
858 !method->GetDeclaringClass()->IsInitialized()) {
Elliott Hughes956af0f2014-12-11 14:34:28 -0800859 UpdateEntrypoints(method, GetQuickResolutionStub());
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100860 } else {
Nicolas Geoffraya0619e22016-12-20 13:57:43 +0000861 const void* quick_code = NeedDebugVersionFor(method)
862 ? GetQuickToInterpreterBridge()
863 : class_linker->GetQuickOatCodeFor(method);
Elliott Hughes956af0f2014-12-11 14:34:28 -0800864 UpdateEntrypoints(method, quick_code);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100865 }
866
867 // If there is no deoptimized method left, we can restore the stack of each thread.
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700868 if (empty) {
869 MutexLock mu(self, *Locks::thread_list_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100870 Runtime::Current()->GetThreadList()->ForEach(InstrumentationRestoreStack, this);
871 instrumentation_stubs_installed_ = false;
872 }
873 }
874}
875
Mathieu Chartiere401d142015-04-22 13:56:20 -0700876bool Instrumentation::IsDeoptimized(ArtMethod* method) {
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100877 DCHECK(method != nullptr);
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700878 ReaderMutexLock mu(Thread::Current(), deoptimized_methods_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700879 return IsDeoptimizedMethod(method);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100880}
881
882void Instrumentation::EnableDeoptimization() {
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700883 ReaderMutexLock mu(Thread::Current(), deoptimized_methods_lock_);
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700884 CHECK(IsDeoptimizedMethodsEmpty());
Sebastien Hertz11d40c22014-02-19 18:00:17 +0100885 CHECK_EQ(deoptimization_enabled_, false);
886 deoptimization_enabled_ = true;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100887}
888
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200889void Instrumentation::DisableDeoptimization(const char* key) {
Sebastien Hertz11d40c22014-02-19 18:00:17 +0100890 CHECK_EQ(deoptimization_enabled_, true);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100891 // If we deoptimized everything, undo it.
Alex Lightdba61482016-12-21 08:20:29 -0800892 InstrumentationLevel level = GetCurrentInstrumentationLevel();
893 if (level == InstrumentationLevel::kInstrumentWithInterpreter) {
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200894 UndeoptimizeEverything(key);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100895 }
896 // Undeoptimized selected methods.
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700897 while (true) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700898 ArtMethod* method;
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700899 {
900 ReaderMutexLock mu(Thread::Current(), deoptimized_methods_lock_);
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700901 if (IsDeoptimizedMethodsEmpty()) {
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700902 break;
903 }
Hiroshi Yamauchi799eb3a2014-07-18 15:38:17 -0700904 method = BeginDeoptimizedMethod();
905 CHECK(method != nullptr);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700906 }
907 Undeoptimize(method);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100908 }
Sebastien Hertz11d40c22014-02-19 18:00:17 +0100909 deoptimization_enabled_ = false;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100910}
911
Sebastien Hertz11d40c22014-02-19 18:00:17 +0100912// Indicates if instrumentation should notify method enter/exit events to the listeners.
913bool Instrumentation::ShouldNotifyMethodEnterExitEvents() const {
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200914 if (!HasMethodEntryListeners() && !HasMethodExitListeners()) {
915 return false;
916 }
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100917 return !deoptimization_enabled_ && !interpreter_stubs_installed_;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100918}
919
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200920void Instrumentation::DeoptimizeEverything(const char* key) {
921 CHECK(deoptimization_enabled_);
922 ConfigureStubs(key, InstrumentationLevel::kInstrumentWithInterpreter);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100923}
924
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200925void Instrumentation::UndeoptimizeEverything(const char* key) {
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100926 CHECK(interpreter_stubs_installed_);
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200927 CHECK(deoptimization_enabled_);
928 ConfigureStubs(key, InstrumentationLevel::kInstrumentNothing);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100929}
930
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200931void Instrumentation::EnableMethodTracing(const char* key, bool needs_interpreter) {
932 InstrumentationLevel level;
933 if (needs_interpreter) {
934 level = InstrumentationLevel::kInstrumentWithInterpreter;
935 } else {
936 level = InstrumentationLevel::kInstrumentWithInstrumentationStubs;
937 }
938 ConfigureStubs(key, level);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100939}
940
Sebastien Hertz0462c4c2015-04-01 16:34:17 +0200941void Instrumentation::DisableMethodTracing(const char* key) {
942 ConfigureStubs(key, InstrumentationLevel::kInstrumentNothing);
jeffhao725a9572012-11-13 18:20:12 -0800943}
944
Andreas Gampe542451c2016-07-26 09:02:02 -0700945const void* Instrumentation::GetQuickCodeFor(ArtMethod* method, PointerSize pointer_size) const {
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100946 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Ian Rogers62d6c772013-02-27 08:32:07 -0800947 if (LIKELY(!instrumentation_stubs_installed_)) {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -0800948 const void* code = method->GetEntryPointFromQuickCompiledCodePtrSize(pointer_size);
Vladimir Marko8a630572014-04-09 18:45:35 +0100949 DCHECK(code != nullptr);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700950 if (LIKELY(!class_linker->IsQuickResolutionStub(code) &&
951 !class_linker->IsQuickToInterpreterBridge(code)) &&
952 !class_linker->IsQuickResolutionStub(code) &&
953 !class_linker->IsQuickToInterpreterBridge(code)) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800954 return code;
955 }
956 }
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100957 return class_linker->GetQuickOatCodeFor(method);
jeffhao725a9572012-11-13 18:20:12 -0800958}
959
Alex Lightd7661582017-05-01 13:48:16 -0700960void Instrumentation::MethodEnterEventImpl(Thread* thread,
961 ObjPtr<mirror::Object> this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700962 ArtMethod* method,
Ian Rogers62d6c772013-02-27 08:32:07 -0800963 uint32_t dex_pc) const {
Mingyao Yang2ee17902017-08-30 11:37:08 -0700964 DCHECK(!method->IsRuntimeMethod());
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000965 if (HasMethodEntryListeners()) {
Alex Lightd7661582017-05-01 13:48:16 -0700966 Thread* self = Thread::Current();
967 StackHandleScope<1> hs(self);
968 Handle<mirror::Object> thiz(hs.NewHandle(this_object));
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000969 for (InstrumentationListener* listener : method_entry_listeners_) {
970 if (listener != nullptr) {
Alex Lightd7661582017-05-01 13:48:16 -0700971 listener->MethodEntered(thread, thiz, method, dex_pc);
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000972 }
973 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800974 }
975}
976
Alex Lightd7661582017-05-01 13:48:16 -0700977void Instrumentation::MethodExitEventImpl(Thread* thread,
978 ObjPtr<mirror::Object> this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700979 ArtMethod* method,
Alex Lightd7661582017-05-01 13:48:16 -0700980 uint32_t dex_pc,
981 const JValue& return_value) const {
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000982 if (HasMethodExitListeners()) {
Alex Lightd7661582017-05-01 13:48:16 -0700983 Thread* self = Thread::Current();
984 StackHandleScope<2> hs(self);
985 Handle<mirror::Object> thiz(hs.NewHandle(this_object));
986 if (method->GetInterfaceMethodIfProxy(kRuntimePointerSize)
987 ->GetReturnTypePrimitive() != Primitive::kPrimNot) {
988 for (InstrumentationListener* listener : method_exit_listeners_) {
989 if (listener != nullptr) {
990 listener->MethodExited(thread, thiz, method, dex_pc, return_value);
991 }
992 }
993 } else {
994 Handle<mirror::Object> ret(hs.NewHandle(return_value.GetL()));
995 for (InstrumentationListener* listener : method_exit_listeners_) {
996 if (listener != nullptr) {
997 listener->MethodExited(thread, thiz, method, dex_pc, ret);
998 }
Nicolas Geoffray514a6162015-11-03 11:44:24 +0000999 }
1000 }
Ian Rogers62d6c772013-02-27 08:32:07 -08001001 }
1002}
1003
Alex Lightd7661582017-05-01 13:48:16 -07001004void Instrumentation::MethodUnwindEvent(Thread* thread,
1005 mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -07001006 ArtMethod* method,
Ian Rogers62d6c772013-02-27 08:32:07 -08001007 uint32_t dex_pc) const {
Sebastien Hertz0462c4c2015-04-01 16:34:17 +02001008 if (HasMethodUnwindListeners()) {
Alex Lightd7661582017-05-01 13:48:16 -07001009 Thread* self = Thread::Current();
1010 StackHandleScope<1> hs(self);
1011 Handle<mirror::Object> thiz(hs.NewHandle(this_object));
Mathieu Chartier02e25112013-08-14 16:14:24 -07001012 for (InstrumentationListener* listener : method_unwind_listeners_) {
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001013 if (listener != nullptr) {
Alex Lightd7661582017-05-01 13:48:16 -07001014 listener->MethodUnwind(thread, thiz, method, dex_pc);
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001015 }
Ian Rogers62d6c772013-02-27 08:32:07 -08001016 }
1017 }
1018}
1019
Alex Lightd7661582017-05-01 13:48:16 -07001020void Instrumentation::DexPcMovedEventImpl(Thread* thread,
1021 ObjPtr<mirror::Object> this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -07001022 ArtMethod* method,
Ian Rogers62d6c772013-02-27 08:32:07 -08001023 uint32_t dex_pc) const {
Alex Lightd7661582017-05-01 13:48:16 -07001024 Thread* self = Thread::Current();
1025 StackHandleScope<1> hs(self);
1026 Handle<mirror::Object> thiz(hs.NewHandle(this_object));
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001027 for (InstrumentationListener* listener : dex_pc_listeners_) {
1028 if (listener != nullptr) {
Alex Lightd7661582017-05-01 13:48:16 -07001029 listener->DexPcMoved(thread, thiz, method, dex_pc);
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001030 }
Ian Rogers62d6c772013-02-27 08:32:07 -08001031 }
1032}
1033
Nicolas Geoffray81f0f952016-01-20 16:25:19 +00001034void Instrumentation::BranchImpl(Thread* thread,
1035 ArtMethod* method,
1036 uint32_t dex_pc,
1037 int32_t offset) const {
1038 for (InstrumentationListener* listener : branch_listeners_) {
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001039 if (listener != nullptr) {
Nicolas Geoffray81f0f952016-01-20 16:25:19 +00001040 listener->Branch(thread, method, dex_pc, offset);
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001041 }
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001042 }
1043}
1044
Nicolas Geoffray5550ca82015-08-21 18:38:30 +01001045void Instrumentation::InvokeVirtualOrInterfaceImpl(Thread* thread,
Alex Lightd7661582017-05-01 13:48:16 -07001046 ObjPtr<mirror::Object> this_object,
Nicolas Geoffray5550ca82015-08-21 18:38:30 +01001047 ArtMethod* caller,
1048 uint32_t dex_pc,
1049 ArtMethod* callee) const {
Alex Lightd7661582017-05-01 13:48:16 -07001050 Thread* self = Thread::Current();
1051 StackHandleScope<1> hs(self);
1052 Handle<mirror::Object> thiz(hs.NewHandle(this_object));
Nicolas Geoffray5550ca82015-08-21 18:38:30 +01001053 for (InstrumentationListener* listener : invoke_virtual_or_interface_listeners_) {
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001054 if (listener != nullptr) {
Alex Lightd7661582017-05-01 13:48:16 -07001055 listener->InvokeVirtualOrInterface(thread, thiz, caller, dex_pc, callee);
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001056 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +01001057 }
1058}
1059
Alex Lighte814f9d2017-07-31 16:14:39 -07001060void Instrumentation::WatchedFramePopImpl(Thread* thread, const ShadowFrame& frame) const {
1061 for (InstrumentationListener* listener : watched_frame_pop_listeners_) {
1062 if (listener != nullptr) {
1063 listener->WatchedFramePop(thread, frame);
1064 }
1065 }
1066}
1067
Alex Lightd7661582017-05-01 13:48:16 -07001068void Instrumentation::FieldReadEventImpl(Thread* thread,
1069 ObjPtr<mirror::Object> this_object,
1070 ArtMethod* method,
1071 uint32_t dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -07001072 ArtField* field) const {
Alex Lightd7661582017-05-01 13:48:16 -07001073 Thread* self = Thread::Current();
1074 StackHandleScope<1> hs(self);
1075 Handle<mirror::Object> thiz(hs.NewHandle(this_object));
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001076 for (InstrumentationListener* listener : field_read_listeners_) {
1077 if (listener != nullptr) {
Alex Lightd7661582017-05-01 13:48:16 -07001078 listener->FieldRead(thread, thiz, method, dex_pc, field);
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001079 }
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +02001080 }
1081}
1082
Alex Lightd7661582017-05-01 13:48:16 -07001083void Instrumentation::FieldWriteEventImpl(Thread* thread,
1084 ObjPtr<mirror::Object> this_object,
1085 ArtMethod* method,
1086 uint32_t dex_pc,
1087 ArtField* field,
1088 const JValue& field_value) const {
1089 Thread* self = Thread::Current();
1090 StackHandleScope<2> hs(self);
1091 Handle<mirror::Object> thiz(hs.NewHandle(this_object));
1092 if (field->IsPrimitiveType()) {
1093 for (InstrumentationListener* listener : field_write_listeners_) {
1094 if (listener != nullptr) {
1095 listener->FieldWritten(thread, thiz, method, dex_pc, field, field_value);
1096 }
1097 }
1098 } else {
1099 Handle<mirror::Object> val(hs.NewHandle(field_value.GetL()));
1100 for (InstrumentationListener* listener : field_write_listeners_) {
1101 if (listener != nullptr) {
1102 listener->FieldWritten(thread, thiz, method, dex_pc, field, val);
1103 }
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001104 }
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +02001105 }
1106}
1107
Alex Light6e1607e2017-08-23 10:06:18 -07001108void Instrumentation::ExceptionThrownEvent(Thread* thread,
Sebastien Hertz947ff082013-09-17 14:10:13 +02001109 mirror::Throwable* exception_object) const {
Hiroshi Yamauchi3481f7a2017-02-10 12:07:36 -08001110 Thread* self = Thread::Current();
1111 StackHandleScope<1> hs(self);
1112 Handle<mirror::Throwable> h_exception(hs.NewHandle(exception_object));
Alex Light6e1607e2017-08-23 10:06:18 -07001113 if (HasExceptionThrownListeners()) {
Hiroshi Yamauchi3481f7a2017-02-10 12:07:36 -08001114 DCHECK_EQ(thread->GetException(), h_exception.Get());
Jeff Haoc0bd4da2013-04-11 15:52:28 -07001115 thread->ClearException();
Alex Light6e1607e2017-08-23 10:06:18 -07001116 for (InstrumentationListener* listener : exception_thrown_listeners_) {
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001117 if (listener != nullptr) {
Alex Light6e1607e2017-08-23 10:06:18 -07001118 listener->ExceptionThrown(thread, h_exception);
Nicolas Geoffray514a6162015-11-03 11:44:24 +00001119 }
Ian Rogers62d6c772013-02-27 08:32:07 -08001120 }
Hiroshi Yamauchi3481f7a2017-02-10 12:07:36 -08001121 thread->SetException(h_exception.Get());
Ian Rogers62d6c772013-02-27 08:32:07 -08001122 }
1123}
1124
Sebastien Hertzb2feaaf2015-10-12 13:40:10 +00001125// Computes a frame ID by ignoring inlined frames.
1126size_t Instrumentation::ComputeFrameId(Thread* self,
1127 size_t frame_depth,
1128 size_t inlined_frames_before_frame) {
1129 CHECK_GE(frame_depth, inlined_frames_before_frame);
1130 size_t no_inline_depth = frame_depth - inlined_frames_before_frame;
1131 return StackVisitor::ComputeNumFrames(self, kInstrumentationStackWalk) - no_inline_depth;
1132}
1133
Ian Rogers62d6c772013-02-27 08:32:07 -08001134static void CheckStackDepth(Thread* self, const InstrumentationStackFrame& instrumentation_frame,
1135 int delta)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001136 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray8e5bd182015-05-06 11:34:34 +01001137 size_t frame_id = StackVisitor::ComputeNumFrames(self, kInstrumentationStackWalk) + delta;
Ian Rogers62d6c772013-02-27 08:32:07 -08001138 if (frame_id != instrumentation_frame.frame_id_) {
1139 LOG(ERROR) << "Expected frame_id=" << frame_id << " but found "
1140 << instrumentation_frame.frame_id_;
1141 StackVisitor::DescribeStack(self);
1142 CHECK_EQ(frame_id, instrumentation_frame.frame_id_);
1143 }
1144}
1145
1146void Instrumentation::PushInstrumentationStackFrame(Thread* self, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -07001147 ArtMethod* method,
Jeff Hao9a916d32013-06-27 18:45:37 -07001148 uintptr_t lr, bool interpreter_entry) {
Alex Lightb7edcda2017-04-27 13:20:31 -07001149 DCHECK(!self->IsExceptionPending());
Ian Rogers62d6c772013-02-27 08:32:07 -08001150 std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack();
1151 if (kVerboseInstrumentation) {
David Sehr709b0702016-10-13 09:12:37 -07001152 LOG(INFO) << "Entering " << ArtMethod::PrettyMethod(method) << " from PC "
1153 << reinterpret_cast<void*>(lr);
Ian Rogers62d6c772013-02-27 08:32:07 -08001154 }
Alex Lightb7edcda2017-04-27 13:20:31 -07001155
1156 // We send the enter event before pushing the instrumentation frame to make cleanup easier. If the
1157 // event causes an exception we can simply send the unwind event and return.
1158 StackHandleScope<1> hs(self);
1159 Handle<mirror::Object> h_this(hs.NewHandle(this_object));
1160 if (!interpreter_entry) {
1161 MethodEnterEvent(self, h_this.Get(), method, 0);
1162 if (self->IsExceptionPending()) {
1163 MethodUnwindEvent(self, h_this.Get(), method, 0);
1164 return;
1165 }
1166 }
1167
1168 // We have a callee-save frame meaning this value is guaranteed to never be 0.
1169 DCHECK(!self->IsExceptionPending());
1170 size_t frame_id = StackVisitor::ComputeNumFrames(self, kInstrumentationStackWalk);
1171
1172 instrumentation::InstrumentationStackFrame instrumentation_frame(h_this.Get(), method, lr,
Jeff Hao9a916d32013-06-27 18:45:37 -07001173 frame_id, interpreter_entry);
Ian Rogers62d6c772013-02-27 08:32:07 -08001174 stack->push_front(instrumentation_frame);
Ian Rogers62d6c772013-02-27 08:32:07 -08001175}
1176
Mingyao Yang2ee17902017-08-30 11:37:08 -07001177DeoptimizationMethodType Instrumentation::GetDeoptimizationMethodType(ArtMethod* method) {
1178 if (method->IsRuntimeMethod()) {
1179 // Certain methods have strict requirement on whether the dex instruction
1180 // should be re-executed upon deoptimization.
1181 if (method == Runtime::Current()->GetCalleeSaveMethod(
1182 CalleeSaveType::kSaveEverythingForClinit)) {
1183 return DeoptimizationMethodType::kKeepDexPc;
1184 }
1185 if (method == Runtime::Current()->GetCalleeSaveMethod(
1186 CalleeSaveType::kSaveEverythingForSuspendCheck)) {
1187 return DeoptimizationMethodType::kKeepDexPc;
1188 }
1189 }
1190 return DeoptimizationMethodType::kDefault;
1191}
1192
1193// Try to get the shorty of a runtime method if it's an invocation stub.
1194struct RuntimeMethodShortyVisitor : public StackVisitor {
1195 explicit RuntimeMethodShortyVisitor(Thread* thread)
1196 : StackVisitor(thread, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
1197 shorty('V') {}
1198
1199 bool VisitFrame() REQUIRES_SHARED(Locks::mutator_lock_) {
1200 ArtMethod* m = GetMethod();
1201 if (m != nullptr && !m->IsRuntimeMethod()) {
1202 // The first Java method.
1203 if (m->IsNative()) {
1204 // Use JNI method's shorty for the jni stub.
1205 shorty = m->GetShorty()[0];
1206 return false;
1207 }
1208 if (m->IsProxyMethod()) {
1209 // Proxy method just invokes its proxied method via
1210 // art_quick_proxy_invoke_handler.
1211 shorty = m->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty()[0];
1212 return false;
1213 }
1214 const DexFile::CodeItem* code_item = m->GetCodeItem();
1215 const Instruction* instr = Instruction::At(&code_item->insns_[GetDexPc()]);
1216 if (instr->IsInvoke()) {
1217 const DexFile* dex_file = m->GetDexFile();
1218 if (interpreter::IsStringInit(dex_file, instr->VRegB())) {
1219 // Invoking string init constructor is turned into invoking
1220 // StringFactory.newStringFromChars() which returns a string.
1221 shorty = 'L';
1222 return false;
1223 }
1224 // A regular invoke, use callee's shorty.
1225 uint32_t method_idx = instr->VRegB();
1226 shorty = dex_file->GetMethodShorty(method_idx)[0];
1227 }
1228 // Stop stack walking since we've seen a Java frame.
1229 return false;
1230 }
1231 return true;
1232 }
1233
1234 char shorty;
1235};
1236
Alex Lightb7edcda2017-04-27 13:20:31 -07001237TwoWordReturn Instrumentation::PopInstrumentationStackFrame(Thread* self,
1238 uintptr_t* return_pc,
1239 uint64_t* gpr_result,
1240 uint64_t* fpr_result) {
1241 DCHECK(gpr_result != nullptr);
1242 DCHECK(fpr_result != nullptr);
Ian Rogers62d6c772013-02-27 08:32:07 -08001243 // Do the pop.
1244 std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack();
1245 CHECK_GT(stack->size(), 0U);
1246 InstrumentationStackFrame instrumentation_frame = stack->front();
1247 stack->pop_front();
1248
1249 // Set return PC and check the sanity of the stack.
1250 *return_pc = instrumentation_frame.return_pc_;
1251 CheckStackDepth(self, instrumentation_frame, 0);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001252 self->VerifyStack();
Ian Rogers62d6c772013-02-27 08:32:07 -08001253
Mathieu Chartiere401d142015-04-22 13:56:20 -07001254 ArtMethod* method = instrumentation_frame.method_;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -07001255 uint32_t length;
Andreas Gampe542451c2016-07-26 09:02:02 -07001256 const PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
Mingyao Yang2ee17902017-08-30 11:37:08 -07001257 char return_shorty;
1258
1259 // Runtime method does not call into MethodExitEvent() so there should not be
1260 // suspension point below.
1261 ScopedAssertNoThreadSuspension ants(__FUNCTION__, method->IsRuntimeMethod());
1262 if (method->IsRuntimeMethod()) {
1263 if (method != Runtime::Current()->GetCalleeSaveMethod(
1264 CalleeSaveType::kSaveEverythingForClinit)) {
1265 // If the caller is at an invocation point and the runtime method is not
1266 // for clinit, we need to pass return results to the caller.
1267 // We need the correct shorty to decide whether we need to pass the return
1268 // result for deoptimization below.
1269 RuntimeMethodShortyVisitor visitor(self);
1270 visitor.WalkStack();
1271 return_shorty = visitor.shorty;
1272 } else {
1273 // Some runtime methods such as allocations, unresolved field getters, etc.
1274 // have return value. We don't need to set return_value since MethodExitEvent()
1275 // below isn't called for runtime methods. Deoptimization doesn't need the
1276 // value either since the dex instruction will be re-executed by the
1277 // interpreter, except these two cases:
1278 // (1) For an invoke, which is handled above to get the correct shorty.
1279 // (2) For MONITOR_ENTER/EXIT, which cannot be re-executed since it's not
1280 // idempotent. However there is no return value for it anyway.
1281 return_shorty = 'V';
1282 }
1283 } else {
1284 return_shorty = method->GetInterfaceMethodIfProxy(pointer_size)->GetShorty(&length)[0];
1285 }
1286
Alex Lightb7edcda2017-04-27 13:20:31 -07001287 bool is_ref = return_shorty == '[' || return_shorty == 'L';
1288 StackHandleScope<1> hs(self);
1289 MutableHandle<mirror::Object> res(hs.NewHandle<mirror::Object>(nullptr));
Ian Rogers62d6c772013-02-27 08:32:07 -08001290 JValue return_value;
1291 if (return_shorty == 'V') {
1292 return_value.SetJ(0);
1293 } else if (return_shorty == 'F' || return_shorty == 'D') {
Alex Lightb7edcda2017-04-27 13:20:31 -07001294 return_value.SetJ(*fpr_result);
Ian Rogers62d6c772013-02-27 08:32:07 -08001295 } else {
Alex Lightb7edcda2017-04-27 13:20:31 -07001296 return_value.SetJ(*gpr_result);
1297 }
1298 if (is_ref) {
1299 // Take a handle to the return value so we won't lose it if we suspend.
1300 res.Assign(return_value.GetL());
Ian Rogers62d6c772013-02-27 08:32:07 -08001301 }
1302 // TODO: improve the dex pc information here, requires knowledge of current PC as opposed to
1303 // return_pc.
1304 uint32_t dex_pc = DexFile::kDexNoIndex;
1305 mirror::Object* this_object = instrumentation_frame.this_object_;
Mingyao Yang2ee17902017-08-30 11:37:08 -07001306 if (!method->IsRuntimeMethod() && !instrumentation_frame.interpreter_entry_) {
Sebastien Hertz320deb22014-06-11 19:45:05 +02001307 MethodExitEvent(self, this_object, instrumentation_frame.method_, dex_pc, return_value);
1308 }
jeffhao725a9572012-11-13 18:20:12 -08001309
Sebastien Hertz138dbfc2013-12-04 18:15:25 +01001310 // Deoptimize if the caller needs to continue execution in the interpreter. Do nothing if we get
1311 // back to an upcall.
1312 NthCallerVisitor visitor(self, 1, true);
1313 visitor.WalkStack(true);
Sebastien Hertz270a0e12015-01-16 19:49:09 +01001314 bool deoptimize = (visitor.caller != nullptr) &&
Daniel Mihalyieb076692014-08-22 17:33:31 +02001315 (interpreter_stubs_installed_ || IsDeoptimized(visitor.caller) ||
1316 Dbg::IsForcedInterpreterNeededForUpcall(self, visitor.caller));
Alex Lightb7edcda2017-04-27 13:20:31 -07001317 if (is_ref) {
1318 // Restore the return value if it's a reference since it might have moved.
1319 *reinterpret_cast<mirror::Object**>(gpr_result) = res.Get();
1320 }
Nicolas Geoffraya0619e22016-12-20 13:57:43 +00001321 if (deoptimize && Runtime::Current()->IsAsyncDeoptimizeable(*return_pc)) {
Ian Rogers62d6c772013-02-27 08:32:07 -08001322 if (kVerboseInstrumentation) {
Andreas Gampe46ee31b2016-12-14 10:11:49 -08001323 LOG(INFO) << "Deoptimizing "
1324 << visitor.caller->PrettyMethod()
1325 << " by returning from "
1326 << method->PrettyMethod()
1327 << " with result "
1328 << std::hex << return_value.GetJ() << std::dec
1329 << " in "
1330 << *self;
Ian Rogers62d6c772013-02-27 08:32:07 -08001331 }
Mingyao Yang2ee17902017-08-30 11:37:08 -07001332 DeoptimizationMethodType deopt_method_type = GetDeoptimizationMethodType(method);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001333 self->PushDeoptimizationContext(return_value,
Mingyao Yang2ee17902017-08-30 11:37:08 -07001334 return_shorty == 'L' || return_shorty == '[',
1335 nullptr /* no pending exception */,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +01001336 false /* from_code */,
Mingyao Yang2ee17902017-08-30 11:37:08 -07001337 deopt_method_type);
Andreas Gamped58342c2014-06-05 14:18:08 -07001338 return GetTwoWordSuccessValue(*return_pc,
1339 reinterpret_cast<uintptr_t>(GetQuickDeoptimizationEntryPoint()));
Ian Rogers62d6c772013-02-27 08:32:07 -08001340 } else {
Nicolas Geoffraya0619e22016-12-20 13:57:43 +00001341 if (deoptimize && !Runtime::Current()->IsAsyncDeoptimizeable(*return_pc)) {
1342 LOG(WARNING) << "Got a deoptimization request on un-deoptimizable " << method->PrettyMethod()
1343 << " at PC " << reinterpret_cast<void*>(*return_pc);
1344 }
Ian Rogers62d6c772013-02-27 08:32:07 -08001345 if (kVerboseInstrumentation) {
David Sehr709b0702016-10-13 09:12:37 -07001346 LOG(INFO) << "Returning from " << method->PrettyMethod()
Brian Carlstrom2d888622013-07-18 17:02:00 -07001347 << " to PC " << reinterpret_cast<void*>(*return_pc);
Ian Rogers62d6c772013-02-27 08:32:07 -08001348 }
Andreas Gamped58342c2014-06-05 14:18:08 -07001349 return GetTwoWordSuccessValue(0, *return_pc);
Ian Rogers62d6c772013-02-27 08:32:07 -08001350 }
jeffhao725a9572012-11-13 18:20:12 -08001351}
1352
Mingyao Yangf711f2c2016-05-23 12:29:39 -07001353uintptr_t Instrumentation::PopMethodForUnwind(Thread* self, bool is_deoptimization) const {
Ian Rogers62d6c772013-02-27 08:32:07 -08001354 // Do the pop.
1355 std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack();
1356 CHECK_GT(stack->size(), 0U);
Alex Lightb7edcda2017-04-27 13:20:31 -07001357 size_t idx = stack->size();
Ian Rogers62d6c772013-02-27 08:32:07 -08001358 InstrumentationStackFrame instrumentation_frame = stack->front();
Ian Rogers62d6c772013-02-27 08:32:07 -08001359
Mathieu Chartiere401d142015-04-22 13:56:20 -07001360 ArtMethod* method = instrumentation_frame.method_;
Ian Rogers62d6c772013-02-27 08:32:07 -08001361 if (is_deoptimization) {
1362 if (kVerboseInstrumentation) {
David Sehr709b0702016-10-13 09:12:37 -07001363 LOG(INFO) << "Popping for deoptimization " << ArtMethod::PrettyMethod(method);
Ian Rogers62d6c772013-02-27 08:32:07 -08001364 }
1365 } else {
1366 if (kVerboseInstrumentation) {
David Sehr709b0702016-10-13 09:12:37 -07001367 LOG(INFO) << "Popping for unwind " << ArtMethod::PrettyMethod(method);
Ian Rogers62d6c772013-02-27 08:32:07 -08001368 }
1369
1370 // Notify listeners of method unwind.
1371 // TODO: improve the dex pc information here, requires knowledge of current PC as opposed to
1372 // return_pc.
1373 uint32_t dex_pc = DexFile::kDexNoIndex;
Mingyao Yang2ee17902017-08-30 11:37:08 -07001374 if (!method->IsRuntimeMethod()) {
1375 MethodUnwindEvent(self, instrumentation_frame.this_object_, method, dex_pc);
1376 }
Ian Rogers62d6c772013-02-27 08:32:07 -08001377 }
Alex Lightb7edcda2017-04-27 13:20:31 -07001378 // TODO: bring back CheckStackDepth(self, instrumentation_frame, 2);
1379 CHECK_EQ(stack->size(), idx);
1380 DCHECK(instrumentation_frame.method_ == stack->front().method_);
1381 stack->pop_front();
Mingyao Yangf711f2c2016-05-23 12:29:39 -07001382 return instrumentation_frame.return_pc_;
Ian Rogers62d6c772013-02-27 08:32:07 -08001383}
1384
1385std::string InstrumentationStackFrame::Dump() const {
1386 std::ostringstream os;
David Sehr709b0702016-10-13 09:12:37 -07001387 os << "Frame " << frame_id_ << " " << ArtMethod::PrettyMethod(method_) << ":"
Ian Rogers62d6c772013-02-27 08:32:07 -08001388 << reinterpret_cast<void*>(return_pc_) << " this=" << reinterpret_cast<void*>(this_object_);
1389 return os.str();
1390}
1391
1392} // namespace instrumentation
jeffhao725a9572012-11-13 18:20:12 -08001393} // namespace art