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