1 /*
2 * Copyright (C) 2014 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 #include <stdint.h>
18
19 #include "art_method-inl.h"
20 #include "common_runtime_test.h"
21 #include "quick/quick_method_frame_info.h"
22 // Common tests are declared next to the constants.
23 #define ADD_TEST_EQ(x, y) EXPECT_EQ(x, y);
24 #include "asm_support.h"
25
26 namespace art {
27
28 class ArchTest : public CommonRuntimeTest {
29 protected:
SetUpRuntimeOptions(RuntimeOptions * options)30 void SetUpRuntimeOptions(RuntimeOptions *options) OVERRIDE {
31 // Use 64-bit ISA for runtime setup to make method size potentially larger
32 // than necessary (rather than smaller) during CreateCalleeSaveMethod
33 options->push_back(std::make_pair("imageinstructionset", "x86_64"));
34 }
35
36 // Do not do any of the finalization. We don't want to run any code, we don't need the heap
37 // prepared, it actually will be a problem with setting the instruction set to x86_64 in
38 // SetUpRuntimeOptions.
FinalizeSetup()39 void FinalizeSetup() OVERRIDE {
40 ASSERT_EQ(InstructionSet::kX86_64, Runtime::Current()->GetInstructionSet());
41 }
42
CheckFrameSize(InstructionSet isa,Runtime::CalleeSaveType type,uint32_t save_size)43 static void CheckFrameSize(InstructionSet isa, Runtime::CalleeSaveType type, uint32_t save_size)
44 NO_THREAD_SAFETY_ANALYSIS {
45 Runtime* const runtime = Runtime::Current();
46 Thread* const self = Thread::Current();
47 ScopedObjectAccess soa(self); // So we can create callee-save methods.
48
49 runtime->SetInstructionSet(isa);
50 ArtMethod* save_method = runtime->CreateCalleeSaveMethod();
51 runtime->SetCalleeSaveMethod(save_method, type);
52 QuickMethodFrameInfo frame_info = runtime->GetRuntimeMethodFrameInfo(save_method);
53 EXPECT_EQ(frame_info.FrameSizeInBytes(), save_size) << "Expected and real size differs for "
54 << type << " core spills=" << std::hex << frame_info.CoreSpillMask() << " fp spills="
55 << frame_info.FpSpillMask() << std::dec;
56 }
57 };
58
TEST_F(ArchTest,CheckCommonOffsetsAndSizes)59 TEST_F(ArchTest, CheckCommonOffsetsAndSizes) {
60 CheckAsmSupportOffsetsAndSizes();
61 }
62
63 // Grab architecture specific constants.
64 namespace arm {
65 #include "arch/arm/asm_support_arm.h"
66 static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
67 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
68 static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
69 #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
70 static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
71 #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
72 }
73
74 namespace arm64 {
75 #include "arch/arm64/asm_support_arm64.h"
76 static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
77 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
78 static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
79 #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
80 static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
81 #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
82 }
83
84 namespace mips {
85 #include "arch/mips/asm_support_mips.h"
86 static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
87 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
88 static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
89 #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
90 static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
91 #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
92 }
93
94 namespace mips64 {
95 #include "arch/mips64/asm_support_mips64.h"
96 static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
97 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
98 static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
99 #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
100 static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
101 #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
102 }
103
104 namespace x86 {
105 #include "arch/x86/asm_support_x86.h"
106 static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
107 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
108 static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
109 #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
110 static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
111 #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
112 }
113
114 namespace x86_64 {
115 #include "arch/x86_64/asm_support_x86_64.h"
116 static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
117 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
118 static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
119 #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
120 static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
121 #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
122 }
123
124 // Check architecture specific constants are sound.
TEST_F(ArchTest,ARM)125 TEST_F(ArchTest, ARM) {
126 CheckFrameSize(InstructionSet::kArm, Runtime::kSaveAll, arm::kFrameSizeSaveAllCalleeSave);
127 CheckFrameSize(InstructionSet::kArm, Runtime::kRefsOnly, arm::kFrameSizeRefsOnlyCalleeSave);
128 CheckFrameSize(InstructionSet::kArm, Runtime::kRefsAndArgs, arm::kFrameSizeRefsAndArgsCalleeSave);
129 }
130
131
TEST_F(ArchTest,ARM64)132 TEST_F(ArchTest, ARM64) {
133 CheckFrameSize(InstructionSet::kArm64, Runtime::kSaveAll, arm64::kFrameSizeSaveAllCalleeSave);
134 CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsOnly, arm64::kFrameSizeRefsOnlyCalleeSave);
135 CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsAndArgs,
136 arm64::kFrameSizeRefsAndArgsCalleeSave);
137 }
138
TEST_F(ArchTest,MIPS)139 TEST_F(ArchTest, MIPS) {
140 CheckFrameSize(InstructionSet::kMips, Runtime::kSaveAll, mips::kFrameSizeSaveAllCalleeSave);
141 CheckFrameSize(InstructionSet::kMips, Runtime::kRefsOnly, mips::kFrameSizeRefsOnlyCalleeSave);
142 CheckFrameSize(InstructionSet::kMips, Runtime::kRefsAndArgs,
143 mips::kFrameSizeRefsAndArgsCalleeSave);
144 }
145
TEST_F(ArchTest,MIPS64)146 TEST_F(ArchTest, MIPS64) {
147 CheckFrameSize(InstructionSet::kMips64, Runtime::kSaveAll, mips64::kFrameSizeSaveAllCalleeSave);
148 CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsOnly, mips64::kFrameSizeRefsOnlyCalleeSave);
149 CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsAndArgs,
150 mips64::kFrameSizeRefsAndArgsCalleeSave);
151 }
152
TEST_F(ArchTest,X86)153 TEST_F(ArchTest, X86) {
154 CheckFrameSize(InstructionSet::kX86, Runtime::kSaveAll, x86::kFrameSizeSaveAllCalleeSave);
155 CheckFrameSize(InstructionSet::kX86, Runtime::kRefsOnly, x86::kFrameSizeRefsOnlyCalleeSave);
156 CheckFrameSize(InstructionSet::kX86, Runtime::kRefsAndArgs, x86::kFrameSizeRefsAndArgsCalleeSave);
157 }
158
TEST_F(ArchTest,X86_64)159 TEST_F(ArchTest, X86_64) {
160 CheckFrameSize(InstructionSet::kX86_64, Runtime::kSaveAll, x86_64::kFrameSizeSaveAllCalleeSave);
161 CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsOnly, x86_64::kFrameSizeRefsOnlyCalleeSave);
162 CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsAndArgs,
163 x86_64::kFrameSizeRefsAndArgsCalleeSave);
164 }
165
166 } // namespace art
167