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 "art_method-inl.h" 20 #include "base/callee_save_type.h" 21 #include "base/common_art_test.h" 22 #include "entrypoints/quick/callee_save_frame.h" 23 #include "quick/quick_method_frame_info.h" 24 25 namespace art { 26 27 class ArchTest : public CommonArtTest {}; 28 29 // Grab architecture specific constants. 30 namespace arm { 31 #include "arch/arm/asm_support_arm.h" 32 static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES; 33 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES 34 static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY; 35 #undef FRAME_SIZE_SAVE_REFS_ONLY 36 static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS; 37 #undef FRAME_SIZE_SAVE_REFS_AND_ARGS 38 static constexpr size_t kFrameSizeSaveEverythingForClinit = FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT; 39 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT 40 static constexpr size_t kFrameSizeSaveEverythingForSuspendCheck = 41 FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK; 42 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK 43 static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING; 44 #undef FRAME_SIZE_SAVE_EVERYTHING 45 #undef BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET 46 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET 47 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET 48 #undef BAKER_MARK_INTROSPECTION_ARRAY_SWITCH_OFFSET 49 #undef BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET 50 #undef BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET 51 #undef BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET 52 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET 53 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET 54 } // namespace arm 55 56 namespace arm64 { 57 #include "arch/arm64/asm_support_arm64.h" 58 static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES; 59 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES 60 static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY; 61 #undef FRAME_SIZE_SAVE_REFS_ONLY 62 static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS; 63 #undef FRAME_SIZE_SAVE_REFS_AND_ARGS 64 static constexpr size_t kFrameSizeSaveEverythingForClinit = FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT; 65 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT 66 static constexpr size_t kFrameSizeSaveEverythingForSuspendCheck = 67 FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK; 68 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK 69 static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING; 70 #undef FRAME_SIZE_SAVE_EVERYTHING 71 #undef BAKER_MARK_INTROSPECTION_ARRAY_SWITCH_OFFSET 72 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET 73 #undef BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET 74 #undef BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET 75 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET 76 } // namespace arm64 77 78 namespace x86 { 79 #include "arch/x86/asm_support_x86.h" 80 static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES; 81 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES 82 static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY; 83 #undef FRAME_SIZE_SAVE_REFS_ONLY 84 static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS; 85 #undef FRAME_SIZE_SAVE_REFS_AND_ARGS 86 static constexpr size_t kFrameSizeSaveEverythingForClinit = FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT; 87 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT 88 static constexpr size_t kFrameSizeSaveEverythingForSuspendCheck = 89 FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK; 90 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK 91 static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING; 92 #undef FRAME_SIZE_SAVE_EVERYTHING 93 } // namespace x86 94 95 namespace x86_64 { 96 #include "arch/x86_64/asm_support_x86_64.h" 97 static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES; 98 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES 99 static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY; 100 #undef FRAME_SIZE_SAVE_REFS_ONLY 101 static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS; 102 #undef FRAME_SIZE_SAVE_REFS_AND_ARGS 103 static constexpr size_t kFrameSizeSaveEverythingForClinit = FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT; 104 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT 105 static constexpr size_t kFrameSizeSaveEverythingForSuspendCheck = 106 FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK; 107 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK 108 static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING; 109 #undef FRAME_SIZE_SAVE_EVERYTHING 110 } // namespace x86_64 111 112 // Check architecture specific constants are sound. 113 // We expect the return PC to be stored at the highest address slot in the frame. 114 #define TEST_ARCH_TYPE(Arch, arch, type) \ 115 EXPECT_EQ(arch::Arch##CalleeSaveFrame::GetFrameSize(CalleeSaveType::k##type), \ 116 arch::kFrameSize##type); \ 117 EXPECT_EQ(arch::Arch##CalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::k##type), \ 118 arch::kFrameSize##type - static_cast<size_t>(k##Arch##PointerSize)) 119 #define TEST_ARCH(Arch, arch) \ 120 TEST_F(ArchTest, Arch) { \ 121 TEST_ARCH_TYPE(Arch, arch, SaveAllCalleeSaves); \ 122 TEST_ARCH_TYPE(Arch, arch, SaveRefsOnly); \ 123 TEST_ARCH_TYPE(Arch, arch, SaveRefsAndArgs); \ 124 TEST_ARCH_TYPE(Arch, arch, SaveEverything); \ 125 TEST_ARCH_TYPE(Arch, arch, SaveEverythingForClinit); \ 126 TEST_ARCH_TYPE(Arch, arch, SaveEverythingForSuspendCheck); \ 127 } 128 TEST_ARCH(Arm, arm) 129 TEST_ARCH(Arm64, arm64) 130 TEST_ARCH(X86, x86) 131 TEST_ARCH(X86_64, x86_64) 132 133 } // namespace art 134