blob: 3b4c3e5233892f95fa97d4987ac849fc30b0cbf1 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
jeffhaoe343b762011-12-05 16:36:44 -080016
17#include "trace.h"
18
jeffhaoa9ef3fd2011-12-13 18:33:43 -080019#include <sys/uio.h>
20
jeffhaoe343b762011-12-05 16:36:44 -080021#include "class_linker.h"
jeffhaoa9ef3fd2011-12-13 18:33:43 -080022#include "debugger.h"
jeffhaoe343b762011-12-05 16:36:44 -080023#include "dex_cache.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070024#include "oat/runtime/oat_support_entrypoints.h"
jeffhaoa9ef3fd2011-12-13 18:33:43 -080025#include "object_utils.h"
26#include "os.h"
Elliott Hughes88c5c352012-03-15 18:49:48 -070027#include "scoped_thread_list_lock.h"
jeffhaoe343b762011-12-05 16:36:44 -080028#include "thread.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070029#include "thread_list.h"
jeffhao2692b572011-12-16 15:42:28 -080030
31namespace art {
32
jeffhaoa9ef3fd2011-12-13 18:33:43 -080033static const uint32_t kTraceMethodActionMask = 0x03; // two bits
34static const char kTraceTokenChar = '*';
35static const uint16_t kTraceHeaderLength = 32;
36static const uint32_t kTraceMagicValue = 0x574f4c53;
37static const uint16_t kTraceVersionSingleClock = 2;
38static const uint16_t kTraceVersionDualClock = 3;
39static const uint16_t kTraceRecordSizeSingleClock = 10; // using v2
40static const uint16_t kTraceRecordSizeDualClock = 14; // using v3 with two timestamps
41
42static inline uint32_t TraceMethodId(uint32_t methodValue) {
43 return (methodValue & ~kTraceMethodActionMask);
44}
45static inline uint32_t TraceMethodCombine(uint32_t method, uint8_t traceEvent) {
46 return (method | traceEvent);
47}
48
Elliott Hughesffb465f2012-03-01 18:46:05 -080049static bool UseThreadCpuClock() {
jeffhaoa9ef3fd2011-12-13 18:33:43 -080050 // TODO: Allow control over which clock is used
51 return true;
52}
53
Elliott Hughesffb465f2012-03-01 18:46:05 -080054static bool UseWallClock() {
jeffhaoa9ef3fd2011-12-13 18:33:43 -080055 // TODO: Allow control over which clock is used
56 return true;
57}
58
Elliott Hughesffb465f2012-03-01 18:46:05 -080059static void MeasureClockOverhead() {
jeffhaoa9ef3fd2011-12-13 18:33:43 -080060 if (UseThreadCpuClock()) {
61 ThreadCpuMicroTime();
62 }
63 if (UseWallClock()) {
64 MicroTime();
65 }
66}
67
Elliott Hughesffb465f2012-03-01 18:46:05 -080068static uint32_t GetClockOverhead() {
jeffhaoa9ef3fd2011-12-13 18:33:43 -080069 uint64_t start = ThreadCpuMicroTime();
70
71 for (int i = 4000; i > 0; i--) {
72 MeasureClockOverhead();
73 MeasureClockOverhead();
74 MeasureClockOverhead();
75 MeasureClockOverhead();
76 MeasureClockOverhead();
77 MeasureClockOverhead();
78 MeasureClockOverhead();
79 MeasureClockOverhead();
80 }
81
82 uint64_t elapsed = ThreadCpuMicroTime() - start;
83 return uint32_t (elapsed / 32);
84}
85
Elliott Hughesffb465f2012-03-01 18:46:05 -080086// TODO: put this somewhere with the big-endian equivalent used by JDWP.
87static void Append2LE(uint8_t* buf, uint16_t val) {
jeffhaoa9ef3fd2011-12-13 18:33:43 -080088 *buf++ = (uint8_t) val;
89 *buf++ = (uint8_t) (val >> 8);
90}
91
Elliott Hughesffb465f2012-03-01 18:46:05 -080092// TODO: put this somewhere with the big-endian equivalent used by JDWP.
93static void Append4LE(uint8_t* buf, uint32_t val) {
jeffhaoa9ef3fd2011-12-13 18:33:43 -080094 *buf++ = (uint8_t) val;
95 *buf++ = (uint8_t) (val >> 8);
96 *buf++ = (uint8_t) (val >> 16);
97 *buf++ = (uint8_t) (val >> 24);
98}
99
Elliott Hughesffb465f2012-03-01 18:46:05 -0800100// TODO: put this somewhere with the big-endian equivalent used by JDWP.
101static void Append8LE(uint8_t* buf, uint64_t val) {
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800102 *buf++ = (uint8_t) val;
103 *buf++ = (uint8_t) (val >> 8);
104 *buf++ = (uint8_t) (val >> 16);
105 *buf++ = (uint8_t) (val >> 24);
106 *buf++ = (uint8_t) (val >> 32);
107 *buf++ = (uint8_t) (val >> 40);
108 *buf++ = (uint8_t) (val >> 48);
109 *buf++ = (uint8_t) (val >> 56);
110}
111
jeffhaob5e81852012-03-12 11:15:45 -0700112static bool InstallStubsClassVisitor(Class* klass, void*) {
jeffhao2692b572011-12-16 15:42:28 -0800113 Trace* tracer = Runtime::Current()->GetTracer();
jeffhaoe343b762011-12-05 16:36:44 -0800114 for (size_t i = 0; i < klass->NumDirectMethods(); i++) {
115 Method* method = klass->GetDirectMethod(i);
jeffhaob5e81852012-03-12 11:15:45 -0700116 if (tracer->GetSavedCodeFromMap(method) == NULL) {
117 tracer->SaveAndUpdateCode(method);
jeffhaoe343b762011-12-05 16:36:44 -0800118 }
119 }
120
121 for (size_t i = 0; i < klass->NumVirtualMethods(); i++) {
122 Method* method = klass->GetVirtualMethod(i);
jeffhaob5e81852012-03-12 11:15:45 -0700123 if (tracer->GetSavedCodeFromMap(method) == NULL) {
124 tracer->SaveAndUpdateCode(method);
jeffhaoe343b762011-12-05 16:36:44 -0800125 }
126 }
jeffhaoe343b762011-12-05 16:36:44 -0800127 return true;
128}
129
jeffhaob5e81852012-03-12 11:15:45 -0700130static bool UninstallStubsClassVisitor(Class* klass, void*) {
jeffhao2692b572011-12-16 15:42:28 -0800131 Trace* tracer = Runtime::Current()->GetTracer();
jeffhaoe343b762011-12-05 16:36:44 -0800132 for (size_t i = 0; i < klass->NumDirectMethods(); i++) {
133 Method* method = klass->GetDirectMethod(i);
jeffhao2692b572011-12-16 15:42:28 -0800134 if (tracer->GetSavedCodeFromMap(method) != NULL) {
135 tracer->ResetSavedCode(method);
jeffhaoe343b762011-12-05 16:36:44 -0800136 }
137 }
138
139 for (size_t i = 0; i < klass->NumVirtualMethods(); i++) {
140 Method* method = klass->GetVirtualMethod(i);
jeffhao2692b572011-12-16 15:42:28 -0800141 if (tracer->GetSavedCodeFromMap(method) != NULL) {
142 tracer->ResetSavedCode(method);
jeffhaoe343b762011-12-05 16:36:44 -0800143 }
144 }
jeffhaoe343b762011-12-05 16:36:44 -0800145 return true;
146}
147
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700148static void TraceRestoreStack(Thread* t, void*) {
jeffhaoe343b762011-12-05 16:36:44 -0800149 Frame frame = t->GetTopOfStack();
150 if (frame.GetSP() != 0) {
151 for ( ; frame.GetMethod() != 0; frame.Next()) {
152 if (t->IsTraceStackEmpty()) {
153 break;
154 }
155 uintptr_t pc = frame.GetReturnPC();
156 Method* method = frame.GetMethod();
Ian Rogers57b86d42012-03-27 16:05:41 -0700157 if (IsTraceExitPc(pc)) {
jeffhaoe343b762011-12-05 16:36:44 -0800158 TraceStackFrame trace_frame = t->PopTraceStackFrame();
159 frame.SetReturnPC(trace_frame.return_pc_);
160 CHECK(method == trace_frame.method_);
161 }
162 }
163 }
jeffhaob5e81852012-03-12 11:15:45 -0700164}
jeffhaoe343b762011-12-05 16:36:44 -0800165
jeffhaoe343b762011-12-05 16:36:44 -0800166void Trace::AddSavedCodeToMap(const Method* method, const void* code) {
167 saved_code_map_.insert(std::make_pair(method, code));
168}
169
170void Trace::RemoveSavedCodeFromMap(const Method* method) {
171 saved_code_map_.erase(method);
172}
173
174const void* Trace::GetSavedCodeFromMap(const Method* method) {
jeffhao2692b572011-12-16 15:42:28 -0800175 typedef std::map<const Method*, const void*>::const_iterator It; // TODO: C++0x auto
176 It it = saved_code_map_.find(method);
177 if (it == saved_code_map_.end()) {
178 return NULL;
179 } else {
180 return it->second;
181 }
jeffhaoe343b762011-12-05 16:36:44 -0800182}
183
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700184void Trace::SaveAndUpdateCode(Method* method) {
Ian Rogers57b86d42012-03-27 16:05:41 -0700185 void* trace_stub = GetLogTraceEntryPoint();
jeffhaoe343b762011-12-05 16:36:44 -0800186 CHECK(GetSavedCodeFromMap(method) == NULL);
187 AddSavedCodeToMap(method, method->GetCode());
jeffhaob5e81852012-03-12 11:15:45 -0700188 method->SetCode(trace_stub);
jeffhaoe343b762011-12-05 16:36:44 -0800189}
190
191void Trace::ResetSavedCode(Method* method) {
192 CHECK(GetSavedCodeFromMap(method) != NULL);
193 method->SetCode(GetSavedCodeFromMap(method));
194 RemoveSavedCodeFromMap(method);
195}
196
jeffhaoe343b762011-12-05 16:36:44 -0800197void Trace::Start(const char* trace_filename, int trace_fd, int buffer_size, int flags, bool direct_to_ddms) {
jeffhao2692b572011-12-16 15:42:28 -0800198 if (Runtime::Current()->IsMethodTracingActive()) {
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800199 LOG(INFO) << "Trace already in progress, ignoring this request";
jeffhaoe343b762011-12-05 16:36:44 -0800200 return;
201 }
202
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800203 ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable);
204 Runtime::Current()->GetThreadList()->SuspendAll(false);
205
jeffhao2692b572011-12-16 15:42:28 -0800206 // Open trace file if not going directly to ddms.
207 File* trace_file = NULL;
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800208 if (!direct_to_ddms) {
209 if (trace_fd < 0) {
jeffhao2692b572011-12-16 15:42:28 -0800210 trace_file = OS::OpenFile(trace_filename, true);
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800211 } else {
jeffhao2692b572011-12-16 15:42:28 -0800212 trace_file = OS::FileFromFd("tracefile", trace_fd);
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800213 }
jeffhao2692b572011-12-16 15:42:28 -0800214 if (trace_file == NULL) {
jeffhaob5e81852012-03-12 11:15:45 -0700215 PLOG(ERROR) << "Unable to open trace file '" << trace_filename << "'";
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800216 Thread::Current()->ThrowNewException("Ljava/lang/RuntimeException;",
217 StringPrintf("Unable to open trace file '%s'", trace_filename).c_str());
218 Runtime::Current()->GetThreadList()->ResumeAll(false);
219 return;
220 }
221 }
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800222
jeffhao2692b572011-12-16 15:42:28 -0800223 // Create Trace object.
jeffhao0791adc2012-04-04 11:14:32 -0700224 Trace* tracer(new Trace(trace_file, buffer_size, flags));
225
226 // Enable count of allocs if specified in the flags.
227 if ((flags && kTraceCountAllocs) != 0) {
228 Runtime::Current()->SetStatsEnabled(true);
229 }
230
jeffhao2692b572011-12-16 15:42:28 -0800231 Runtime::Current()->EnableMethodTracing(tracer);
232 tracer->BeginTracing();
233
234 Runtime::Current()->GetThreadList()->ResumeAll(false);
235}
236
237void Trace::Stop() {
238 if (!Runtime::Current()->IsMethodTracingActive()) {
239 LOG(INFO) << "Trace stop requested, but no trace currently running";
240 return;
241 }
242
243 ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable);
244 Runtime::Current()->GetThreadList()->SuspendAll(false);
245
246 Runtime::Current()->GetTracer()->FinishTracing();
247 Runtime::Current()->DisableMethodTracing();
248
249 Runtime::Current()->GetThreadList()->ResumeAll(false);
250}
251
jeffhaob5e81852012-03-12 11:15:45 -0700252void Trace::Shutdown() {
253 if (!Runtime::Current()->IsMethodTracingActive()) {
254 LOG(INFO) << "Trace shutdown requested, but no trace currently running";
255 return;
256 }
257 Runtime::Current()->GetTracer()->FinishTracing();
258 Runtime::Current()->DisableMethodTracing();
259}
260
jeffhao2692b572011-12-16 15:42:28 -0800261void Trace::BeginTracing() {
262 // Set the start time of tracing.
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800263 start_time_ = MicroTime();
264
jeffhao2692b572011-12-16 15:42:28 -0800265 // Set trace version and record size.
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800266 if (UseThreadCpuClock() && UseWallClock()) {
267 trace_version_ = kTraceVersionDualClock;
268 record_size_ = kTraceRecordSizeDualClock;
269 } else {
270 trace_version_ = kTraceVersionSingleClock;
271 record_size_ = kTraceRecordSizeSingleClock;
272 }
273
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800274 // Set up the beginning of the trace.
jeffhao2692b572011-12-16 15:42:28 -0800275 memset(buf_.get(), 0, kTraceHeaderLength);
276 Append4LE(buf_.get(), kTraceMagicValue);
277 Append2LE(buf_.get() + 4, trace_version_);
278 Append2LE(buf_.get() + 6, kTraceHeaderLength);
279 Append8LE(buf_.get() + 8, start_time_);
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800280 if (trace_version_ >= kTraceVersionDualClock) {
jeffhao2692b572011-12-16 15:42:28 -0800281 Append2LE(buf_.get() + 16, record_size_);
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800282 }
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800283
jeffhao2692b572011-12-16 15:42:28 -0800284 // Update current offset.
285 cur_offset_ = kTraceHeaderLength;
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800286
287 // Install all method tracing stubs.
jeffhaoe343b762011-12-05 16:36:44 -0800288 InstallStubs();
jeffhaoe343b762011-12-05 16:36:44 -0800289}
290
jeffhao2692b572011-12-16 15:42:28 -0800291void Trace::FinishTracing() {
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800292 // Uninstall all method tracing stubs.
jeffhaoe343b762011-12-05 16:36:44 -0800293 UninstallStubs();
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800294
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800295 // Compute elapsed time.
296 uint64_t elapsed = MicroTime() - start_time_;
297
298 size_t final_offset = cur_offset_;
299 uint32_t clock_overhead = GetClockOverhead();
300
jeffhao0791adc2012-04-04 11:14:32 -0700301 if ((flags_ & kTraceCountAllocs) != 0) {
302 Runtime::Current()->SetStatsEnabled(false);
303 }
304
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800305 GetVisitedMethods(final_offset);
306
307 std::ostringstream os;
308
309 os << StringPrintf("%cversion\n", kTraceTokenChar);
310 os << StringPrintf("%d\n", trace_version_);
311 os << StringPrintf("data-file-overflow=%s\n", overflow_ ? "true" : "false");
312 if (UseThreadCpuClock()) {
313 if (UseWallClock()) {
314 os << StringPrintf("clock=dual\n");
315 } else {
316 os << StringPrintf("clock=thread-cpu\n");
317 }
318 } else {
319 os << StringPrintf("clock=wall\n");
320 }
321 os << StringPrintf("elapsed-time-usec=%llu\n", elapsed);
Elliott Hughesad6c9c32012-01-19 17:39:12 -0800322 os << StringPrintf("num-method-calls=%zd\n", (final_offset - kTraceHeaderLength) / record_size_);
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800323 os << StringPrintf("clock-call-overhead-nsec=%d\n", clock_overhead);
324 os << StringPrintf("vm=art\n");
jeffhao0791adc2012-04-04 11:14:32 -0700325 if ((flags_ & kTraceCountAllocs) != 0) {
326 os << StringPrintf("alloc-count=%d\n", Runtime::Current()->GetStat(KIND_ALLOCATED_OBJECTS));
327 os << StringPrintf("alloc-size=%d\n", Runtime::Current()->GetStat(KIND_ALLOCATED_BYTES));
328 os << StringPrintf("gc-count=%d\n", Runtime::Current()->GetStat(KIND_GC_INVOCATIONS));
329 }
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800330 os << StringPrintf("%cthreads\n", kTraceTokenChar);
331 DumpThreadList(os);
332 os << StringPrintf("%cmethods\n", kTraceTokenChar);
333 DumpMethodList(os);
334 os << StringPrintf("%cend\n", kTraceTokenChar);
335
336 std::string header(os.str());
jeffhao2692b572011-12-16 15:42:28 -0800337 if (trace_file_.get() == NULL) {
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800338 struct iovec iov[2];
339 iov[0].iov_base = reinterpret_cast<void*>(const_cast<char*>(header.c_str()));
340 iov[0].iov_len = header.length();
jeffhao2692b572011-12-16 15:42:28 -0800341 iov[1].iov_base = buf_.get();
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800342 iov[1].iov_len = final_offset;
343 Dbg::DdmSendChunkV(CHUNK_TYPE("MPSE"), iov, 2);
344 } else {
345 if (!trace_file_->WriteFully(header.c_str(), header.length()) ||
jeffhao2692b572011-12-16 15:42:28 -0800346 !trace_file_->WriteFully(buf_.get(), final_offset)) {
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800347 int err = errno;
348 LOG(ERROR) << "Trace data write failed: " << strerror(err);
349 Thread::Current()->ThrowNewException("Ljava/lang/RuntimeException;",
350 StringPrintf("Trace data write failed: %s", strerror(err)).c_str());
351 }
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800352 }
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800353}
354
355void Trace::LogMethodTraceEvent(Thread* self, const Method* method, Trace::TraceEvent event) {
356 if (thread_clock_base_map_.find(self) == thread_clock_base_map_.end()) {
357 uint64_t time = ThreadCpuMicroTime();
358 thread_clock_base_map_.insert(std::make_pair(self, time));
359 }
360
361 // Advance cur_offset_ atomically.
362 int32_t new_offset;
363 int32_t old_offset;
364 do {
365 old_offset = cur_offset_;
366 new_offset = old_offset + record_size_;
367 if (new_offset > buffer_size_) {
368 overflow_ = true;
369 return;
370 }
371 } while (android_atomic_release_cas(old_offset, new_offset, &cur_offset_) != 0);
372
373 uint32_t method_value = TraceMethodCombine(reinterpret_cast<uint32_t>(method), event);
374
375 // Write data
jeffhao2692b572011-12-16 15:42:28 -0800376 uint8_t* ptr = buf_.get() + old_offset;
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800377 Append2LE(ptr, self->GetTid());
378 Append4LE(ptr + 2, method_value);
379 ptr += 6;
380
381 if (UseThreadCpuClock()) {
382 uint64_t thread_clock_base = thread_clock_base_map_.find(self)->second;
383 uint32_t thread_clock_diff = ThreadCpuMicroTime() - thread_clock_base;
384 Append4LE(ptr, thread_clock_diff);
385 ptr += 4;
386 }
387
388 if (UseWallClock()) {
389 uint32_t wall_clock_diff = MicroTime() - start_time_;
390 Append4LE(ptr, wall_clock_diff);
391 }
392}
393
394void Trace::GetVisitedMethods(size_t end_offset) {
jeffhao2692b572011-12-16 15:42:28 -0800395 uint8_t* ptr = buf_.get() + kTraceHeaderLength;
396 uint8_t* end = buf_.get() + end_offset;
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800397
398 while (ptr < end) {
399 uint32_t method_value = ptr[2] | (ptr[3] << 8) | (ptr[4] << 16) | (ptr[5] << 24);
400 Method* method = reinterpret_cast<Method*>(TraceMethodId(method_value));
401 visited_methods_.insert(method);
402 ptr += record_size_;
403 }
404}
405
406void Trace::DumpMethodList(std::ostream& os) {
407 typedef std::set<const Method*>::const_iterator It; // TODO: C++0x auto
408 for (It it = visited_methods_.begin(); it != visited_methods_.end(); ++it) {
409 const Method* method = *it;
410 MethodHelper mh(method);
Elliott Hughesba8eee12012-01-24 20:25:24 -0800411 os << StringPrintf("%p\t%s\t%s\t%s\t%s\t%d\n", method,
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800412 PrettyDescriptor(mh.GetDeclaringClassDescriptor()).c_str(), mh.GetName(),
413 mh.GetSignature().c_str(), mh.GetDeclaringClassSourceFile(),
414 mh.GetLineNumFromNativePC(0));
415 }
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800416}
417
418static void DumpThread(Thread* t, void* arg) {
Elliott Hughesffb465f2012-03-01 18:46:05 -0800419 std::ostream& os = *reinterpret_cast<std::ostream*>(arg);
420 std::string name;
421 t->GetThreadName(name);
422 os << t->GetTid() << "\t" << name << "\n";
jeffhaoa9ef3fd2011-12-13 18:33:43 -0800423}
424
425void Trace::DumpThreadList(std::ostream& os) {
426 ScopedThreadListLock thread_list_lock;
427 Runtime::Current()->GetThreadList()->ForEach(DumpThread, &os);
jeffhaoe343b762011-12-05 16:36:44 -0800428}
429
430void Trace::InstallStubs() {
jeffhaob5e81852012-03-12 11:15:45 -0700431 Runtime::Current()->GetClassLinker()->VisitClasses(InstallStubsClassVisitor, NULL);
jeffhaoe343b762011-12-05 16:36:44 -0800432}
433
434void Trace::UninstallStubs() {
jeffhaob5e81852012-03-12 11:15:45 -0700435 Runtime::Current()->GetClassLinker()->VisitClasses(UninstallStubsClassVisitor, NULL);
jeffhaoe343b762011-12-05 16:36:44 -0800436
437 // Restore stacks of all threads
438 {
439 ScopedThreadListLock thread_list_lock;
440 Runtime::Current()->GetThreadList()->ForEach(TraceRestoreStack, NULL);
441 }
jeffhaoe343b762011-12-05 16:36:44 -0800442}
443
Ian Rogers57b86d42012-03-27 16:05:41 -0700444uint32_t TraceMethodUnwindFromCode(Thread* self) {
445 Trace* tracer = Runtime::Current()->GetTracer();
446 TraceStackFrame trace_frame = self->PopTraceStackFrame();
447 Method* method = trace_frame.method_;
448 uint32_t lr = trace_frame.return_pc_;
449
450 tracer->LogMethodTraceEvent(self, method, Trace::kMethodTraceUnwind);
451
452 return lr;
453}
454
jeffhaoe343b762011-12-05 16:36:44 -0800455} // namespace art