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