/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
#define ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_

#include "arch/instruction_set.h"
#include "base/callee_save_type.h"
#include "base/enums.h"
#include "base/locks.h"
#include "quick/quick_method_frame_info.h"
#include "thread-inl.h"

// Specific frame size code is in architecture-specific files. We include this to compile-time
// specialize the code.
#include "arch/arm/callee_save_frame_arm.h"
#include "arch/arm64/callee_save_frame_arm64.h"
#include "arch/riscv64/callee_save_frame_riscv64.h"
#include "arch/x86/callee_save_frame_x86.h"
#include "arch/x86_64/callee_save_frame_x86_64.h"

namespace art HIDDEN {
class ArtMethod;

class ScopedQuickEntrypointChecks {
 public:
  explicit ScopedQuickEntrypointChecks(Thread *self,
                                       bool entry_check = kIsDebugBuild,
                                       bool exit_check = kIsDebugBuild)
      REQUIRES_SHARED(Locks::mutator_lock_) : self_(self), exit_check_(exit_check) {
    if (entry_check) {
      TestsOnEntry();
    }
  }

  ~ScopedQuickEntrypointChecks() REQUIRES_SHARED(Locks::mutator_lock_) {
    if (exit_check_) {
      TestsOnExit();
    }
  }

 private:
  void TestsOnEntry() REQUIRES_SHARED(Locks::mutator_lock_) {
    Locks::mutator_lock_->AssertSharedHeld(self_);
    self_->VerifyStack();
  }

  void TestsOnExit() REQUIRES_SHARED(Locks::mutator_lock_) {
    Locks::mutator_lock_->AssertSharedHeld(self_);
    self_->VerifyStack();
  }

  Thread* const self_;
  bool exit_check_;
};

namespace detail {

template <InstructionSet>
struct CSFSelector;  // No definition for unspecialized callee save frame selector.

// Note: kThumb2 is never the kRuntimeISA.
template <>
struct CSFSelector<InstructionSet::kArm> {
  using type = arm::ArmCalleeSaveFrame;
};
template <>
struct CSFSelector<InstructionSet::kArm64> {
  using type = arm64::Arm64CalleeSaveFrame;
};
template <>
struct CSFSelector<InstructionSet::kRiscv64> {
  using type = riscv64::Riscv64CalleeSaveFrame;
};
template <>
struct CSFSelector<InstructionSet::kX86> {
  using type = x86::X86CalleeSaveFrame;
};
template <>
struct CSFSelector<InstructionSet::kX86_64> {
  using type = x86_64::X86_64CalleeSaveFrame;
};

}  // namespace detail

using RuntimeCalleeSaveFrame = detail::CSFSelector<kRuntimeISA>::type;

}  // namespace art

#endif  // ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_
