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_ARM_CALLING_CONVENTION_ARM_H_
18 #define ART_COMPILER_JNI_QUICK_ARM_CALLING_CONVENTION_ARM_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 arm {
26 
27 class ArmManagedRuntimeCallingConvention final : public ManagedRuntimeCallingConvention {
28  public:
ArmManagedRuntimeCallingConvention(bool is_static,bool is_synchronized,std::string_view shorty)29   ArmManagedRuntimeCallingConvention(bool is_static, bool is_synchronized, std::string_view shorty)
30       : ManagedRuntimeCallingConvention(is_static,
31                                         is_synchronized,
32                                         shorty,
33                                         PointerSize::k32),
34         gpr_index_(1u),  // Skip r0 for ArtMethod*
35         float_index_(0u),
36         double_index_(0u) {}
~ArmManagedRuntimeCallingConvention()37   ~ArmManagedRuntimeCallingConvention() override {}
38   // Calling convention
39   ManagedRegister ReturnRegister() const override;
40   void ResetIterator(FrameOffset displacement) override;
41   // Managed runtime calling convention
42   ManagedRegister MethodRegister() override;
43   ManagedRegister ArgumentRegisterForMethodExitHook() override;
44   void Next() override;
45   bool IsCurrentParamInRegister() override;
46   bool IsCurrentParamOnStack() override;
47   ManagedRegister CurrentParamRegister() override;
48   FrameOffset CurrentParamStackOffset() override;
49 
50  private:
51   size_t gpr_index_;
52   size_t float_index_;
53   size_t double_index_;
54   DISALLOW_COPY_AND_ASSIGN(ArmManagedRuntimeCallingConvention);
55 };
56 
57 class ArmJniCallingConvention final : public JniCallingConvention {
58  public:
59   ArmJniCallingConvention(bool is_static,
60                           bool is_synchronized,
61                           bool is_fast_native,
62                           bool is_critical_native,
63                           std::string_view shorty);
~ArmJniCallingConvention()64   ~ArmJniCallingConvention() override {}
65   // Calling convention
66   ManagedRegister ReturnRegister() const override;
67   ManagedRegister IntReturnRegister() const override;
68   // JNI calling convention
69   void Next() override;  // Override default behavior for AAPCS
70   size_t FrameSize() const override;
71   size_t OutFrameSize() const override;
72   ArrayRef<const ManagedRegister> CalleeSaveRegisters() const override;
73   ArrayRef<const ManagedRegister> CalleeSaveScratchRegisters() const override;
74   ArrayRef<const ManagedRegister> ArgumentScratchRegisters() const override;
75   uint32_t CoreSpillMask() const override;
76   uint32_t FpSpillMask() const override;
77   bool IsCurrentParamInRegister() override;
78   bool IsCurrentParamOnStack() override;
79   ManagedRegister CurrentParamRegister() override;
80   FrameOffset CurrentParamStackOffset() override;
81 
82   // AAPCS mandates return values are extended.
RequiresSmallResultTypeExtension()83   bool RequiresSmallResultTypeExtension() const override {
84     return false;
85   }
86 
87   // Locking argument register, used to pass the synchronization object for calls
88   // to `JniLockObject()` and `JniUnlockObject()`.
89   ManagedRegister LockingArgumentRegister() const override;
90 
91   // Hidden argument register, used to pass the method pointer for @CriticalNative call.
92   ManagedRegister HiddenArgumentRegister() const override;
93 
94   // Whether to use tail call (used only for @CriticalNative).
95   bool UseTailCall() const override;
96 
97  private:
98   // Padding to ensure longs and doubles are not split in AAPCS
99   size_t padding_;
100 
101   DISALLOW_COPY_AND_ASSIGN(ArmJniCallingConvention);
102 };
103 
104 }  // namespace arm
105 }  // namespace art
106 
107 #endif  // ART_COMPILER_JNI_QUICK_ARM_CALLING_CONVENTION_ARM_H_
108