jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | #include <sys/uio.h> |
| 20 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 21 | #include <sstream> |
| 22 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 23 | #include "arch/context.h" |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 24 | #include "atomic.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 25 | #include "base/unix_file/fd_file.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 26 | #include "class_linker.h" |
| 27 | #include "debugger.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 28 | #include "dex_file-inl.h" |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 29 | #include "entrypoints/quick/quick_entrypoints.h" |
Mathieu Chartier | d889178 | 2014-03-02 13:28:37 -0800 | [diff] [blame] | 30 | #include "entrypoints/quick/quick_alloc_entrypoints.h" |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 31 | #include "entrypoints/runtime_asm_entrypoints.h" |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 32 | #include "gc_root-inl.h" |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 33 | #include "interpreter/interpreter.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 34 | #include "mirror/art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | #include "mirror/class-inl.h" |
| 36 | #include "mirror/dex_cache.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | #include "mirror/object_array-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 38 | #include "mirror/object-inl.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 39 | #include "nth_caller_visitor.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 40 | #include "os.h" |
| 41 | #include "scoped_thread_state_change.h" |
| 42 | #include "thread.h" |
| 43 | #include "thread_list.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 44 | |
| 45 | namespace art { |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 46 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 47 | namespace instrumentation { |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 48 | |
Sebastien Hertz | 5bfd5c9 | 2013-11-15 11:36:07 +0100 | [diff] [blame] | 49 | const bool kVerboseInstrumentation = false; |
| 50 | |
Ian Rogers | 816432e | 2013-09-06 15:47:45 -0700 | [diff] [blame] | 51 | // Do we want to deoptimize for method entry and exit listeners or just try to intercept |
| 52 | // invocations? Deoptimization forces all code to run in the interpreter and considerably hurts the |
| 53 | // application's performance. |
Jeff Hao | bc678bb | 2014-08-11 18:00:29 -0700 | [diff] [blame] | 54 | static constexpr bool kDeoptimizeForAccurateMethodEntryExitListeners = true; |
Ian Rogers | 816432e | 2013-09-06 15:47:45 -0700 | [diff] [blame] | 55 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 56 | static bool InstallStubsClassVisitor(mirror::Class* klass, void* arg) |
Sebastien Hertz | a8a697f | 2015-01-15 12:28:47 +0100 | [diff] [blame] | 57 | EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 58 | Instrumentation* instrumentation = reinterpret_cast<Instrumentation*>(arg); |
Sebastien Hertz | a10aa37 | 2015-01-21 17:30:58 +0100 | [diff] [blame^] | 59 | instrumentation->InstallStubsForClass(klass); |
| 60 | return true; // we visit all classes. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 63 | Instrumentation::Instrumentation() |
| 64 | : instrumentation_stubs_installed_(false), entry_exit_stubs_installed_(false), |
| 65 | interpreter_stubs_installed_(false), |
| 66 | interpret_only_(false), forced_interpret_only_(false), |
| 67 | have_method_entry_listeners_(false), have_method_exit_listeners_(false), |
| 68 | have_method_unwind_listeners_(false), have_dex_pc_listeners_(false), |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 69 | have_field_read_listeners_(false), have_field_write_listeners_(false), |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 70 | have_exception_caught_listeners_(false), |
| 71 | deoptimized_methods_lock_("deoptimized methods lock"), |
| 72 | deoptimization_enabled_(false), |
| 73 | interpreter_handler_table_(kMainHandlerTable), |
| 74 | quick_alloc_entry_points_instrumentation_counter_(0) { |
| 75 | } |
| 76 | |
Sebastien Hertz | a10aa37 | 2015-01-21 17:30:58 +0100 | [diff] [blame^] | 77 | void Instrumentation::InstallStubsForClass(mirror::Class* klass) { |
Sebastien Hertz | a8a697f | 2015-01-15 12:28:47 +0100 | [diff] [blame] | 78 | if (klass->IsErroneous()) { |
| 79 | // We can't execute code in a erroneous class: do nothing. |
| 80 | } else if (!klass->IsResolved()) { |
| 81 | // We need the class to be resolved to install/uninstall stubs. Otherwise its methods |
| 82 | // could not be initialized or linked with regards to class inheritance. |
| 83 | } else { |
| 84 | for (size_t i = 0, e = klass->NumDirectMethods(); i < e; i++) { |
| 85 | InstallStubsForMethod(klass->GetDirectMethod(i)); |
| 86 | } |
| 87 | for (size_t i = 0, e = klass->NumVirtualMethods(); i < e; i++) { |
| 88 | InstallStubsForMethod(klass->GetVirtualMethod(i)); |
| 89 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 90 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 93 | static void UpdateEntrypoints(mirror::ArtMethod* method, const void* quick_code) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 94 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 95 | method->SetEntryPointFromQuickCompiledCode(quick_code); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 96 | if (!method->IsResolutionMethod()) { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 97 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 98 | if (class_linker->IsQuickToInterpreterBridge(quick_code) || |
| 99 | (class_linker->IsQuickResolutionStub(quick_code) && |
| 100 | Runtime::Current()->GetInstrumentation()->IsForcedInterpretOnly() && |
| 101 | !method->IsNative() && !method->IsProxyMethod())) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 102 | DCHECK(!method->IsNative()) << PrettyMethod(method); |
Hiroshi Yamauchi | 563b47c | 2014-02-28 17:18:37 -0800 | [diff] [blame] | 103 | DCHECK(!method->IsProxyMethod()) << PrettyMethod(method); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 104 | method->SetEntryPointFromInterpreter(art::artInterpreterToInterpreterBridge); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 105 | } else { |
| 106 | method->SetEntryPointFromInterpreter(art::artInterpreterToCompiledCodeBridge); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | void Instrumentation::InstallStubsForMethod(mirror::ArtMethod* method) { |
| 112 | if (method->IsAbstract() || method->IsProxyMethod()) { |
| 113 | // Do not change stubs for these methods. |
| 114 | return; |
| 115 | } |
Jeff Hao | 5680277 | 2014-08-19 10:17:36 -0700 | [diff] [blame] | 116 | // Don't stub Proxy.<init>. Note that the Proxy class itself is not a proxy class. |
| 117 | if (method->IsConstructor() && |
| 118 | method->GetDeclaringClass()->DescriptorEquals("Ljava/lang/reflect/Proxy;")) { |
Jeff Hao | db8a664 | 2014-08-14 17:18:52 -0700 | [diff] [blame] | 119 | return; |
| 120 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 121 | const void* new_quick_code; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 122 | bool uninstall = !entry_exit_stubs_installed_ && !interpreter_stubs_installed_; |
| 123 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 124 | bool is_class_initialized = method->GetDeclaringClass()->IsInitialized(); |
| 125 | if (uninstall) { |
| 126 | if ((forced_interpret_only_ || IsDeoptimized(method)) && !method->IsNative()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 127 | new_quick_code = GetQuickToInterpreterBridge(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 128 | } else if (is_class_initialized || !method->IsStatic() || method->IsConstructor()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 129 | new_quick_code = class_linker->GetQuickOatCodeFor(method); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 130 | } else { |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 131 | new_quick_code = GetQuickResolutionStub(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 132 | } |
| 133 | } else { // !uninstall |
Sebastien Hertz | bae182c | 2013-12-17 10:42:03 +0100 | [diff] [blame] | 134 | if ((interpreter_stubs_installed_ || forced_interpret_only_ || IsDeoptimized(method)) && |
| 135 | !method->IsNative()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 136 | new_quick_code = GetQuickToInterpreterBridge(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 137 | } else { |
| 138 | // Do not overwrite resolution trampoline. When the trampoline initializes the method's |
| 139 | // class, all its static methods code will be set to the instrumentation entry point. |
| 140 | // For more details, see ClassLinker::FixupStaticTrampolines. |
| 141 | if (is_class_initialized || !method->IsStatic() || method->IsConstructor()) { |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 142 | if (entry_exit_stubs_installed_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 143 | new_quick_code = GetQuickInstrumentationEntryPoint(); |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 144 | } else { |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 145 | new_quick_code = class_linker->GetQuickOatCodeFor(method); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 146 | DCHECK(!class_linker->IsQuickToInterpreterBridge(new_quick_code)); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 147 | } |
| 148 | } else { |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 149 | new_quick_code = GetQuickResolutionStub(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | } |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 153 | UpdateEntrypoints(method, new_quick_code); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 156 | // Places the instrumentation exit pc as the return PC for every quick frame. This also allows |
| 157 | // deoptimization of quick frames to interpreter frames. |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 158 | // Since we may already have done this previously, we need to push new instrumentation frame before |
| 159 | // existing instrumentation frames. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 160 | static void InstrumentationInstallStack(Thread* thread, void* arg) |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 161 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 162 | struct InstallStackVisitor : public StackVisitor { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 163 | InstallStackVisitor(Thread* thread_in, Context* context, uintptr_t instrumentation_exit_pc) |
| 164 | : StackVisitor(thread_in, context), |
| 165 | instrumentation_stack_(thread_in->GetInstrumentationStack()), |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 166 | instrumentation_exit_pc_(instrumentation_exit_pc), |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 167 | reached_existing_instrumentation_frames_(false), instrumentation_stack_depth_(0), |
| 168 | last_return_pc_(0) { |
| 169 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 170 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 171 | virtual bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 172 | mirror::ArtMethod* m = GetMethod(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 173 | if (m == NULL) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 174 | if (kVerboseInstrumentation) { |
| 175 | LOG(INFO) << " Skipping upcall. Frame " << GetFrameId(); |
| 176 | } |
| 177 | last_return_pc_ = 0; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 178 | return true; // Ignore upcalls. |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 179 | } |
Jeff Hao | a15a81b | 2014-05-27 18:25:47 -0700 | [diff] [blame] | 180 | if (GetCurrentQuickFrame() == NULL) { |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 181 | bool interpreter_frame = true; |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 182 | InstrumentationStackFrame instrumentation_frame(GetThisObject(), m, 0, GetFrameId(), |
| 183 | interpreter_frame); |
Jeff Hao | a15a81b | 2014-05-27 18:25:47 -0700 | [diff] [blame] | 184 | if (kVerboseInstrumentation) { |
| 185 | LOG(INFO) << "Pushing shadow frame " << instrumentation_frame.Dump(); |
| 186 | } |
| 187 | shadow_stack_.push_back(instrumentation_frame); |
| 188 | return true; // Continue. |
| 189 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 190 | uintptr_t return_pc = GetReturnPc(); |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 191 | if (m->IsRuntimeMethod()) { |
| 192 | if (return_pc == instrumentation_exit_pc_) { |
| 193 | if (kVerboseInstrumentation) { |
| 194 | LOG(INFO) << " Handling quick to interpreter transition. Frame " << GetFrameId(); |
| 195 | } |
| 196 | CHECK_LT(instrumentation_stack_depth_, instrumentation_stack_->size()); |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 197 | const InstrumentationStackFrame& frame = |
| 198 | instrumentation_stack_->at(instrumentation_stack_depth_); |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 199 | CHECK(frame.interpreter_entry_); |
| 200 | // This is an interpreter frame so method enter event must have been reported. However we |
| 201 | // need to push a DEX pc into the dex_pcs_ list to match size of instrumentation stack. |
| 202 | // Since we won't report method entry here, we can safely push any DEX pc. |
| 203 | dex_pcs_.push_back(0); |
| 204 | last_return_pc_ = frame.return_pc_; |
| 205 | ++instrumentation_stack_depth_; |
| 206 | return true; |
| 207 | } else { |
| 208 | if (kVerboseInstrumentation) { |
| 209 | LOG(INFO) << " Skipping runtime method. Frame " << GetFrameId(); |
| 210 | } |
| 211 | last_return_pc_ = GetReturnPc(); |
| 212 | return true; // Ignore unresolved methods since they will be instrumented after resolution. |
| 213 | } |
| 214 | } |
| 215 | if (kVerboseInstrumentation) { |
| 216 | LOG(INFO) << " Installing exit stub in " << DescribeLocation(); |
| 217 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 218 | if (return_pc == instrumentation_exit_pc_) { |
| 219 | // We've reached a frame which has already been installed with instrumentation exit stub. |
| 220 | // We should have already installed instrumentation on previous frames. |
| 221 | reached_existing_instrumentation_frames_ = true; |
| 222 | |
| 223 | CHECK_LT(instrumentation_stack_depth_, instrumentation_stack_->size()); |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 224 | const InstrumentationStackFrame& frame = |
| 225 | instrumentation_stack_->at(instrumentation_stack_depth_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 226 | CHECK_EQ(m, frame.method_) << "Expected " << PrettyMethod(m) |
| 227 | << ", Found " << PrettyMethod(frame.method_); |
| 228 | return_pc = frame.return_pc_; |
| 229 | if (kVerboseInstrumentation) { |
| 230 | LOG(INFO) << "Ignoring already instrumented " << frame.Dump(); |
| 231 | } |
| 232 | } else { |
| 233 | CHECK_NE(return_pc, 0U); |
| 234 | CHECK(!reached_existing_instrumentation_frames_); |
| 235 | InstrumentationStackFrame instrumentation_frame(GetThisObject(), m, return_pc, GetFrameId(), |
| 236 | false); |
| 237 | if (kVerboseInstrumentation) { |
| 238 | LOG(INFO) << "Pushing frame " << instrumentation_frame.Dump(); |
| 239 | } |
| 240 | |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 241 | // Insert frame at the right position so we do not corrupt the instrumentation stack. |
| 242 | // Instrumentation stack frames are in descending frame id order. |
| 243 | auto it = instrumentation_stack_->begin(); |
| 244 | for (auto end = instrumentation_stack_->end(); it != end; ++it) { |
| 245 | const InstrumentationStackFrame& current = *it; |
| 246 | if (instrumentation_frame.frame_id_ >= current.frame_id_) { |
| 247 | break; |
| 248 | } |
| 249 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 250 | instrumentation_stack_->insert(it, instrumentation_frame); |
| 251 | SetReturnPc(instrumentation_exit_pc_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 252 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 253 | dex_pcs_.push_back(m->ToDexPc(last_return_pc_)); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 254 | last_return_pc_ = return_pc; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 255 | ++instrumentation_stack_depth_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 256 | return true; // Continue. |
| 257 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 258 | std::deque<InstrumentationStackFrame>* const instrumentation_stack_; |
Jeff Hao | a15a81b | 2014-05-27 18:25:47 -0700 | [diff] [blame] | 259 | std::vector<InstrumentationStackFrame> shadow_stack_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 260 | std::vector<uint32_t> dex_pcs_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 261 | const uintptr_t instrumentation_exit_pc_; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 262 | bool reached_existing_instrumentation_frames_; |
| 263 | size_t instrumentation_stack_depth_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 264 | uintptr_t last_return_pc_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 265 | }; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 266 | if (kVerboseInstrumentation) { |
| 267 | std::string thread_name; |
| 268 | thread->GetThreadName(thread_name); |
| 269 | LOG(INFO) << "Installing exit stubs in " << thread_name; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 270 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 271 | |
| 272 | Instrumentation* instrumentation = reinterpret_cast<Instrumentation*>(arg); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 273 | std::unique_ptr<Context> context(Context::Create()); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 274 | uintptr_t instrumentation_exit_pc = reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()); |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 275 | InstallStackVisitor visitor(thread, context.get(), instrumentation_exit_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 276 | visitor.WalkStack(true); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 277 | CHECK_EQ(visitor.dex_pcs_.size(), thread->GetInstrumentationStack()->size()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 278 | |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 279 | if (instrumentation->ShouldNotifyMethodEnterExitEvents()) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 280 | // Create method enter events for all methods currently on the thread's stack. We only do this |
| 281 | // if no debugger is attached to prevent from posting events twice. |
Jeff Hao | a15a81b | 2014-05-27 18:25:47 -0700 | [diff] [blame] | 282 | auto ssi = visitor.shadow_stack_.rbegin(); |
| 283 | for (auto isi = thread->GetInstrumentationStack()->rbegin(), |
| 284 | end = thread->GetInstrumentationStack()->rend(); isi != end; ++isi) { |
| 285 | while (ssi != visitor.shadow_stack_.rend() && (*ssi).frame_id_ < (*isi).frame_id_) { |
| 286 | instrumentation->MethodEnterEvent(thread, (*ssi).this_object_, (*ssi).method_, 0); |
| 287 | ++ssi; |
| 288 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 289 | uint32_t dex_pc = visitor.dex_pcs_.back(); |
| 290 | visitor.dex_pcs_.pop_back(); |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 291 | if (!isi->interpreter_entry_) { |
| 292 | instrumentation->MethodEnterEvent(thread, (*isi).this_object_, (*isi).method_, dex_pc); |
| 293 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 294 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 295 | } |
| 296 | thread->VerifyStack(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 297 | } |
| 298 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 299 | // Removes the instrumentation exit pc as the return PC for every quick frame. |
| 300 | static void InstrumentationRestoreStack(Thread* thread, void* arg) |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 301 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 302 | struct RestoreStackVisitor : public StackVisitor { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 303 | RestoreStackVisitor(Thread* thread_in, uintptr_t instrumentation_exit_pc, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 304 | Instrumentation* instrumentation) |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 305 | : StackVisitor(thread_in, NULL), thread_(thread_in), |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 306 | instrumentation_exit_pc_(instrumentation_exit_pc), |
| 307 | instrumentation_(instrumentation), |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 308 | instrumentation_stack_(thread_in->GetInstrumentationStack()), |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 309 | frames_removed_(0) {} |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 310 | |
| 311 | virtual bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 312 | if (instrumentation_stack_->size() == 0) { |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 313 | return false; // Stop. |
| 314 | } |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 315 | mirror::ArtMethod* m = GetMethod(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 316 | if (GetCurrentQuickFrame() == NULL) { |
| 317 | if (kVerboseInstrumentation) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 318 | LOG(INFO) << " Ignoring a shadow frame. Frame " << GetFrameId() |
| 319 | << " Method=" << PrettyMethod(m); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 320 | } |
| 321 | return true; // Ignore shadow frames. |
| 322 | } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 323 | if (m == NULL) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 324 | if (kVerboseInstrumentation) { |
| 325 | LOG(INFO) << " Skipping upcall. Frame " << GetFrameId(); |
| 326 | } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 327 | return true; // Ignore upcalls. |
| 328 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 329 | bool removed_stub = false; |
| 330 | // TODO: make this search more efficient? |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 331 | const size_t frameId = GetFrameId(); |
| 332 | for (const InstrumentationStackFrame& instrumentation_frame : *instrumentation_stack_) { |
| 333 | if (instrumentation_frame.frame_id_ == frameId) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 334 | if (kVerboseInstrumentation) { |
| 335 | LOG(INFO) << " Removing exit stub in " << DescribeLocation(); |
| 336 | } |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 337 | if (instrumentation_frame.interpreter_entry_) { |
| 338 | CHECK(m == Runtime::Current()->GetCalleeSaveMethod(Runtime::kRefsAndArgs)); |
| 339 | } else { |
| 340 | CHECK(m == instrumentation_frame.method_) << PrettyMethod(m); |
| 341 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 342 | SetReturnPc(instrumentation_frame.return_pc_); |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 343 | if (instrumentation_->ShouldNotifyMethodEnterExitEvents()) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 344 | // Create the method exit events. As the methods didn't really exit the result is 0. |
| 345 | // We only do this if no debugger is attached to prevent from posting events twice. |
| 346 | instrumentation_->MethodExitEvent(thread_, instrumentation_frame.this_object_, m, |
| 347 | GetDexPc(), JValue()); |
| 348 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 349 | frames_removed_++; |
| 350 | removed_stub = true; |
| 351 | break; |
| 352 | } |
| 353 | } |
| 354 | if (!removed_stub) { |
| 355 | if (kVerboseInstrumentation) { |
| 356 | LOG(INFO) << " No exit stub in " << DescribeLocation(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 357 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 358 | } |
| 359 | return true; // Continue. |
| 360 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 361 | Thread* const thread_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 362 | const uintptr_t instrumentation_exit_pc_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 363 | Instrumentation* const instrumentation_; |
| 364 | std::deque<instrumentation::InstrumentationStackFrame>* const instrumentation_stack_; |
| 365 | size_t frames_removed_; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 366 | }; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 367 | if (kVerboseInstrumentation) { |
| 368 | std::string thread_name; |
| 369 | thread->GetThreadName(thread_name); |
| 370 | LOG(INFO) << "Removing exit stubs in " << thread_name; |
| 371 | } |
| 372 | std::deque<instrumentation::InstrumentationStackFrame>* stack = thread->GetInstrumentationStack(); |
| 373 | if (stack->size() > 0) { |
| 374 | Instrumentation* instrumentation = reinterpret_cast<Instrumentation*>(arg); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 375 | uintptr_t instrumentation_exit_pc = |
| 376 | reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 377 | RestoreStackVisitor visitor(thread, instrumentation_exit_pc, instrumentation); |
| 378 | visitor.WalkStack(true); |
| 379 | CHECK_EQ(visitor.frames_removed_, stack->size()); |
| 380 | while (stack->size() > 0) { |
| 381 | stack->pop_front(); |
| 382 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 386 | void Instrumentation::AddListener(InstrumentationListener* listener, uint32_t events) { |
| 387 | Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 388 | if ((events & kMethodEntered) != 0) { |
| 389 | method_entry_listeners_.push_back(listener); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 390 | have_method_entry_listeners_ = true; |
| 391 | } |
| 392 | if ((events & kMethodExited) != 0) { |
| 393 | method_exit_listeners_.push_back(listener); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 394 | have_method_exit_listeners_ = true; |
| 395 | } |
| 396 | if ((events & kMethodUnwind) != 0) { |
| 397 | method_unwind_listeners_.push_back(listener); |
| 398 | have_method_unwind_listeners_ = true; |
| 399 | } |
| 400 | if ((events & kDexPcMoved) != 0) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 401 | std::list<InstrumentationListener*>* modified; |
| 402 | if (have_dex_pc_listeners_) { |
| 403 | modified = new std::list<InstrumentationListener*>(*dex_pc_listeners_.get()); |
| 404 | } else { |
| 405 | modified = new std::list<InstrumentationListener*>(); |
| 406 | } |
| 407 | modified->push_back(listener); |
| 408 | dex_pc_listeners_.reset(modified); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 409 | have_dex_pc_listeners_ = true; |
| 410 | } |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 411 | if ((events & kFieldRead) != 0) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 412 | std::list<InstrumentationListener*>* modified; |
| 413 | if (have_field_read_listeners_) { |
| 414 | modified = new std::list<InstrumentationListener*>(*field_read_listeners_.get()); |
| 415 | } else { |
| 416 | modified = new std::list<InstrumentationListener*>(); |
| 417 | } |
| 418 | modified->push_back(listener); |
| 419 | field_read_listeners_.reset(modified); |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 420 | have_field_read_listeners_ = true; |
| 421 | } |
| 422 | if ((events & kFieldWritten) != 0) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 423 | std::list<InstrumentationListener*>* modified; |
| 424 | if (have_field_write_listeners_) { |
| 425 | modified = new std::list<InstrumentationListener*>(*field_write_listeners_.get()); |
| 426 | } else { |
| 427 | modified = new std::list<InstrumentationListener*>(); |
| 428 | } |
| 429 | modified->push_back(listener); |
| 430 | field_write_listeners_.reset(modified); |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 431 | have_field_write_listeners_ = true; |
| 432 | } |
Jeff Hao | 14dd5a8 | 2013-04-11 10:23:36 -0700 | [diff] [blame] | 433 | if ((events & kExceptionCaught) != 0) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 434 | std::list<InstrumentationListener*>* modified; |
| 435 | if (have_exception_caught_listeners_) { |
| 436 | modified = new std::list<InstrumentationListener*>(*exception_caught_listeners_.get()); |
| 437 | } else { |
| 438 | modified = new std::list<InstrumentationListener*>(); |
| 439 | } |
| 440 | modified->push_back(listener); |
| 441 | exception_caught_listeners_.reset(modified); |
Jeff Hao | 14dd5a8 | 2013-04-11 10:23:36 -0700 | [diff] [blame] | 442 | have_exception_caught_listeners_ = true; |
| 443 | } |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 444 | UpdateInterpreterHandlerTable(); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 447 | void Instrumentation::RemoveListener(InstrumentationListener* listener, uint32_t events) { |
| 448 | Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 449 | |
| 450 | if ((events & kMethodEntered) != 0) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 451 | if (have_method_entry_listeners_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 452 | method_entry_listeners_.remove(listener); |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 453 | have_method_entry_listeners_ = !method_entry_listeners_.empty(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 454 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 455 | } |
| 456 | if ((events & kMethodExited) != 0) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 457 | if (have_method_exit_listeners_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 458 | method_exit_listeners_.remove(listener); |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 459 | have_method_exit_listeners_ = !method_exit_listeners_.empty(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 460 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 461 | } |
| 462 | if ((events & kMethodUnwind) != 0) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 463 | if (have_method_unwind_listeners_) { |
| 464 | method_unwind_listeners_.remove(listener); |
| 465 | have_method_unwind_listeners_ = !method_unwind_listeners_.empty(); |
| 466 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 467 | } |
| 468 | if ((events & kDexPcMoved) != 0) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 469 | if (have_dex_pc_listeners_) { |
| 470 | std::list<InstrumentationListener*>* modified = |
| 471 | new std::list<InstrumentationListener*>(*dex_pc_listeners_.get()); |
| 472 | modified->remove(listener); |
| 473 | have_dex_pc_listeners_ = !modified->empty(); |
| 474 | if (have_dex_pc_listeners_) { |
| 475 | dex_pc_listeners_.reset(modified); |
| 476 | } else { |
| 477 | dex_pc_listeners_.reset(); |
| 478 | delete modified; |
| 479 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 480 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 481 | } |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 482 | if ((events & kFieldRead) != 0) { |
Daniel Mihalyi | 6644521 | 2014-08-21 15:57:25 +0200 | [diff] [blame] | 483 | if (have_field_read_listeners_) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 484 | std::list<InstrumentationListener*>* modified = |
| 485 | new std::list<InstrumentationListener*>(*field_read_listeners_.get()); |
| 486 | modified->remove(listener); |
| 487 | have_field_read_listeners_ = !modified->empty(); |
| 488 | if (have_field_read_listeners_) { |
| 489 | field_read_listeners_.reset(modified); |
| 490 | } else { |
| 491 | field_read_listeners_.reset(); |
| 492 | delete modified; |
| 493 | } |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 494 | } |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 495 | } |
| 496 | if ((events & kFieldWritten) != 0) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 497 | if (have_field_write_listeners_) { |
| 498 | std::list<InstrumentationListener*>* modified = |
| 499 | new std::list<InstrumentationListener*>(*field_write_listeners_.get()); |
| 500 | modified->remove(listener); |
| 501 | have_field_write_listeners_ = !modified->empty(); |
| 502 | if (have_field_write_listeners_) { |
| 503 | field_write_listeners_.reset(modified); |
| 504 | } else { |
| 505 | field_write_listeners_.reset(); |
| 506 | delete modified; |
| 507 | } |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 508 | } |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 509 | } |
Jeff Hao | 14dd5a8 | 2013-04-11 10:23:36 -0700 | [diff] [blame] | 510 | if ((events & kExceptionCaught) != 0) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 511 | if (have_exception_caught_listeners_) { |
| 512 | std::list<InstrumentationListener*>* modified = |
| 513 | new std::list<InstrumentationListener*>(*exception_caught_listeners_.get()); |
| 514 | modified->remove(listener); |
| 515 | have_exception_caught_listeners_ = !modified->empty(); |
| 516 | if (have_exception_caught_listeners_) { |
| 517 | exception_caught_listeners_.reset(modified); |
| 518 | } else { |
| 519 | exception_caught_listeners_.reset(); |
| 520 | delete modified; |
| 521 | } |
| 522 | } |
Jeff Hao | 14dd5a8 | 2013-04-11 10:23:36 -0700 | [diff] [blame] | 523 | } |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 524 | UpdateInterpreterHandlerTable(); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 525 | } |
| 526 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 527 | void Instrumentation::ConfigureStubs(bool require_entry_exit_stubs, bool require_interpreter) { |
| 528 | interpret_only_ = require_interpreter || forced_interpret_only_; |
| 529 | // Compute what level of instrumentation is required and compare to current. |
| 530 | int desired_level, current_level; |
| 531 | if (require_interpreter) { |
| 532 | desired_level = 2; |
| 533 | } else if (require_entry_exit_stubs) { |
| 534 | desired_level = 1; |
| 535 | } else { |
| 536 | desired_level = 0; |
| 537 | } |
| 538 | if (interpreter_stubs_installed_) { |
| 539 | current_level = 2; |
| 540 | } else if (entry_exit_stubs_installed_) { |
| 541 | current_level = 1; |
| 542 | } else { |
| 543 | current_level = 0; |
| 544 | } |
| 545 | if (desired_level == current_level) { |
| 546 | // We're already set. |
| 547 | return; |
| 548 | } |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 549 | Thread* const self = Thread::Current(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 550 | Runtime* runtime = Runtime::Current(); |
Sebastien Hertz | a8a697f | 2015-01-15 12:28:47 +0100 | [diff] [blame] | 551 | Locks::mutator_lock_->AssertExclusiveHeld(self); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 552 | Locks::thread_list_lock_->AssertNotHeld(self); |
| 553 | if (desired_level > 0) { |
| 554 | if (require_interpreter) { |
| 555 | interpreter_stubs_installed_ = true; |
| 556 | } else { |
| 557 | CHECK(require_entry_exit_stubs); |
| 558 | entry_exit_stubs_installed_ = true; |
| 559 | } |
| 560 | runtime->GetClassLinker()->VisitClasses(InstallStubsClassVisitor, this); |
| 561 | instrumentation_stubs_installed_ = true; |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 562 | MutexLock mu(self, *Locks::thread_list_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 563 | runtime->GetThreadList()->ForEach(InstrumentationInstallStack, this); |
| 564 | } else { |
| 565 | interpreter_stubs_installed_ = false; |
| 566 | entry_exit_stubs_installed_ = false; |
| 567 | runtime->GetClassLinker()->VisitClasses(InstallStubsClassVisitor, this); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 568 | // Restore stack only if there is no method currently deoptimized. |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 569 | bool empty; |
| 570 | { |
| 571 | ReaderMutexLock mu(self, deoptimized_methods_lock_); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 572 | empty = IsDeoptimizedMethodsEmpty(); // Avoid lock violation. |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 573 | } |
| 574 | if (empty) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 575 | instrumentation_stubs_installed_ = false; |
| 576 | MutexLock mu(self, *Locks::thread_list_lock_); |
| 577 | Runtime::Current()->GetThreadList()->ForEach(InstrumentationRestoreStack, this); |
| 578 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 579 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 580 | } |
| 581 | |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 582 | static void ResetQuickAllocEntryPointsForThread(Thread* thread, void* arg) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 583 | UNUSED(arg); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 584 | thread->ResetQuickAllocEntryPointsForThread(); |
| 585 | } |
| 586 | |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 587 | void Instrumentation::SetEntrypointsInstrumented(bool instrumented) { |
| 588 | Thread* self = Thread::Current(); |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 589 | Runtime* runtime = Runtime::Current(); |
| 590 | ThreadList* tl = runtime->GetThreadList(); |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 591 | Locks::mutator_lock_->AssertNotHeld(self); |
| 592 | Locks::instrument_entrypoints_lock_->AssertHeld(self); |
| 593 | if (runtime->IsStarted()) { |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 594 | tl->SuspendAll(); |
| 595 | } |
| 596 | { |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 597 | MutexLock mu(self, *Locks::runtime_shutdown_lock_); |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 598 | SetQuickAllocEntryPointsInstrumented(instrumented); |
| 599 | ResetQuickAllocEntryPoints(); |
| 600 | } |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 601 | if (runtime->IsStarted()) { |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 602 | tl->ResumeAll(); |
| 603 | } |
| 604 | } |
| 605 | |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 606 | void Instrumentation::InstrumentQuickAllocEntryPoints() { |
| 607 | MutexLock mu(Thread::Current(), *Locks::instrument_entrypoints_lock_); |
| 608 | InstrumentQuickAllocEntryPointsLocked(); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 609 | } |
| 610 | |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 611 | void Instrumentation::UninstrumentQuickAllocEntryPoints() { |
| 612 | MutexLock mu(Thread::Current(), *Locks::instrument_entrypoints_lock_); |
| 613 | UninstrumentQuickAllocEntryPointsLocked(); |
| 614 | } |
| 615 | |
| 616 | void Instrumentation::InstrumentQuickAllocEntryPointsLocked() { |
| 617 | Locks::instrument_entrypoints_lock_->AssertHeld(Thread::Current()); |
| 618 | if (quick_alloc_entry_points_instrumentation_counter_ == 0) { |
| 619 | SetEntrypointsInstrumented(true); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 620 | } |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 621 | ++quick_alloc_entry_points_instrumentation_counter_; |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | void Instrumentation::UninstrumentQuickAllocEntryPointsLocked() { |
| 625 | Locks::instrument_entrypoints_lock_->AssertHeld(Thread::Current()); |
| 626 | CHECK_GT(quick_alloc_entry_points_instrumentation_counter_, 0U); |
| 627 | --quick_alloc_entry_points_instrumentation_counter_; |
| 628 | if (quick_alloc_entry_points_instrumentation_counter_ == 0) { |
| 629 | SetEntrypointsInstrumented(false); |
| 630 | } |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | void Instrumentation::ResetQuickAllocEntryPoints() { |
| 634 | Runtime* runtime = Runtime::Current(); |
| 635 | if (runtime->IsStarted()) { |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 636 | MutexLock mu(Thread::Current(), *Locks::thread_list_lock_); |
| 637 | runtime->GetThreadList()->ForEach(ResetQuickAllocEntryPointsForThread, NULL); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 641 | void Instrumentation::UpdateMethodsCode(mirror::ArtMethod* method, const void* quick_code) { |
Sebastien Hertz | a8a697f | 2015-01-15 12:28:47 +0100 | [diff] [blame] | 642 | DCHECK(method->GetDeclaringClass()->IsResolved()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 643 | const void* new_quick_code; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 644 | if (LIKELY(!instrumentation_stubs_installed_)) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 645 | new_quick_code = quick_code; |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 646 | } else { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 647 | if ((interpreter_stubs_installed_ || IsDeoptimized(method)) && !method->IsNative()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 648 | new_quick_code = GetQuickToInterpreterBridge(); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 649 | } else { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 650 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 651 | if (class_linker->IsQuickResolutionStub(quick_code) || |
| 652 | class_linker->IsQuickToInterpreterBridge(quick_code)) { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 653 | new_quick_code = quick_code; |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 654 | } else if (entry_exit_stubs_installed_) { |
| 655 | new_quick_code = GetQuickInstrumentationEntryPoint(); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 656 | } else { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 657 | new_quick_code = quick_code; |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 658 | } |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 659 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 660 | } |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 661 | UpdateEntrypoints(method, new_quick_code); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 662 | } |
| 663 | |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 664 | bool Instrumentation::AddDeoptimizedMethod(mirror::ArtMethod* method) { |
| 665 | // Note that the insert() below isn't read barrier-aware. So, this |
| 666 | // FindDeoptimizedMethod() call is necessary or else we would end up |
| 667 | // storing the same method twice in the map (the from-space and the |
| 668 | // to-space ones). |
| 669 | if (FindDeoptimizedMethod(method)) { |
| 670 | // Already in the map. Return. |
| 671 | return false; |
| 672 | } |
| 673 | // Not found. Add it. |
| 674 | int32_t hash_code = method->IdentityHashCode(); |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 675 | deoptimized_methods_.insert(std::make_pair(hash_code, GcRoot<mirror::ArtMethod>(method))); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 676 | return true; |
| 677 | } |
| 678 | |
| 679 | bool Instrumentation::FindDeoptimizedMethod(mirror::ArtMethod* method) { |
| 680 | int32_t hash_code = method->IdentityHashCode(); |
| 681 | auto range = deoptimized_methods_.equal_range(hash_code); |
| 682 | for (auto it = range.first; it != range.second; ++it) { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 683 | mirror::ArtMethod* m = it->second.Read(); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 684 | if (m == method) { |
| 685 | // Found. |
| 686 | return true; |
| 687 | } |
| 688 | } |
| 689 | // Not found. |
| 690 | return false; |
| 691 | } |
| 692 | |
| 693 | mirror::ArtMethod* Instrumentation::BeginDeoptimizedMethod() { |
| 694 | auto it = deoptimized_methods_.begin(); |
| 695 | if (it == deoptimized_methods_.end()) { |
| 696 | // Empty. |
| 697 | return nullptr; |
| 698 | } |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 699 | return it->second.Read(); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | bool Instrumentation::RemoveDeoptimizedMethod(mirror::ArtMethod* method) { |
| 703 | int32_t hash_code = method->IdentityHashCode(); |
| 704 | auto range = deoptimized_methods_.equal_range(hash_code); |
| 705 | for (auto it = range.first; it != range.second; ++it) { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 706 | mirror::ArtMethod* m = it->second.Read(); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 707 | if (m == method) { |
| 708 | // Found. Erase and return. |
| 709 | deoptimized_methods_.erase(it); |
| 710 | return true; |
| 711 | } |
| 712 | } |
| 713 | // Not found. |
| 714 | return false; |
| 715 | } |
| 716 | |
| 717 | bool Instrumentation::IsDeoptimizedMethodsEmpty() const { |
| 718 | return deoptimized_methods_.empty(); |
| 719 | } |
| 720 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 721 | void Instrumentation::Deoptimize(mirror::ArtMethod* method) { |
| 722 | CHECK(!method->IsNative()); |
| 723 | CHECK(!method->IsProxyMethod()); |
| 724 | CHECK(!method->IsAbstract()); |
| 725 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 726 | Thread* self = Thread::Current(); |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 727 | { |
| 728 | WriterMutexLock mu(self, deoptimized_methods_lock_); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 729 | bool has_not_been_deoptimized = AddDeoptimizedMethod(method); |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 730 | CHECK(has_not_been_deoptimized) << "Method " << PrettyMethod(method) |
| 731 | << " is already deoptimized"; |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 732 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 733 | if (!interpreter_stubs_installed_) { |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 734 | UpdateEntrypoints(method, GetQuickInstrumentationEntryPoint()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 735 | |
| 736 | // Install instrumentation exit stub and instrumentation frames. We may already have installed |
| 737 | // these previously so it will only cover the newly created frames. |
| 738 | instrumentation_stubs_installed_ = true; |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 739 | MutexLock mu(self, *Locks::thread_list_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 740 | Runtime::Current()->GetThreadList()->ForEach(InstrumentationInstallStack, this); |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | void Instrumentation::Undeoptimize(mirror::ArtMethod* method) { |
| 745 | CHECK(!method->IsNative()); |
| 746 | CHECK(!method->IsProxyMethod()); |
| 747 | CHECK(!method->IsAbstract()); |
| 748 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 749 | Thread* self = Thread::Current(); |
| 750 | bool empty; |
| 751 | { |
| 752 | WriterMutexLock mu(self, deoptimized_methods_lock_); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 753 | bool found_and_erased = RemoveDeoptimizedMethod(method); |
| 754 | CHECK(found_and_erased) << "Method " << PrettyMethod(method) |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 755 | << " is not deoptimized"; |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 756 | empty = IsDeoptimizedMethodsEmpty(); |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 757 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 758 | |
| 759 | // Restore code and possibly stack only if we did not deoptimize everything. |
| 760 | if (!interpreter_stubs_installed_) { |
| 761 | // Restore its code or resolution trampoline. |
| 762 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 763 | if (method->IsStatic() && !method->IsConstructor() && |
| 764 | !method->GetDeclaringClass()->IsInitialized()) { |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 765 | UpdateEntrypoints(method, GetQuickResolutionStub()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 766 | } else { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 767 | const void* quick_code = class_linker->GetQuickOatCodeFor(method); |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 768 | UpdateEntrypoints(method, quick_code); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | // If there is no deoptimized method left, we can restore the stack of each thread. |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 772 | if (empty) { |
| 773 | MutexLock mu(self, *Locks::thread_list_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 774 | Runtime::Current()->GetThreadList()->ForEach(InstrumentationRestoreStack, this); |
| 775 | instrumentation_stubs_installed_ = false; |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 780 | bool Instrumentation::IsDeoptimized(mirror::ArtMethod* method) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 781 | DCHECK(method != nullptr); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 782 | ReaderMutexLock mu(Thread::Current(), deoptimized_methods_lock_); |
| 783 | return FindDeoptimizedMethod(method); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | void Instrumentation::EnableDeoptimization() { |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 787 | ReaderMutexLock mu(Thread::Current(), deoptimized_methods_lock_); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 788 | CHECK(IsDeoptimizedMethodsEmpty()); |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 789 | CHECK_EQ(deoptimization_enabled_, false); |
| 790 | deoptimization_enabled_ = true; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | void Instrumentation::DisableDeoptimization() { |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 794 | CHECK_EQ(deoptimization_enabled_, true); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 795 | // If we deoptimized everything, undo it. |
| 796 | if (interpreter_stubs_installed_) { |
| 797 | UndeoptimizeEverything(); |
| 798 | } |
| 799 | // Undeoptimized selected methods. |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 800 | while (true) { |
| 801 | mirror::ArtMethod* method; |
| 802 | { |
| 803 | ReaderMutexLock mu(Thread::Current(), deoptimized_methods_lock_); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 804 | if (IsDeoptimizedMethodsEmpty()) { |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 805 | break; |
| 806 | } |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 807 | method = BeginDeoptimizedMethod(); |
| 808 | CHECK(method != nullptr); |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 809 | } |
| 810 | Undeoptimize(method); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 811 | } |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 812 | deoptimization_enabled_ = false; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 813 | } |
| 814 | |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 815 | // Indicates if instrumentation should notify method enter/exit events to the listeners. |
| 816 | bool Instrumentation::ShouldNotifyMethodEnterExitEvents() const { |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 817 | return !deoptimization_enabled_ && !interpreter_stubs_installed_; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | void Instrumentation::DeoptimizeEverything() { |
| 821 | CHECK(!interpreter_stubs_installed_); |
| 822 | ConfigureStubs(false, true); |
| 823 | } |
| 824 | |
| 825 | void Instrumentation::UndeoptimizeEverything() { |
| 826 | CHECK(interpreter_stubs_installed_); |
| 827 | ConfigureStubs(false, false); |
| 828 | } |
| 829 | |
| 830 | void Instrumentation::EnableMethodTracing() { |
| 831 | bool require_interpreter = kDeoptimizeForAccurateMethodEntryExitListeners; |
| 832 | ConfigureStubs(!require_interpreter, require_interpreter); |
| 833 | } |
| 834 | |
| 835 | void Instrumentation::DisableMethodTracing() { |
| 836 | ConfigureStubs(false, false); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 837 | } |
| 838 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 839 | const void* Instrumentation::GetQuickCodeFor(mirror::ArtMethod* method, size_t pointer_size) const { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 840 | Runtime* runtime = Runtime::Current(); |
| 841 | if (LIKELY(!instrumentation_stubs_installed_)) { |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 842 | const void* code = method->GetEntryPointFromQuickCompiledCodePtrSize(pointer_size); |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 843 | DCHECK(code != nullptr); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 844 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 845 | if (LIKELY(!class_linker->IsQuickResolutionStub(code) && |
| 846 | !class_linker->IsQuickToInterpreterBridge(code)) && |
| 847 | !class_linker->IsQuickResolutionStub(code) && |
| 848 | !class_linker->IsQuickToInterpreterBridge(code)) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 849 | return code; |
| 850 | } |
| 851 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 852 | return runtime->GetClassLinker()->GetQuickOatCodeFor(method); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 853 | } |
| 854 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 855 | void Instrumentation::MethodEnterEventImpl(Thread* thread, mirror::Object* this_object, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 856 | mirror::ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 857 | uint32_t dex_pc) const { |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 858 | auto it = method_entry_listeners_.begin(); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 859 | bool is_end = (it == method_entry_listeners_.end()); |
| 860 | // Implemented this way to prevent problems caused by modification of the list while iterating. |
| 861 | while (!is_end) { |
| 862 | InstrumentationListener* cur = *it; |
| 863 | ++it; |
| 864 | is_end = (it == method_entry_listeners_.end()); |
| 865 | cur->MethodEntered(thread, this_object, method, dex_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
| 869 | void Instrumentation::MethodExitEventImpl(Thread* thread, mirror::Object* this_object, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 870 | mirror::ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 871 | uint32_t dex_pc, const JValue& return_value) const { |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 872 | auto it = method_exit_listeners_.begin(); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 873 | bool is_end = (it == method_exit_listeners_.end()); |
| 874 | // Implemented this way to prevent problems caused by modification of the list while iterating. |
| 875 | while (!is_end) { |
| 876 | InstrumentationListener* cur = *it; |
| 877 | ++it; |
| 878 | is_end = (it == method_exit_listeners_.end()); |
| 879 | cur->MethodExited(thread, this_object, method, dex_pc, return_value); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | |
| 883 | void Instrumentation::MethodUnwindEvent(Thread* thread, mirror::Object* this_object, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 884 | mirror::ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 885 | uint32_t dex_pc) const { |
| 886 | if (have_method_unwind_listeners_) { |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 887 | for (InstrumentationListener* listener : method_unwind_listeners_) { |
Sebastien Hertz | 51db44a | 2013-11-19 10:00:29 +0100 | [diff] [blame] | 888 | listener->MethodUnwind(thread, this_object, method, dex_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | void Instrumentation::DexPcMovedEventImpl(Thread* thread, mirror::Object* this_object, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 894 | mirror::ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 895 | uint32_t dex_pc) const { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 896 | if (HasDexPcListeners()) { |
| 897 | std::shared_ptr<std::list<InstrumentationListener*>> original(dex_pc_listeners_); |
| 898 | for (InstrumentationListener* listener : *original.get()) { |
| 899 | listener->DexPcMoved(thread, this_object, method, dex_pc); |
| 900 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 904 | void Instrumentation::FieldReadEventImpl(Thread* thread, mirror::Object* this_object, |
| 905 | mirror::ArtMethod* method, uint32_t dex_pc, |
| 906 | mirror::ArtField* field) const { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 907 | if (HasFieldReadListeners()) { |
| 908 | std::shared_ptr<std::list<InstrumentationListener*>> original(field_read_listeners_); |
| 909 | for (InstrumentationListener* listener : *original.get()) { |
| 910 | listener->FieldRead(thread, this_object, method, dex_pc, field); |
| 911 | } |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | |
| 915 | void Instrumentation::FieldWriteEventImpl(Thread* thread, mirror::Object* this_object, |
| 916 | mirror::ArtMethod* method, uint32_t dex_pc, |
| 917 | mirror::ArtField* field, const JValue& field_value) const { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 918 | if (HasFieldWriteListeners()) { |
| 919 | std::shared_ptr<std::list<InstrumentationListener*>> original(field_write_listeners_); |
| 920 | for (InstrumentationListener* listener : *original.get()) { |
| 921 | listener->FieldWritten(thread, this_object, method, dex_pc, field, field_value); |
| 922 | } |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 926 | void Instrumentation::ExceptionCaughtEvent(Thread* thread, const ThrowLocation& throw_location, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 927 | mirror::ArtMethod* catch_method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 928 | uint32_t catch_dex_pc, |
Sebastien Hertz | 947ff08 | 2013-09-17 14:10:13 +0200 | [diff] [blame] | 929 | mirror::Throwable* exception_object) const { |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 930 | if (HasExceptionCaughtListeners()) { |
| 931 | DCHECK_EQ(thread->GetException(nullptr), exception_object); |
| 932 | bool is_exception_reported = thread->IsExceptionReportedToInstrumentation(); |
Jeff Hao | c0bd4da | 2013-04-11 15:52:28 -0700 | [diff] [blame] | 933 | thread->ClearException(); |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 934 | std::shared_ptr<std::list<InstrumentationListener*>> original(exception_caught_listeners_); |
| 935 | for (InstrumentationListener* listener : *original.get()) { |
| 936 | listener->ExceptionCaught(thread, throw_location, catch_method, catch_dex_pc, |
| 937 | exception_object); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 938 | } |
Jeff Hao | c0bd4da | 2013-04-11 15:52:28 -0700 | [diff] [blame] | 939 | thread->SetException(throw_location, exception_object); |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 940 | thread->SetExceptionReportedToInstrumentation(is_exception_reported); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | |
| 944 | static void CheckStackDepth(Thread* self, const InstrumentationStackFrame& instrumentation_frame, |
| 945 | int delta) |
| 946 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 947 | size_t frame_id = StackVisitor::ComputeNumFrames(self) + delta; |
| 948 | if (frame_id != instrumentation_frame.frame_id_) { |
| 949 | LOG(ERROR) << "Expected frame_id=" << frame_id << " but found " |
| 950 | << instrumentation_frame.frame_id_; |
| 951 | StackVisitor::DescribeStack(self); |
| 952 | CHECK_EQ(frame_id, instrumentation_frame.frame_id_); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | void Instrumentation::PushInstrumentationStackFrame(Thread* self, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 957 | mirror::ArtMethod* method, |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 958 | uintptr_t lr, bool interpreter_entry) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 959 | // We have a callee-save frame meaning this value is guaranteed to never be 0. |
| 960 | size_t frame_id = StackVisitor::ComputeNumFrames(self); |
| 961 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack(); |
| 962 | if (kVerboseInstrumentation) { |
Brian Carlstrom | 2d88862 | 2013-07-18 17:02:00 -0700 | [diff] [blame] | 963 | LOG(INFO) << "Entering " << PrettyMethod(method) << " from PC " << reinterpret_cast<void*>(lr); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 964 | } |
| 965 | instrumentation::InstrumentationStackFrame instrumentation_frame(this_object, method, lr, |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 966 | frame_id, interpreter_entry); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 967 | stack->push_front(instrumentation_frame); |
| 968 | |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 969 | if (!interpreter_entry) { |
| 970 | MethodEnterEvent(self, this_object, method, 0); |
| 971 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 972 | } |
| 973 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 974 | TwoWordReturn Instrumentation::PopInstrumentationStackFrame(Thread* self, uintptr_t* return_pc, |
| 975 | uint64_t gpr_result, |
| 976 | uint64_t fpr_result) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 977 | // Do the pop. |
| 978 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack(); |
| 979 | CHECK_GT(stack->size(), 0U); |
| 980 | InstrumentationStackFrame instrumentation_frame = stack->front(); |
| 981 | stack->pop_front(); |
| 982 | |
| 983 | // Set return PC and check the sanity of the stack. |
| 984 | *return_pc = instrumentation_frame.return_pc_; |
| 985 | CheckStackDepth(self, instrumentation_frame, 0); |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 986 | self->VerifyStack(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 987 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 988 | mirror::ArtMethod* method = instrumentation_frame.method_; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 989 | uint32_t length; |
| 990 | char return_shorty = method->GetShorty(&length)[0]; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 991 | JValue return_value; |
| 992 | if (return_shorty == 'V') { |
| 993 | return_value.SetJ(0); |
| 994 | } else if (return_shorty == 'F' || return_shorty == 'D') { |
| 995 | return_value.SetJ(fpr_result); |
| 996 | } else { |
| 997 | return_value.SetJ(gpr_result); |
| 998 | } |
| 999 | // TODO: improve the dex pc information here, requires knowledge of current PC as opposed to |
| 1000 | // return_pc. |
| 1001 | uint32_t dex_pc = DexFile::kDexNoIndex; |
| 1002 | mirror::Object* this_object = instrumentation_frame.this_object_; |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 1003 | if (!instrumentation_frame.interpreter_entry_) { |
| 1004 | MethodExitEvent(self, this_object, instrumentation_frame.method_, dex_pc, return_value); |
| 1005 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1006 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1007 | // Deoptimize if the caller needs to continue execution in the interpreter. Do nothing if we get |
| 1008 | // back to an upcall. |
| 1009 | NthCallerVisitor visitor(self, 1, true); |
| 1010 | visitor.WalkStack(true); |
| 1011 | bool deoptimize = (visitor.caller != NULL) && |
| 1012 | (interpreter_stubs_installed_ || IsDeoptimized(visitor.caller)); |
| 1013 | if (deoptimize && kVerboseInstrumentation) { |
| 1014 | LOG(INFO) << "Deoptimizing into " << PrettyMethod(visitor.caller); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1015 | } |
| 1016 | if (deoptimize) { |
| 1017 | if (kVerboseInstrumentation) { |
| 1018 | LOG(INFO) << "Deoptimizing from " << PrettyMethod(method) |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1019 | << " result is " << std::hex << return_value.GetJ(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1020 | } |
| 1021 | self->SetDeoptimizationReturnValue(return_value); |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1022 | return GetTwoWordSuccessValue(*return_pc, |
| 1023 | reinterpret_cast<uintptr_t>(GetQuickDeoptimizationEntryPoint())); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1024 | } else { |
| 1025 | if (kVerboseInstrumentation) { |
Brian Carlstrom | 2d88862 | 2013-07-18 17:02:00 -0700 | [diff] [blame] | 1026 | LOG(INFO) << "Returning from " << PrettyMethod(method) |
| 1027 | << " to PC " << reinterpret_cast<void*>(*return_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1028 | } |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1029 | return GetTwoWordSuccessValue(0, *return_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1030 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1031 | } |
| 1032 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1033 | void Instrumentation::PopMethodForUnwind(Thread* self, bool is_deoptimization) const { |
| 1034 | // Do the pop. |
| 1035 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack(); |
| 1036 | CHECK_GT(stack->size(), 0U); |
| 1037 | InstrumentationStackFrame instrumentation_frame = stack->front(); |
| 1038 | // TODO: bring back CheckStackDepth(self, instrumentation_frame, 2); |
| 1039 | stack->pop_front(); |
| 1040 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1041 | mirror::ArtMethod* method = instrumentation_frame.method_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1042 | if (is_deoptimization) { |
| 1043 | if (kVerboseInstrumentation) { |
| 1044 | LOG(INFO) << "Popping for deoptimization " << PrettyMethod(method); |
| 1045 | } |
| 1046 | } else { |
| 1047 | if (kVerboseInstrumentation) { |
| 1048 | LOG(INFO) << "Popping for unwind " << PrettyMethod(method); |
| 1049 | } |
| 1050 | |
| 1051 | // Notify listeners of method unwind. |
| 1052 | // TODO: improve the dex pc information here, requires knowledge of current PC as opposed to |
| 1053 | // return_pc. |
| 1054 | uint32_t dex_pc = DexFile::kDexNoIndex; |
| 1055 | MethodUnwindEvent(self, instrumentation_frame.this_object_, method, dex_pc); |
| 1056 | } |
| 1057 | } |
| 1058 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 1059 | void Instrumentation::VisitRoots(RootCallback* callback, void* arg) { |
| 1060 | WriterMutexLock mu(Thread::Current(), deoptimized_methods_lock_); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 1061 | if (IsDeoptimizedMethodsEmpty()) { |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 1062 | return; |
| 1063 | } |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 1064 | for (auto pair : deoptimized_methods_) { |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 1065 | pair.second.VisitRoot(callback, arg, RootInfo(kRootVMInternal)); |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 1066 | } |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1069 | std::string InstrumentationStackFrame::Dump() const { |
| 1070 | std::ostringstream os; |
| 1071 | os << "Frame " << frame_id_ << " " << PrettyMethod(method_) << ":" |
| 1072 | << reinterpret_cast<void*>(return_pc_) << " this=" << reinterpret_cast<void*>(this_object_); |
| 1073 | return os.str(); |
| 1074 | } |
| 1075 | |
| 1076 | } // namespace instrumentation |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1077 | } // namespace art |