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 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 19 | #include <sstream> |
| 20 | |
Andreas Gampe | c7d878d | 2018-11-19 18:42:06 +0000 | [diff] [blame] | 21 | #include <android-base/logging.h> |
| 22 | |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 23 | #include "arch/context.h" |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 24 | #include "art_field-inl.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 25 | #include "art_method-inl.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 26 | #include "base/atomic.h" |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 27 | #include "base/callee_save_type.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 28 | #include "class_linker.h" |
| 29 | #include "debugger.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 30 | #include "dex/dex_file-inl.h" |
| 31 | #include "dex/dex_file_types.h" |
| 32 | #include "dex/dex_instruction-inl.h" |
Mathieu Chartier | d889178 | 2014-03-02 13:28:37 -0800 | [diff] [blame] | 33 | #include "entrypoints/quick/quick_alloc_entrypoints.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 34 | #include "entrypoints/quick/quick_entrypoints.h" |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 35 | #include "entrypoints/runtime_asm_entrypoints.h" |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 36 | #include "gc_root-inl.h" |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 37 | #include "interpreter/interpreter.h" |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 38 | #include "interpreter/interpreter_common.h" |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 39 | #include "jit/jit.h" |
| 40 | #include "jit/jit_code_cache.h" |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 41 | #include "jvalue-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 42 | #include "mirror/class-inl.h" |
| 43 | #include "mirror/dex_cache.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 44 | #include "mirror/object-inl.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 45 | #include "mirror/object_array-inl.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 46 | #include "nth_caller_visitor.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 47 | #include "oat_quick_method_header.h" |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 48 | #include "runtime-inl.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 49 | #include "thread.h" |
| 50 | #include "thread_list.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 51 | |
| 52 | namespace art { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 53 | namespace instrumentation { |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 54 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 55 | constexpr bool kVerboseInstrumentation = false; |
Sebastien Hertz | 5bfd5c9 | 2013-11-15 11:36:07 +0100 | [diff] [blame] | 56 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 57 | void InstrumentationListener::MethodExited(Thread* thread, |
| 58 | Handle<mirror::Object> this_object, |
| 59 | ArtMethod* method, |
| 60 | uint32_t dex_pc, |
| 61 | Handle<mirror::Object> return_value) { |
| 62 | DCHECK_EQ(method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetReturnTypePrimitive(), |
| 63 | Primitive::kPrimNot); |
| 64 | JValue v; |
| 65 | v.SetL(return_value.Get()); |
| 66 | MethodExited(thread, this_object, method, dex_pc, v); |
| 67 | } |
| 68 | |
| 69 | void InstrumentationListener::FieldWritten(Thread* thread, |
| 70 | Handle<mirror::Object> this_object, |
| 71 | ArtMethod* method, |
| 72 | uint32_t dex_pc, |
| 73 | ArtField* field, |
| 74 | Handle<mirror::Object> field_value) { |
| 75 | DCHECK(!field->IsPrimitiveType()); |
| 76 | JValue v; |
| 77 | v.SetL(field_value.Get()); |
| 78 | FieldWritten(thread, this_object, method, dex_pc, field, v); |
| 79 | } |
| 80 | |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 81 | // Instrumentation works on non-inlined frames by updating returned PCs |
| 82 | // of compiled frames. |
| 83 | static constexpr StackVisitor::StackWalkKind kInstrumentationStackWalk = |
| 84 | StackVisitor::StackWalkKind::kSkipInlinedFrames; |
| 85 | |
Mathieu Chartier | e0671ce | 2015-07-28 17:23:28 -0700 | [diff] [blame] | 86 | class InstallStubsClassVisitor : public ClassVisitor { |
| 87 | public: |
| 88 | explicit InstallStubsClassVisitor(Instrumentation* instrumentation) |
| 89 | : instrumentation_(instrumentation) {} |
| 90 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 91 | bool operator()(ObjPtr<mirror::Class> klass) override REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 92 | instrumentation_->InstallStubsForClass(klass.Ptr()); |
Mathieu Chartier | e0671ce | 2015-07-28 17:23:28 -0700 | [diff] [blame] | 93 | return true; // we visit all classes. |
| 94 | } |
| 95 | |
| 96 | private: |
| 97 | Instrumentation* const instrumentation_; |
| 98 | }; |
| 99 | |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 100 | InstrumentationStackPopper::InstrumentationStackPopper(Thread* self) |
| 101 | : self_(self), |
| 102 | instrumentation_(Runtime::Current()->GetInstrumentation()), |
| 103 | frames_to_remove_(0) {} |
| 104 | |
| 105 | InstrumentationStackPopper::~InstrumentationStackPopper() { |
| 106 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self_->GetInstrumentationStack(); |
| 107 | for (size_t i = 0; i < frames_to_remove_; i++) { |
| 108 | stack->pop_front(); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | bool InstrumentationStackPopper::PopFramesTo(uint32_t desired_pops, |
| 113 | MutableHandle<mirror::Throwable>& exception) { |
| 114 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self_->GetInstrumentationStack(); |
| 115 | DCHECK_LE(frames_to_remove_, desired_pops); |
| 116 | DCHECK_GE(stack->size(), desired_pops); |
| 117 | DCHECK(!self_->IsExceptionPending()); |
| 118 | if (!instrumentation_->HasMethodUnwindListeners()) { |
| 119 | frames_to_remove_ = desired_pops; |
| 120 | return true; |
| 121 | } |
| 122 | if (kVerboseInstrumentation) { |
| 123 | LOG(INFO) << "Popping frames for exception " << exception->Dump(); |
| 124 | } |
| 125 | // The instrumentation events expect the exception to be set. |
| 126 | self_->SetException(exception.Get()); |
| 127 | bool new_exception_thrown = false; |
| 128 | for (; frames_to_remove_ < desired_pops && !new_exception_thrown; frames_to_remove_++) { |
| 129 | InstrumentationStackFrame frame = stack->at(frames_to_remove_); |
| 130 | ArtMethod* method = frame.method_; |
| 131 | // Notify listeners of method unwind. |
| 132 | // TODO: improve the dex_pc information here. |
| 133 | uint32_t dex_pc = dex::kDexNoIndex; |
| 134 | if (kVerboseInstrumentation) { |
| 135 | LOG(INFO) << "Popping for unwind " << method->PrettyMethod(); |
| 136 | } |
| 137 | if (!method->IsRuntimeMethod() && !frame.interpreter_entry_) { |
| 138 | instrumentation_->MethodUnwindEvent(self_, frame.this_object_, method, dex_pc); |
| 139 | new_exception_thrown = self_->GetException() != exception.Get(); |
| 140 | } |
| 141 | } |
| 142 | exception.Assign(self_->GetException()); |
| 143 | self_->ClearException(); |
| 144 | if (kVerboseInstrumentation && new_exception_thrown) { |
| 145 | LOG(INFO) << "Failed to pop " << (desired_pops - frames_to_remove_) |
| 146 | << " frames due to new exception"; |
| 147 | } |
| 148 | return !new_exception_thrown; |
| 149 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 150 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 151 | Instrumentation::Instrumentation() |
Nicolas Geoffray | 5a23d2e | 2015-11-03 18:58:57 +0000 | [diff] [blame] | 152 | : instrumentation_stubs_installed_(false), |
| 153 | entry_exit_stubs_installed_(false), |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 154 | interpreter_stubs_installed_(false), |
Nicolas Geoffray | 5a23d2e | 2015-11-03 18:58:57 +0000 | [diff] [blame] | 155 | interpret_only_(false), |
| 156 | forced_interpret_only_(false), |
| 157 | have_method_entry_listeners_(false), |
| 158 | have_method_exit_listeners_(false), |
| 159 | have_method_unwind_listeners_(false), |
| 160 | have_dex_pc_listeners_(false), |
| 161 | have_field_read_listeners_(false), |
| 162 | have_field_write_listeners_(false), |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 163 | have_exception_thrown_listeners_(false), |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 164 | have_watched_frame_pop_listeners_(false), |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 165 | have_branch_listeners_(false), |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 166 | have_exception_handled_listeners_(false), |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame^] | 167 | deoptimized_methods_lock_(new ReaderWriterMutex("deoptimized methods lock", |
| 168 | kGenericBottomLock)), |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 169 | deoptimization_enabled_(false), |
| 170 | interpreter_handler_table_(kMainHandlerTable), |
Mathieu Chartier | 50e9331 | 2016-03-16 11:25:29 -0700 | [diff] [blame] | 171 | quick_alloc_entry_points_instrumentation_counter_(0), |
| 172 | alloc_entrypoints_instrumented_(false) { |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Sebastien Hertz | a10aa37 | 2015-01-21 17:30:58 +0100 | [diff] [blame] | 175 | void Instrumentation::InstallStubsForClass(mirror::Class* klass) { |
Vladimir Marko | 72ab684 | 2017-01-20 19:32:50 +0000 | [diff] [blame] | 176 | if (!klass->IsResolved()) { |
Sebastien Hertz | a8a697f | 2015-01-15 12:28:47 +0100 | [diff] [blame] | 177 | // We need the class to be resolved to install/uninstall stubs. Otherwise its methods |
| 178 | // could not be initialized or linked with regards to class inheritance. |
Vladimir Marko | 72ab684 | 2017-01-20 19:32:50 +0000 | [diff] [blame] | 179 | } else if (klass->IsErroneousResolved()) { |
| 180 | // We can't execute code in a erroneous class: do nothing. |
Sebastien Hertz | a8a697f | 2015-01-15 12:28:47 +0100 | [diff] [blame] | 181 | } else { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 182 | for (ArtMethod& method : klass->GetMethods(kRuntimePointerSize)) { |
Alex Light | 51a64d5 | 2015-12-17 13:55:59 -0800 | [diff] [blame] | 183 | InstallStubsForMethod(&method); |
Sebastien Hertz | a8a697f | 2015-01-15 12:28:47 +0100 | [diff] [blame] | 184 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 185 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 188 | static void UpdateEntrypoints(ArtMethod* method, const void* quick_code) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 189 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 190 | method->SetEntryPointFromQuickCompiledCode(quick_code); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Alex Light | 0fa1786 | 2017-10-24 13:43:05 -0700 | [diff] [blame] | 193 | bool Instrumentation::NeedDebugVersionFor(ArtMethod* method) const |
| 194 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Alex Light | f285863 | 2018-04-02 11:28:50 -0700 | [diff] [blame] | 195 | art::Runtime* runtime = Runtime::Current(); |
| 196 | // If anything says we need the debug version or we are debuggable we will need the debug version |
| 197 | // of the method. |
| 198 | return (runtime->GetRuntimeCallbacks()->MethodNeedsDebugVersion(method) || |
| 199 | runtime->IsJavaDebuggable()) && |
Mingyao Yang | 6ea1a0e | 2016-01-29 12:12:49 -0800 | [diff] [blame] | 200 | !method->IsNative() && |
Alex Light | f285863 | 2018-04-02 11:28:50 -0700 | [diff] [blame] | 201 | !method->IsProxyMethod(); |
Mingyao Yang | 6ea1a0e | 2016-01-29 12:12:49 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 204 | void Instrumentation::InstallStubsForMethod(ArtMethod* method) { |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 205 | if (!method->IsInvokable() || method->IsProxyMethod()) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 206 | // Do not change stubs for these methods. |
| 207 | return; |
| 208 | } |
Jeff Hao | 5680277 | 2014-08-19 10:17:36 -0700 | [diff] [blame] | 209 | // Don't stub Proxy.<init>. Note that the Proxy class itself is not a proxy class. |
Alex Light | 6cae5ea | 2018-06-07 17:07:02 -0700 | [diff] [blame] | 210 | // TODO We should remove the need for this since it means we cannot always correctly detect calls |
| 211 | // to Proxy.<init> |
| 212 | // Annoyingly this can be called before we have actually initialized WellKnownClasses so therefore |
| 213 | // we also need to check this based on the declaring-class descriptor. The check is valid because |
| 214 | // Proxy only has a single constructor. |
| 215 | ArtMethod* well_known_proxy_init = jni::DecodeArtMethod( |
| 216 | WellKnownClasses::java_lang_reflect_Proxy_init); |
| 217 | if ((LIKELY(well_known_proxy_init != nullptr) && UNLIKELY(method == well_known_proxy_init)) || |
| 218 | UNLIKELY(method->IsConstructor() && |
| 219 | method->GetDeclaringClass()->DescriptorEquals("Ljava/lang/reflect/Proxy;"))) { |
Jeff Hao | db8a664 | 2014-08-14 17:18:52 -0700 | [diff] [blame] | 220 | return; |
| 221 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 222 | const void* new_quick_code; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 223 | bool uninstall = !entry_exit_stubs_installed_ && !interpreter_stubs_installed_; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 224 | Runtime* const runtime = Runtime::Current(); |
| 225 | ClassLinker* const class_linker = runtime->GetClassLinker(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 226 | bool is_class_initialized = method->GetDeclaringClass()->IsInitialized(); |
| 227 | if (uninstall) { |
| 228 | if ((forced_interpret_only_ || IsDeoptimized(method)) && !method->IsNative()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 229 | new_quick_code = GetQuickToInterpreterBridge(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 230 | } else if (is_class_initialized || !method->IsStatic() || method->IsConstructor()) { |
Alex Light | 3e36a9c | 2018-06-19 09:45:05 -0700 | [diff] [blame] | 231 | new_quick_code = GetCodeForInvoke(method); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 232 | } else { |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 233 | new_quick_code = GetQuickResolutionStub(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 234 | } |
| 235 | } else { // !uninstall |
Sebastien Hertz | bae182c | 2013-12-17 10:42:03 +0100 | [diff] [blame] | 236 | if ((interpreter_stubs_installed_ || forced_interpret_only_ || IsDeoptimized(method)) && |
| 237 | !method->IsNative()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 238 | new_quick_code = GetQuickToInterpreterBridge(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 239 | } else { |
| 240 | // Do not overwrite resolution trampoline. When the trampoline initializes the method's |
| 241 | // class, all its static methods code will be set to the instrumentation entry point. |
| 242 | // For more details, see ClassLinker::FixupStaticTrampolines. |
| 243 | if (is_class_initialized || !method->IsStatic() || method->IsConstructor()) { |
Alex Light | 2d441b1 | 2018-06-08 15:33:21 -0700 | [diff] [blame] | 244 | if (entry_exit_stubs_installed_) { |
| 245 | // This needs to be checked first since the instrumentation entrypoint will be able to |
| 246 | // find the actual JIT compiled code that corresponds to this method. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 247 | new_quick_code = GetQuickInstrumentationEntryPoint(); |
Alex Light | 2d441b1 | 2018-06-08 15:33:21 -0700 | [diff] [blame] | 248 | } else if (NeedDebugVersionFor(method)) { |
| 249 | // It would be great to search the JIT for its implementation here but we cannot due to |
| 250 | // the locks we hold. Instead just set to the interpreter bridge and that code will search |
| 251 | // the JIT when it gets called and replace the entrypoint then. |
| 252 | new_quick_code = GetQuickToInterpreterBridge(); |
Nicolas Geoffray | a0619e2 | 2016-12-20 13:57:43 +0000 | [diff] [blame] | 253 | } else { |
Alex Light | fc49fec | 2018-01-16 22:28:36 +0000 | [diff] [blame] | 254 | new_quick_code = class_linker->GetQuickOatCodeFor(method); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 255 | } |
| 256 | } else { |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 257 | new_quick_code = GetQuickResolutionStub(); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | } |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 261 | UpdateEntrypoints(method, new_quick_code); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 264 | // Places the instrumentation exit pc as the return PC for every quick frame. This also allows |
| 265 | // deoptimization of quick frames to interpreter frames. |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 266 | // Since we may already have done this previously, we need to push new instrumentation frame before |
| 267 | // existing instrumentation frames. |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 268 | static void InstrumentationInstallStack(Thread* thread, void* arg) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 269 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 270 | struct InstallStackVisitor final : public StackVisitor { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 271 | InstallStackVisitor(Thread* thread_in, Context* context, uintptr_t instrumentation_exit_pc) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 272 | : StackVisitor(thread_in, context, kInstrumentationStackWalk), |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 273 | instrumentation_stack_(thread_in->GetInstrumentationStack()), |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 274 | instrumentation_exit_pc_(instrumentation_exit_pc), |
Alex Light | e927866 | 2018-03-08 16:55:58 -0800 | [diff] [blame] | 275 | reached_existing_instrumentation_frames_(false), instrumentation_stack_depth_(0), |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 276 | last_return_pc_(0) { |
| 277 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 278 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 279 | bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 280 | ArtMethod* m = GetMethod(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 281 | if (m == nullptr) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 282 | if (kVerboseInstrumentation) { |
| 283 | LOG(INFO) << " Skipping upcall. Frame " << GetFrameId(); |
| 284 | } |
| 285 | last_return_pc_ = 0; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 286 | return true; // Ignore upcalls. |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 287 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 288 | if (GetCurrentQuickFrame() == nullptr) { |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 289 | bool interpreter_frame = true; |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 290 | InstrumentationStackFrame instrumentation_frame(GetThisObject(), m, 0, GetFrameId(), |
| 291 | interpreter_frame); |
Jeff Hao | a15a81b | 2014-05-27 18:25:47 -0700 | [diff] [blame] | 292 | if (kVerboseInstrumentation) { |
| 293 | LOG(INFO) << "Pushing shadow frame " << instrumentation_frame.Dump(); |
| 294 | } |
| 295 | shadow_stack_.push_back(instrumentation_frame); |
| 296 | return true; // Continue. |
| 297 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 298 | uintptr_t return_pc = GetReturnPc(); |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 299 | if (kVerboseInstrumentation) { |
| 300 | LOG(INFO) << " Installing exit stub in " << DescribeLocation(); |
| 301 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 302 | if (return_pc == instrumentation_exit_pc_) { |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 303 | CHECK_LT(instrumentation_stack_depth_, instrumentation_stack_->size()); |
| 304 | |
| 305 | if (m->IsRuntimeMethod()) { |
| 306 | const InstrumentationStackFrame& frame = |
Vladimir Marko | 35d5b8a | 2018-07-03 09:18:32 +0100 | [diff] [blame] | 307 | (*instrumentation_stack_)[instrumentation_stack_depth_]; |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 308 | if (frame.interpreter_entry_) { |
| 309 | // This instrumentation frame is for an interpreter bridge and is |
| 310 | // pushed when executing the instrumented interpreter bridge. So method |
| 311 | // enter event must have been reported. However we need to push a DEX pc |
| 312 | // into the dex_pcs_ list to match size of instrumentation stack. |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 313 | uint32_t dex_pc = dex::kDexNoIndex; |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 314 | dex_pcs_.push_back(dex_pc); |
| 315 | last_return_pc_ = frame.return_pc_; |
| 316 | ++instrumentation_stack_depth_; |
| 317 | return true; |
| 318 | } |
| 319 | } |
| 320 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 321 | // We've reached a frame which has already been installed with instrumentation exit stub. |
Alex Light | 74c91c9 | 2018-03-08 14:01:44 -0800 | [diff] [blame] | 322 | // We should have already installed instrumentation or be interpreter on previous frames. |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 323 | reached_existing_instrumentation_frames_ = true; |
| 324 | |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 325 | const InstrumentationStackFrame& frame = |
Vladimir Marko | 35d5b8a | 2018-07-03 09:18:32 +0100 | [diff] [blame] | 326 | (*instrumentation_stack_)[instrumentation_stack_depth_]; |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 327 | CHECK_EQ(m, frame.method_) << "Expected " << ArtMethod::PrettyMethod(m) |
| 328 | << ", Found " << ArtMethod::PrettyMethod(frame.method_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 329 | return_pc = frame.return_pc_; |
| 330 | if (kVerboseInstrumentation) { |
| 331 | LOG(INFO) << "Ignoring already instrumented " << frame.Dump(); |
| 332 | } |
| 333 | } else { |
| 334 | CHECK_NE(return_pc, 0U); |
Alex Light | 74c91c9 | 2018-03-08 14:01:44 -0800 | [diff] [blame] | 335 | if (UNLIKELY(reached_existing_instrumentation_frames_ && !m->IsRuntimeMethod())) { |
| 336 | // We already saw an existing instrumentation frame so this should be a runtime-method |
| 337 | // inserted by the interpreter or runtime. |
Alex Light | e927866 | 2018-03-08 16:55:58 -0800 | [diff] [blame] | 338 | std::string thread_name; |
| 339 | GetThread()->GetThreadName(thread_name); |
| 340 | uint32_t dex_pc = dex::kDexNoIndex; |
| 341 | if (last_return_pc_ != 0 && |
| 342 | GetCurrentOatQuickMethodHeader() != nullptr) { |
| 343 | dex_pc = GetCurrentOatQuickMethodHeader()->ToDexPc(m, last_return_pc_); |
| 344 | } |
Alex Light | 74c91c9 | 2018-03-08 14:01:44 -0800 | [diff] [blame] | 345 | LOG(FATAL) << "While walking " << thread_name << " found unexpected non-runtime method" |
| 346 | << " without instrumentation exit return or interpreter frame." |
Alex Light | e927866 | 2018-03-08 16:55:58 -0800 | [diff] [blame] | 347 | << " method is " << GetMethod()->PrettyMethod() |
| 348 | << " return_pc is " << std::hex << return_pc |
| 349 | << " dex pc: " << dex_pc; |
| 350 | UNREACHABLE(); |
| 351 | } |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 352 | InstrumentationStackFrame instrumentation_frame( |
| 353 | m->IsRuntimeMethod() ? nullptr : GetThisObject(), |
| 354 | m, |
| 355 | return_pc, |
| 356 | GetFrameId(), // A runtime method still gets a frame id. |
| 357 | false); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 358 | if (kVerboseInstrumentation) { |
| 359 | LOG(INFO) << "Pushing frame " << instrumentation_frame.Dump(); |
| 360 | } |
| 361 | |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 362 | // Insert frame at the right position so we do not corrupt the instrumentation stack. |
| 363 | // Instrumentation stack frames are in descending frame id order. |
| 364 | auto it = instrumentation_stack_->begin(); |
| 365 | for (auto end = instrumentation_stack_->end(); it != end; ++it) { |
| 366 | const InstrumentationStackFrame& current = *it; |
| 367 | if (instrumentation_frame.frame_id_ >= current.frame_id_) { |
| 368 | break; |
| 369 | } |
| 370 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 371 | instrumentation_stack_->insert(it, instrumentation_frame); |
| 372 | SetReturnPc(instrumentation_exit_pc_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 373 | } |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 374 | uint32_t dex_pc = dex::kDexNoIndex; |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 375 | if (last_return_pc_ != 0 && |
| 376 | GetCurrentOatQuickMethodHeader() != nullptr) { |
| 377 | dex_pc = GetCurrentOatQuickMethodHeader()->ToDexPc(m, last_return_pc_); |
| 378 | } |
| 379 | dex_pcs_.push_back(dex_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 380 | last_return_pc_ = return_pc; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 381 | ++instrumentation_stack_depth_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 382 | return true; // Continue. |
| 383 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 384 | std::deque<InstrumentationStackFrame>* const instrumentation_stack_; |
Jeff Hao | a15a81b | 2014-05-27 18:25:47 -0700 | [diff] [blame] | 385 | std::vector<InstrumentationStackFrame> shadow_stack_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 386 | std::vector<uint32_t> dex_pcs_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 387 | const uintptr_t instrumentation_exit_pc_; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 388 | bool reached_existing_instrumentation_frames_; |
| 389 | size_t instrumentation_stack_depth_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 390 | uintptr_t last_return_pc_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 391 | }; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 392 | if (kVerboseInstrumentation) { |
| 393 | std::string thread_name; |
| 394 | thread->GetThreadName(thread_name); |
| 395 | LOG(INFO) << "Installing exit stubs in " << thread_name; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 396 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 397 | |
| 398 | Instrumentation* instrumentation = reinterpret_cast<Instrumentation*>(arg); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 399 | std::unique_ptr<Context> context(Context::Create()); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 400 | uintptr_t instrumentation_exit_pc = reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()); |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 401 | InstallStackVisitor visitor(thread, context.get(), instrumentation_exit_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 402 | visitor.WalkStack(true); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 403 | CHECK_EQ(visitor.dex_pcs_.size(), thread->GetInstrumentationStack()->size()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 404 | |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 405 | if (instrumentation->ShouldNotifyMethodEnterExitEvents()) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 406 | // Create method enter events for all methods currently on the thread's stack. We only do this |
| 407 | // if no debugger is attached to prevent from posting events twice. |
Jeff Hao | a15a81b | 2014-05-27 18:25:47 -0700 | [diff] [blame] | 408 | auto ssi = visitor.shadow_stack_.rbegin(); |
| 409 | for (auto isi = thread->GetInstrumentationStack()->rbegin(), |
| 410 | end = thread->GetInstrumentationStack()->rend(); isi != end; ++isi) { |
| 411 | while (ssi != visitor.shadow_stack_.rend() && (*ssi).frame_id_ < (*isi).frame_id_) { |
| 412 | instrumentation->MethodEnterEvent(thread, (*ssi).this_object_, (*ssi).method_, 0); |
| 413 | ++ssi; |
| 414 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 415 | uint32_t dex_pc = visitor.dex_pcs_.back(); |
| 416 | visitor.dex_pcs_.pop_back(); |
Alex Light | dc5423f | 2018-06-08 10:43:38 -0700 | [diff] [blame] | 417 | if (!isi->interpreter_entry_ && !isi->method_->IsRuntimeMethod()) { |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 418 | instrumentation->MethodEnterEvent(thread, (*isi).this_object_, (*isi).method_, dex_pc); |
| 419 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 420 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 421 | } |
| 422 | thread->VerifyStack(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 423 | } |
| 424 | |
Mingyao Yang | 99170c6 | 2015-07-06 11:10:37 -0700 | [diff] [blame] | 425 | void Instrumentation::InstrumentThreadStack(Thread* thread) { |
| 426 | instrumentation_stubs_installed_ = true; |
| 427 | InstrumentationInstallStack(thread, this); |
| 428 | } |
| 429 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 430 | // Removes the instrumentation exit pc as the return PC for every quick frame. |
| 431 | static void InstrumentationRestoreStack(Thread* thread, void* arg) |
Nicolas Geoffray | 5a23d2e | 2015-11-03 18:58:57 +0000 | [diff] [blame] | 432 | REQUIRES(Locks::mutator_lock_) { |
| 433 | Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current()); |
| 434 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 435 | struct RestoreStackVisitor final : public StackVisitor { |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 436 | RestoreStackVisitor(Thread* thread_in, uintptr_t instrumentation_exit_pc, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 437 | Instrumentation* instrumentation) |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 438 | : StackVisitor(thread_in, nullptr, kInstrumentationStackWalk), |
| 439 | thread_(thread_in), |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 440 | instrumentation_exit_pc_(instrumentation_exit_pc), |
| 441 | instrumentation_(instrumentation), |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 442 | instrumentation_stack_(thread_in->GetInstrumentationStack()), |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 443 | frames_removed_(0) {} |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 444 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 445 | bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 446 | if (instrumentation_stack_->size() == 0) { |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 447 | return false; // Stop. |
| 448 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 449 | ArtMethod* m = GetMethod(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 450 | if (GetCurrentQuickFrame() == nullptr) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 451 | if (kVerboseInstrumentation) { |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 452 | LOG(INFO) << " Ignoring a shadow frame. Frame " << GetFrameId() |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 453 | << " Method=" << ArtMethod::PrettyMethod(m); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 454 | } |
| 455 | return true; // Ignore shadow frames. |
| 456 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 457 | if (m == nullptr) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 458 | if (kVerboseInstrumentation) { |
| 459 | LOG(INFO) << " Skipping upcall. Frame " << GetFrameId(); |
| 460 | } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 461 | return true; // Ignore upcalls. |
| 462 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 463 | bool removed_stub = false; |
| 464 | // TODO: make this search more efficient? |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 465 | const size_t frameId = GetFrameId(); |
| 466 | for (const InstrumentationStackFrame& instrumentation_frame : *instrumentation_stack_) { |
| 467 | if (instrumentation_frame.frame_id_ == frameId) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 468 | if (kVerboseInstrumentation) { |
| 469 | LOG(INFO) << " Removing exit stub in " << DescribeLocation(); |
| 470 | } |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 471 | if (instrumentation_frame.interpreter_entry_) { |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 472 | CHECK(m == Runtime::Current()->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs)); |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 473 | } else { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 474 | CHECK(m == instrumentation_frame.method_) << ArtMethod::PrettyMethod(m); |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 475 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 476 | SetReturnPc(instrumentation_frame.return_pc_); |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 477 | if (instrumentation_->ShouldNotifyMethodEnterExitEvents() && |
| 478 | !m->IsRuntimeMethod()) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 479 | // Create the method exit events. As the methods didn't really exit the result is 0. |
| 480 | // We only do this if no debugger is attached to prevent from posting events twice. |
| 481 | instrumentation_->MethodExitEvent(thread_, instrumentation_frame.this_object_, m, |
| 482 | GetDexPc(), JValue()); |
| 483 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 484 | frames_removed_++; |
| 485 | removed_stub = true; |
| 486 | break; |
| 487 | } |
| 488 | } |
| 489 | if (!removed_stub) { |
| 490 | if (kVerboseInstrumentation) { |
| 491 | LOG(INFO) << " No exit stub in " << DescribeLocation(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 492 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 493 | } |
| 494 | return true; // Continue. |
| 495 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 496 | Thread* const thread_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 497 | const uintptr_t instrumentation_exit_pc_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 498 | Instrumentation* const instrumentation_; |
| 499 | std::deque<instrumentation::InstrumentationStackFrame>* const instrumentation_stack_; |
| 500 | size_t frames_removed_; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 501 | }; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 502 | if (kVerboseInstrumentation) { |
| 503 | std::string thread_name; |
| 504 | thread->GetThreadName(thread_name); |
| 505 | LOG(INFO) << "Removing exit stubs in " << thread_name; |
| 506 | } |
| 507 | std::deque<instrumentation::InstrumentationStackFrame>* stack = thread->GetInstrumentationStack(); |
| 508 | if (stack->size() > 0) { |
| 509 | Instrumentation* instrumentation = reinterpret_cast<Instrumentation*>(arg); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 510 | uintptr_t instrumentation_exit_pc = |
| 511 | reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 512 | RestoreStackVisitor visitor(thread, instrumentation_exit_pc, instrumentation); |
| 513 | visitor.WalkStack(true); |
| 514 | CHECK_EQ(visitor.frames_removed_, stack->size()); |
| 515 | while (stack->size() > 0) { |
| 516 | stack->pop_front(); |
| 517 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 521 | static bool HasEvent(Instrumentation::InstrumentationEvent expected, uint32_t events) { |
| 522 | return (events & expected) != 0; |
| 523 | } |
| 524 | |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 525 | static void PotentiallyAddListenerTo(Instrumentation::InstrumentationEvent event, |
| 526 | uint32_t events, |
| 527 | std::list<InstrumentationListener*>& list, |
| 528 | InstrumentationListener* listener, |
| 529 | bool* has_listener) |
| 530 | REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::classlinker_classes_lock_) { |
| 531 | Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current()); |
| 532 | if (!HasEvent(event, events)) { |
| 533 | return; |
| 534 | } |
| 535 | // If there is a free slot in the list, we insert the listener in that slot. |
| 536 | // Otherwise we add it to the end of the list. |
| 537 | auto it = std::find(list.begin(), list.end(), nullptr); |
| 538 | if (it != list.end()) { |
| 539 | *it = listener; |
| 540 | } else { |
| 541 | list.push_back(listener); |
| 542 | } |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 543 | Runtime::DoAndMaybeSwitchInterpreter([=](){ *has_listener = true; }); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 546 | void Instrumentation::AddListener(InstrumentationListener* listener, uint32_t events) { |
| 547 | Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current()); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 548 | PotentiallyAddListenerTo(kMethodEntered, |
| 549 | events, |
| 550 | method_entry_listeners_, |
| 551 | listener, |
| 552 | &have_method_entry_listeners_); |
| 553 | PotentiallyAddListenerTo(kMethodExited, |
| 554 | events, |
| 555 | method_exit_listeners_, |
| 556 | listener, |
| 557 | &have_method_exit_listeners_); |
| 558 | PotentiallyAddListenerTo(kMethodUnwind, |
| 559 | events, |
| 560 | method_unwind_listeners_, |
| 561 | listener, |
| 562 | &have_method_unwind_listeners_); |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 563 | PotentiallyAddListenerTo(kBranch, |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 564 | events, |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 565 | branch_listeners_, |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 566 | listener, |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 567 | &have_branch_listeners_); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 568 | PotentiallyAddListenerTo(kDexPcMoved, |
| 569 | events, |
| 570 | dex_pc_listeners_, |
| 571 | listener, |
| 572 | &have_dex_pc_listeners_); |
| 573 | PotentiallyAddListenerTo(kFieldRead, |
| 574 | events, |
| 575 | field_read_listeners_, |
| 576 | listener, |
| 577 | &have_field_read_listeners_); |
| 578 | PotentiallyAddListenerTo(kFieldWritten, |
| 579 | events, |
| 580 | field_write_listeners_, |
| 581 | listener, |
| 582 | &have_field_write_listeners_); |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 583 | PotentiallyAddListenerTo(kExceptionThrown, |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 584 | events, |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 585 | exception_thrown_listeners_, |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 586 | listener, |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 587 | &have_exception_thrown_listeners_); |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 588 | PotentiallyAddListenerTo(kWatchedFramePop, |
| 589 | events, |
| 590 | watched_frame_pop_listeners_, |
| 591 | listener, |
| 592 | &have_watched_frame_pop_listeners_); |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 593 | PotentiallyAddListenerTo(kExceptionHandled, |
| 594 | events, |
| 595 | exception_handled_listeners_, |
| 596 | listener, |
| 597 | &have_exception_handled_listeners_); |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 598 | UpdateInterpreterHandlerTable(); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 601 | static void PotentiallyRemoveListenerFrom(Instrumentation::InstrumentationEvent event, |
| 602 | uint32_t events, |
| 603 | std::list<InstrumentationListener*>& list, |
| 604 | InstrumentationListener* listener, |
| 605 | bool* has_listener) |
| 606 | REQUIRES(Locks::mutator_lock_, !Locks::thread_list_lock_, !Locks::classlinker_classes_lock_) { |
| 607 | Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current()); |
| 608 | if (!HasEvent(event, events)) { |
| 609 | return; |
| 610 | } |
| 611 | auto it = std::find(list.begin(), list.end(), listener); |
| 612 | if (it != list.end()) { |
| 613 | // Just update the entry, do not remove from the list. Removing entries in the list |
| 614 | // is unsafe when mutators are iterating over it. |
| 615 | *it = nullptr; |
| 616 | } |
| 617 | |
| 618 | // Check if the list contains any non-null listener, and update 'has_listener'. |
| 619 | for (InstrumentationListener* l : list) { |
| 620 | if (l != nullptr) { |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 621 | Runtime::DoAndMaybeSwitchInterpreter([=](){ *has_listener = true; }); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 622 | return; |
| 623 | } |
| 624 | } |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 625 | Runtime::DoAndMaybeSwitchInterpreter([=](){ *has_listener = false; }); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 628 | void Instrumentation::RemoveListener(InstrumentationListener* listener, uint32_t events) { |
| 629 | Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current()); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 630 | PotentiallyRemoveListenerFrom(kMethodEntered, |
| 631 | events, |
| 632 | method_entry_listeners_, |
| 633 | listener, |
| 634 | &have_method_entry_listeners_); |
| 635 | PotentiallyRemoveListenerFrom(kMethodExited, |
| 636 | events, |
| 637 | method_exit_listeners_, |
| 638 | listener, |
| 639 | &have_method_exit_listeners_); |
| 640 | PotentiallyRemoveListenerFrom(kMethodUnwind, |
| 641 | events, |
| 642 | method_unwind_listeners_, |
| 643 | listener, |
| 644 | &have_method_unwind_listeners_); |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 645 | PotentiallyRemoveListenerFrom(kBranch, |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 646 | events, |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 647 | branch_listeners_, |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 648 | listener, |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 649 | &have_branch_listeners_); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 650 | PotentiallyRemoveListenerFrom(kDexPcMoved, |
| 651 | events, |
| 652 | dex_pc_listeners_, |
| 653 | listener, |
| 654 | &have_dex_pc_listeners_); |
| 655 | PotentiallyRemoveListenerFrom(kFieldRead, |
| 656 | events, |
| 657 | field_read_listeners_, |
| 658 | listener, |
| 659 | &have_field_read_listeners_); |
| 660 | PotentiallyRemoveListenerFrom(kFieldWritten, |
| 661 | events, |
| 662 | field_write_listeners_, |
| 663 | listener, |
| 664 | &have_field_write_listeners_); |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 665 | PotentiallyRemoveListenerFrom(kExceptionThrown, |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 666 | events, |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 667 | exception_thrown_listeners_, |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 668 | listener, |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 669 | &have_exception_thrown_listeners_); |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 670 | PotentiallyRemoveListenerFrom(kWatchedFramePop, |
| 671 | events, |
| 672 | watched_frame_pop_listeners_, |
| 673 | listener, |
| 674 | &have_watched_frame_pop_listeners_); |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 675 | PotentiallyRemoveListenerFrom(kExceptionHandled, |
| 676 | events, |
| 677 | exception_handled_listeners_, |
| 678 | listener, |
| 679 | &have_exception_handled_listeners_); |
Sebastien Hertz | ee1997a | 2013-09-19 14:47:09 +0200 | [diff] [blame] | 680 | UpdateInterpreterHandlerTable(); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 681 | } |
| 682 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 683 | Instrumentation::InstrumentationLevel Instrumentation::GetCurrentInstrumentationLevel() const { |
Alex Light | 4ba388a | 2017-01-27 10:26:49 -0800 | [diff] [blame] | 684 | if (interpreter_stubs_installed_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 685 | return InstrumentationLevel::kInstrumentWithInterpreter; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 686 | } else if (entry_exit_stubs_installed_) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 687 | return InstrumentationLevel::kInstrumentWithInstrumentationStubs; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 688 | } else { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 689 | return InstrumentationLevel::kInstrumentNothing; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 690 | } |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 691 | } |
| 692 | |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 693 | bool Instrumentation::RequiresInstrumentationInstallation(InstrumentationLevel new_level) const { |
Alex Light | 4ba388a | 2017-01-27 10:26:49 -0800 | [diff] [blame] | 694 | // We need to reinstall instrumentation if we go to a different level. |
| 695 | return GetCurrentInstrumentationLevel() != new_level; |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 696 | } |
| 697 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 698 | void Instrumentation::ConfigureStubs(const char* key, InstrumentationLevel desired_level) { |
| 699 | // Store the instrumentation level for this key or remove it. |
| 700 | if (desired_level == InstrumentationLevel::kInstrumentNothing) { |
| 701 | // The client no longer needs instrumentation. |
| 702 | requested_instrumentation_levels_.erase(key); |
| 703 | } else { |
| 704 | // The client needs instrumentation. |
| 705 | requested_instrumentation_levels_.Overwrite(key, desired_level); |
| 706 | } |
| 707 | |
| 708 | // Look for the highest required instrumentation level. |
| 709 | InstrumentationLevel requested_level = InstrumentationLevel::kInstrumentNothing; |
| 710 | for (const auto& v : requested_instrumentation_levels_) { |
| 711 | requested_level = std::max(requested_level, v.second); |
| 712 | } |
| 713 | |
| 714 | interpret_only_ = (requested_level == InstrumentationLevel::kInstrumentWithInterpreter) || |
| 715 | forced_interpret_only_; |
| 716 | |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 717 | if (!RequiresInstrumentationInstallation(requested_level)) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 718 | // We're already set. |
| 719 | return; |
| 720 | } |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 721 | Thread* const self = Thread::Current(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 722 | Runtime* runtime = Runtime::Current(); |
Sebastien Hertz | a8a697f | 2015-01-15 12:28:47 +0100 | [diff] [blame] | 723 | Locks::mutator_lock_->AssertExclusiveHeld(self); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 724 | Locks::thread_list_lock_->AssertNotHeld(self); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 725 | if (requested_level > InstrumentationLevel::kInstrumentNothing) { |
Alex Light | 4ba388a | 2017-01-27 10:26:49 -0800 | [diff] [blame] | 726 | if (requested_level == InstrumentationLevel::kInstrumentWithInterpreter) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 727 | interpreter_stubs_installed_ = true; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 728 | entry_exit_stubs_installed_ = true; |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 729 | } else { |
| 730 | CHECK_EQ(requested_level, InstrumentationLevel::kInstrumentWithInstrumentationStubs); |
| 731 | entry_exit_stubs_installed_ = true; |
| 732 | interpreter_stubs_installed_ = false; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 733 | } |
Mathieu Chartier | e0671ce | 2015-07-28 17:23:28 -0700 | [diff] [blame] | 734 | InstallStubsClassVisitor visitor(this); |
| 735 | runtime->GetClassLinker()->VisitClasses(&visitor); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 736 | instrumentation_stubs_installed_ = true; |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 737 | MutexLock mu(self, *Locks::thread_list_lock_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 738 | runtime->GetThreadList()->ForEach(InstrumentationInstallStack, this); |
| 739 | } else { |
| 740 | interpreter_stubs_installed_ = false; |
| 741 | entry_exit_stubs_installed_ = false; |
Mathieu Chartier | e0671ce | 2015-07-28 17:23:28 -0700 | [diff] [blame] | 742 | InstallStubsClassVisitor visitor(this); |
| 743 | runtime->GetClassLinker()->VisitClasses(&visitor); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 744 | // Restore stack only if there is no method currently deoptimized. |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 745 | bool empty; |
| 746 | { |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame^] | 747 | ReaderMutexLock mu(self, *GetDeoptimizedMethodsLock()); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 748 | empty = IsDeoptimizedMethodsEmpty(); // Avoid lock violation. |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 749 | } |
| 750 | if (empty) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 751 | MutexLock mu(self, *Locks::thread_list_lock_); |
| 752 | Runtime::Current()->GetThreadList()->ForEach(InstrumentationRestoreStack, this); |
Nicolas Geoffray | 5a23d2e | 2015-11-03 18:58:57 +0000 | [diff] [blame] | 753 | // Only do this after restoring, as walking the stack when restoring will see |
| 754 | // the instrumentation exit pc. |
| 755 | instrumentation_stubs_installed_ = false; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 756 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 757 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 760 | static void ResetQuickAllocEntryPointsForThread(Thread* thread, void* arg ATTRIBUTE_UNUSED) { |
Mathieu Chartier | 5ace201 | 2016-11-30 10:15:41 -0800 | [diff] [blame] | 761 | thread->ResetQuickAllocEntryPointsForThread(kUseReadBarrier && thread->GetIsGcMarking()); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 762 | } |
| 763 | |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 764 | void Instrumentation::SetEntrypointsInstrumented(bool instrumented) { |
| 765 | Thread* self = Thread::Current(); |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 766 | Runtime* runtime = Runtime::Current(); |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 767 | Locks::mutator_lock_->AssertNotHeld(self); |
| 768 | Locks::instrument_entrypoints_lock_->AssertHeld(self); |
| 769 | if (runtime->IsStarted()) { |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 770 | ScopedSuspendAll ssa(__FUNCTION__); |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 771 | MutexLock mu(self, *Locks::runtime_shutdown_lock_); |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 772 | SetQuickAllocEntryPointsInstrumented(instrumented); |
| 773 | ResetQuickAllocEntryPoints(); |
Mathieu Chartier | 50e9331 | 2016-03-16 11:25:29 -0700 | [diff] [blame] | 774 | alloc_entrypoints_instrumented_ = instrumented; |
Mathieu Chartier | 4f55e22 | 2015-09-04 13:26:21 -0700 | [diff] [blame] | 775 | } else { |
| 776 | MutexLock mu(self, *Locks::runtime_shutdown_lock_); |
| 777 | SetQuickAllocEntryPointsInstrumented(instrumented); |
Andreas Gampe | 157c77e | 2016-10-17 17:44:41 -0700 | [diff] [blame] | 778 | |
| 779 | // Note: ResetQuickAllocEntryPoints only works when the runtime is started. Manually run the |
| 780 | // update for just this thread. |
Andreas Gampe | 162ae50 | 2016-10-18 10:03:42 -0700 | [diff] [blame] | 781 | // Note: self may be null. One of those paths is setting instrumentation in the Heap |
| 782 | // constructor for gcstress mode. |
| 783 | if (self != nullptr) { |
| 784 | ResetQuickAllocEntryPointsForThread(self, nullptr); |
| 785 | } |
Andreas Gampe | 157c77e | 2016-10-17 17:44:41 -0700 | [diff] [blame] | 786 | |
Mathieu Chartier | 50e9331 | 2016-03-16 11:25:29 -0700 | [diff] [blame] | 787 | alloc_entrypoints_instrumented_ = instrumented; |
Mathieu Chartier | 661974a | 2014-01-09 11:23:53 -0800 | [diff] [blame] | 788 | } |
| 789 | } |
| 790 | |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 791 | void Instrumentation::InstrumentQuickAllocEntryPoints() { |
| 792 | MutexLock mu(Thread::Current(), *Locks::instrument_entrypoints_lock_); |
| 793 | InstrumentQuickAllocEntryPointsLocked(); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 796 | void Instrumentation::UninstrumentQuickAllocEntryPoints() { |
| 797 | MutexLock mu(Thread::Current(), *Locks::instrument_entrypoints_lock_); |
| 798 | UninstrumentQuickAllocEntryPointsLocked(); |
| 799 | } |
| 800 | |
| 801 | void Instrumentation::InstrumentQuickAllocEntryPointsLocked() { |
| 802 | Locks::instrument_entrypoints_lock_->AssertHeld(Thread::Current()); |
| 803 | if (quick_alloc_entry_points_instrumentation_counter_ == 0) { |
| 804 | SetEntrypointsInstrumented(true); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 805 | } |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 806 | ++quick_alloc_entry_points_instrumentation_counter_; |
Mathieu Chartier | 9ef78b5 | 2014-09-25 17:03:12 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | void Instrumentation::UninstrumentQuickAllocEntryPointsLocked() { |
| 810 | Locks::instrument_entrypoints_lock_->AssertHeld(Thread::Current()); |
| 811 | CHECK_GT(quick_alloc_entry_points_instrumentation_counter_, 0U); |
| 812 | --quick_alloc_entry_points_instrumentation_counter_; |
| 813 | if (quick_alloc_entry_points_instrumentation_counter_ == 0) { |
| 814 | SetEntrypointsInstrumented(false); |
| 815 | } |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | void Instrumentation::ResetQuickAllocEntryPoints() { |
| 819 | Runtime* runtime = Runtime::Current(); |
| 820 | if (runtime->IsStarted()) { |
Mathieu Chartier | e6da9af | 2013-12-16 11:54:42 -0800 | [diff] [blame] | 821 | MutexLock mu(Thread::Current(), *Locks::thread_list_lock_); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 822 | runtime->GetThreadList()->ForEach(ResetQuickAllocEntryPointsForThread, nullptr); |
Ian Rogers | fa82427 | 2013-11-05 16:12:57 -0800 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | |
Mingyao Yang | 3fd448a | 2016-05-10 14:30:41 -0700 | [diff] [blame] | 826 | void Instrumentation::UpdateMethodsCodeImpl(ArtMethod* method, const void* quick_code) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 827 | const void* new_quick_code; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 828 | if (LIKELY(!instrumentation_stubs_installed_)) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 829 | new_quick_code = quick_code; |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 830 | } else { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 831 | if ((interpreter_stubs_installed_ || IsDeoptimized(method)) && !method->IsNative()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 832 | new_quick_code = GetQuickToInterpreterBridge(); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 833 | } else { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 834 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 835 | if (class_linker->IsQuickResolutionStub(quick_code) || |
| 836 | class_linker->IsQuickToInterpreterBridge(quick_code)) { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 837 | new_quick_code = quick_code; |
Alex Light | 6cae5ea | 2018-06-07 17:07:02 -0700 | [diff] [blame] | 838 | } else if (entry_exit_stubs_installed_ && |
| 839 | // We need to make sure not to replace anything that InstallStubsForMethod |
| 840 | // wouldn't. Specifically we cannot stub out Proxy.<init> since subtypes copy the |
| 841 | // implementation directly and this will confuse the instrumentation trampolines. |
| 842 | // TODO We should remove the need for this since it makes it impossible to profile |
| 843 | // Proxy.<init> correctly in all cases. |
| 844 | method != jni::DecodeArtMethod(WellKnownClasses::java_lang_reflect_Proxy_init)) { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 845 | new_quick_code = GetQuickInstrumentationEntryPoint(); |
Alex Light | 2d441b1 | 2018-06-08 15:33:21 -0700 | [diff] [blame] | 846 | if (!method->IsNative() && Runtime::Current()->GetJit() != nullptr) { |
| 847 | // Native methods use trampoline entrypoints during interpreter tracing. |
| 848 | DCHECK(!Runtime::Current()->GetJit()->GetCodeCache()->GetGarbageCollectCode()); |
| 849 | ProfilingInfo* profiling_info = method->GetProfilingInfo(kRuntimePointerSize); |
| 850 | // Tracing will look at the saved entry point in the profiling info to know the actual |
| 851 | // entrypoint, so we store it here. |
| 852 | if (profiling_info != nullptr) { |
| 853 | profiling_info->SetSavedEntryPoint(quick_code); |
| 854 | } |
| 855 | } |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 856 | } else { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 857 | new_quick_code = quick_code; |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 858 | } |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 859 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 860 | } |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 861 | UpdateEntrypoints(method, new_quick_code); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 862 | } |
| 863 | |
Nicolas Geoffray | a6e0e7d | 2018-01-26 13:16:50 +0000 | [diff] [blame] | 864 | void Instrumentation::UpdateNativeMethodsCodeToJitCode(ArtMethod* method, const void* quick_code) { |
| 865 | // We don't do any read barrier on `method`'s declaring class in this code, as the JIT might |
| 866 | // enter here on a soon-to-be deleted ArtMethod. Updating the entrypoint is OK though, as |
| 867 | // the ArtMethod is still in memory. |
| 868 | const void* new_quick_code = quick_code; |
| 869 | if (UNLIKELY(instrumentation_stubs_installed_) && entry_exit_stubs_installed_) { |
| 870 | new_quick_code = GetQuickInstrumentationEntryPoint(); |
| 871 | } |
| 872 | UpdateEntrypoints(method, new_quick_code); |
| 873 | } |
| 874 | |
Mingyao Yang | 3fd448a | 2016-05-10 14:30:41 -0700 | [diff] [blame] | 875 | void Instrumentation::UpdateMethodsCode(ArtMethod* method, const void* quick_code) { |
| 876 | DCHECK(method->GetDeclaringClass()->IsResolved()); |
| 877 | UpdateMethodsCodeImpl(method, quick_code); |
| 878 | } |
| 879 | |
Alex Light | 0a5ec3d | 2017-07-25 16:50:26 -0700 | [diff] [blame] | 880 | void Instrumentation::UpdateMethodsCodeToInterpreterEntryPoint(ArtMethod* method) { |
| 881 | UpdateMethodsCodeImpl(method, GetQuickToInterpreterBridge()); |
| 882 | } |
| 883 | |
Nicolas Geoffray | a0619e2 | 2016-12-20 13:57:43 +0000 | [diff] [blame] | 884 | void Instrumentation::UpdateMethodsCodeForJavaDebuggable(ArtMethod* method, |
| 885 | const void* quick_code) { |
| 886 | // When the runtime is set to Java debuggable, we may update the entry points of |
| 887 | // all methods of a class to the interpreter bridge. A method's declaring class |
| 888 | // might not be in resolved state yet in that case, so we bypass the DCHECK in |
| 889 | // UpdateMethodsCode. |
Mingyao Yang | 3fd448a | 2016-05-10 14:30:41 -0700 | [diff] [blame] | 890 | UpdateMethodsCodeImpl(method, quick_code); |
| 891 | } |
| 892 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 893 | bool Instrumentation::AddDeoptimizedMethod(ArtMethod* method) { |
| 894 | if (IsDeoptimizedMethod(method)) { |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 895 | // Already in the map. Return. |
| 896 | return false; |
| 897 | } |
| 898 | // Not found. Add it. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 899 | deoptimized_methods_.insert(method); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 900 | return true; |
| 901 | } |
| 902 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 903 | bool Instrumentation::IsDeoptimizedMethod(ArtMethod* method) { |
| 904 | return deoptimized_methods_.find(method) != deoptimized_methods_.end(); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 907 | ArtMethod* Instrumentation::BeginDeoptimizedMethod() { |
| 908 | if (deoptimized_methods_.empty()) { |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 909 | // Empty. |
| 910 | return nullptr; |
| 911 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 912 | return *deoptimized_methods_.begin(); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 915 | bool Instrumentation::RemoveDeoptimizedMethod(ArtMethod* method) { |
| 916 | auto it = deoptimized_methods_.find(method); |
| 917 | if (it == deoptimized_methods_.end()) { |
| 918 | return false; |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 919 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 920 | deoptimized_methods_.erase(it); |
| 921 | return true; |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | bool Instrumentation::IsDeoptimizedMethodsEmpty() const { |
| 925 | return deoptimized_methods_.empty(); |
| 926 | } |
| 927 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 928 | void Instrumentation::Deoptimize(ArtMethod* method) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 929 | CHECK(!method->IsNative()); |
| 930 | CHECK(!method->IsProxyMethod()); |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 931 | CHECK(method->IsInvokable()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 932 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 933 | Thread* self = Thread::Current(); |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 934 | { |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame^] | 935 | WriterMutexLock mu(self, *GetDeoptimizedMethodsLock()); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 936 | bool has_not_been_deoptimized = AddDeoptimizedMethod(method); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 937 | CHECK(has_not_been_deoptimized) << "Method " << ArtMethod::PrettyMethod(method) |
Daniel Mihalyi | ca1d06c | 2014-08-18 18:45:31 +0200 | [diff] [blame] | 938 | << " is already deoptimized"; |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 939 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 940 | if (!interpreter_stubs_installed_) { |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 941 | UpdateEntrypoints(method, GetQuickInstrumentationEntryPoint()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 942 | |
| 943 | // Install instrumentation exit stub and instrumentation frames. We may already have installed |
| 944 | // these previously so it will only cover the newly created frames. |
| 945 | instrumentation_stubs_installed_ = true; |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 946 | MutexLock mu(self, *Locks::thread_list_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 947 | Runtime::Current()->GetThreadList()->ForEach(InstrumentationInstallStack, this); |
| 948 | } |
| 949 | } |
| 950 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 951 | void Instrumentation::Undeoptimize(ArtMethod* method) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 952 | CHECK(!method->IsNative()); |
| 953 | CHECK(!method->IsProxyMethod()); |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 954 | CHECK(method->IsInvokable()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 955 | |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 956 | Thread* self = Thread::Current(); |
| 957 | bool empty; |
| 958 | { |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame^] | 959 | WriterMutexLock mu(self, *GetDeoptimizedMethodsLock()); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 960 | bool found_and_erased = RemoveDeoptimizedMethod(method); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 961 | CHECK(found_and_erased) << "Method " << ArtMethod::PrettyMethod(method) |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 962 | << " is not deoptimized"; |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 963 | empty = IsDeoptimizedMethodsEmpty(); |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 964 | } |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 965 | |
| 966 | // Restore code and possibly stack only if we did not deoptimize everything. |
| 967 | if (!interpreter_stubs_installed_) { |
| 968 | // Restore its code or resolution trampoline. |
| 969 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 970 | if (method->IsStatic() && !method->IsConstructor() && |
| 971 | !method->GetDeclaringClass()->IsInitialized()) { |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 972 | UpdateEntrypoints(method, GetQuickResolutionStub()); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 973 | } else { |
Nicolas Geoffray | a0619e2 | 2016-12-20 13:57:43 +0000 | [diff] [blame] | 974 | const void* quick_code = NeedDebugVersionFor(method) |
| 975 | ? GetQuickToInterpreterBridge() |
Alex Light | fc49fec | 2018-01-16 22:28:36 +0000 | [diff] [blame] | 976 | : class_linker->GetQuickOatCodeFor(method); |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 977 | UpdateEntrypoints(method, quick_code); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | // If there is no deoptimized method left, we can restore the stack of each thread. |
Alex Light | f244a57 | 2018-06-08 13:56:51 -0700 | [diff] [blame] | 981 | if (empty && !entry_exit_stubs_installed_) { |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 982 | MutexLock mu(self, *Locks::thread_list_lock_); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 983 | Runtime::Current()->GetThreadList()->ForEach(InstrumentationRestoreStack, this); |
| 984 | instrumentation_stubs_installed_ = false; |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 989 | bool Instrumentation::IsDeoptimized(ArtMethod* method) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 990 | DCHECK(method != nullptr); |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame^] | 991 | ReaderMutexLock mu(Thread::Current(), *GetDeoptimizedMethodsLock()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 992 | return IsDeoptimizedMethod(method); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | void Instrumentation::EnableDeoptimization() { |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame^] | 996 | ReaderMutexLock mu(Thread::Current(), *GetDeoptimizedMethodsLock()); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 997 | CHECK(IsDeoptimizedMethodsEmpty()); |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 998 | CHECK_EQ(deoptimization_enabled_, false); |
| 999 | deoptimization_enabled_ = true; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1000 | } |
| 1001 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 1002 | void Instrumentation::DisableDeoptimization(const char* key) { |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 1003 | CHECK_EQ(deoptimization_enabled_, true); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1004 | // If we deoptimized everything, undo it. |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 1005 | InstrumentationLevel level = GetCurrentInstrumentationLevel(); |
| 1006 | if (level == InstrumentationLevel::kInstrumentWithInterpreter) { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 1007 | UndeoptimizeEverything(key); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1008 | } |
| 1009 | // Undeoptimized selected methods. |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 1010 | while (true) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1011 | ArtMethod* method; |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 1012 | { |
Andreas Gampe | 7e56a07 | 2018-11-29 10:40:06 -0800 | [diff] [blame^] | 1013 | ReaderMutexLock mu(Thread::Current(), *GetDeoptimizedMethodsLock()); |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 1014 | if (IsDeoptimizedMethodsEmpty()) { |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 1015 | break; |
| 1016 | } |
Hiroshi Yamauchi | 799eb3a | 2014-07-18 15:38:17 -0700 | [diff] [blame] | 1017 | method = BeginDeoptimizedMethod(); |
| 1018 | CHECK(method != nullptr); |
Mathieu Chartier | 3b05e9b | 2014-03-25 09:29:43 -0700 | [diff] [blame] | 1019 | } |
| 1020 | Undeoptimize(method); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1021 | } |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 1022 | deoptimization_enabled_ = false; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1023 | } |
| 1024 | |
Sebastien Hertz | 11d40c2 | 2014-02-19 18:00:17 +0100 | [diff] [blame] | 1025 | // Indicates if instrumentation should notify method enter/exit events to the listeners. |
| 1026 | bool Instrumentation::ShouldNotifyMethodEnterExitEvents() const { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 1027 | if (!HasMethodEntryListeners() && !HasMethodExitListeners()) { |
| 1028 | return false; |
| 1029 | } |
Sebastien Hertz | 7ec2f1c | 2014-03-27 20:06:47 +0100 | [diff] [blame] | 1030 | return !deoptimization_enabled_ && !interpreter_stubs_installed_; |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 1033 | void Instrumentation::DeoptimizeEverything(const char* key) { |
| 1034 | CHECK(deoptimization_enabled_); |
| 1035 | ConfigureStubs(key, InstrumentationLevel::kInstrumentWithInterpreter); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1036 | } |
| 1037 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 1038 | void Instrumentation::UndeoptimizeEverything(const char* key) { |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1039 | CHECK(interpreter_stubs_installed_); |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 1040 | CHECK(deoptimization_enabled_); |
| 1041 | ConfigureStubs(key, InstrumentationLevel::kInstrumentNothing); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1042 | } |
| 1043 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 1044 | void Instrumentation::EnableMethodTracing(const char* key, bool needs_interpreter) { |
| 1045 | InstrumentationLevel level; |
| 1046 | if (needs_interpreter) { |
| 1047 | level = InstrumentationLevel::kInstrumentWithInterpreter; |
| 1048 | } else { |
| 1049 | level = InstrumentationLevel::kInstrumentWithInstrumentationStubs; |
Alex Light | 2d441b1 | 2018-06-08 15:33:21 -0700 | [diff] [blame] | 1050 | if (Runtime::Current()->GetJit() != nullptr) { |
| 1051 | // TODO b/110263880 It would be better if we didn't need to do this. |
| 1052 | // Since we need to hold the method entrypoint across a suspend to ensure instrumentation |
| 1053 | // hooks are called correctly we have to disable jit-gc to ensure that the entrypoint doesn't |
| 1054 | // go away. Furthermore we need to leave this off permanently since one could get the same |
| 1055 | // effect by causing this to be toggled on and off. |
| 1056 | Runtime::Current()->GetJit()->GetCodeCache()->SetGarbageCollectCode(false); |
| 1057 | } |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 1058 | } |
| 1059 | ConfigureStubs(key, level); |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1060 | } |
| 1061 | |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 1062 | void Instrumentation::DisableMethodTracing(const char* key) { |
| 1063 | ConfigureStubs(key, InstrumentationLevel::kInstrumentNothing); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1064 | } |
| 1065 | |
Alex Light | 2d441b1 | 2018-06-08 15:33:21 -0700 | [diff] [blame] | 1066 | const void* Instrumentation::GetCodeForInvoke(ArtMethod* method) const { |
| 1067 | // This is called by instrumentation entry only and that should never be getting proxy methods. |
| 1068 | DCHECK(!method->IsProxyMethod()) << method->PrettyMethod(); |
| 1069 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 1070 | if (LIKELY(!instrumentation_stubs_installed_ && !interpreter_stubs_installed_)) { |
| 1071 | // In general we just return whatever the method thinks its entrypoint is here. The only |
| 1072 | // exception is if it still has the instrumentation entrypoint. That means we are racing another |
| 1073 | // thread getting rid of instrumentation which is unexpected but possible. In that case we want |
| 1074 | // to wait and try to get it from the oat file or jit. |
| 1075 | const void* code = method->GetEntryPointFromQuickCompiledCodePtrSize(kRuntimePointerSize); |
| 1076 | DCHECK(code != nullptr); |
| 1077 | if (code != GetQuickInstrumentationEntryPoint()) { |
| 1078 | return code; |
| 1079 | } else if (method->IsNative()) { |
| 1080 | return class_linker->GetQuickOatCodeFor(method); |
| 1081 | } |
| 1082 | // We don't know what it is. Fallthough to try to find the code from the JIT or Oat file. |
| 1083 | } else if (method->IsNative()) { |
| 1084 | // TODO We could have JIT compiled native entrypoints. It might be worth it to find these. |
| 1085 | return class_linker->GetQuickOatCodeFor(method); |
| 1086 | } else if (UNLIKELY(interpreter_stubs_installed_)) { |
| 1087 | return GetQuickToInterpreterBridge(); |
| 1088 | } |
| 1089 | // Since the method cannot be native due to ifs above we can always fall back to interpreter |
| 1090 | // bridge. |
| 1091 | const void* result = GetQuickToInterpreterBridge(); |
| 1092 | if (!NeedDebugVersionFor(method)) { |
| 1093 | // If we don't need a debug version we should see what the oat file/class linker has to say. |
| 1094 | result = class_linker->GetQuickOatCodeFor(method); |
| 1095 | } |
| 1096 | // If both those fail try the jit. |
| 1097 | if (result == GetQuickToInterpreterBridge()) { |
| 1098 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 1099 | if (jit != nullptr) { |
| 1100 | const void* res = jit->GetCodeCache()->FindCompiledCodeForInstrumentation(method); |
| 1101 | if (res != nullptr) { |
| 1102 | result = res; |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | return result; |
| 1107 | } |
| 1108 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1109 | const void* Instrumentation::GetQuickCodeFor(ArtMethod* method, PointerSize pointer_size) const { |
Vladimir Marko | 97d7e1c | 2016-10-04 14:44:28 +0100 | [diff] [blame] | 1110 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1111 | if (LIKELY(!instrumentation_stubs_installed_)) { |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 1112 | const void* code = method->GetEntryPointFromQuickCompiledCodePtrSize(pointer_size); |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 1113 | DCHECK(code != nullptr); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1114 | if (LIKELY(!class_linker->IsQuickResolutionStub(code) && |
| 1115 | !class_linker->IsQuickToInterpreterBridge(code)) && |
| 1116 | !class_linker->IsQuickResolutionStub(code) && |
| 1117 | !class_linker->IsQuickToInterpreterBridge(code)) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1118 | return code; |
| 1119 | } |
| 1120 | } |
Alex Light | fc49fec | 2018-01-16 22:28:36 +0000 | [diff] [blame] | 1121 | return class_linker->GetQuickOatCodeFor(method); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1122 | } |
| 1123 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1124 | void Instrumentation::MethodEnterEventImpl(Thread* thread, |
| 1125 | ObjPtr<mirror::Object> this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1126 | ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1127 | uint32_t dex_pc) const { |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 1128 | DCHECK(!method->IsRuntimeMethod()); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1129 | if (HasMethodEntryListeners()) { |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1130 | Thread* self = Thread::Current(); |
| 1131 | StackHandleScope<1> hs(self); |
| 1132 | Handle<mirror::Object> thiz(hs.NewHandle(this_object)); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1133 | for (InstrumentationListener* listener : method_entry_listeners_) { |
| 1134 | if (listener != nullptr) { |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1135 | listener->MethodEntered(thread, thiz, method, dex_pc); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1136 | } |
| 1137 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1141 | void Instrumentation::MethodExitEventImpl(Thread* thread, |
| 1142 | ObjPtr<mirror::Object> this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1143 | ArtMethod* method, |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1144 | uint32_t dex_pc, |
| 1145 | const JValue& return_value) const { |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1146 | if (HasMethodExitListeners()) { |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1147 | Thread* self = Thread::Current(); |
| 1148 | StackHandleScope<2> hs(self); |
| 1149 | Handle<mirror::Object> thiz(hs.NewHandle(this_object)); |
| 1150 | if (method->GetInterfaceMethodIfProxy(kRuntimePointerSize) |
| 1151 | ->GetReturnTypePrimitive() != Primitive::kPrimNot) { |
| 1152 | for (InstrumentationListener* listener : method_exit_listeners_) { |
| 1153 | if (listener != nullptr) { |
| 1154 | listener->MethodExited(thread, thiz, method, dex_pc, return_value); |
| 1155 | } |
| 1156 | } |
| 1157 | } else { |
| 1158 | Handle<mirror::Object> ret(hs.NewHandle(return_value.GetL())); |
| 1159 | for (InstrumentationListener* listener : method_exit_listeners_) { |
| 1160 | if (listener != nullptr) { |
| 1161 | listener->MethodExited(thread, thiz, method, dex_pc, ret); |
| 1162 | } |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1163 | } |
| 1164 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1168 | void Instrumentation::MethodUnwindEvent(Thread* thread, |
| 1169 | mirror::Object* this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1170 | ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1171 | uint32_t dex_pc) const { |
Sebastien Hertz | 0462c4c | 2015-04-01 16:34:17 +0200 | [diff] [blame] | 1172 | if (HasMethodUnwindListeners()) { |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1173 | Thread* self = Thread::Current(); |
| 1174 | StackHandleScope<1> hs(self); |
| 1175 | Handle<mirror::Object> thiz(hs.NewHandle(this_object)); |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 1176 | for (InstrumentationListener* listener : method_unwind_listeners_) { |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1177 | if (listener != nullptr) { |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1178 | listener->MethodUnwind(thread, thiz, method, dex_pc); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1179 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1184 | void Instrumentation::DexPcMovedEventImpl(Thread* thread, |
| 1185 | ObjPtr<mirror::Object> this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1186 | ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1187 | uint32_t dex_pc) const { |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1188 | Thread* self = Thread::Current(); |
| 1189 | StackHandleScope<1> hs(self); |
| 1190 | Handle<mirror::Object> thiz(hs.NewHandle(this_object)); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1191 | for (InstrumentationListener* listener : dex_pc_listeners_) { |
| 1192 | if (listener != nullptr) { |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1193 | listener->DexPcMoved(thread, thiz, method, dex_pc); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1194 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 1198 | void Instrumentation::BranchImpl(Thread* thread, |
| 1199 | ArtMethod* method, |
| 1200 | uint32_t dex_pc, |
| 1201 | int32_t offset) const { |
| 1202 | for (InstrumentationListener* listener : branch_listeners_) { |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1203 | if (listener != nullptr) { |
Nicolas Geoffray | 81f0f95 | 2016-01-20 16:25:19 +0000 | [diff] [blame] | 1204 | listener->Branch(thread, method, dex_pc, offset); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1205 | } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 1209 | void Instrumentation::WatchedFramePopImpl(Thread* thread, const ShadowFrame& frame) const { |
| 1210 | for (InstrumentationListener* listener : watched_frame_pop_listeners_) { |
| 1211 | if (listener != nullptr) { |
| 1212 | listener->WatchedFramePop(thread, frame); |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1217 | void Instrumentation::FieldReadEventImpl(Thread* thread, |
| 1218 | ObjPtr<mirror::Object> this_object, |
| 1219 | ArtMethod* method, |
| 1220 | uint32_t dex_pc, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1221 | ArtField* field) const { |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1222 | Thread* self = Thread::Current(); |
| 1223 | StackHandleScope<1> hs(self); |
| 1224 | Handle<mirror::Object> thiz(hs.NewHandle(this_object)); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1225 | for (InstrumentationListener* listener : field_read_listeners_) { |
| 1226 | if (listener != nullptr) { |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1227 | listener->FieldRead(thread, thiz, method, dex_pc, field); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1228 | } |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 1232 | void Instrumentation::FieldWriteEventImpl(Thread* thread, |
| 1233 | ObjPtr<mirror::Object> this_object, |
| 1234 | ArtMethod* method, |
| 1235 | uint32_t dex_pc, |
| 1236 | ArtField* field, |
| 1237 | const JValue& field_value) const { |
| 1238 | Thread* self = Thread::Current(); |
| 1239 | StackHandleScope<2> hs(self); |
| 1240 | Handle<mirror::Object> thiz(hs.NewHandle(this_object)); |
| 1241 | if (field->IsPrimitiveType()) { |
| 1242 | for (InstrumentationListener* listener : field_write_listeners_) { |
| 1243 | if (listener != nullptr) { |
| 1244 | listener->FieldWritten(thread, thiz, method, dex_pc, field, field_value); |
| 1245 | } |
| 1246 | } |
| 1247 | } else { |
| 1248 | Handle<mirror::Object> val(hs.NewHandle(field_value.GetL())); |
| 1249 | for (InstrumentationListener* listener : field_write_listeners_) { |
| 1250 | if (listener != nullptr) { |
| 1251 | listener->FieldWritten(thread, thiz, method, dex_pc, field, val); |
| 1252 | } |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1253 | } |
Sebastien Hertz | 3f52eaf | 2014-04-04 17:50:18 +0200 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 1257 | void Instrumentation::ExceptionThrownEvent(Thread* thread, |
Sebastien Hertz | 947ff08 | 2013-09-17 14:10:13 +0200 | [diff] [blame] | 1258 | mirror::Throwable* exception_object) const { |
Hiroshi Yamauchi | 3481f7a | 2017-02-10 12:07:36 -0800 | [diff] [blame] | 1259 | Thread* self = Thread::Current(); |
| 1260 | StackHandleScope<1> hs(self); |
| 1261 | Handle<mirror::Throwable> h_exception(hs.NewHandle(exception_object)); |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 1262 | if (HasExceptionThrownListeners()) { |
Hiroshi Yamauchi | 3481f7a | 2017-02-10 12:07:36 -0800 | [diff] [blame] | 1263 | DCHECK_EQ(thread->GetException(), h_exception.Get()); |
Jeff Hao | c0bd4da | 2013-04-11 15:52:28 -0700 | [diff] [blame] | 1264 | thread->ClearException(); |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 1265 | for (InstrumentationListener* listener : exception_thrown_listeners_) { |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1266 | if (listener != nullptr) { |
Alex Light | 6e1607e | 2017-08-23 10:06:18 -0700 | [diff] [blame] | 1267 | listener->ExceptionThrown(thread, h_exception); |
Nicolas Geoffray | 514a616 | 2015-11-03 11:44:24 +0000 | [diff] [blame] | 1268 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1269 | } |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 1270 | // See b/65049545 for discussion about this behavior. |
| 1271 | thread->AssertNoPendingException(); |
Hiroshi Yamauchi | 3481f7a | 2017-02-10 12:07:36 -0800 | [diff] [blame] | 1272 | thread->SetException(h_exception.Get()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | |
Alex Light | 9fb1ab1 | 2017-09-05 09:32:49 -0700 | [diff] [blame] | 1276 | void Instrumentation::ExceptionHandledEvent(Thread* thread, |
| 1277 | mirror::Throwable* exception_object) const { |
| 1278 | Thread* self = Thread::Current(); |
| 1279 | StackHandleScope<1> hs(self); |
| 1280 | Handle<mirror::Throwable> h_exception(hs.NewHandle(exception_object)); |
| 1281 | if (HasExceptionHandledListeners()) { |
| 1282 | // We should have cleared the exception so that callers can detect a new one. |
| 1283 | DCHECK(thread->GetException() == nullptr); |
| 1284 | for (InstrumentationListener* listener : exception_handled_listeners_) { |
| 1285 | if (listener != nullptr) { |
| 1286 | listener->ExceptionHandled(thread, h_exception); |
| 1287 | } |
| 1288 | } |
| 1289 | } |
| 1290 | } |
| 1291 | |
Sebastien Hertz | b2feaaf | 2015-10-12 13:40:10 +0000 | [diff] [blame] | 1292 | // Computes a frame ID by ignoring inlined frames. |
| 1293 | size_t Instrumentation::ComputeFrameId(Thread* self, |
| 1294 | size_t frame_depth, |
| 1295 | size_t inlined_frames_before_frame) { |
| 1296 | CHECK_GE(frame_depth, inlined_frames_before_frame); |
| 1297 | size_t no_inline_depth = frame_depth - inlined_frames_before_frame; |
| 1298 | return StackVisitor::ComputeNumFrames(self, kInstrumentationStackWalk) - no_inline_depth; |
| 1299 | } |
| 1300 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1301 | static void CheckStackDepth(Thread* self, const InstrumentationStackFrame& instrumentation_frame, |
| 1302 | int delta) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1303 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 8e5bd18 | 2015-05-06 11:34:34 +0100 | [diff] [blame] | 1304 | size_t frame_id = StackVisitor::ComputeNumFrames(self, kInstrumentationStackWalk) + delta; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1305 | if (frame_id != instrumentation_frame.frame_id_) { |
| 1306 | LOG(ERROR) << "Expected frame_id=" << frame_id << " but found " |
| 1307 | << instrumentation_frame.frame_id_; |
| 1308 | StackVisitor::DescribeStack(self); |
| 1309 | CHECK_EQ(frame_id, instrumentation_frame.frame_id_); |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | void Instrumentation::PushInstrumentationStackFrame(Thread* self, mirror::Object* this_object, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1314 | ArtMethod* method, |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 1315 | uintptr_t lr, bool interpreter_entry) { |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1316 | DCHECK(!self->IsExceptionPending()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1317 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack(); |
| 1318 | if (kVerboseInstrumentation) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1319 | LOG(INFO) << "Entering " << ArtMethod::PrettyMethod(method) << " from PC " |
| 1320 | << reinterpret_cast<void*>(lr); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1321 | } |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1322 | |
| 1323 | // We send the enter event before pushing the instrumentation frame to make cleanup easier. If the |
| 1324 | // event causes an exception we can simply send the unwind event and return. |
| 1325 | StackHandleScope<1> hs(self); |
| 1326 | Handle<mirror::Object> h_this(hs.NewHandle(this_object)); |
| 1327 | if (!interpreter_entry) { |
| 1328 | MethodEnterEvent(self, h_this.Get(), method, 0); |
| 1329 | if (self->IsExceptionPending()) { |
| 1330 | MethodUnwindEvent(self, h_this.Get(), method, 0); |
| 1331 | return; |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | // We have a callee-save frame meaning this value is guaranteed to never be 0. |
| 1336 | DCHECK(!self->IsExceptionPending()); |
| 1337 | size_t frame_id = StackVisitor::ComputeNumFrames(self, kInstrumentationStackWalk); |
| 1338 | |
| 1339 | instrumentation::InstrumentationStackFrame instrumentation_frame(h_this.Get(), method, lr, |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 1340 | frame_id, interpreter_entry); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1341 | stack->push_front(instrumentation_frame); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1342 | } |
| 1343 | |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 1344 | DeoptimizationMethodType Instrumentation::GetDeoptimizationMethodType(ArtMethod* method) { |
| 1345 | if (method->IsRuntimeMethod()) { |
| 1346 | // Certain methods have strict requirement on whether the dex instruction |
| 1347 | // should be re-executed upon deoptimization. |
| 1348 | if (method == Runtime::Current()->GetCalleeSaveMethod( |
| 1349 | CalleeSaveType::kSaveEverythingForClinit)) { |
| 1350 | return DeoptimizationMethodType::kKeepDexPc; |
| 1351 | } |
| 1352 | if (method == Runtime::Current()->GetCalleeSaveMethod( |
| 1353 | CalleeSaveType::kSaveEverythingForSuspendCheck)) { |
| 1354 | return DeoptimizationMethodType::kKeepDexPc; |
| 1355 | } |
| 1356 | } |
| 1357 | return DeoptimizationMethodType::kDefault; |
| 1358 | } |
| 1359 | |
| 1360 | // Try to get the shorty of a runtime method if it's an invocation stub. |
Andreas Gampe | c7d878d | 2018-11-19 18:42:06 +0000 | [diff] [blame] | 1361 | static char GetRuntimeMethodShorty(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1362 | char shorty = 'V'; |
| 1363 | StackVisitor::WalkStack( |
| 1364 | [&shorty](const art::StackVisitor* stack_visitor) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1365 | ArtMethod* m = stack_visitor->GetMethod(); |
| 1366 | if (m == nullptr || m->IsRuntimeMethod()) { |
| 1367 | return true; |
Andreas Gampe | 3d477f3 | 2018-11-16 16:40:45 +0000 | [diff] [blame] | 1368 | } |
Andreas Gampe | c7d878d | 2018-11-19 18:42:06 +0000 | [diff] [blame] | 1369 | // The first Java method. |
| 1370 | if (m->IsNative()) { |
| 1371 | // Use JNI method's shorty for the jni stub. |
| 1372 | shorty = m->GetShorty()[0]; |
| 1373 | } else if (m->IsProxyMethod()) { |
| 1374 | // Proxy method just invokes its proxied method via |
| 1375 | // art_quick_proxy_invoke_handler. |
| 1376 | shorty = m->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty()[0]; |
| 1377 | } else { |
| 1378 | const Instruction& instr = m->DexInstructions().InstructionAt(stack_visitor->GetDexPc()); |
| 1379 | if (instr.IsInvoke()) { |
| 1380 | auto get_method_index_fn = [](ArtMethod* caller, |
| 1381 | const Instruction& inst, |
| 1382 | uint32_t dex_pc) |
| 1383 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1384 | switch (inst.Opcode()) { |
| 1385 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: |
| 1386 | case Instruction::INVOKE_VIRTUAL_QUICK: { |
| 1387 | uint16_t method_idx = caller->GetIndexFromQuickening(dex_pc); |
| 1388 | CHECK_NE(method_idx, DexFile::kDexNoIndex16); |
| 1389 | return method_idx; |
| 1390 | } |
| 1391 | default: { |
| 1392 | return static_cast<uint16_t>(inst.VRegB()); |
| 1393 | } |
| 1394 | } |
| 1395 | }; |
Nicolas Geoffray | ec43a01 | 2018-11-17 13:10:40 +0000 | [diff] [blame] | 1396 | |
Andreas Gampe | c7d878d | 2018-11-19 18:42:06 +0000 | [diff] [blame] | 1397 | uint16_t method_index = get_method_index_fn(m, instr, stack_visitor->GetDexPc()); |
| 1398 | const DexFile* dex_file = m->GetDexFile(); |
| 1399 | if (interpreter::IsStringInit(dex_file, method_index)) { |
| 1400 | // Invoking string init constructor is turned into invoking |
| 1401 | // StringFactory.newStringFromChars() which returns a string. |
| 1402 | shorty = 'L'; |
| 1403 | } else { |
| 1404 | shorty = dex_file->GetMethodShorty(method_index)[0]; |
| 1405 | } |
| 1406 | |
| 1407 | } else { |
| 1408 | // It could be that a non-invoke opcode invokes a stub, which in turn |
| 1409 | // invokes Java code. In such cases, we should never expect a return |
| 1410 | // value from the stub. |
| 1411 | } |
| 1412 | } |
| 1413 | // Stop stack walking since we've seen a Java frame. |
| 1414 | return false; |
| 1415 | }, |
| 1416 | thread, |
| 1417 | /* context= */ nullptr, |
| 1418 | art::StackVisitor::StackWalkKind::kIncludeInlinedFrames); |
| 1419 | return shorty; |
| 1420 | } |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 1421 | |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1422 | TwoWordReturn Instrumentation::PopInstrumentationStackFrame(Thread* self, |
| 1423 | uintptr_t* return_pc, |
| 1424 | uint64_t* gpr_result, |
| 1425 | uint64_t* fpr_result) { |
| 1426 | DCHECK(gpr_result != nullptr); |
| 1427 | DCHECK(fpr_result != nullptr); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1428 | // Do the pop. |
| 1429 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack(); |
| 1430 | CHECK_GT(stack->size(), 0U); |
| 1431 | InstrumentationStackFrame instrumentation_frame = stack->front(); |
| 1432 | stack->pop_front(); |
| 1433 | |
| 1434 | // Set return PC and check the sanity of the stack. |
| 1435 | *return_pc = instrumentation_frame.return_pc_; |
| 1436 | CheckStackDepth(self, instrumentation_frame, 0); |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1437 | self->VerifyStack(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1438 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1439 | ArtMethod* method = instrumentation_frame.method_; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 1440 | uint32_t length; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1441 | const PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize(); |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 1442 | char return_shorty; |
| 1443 | |
| 1444 | // Runtime method does not call into MethodExitEvent() so there should not be |
| 1445 | // suspension point below. |
| 1446 | ScopedAssertNoThreadSuspension ants(__FUNCTION__, method->IsRuntimeMethod()); |
| 1447 | if (method->IsRuntimeMethod()) { |
| 1448 | if (method != Runtime::Current()->GetCalleeSaveMethod( |
| 1449 | CalleeSaveType::kSaveEverythingForClinit)) { |
| 1450 | // If the caller is at an invocation point and the runtime method is not |
| 1451 | // for clinit, we need to pass return results to the caller. |
| 1452 | // We need the correct shorty to decide whether we need to pass the return |
| 1453 | // result for deoptimization below. |
Andreas Gampe | c7d878d | 2018-11-19 18:42:06 +0000 | [diff] [blame] | 1454 | return_shorty = GetRuntimeMethodShorty(self); |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 1455 | } else { |
| 1456 | // Some runtime methods such as allocations, unresolved field getters, etc. |
| 1457 | // have return value. We don't need to set return_value since MethodExitEvent() |
| 1458 | // below isn't called for runtime methods. Deoptimization doesn't need the |
| 1459 | // value either since the dex instruction will be re-executed by the |
| 1460 | // interpreter, except these two cases: |
| 1461 | // (1) For an invoke, which is handled above to get the correct shorty. |
| 1462 | // (2) For MONITOR_ENTER/EXIT, which cannot be re-executed since it's not |
| 1463 | // idempotent. However there is no return value for it anyway. |
| 1464 | return_shorty = 'V'; |
| 1465 | } |
| 1466 | } else { |
| 1467 | return_shorty = method->GetInterfaceMethodIfProxy(pointer_size)->GetShorty(&length)[0]; |
| 1468 | } |
| 1469 | |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1470 | bool is_ref = return_shorty == '[' || return_shorty == 'L'; |
| 1471 | StackHandleScope<1> hs(self); |
| 1472 | MutableHandle<mirror::Object> res(hs.NewHandle<mirror::Object>(nullptr)); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1473 | JValue return_value; |
| 1474 | if (return_shorty == 'V') { |
| 1475 | return_value.SetJ(0); |
| 1476 | } else if (return_shorty == 'F' || return_shorty == 'D') { |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1477 | return_value.SetJ(*fpr_result); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1478 | } else { |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1479 | return_value.SetJ(*gpr_result); |
| 1480 | } |
| 1481 | if (is_ref) { |
| 1482 | // Take a handle to the return value so we won't lose it if we suspend. |
| 1483 | res.Assign(return_value.GetL()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1484 | } |
| 1485 | // TODO: improve the dex pc information here, requires knowledge of current PC as opposed to |
| 1486 | // return_pc. |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 1487 | uint32_t dex_pc = dex::kDexNoIndex; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1488 | mirror::Object* this_object = instrumentation_frame.this_object_; |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 1489 | if (!method->IsRuntimeMethod() && !instrumentation_frame.interpreter_entry_) { |
Sebastien Hertz | 320deb2 | 2014-06-11 19:45:05 +0200 | [diff] [blame] | 1490 | MethodExitEvent(self, this_object, instrumentation_frame.method_, dex_pc, return_value); |
| 1491 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1492 | |
Sebastien Hertz | 138dbfc | 2013-12-04 18:15:25 +0100 | [diff] [blame] | 1493 | // Deoptimize if the caller needs to continue execution in the interpreter. Do nothing if we get |
| 1494 | // back to an upcall. |
| 1495 | NthCallerVisitor visitor(self, 1, true); |
| 1496 | visitor.WalkStack(true); |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 1497 | bool deoptimize = (visitor.caller != nullptr) && |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 1498 | (interpreter_stubs_installed_ || IsDeoptimized(visitor.caller) || |
| 1499 | Dbg::IsForcedInterpreterNeededForUpcall(self, visitor.caller)); |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1500 | if (is_ref) { |
| 1501 | // Restore the return value if it's a reference since it might have moved. |
| 1502 | *reinterpret_cast<mirror::Object**>(gpr_result) = res.Get(); |
| 1503 | } |
Nicolas Geoffray | a0619e2 | 2016-12-20 13:57:43 +0000 | [diff] [blame] | 1504 | if (deoptimize && Runtime::Current()->IsAsyncDeoptimizeable(*return_pc)) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1505 | if (kVerboseInstrumentation) { |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 1506 | LOG(INFO) << "Deoptimizing " |
| 1507 | << visitor.caller->PrettyMethod() |
| 1508 | << " by returning from " |
| 1509 | << method->PrettyMethod() |
| 1510 | << " with result " |
| 1511 | << std::hex << return_value.GetJ() << std::dec |
| 1512 | << " in " |
| 1513 | << *self; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1514 | } |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 1515 | DeoptimizationMethodType deopt_method_type = GetDeoptimizationMethodType(method); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 1516 | self->PushDeoptimizationContext(return_value, |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 1517 | return_shorty == 'L' || return_shorty == '[', |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 1518 | /* exception= */ nullptr , |
| 1519 | /* from_code= */ false, |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 1520 | deopt_method_type); |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1521 | return GetTwoWordSuccessValue(*return_pc, |
| 1522 | reinterpret_cast<uintptr_t>(GetQuickDeoptimizationEntryPoint())); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1523 | } else { |
Nicolas Geoffray | a0619e2 | 2016-12-20 13:57:43 +0000 | [diff] [blame] | 1524 | if (deoptimize && !Runtime::Current()->IsAsyncDeoptimizeable(*return_pc)) { |
Alex Light | d8eb673 | 2018-01-29 15:16:02 -0800 | [diff] [blame] | 1525 | VLOG(deopt) << "Got a deoptimization request on un-deoptimizable " << method->PrettyMethod() |
| 1526 | << " at PC " << reinterpret_cast<void*>(*return_pc); |
Nicolas Geoffray | a0619e2 | 2016-12-20 13:57:43 +0000 | [diff] [blame] | 1527 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1528 | if (kVerboseInstrumentation) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1529 | LOG(INFO) << "Returning from " << method->PrettyMethod() |
Brian Carlstrom | 2d88862 | 2013-07-18 17:02:00 -0700 | [diff] [blame] | 1530 | << " to PC " << reinterpret_cast<void*>(*return_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1531 | } |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 1532 | return GetTwoWordSuccessValue(0, *return_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1533 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1534 | } |
| 1535 | |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 1536 | uintptr_t Instrumentation::PopFramesForDeoptimization(Thread* self, size_t nframes) const { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1537 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack(); |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 1538 | CHECK_GE(stack->size(), nframes); |
| 1539 | if (nframes == 0) { |
| 1540 | return 0u; |
| 1541 | } |
| 1542 | // Only need to send instrumentation events if it's not for deopt (do give the log messages if we |
| 1543 | // have verbose-instrumentation anyway though). |
| 1544 | if (kVerboseInstrumentation) { |
| 1545 | for (size_t i = 0; i < nframes; i++) { |
| 1546 | LOG(INFO) << "Popping for deoptimization " << stack->at(i).method_->PrettyMethod(); |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 1547 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1548 | } |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 1549 | // Now that we've sent all the instrumentation events we can actually modify the |
| 1550 | // instrumentation-stack. We cannot do this earlier since MethodUnwindEvent can re-enter java and |
| 1551 | // do other things that require the instrumentation stack to be in a consistent state with the |
| 1552 | // actual stack. |
| 1553 | for (size_t i = 0; i < nframes - 1; i++) { |
| 1554 | stack->pop_front(); |
| 1555 | } |
| 1556 | uintptr_t return_pc = stack->front().return_pc_; |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1557 | stack->pop_front(); |
Alex Light | 2c8206f | 2018-06-08 14:51:09 -0700 | [diff] [blame] | 1558 | return return_pc; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | std::string InstrumentationStackFrame::Dump() const { |
| 1562 | std::ostringstream os; |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1563 | os << "Frame " << frame_id_ << " " << ArtMethod::PrettyMethod(method_) << ":" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 1564 | << reinterpret_cast<void*>(return_pc_) << " this=" << reinterpret_cast<void*>(this_object_); |
| 1565 | return os.str(); |
| 1566 | } |
| 1567 | |
| 1568 | } // namespace instrumentation |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1569 | } // namespace art |