Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 1 | /* |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 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 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_ |
| 18 | #define ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_ |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 19 | |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 20 | #include "base/mutex.h" |
Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 21 | #include "gc_root-inl.h" |
Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 22 | #include "instruction_set.h" |
Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 23 | #include "runtime-inl.h" |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 24 | #include "thread-inl.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 25 | |
Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 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/x86/quick_method_frame_info_x86.h" |
| 32 | #include "arch/x86_64/quick_method_frame_info_x86_64.h" |
| 33 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 34 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | namespace mirror { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 36 | class ArtMethod; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | } // namespace mirror |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 38 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 39 | // Place a special frame at the TOS that will save the callee saves for the given type. |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 40 | static inline void FinishCalleeSaveFrameSetup(Thread* self, StackReference<mirror::ArtMethod>* sp, |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 41 | Runtime::CalleeSaveType type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 42 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 43 | // Be aware the store below may well stomp on an incoming argument. |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 44 | Locks::mutator_lock_->AssertSharedHeld(self); |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 45 | sp->Assign(Runtime::Current()->GetCalleeSaveMethod(type)); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 46 | self->SetTopOfStack(sp, 0); |
| 47 | self->VerifyStack(); |
| 48 | } |
| 49 | |
Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 50 | static constexpr size_t GetCalleeSaveFrameSize(InstructionSet isa, Runtime::CalleeSaveType type) { |
| 51 | // constexpr must be a return statement. |
| 52 | return (isa == kArm || isa == kThumb2) ? arm::ArmCalleeSaveFrameSize(type) : |
| 53 | isa == kArm64 ? arm64::Arm64CalleeSaveFrameSize(type) : |
| 54 | isa == kMips ? mips::MipsCalleeSaveFrameSize(type) : |
| 55 | isa == kX86 ? x86::X86CalleeSaveFrameSize(type) : |
| 56 | isa == kX86_64 ? x86_64::X86_64CalleeSaveFrameSize(type) : |
| 57 | isa == kNone ? (LOG(FATAL) << "kNone has no frame size", 0) : |
| 58 | (LOG(FATAL) << "Unknown instruction set" << isa, 0); |
| 59 | } |
| 60 | |
| 61 | // Note: this specialized statement is sanity-checked in the quick-trampoline gtest. |
| 62 | static constexpr size_t GetConstExprPointerSize(InstructionSet isa) { |
| 63 | // constexpr must be a return statement. |
| 64 | return (isa == kArm || isa == kThumb2) ? kArmPointerSize : |
| 65 | isa == kArm64 ? kArm64PointerSize : |
| 66 | isa == kMips ? kMipsPointerSize : |
| 67 | isa == kX86 ? kX86PointerSize : |
| 68 | isa == kX86_64 ? kX86_64PointerSize : |
| 69 | isa == kNone ? (LOG(FATAL) << "kNone has no pointer size", 0) : |
| 70 | (LOG(FATAL) << "Unknown instruction set" << isa, 0); |
| 71 | } |
| 72 | |
| 73 | // Note: this specialized statement is sanity-checked in the quick-trampoline gtest. |
| 74 | static constexpr size_t GetCalleeSavePCOffset(InstructionSet isa, Runtime::CalleeSaveType type) { |
| 75 | return GetCalleeSaveFrameSize(isa, type) - GetConstExprPointerSize(isa); |
| 76 | } |
| 77 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 78 | } // namespace art |
| 79 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 80 | #endif // ART_RUNTIME_ENTRYPOINTS_QUICK_CALLEE_SAVE_FRAME_H_ |