Home | History | Annotate | Download | only in arch
      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 "entrypoints/quick/callee_save_frame.h"
     22 #include "common_runtime_test.h"
     23 #include "quick/quick_method_frame_info.h"
     24 
     25 namespace art {
     26 
     27 class ArchTest : public CommonRuntimeTest {
     28  protected:
     29   void SetUpRuntimeOptions(RuntimeOptions *options) override {
     30     // Use 64-bit ISA for runtime setup to make method size potentially larger
     31     // than necessary (rather than smaller) during CreateCalleeSaveMethod
     32     options->push_back(std::make_pair("imageinstructionset", "x86_64"));
     33   }
     34 
     35   // Do not do any of the finalization. We don't want to run any code, we don't need the heap
     36   // prepared, it actually will be a problem with setting the instruction set to x86_64 in
     37   // SetUpRuntimeOptions.
     38   void FinalizeSetup() override {
     39     ASSERT_EQ(InstructionSet::kX86_64, Runtime::Current()->GetInstructionSet());
     40   }
     41 };
     42 
     43 // Grab architecture specific constants.
     44 namespace arm {
     45 #include "arch/arm/asm_support_arm.h"
     46 static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
     47 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
     48 static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
     49 #undef FRAME_SIZE_SAVE_REFS_ONLY
     50 static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
     51 #undef FRAME_SIZE_SAVE_REFS_AND_ARGS
     52 static constexpr size_t kFrameSizeSaveEverythingForClinit = FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT;
     53 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT
     54 static constexpr size_t kFrameSizeSaveEverythingForSuspendCheck =
     55     FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK;
     56 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK
     57 static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
     58 #undef FRAME_SIZE_SAVE_EVERYTHING
     59 #undef BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET
     60 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET
     61 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET
     62 #undef BAKER_MARK_INTROSPECTION_ARRAY_SWITCH_OFFSET
     63 #undef BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET
     64 #undef BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET
     65 #undef BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET
     66 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET
     67 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET
     68 }  // namespace arm
     69 
     70 namespace arm64 {
     71 #include "arch/arm64/asm_support_arm64.h"
     72 static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
     73 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
     74 static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
     75 #undef FRAME_SIZE_SAVE_REFS_ONLY
     76 static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
     77 #undef FRAME_SIZE_SAVE_REFS_AND_ARGS
     78 static constexpr size_t kFrameSizeSaveEverythingForClinit = FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT;
     79 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT
     80 static constexpr size_t kFrameSizeSaveEverythingForSuspendCheck =
     81     FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK;
     82 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK
     83 static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
     84 #undef FRAME_SIZE_SAVE_EVERYTHING
     85 #undef BAKER_MARK_INTROSPECTION_ARRAY_SWITCH_OFFSET
     86 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET
     87 #undef BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET
     88 #undef BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET
     89 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET
     90 }  // namespace arm64
     91 
     92 namespace mips {
     93 #include "arch/mips/asm_support_mips.h"
     94 static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
     95 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
     96 static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
     97 #undef FRAME_SIZE_SAVE_REFS_ONLY
     98 static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
     99 #undef FRAME_SIZE_SAVE_REFS_AND_ARGS
    100 static constexpr size_t kFrameSizeSaveEverythingForClinit = FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT;
    101 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT
    102 static constexpr size_t kFrameSizeSaveEverythingForSuspendCheck =
    103     FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK;
    104 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK
    105 static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
    106 #undef FRAME_SIZE_SAVE_EVERYTHING
    107 #undef BAKER_MARK_INTROSPECTION_REGISTER_COUNT
    108 #undef BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE
    109 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET
    110 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE
    111 }  // namespace mips
    112 
    113 namespace mips64 {
    114 #include "arch/mips64/asm_support_mips64.h"
    115 static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
    116 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
    117 static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
    118 #undef FRAME_SIZE_SAVE_REFS_ONLY
    119 static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
    120 #undef FRAME_SIZE_SAVE_REFS_AND_ARGS
    121 static constexpr size_t kFrameSizeSaveEverythingForClinit = FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT;
    122 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT
    123 static constexpr size_t kFrameSizeSaveEverythingForSuspendCheck =
    124     FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK;
    125 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK
    126 static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
    127 #undef FRAME_SIZE_SAVE_EVERYTHING
    128 #undef BAKER_MARK_INTROSPECTION_REGISTER_COUNT
    129 #undef BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE
    130 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET
    131 #undef BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE
    132 }  // namespace mips64
    133 
    134 namespace x86 {
    135 #include "arch/x86/asm_support_x86.h"
    136 static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
    137 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
    138 static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
    139 #undef FRAME_SIZE_SAVE_REFS_ONLY
    140 static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
    141 #undef FRAME_SIZE_SAVE_REFS_AND_ARGS
    142 static constexpr size_t kFrameSizeSaveEverythingForClinit = FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT;
    143 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT
    144 static constexpr size_t kFrameSizeSaveEverythingForSuspendCheck =
    145     FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK;
    146 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK
    147 static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
    148 #undef FRAME_SIZE_SAVE_EVERYTHING
    149 }  // namespace x86
    150 
    151 namespace x86_64 {
    152 #include "arch/x86_64/asm_support_x86_64.h"
    153 static constexpr size_t kFrameSizeSaveAllCalleeSaves = FRAME_SIZE_SAVE_ALL_CALLEE_SAVES;
    154 #undef FRAME_SIZE_SAVE_ALL_CALLEE_SAVES
    155 static constexpr size_t kFrameSizeSaveRefsOnly = FRAME_SIZE_SAVE_REFS_ONLY;
    156 #undef FRAME_SIZE_SAVE_REFS_ONLY
    157 static constexpr size_t kFrameSizeSaveRefsAndArgs = FRAME_SIZE_SAVE_REFS_AND_ARGS;
    158 #undef FRAME_SIZE_SAVE_REFS_AND_ARGS
    159 static constexpr size_t kFrameSizeSaveEverythingForClinit = FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT;
    160 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_CLINIT
    161 static constexpr size_t kFrameSizeSaveEverythingForSuspendCheck =
    162     FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK;
    163 #undef FRAME_SIZE_SAVE_EVERYTHING_FOR_SUSPEND_CHECK
    164 static constexpr size_t kFrameSizeSaveEverything = FRAME_SIZE_SAVE_EVERYTHING;
    165 #undef FRAME_SIZE_SAVE_EVERYTHING
    166 }  // namespace x86_64
    167 
    168 // Check architecture specific constants are sound.
    169 // We expect the return PC to be stored at the highest address slot in the frame.
    170 #define TEST_ARCH_TYPE(Arch, arch, type)                                              \
    171   EXPECT_EQ(arch::Arch##CalleeSaveFrame::GetFrameSize(CalleeSaveType::k##type),       \
    172             arch::kFrameSize##type);                                                  \
    173   EXPECT_EQ(arch::Arch##CalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::k##type),  \
    174             arch::kFrameSize##type - static_cast<size_t>(k##Arch##PointerSize))
    175 #define TEST_ARCH(Arch, arch)                                   \
    176   TEST_F(ArchTest, Arch) {                                      \
    177     TEST_ARCH_TYPE(Arch, arch, SaveAllCalleeSaves);             \
    178     TEST_ARCH_TYPE(Arch, arch, SaveRefsOnly);                   \
    179     TEST_ARCH_TYPE(Arch, arch, SaveRefsAndArgs);                \
    180     TEST_ARCH_TYPE(Arch, arch, SaveEverything);                 \
    181     TEST_ARCH_TYPE(Arch, arch, SaveEverythingForClinit);        \
    182     TEST_ARCH_TYPE(Arch, arch, SaveEverythingForSuspendCheck);  \
    183   }
    184 TEST_ARCH(Arm, arm)
    185 TEST_ARCH(Arm64, arm64)
    186 TEST_ARCH(Mips, mips)
    187 TEST_ARCH(Mips64, mips64)
    188 TEST_ARCH(X86, x86)
    189 TEST_ARCH(X86_64, x86_64)
    190 
    191 }  // namespace art
    192