jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 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 Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 17 | #include "base/logging.h" |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 18 | #include "instrumentation.h" |
| 19 | #include "runtime.h" |
| 20 | #include "thread.h" |
| 21 | #include "trace.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | extern "C" const void* artInstrumentationMethodEntryFromCode(AbstractMethod* method, Thread* self, |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 26 | AbstractMethod** sp, uintptr_t lr) |
| 27 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
jeffhao | 6641ea1 | 2013-01-02 18:13:42 -0800 | [diff] [blame^] | 28 | self->SetTopOfStack(sp, lr); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 29 | self->VerifyStack(); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 30 | Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 31 | // +1 as frame id's start at 1, +1 as we haven't yet built this method's frame. |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 32 | size_t frame_id = StackVisitor::ComputeNumFrames(self->GetManagedStack(), |
jeffhao | 6641ea1 | 2013-01-02 18:13:42 -0800 | [diff] [blame^] | 33 | self->GetInstrumentationStack()) + 2; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 34 | InstrumentationStackFrame instrumentation_frame(method, lr, frame_id); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 35 | self->PushInstrumentationStackFrame(instrumentation_frame); |
| 36 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 37 | Trace* trace = instrumentation->GetTrace(); |
| 38 | if (trace != NULL) { |
| 39 | trace->LogMethodTraceEvent(self, method, Trace::kMethodTraceEnter); |
| 40 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 41 | |
| 42 | return instrumentation->GetSavedCodeFromMap(method); |
| 43 | } |
| 44 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 45 | extern "C" uint64_t artInstrumentationMethodExitFromCode(Thread* self, AbstractMethod** sp) |
| 46 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
jeffhao | 6641ea1 | 2013-01-02 18:13:42 -0800 | [diff] [blame^] | 47 | self->SetTopOfStack(sp, 0); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 48 | self->VerifyStack(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 49 | // +1 as frame id's start at 1, +1 as we want the called frame not the frame being returned into. |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 50 | size_t frame_id = StackVisitor::ComputeNumFrames(self->GetManagedStack(), |
jeffhao | 6641ea1 | 2013-01-02 18:13:42 -0800 | [diff] [blame^] | 51 | self->GetInstrumentationStack()) + 2; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 52 | InstrumentationStackFrame instrumentation_frame; |
| 53 | instrumentation_frame = self->PopInstrumentationStackFrame(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 54 | if (frame_id != instrumentation_frame.frame_id_) { |
| 55 | LOG(ERROR) << "Expected frame_id=" << frame_id << " but found " << instrumentation_frame.frame_id_; |
| 56 | StackVisitor::DescribeStack(self->GetManagedStack(), self->GetInstrumentationStack()); |
| 57 | } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 58 | 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 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | } // namespace art |