blob: ee31c589795d6470e7ca7bd07a60131e721fdd73 [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"
buzbee69dd2ed2016-03-21 15:11:04 -070022// Common tests are declared next to the constants.
23#define ADD_TEST_EQ(x, y) EXPECT_EQ(x, y);
24#include "asm_support.h"
Andreas Gampe5c1e4352014-04-21 19:28:24 -070025
26namespace art {
27
28class ArchTest : public CommonRuntimeTest {
29 protected:
Jeff Hao6d254192015-02-17 18:01:00 -080030 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
Andreas Gampea00f0122015-12-16 16:54:35 -080036 // 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.
39 void FinalizeSetup() OVERRIDE {
40 ASSERT_EQ(InstructionSet::kX86_64, Runtime::Current()->GetInstructionSet());
41 }
42
Andreas Gampe5c1e4352014-04-21 19:28:24 -070043 static void CheckFrameSize(InstructionSet isa, Runtime::CalleeSaveType type, uint32_t save_size)
44 NO_THREAD_SAFETY_ANALYSIS {
Mathieu Chartierf1d666e2015-09-03 16:13:34 -070045 Runtime* const runtime = Runtime::Current();
46 Thread* const self = Thread::Current();
47 ScopedObjectAccess soa(self); // So we can create callee-save methods.
Andreas Gampe5c1e4352014-04-21 19:28:24 -070048
Mathieu Chartierf1d666e2015-09-03 16:13:34 -070049 runtime->SetInstructionSet(isa);
50 ArtMethod* save_method = runtime->CreateCalleeSaveMethod();
51 runtime->SetCalleeSaveMethod(save_method, type);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010052 QuickMethodFrameInfo frame_info = runtime->GetRuntimeMethodFrameInfo(save_method);
Vladimir Marko7624d252014-05-02 14:40:15 +010053 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;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070056 }
57};
58
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070059TEST_F(ArchTest, CheckCommonOffsetsAndSizes) {
60 CheckAsmSupportOffsetsAndSizes();
61}
62
63// Grab architecture specific constants.
64namespace arm {
Andreas Gampe5c1e4352014-04-21 19:28:24 -070065#include "arch/arm/asm_support_arm.h"
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070066static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070067#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070068static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070069#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070070static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070071#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070072}
73
74namespace arm64 {
75#include "arch/arm64/asm_support_arm64.h"
76static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
77#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
78static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
79#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
80static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
81#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
82}
83
84namespace mips {
85#include "arch/mips/asm_support_mips.h"
86static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
87#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
88static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
89#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
90static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
91#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
92}
93
Andreas Gampe1a5c4062015-01-15 12:10:47 -080094namespace mips64 {
95#include "arch/mips64/asm_support_mips64.h"
96static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
97#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
98static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
99#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
100static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
101#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
102}
103
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700104namespace x86 {
105#include "arch/x86/asm_support_x86.h"
106static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
107#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
108static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
109#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
110static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE;
111#undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE
112}
113
114namespace x86_64 {
115#include "arch/x86_64/asm_support_x86_64.h"
116static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE;
117#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE
118static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE;
119#undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE
120static 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.
125TEST_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);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700129}
130
131
132TEST_F(ArchTest, ARM64) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700133 CheckFrameSize(InstructionSet::kArm64, Runtime::kSaveAll, arm64::kFrameSizeSaveAllCalleeSave);
134 CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsOnly, arm64::kFrameSizeRefsOnlyCalleeSave);
135 CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsAndArgs,
136 arm64::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700137}
138
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700139TEST_F(ArchTest, MIPS) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700140 CheckFrameSize(InstructionSet::kMips, Runtime::kSaveAll, mips::kFrameSizeSaveAllCalleeSave);
141 CheckFrameSize(InstructionSet::kMips, Runtime::kRefsOnly, mips::kFrameSizeRefsOnlyCalleeSave);
142 CheckFrameSize(InstructionSet::kMips, Runtime::kRefsAndArgs,
143 mips::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700144}
145
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800146TEST_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
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700153TEST_F(ArchTest, X86) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700154 CheckFrameSize(InstructionSet::kX86, Runtime::kSaveAll, x86::kFrameSizeSaveAllCalleeSave);
155 CheckFrameSize(InstructionSet::kX86, Runtime::kRefsOnly, x86::kFrameSizeRefsOnlyCalleeSave);
156 CheckFrameSize(InstructionSet::kX86, Runtime::kRefsAndArgs, x86::kFrameSizeRefsAndArgsCalleeSave);
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700157}
158
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700159TEST_F(ArchTest, X86_64) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700160 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);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700164}
165
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700166} // namespace art