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 | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 32 | size_t frame_id = StackVisitor::ComputeNumFrames(self) + 2; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 33 | InstrumentationStackFrame instrumentation_frame(method, lr, frame_id); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 34 | self->PushInstrumentationStackFrame(instrumentation_frame); |
| 35 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 36 | Trace* trace = instrumentation->GetTrace(); |
| 37 | if (trace != NULL) { |
| 38 | trace->LogMethodTraceEvent(self, method, Trace::kMethodTraceEnter); |
| 39 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 40 | |
| 41 | return instrumentation->GetSavedCodeFromMap(method); |
| 42 | } |
| 43 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 44 | extern "C" uint64_t artInstrumentationMethodExitFromCode(Thread* self, AbstractMethod** sp) |
| 45 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
jeffhao | 6641ea1 | 2013-01-02 18:13:42 -0800 | [diff] [blame] | 46 | self->SetTopOfStack(sp, 0); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 47 | self->VerifyStack(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 48 | // +1 as frame id's start at 1, +1 as we want the called frame not the frame being returned into. |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 49 | size_t frame_id = StackVisitor::ComputeNumFrames(self) + 2; |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 50 | InstrumentationStackFrame instrumentation_frame; |
| 51 | instrumentation_frame = self->PopInstrumentationStackFrame(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 52 | if (frame_id != instrumentation_frame.frame_id_) { |
| 53 | LOG(ERROR) << "Expected frame_id=" << frame_id << " but found " << instrumentation_frame.frame_id_; |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 54 | StackVisitor::DescribeStack(self); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 55 | } |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 56 | Runtime* runtime = Runtime::Current(); |
| 57 | if (runtime->IsMethodTracingActive()) { |
| 58 | Trace* trace = runtime->GetInstrumentation()->GetTrace(); |
| 59 | trace->LogMethodTraceEvent(self, instrumentation_frame.method_, Trace::kMethodTraceExit); |
| 60 | } |
| 61 | if (self->ReadFlag(kEnterInterpreter)) { |
| 62 | return static_cast<uint64_t>(GetDeoptimizationEntryPoint()) | |
| 63 | (static_cast<uint64_t>(instrumentation_frame.return_pc_) << 32); |
| 64 | } else { |
| 65 | return instrumentation_frame.return_pc_; |
| 66 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } // namespace art |