blob: 1e309071f6ec6d7904c01dd22f815afcb881af46 [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
Ian Rogersd582fa42014-11-05 23:46:43 -080020#include "arch/instruction_set.h"
Andreas Gampe8228cdf2017-05-30 15:03:54 -070021#include "base/callee_save_type.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070022#include "base/enums.h"
Elliott Hughes76b61672012-12-12 17:47:30 -080023#include "base/mutex.h"
Vladimir Markod3083dd2018-05-17 08:43:47 +010024#include "quick/quick_method_frame_info.h"
Andreas Gampe8228cdf2017-05-30 15:03:54 -070025#include "thread-inl.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070026
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070027// Specific frame size code is in architecture-specific files. We include this to compile-time
28// specialize the code.
Vladimir Markod3083dd2018-05-17 08:43:47 +010029#include "arch/arm/callee_save_frame_arm.h"
30#include "arch/arm64/callee_save_frame_arm64.h"
31#include "arch/mips/callee_save_frame_mips.h"
32#include "arch/mips64/callee_save_frame_mips64.h"
33#include "arch/x86/callee_save_frame_x86.h"
34#include "arch/x86_64/callee_save_frame_x86_64.h"
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070035
Ian Rogers57b86d42012-03-27 16:05:41 -070036namespace art {
Brian Carlstromea46f952013-07-30 01:26:50 -070037class ArtMethod;
Ian Rogers57b86d42012-03-27 16:05:41 -070038
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070039class ScopedQuickEntrypointChecks {
40 public:
Andreas Gampe3b45ef22015-05-26 21:34:09 -070041 explicit ScopedQuickEntrypointChecks(Thread *self,
42 bool entry_check = kIsDebugBuild,
43 bool exit_check = kIsDebugBuild)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070044 REQUIRES_SHARED(Locks::mutator_lock_) : self_(self), exit_check_(exit_check) {
Andreas Gampe3b45ef22015-05-26 21:34:09 -070045 if (entry_check) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070046 TestsOnEntry();
47 }
48 }
49
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070050 ~ScopedQuickEntrypointChecks() REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe3b45ef22015-05-26 21:34:09 -070051 if (exit_check_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070052 TestsOnExit();
53 }
54 }
55
56 private:
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070057 void TestsOnEntry() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070058 Locks::mutator_lock_->AssertSharedHeld(self_);
59 self_->VerifyStack();
60 }
61
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070062 void TestsOnExit() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070063 Locks::mutator_lock_->AssertSharedHeld(self_);
64 self_->VerifyStack();
65 }
66
67 Thread* const self_;
Andreas Gampe3b45ef22015-05-26 21:34:09 -070068 bool exit_check_;
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070069};
Ian Rogers57b86d42012-03-27 16:05:41 -070070
Vladimir Markob4eb1b12018-05-24 11:09:38 +010071namespace detail {
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070072
Vladimir Markod3083dd2018-05-17 08:43:47 +010073template <InstructionSet>
74struct CSFSelector; // No definition for unspecialized callee save frame selector.
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070075
Vladimir Markod3083dd2018-05-17 08:43:47 +010076// Note: kThumb2 is never the kRuntimeISA.
77template <>
78struct CSFSelector<InstructionSet::kArm> { using type = arm::ArmCalleeSaveFrame; };
79template <>
80struct CSFSelector<InstructionSet::kArm64> { using type = arm64::Arm64CalleeSaveFrame; };
81template <>
82struct CSFSelector<InstructionSet::kMips> { using type = mips::MipsCalleeSaveFrame; };
83template <>
84struct CSFSelector<InstructionSet::kMips64> { using type = mips64::Mips64CalleeSaveFrame; };
85template <>
86struct CSFSelector<InstructionSet::kX86> { using type = x86::X86CalleeSaveFrame; };
87template <>
88struct CSFSelector<InstructionSet::kX86_64> { using type = x86_64::X86_64CalleeSaveFrame; };
89
Vladimir Markob4eb1b12018-05-24 11:09:38 +010090} // namespace detail
Vladimir Markod3083dd2018-05-17 08:43:47 +010091
Vladimir Markob4eb1b12018-05-24 11:09:38 +010092using RuntimeCalleeSaveFrame = detail::CSFSelector<kRuntimeISA>::type;
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070093
Ian Rogers57b86d42012-03-27 16:05:41 -070094} // namespace art
95
Ian Rogers166db042013-07-26 12:05:57 -070096#endif // ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_