blob: ab6b00bddf15cf66bfd3ee7d568de987d3afb8d8 [file] [log] [blame]
Andreas Gampe5c1e4352014-04-21 19:28:24 -07001/*
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 "common_runtime_test.h"
Vladimir Markoc0480ef2014-05-13 17:45:46 +010020#include "mirror/art_method-inl.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010021#include "quick/quick_method_frame_info.h"
Andreas Gampe5c1e4352014-04-21 19:28:24 -070022
23namespace art {
24
25class ArchTest : public CommonRuntimeTest {
26 protected:
27 static void CheckFrameSize(InstructionSet isa, Runtime::CalleeSaveType type, uint32_t save_size)
28 NO_THREAD_SAFETY_ANALYSIS {
29 Runtime* r = Runtime::Current();
30
31 Thread* t = Thread::Current();
32 t->TransitionFromSuspendedToRunnable(); // So we can create callee-save methods.
33
Vladimir Marko7624d252014-05-02 14:40:15 +010034 r->SetInstructionSet(isa);
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070035 mirror::ArtMethod* save_method = r->CreateCalleeSaveMethod();
Vladimir Marko7624d252014-05-02 14:40:15 +010036 r->SetCalleeSaveMethod(save_method, type);
37 QuickMethodFrameInfo frame_info = save_method->GetQuickFrameInfo();
38 EXPECT_EQ(frame_info.FrameSizeInBytes(), save_size) << "Expected and real size differs for "
39 << type << " core spills=" << std::hex << frame_info.CoreSpillMask() << " fp spills="
40 << frame_info.FpSpillMask() << std::dec;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070041
42 t->TransitionFromRunnableToSuspended(ThreadState::kNative); // So we can shut down.
43 }
44};
45
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070046// Common tests are declared next to the constants.
47#define ADD_TEST_EQ(x, y) EXPECT_EQ(x, y);
48#include "asm_support.h"
Andreas Gampe5c1e4352014-04-21 19:28:24 -070049
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070050TEST_F(ArchTest, CheckCommonOffsetsAndSizes) {
51 CheckAsmSupportOffsetsAndSizes();
52}
53
54// Grab architecture specific constants.
55namespace arm {
Andreas Gampe5c1e4352014-04-21 19:28:24 -070056#include "arch/arm/asm_support_arm.h"
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070057static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070058#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070059static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070060#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070061static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070062#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070063}
64
65namespace arm64 {
66#include "arch/arm64/asm_support_arm64.h"
67static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
68#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
69static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
70#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
71static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
72#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
73}
74
75namespace mips {
76#include "arch/mips/asm_support_mips.h"
77static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
78#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
79static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
80#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
81static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
82#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
83}
84
Andreas Gampe1a5c4062015-01-15 12:10:47 -080085namespace mips64 {
86#include "arch/mips64/asm_support_mips64.h"
87static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
88#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
89static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
90#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
91static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
92#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
93}
94
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070095namespace x86 {
96#include "arch/x86/asm_support_x86.h"
97static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
98#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
99static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
100#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
101static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
102#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
103}
104
105namespace x86_64 {
106#include "arch/x86_64/asm_support_x86_64.h"
107static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
108#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
109static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
110#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
111static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
112#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
113}
114
115// Check architecture specific constants are sound.
116TEST_F(ArchTest, ARM) {
117 CheckFrameSize(InstructionSet::kArm, Runtime::kSaveAll, arm::kFrameSizeSaveAllCalleeSave);
118 CheckFrameSize(InstructionSet::kArm, Runtime::kRefsOnly, arm::kFrameSizeRefsOnlyCalleeSave);
119 CheckFrameSize(InstructionSet::kArm, Runtime::kRefsAndArgs, arm::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700120}
121
122
123TEST_F(ArchTest, ARM64) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700124 CheckFrameSize(InstructionSet::kArm64, Runtime::kSaveAll, arm64::kFrameSizeSaveAllCalleeSave);
125 CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsOnly, arm64::kFrameSizeRefsOnlyCalleeSave);
126 CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsAndArgs,
127 arm64::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700128}
129
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700130TEST_F(ArchTest, MIPS) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700131 CheckFrameSize(InstructionSet::kMips, Runtime::kSaveAll, mips::kFrameSizeSaveAllCalleeSave);
132 CheckFrameSize(InstructionSet::kMips, Runtime::kRefsOnly, mips::kFrameSizeRefsOnlyCalleeSave);
133 CheckFrameSize(InstructionSet::kMips, Runtime::kRefsAndArgs,
134 mips::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700135}
136
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800137TEST_F(ArchTest, MIPS64) {
138 CheckFrameSize(InstructionSet::kMips64, Runtime::kSaveAll, mips64::kFrameSizeSaveAllCalleeSave);
139 CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsOnly, mips64::kFrameSizeRefsOnlyCalleeSave);
140 CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsAndArgs,
141 mips64::kFrameSizeRefsAndArgsCalleeSave);
142}
143
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700144TEST_F(ArchTest, X86) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700145 CheckFrameSize(InstructionSet::kX86, Runtime::kSaveAll, x86::kFrameSizeSaveAllCalleeSave);
146 CheckFrameSize(InstructionSet::kX86, Runtime::kRefsOnly, x86::kFrameSizeRefsOnlyCalleeSave);
147 CheckFrameSize(InstructionSet::kX86, Runtime::kRefsAndArgs, x86::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700148}
149
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700150TEST_F(ArchTest, X86_64) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700151 CheckFrameSize(InstructionSet::kX86_64, Runtime::kSaveAll, x86_64::kFrameSizeSaveAllCalleeSave);
152 CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsOnly, x86_64::kFrameSizeRefsOnlyCalleeSave);
153 CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsAndArgs,
154 x86_64::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700155}
156
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700157} // namespace art