blob: e728f7dd11c731d67c35d410956a96e8c893aa42 [file] [log] [blame]
Ian Rogers57b86d42012-03-27 16:05:41 -07001/*
Elliott Hughes0f3c5532012-03-30 14:51:51 -07002 * Copyright (C) 2012 The Android Open Source Project
Ian Rogers57b86d42012-03-27 16:05:41 -07003 *
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 Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
18#define ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
Ian Rogers57b86d42012-03-27 16:05:41 -070019
Elliott Hughes76b61672012-12-12 17:47:30 -080020#include "base/mutex.h"
Mathieu Chartier76433272014-09-26 14:32:37 -070021#include "gc_root-inl.h"
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070022#include "instruction_set.h"
Mathieu Chartier76433272014-09-26 14:32:37 -070023#include "runtime-inl.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070024#include "thread-inl.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070025
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070026// Specific frame size code is in architecture-specific files. We include this to compile-time
27// specialize the code.
28#include "arch/arm/quick_method_frame_info_arm.h"
29#include "arch/arm64/quick_method_frame_info_arm64.h"
30#include "arch/mips/quick_method_frame_info_mips.h"
31#include "arch/x86/quick_method_frame_info_x86.h"
32#include "arch/x86_64/quick_method_frame_info_x86_64.h"
33
Ian Rogers57b86d42012-03-27 16:05:41 -070034namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035namespace mirror {
Brian Carlstromea46f952013-07-30 01:26:50 -070036class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037} // namespace mirror
Ian Rogers57b86d42012-03-27 16:05:41 -070038
Ian Rogers00f7d0e2012-07-19 15:28:27 -070039// Place a special frame at the TOS that will save the callee saves for the given type.
Andreas Gampecf4035a2014-05-28 22:43:01 -070040static inline void FinishCalleeSaveFrameSetup(Thread* self, StackReference<mirror::ArtMethod>* sp,
Ian Rogers719d1a32014-03-06 12:13:39 -080041 Runtime::CalleeSaveType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -070042 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070043 // Be aware the store below may well stomp on an incoming argument.
Ian Rogers81d425b2012-09-27 16:03:43 -070044 Locks::mutator_lock_->AssertSharedHeld(self);
Andreas Gampecf4035a2014-05-28 22:43:01 -070045 sp->Assign(Runtime::Current()->GetCalleeSaveMethod(type));
Ian Rogers57b86d42012-03-27 16:05:41 -070046 self->SetTopOfStack(sp, 0);
47 self->VerifyStack();
48}
49
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070050static constexpr size_t GetCalleeSaveFrameSize(InstructionSet isa, Runtime::CalleeSaveType type) {
51 // constexpr must be a return statement.
52 return (isa == kArm || isa == kThumb2) ? arm::ArmCalleeSaveFrameSize(type) :
53 isa == kArm64 ? arm64::Arm64CalleeSaveFrameSize(type) :
54 isa == kMips ? mips::MipsCalleeSaveFrameSize(type) :
55 isa == kX86 ? x86::X86CalleeSaveFrameSize(type) :
56 isa == kX86_64 ? x86_64::X86_64CalleeSaveFrameSize(type) :
57 isa == kNone ? (LOG(FATAL) << "kNone has no frame size", 0) :
58 (LOG(FATAL) << "Unknown instruction set" << isa, 0);
59}
60
61// Note: this specialized statement is sanity-checked in the quick-trampoline gtest.
62static constexpr size_t GetConstExprPointerSize(InstructionSet isa) {
63 // constexpr must be a return statement.
64 return (isa == kArm || isa == kThumb2) ? kArmPointerSize :
65 isa == kArm64 ? kArm64PointerSize :
66 isa == kMips ? kMipsPointerSize :
67 isa == kX86 ? kX86PointerSize :
68 isa == kX86_64 ? kX86_64PointerSize :
69 isa == kNone ? (LOG(FATAL) << "kNone has no pointer size", 0) :
70 (LOG(FATAL) << "Unknown instruction set" << isa, 0);
71}
72
73// Note: this specialized statement is sanity-checked in the quick-trampoline gtest.
74static constexpr size_t GetCalleeSavePCOffset(InstructionSet isa, Runtime::CalleeSaveType type) {
75 return GetCalleeSaveFrameSize(isa, type) - GetConstExprPointerSize(isa);
76}
77
Ian Rogers57b86d42012-03-27 16:05:41 -070078} // namespace art
79
Ian Rogers166db042013-07-26 12:05:57 -070080#endif // ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_