jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "instrumentation.h" |
| 18 | |
| 19 | #include <sys/uio.h> |
| 20 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 21 | #include "atomic_integer.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 22 | #include "base/unix_file/fd_file.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 23 | #include "class_linker.h" |
| 24 | #include "debugger.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 25 | #include "dex_file-inl.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 26 | #include "mirror/art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
| 28 | #include "mirror/dex_cache.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | #include "mirror/object_array-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 30 | #include "mirror/object-inl.h" |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 31 | #include "nth_caller_visitor.h" |
Ian Rogers | c928de9 | 2013-02-27 14:30:44 -0800 | [diff] [blame] | 32 | #if !defined(ART_USE_PORTABLE_COMPILER) |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 33 | #include "entrypoints/quick/quick_entrypoints.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 34 | #endif |
| 35 | #include "object_utils.h" |
| 36 | #include "os.h" |
| 37 | #include "scoped_thread_state_change.h" |
| 38 | #include "thread.h" |
| 39 | #include "thread_list.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 40 | |
| 41 | namespace art { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 42 | namespace instrumentation { |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 43 | |
Ian Rogers | 816432e | 2013-09-06 15:47:45 -0700 | [diff] [blame] | 44 | // Do we want to deoptimize for method entry and exit listeners or just try to intercept |
| 45 | // invocations? Deoptimization forces all code to run in the interpreter and considerably hurts the |
| 46 | // application's performance. |
Ian Rogers | 7b6da36 | 2013-09-11 09:29:40 -0700 | [diff] [blame] | 47 | static constexpr bool kDeoptimizeForAccurateMethodEntryExitListeners = false; |
Ian Rogers | 816432e | 2013-09-06 15:47:45 -0700 | [diff] [blame] | 48 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 49 | static bool InstallStubsClassVisitor(mirror::Class* klass, void* arg) |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 50 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 51 | Instrumentation* instrumentation = reinterpret_cast<Instrumentation*>(arg); |
| 52 | return instrumentation->InstallStubsForClass(klass); |
| 53 | } |
| 54 | |
| 55 | bool Instrumentation::InstallStubsForClass(mirror::Class* klass) { |
| 56 | bool uninstall = !entry_exit_stubs_installed_ && !interpreter_stubs_installed_; |
| 57 | ClassLinker* class_linker = NULL; |
| 58 | if (uninstall) { |
| 59 | class_linker = Runtime::Current()->GetClassLinker(); |
| 60 | } |
| 61 | bool is_initialized = klass->IsInitialized(); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 62 | for (size_t i = 0; i < klass->NumDirectMethods(); i++) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 63 | mirror::ArtMethod* method = klass->GetDirectMethod(i); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 64 | if (!method->IsAbstract()) { |
| 65 | const void* new_code; |
| 66 | if (uninstall) { |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 67 | if (forced_interpret_only_ && !method->IsNative() && !method->IsProxyMethod()) { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 68 | new_code = GetCompiledCodeToInterpreterBridge(); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 69 | } else if (is_initialized || !method->IsStatic() || method->IsConstructor()) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 70 | new_code = class_linker->GetOatCodeFor(method); |
| 71 | } else { |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 72 | new_code = GetResolutionTrampoline(class_linker); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 73 | } |
| 74 | } else { // !uninstall |
| 75 | if (!interpreter_stubs_installed_ || method->IsNative()) { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 76 | new_code = GetQuickInstrumentationEntryPoint(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 77 | } else { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 78 | new_code = GetCompiledCodeToInterpreterBridge(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 79 | } |
| 80 | } |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 81 | method->SetEntryPointFromCompiledCode(new_code); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 82 | } |
| 83 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 84 | for (size_t i = 0; i < klass->NumVirtualMethods(); i++) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 85 | mirror::ArtMethod* method = klass->GetVirtualMethod(i); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 86 | if (!method->IsAbstract()) { |
| 87 | const void* new_code; |
| 88 | if (uninstall) { |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 89 | if (forced_interpret_only_ && !method->IsNative() && !method->IsProxyMethod()) { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 90 | new_code = GetCompiledCodeToInterpreterBridge(); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 91 | } else { |
| 92 | new_code = class_linker->GetOatCodeFor(method); |
| 93 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 94 | } else { // !uninstall |
| 95 | if (!interpreter_stubs_installed_ || method->IsNative()) { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 96 | new_code = GetQuickInstrumentationEntryPoint(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 97 | } else { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 98 | new_code = GetCompiledCodeToInterpreterBridge(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 99 | } |
| 100 | } |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 101 | method->SetEntryPointFromCompiledCode(new_code); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | return true; |
| 105 | } |
| 106 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 107 | // Places the instrumentation exit pc as the return PC for every quick frame. This also allows |
| 108 | // deoptimization of quick frames to interpreter frames. |
| 109 | static void InstrumentationInstallStack(Thread* thread, void* arg) |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 110 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 111 | struct InstallStackVisitor : public StackVisitor { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 112 | InstallStackVisitor(Thread* thread, Context* context, uintptr_t instrumentation_exit_pc) |
| 113 | : StackVisitor(thread, context), instrumentation_stack_(thread->GetInstrumentationStack()), |
| 114 | instrumentation_exit_pc_(instrumentation_exit_pc), last_return_pc_(0) {} |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 115 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 116 | virtual bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 117 | mirror::ArtMethod* m = GetMethod(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 118 | if (GetCurrentQuickFrame() == NULL) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 119 | if (kVerboseInstrumentation) { |
| 120 | LOG(INFO) << " Ignoring a shadow frame. Frame " << GetFrameId() |
| 121 | << " Method=" << PrettyMethod(m); |
| 122 | } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 123 | return true; // Ignore shadow frames. |
| 124 | } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 125 | if (m == NULL) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 126 | if (kVerboseInstrumentation) { |
| 127 | LOG(INFO) << " Skipping upcall. Frame " << GetFrameId(); |
| 128 | } |
| 129 | last_return_pc_ = 0; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 130 | return true; // Ignore upcalls. |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 131 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 132 | if (m->IsRuntimeMethod()) { |
| 133 | if (kVerboseInstrumentation) { |
| 134 | LOG(INFO) << " Skipping runtime method. Frame " << GetFrameId(); |
| 135 | } |
| 136 | last_return_pc_ = GetReturnPc(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 137 | return true; // Ignore unresolved methods since they will be instrumented after resolution. |
| 138 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 139 | if (kVerboseInstrumentation) { |
| 140 | LOG(INFO) << " Installing exit stub in " << DescribeLocation(); |
| 141 | } |
| 142 | uintptr_t return_pc = GetReturnPc(); |
| 143 | CHECK_NE(return_pc, instrumentation_exit_pc_); |
| 144 | CHECK_NE(return_pc, 0U); |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 145 | InstrumentationStackFrame instrumentation_frame(GetThisObject(), m, return_pc, GetFrameId(), |
| 146 | false); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 147 | if (kVerboseInstrumentation) { |
| 148 | LOG(INFO) << "Pushing frame " << instrumentation_frame.Dump(); |
| 149 | } |
| 150 | instrumentation_stack_->push_back(instrumentation_frame); |
| 151 | dex_pcs_.push_back(m->ToDexPc(last_return_pc_)); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 152 | SetReturnPc(instrumentation_exit_pc_); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 153 | last_return_pc_ = return_pc; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 154 | return true; // Continue. |
| 155 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 156 | std::deque<InstrumentationStackFrame>* const instrumentation_stack_; |
| 157 | std::vector<uint32_t> dex_pcs_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 158 | const uintptr_t instrumentation_exit_pc_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 159 | uintptr_t last_return_pc_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 160 | }; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 161 | if (kVerboseInstrumentation) { |
| 162 | std::string thread_name; |
| 163 | thread->GetThreadName(thread_name); |
| 164 | LOG(INFO) << "Installing exit stubs in " << thread_name; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 165 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 166 | UniquePtr<Context> context(Context::Create()); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 167 | uintptr_t instrumentation_exit_pc = GetQuickInstrumentationExitPc(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 168 | InstallStackVisitor visitor(thread, context.get(), instrumentation_exit_pc); |
| 169 | visitor.WalkStack(true); |
| 170 | |
| 171 | // Create method enter events for all methods current on the thread's stack. |
| 172 | Instrumentation* instrumentation = reinterpret_cast<Instrumentation*>(arg); |
| 173 | typedef std::deque<InstrumentationStackFrame>::const_reverse_iterator It; |
| 174 | for (It it = thread->GetInstrumentationStack()->rbegin(), |
| 175 | end = thread->GetInstrumentationStack()->rend(); it != end; ++it) { |
| 176 | mirror::Object* this_object = (*it).this_object_; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 177 | mirror::ArtMethod* method = (*it).method_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 178 | uint32_t dex_pc = visitor.dex_pcs_.back(); |
| 179 | visitor.dex_pcs_.pop_back(); |
| 180 | instrumentation->MethodEnterEvent(thread, this_object, method, dex_pc); |
| 181 | } |
| 182 | thread->VerifyStack(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 185 | // Removes the instrumentation exit pc as the return PC for every quick frame. |
| 186 | static void InstrumentationRestoreStack(Thread* thread, void* arg) |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 187 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 188 | struct RestoreStackVisitor : public StackVisitor { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 189 | RestoreStackVisitor(Thread* thread, uintptr_t instrumentation_exit_pc, |
| 190 | Instrumentation* instrumentation) |
| 191 | : StackVisitor(thread, NULL), thread_(thread), |
| 192 | instrumentation_exit_pc_(instrumentation_exit_pc), |
| 193 | instrumentation_(instrumentation), |
| 194 | instrumentation_stack_(thread->GetInstrumentationStack()), |
| 195 | frames_removed_(0) {} |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 196 | |
| 197 | virtual bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 198 | if (instrumentation_stack_->size() == 0) { |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 199 | return false; // Stop. |
| 200 | } |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 201 | mirror::ArtMethod* m = GetMethod(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 202 | if (GetCurrentQuickFrame() == NULL) { |
| 203 | if (kVerboseInstrumentation) { |
| 204 | LOG(INFO) << " Ignoring a shadow frame. Frame " << GetFrameId() << " Method=" << PrettyMethod(m); |
| 205 | } |
| 206 | return true; // Ignore shadow frames. |
| 207 | } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 208 | if (m == NULL) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 209 | if (kVerboseInstrumentation) { |
| 210 | LOG(INFO) << " Skipping upcall. Frame " << GetFrameId(); |
| 211 | } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 212 | return true; // Ignore upcalls. |
| 213 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 214 | bool removed_stub = false; |
| 215 | // TODO: make this search more efficient? |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 216 | for (InstrumentationStackFrame instrumentation_frame : *instrumentation_stack_) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 217 | if (instrumentation_frame.frame_id_ == GetFrameId()) { |
| 218 | if (kVerboseInstrumentation) { |
| 219 | LOG(INFO) << " Removing exit stub in " << DescribeLocation(); |
| 220 | } |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 221 | if (instrumentation_frame.interpreter_entry_) { |
| 222 | CHECK(m == Runtime::Current()->GetCalleeSaveMethod(Runtime::kRefsAndArgs)); |
| 223 | } else { |
| 224 | CHECK(m == instrumentation_frame.method_) << PrettyMethod(m); |
| 225 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 226 | SetReturnPc(instrumentation_frame.return_pc_); |
| 227 | // Create the method exit events. As the methods didn't really exit the result is 0. |
| 228 | instrumentation_->MethodExitEvent(thread_, instrumentation_frame.this_object_, m, |
| 229 | GetDexPc(), JValue()); |
| 230 | frames_removed_++; |
| 231 | removed_stub = true; |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | if (!removed_stub) { |
| 236 | if (kVerboseInstrumentation) { |
| 237 | LOG(INFO) << " No exit stub in " << DescribeLocation(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 238 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 239 | } |
| 240 | return true; // Continue. |
| 241 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 242 | Thread* const thread_; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 243 | const uintptr_t instrumentation_exit_pc_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 244 | Instrumentation* const instrumentation_; |
| 245 | std::deque<instrumentation::InstrumentationStackFrame>* const instrumentation_stack_; |
| 246 | size_t frames_removed_; |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 247 | }; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 248 | if (kVerboseInstrumentation) { |
| 249 | std::string thread_name; |
| 250 | thread->GetThreadName(thread_name); |
| 251 | LOG(INFO) << "Removing exit stubs in " << thread_name; |
| 252 | } |
| 253 | std::deque<instrumentation::InstrumentationStackFrame>* stack = thread->GetInstrumentationStack(); |
| 254 | if (stack->size() > 0) { |
| 255 | Instrumentation* instrumentation = reinterpret_cast<Instrumentation*>(arg); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 256 | uintptr_t instrumentation_exit_pc = GetQuickInstrumentationExitPc(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 257 | RestoreStackVisitor visitor(thread, instrumentation_exit_pc, instrumentation); |
| 258 | visitor.WalkStack(true); |
| 259 | CHECK_EQ(visitor.frames_removed_, stack->size()); |
| 260 | while (stack->size() > 0) { |
| 261 | stack->pop_front(); |
| 262 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 266 | void Instrumentation::AddListener(InstrumentationListener* listener, uint32_t events) { |
| 267 | Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current()); |
| 268 | bool require_entry_exit_stubs = false; |
| 269 | bool require_interpreter = false; |
| 270 | if ((events & kMethodEntered) != 0) { |
| 271 | method_entry_listeners_.push_back(listener); |
Ian Rogers | 816432e | 2013-09-06 15:47:45 -0700 | [diff] [blame] | 272 | require_interpreter = kDeoptimizeForAccurateMethodEntryExitListeners; |
| 273 | require_entry_exit_stubs = !kDeoptimizeForAccurateMethodEntryExitListeners; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 274 | have_method_entry_listeners_ = true; |
| 275 | } |
| 276 | if ((events & kMethodExited) != 0) { |
| 277 | method_exit_listeners_.push_back(listener); |
Ian Rogers | 816432e | 2013-09-06 15:47:45 -0700 | [diff] [blame] | 278 | require_interpreter = kDeoptimizeForAccurateMethodEntryExitListeners; |
| 279 | require_entry_exit_stubs = !kDeoptimizeForAccurateMethodEntryExitListeners; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 280 | have_method_exit_listeners_ = true; |
| 281 | } |
| 282 | if ((events & kMethodUnwind) != 0) { |
| 283 | method_unwind_listeners_.push_back(listener); |
| 284 | have_method_unwind_listeners_ = true; |
| 285 | } |
| 286 | if ((events & kDexPcMoved) != 0) { |
| 287 | dex_pc_listeners_.push_back(listener); |
| 288 | require_interpreter = true; |
| 289 | have_dex_pc_listeners_ = true; |
| 290 | } |
Jeff Hao | 14dd5a8 | 2013-04-11 10:23:36 -0700 | [diff] [blame] | 291 | if ((events & kExceptionCaught) != 0) { |
| 292 | exception_caught_listeners_.push_back(listener); |
| 293 | have_exception_caught_listeners_ = true; |
| 294 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 295 | ConfigureStubs(require_entry_exit_stubs, require_interpreter); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 298 | void Instrumentation::RemoveListener(InstrumentationListener* listener, uint32_t events) { |
| 299 | Locks::mutator_lock_->AssertExclusiveHeld(Thread::Current()); |
| 300 | bool require_entry_exit_stubs = false; |
| 301 | bool require_interpreter = false; |
| 302 | |
| 303 | if ((events & kMethodEntered) != 0) { |
| 304 | bool contains = std::find(method_entry_listeners_.begin(), method_entry_listeners_.end(), |
| 305 | listener) != method_entry_listeners_.end(); |
| 306 | if (contains) { |
| 307 | method_entry_listeners_.remove(listener); |
| 308 | } |
| 309 | have_method_entry_listeners_ = method_entry_listeners_.size() > 0; |
Ian Rogers | 816432e | 2013-09-06 15:47:45 -0700 | [diff] [blame] | 310 | require_entry_exit_stubs |= have_method_entry_listeners_ && |
| 311 | !kDeoptimizeForAccurateMethodEntryExitListeners; |
| 312 | require_interpreter = have_method_entry_listeners_ && |
| 313 | kDeoptimizeForAccurateMethodEntryExitListeners; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 314 | } |
| 315 | if ((events & kMethodExited) != 0) { |
| 316 | bool contains = std::find(method_exit_listeners_.begin(), method_exit_listeners_.end(), |
| 317 | listener) != method_exit_listeners_.end(); |
| 318 | if (contains) { |
| 319 | method_exit_listeners_.remove(listener); |
| 320 | } |
| 321 | have_method_exit_listeners_ = method_exit_listeners_.size() > 0; |
Ian Rogers | 816432e | 2013-09-06 15:47:45 -0700 | [diff] [blame] | 322 | require_entry_exit_stubs |= have_method_exit_listeners_ && |
| 323 | !kDeoptimizeForAccurateMethodEntryExitListeners; |
| 324 | require_interpreter = have_method_exit_listeners_ && |
| 325 | kDeoptimizeForAccurateMethodEntryExitListeners; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 326 | } |
| 327 | if ((events & kMethodUnwind) != 0) { |
| 328 | method_unwind_listeners_.remove(listener); |
| 329 | } |
| 330 | if ((events & kDexPcMoved) != 0) { |
| 331 | bool contains = std::find(dex_pc_listeners_.begin(), dex_pc_listeners_.end(), |
| 332 | listener) != dex_pc_listeners_.end(); |
| 333 | if (contains) { |
| 334 | dex_pc_listeners_.remove(listener); |
| 335 | } |
| 336 | have_dex_pc_listeners_ = dex_pc_listeners_.size() > 0; |
| 337 | require_interpreter |= have_dex_pc_listeners_; |
| 338 | } |
Jeff Hao | 14dd5a8 | 2013-04-11 10:23:36 -0700 | [diff] [blame] | 339 | if ((events & kExceptionCaught) != 0) { |
| 340 | exception_caught_listeners_.remove(listener); |
| 341 | have_exception_caught_listeners_ = exception_caught_listeners_.size() > 0; |
| 342 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 343 | ConfigureStubs(require_entry_exit_stubs, require_interpreter); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 346 | void Instrumentation::ConfigureStubs(bool require_entry_exit_stubs, bool require_interpreter) { |
| 347 | interpret_only_ = require_interpreter || forced_interpret_only_; |
| 348 | // Compute what level of instrumentation is required and compare to current. |
| 349 | int desired_level, current_level; |
| 350 | if (require_interpreter) { |
| 351 | desired_level = 2; |
| 352 | } else if (require_entry_exit_stubs) { |
| 353 | desired_level = 1; |
| 354 | } else { |
| 355 | desired_level = 0; |
| 356 | } |
| 357 | if (interpreter_stubs_installed_) { |
| 358 | current_level = 2; |
| 359 | } else if (entry_exit_stubs_installed_) { |
| 360 | current_level = 1; |
| 361 | } else { |
| 362 | current_level = 0; |
| 363 | } |
| 364 | if (desired_level == current_level) { |
| 365 | // We're already set. |
| 366 | return; |
| 367 | } |
| 368 | Thread* self = Thread::Current(); |
| 369 | Runtime* runtime = Runtime::Current(); |
| 370 | Locks::thread_list_lock_->AssertNotHeld(self); |
| 371 | if (desired_level > 0) { |
| 372 | if (require_interpreter) { |
| 373 | interpreter_stubs_installed_ = true; |
| 374 | } else { |
| 375 | CHECK(require_entry_exit_stubs); |
| 376 | entry_exit_stubs_installed_ = true; |
| 377 | } |
| 378 | runtime->GetClassLinker()->VisitClasses(InstallStubsClassVisitor, this); |
| 379 | instrumentation_stubs_installed_ = true; |
| 380 | MutexLock mu(Thread::Current(), *Locks::thread_list_lock_); |
| 381 | runtime->GetThreadList()->ForEach(InstrumentationInstallStack, this); |
| 382 | } else { |
| 383 | interpreter_stubs_installed_ = false; |
| 384 | entry_exit_stubs_installed_ = false; |
| 385 | runtime->GetClassLinker()->VisitClasses(InstallStubsClassVisitor, this); |
| 386 | instrumentation_stubs_installed_ = false; |
| 387 | MutexLock mu(self, *Locks::thread_list_lock_); |
| 388 | Runtime::Current()->GetThreadList()->ForEach(InstrumentationRestoreStack, this); |
| 389 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 392 | void Instrumentation::UpdateMethodsCode(mirror::ArtMethod* method, const void* code) const { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 393 | if (LIKELY(!instrumentation_stubs_installed_)) { |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 394 | method->SetEntryPointFromCompiledCode(code); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 395 | } else { |
| 396 | if (!interpreter_stubs_installed_ || method->IsNative()) { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 397 | method->SetEntryPointFromCompiledCode(GetQuickInstrumentationEntryPoint()); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 398 | } else { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 399 | method->SetEntryPointFromCompiledCode(GetCompiledCodeToInterpreterBridge()); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 400 | } |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 401 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 402 | } |
| 403 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 404 | const void* Instrumentation::GetQuickCodeFor(const mirror::ArtMethod* method) const { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 405 | Runtime* runtime = Runtime::Current(); |
| 406 | if (LIKELY(!instrumentation_stubs_installed_)) { |
Jeff Hao | aa4a793 | 2013-05-13 11:28:27 -0700 | [diff] [blame] | 407 | const void* code = method->GetEntryPointFromCompiledCode(); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 408 | DCHECK(code != NULL); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 409 | if (LIKELY(code != GetQuickResolutionTrampoline(runtime->GetClassLinker()) && |
| 410 | code != GetQuickToInterpreterBridge())) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 411 | return code; |
| 412 | } |
| 413 | } |
| 414 | return runtime->GetClassLinker()->GetOatCodeFor(method); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 417 | void Instrumentation::MethodEnterEventImpl(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 418 | const mirror::ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 419 | uint32_t dex_pc) const { |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 420 | auto it = method_entry_listeners_.begin(); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 421 | bool is_end = (it == method_entry_listeners_.end()); |
| 422 | // Implemented this way to prevent problems caused by modification of the list while iterating. |
| 423 | while (!is_end) { |
| 424 | InstrumentationListener* cur = *it; |
| 425 | ++it; |
| 426 | is_end = (it == method_entry_listeners_.end()); |
| 427 | cur->MethodEntered(thread, this_object, method, dex_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
| 431 | void Instrumentation::MethodExitEventImpl(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 432 | const mirror::ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 433 | uint32_t dex_pc, const JValue& return_value) const { |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 434 | auto it = method_exit_listeners_.begin(); |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 435 | bool is_end = (it == method_exit_listeners_.end()); |
| 436 | // Implemented this way to prevent problems caused by modification of the list while iterating. |
| 437 | while (!is_end) { |
| 438 | InstrumentationListener* cur = *it; |
| 439 | ++it; |
| 440 | is_end = (it == method_exit_listeners_.end()); |
| 441 | cur->MethodExited(thread, this_object, method, dex_pc, return_value); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
| 445 | void Instrumentation::MethodUnwindEvent(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 446 | const mirror::ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 447 | uint32_t dex_pc) const { |
| 448 | if (have_method_unwind_listeners_) { |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 449 | for (InstrumentationListener* listener : method_unwind_listeners_) { |
| 450 | listener->MethodUnwind(thread, method, dex_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | void Instrumentation::DexPcMovedEventImpl(Thread* thread, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 456 | const mirror::ArtMethod* method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 457 | uint32_t dex_pc) const { |
| 458 | // TODO: STL copy-on-write collection? The copy below is due to the debug listener having an |
| 459 | // action where it can remove itself as a listener and break the iterator. The copy only works |
| 460 | // around the problem and in general we may have to move to something like reference counting to |
| 461 | // ensure listeners are deleted correctly. |
| 462 | std::list<InstrumentationListener*> copy(dex_pc_listeners_); |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 463 | for (InstrumentationListener* listener : copy) { |
| 464 | listener->DexPcMoved(thread, this_object, method, dex_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
| 468 | void Instrumentation::ExceptionCaughtEvent(Thread* thread, const ThrowLocation& throw_location, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 469 | mirror::ArtMethod* catch_method, |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 470 | uint32_t catch_dex_pc, |
Sebastien Hertz | 947ff08 | 2013-09-17 14:10:13 +0200 | [diff] [blame^] | 471 | mirror::Throwable* exception_object) const { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 472 | if (have_exception_caught_listeners_) { |
Jeff Hao | c0bd4da | 2013-04-11 15:52:28 -0700 | [diff] [blame] | 473 | DCHECK_EQ(thread->GetException(NULL), exception_object); |
| 474 | thread->ClearException(); |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 475 | for (InstrumentationListener* listener : exception_caught_listeners_) { |
| 476 | listener->ExceptionCaught(thread, throw_location, catch_method, catch_dex_pc, exception_object); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 477 | } |
Jeff Hao | c0bd4da | 2013-04-11 15:52:28 -0700 | [diff] [blame] | 478 | thread->SetException(throw_location, exception_object); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | |
| 482 | static void CheckStackDepth(Thread* self, const InstrumentationStackFrame& instrumentation_frame, |
| 483 | int delta) |
| 484 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 485 | size_t frame_id = StackVisitor::ComputeNumFrames(self) + delta; |
| 486 | if (frame_id != instrumentation_frame.frame_id_) { |
| 487 | LOG(ERROR) << "Expected frame_id=" << frame_id << " but found " |
| 488 | << instrumentation_frame.frame_id_; |
| 489 | StackVisitor::DescribeStack(self); |
| 490 | CHECK_EQ(frame_id, instrumentation_frame.frame_id_); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | void Instrumentation::PushInstrumentationStackFrame(Thread* self, mirror::Object* this_object, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 495 | mirror::ArtMethod* method, |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 496 | uintptr_t lr, bool interpreter_entry) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 497 | // We have a callee-save frame meaning this value is guaranteed to never be 0. |
| 498 | size_t frame_id = StackVisitor::ComputeNumFrames(self); |
| 499 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack(); |
| 500 | if (kVerboseInstrumentation) { |
Brian Carlstrom | 2d88862 | 2013-07-18 17:02:00 -0700 | [diff] [blame] | 501 | LOG(INFO) << "Entering " << PrettyMethod(method) << " from PC " << reinterpret_cast<void*>(lr); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 502 | } |
| 503 | instrumentation::InstrumentationStackFrame instrumentation_frame(this_object, method, lr, |
Jeff Hao | 9a916d3 | 2013-06-27 18:45:37 -0700 | [diff] [blame] | 504 | frame_id, interpreter_entry); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 505 | stack->push_front(instrumentation_frame); |
| 506 | |
| 507 | MethodEnterEvent(self, this_object, method, 0); |
| 508 | } |
| 509 | |
| 510 | uint64_t Instrumentation::PopInstrumentationStackFrame(Thread* self, uintptr_t* return_pc, |
| 511 | uint64_t gpr_result, uint64_t fpr_result) { |
| 512 | // Do the pop. |
| 513 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack(); |
| 514 | CHECK_GT(stack->size(), 0U); |
| 515 | InstrumentationStackFrame instrumentation_frame = stack->front(); |
| 516 | stack->pop_front(); |
| 517 | |
| 518 | // Set return PC and check the sanity of the stack. |
| 519 | *return_pc = instrumentation_frame.return_pc_; |
| 520 | CheckStackDepth(self, instrumentation_frame, 0); |
| 521 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 522 | mirror::ArtMethod* method = instrumentation_frame.method_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 523 | char return_shorty = MethodHelper(method).GetShorty()[0]; |
| 524 | JValue return_value; |
| 525 | if (return_shorty == 'V') { |
| 526 | return_value.SetJ(0); |
| 527 | } else if (return_shorty == 'F' || return_shorty == 'D') { |
| 528 | return_value.SetJ(fpr_result); |
| 529 | } else { |
| 530 | return_value.SetJ(gpr_result); |
| 531 | } |
| 532 | // TODO: improve the dex pc information here, requires knowledge of current PC as opposed to |
| 533 | // return_pc. |
| 534 | uint32_t dex_pc = DexFile::kDexNoIndex; |
| 535 | mirror::Object* this_object = instrumentation_frame.this_object_; |
| 536 | MethodExitEvent(self, this_object, instrumentation_frame.method_, dex_pc, return_value); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 537 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 538 | bool deoptimize = false; |
| 539 | if (interpreter_stubs_installed_) { |
| 540 | // Deoptimize unless we're returning to an upcall. |
| 541 | NthCallerVisitor visitor(self, 1, true); |
| 542 | visitor.WalkStack(true); |
| 543 | deoptimize = visitor.caller != NULL; |
| 544 | if (deoptimize && kVerboseInstrumentation) { |
| 545 | LOG(INFO) << "Deoptimizing into " << PrettyMethod(visitor.caller); |
| 546 | } |
| 547 | } |
| 548 | if (deoptimize) { |
| 549 | if (kVerboseInstrumentation) { |
| 550 | LOG(INFO) << "Deoptimizing from " << PrettyMethod(method) |
| 551 | << " result is " << std::hex << return_value.GetJ(); |
| 552 | } |
| 553 | self->SetDeoptimizationReturnValue(return_value); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 554 | return static_cast<uint64_t>(GetQuickDeoptimizationEntryPoint()) | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 555 | (static_cast<uint64_t>(*return_pc) << 32); |
| 556 | } else { |
| 557 | if (kVerboseInstrumentation) { |
Brian Carlstrom | 2d88862 | 2013-07-18 17:02:00 -0700 | [diff] [blame] | 558 | LOG(INFO) << "Returning from " << PrettyMethod(method) |
| 559 | << " to PC " << reinterpret_cast<void*>(*return_pc); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 560 | } |
| 561 | return *return_pc; |
| 562 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 565 | void Instrumentation::PopMethodForUnwind(Thread* self, bool is_deoptimization) const { |
| 566 | // Do the pop. |
| 567 | std::deque<instrumentation::InstrumentationStackFrame>* stack = self->GetInstrumentationStack(); |
| 568 | CHECK_GT(stack->size(), 0U); |
| 569 | InstrumentationStackFrame instrumentation_frame = stack->front(); |
| 570 | // TODO: bring back CheckStackDepth(self, instrumentation_frame, 2); |
| 571 | stack->pop_front(); |
| 572 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 573 | mirror::ArtMethod* method = instrumentation_frame.method_; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 574 | if (is_deoptimization) { |
| 575 | if (kVerboseInstrumentation) { |
| 576 | LOG(INFO) << "Popping for deoptimization " << PrettyMethod(method); |
| 577 | } |
| 578 | } else { |
| 579 | if (kVerboseInstrumentation) { |
| 580 | LOG(INFO) << "Popping for unwind " << PrettyMethod(method); |
| 581 | } |
| 582 | |
| 583 | // Notify listeners of method unwind. |
| 584 | // TODO: improve the dex pc information here, requires knowledge of current PC as opposed to |
| 585 | // return_pc. |
| 586 | uint32_t dex_pc = DexFile::kDexNoIndex; |
| 587 | MethodUnwindEvent(self, instrumentation_frame.this_object_, method, dex_pc); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | std::string InstrumentationStackFrame::Dump() const { |
| 592 | std::ostringstream os; |
| 593 | os << "Frame " << frame_id_ << " " << PrettyMethod(method_) << ":" |
| 594 | << reinterpret_cast<void*>(return_pc_) << " this=" << reinterpret_cast<void*>(this_object_); |
| 595 | return os.str(); |
| 596 | } |
| 597 | |
| 598 | } // namespace instrumentation |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 599 | } // namespace art |