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