blob: 339c11aa2b85488426150d2dd6ac1b7f575a6d96 [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"
20#include "thread.h"
21#include "trace.h"
22
23namespace art {
24
25extern "C" const void* artInstrumentationMethodEntryFromCode(AbstractMethod* method, Thread* self,
Ian Rogers306057f2012-11-26 12:45:53 -080026 AbstractMethod** sp, uintptr_t lr)
27 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
28 if (*sp != NULL) {
29 self->SetTopOfStack(sp, lr);
30 }
31 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.
34 const size_t kFrameIdAdjust = 2;
35 size_t frame_id = StackVisitor::ComputeNumFrames(self->GetManagedStack(),
36 self->GetInstrumentationStack()) + kFrameIdAdjust;
37 InstrumentationStackFrame instrumentation_frame(method, lr, frame_id);
jeffhao725a9572012-11-13 18:20:12 -080038 self->PushInstrumentationStackFrame(instrumentation_frame);
39
Ian Rogers306057f2012-11-26 12:45:53 -080040 Trace* trace = instrumentation->GetTrace();
41 if (trace != NULL) {
42 trace->LogMethodTraceEvent(self, method, Trace::kMethodTraceEnter);
43 }
jeffhao725a9572012-11-13 18:20:12 -080044
45 return instrumentation->GetSavedCodeFromMap(method);
46}
47
Ian Rogers306057f2012-11-26 12:45:53 -080048extern "C" uint64_t artInstrumentationMethodExitFromCode(Thread* self, AbstractMethod** sp)
49 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
50 if (*sp != NULL) {
51 self->SetTopOfStack(sp, 0);
52 }
53 self->VerifyStack();
jeffhao725a9572012-11-13 18:20:12 -080054
Ian Rogers306057f2012-11-26 12:45:53 -080055 /*
56 // TODO: ComputeNumFrames currently fails here, so it's disabled.
57 // +1 as frame id's start at 1, +1 as we want the called frame not the frame being returned into.
58 const size_t kFrameIdAdjust = 2;
59 size_t frame_id = StackVisitor::ComputeNumFrames(self->GetManagedStack(),
60 self->GetInstrumentationStack()) + kFrameIdAdjust;
61 */
62 InstrumentationStackFrame instrumentation_frame;
63 instrumentation_frame = self->PopInstrumentationStackFrame();
64 /*
65 if (frame_id != instrumentation_frame.frame_id_) {
66 LOG(ERROR) << "Expected frame_id=" << frame_id << " but found " << instrumentation_frame.frame_id_;
67 StackVisitor::DescribeStack(self->GetManagedStack(), self->GetInstrumentationStack());
68 }
69 */
70 Runtime* runtime = Runtime::Current();
71 if (runtime->IsMethodTracingActive()) {
72 Trace* trace = runtime->GetInstrumentation()->GetTrace();
73 trace->LogMethodTraceEvent(self, instrumentation_frame.method_, Trace::kMethodTraceExit);
74 }
75 if (self->ReadFlag(kEnterInterpreter)) {
76 return static_cast<uint64_t>(GetDeoptimizationEntryPoint()) |
77 (static_cast<uint64_t>(instrumentation_frame.return_pc_) << 32);
78 } else {
79 return instrumentation_frame.return_pc_;
80 }
jeffhao725a9572012-11-13 18:20:12 -080081}
82
83} // namespace art