Home | History | Annotate | Download | only in quick
      1 /*
      2  * Copyright (C) 2012 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 #ifndef ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
     18 #define ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
     19 
     20 #include "arch/instruction_set.h"
     21 #include "base/callee_save_type.h"
     22 #include "base/enums.h"
     23 #include "base/mutex.h"
     24 #include "thread-inl.h"
     25 
     26 // Specific frame size code is in architecture-specific files. We include this to compile-time
     27 // specialize the code.
     28 #include "arch/arm/quick_method_frame_info_arm.h"
     29 #include "arch/arm64/quick_method_frame_info_arm64.h"
     30 #include "arch/mips/quick_method_frame_info_mips.h"
     31 #include "arch/mips64/quick_method_frame_info_mips64.h"
     32 #include "arch/x86/quick_method_frame_info_x86.h"
     33 #include "arch/x86_64/quick_method_frame_info_x86_64.h"
     34 
     35 namespace art {
     36 class ArtMethod;
     37 
     38 class ScopedQuickEntrypointChecks {
     39  public:
     40   explicit ScopedQuickEntrypointChecks(Thread *self,
     41                                        bool entry_check = kIsDebugBuild,
     42                                        bool exit_check = kIsDebugBuild)
     43       REQUIRES_SHARED(Locks::mutator_lock_) : self_(self), exit_check_(exit_check) {
     44     if (entry_check) {
     45       TestsOnEntry();
     46     }
     47   }
     48 
     49   ~ScopedQuickEntrypointChecks() REQUIRES_SHARED(Locks::mutator_lock_) {
     50     if (exit_check_) {
     51       TestsOnExit();
     52     }
     53   }
     54 
     55  private:
     56   void TestsOnEntry() REQUIRES_SHARED(Locks::mutator_lock_) {
     57     Locks::mutator_lock_->AssertSharedHeld(self_);
     58     self_->VerifyStack();
     59   }
     60 
     61   void TestsOnExit() REQUIRES_SHARED(Locks::mutator_lock_) {
     62     Locks::mutator_lock_->AssertSharedHeld(self_);
     63     self_->VerifyStack();
     64   }
     65 
     66   Thread* const self_;
     67   bool exit_check_;
     68 };
     69 
     70 static constexpr size_t GetCalleeSaveFrameSize(InstructionSet isa, CalleeSaveType type) {
     71   // constexpr must be a return statement.
     72   return (isa == kArm || isa == kThumb2) ? arm::ArmCalleeSaveFrameSize(type) :
     73          isa == kArm64 ? arm64::Arm64CalleeSaveFrameSize(type) :
     74          isa == kMips ? mips::MipsCalleeSaveFrameSize(type) :
     75          isa == kMips64 ? mips64::Mips64CalleeSaveFrameSize(type) :
     76          isa == kX86 ? x86::X86CalleeSaveFrameSize(type) :
     77          isa == kX86_64 ? x86_64::X86_64CalleeSaveFrameSize(type) :
     78          isa == kNone ? (LOG(FATAL) << "kNone has no frame size", 0) :
     79          (LOG(FATAL) << "Unknown instruction set" << isa, 0);
     80 }
     81 
     82 // Note: this specialized statement is sanity-checked in the quick-trampoline gtest.
     83 static constexpr PointerSize GetConstExprPointerSize(InstructionSet isa) {
     84   // constexpr must be a return statement.
     85   return (isa == kArm || isa == kThumb2) ? kArmPointerSize :
     86          isa == kArm64 ? kArm64PointerSize :
     87          isa == kMips ? kMipsPointerSize :
     88          isa == kMips64 ? kMips64PointerSize :
     89          isa == kX86 ? kX86PointerSize :
     90          isa == kX86_64 ? kX86_64PointerSize :
     91          isa == kNone ? (LOG(FATAL) << "kNone has no pointer size", PointerSize::k32) :
     92          (LOG(FATAL) << "Unknown instruction set" << isa, PointerSize::k32);
     93 }
     94 
     95 // Note: this specialized statement is sanity-checked in the quick-trampoline gtest.
     96 static constexpr size_t GetCalleeSaveReturnPcOffset(InstructionSet isa, CalleeSaveType type) {
     97   return GetCalleeSaveFrameSize(isa, type) - static_cast<size_t>(GetConstExprPointerSize(isa));
     98 }
     99 
    100 }  // namespace art
    101 
    102 #endif  // ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
    103