quick_instrumentation_entrypoints.cc revision 62d6c772205b8859f0ebf7ad105402ec4c3e2e01
1725a957985171d712d5c048cc3d00ff14968784bjeffhao/*
2725a957985171d712d5c048cc3d00ff14968784bjeffhao * Copyright (C) 2012 The Android Open Source Project
3725a957985171d712d5c048cc3d00ff14968784bjeffhao *
4725a957985171d712d5c048cc3d00ff14968784bjeffhao * Licensed under the Apache License, Version 2.0 (the "License");
5725a957985171d712d5c048cc3d00ff14968784bjeffhao * you may not use this file except in compliance with the License.
6725a957985171d712d5c048cc3d00ff14968784bjeffhao * You may obtain a copy of the License at
7725a957985171d712d5c048cc3d00ff14968784bjeffhao *
8725a957985171d712d5c048cc3d00ff14968784bjeffhao *      http://www.apache.org/licenses/LICENSE-2.0
9725a957985171d712d5c048cc3d00ff14968784bjeffhao *
10725a957985171d712d5c048cc3d00ff14968784bjeffhao * Unless required by applicable law or agreed to in writing, software
11725a957985171d712d5c048cc3d00ff14968784bjeffhao * distributed under the License is distributed on an "AS IS" BASIS,
12725a957985171d712d5c048cc3d00ff14968784bjeffhao * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13725a957985171d712d5c048cc3d00ff14968784bjeffhao * See the License for the specific language governing permissions and
14725a957985171d712d5c048cc3d00ff14968784bjeffhao * limitations under the License.
15725a957985171d712d5c048cc3d00ff14968784bjeffhao */
16725a957985171d712d5c048cc3d00ff14968784bjeffhao
1762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers#include "callee_save_frame.h"
18725a957985171d712d5c048cc3d00ff14968784bjeffhao#include "instrumentation.h"
1962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers#include "mirror/abstract_method-inl.h"
2062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers#include "mirror/object-inl.h"
21725a957985171d712d5c048cc3d00ff14968784bjeffhao#include "runtime.h"
2204d7aa92bc5548bc4d272b9480614f06248194ccIan Rogers#include "thread-inl.h"
23725a957985171d712d5c048cc3d00ff14968784bjeffhao
24725a957985171d712d5c048cc3d00ff14968784bjeffhaonamespace art {
25725a957985171d712d5c048cc3d00ff14968784bjeffhao
262dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersextern "C" const void* artInstrumentationMethodEntryFromCode(mirror::AbstractMethod* method,
2762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                                                             mirror::Object* this_object,
282dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers                                                             Thread* self,
292dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers                                                             mirror::AbstractMethod** sp,
302dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers                                                             uintptr_t lr)
31306057fd278d75bf3794bd5243a3b6652c487d18Ian Rogers    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
3262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsAndArgs);
3362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
3462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  instrumentation->PushInstrumentationStackFrame(self, method->IsStatic() ? NULL : this_object,
3562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                                                 method, lr);
3662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  const void* result = instrumentation->GetQuickCodeFor(method);
3762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  CHECK(result != NULL) << PrettyMethod(method);
3862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  return result;
39725a957985171d712d5c048cc3d00ff14968784bjeffhao}
40725a957985171d712d5c048cc3d00ff14968784bjeffhao
4162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogersextern "C" uint64_t artInstrumentationMethodExitFromCode(Thread* self, mirror::AbstractMethod** sp,
4262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                                                         uint64_t gpr_result, uint64_t fpr_result)
43306057fd278d75bf3794bd5243a3b6652c487d18Ian Rogers    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
4462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // TODO: use FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly) not the hand inlined below.
4562d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  //       We use the hand inline version to ensure the return_pc is assigned before verifying the
4662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  //       stack.
4762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  // Be aware the store below may well stomp on an incoming argument.
4862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  Locks::mutator_lock_->AssertSharedHeld(self);
4962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  mirror::AbstractMethod* callee_save = Runtime::Current()->GetCalleeSaveMethod(Runtime::kRefsOnly);
5062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  *sp = callee_save;
5162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  uintptr_t* return_pc = reinterpret_cast<uintptr_t*>(reinterpret_cast<byte*>(sp) +
5262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                                                      callee_save->GetReturnPcOffsetInBytes());
5362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  CHECK(*return_pc == 0);
546641ea12b98dda9ec45d29f20e43f85698b88a02jeffhao  self->SetTopOfStack(sp, 0);
55306057fd278d75bf3794bd5243a3b6652c487d18Ian Rogers  self->VerifyStack();
5662d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
5762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  uint64_t return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame(self, return_pc,
5862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                                                                                   gpr_result,
5962d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers                                                                                   fpr_result);
6062d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  self->VerifyStack();
6162d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers  return return_or_deoptimize_pc;
62725a957985171d712d5c048cc3d00ff14968784bjeffhao}
63725a957985171d712d5c048cc3d00ff14968784bjeffhao
64725a957985171d712d5c048cc3d00ff14968784bjeffhao}  // namespace art
65