blob: 40e2cd340fa140e1935b8c7959c7bb600797169b [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 {
35 Runtime* r = Runtime::Current();
36
37 Thread* t = Thread::Current();
38 t->TransitionFromSuspendedToRunnable(); // So we can create callee-save methods.
39
Vladimir Marko7624d252014-05-02 14:40:15 +010040 r->SetInstructionSet(isa);
Mathieu Chartiere401d142015-04-22 13:56:20 -070041 ArtMethod* save_method = r->CreateCalleeSaveMethod();
Vladimir Marko7624d252014-05-02 14:40:15 +010042 r->SetCalleeSaveMethod(save_method, type);
43 QuickMethodFrameInfo frame_info = save_method->GetQuickFrameInfo();
44 EXPECT_EQ(frame_info.FrameSizeInBytes(), save_size) << "Expected and real size differs for "
45 << type << " core spills=" << std::hex << frame_info.CoreSpillMask() << " fp spills="
46 << frame_info.FpSpillMask() << std::dec;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070047
48 t->TransitionFromRunnableToSuspended(ThreadState::kNative); // So we can shut down.
49 }
50};
51
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070052// Common tests are declared next to the constants.
53#define ADD_TEST_EQ(x, y) EXPECT_EQ(x, y);
54#include "asm_support.h"
Andreas Gampe5c1e4352014-04-21 19:28:24 -070055
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070056TEST_F(ArchTest, CheckCommonOffsetsAndSizes) {
57 CheckAsmSupportOffsetsAndSizes();
58}
59
60// Grab architecture specific constants.
61namespace arm {
Andreas Gampe5c1e4352014-04-21 19:28:24 -070062#include "arch/arm/asm_support_arm.h"
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070063static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070064#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070065static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070066#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070067static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070068#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070069}
70
71namespace arm64 {
72#include "arch/arm64/asm_support_arm64.h"
73static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
74#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
75static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
76#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
77static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
78#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
79}
80
81namespace mips {
82#include "arch/mips/asm_support_mips.h"
83static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
84#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
85static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
86#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
87static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
88#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
89}
90
Andreas Gampe1a5c4062015-01-15 12:10:47 -080091namespace mips64 {
92#include "arch/mips64/asm_support_mips64.h"
93static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
94#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
95static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
96#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
97static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
98#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
99}
100
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700101namespace x86 {
102#include "arch/x86/asm_support_x86.h"
103static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
104#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
105static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
106#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
107static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
108#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
109}
110
111namespace x86_64 {
112#include "arch/x86_64/asm_support_x86_64.h"
113static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
114#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
115static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
116#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
117static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
118#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
119}
120
121// Check architecture specific constants are sound.
122TEST_F(ArchTest, ARM) {
123 CheckFrameSize(InstructionSet::kArm, Runtime::kSaveAll, arm::kFrameSizeSaveAllCalleeSave);
124 CheckFrameSize(InstructionSet::kArm, Runtime::kRefsOnly, arm::kFrameSizeRefsOnlyCalleeSave);
125 CheckFrameSize(InstructionSet::kArm, Runtime::kRefsAndArgs, arm::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700126}
127
128
129TEST_F(ArchTest, ARM64) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700130 CheckFrameSize(InstructionSet::kArm64, Runtime::kSaveAll, arm64::kFrameSizeSaveAllCalleeSave);
131 CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsOnly, arm64::kFrameSizeRefsOnlyCalleeSave);
132 CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsAndArgs,
133 arm64::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700134}
135
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700136TEST_F(ArchTest, MIPS) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700137 CheckFrameSize(InstructionSet::kMips, Runtime::kSaveAll, mips::kFrameSizeSaveAllCalleeSave);
138 CheckFrameSize(InstructionSet::kMips, Runtime::kRefsOnly, mips::kFrameSizeRefsOnlyCalleeSave);
139 CheckFrameSize(InstructionSet::kMips, Runtime::kRefsAndArgs,
140 mips::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700141}
142
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800143TEST_F(ArchTest, MIPS64) {
144 CheckFrameSize(InstructionSet::kMips64, Runtime::kSaveAll, mips64::kFrameSizeSaveAllCalleeSave);
145 CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsOnly, mips64::kFrameSizeRefsOnlyCalleeSave);
146 CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsAndArgs,
147 mips64::kFrameSizeRefsAndArgsCalleeSave);
148}
149
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700150TEST_F(ArchTest, X86) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700151 CheckFrameSize(InstructionSet::kX86, Runtime::kSaveAll, x86::kFrameSizeSaveAllCalleeSave);
152 CheckFrameSize(InstructionSet::kX86, Runtime::kRefsOnly, x86::kFrameSizeRefsOnlyCalleeSave);
153 CheckFrameSize(InstructionSet::kX86, Runtime::kRefsAndArgs, x86::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700154}
155
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700156TEST_F(ArchTest, X86_64) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700157 CheckFrameSize(InstructionSet::kX86_64, Runtime::kSaveAll, x86_64::kFrameSizeSaveAllCalleeSave);
158 CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsOnly, x86_64::kFrameSizeRefsOnlyCalleeSave);
159 CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsAndArgs,
160 x86_64::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700161}
162
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700163} // namespace art