blob: 633f580bd63f7b38982d8fb3e8b453a870a87cdc [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 Rogers62d6c772013-02-27 08:32:07 -080017#include "callee_save_frame.h"
jeffhao725a9572012-11-13 18:20:12 -080018#include "instrumentation.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070019#include "mirror/art_method-inl.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080020#include "mirror/object-inl.h"
jeffhao725a9572012-11-13 18:20:12 -080021#include "runtime.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070022#include "thread-inl.h"
jeffhao725a9572012-11-13 18:20:12 -080023
24namespace art {
25
Brian Carlstromea46f952013-07-30 01:26:50 -070026extern "C" const void* artInstrumentationMethodEntryFromCode(mirror::ArtMethod* method,
Ian Rogers62d6c772013-02-27 08:32:07 -080027 mirror::Object* this_object,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028 Thread* self,
Brian Carlstromea46f952013-07-30 01:26:50 -070029 mirror::ArtMethod** sp,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030 uintptr_t lr)
Ian Rogers306057f2012-11-26 12:45:53 -080031 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -080032 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsAndArgs);
33 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Ian Rogers62d6c772013-02-27 08:32:07 -080034 const void* result = instrumentation->GetQuickCodeFor(method);
Ian Rogers848871b2013-08-05 10:56:33 -070035 bool interpreter_entry = (result == GetQuickToInterpreterBridge());
Jeff Hao9a916d32013-06-27 18:45:37 -070036 instrumentation->PushInstrumentationStackFrame(self, method->IsStatic() ? NULL : this_object,
37 method, lr, interpreter_entry);
Ian Rogers62d6c772013-02-27 08:32:07 -080038 CHECK(result != NULL) << PrettyMethod(method);
39 return result;
jeffhao725a9572012-11-13 18:20:12 -080040}
41
Brian Carlstromea46f952013-07-30 01:26:50 -070042extern "C" uint64_t artInstrumentationMethodExitFromCode(Thread* self, mirror::ArtMethod** sp,
Ian Rogers62d6c772013-02-27 08:32:07 -080043 uint64_t gpr_result, uint64_t fpr_result)
Ian Rogers306057f2012-11-26 12:45:53 -080044 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -080045 // TODO: use FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly) not the hand inlined below.
46 // We use the hand inline version to ensure the return_pc is assigned before verifying the
47 // stack.
48 // Be aware the store below may well stomp on an incoming argument.
49 Locks::mutator_lock_->AssertSharedHeld(self);
Brian Carlstromea46f952013-07-30 01:26:50 -070050 mirror::ArtMethod* callee_save = Runtime::Current()->GetCalleeSaveMethod(Runtime::kRefsOnly);
Ian Rogers62d6c772013-02-27 08:32:07 -080051 *sp = callee_save;
52 uintptr_t* return_pc = reinterpret_cast<uintptr_t*>(reinterpret_cast<byte*>(sp) +
53 callee_save->GetReturnPcOffsetInBytes());
Brian Carlstrom42748892013-07-18 18:04:08 -070054 CHECK_EQ(*return_pc, 0U);
jeffhao6641ea12013-01-02 18:13:42 -080055 self->SetTopOfStack(sp, 0);
Ian Rogers306057f2012-11-26 12:45:53 -080056 self->VerifyStack();
Ian Rogers62d6c772013-02-27 08:32:07 -080057 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
58 uint64_t return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame(self, return_pc,
59 gpr_result,
60 fpr_result);
61 self->VerifyStack();
62 return return_or_deoptimize_pc;
jeffhao725a9572012-11-13 18:20:12 -080063}
64
65} // namespace art