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 | |
| 19 | #include "common_runtime_test.h" |
Vladimir Marko | c0480ef | 2014-05-13 17:45:46 +0100 | [diff] [blame] | 20 | #include "mirror/art_method-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 21 | #include "quick/quick_method_frame_info.h" |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | class ArchTest : public CommonRuntimeTest { |
| 26 | protected: |
| 27 | static void CheckFrameSize(InstructionSet isa, Runtime::CalleeSaveType type, uint32_t save_size) |
| 28 | NO_THREAD_SAFETY_ANALYSIS { |
| 29 | Runtime* r = Runtime::Current(); |
| 30 | |
| 31 | Thread* t = Thread::Current(); |
| 32 | t->TransitionFromSuspendedToRunnable(); // So we can create callee-save methods. |
| 33 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 34 | r->SetInstructionSet(isa); |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 35 | mirror::ArtMethod* save_method = r->CreateCalleeSaveMethod(); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 36 | r->SetCalleeSaveMethod(save_method, type); |
| 37 | QuickMethodFrameInfo frame_info = save_method->GetQuickFrameInfo(); |
| 38 | EXPECT_EQ(frame_info.FrameSizeInBytes(), save_size) << "Expected and real size differs for " |
| 39 | << type << " core spills=" << std::hex << frame_info.CoreSpillMask() << " fp spills=" |
| 40 | << frame_info.FpSpillMask() << std::dec; |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 41 | |
| 42 | t->TransitionFromRunnableToSuspended(ThreadState::kNative); // So we can shut down. |
| 43 | } |
| 44 | }; |
| 45 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 46 | // Common tests are declared next to the constants. |
| 47 | #define ADD_TEST_EQ(x, y) EXPECT_EQ(x, y); |
| 48 | #include "asm_support.h" |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 49 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 50 | TEST_F(ArchTest, CheckCommonOffsetsAndSizes) { |
| 51 | CheckAsmSupportOffsetsAndSizes(); |
| 52 | } |
| 53 | |
| 54 | // Grab architecture specific constants. |
| 55 | namespace arm { |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 56 | #include "arch/arm/asm_support_arm.h" |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 57 | static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE; |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 58 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 59 | static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE; |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 60 | #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 61 | static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE; |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 62 | #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | namespace arm64 { |
| 66 | #include "arch/arm64/asm_support_arm64.h" |
| 67 | static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE; |
| 68 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE |
| 69 | static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE; |
| 70 | #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE |
| 71 | static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE; |
| 72 | #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE |
| 73 | } |
| 74 | |
| 75 | namespace mips { |
| 76 | #include "arch/mips/asm_support_mips.h" |
| 77 | static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE; |
| 78 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE |
| 79 | static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE; |
| 80 | #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE |
| 81 | static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE; |
| 82 | #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE |
| 83 | } |
| 84 | |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 85 | namespace mips64 { |
| 86 | #include "arch/mips64/asm_support_mips64.h" |
| 87 | static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE; |
| 88 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE |
| 89 | static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE; |
| 90 | #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE |
| 91 | static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE; |
| 92 | #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE |
| 93 | } |
| 94 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 95 | namespace x86 { |
| 96 | #include "arch/x86/asm_support_x86.h" |
| 97 | static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE; |
| 98 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE |
| 99 | static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE; |
| 100 | #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE |
| 101 | static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE; |
| 102 | #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE |
| 103 | } |
| 104 | |
| 105 | namespace x86_64 { |
| 106 | #include "arch/x86_64/asm_support_x86_64.h" |
| 107 | static constexpr size_t kFrameSizeSaveAllCalleeSave = FRAME_SIZE_SAVE_ALL_CALLEE_SAVE; |
| 108 | #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVE |
| 109 | static constexpr size_t kFrameSizeRefsOnlyCalleeSave = FRAME_SIZE_REFS_ONLY_CALLEE_SAVE; |
| 110 | #undef FRAME_SIZE_REFS_ONLY_CALLEE_SAVE |
| 111 | static constexpr size_t kFrameSizeRefsAndArgsCalleeSave = FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE; |
| 112 | #undef FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE |
| 113 | } |
| 114 | |
| 115 | // Check architecture specific constants are sound. |
| 116 | TEST_F(ArchTest, ARM) { |
| 117 | CheckFrameSize(InstructionSet::kArm, Runtime::kSaveAll, arm::kFrameSizeSaveAllCalleeSave); |
| 118 | CheckFrameSize(InstructionSet::kArm, Runtime::kRefsOnly, arm::kFrameSizeRefsOnlyCalleeSave); |
| 119 | CheckFrameSize(InstructionSet::kArm, Runtime::kRefsAndArgs, arm::kFrameSizeRefsAndArgsCalleeSave); |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | |
| 123 | TEST_F(ArchTest, ARM64) { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 124 | CheckFrameSize(InstructionSet::kArm64, Runtime::kSaveAll, arm64::kFrameSizeSaveAllCalleeSave); |
| 125 | CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsOnly, arm64::kFrameSizeRefsOnlyCalleeSave); |
| 126 | CheckFrameSize(InstructionSet::kArm64, Runtime::kRefsAndArgs, |
| 127 | arm64::kFrameSizeRefsAndArgsCalleeSave); |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 130 | TEST_F(ArchTest, MIPS) { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 131 | CheckFrameSize(InstructionSet::kMips, Runtime::kSaveAll, mips::kFrameSizeSaveAllCalleeSave); |
| 132 | CheckFrameSize(InstructionSet::kMips, Runtime::kRefsOnly, mips::kFrameSizeRefsOnlyCalleeSave); |
| 133 | CheckFrameSize(InstructionSet::kMips, Runtime::kRefsAndArgs, |
| 134 | mips::kFrameSizeRefsAndArgsCalleeSave); |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 137 | TEST_F(ArchTest, MIPS64) { |
| 138 | CheckFrameSize(InstructionSet::kMips64, Runtime::kSaveAll, mips64::kFrameSizeSaveAllCalleeSave); |
| 139 | CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsOnly, mips64::kFrameSizeRefsOnlyCalleeSave); |
| 140 | CheckFrameSize(InstructionSet::kMips64, Runtime::kRefsAndArgs, |
| 141 | mips64::kFrameSizeRefsAndArgsCalleeSave); |
| 142 | } |
| 143 | |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 144 | TEST_F(ArchTest, X86) { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 145 | CheckFrameSize(InstructionSet::kX86, Runtime::kSaveAll, x86::kFrameSizeSaveAllCalleeSave); |
| 146 | CheckFrameSize(InstructionSet::kX86, Runtime::kRefsOnly, x86::kFrameSizeRefsOnlyCalleeSave); |
| 147 | CheckFrameSize(InstructionSet::kX86, Runtime::kRefsAndArgs, x86::kFrameSizeRefsAndArgsCalleeSave); |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 150 | TEST_F(ArchTest, X86_64) { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 151 | CheckFrameSize(InstructionSet::kX86_64, Runtime::kSaveAll, x86_64::kFrameSizeSaveAllCalleeSave); |
| 152 | CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsOnly, x86_64::kFrameSizeRefsOnlyCalleeSave); |
| 153 | CheckFrameSize(InstructionSet::kX86_64, Runtime::kRefsAndArgs, |
| 154 | x86_64::kFrameSizeRefsAndArgsCalleeSave); |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 157 | } // namespace art |