blob: d6ba304bd1400e42e2e2d0756daa201bd65ff85d [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
Mathieu Chartiere401d142015-04-22 13:56:20 -070019#include "art_method-inl.h"
Andreas Gampe5c1e4352014-04-21 19:28:24 -070020#include "common_runtime_test.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:
Jeff Hao6d254192015-02-17 18:01:00 -080027 void SetUpRuntimeOptions(RuntimeOptions *options) OVERRIDE {
28 // Use 64-bit ISA for runtime setup to make method size potentially larger
29 // than necessary (rather than smaller) during CreateCalleeSaveMethod
30 options->push_back(std::make_pair("imageinstructionset", "x86_64"));
31 }
32
Andreas Gampe5c1e4352014-04-21 19:28:24 -070033 static void CheckFrameSize(InstructionSet isa, Runtime::CalleeSaveType type, uint32_t save_size)
34 NO_THREAD_SAFETY_ANALYSIS {
Mathieu Chartierf1d666e2015-09-03 16:13:34 -070035 Runtime* const runtime = Runtime::Current();
36 Thread* const self = Thread::Current();
37 ScopedObjectAccess soa(self); // So we can create callee-save methods.
Andreas Gampe5c1e4352014-04-21 19:28:24 -070038
Mathieu Chartierf1d666e2015-09-03 16:13:34 -070039 runtime->SetInstructionSet(isa);
40 ArtMethod* save_method = runtime->CreateCalleeSaveMethod();
41 runtime->SetCalleeSaveMethod(save_method, type);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010042 QuickMethodFrameInfo frame_info = runtime->GetRuntimeMethodFrameInfo(save_method);
Vladimir Marko7624d252014-05-02 14:40:15 +010043 EXPECT_EQ(frame_info.FrameSizeInBytes(), save_size) << "Expected and real size differs for "
44 << type << " core spills=" << std::hex << frame_info.CoreSpillMask() << " fp spills="
45 << frame_info.FpSpillMask() << std::dec;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070046 }
47};
48
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070049// Common tests are declared next to the constants.
50#define ADD_TEST_EQ(x, y) EXPECT_EQ(x, y);
51#include "asm_support.h"
Andreas Gampe5c1e4352014-04-21 19:28:24 -070052
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070053TEST_F(ArchTest, CheckCommonOffsetsAndSizes) {
54 CheckAsmSupportOffsetsAndSizes();
55}
56
57// Grab architecture specific constants.
58namespace arm {
Andreas Gampe5c1e4352014-04-21 19:28:24 -070059#include "arch/arm/asm_support_arm.h"
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070060static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070061#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070062static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070063#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070064static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070065#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070066}
67
68namespace arm64 {
69#include "arch/arm64/asm_support_arm64.h"
70static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
71#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
72static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
73#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
74static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
75#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
76}
77
78namespace mips {
79#include "arch/mips/asm_support_mips.h"
80static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
81#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
82static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
83#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
84static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
85#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
86}
87
Andreas Gampe1a5c4062015-01-15 12:10:47 -080088namespace mips64 {
89#include "arch/mips64/asm_support_mips64.h"
90static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
91#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
92static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
93#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
94static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
95#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
96}
97
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070098namespace x86 {
99#include "arch/x86/asm_support_x86.h"
100static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
101#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
102static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
103#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
104static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
105#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
106}
107
108namespace x86_64 {
109#include "arch/x86_64/asm_support_x86_64.h"
110static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
111#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
112static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
113#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
114static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
115#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
116}
117
118// Check architecture specific constants are sound.
119TEST_F(ArchTest, ARM) {
120 CheckFrameSize(InstructionSet::kArm, Runtime::kSaveAll, arm::kFrameSizeSaveAllCalleeSave);
121 CheckFrameSize(InstructionSet::kArm, Runtime::kRefsOnly, arm::kFrameSizeRefsOnlyCalleeSave);
122 CheckFrameSize(InstructionSet::kArm, Runtime::kRefsAndArgs, arm::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700123}
124
125
126TEST_F(ArchTest, ARM64) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700127 CheckFrameSize(InstructionSet::kArm64, Runtime::kSaveAll, arm64::kFrameSizeSaveAllCalleeSave);
128 CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsOnly, arm64::kFrameSizeRefsOnlyCalleeSave);
129 CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsAndArgs,
130 arm64::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700131}
132
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700133TEST_F(ArchTest, MIPS) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700134 CheckFrameSize(InstructionSet::kMips, Runtime::kSaveAll, mips::kFrameSizeSaveAllCalleeSave);
135 CheckFrameSize(InstructionSet::kMips, Runtime::kRefsOnly, mips::kFrameSizeRefsOnlyCalleeSave);
136 CheckFrameSize(InstructionSet::kMips, Runtime::kRefsAndArgs,
137 mips::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700138}
139
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800140TEST_F(ArchTest, MIPS64) {
141 CheckFrameSize(InstructionSet::kMips64, Runtime::kSaveAll, mips64::kFrameSizeSaveAllCalleeSave);
142 CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsOnly, mips64::kFrameSizeRefsOnlyCalleeSave);
143 CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsAndArgs,
144 mips64::kFrameSizeRefsAndArgsCalleeSave);
145}
146
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700147TEST_F(ArchTest, X86) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700148 CheckFrameSize(InstructionSet::kX86, Runtime::kSaveAll, x86::kFrameSizeSaveAllCalleeSave);
149 CheckFrameSize(InstructionSet::kX86, Runtime::kRefsOnly, x86::kFrameSizeRefsOnlyCalleeSave);
150 CheckFrameSize(InstructionSet::kX86, Runtime::kRefsAndArgs, x86::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700151}
152
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700153TEST_F(ArchTest, X86_64) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700154 CheckFrameSize(InstructionSet::kX86_64, Runtime::kSaveAll, x86_64::kFrameSizeSaveAllCalleeSave);
155 CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsOnly, x86_64::kFrameSizeRefsOnlyCalleeSave);
156 CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsAndArgs,
157 x86_64::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700158}
159
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700160} // namespace art