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