blob: bfac8c422dd3b271516ad9a3d86c765de0aa5bb7 [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 Gampe8228cdf2017-05-30 15:03:54 -070020#include "base/callee_save_type.h"
Andreas Gampe5c1e4352014-04-21 19:28:24 -070021#include "common_runtime_test.h"
Vladimir Marko7624d252014-05-02 14:40:15 +010022#include "quick/quick_method_frame_info.h"
Andreas Gampeb2d18fa2017-06-06 20:46:10 -070023
Andreas Gampeb2d18fa2017-06-06 20:46:10 -070024// asm_support.h declares tests next to the #defines. We use asm_support_check.h to (safely)
25// generate CheckAsmSupportOffsetsAndSizes using gtest's EXPECT for the tests. We also use the
26// RETURN_TYPE, HEADER and FOOTER defines from asm_support_check.h to try to ensure that any
27// tests are actually generated.
28
29// Let CheckAsmSupportOffsetsAndSizes return a size_t (the count).
30#define ASM_SUPPORT_CHECK_RETURN_TYPE size_t
31
32// Declare the counter that will be updated per test.
33#define ASM_SUPPORT_CHECK_HEADER size_t count = 0;
34
35// Use EXPECT_EQ for tests, and increment the counter.
36#define ADD_TEST_EQ(x, y) EXPECT_EQ(x, y); count++;
37
38// Return the counter at the end of CheckAsmSupportOffsetsAndSizes.
39#define ASM_SUPPORT_CHECK_FOOTER return count;
40
41// Generate CheckAsmSupportOffsetsAndSizes().
42#include "asm_support_check.h"
Andreas Gampe5c1e4352014-04-21 19:28:24 -070043
44namespace art {
45
46class ArchTest : public CommonRuntimeTest {
47 protected:
Jeff Hao6d254192015-02-17 18:01:00 -080048 void SetUpRuntimeOptions(RuntimeOptions *options) OVERRIDE {
49 // Use 64-bit ISA for runtime setup to make method size potentially larger
50 // than necessary (rather than smaller) during CreateCalleeSaveMethod
51 options->push_back(std::make_pair("imageinstructionset", "x86_64"));
52 }
53
Andreas Gampea00f0122015-12-16 16:54:35 -080054 // Do not do any of the finalization. We don't want to run any code, we don't need the heap
55 // prepared, it actually will be a problem with setting the instruction set to x86_64 in
56 // SetUpRuntimeOptions.
57 void FinalizeSetup() OVERRIDE {
58 ASSERT_EQ(InstructionSet::kX86_64, Runtime::Current()->GetInstructionSet());
59 }
60
Andreas Gampe8228cdf2017-05-30 15:03:54 -070061 static void CheckFrameSize(InstructionSet isa, CalleeSaveType type, uint32_t save_size)
Andreas Gampe5c1e4352014-04-21 19:28:24 -070062 NO_THREAD_SAFETY_ANALYSIS {
Mathieu Chartierf1d666e2015-09-03 16:13:34 -070063 Runtime* const runtime = Runtime::Current();
64 Thread* const self = Thread::Current();
65 ScopedObjectAccess soa(self); // So we can create callee-save methods.
Andreas Gampe5c1e4352014-04-21 19:28:24 -070066
Mathieu Chartierf1d666e2015-09-03 16:13:34 -070067 runtime->SetInstructionSet(isa);
68 ArtMethod* save_method = runtime->CreateCalleeSaveMethod();
69 runtime->SetCalleeSaveMethod(save_method, type);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010070 QuickMethodFrameInfo frame_info = runtime->GetRuntimeMethodFrameInfo(save_method);
Vladimir Marko7624d252014-05-02 14:40:15 +010071 EXPECT_EQ(frame_info.FrameSizeInBytes(), save_size) << "Expected and real size differs for "
72 << type << " core spills=" << std::hex << frame_info.CoreSpillMask() << " fp spills="
73 << frame_info.FpSpillMask() << std::dec;
Andreas Gampe5c1e4352014-04-21 19:28:24 -070074 }
75};
76
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070077TEST_F(ArchTest, CheckCommonOffsetsAndSizes) {
Andreas Gampeb2d18fa2017-06-06 20:46:10 -070078 size_t test_count = CheckAsmSupportOffsetsAndSizes();
79 EXPECT_GT(test_count, 0u);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070080}
81
82// Grab architecture specific constants.
83namespace arm {
Andreas Gampe5c1e4352014-04-21 19:28:24 -070084#include "arch/arm/asm_support_arm.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +010085static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
86#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
87static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
88#undef FRAME_SIZE_SAVE_REFS_ONLY
89static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
90#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
91static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
92#undef FRAME_SIZE_SAVE_EVERYTHING
Vladimir Marko88abba22017-05-03 17:09:25 +010093#undef BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET
94#undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET
95#undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET
Vladimir Markoeee1c0e2017-04-21 17:58:41 +010096#undef BAKER_MARK_INTROSPECTION_ARRAY_SWITCH_OFFSET
Vladimir Marko88abba22017-05-03 17:09:25 +010097#undef BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET
98#undef BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET
Vladimir Markoeee1c0e2017-04-21 17:58:41 +010099#undef BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET
Vladimir Marko88abba22017-05-03 17:09:25 +0100100#undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET
101#undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET
Vladimir Marko952dbb12016-07-28 12:01:51 +0100102} // namespace arm
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700103
104namespace arm64 {
105#include "arch/arm64/asm_support_arm64.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100106static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
107#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
108static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
109#undef FRAME_SIZE_SAVE_REFS_ONLY
110static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
111#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
112static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
113#undef FRAME_SIZE_SAVE_EVERYTHING
Vladimir Markoeee1c0e2017-04-21 17:58:41 +0100114#undef BAKER_MARK_INTROSPECTION_ARRAY_SWITCH_OFFSET
115#undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET
116#undef BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET
117#undef BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET
118#undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET
Vladimir Marko952dbb12016-07-28 12:01:51 +0100119} // namespace arm64
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700120
121namespace mips {
122#include "arch/mips/asm_support_mips.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100123static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
124#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
125static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
126#undef FRAME_SIZE_SAVE_REFS_ONLY
127static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
128#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
129static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
130#undef FRAME_SIZE_SAVE_EVERYTHING
Alexey Frunze4147fcc2017-06-17 19:57:27 -0700131#undef BAKER_MARK_INTROSPECTION_REGISTER_COUNT
132#undef BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE
133#undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET
134#undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE
Vladimir Marko952dbb12016-07-28 12:01:51 +0100135} // namespace mips
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700136
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800137namespace mips64 {
138#include "arch/mips64/asm_support_mips64.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100139static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
140#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
141static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
142#undef FRAME_SIZE_SAVE_REFS_ONLY
143static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
144#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
145static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
146#undef FRAME_SIZE_SAVE_EVERYTHING
Alexey Frunze4147fcc2017-06-17 19:57:27 -0700147#undef BAKER_MARK_INTROSPECTION_REGISTER_COUNT
148#undef BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE
149#undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET
150#undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE
Vladimir Marko952dbb12016-07-28 12:01:51 +0100151} // namespace mips64
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800152
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700153namespace x86 {
154#include "arch/x86/asm_support_x86.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100155static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
156#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
157static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
158#undef FRAME_SIZE_SAVE_REFS_ONLY
159static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
160#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
161static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
162#undef FRAME_SIZE_SAVE_EVERYTHING
Vladimir Marko952dbb12016-07-28 12:01:51 +0100163} // namespace x86
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700164
165namespace x86_64 {
166#include "arch/x86_64/asm_support_x86_64.h"
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100167static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
168#undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
169static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
170#undef FRAME_SIZE_SAVE_REFS_ONLY
171static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
172#undef FRAME_SIZE_SAVE_REFS_AND_ARGS
173static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
174#undef FRAME_SIZE_SAVE_EVERYTHING
Vladimir Marko952dbb12016-07-28 12:01:51 +0100175} // namespace x86_64
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700176
177// Check architecture specific constants are sound.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100178#define TEST_ARCH(Arch, arch) \
179 TEST_F(ArchTest, Arch) { \
180 CheckFrameSize(InstructionSet::k##Arch, \
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700181 CalleeSaveType::kSaveAllCalleeSaves, \
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100182 arch::kFrameSizeSaveAllCalleeSaves); \
183 CheckFrameSize(InstructionSet::k##Arch, \
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700184 CalleeSaveType::kSaveRefsOnly, \
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100185 arch::kFrameSizeSaveRefsOnly); \
186 CheckFrameSize(InstructionSet::k##Arch, \
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700187 CalleeSaveType::kSaveRefsAndArgs, \
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100188 arch::kFrameSizeSaveRefsAndArgs); \
189 CheckFrameSize(InstructionSet::k##Arch, \
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700190 CalleeSaveType::kSaveEverything, \
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100191 arch::kFrameSizeSaveEverything); \
192 }
193TEST_ARCH(Arm, arm)
194TEST_ARCH(Arm64, arm64)
195TEST_ARCH(Mips, mips)
196TEST_ARCH(Mips64, mips64)
197TEST_ARCH(X86, x86)
198TEST_ARCH(X86_64, x86_64)
Andreas Gampecf4035a2014-05-28 22:43:01 -0700199
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700200} // namespace art