| Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 1 | /* |
| 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 Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method-inl.h" |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 20 | #include "base/callee_save_type.h" |
| Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 21 | #include "common_runtime_test.h" |
| Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 22 | #include "quick/quick_method_frame_info.h" |
| Andreas Gampe | b2d18fa | 2017-06-06 20:46:10 -0700 | [diff] [blame] | 23 | |
| Andreas Gampe | b2d18fa | 2017-06-06 20:46:10 -0700 | [diff] [blame] | 24 | // 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 Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 43 | |
| 44 | namespace art { |
| 45 | |
| 46 | class ArchTest : public CommonRuntimeTest { |
| 47 | protected: |
| Jeff Hao | 6d25419 | 2015-02-17 18:01:00 -0800 | [diff] [blame] | 48 | 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 Gampe | a00f012 | 2015-12-16 16:54:35 -0800 | [diff] [blame] | 54 | // 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 Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 61 | static void CheckFrameSize(InstructionSet isa, CalleeSaveType type, uint32_t save_size) |
| Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 62 | NO_THREAD_SAFETY_ANALYSIS { |
| Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 63 | Runtime* const runtime = Runtime::Current(); |
| 64 | Thread* const self = Thread::Current(); |
| 65 | ScopedObjectAccess soa(self); // So we can create callee-save methods. |
| Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 66 | |
| Mathieu Chartier | f1d666e | 2015-09-03 16:13:34 -0700 | [diff] [blame] | 67 | runtime->SetInstructionSet(isa); |
| 68 | ArtMethod* save_method = runtime->CreateCalleeSaveMethod(); |
| 69 | runtime->SetCalleeSaveMethod(save_method, type); |
| Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 70 | QuickMethodFrameInfo frame_info = runtime->GetRuntimeMethodFrameInfo(save_method); |
| Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 71 | 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 Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 74 | } |
| 75 | }; |
| 76 | |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 77 | TEST_F(ArchTest, CheckCommonOffsetsAndSizes) { |
| Andreas Gampe | b2d18fa | 2017-06-06 20:46:10 -0700 | [diff] [blame] | 78 | size_t test_count = CheckAsmSupportOffsetsAndSizes(); |
| 79 | EXPECT_GT(test_count, 0u); |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | // Grab architecture specific constants. |
| 83 | namespace arm { |
| Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 84 | #include "arch/arm/asm_support_arm.h" |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 85 | static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES; |
| 86 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES |
| 87 | static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY; |
| 88 | #undef FRAME_SIZE_SAVE_REFS_ONLY |
| 89 | static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS; |
| 90 | #undef FRAME_SIZE_SAVE_REFS_AND_ARGS |
| 91 | static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING; |
| 92 | #undef FRAME_SIZE_SAVE_EVERYTHING |
| Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 93 | #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 Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 96 | #undef BAKER_MARK_INTROSPECTION_ARRAY_SWITCH_OFFSET |
| Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 97 | #undef BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET |
| 98 | #undef BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 99 | #undef BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET |
| Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 100 | #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET |
| 101 | #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 102 | } // namespace arm |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 103 | |
| 104 | namespace arm64 { |
| 105 | #include "arch/arm64/asm_support_arm64.h" |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 106 | static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES; |
| 107 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES |
| 108 | static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY; |
| 109 | #undef FRAME_SIZE_SAVE_REFS_ONLY |
| 110 | static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS; |
| 111 | #undef FRAME_SIZE_SAVE_REFS_AND_ARGS |
| 112 | static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING; |
| 113 | #undef FRAME_SIZE_SAVE_EVERYTHING |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 114 | #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 Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 119 | } // namespace arm64 |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 120 | |
| 121 | namespace mips { |
| 122 | #include "arch/mips/asm_support_mips.h" |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 123 | static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES; |
| 124 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES |
| 125 | static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY; |
| 126 | #undef FRAME_SIZE_SAVE_REFS_ONLY |
| 127 | static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS; |
| 128 | #undef FRAME_SIZE_SAVE_REFS_AND_ARGS |
| 129 | static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING; |
| 130 | #undef FRAME_SIZE_SAVE_EVERYTHING |
| Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 131 | #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 Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 135 | } // namespace mips |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 136 | |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 137 | namespace mips64 { |
| 138 | #include "arch/mips64/asm_support_mips64.h" |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 139 | static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES; |
| 140 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES |
| 141 | static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY; |
| 142 | #undef FRAME_SIZE_SAVE_REFS_ONLY |
| 143 | static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS; |
| 144 | #undef FRAME_SIZE_SAVE_REFS_AND_ARGS |
| 145 | static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING; |
| 146 | #undef FRAME_SIZE_SAVE_EVERYTHING |
| Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 147 | #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 Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 151 | } // namespace mips64 |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 152 | |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 153 | namespace x86 { |
| 154 | #include "arch/x86/asm_support_x86.h" |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 155 | static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES; |
| 156 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES |
| 157 | static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY; |
| 158 | #undef FRAME_SIZE_SAVE_REFS_ONLY |
| 159 | static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS; |
| 160 | #undef FRAME_SIZE_SAVE_REFS_AND_ARGS |
| 161 | static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING; |
| 162 | #undef FRAME_SIZE_SAVE_EVERYTHING |
| Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 163 | } // namespace x86 |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 164 | |
| 165 | namespace x86_64 { |
| 166 | #include "arch/x86_64/asm_support_x86_64.h" |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 167 | static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES; |
| 168 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES |
| 169 | static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY; |
| 170 | #undef FRAME_SIZE_SAVE_REFS_ONLY |
| 171 | static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS; |
| 172 | #undef FRAME_SIZE_SAVE_REFS_AND_ARGS |
| 173 | static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING; |
| 174 | #undef FRAME_SIZE_SAVE_EVERYTHING |
| Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 175 | } // namespace x86_64 |
| Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 176 | |
| 177 | // Check architecture specific constants are sound. |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 178 | #define TEST_ARCH(Arch, arch) \ |
| 179 | TEST_F(ArchTest, Arch) { \ |
| 180 | CheckFrameSize(InstructionSet::k##Arch, \ |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 181 | CalleeSaveType::kSaveAllCalleeSaves, \ |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 182 | arch::kFrameSizeSaveAllCalleeSaves); \ |
| 183 | CheckFrameSize(InstructionSet::k##Arch, \ |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 184 | CalleeSaveType::kSaveRefsOnly, \ |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 185 | arch::kFrameSizeSaveRefsOnly); \ |
| 186 | CheckFrameSize(InstructionSet::k##Arch, \ |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 187 | CalleeSaveType::kSaveRefsAndArgs, \ |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 188 | arch::kFrameSizeSaveRefsAndArgs); \ |
| 189 | CheckFrameSize(InstructionSet::k##Arch, \ |
| Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 190 | CalleeSaveType::kSaveEverything, \ |
| Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 191 | arch::kFrameSizeSaveEverything); \ |
| 192 | } |
| 193 | TEST_ARCH(Arm, arm) |
| 194 | TEST_ARCH(Arm64, arm64) |
| 195 | TEST_ARCH(Mips, mips) |
| 196 | TEST_ARCH(Mips64, mips64) |
| 197 | TEST_ARCH(X86, x86) |
| 198 | TEST_ARCH(X86_64, x86_64) |
| Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 199 | |
| Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 200 | } // namespace art |