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_) { |
| 28 | if (*sp != NULL) { |
| 29 | self->SetTopOfStack(sp, lr); |
| 30 | } |
| 31 | self->VerifyStack(); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 32 | Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 33 | // +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); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 38 | self->PushInstrumentationStackFrame(instrumentation_frame); |
| 39 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 40 | Trace* trace = instrumentation->GetTrace(); |
| 41 | if (trace != NULL) { |
| 42 | trace->LogMethodTraceEvent(self, method, Trace::kMethodTraceEnter); |
| 43 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 44 | |
| 45 | return instrumentation->GetSavedCodeFromMap(method); |
| 46 | } |
| 47 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 48 | extern "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(); |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 54 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 55 | /* |
| 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 | } |
jeffhao | 725a957 | 2012-11-13 18:20:12 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | } // namespace art |