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/x86/callee_save_frame_x86.h"
32 #include "arch/x86_64/callee_save_frame_x86_64.h"
33 
34 namespace art {
35 class ArtMethod;
36 
37 class ScopedQuickEntrypointChecks {
38  public:
39   explicit ScopedQuickEntrypointChecks(Thread *self,
40                                        bool entry_check = kIsDebugBuild,
41                                        bool exit_check = kIsDebugBuild)
REQUIRES_SHARED(Locks::mutator_lock_)42       REQUIRES_SHARED(Locks::mutator_lock_) : self_(self), exit_check_(exit_check) {
43     if (entry_check) {
44       TestsOnEntry();
45     }
46   }
47 
REQUIRES_SHARED(Locks::mutator_lock_)48   ~ScopedQuickEntrypointChecks() REQUIRES_SHARED(Locks::mutator_lock_) {
49     if (exit_check_) {
50       TestsOnExit();
51     }
52   }
53 
54  private:
TestsOnEntry()55   void TestsOnEntry() REQUIRES_SHARED(Locks::mutator_lock_) {
56     Locks::mutator_lock_->AssertSharedHeld(self_);
57     self_->VerifyStack();
58   }
59 
TestsOnExit()60   void TestsOnExit() REQUIRES_SHARED(Locks::mutator_lock_) {
61     Locks::mutator_lock_->AssertSharedHeld(self_);
62     self_->VerifyStack();
63   }
64 
65   Thread* const self_;
66   bool exit_check_;
67 };
68 
69 namespace detail {
70 
71 template <InstructionSet>
72 struct CSFSelector;  // No definition for unspecialized callee save frame selector.
73 
74 // Note: kThumb2 is never the kRuntimeISA.
75 template <>
76 struct CSFSelector<InstructionSet::kArm> { using type = arm::ArmCalleeSaveFrame; };
77 template <>
78 struct CSFSelector<InstructionSet::kArm64> { using type = arm64::Arm64CalleeSaveFrame; };
79 template <>
80 struct CSFSelector<InstructionSet::kX86> { using type = x86::X86CalleeSaveFrame; };
81 template <>
82 struct CSFSelector<InstructionSet::kX86_64> { using type = x86_64::X86_64CalleeSaveFrame; };
83 
84 }  // namespace detail
85 
86 using RuntimeCalleeSaveFrame = detail::CSFSelector<kRuntimeISA>::type;
87 
88 }  // namespace art
89 
90 #endif  // ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
91