blob: 6598f196cdb3e0b116cddde0275cb82fcae1650b [file] [log] [blame]
jeffhao725a9572012-11-13 18:20:12 -08001/*
2 * Copyright (C) 2012 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
Ian Rogers306057f2012-11-26 12:45:53 -080017#include "base/logging.h"
jeffhao725a9572012-11-13 18:20:12 -080018#include "instrumentation.h"
19#include "runtime.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070020#include "thread-inl.h"
jeffhao725a9572012-11-13 18:20:12 -080021#include "trace.h"
22
23namespace art {
24
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025extern "C" const void* artInstrumentationMethodEntryFromCode(mirror::AbstractMethod* method,
26 Thread* self,
27 mirror::AbstractMethod** sp,
28 uintptr_t lr)
Ian Rogers306057f2012-11-26 12:45:53 -080029 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
jeffhao6641ea12013-01-02 18:13:42 -080030 self->SetTopOfStack(sp, lr);
Ian Rogers306057f2012-11-26 12:45:53 -080031 self->VerifyStack();
jeffhao725a9572012-11-13 18:20:12 -080032 Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Ian Rogers306057f2012-11-26 12:45:53 -080033 // +1 as frame id's start at 1, +1 as we haven't yet built this method's frame.
Ian Rogers7a22fa62013-01-23 12:16:16 -080034 size_t frame_id = StackVisitor::ComputeNumFrames(self) + 2;
Ian Rogers306057f2012-11-26 12:45:53 -080035 InstrumentationStackFrame instrumentation_frame(method, lr, frame_id);
jeffhao725a9572012-11-13 18:20:12 -080036 self->PushInstrumentationStackFrame(instrumentation_frame);
37
Ian Rogers306057f2012-11-26 12:45:53 -080038 Trace* trace = instrumentation->GetTrace();
39 if (trace != NULL) {
40 trace->LogMethodTraceEvent(self, method, Trace::kMethodTraceEnter);
41 }
jeffhao725a9572012-11-13 18:20:12 -080042
43 return instrumentation->GetSavedCodeFromMap(method);
44}
45
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046extern "C" uint64_t artInstrumentationMethodExitFromCode(Thread* self, mirror::AbstractMethod** sp)
Ian Rogers306057f2012-11-26 12:45:53 -080047 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
jeffhao6641ea12013-01-02 18:13:42 -080048 self->SetTopOfStack(sp, 0);
Ian Rogers306057f2012-11-26 12:45:53 -080049 self->VerifyStack();
Ian Rogers306057f2012-11-26 12:45:53 -080050 // +1 as frame id's start at 1, +1 as we want the called frame not the frame being returned into.
Ian Rogers7a22fa62013-01-23 12:16:16 -080051 size_t frame_id = StackVisitor::ComputeNumFrames(self) + 2;
Ian Rogers306057f2012-11-26 12:45:53 -080052 InstrumentationStackFrame instrumentation_frame;
53 instrumentation_frame = self->PopInstrumentationStackFrame();
Ian Rogers306057f2012-11-26 12:45:53 -080054 if (frame_id != instrumentation_frame.frame_id_) {
55 LOG(ERROR) << "Expected frame_id=" << frame_id << " but found " << instrumentation_frame.frame_id_;
Ian Rogers7a22fa62013-01-23 12:16:16 -080056 StackVisitor::DescribeStack(self);
Ian Rogers306057f2012-11-26 12:45:53 -080057 }
Ian Rogers306057f2012-11-26 12:45:53 -080058 Runtime* runtime = Runtime::Current();
59 if (runtime->IsMethodTracingActive()) {
60 Trace* trace = runtime->GetInstrumentation()->GetTrace();
61 trace->LogMethodTraceEvent(self, instrumentation_frame.method_, Trace::kMethodTraceExit);
62 }
63 if (self->ReadFlag(kEnterInterpreter)) {
64 return static_cast<uint64_t>(GetDeoptimizationEntryPoint()) |
65 (static_cast<uint64_t>(instrumentation_frame.return_pc_) << 32);
66 } else {
67 return instrumentation_frame.return_pc_;
68 }
jeffhao725a9572012-11-13 18:20:12 -080069}
70
71} // namespace art