1 /*
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 
17 #ifndef ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
18 #define ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
19 
20 #include "arch/instruction_set.h"
21 #include "base/callee_save_type.h"
22 #include "base/enums.h"
23 #include "base/locks.h"
24 #include "quick/quick_method_frame_info.h"
25 #include "thread-inl.h"
26 
27 // Specific frame size code is in architecture-specific files. We include this to compile-time
28 // specialize the code.
29 #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"
35 
36 namespace art {
37 class ArtMethod;
38 
39 class ScopedQuickEntrypointChecks {
40  public:
41   explicit ScopedQuickEntrypointChecks(Thread *self,
42                                        bool entry_check = kIsDebugBuild,
43                                        bool exit_check = kIsDebugBuild)
REQUIRES_SHARED(Locks::mutator_lock_)44       REQUIRES_SHARED(Locks::mutator_lock_) : self_(self), exit_check_(exit_check) {
45     if (entry_check) {
46       TestsOnEntry();
47     }
48   }
49 
REQUIRES_SHARED(Locks::mutator_lock_)50   ~ScopedQuickEntrypointChecks() REQUIRES_SHARED(Locks::mutator_lock_) {
51     if (exit_check_) {
52       TestsOnExit();
53     }
54   }
55 
56  private:
TestsOnEntry()57   void TestsOnEntry() REQUIRES_SHARED(Locks::mutator_lock_) {
58     Locks::mutator_lock_->AssertSharedHeld(self_);
59     self_->VerifyStack();
60   }
61 
TestsOnExit()62   void TestsOnExit() REQUIRES_SHARED(Locks::mutator_lock_) {
63     Locks::mutator_lock_->AssertSharedHeld(self_);
64     self_->VerifyStack();
65   }
66 
67   Thread* const self_;
68   bool exit_check_;
69 };
70 
71 namespace detail {
72 
73 template <InstructionSet>
74 struct CSFSelector;  // No definition for unspecialized callee save frame selector.
75 
76 // Note: kThumb2 is never the kRuntimeISA.
77 template <>
78 struct CSFSelector<InstructionSet::kArm> { using type = arm::ArmCalleeSaveFrame; };
79 template <>
80 struct CSFSelector<InstructionSet::kArm64> { using type = arm64::Arm64CalleeSaveFrame; };
81 template <>
82 struct CSFSelector<InstructionSet::kMips> { using type = mips::MipsCalleeSaveFrame; };
83 template <>
84 struct CSFSelector<InstructionSet::kMips64> { using type = mips64::Mips64CalleeSaveFrame; };
85 template <>
86 struct CSFSelector<InstructionSet::kX86> { using type = x86::X86CalleeSaveFrame; };
87 template <>
88 struct CSFSelector<InstructionSet::kX86_64> { using type = x86_64::X86_64CalleeSaveFrame; };
89 
90 }  // namespace detail
91 
92 using RuntimeCalleeSaveFrame = detail::CSFSelector<kRuntimeISA>::type;
93 
94 }  // namespace art
95 
96 #endif  // ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
97