1 /* 2 * Copyright (C) 2011 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_COMPILER_JNI_QUICK_X86_CALLING_CONVENTION_X86_H_ 18 #define ART_COMPILER_JNI_QUICK_X86_CALLING_CONVENTION_X86_H_ 19 20 #include "base/macros.h" 21 #include "base/pointer_size.h" 22 #include "jni/quick/calling_convention.h" 23 24 namespace art HIDDEN { 25 namespace x86 { 26 27 class X86ManagedRuntimeCallingConvention final : public ManagedRuntimeCallingConvention { 28 public: X86ManagedRuntimeCallingConvention(bool is_static,bool is_synchronized,std::string_view shorty)29 X86ManagedRuntimeCallingConvention(bool is_static, bool is_synchronized, std::string_view shorty) 30 : ManagedRuntimeCallingConvention(is_static, 31 is_synchronized, 32 shorty, 33 PointerSize::k32), 34 gpr_arg_count_(1u) {} // Skip EAX for ArtMethod* ~X86ManagedRuntimeCallingConvention()35 ~X86ManagedRuntimeCallingConvention() override {} 36 // Calling convention 37 ManagedRegister ReturnRegister() const override; 38 void ResetIterator(FrameOffset displacement) override; 39 // Managed runtime calling convention 40 ManagedRegister MethodRegister() override; 41 ManagedRegister ArgumentRegisterForMethodExitHook() override; 42 void Next() override; 43 bool IsCurrentParamInRegister() override; 44 bool IsCurrentParamOnStack() override; 45 ManagedRegister CurrentParamRegister() override; 46 FrameOffset CurrentParamStackOffset() override; 47 48 private: 49 int gpr_arg_count_; 50 DISALLOW_COPY_AND_ASSIGN(X86ManagedRuntimeCallingConvention); 51 }; 52 53 // Implements the x86 cdecl calling convention. 54 class X86JniCallingConvention final : public JniCallingConvention { 55 public: 56 X86JniCallingConvention(bool is_static, 57 bool is_synchronized, 58 bool is_fast_native, 59 bool is_critical_native, 60 std::string_view shorty); ~X86JniCallingConvention()61 ~X86JniCallingConvention() override {} 62 // Calling convention 63 ManagedRegister ReturnRegister() const override; 64 ManagedRegister IntReturnRegister() const override; 65 // JNI calling convention 66 size_t FrameSize() const override; 67 size_t OutFrameSize() const override; 68 ArrayRef<const ManagedRegister> CalleeSaveRegisters() const override; 69 ArrayRef<const ManagedRegister> CalleeSaveScratchRegisters() const override; 70 ArrayRef<const ManagedRegister> ArgumentScratchRegisters() const override; 71 uint32_t CoreSpillMask() const override; 72 uint32_t FpSpillMask() const override; 73 bool IsCurrentParamInRegister() override; 74 bool IsCurrentParamOnStack() override; 75 ManagedRegister CurrentParamRegister() override; 76 FrameOffset CurrentParamStackOffset() override; 77 78 // x86 needs to extend small return types. RequiresSmallResultTypeExtension()79 bool RequiresSmallResultTypeExtension() const override { 80 return HasSmallReturnType(); 81 } 82 83 // Locking argument register, used to pass the synchronization object for calls 84 // to `JniLockObject()` and `JniUnlockObject()`. 85 ManagedRegister LockingArgumentRegister() const override; 86 87 // Hidden argument register, used to pass the method pointer for @CriticalNative call. 88 ManagedRegister HiddenArgumentRegister() const override; 89 90 // Whether to use tail call (used only for @CriticalNative). 91 bool UseTailCall() const override; 92 93 private: 94 DISALLOW_COPY_AND_ASSIGN(X86JniCallingConvention); 95 }; 96 97 } // namespace x86 98 } // namespace art 99 100 #endif // ART_COMPILER_JNI_QUICK_X86_CALLING_CONVENTION_X86_H_ 101