blob: 2edcb78be38bd6e855541ee2b7ab6ea2dc1e8500 [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"
Andreas Gamped58342c2014-06-05 14:18:08 -070018#include "instruction_set.h"
jeffhao725a9572012-11-13 18:20:12 -080019#include "instrumentation.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070020#include "mirror/art_method-inl.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080021#include "mirror/object-inl.h"
jeffhao725a9572012-11-13 18:20:12 -080022#include "runtime.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070023#include "thread-inl.h"
jeffhao725a9572012-11-13 18:20:12 -080024
25namespace art {
26
Brian Carlstromea46f952013-07-30 01:26:50 -070027extern "C" const void* artInstrumentationMethodEntryFromCode(mirror::ArtMethod* method,
Ian Rogers62d6c772013-02-27 08:32:07 -080028 mirror::Object* this_object,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029 Thread* self,
Andreas Gampecf4035a2014-05-28 22:43:01 -070030 StackReference<mirror::ArtMethod>* sp,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031 uintptr_t lr)
Ian Rogers306057f2012-11-26 12:45:53 -080032 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -080033 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsAndArgs);
34 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Sebastien Hertz320deb22014-06-11 19:45:05 +020035 const void* result;
36 if (instrumentation->IsDeoptimized(method)) {
37 result = GetQuickToInterpreterBridge();
38 } else {
39 result = instrumentation->GetQuickCodeFor(method);
40 }
Vladimir Marko8a630572014-04-09 18:45:35 +010041 DCHECK(result != GetQuickToInterpreterBridgeTrampoline(Runtime::Current()->GetClassLinker()));
Ian Rogers848871b2013-08-05 10:56:33 -070042 bool interpreter_entry = (result == GetQuickToInterpreterBridge());
Sebastien Hertz320deb22014-06-11 19:45:05 +020043 instrumentation->PushInstrumentationStackFrame(self, method->IsStatic() ? nullptr : this_object,
Jeff Hao9a916d32013-06-27 18:45:37 -070044 method, lr, interpreter_entry);
Ian Rogers62d6c772013-02-27 08:32:07 -080045 CHECK(result != NULL) << PrettyMethod(method);
46 return result;
jeffhao725a9572012-11-13 18:20:12 -080047}
48
Andreas Gamped58342c2014-06-05 14:18:08 -070049extern "C" TwoWordReturn artInstrumentationMethodExitFromCode(Thread* self,
50 StackReference<mirror::ArtMethod>* sp,
51 uint64_t gpr_result,
52 uint64_t fpr_result)
Ian Rogers306057f2012-11-26 12:45:53 -080053 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers62d6c772013-02-27 08:32:07 -080054 // TODO: use FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly) not the hand inlined below.
55 // We use the hand inline version to ensure the return_pc is assigned before verifying the
56 // stack.
57 // Be aware the store below may well stomp on an incoming argument.
58 Locks::mutator_lock_->AssertSharedHeld(self);
Vladimir Marko4c1c5102014-05-14 16:51:16 +010059 Runtime* runtime = Runtime::Current();
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070060 sp->Assign(runtime->GetCalleeSaveMethod(Runtime::kRefsOnly));
61 uint32_t return_pc_offset = GetCalleeSavePCOffset(kRuntimeISA, Runtime::kRefsOnly);
Ian Rogers62d6c772013-02-27 08:32:07 -080062 uintptr_t* return_pc = reinterpret_cast<uintptr_t*>(reinterpret_cast<byte*>(sp) +
Vladimir Marko4c1c5102014-05-14 16:51:16 +010063 return_pc_offset);
Brian Carlstrom42748892013-07-18 18:04:08 -070064 CHECK_EQ(*return_pc, 0U);
jeffhao6641ea12013-01-02 18:13:42 -080065 self->SetTopOfStack(sp, 0);
Ian Rogers306057f2012-11-26 12:45:53 -080066 self->VerifyStack();
Ian Rogers62d6c772013-02-27 08:32:07 -080067 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Andreas Gamped58342c2014-06-05 14:18:08 -070068 TwoWordReturn return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame(
69 self, return_pc, gpr_result, fpr_result);
Ian Rogers62d6c772013-02-27 08:32:07 -080070 self->VerifyStack();
71 return return_or_deoptimize_pc;
jeffhao725a9572012-11-13 18:20:12 -080072}
73
74} // namespace art