blob: a85797602155e21ee4644713b1a1246f33d857df [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"
Vladimir Markofd36f1f2016-08-03 18:49:58 +010066static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
67#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
68static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
69#undef FRAME_SIZE_SAVE_REFS_ONLY
70static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
71#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
72static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
73#undef FRAME_SIZE_SAVE_EVERYTHING
Vladimir Marko952dbb12016-07-28 12:01:51 +010074} // namespace arm
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070075
76namespace arm64 {
77#include "arch/arm64/asm_support_arm64.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +010078static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
79#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
80static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
81#undef FRAME_SIZE_SAVE_REFS_ONLY
82static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
83#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
84static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
85#undef FRAME_SIZE_SAVE_EVERYTHING
Vladimir Marko952dbb12016-07-28 12:01:51 +010086} // namespace arm64
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070087
88namespace mips {
89#include "arch/mips/asm_support_mips.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +010090static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
91#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
92static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
93#undef FRAME_SIZE_SAVE_REFS_ONLY
94static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
95#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
96static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
97#undef FRAME_SIZE_SAVE_EVERYTHING
Vladimir Marko952dbb12016-07-28 12:01:51 +010098} // namespace mips
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070099
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800100namespace mips64 {
101#include "arch/mips64/asm_support_mips64.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100102static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
103#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
104static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
105#undef FRAME_SIZE_SAVE_REFS_ONLY
106static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
107#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
108static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
109#undef FRAME_SIZE_SAVE_EVERYTHING
Vladimir Marko952dbb12016-07-28 12:01:51 +0100110} // namespace mips64
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800111
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700112namespace x86 {
113#include "arch/x86/asm_support_x86.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100114static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
115#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
116static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
117#undef FRAME_SIZE_SAVE_REFS_ONLY
118static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
119#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
120static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
121#undef FRAME_SIZE_SAVE_EVERYTHING
Vladimir Marko952dbb12016-07-28 12:01:51 +0100122} // namespace x86
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700123
124namespace x86_64 {
125#include "arch/x86_64/asm_support_x86_64.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100126static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
127#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
128static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
129#undef FRAME_SIZE_SAVE_REFS_ONLY
130static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
131#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
132static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
133#undef FRAME_SIZE_SAVE_EVERYTHING
Vladimir Marko952dbb12016-07-28 12:01:51 +0100134} // namespace x86_64
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700135
136// Check architecture specific constants are sound.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100137#define TEST_ARCH(Arch, arch) \
138 TEST_F(ArchTest, Arch) { \
139 CheckFrameSize(InstructionSet::k##Arch, \
140 Runtime::kSaveAllCalleeSaves, \
141 arch::kFrameSizeSaveAllCalleeSaves); \
142 CheckFrameSize(InstructionSet::k##Arch, \
143 Runtime::kSaveRefsOnly, \
144 arch::kFrameSizeSaveRefsOnly); \
145 CheckFrameSize(InstructionSet::k##Arch, \
146 Runtime::kSaveRefsAndArgs, \
147 arch::kFrameSizeSaveRefsAndArgs); \
148 CheckFrameSize(InstructionSet::k##Arch, \
149 Runtime::kSaveEverything, \
150 arch::kFrameSizeSaveEverything); \
151 }
152TEST_ARCH(Arm, arm)
153TEST_ARCH(Arm64, arm64)
154TEST_ARCH(Mips, mips)
155TEST_ARCH(Mips64, mips64)
156TEST_ARCH(X86, x86)
157TEST_ARCH(X86_64, x86_64)
Andreas Gampecf4035a2014-05-28 22:43:01 -0700158
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700159} // namespace art