Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 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 | */ |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_JNI_QUICK_CALLING_CONVENTION_H_ |
| 18 | #define ART_COMPILER_JNI_QUICK_CALLING_CONVENTION_H_ |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 19 | |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 20 | #include <vector> |
Elliott Hughes | 68e7652 | 2011-10-05 13:22:16 -0700 | [diff] [blame] | 21 | #include "stack_indirect_reference_table.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 22 | #include "thread.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 23 | #include "utils/managed_register.h" |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 27 | // Top-level abstraction for different calling conventions. |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 28 | class CallingConvention { |
| 29 | public: |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 30 | bool IsReturnAReference() const { return shorty_[0] == 'L'; } |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 31 | |
jeffhao | 58136ca | 2012-05-24 13:40:11 -0700 | [diff] [blame] | 32 | Primitive::Type GetReturnType() const { |
| 33 | return Primitive::GetType(shorty_[0]); |
| 34 | } |
| 35 | |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 36 | size_t SizeOfReturnValue() const { |
| 37 | size_t result = Primitive::ComponentSize(Primitive::GetType(shorty_[0])); |
| 38 | if (result >= 1 && result < 4) { |
| 39 | result = 4; |
| 40 | } |
| 41 | return result; |
| 42 | } |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 43 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 44 | // Register that holds result of this method invocation. |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 45 | virtual ManagedRegister ReturnRegister() = 0; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 46 | // Register reserved for scratch usage during procedure calls. |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 47 | virtual ManagedRegister InterproceduralScratchRegister() = 0; |
Shih-wei Liao | 668512a | 2011-09-01 14:18:34 -0700 | [diff] [blame] | 48 | |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 49 | // Offset of Method within the frame. |
| 50 | FrameOffset MethodStackOffset() { |
| 51 | return displacement_; |
| 52 | } |
Carl Shapiro | e2d373e | 2011-07-25 15:20:06 -0700 | [diff] [blame] | 53 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 54 | // Iterator interface |
| 55 | |
| 56 | // Place iterator at start of arguments. The displacement is applied to |
| 57 | // frame offset methods to account for frames which may be on the stack |
| 58 | // below the one being iterated over. |
| 59 | void ResetIterator(FrameOffset displacement) { |
| 60 | displacement_ = displacement; |
Shih-wei Liao | 5381cf9 | 2011-07-27 00:28:04 -0700 | [diff] [blame] | 61 | itr_slots_ = 0; |
| 62 | itr_args_ = 0; |
Shih-wei Liao | 668512a | 2011-09-01 14:18:34 -0700 | [diff] [blame] | 63 | itr_refs_ = 0; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 64 | itr_longs_and_doubles_ = 0; |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 65 | itr_float_and_doubles_ = 0; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 68 | virtual ~CallingConvention() {} |
| 69 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 70 | protected: |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 71 | CallingConvention(bool is_static, bool is_synchronized, const char* shorty, |
| 72 | size_t frame_pointer_size) |
| 73 | : itr_slots_(0), itr_refs_(0), itr_args_(0), itr_longs_and_doubles_(0), |
| 74 | itr_float_and_doubles_(0), displacement_(0), |
| 75 | frame_pointer_size_(frame_pointer_size), |
| 76 | sirt_pointer_size_(sizeof(StackReference<mirror::Object>)), |
| 77 | is_static_(is_static), is_synchronized_(is_synchronized), |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 78 | shorty_(shorty) { |
| 79 | num_args_ = (is_static ? 0 : 1) + strlen(shorty) - 1; |
| 80 | num_ref_args_ = is_static ? 0 : 1; // The implicit this pointer. |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 81 | num_float_or_double_args_ = 0; |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 82 | num_long_or_double_args_ = 0; |
| 83 | for (size_t i = 1; i < strlen(shorty); i++) { |
| 84 | char ch = shorty_[i]; |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 85 | switch (ch) { |
| 86 | case 'L': |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 87 | num_ref_args_++; |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 88 | break; |
| 89 | case 'J': |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 90 | num_long_or_double_args_++; |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 91 | break; |
| 92 | case 'D': |
| 93 | num_long_or_double_args_++; |
| 94 | num_float_or_double_args_++; |
| 95 | break; |
| 96 | case 'F': |
| 97 | num_float_or_double_args_++; |
| 98 | break; |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | } |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 102 | |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 103 | bool IsStatic() const { |
| 104 | return is_static_; |
| 105 | } |
| 106 | bool IsSynchronized() const { |
| 107 | return is_synchronized_; |
| 108 | } |
| 109 | bool IsParamALongOrDouble(unsigned int param) const { |
| 110 | DCHECK_LT(param, NumArgs()); |
| 111 | if (IsStatic()) { |
| 112 | param++; // 0th argument must skip return value at start of the shorty |
| 113 | } else if (param == 0) { |
| 114 | return false; // this argument |
| 115 | } |
| 116 | char ch = shorty_[param]; |
| 117 | return (ch == 'J' || ch == 'D'); |
| 118 | } |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 119 | bool IsParamAFloatOrDouble(unsigned int param) const { |
| 120 | DCHECK_LT(param, NumArgs()); |
| 121 | if (IsStatic()) { |
| 122 | param++; // 0th argument must skip return value at start of the shorty |
| 123 | } else if (param == 0) { |
| 124 | return false; // this argument |
| 125 | } |
| 126 | char ch = shorty_[param]; |
| 127 | return (ch == 'F' || ch == 'D'); |
| 128 | } |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 129 | bool IsParamADouble(unsigned int param) const { |
| 130 | DCHECK_LT(param, NumArgs()); |
| 131 | if (IsStatic()) { |
| 132 | param++; // 0th argument must skip return value at start of the shorty |
| 133 | } else if (param == 0) { |
| 134 | return false; // this argument |
| 135 | } |
| 136 | return shorty_[param] == 'D'; |
| 137 | } |
| 138 | bool IsParamALong(unsigned int param) const { |
| 139 | DCHECK_LT(param, NumArgs()); |
| 140 | if (IsStatic()) { |
| 141 | param++; // 0th argument must skip return value at start of the shorty |
| 142 | } else if (param == 0) { |
| 143 | return true; // this argument |
| 144 | } |
| 145 | return shorty_[param] == 'J'; |
| 146 | } |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 147 | bool IsParamAReference(unsigned int param) const { |
| 148 | DCHECK_LT(param, NumArgs()); |
| 149 | if (IsStatic()) { |
| 150 | param++; // 0th argument must skip return value at start of the shorty |
| 151 | } else if (param == 0) { |
| 152 | return true; // this argument |
| 153 | } |
| 154 | return shorty_[param] == 'L'; |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 155 | } |
| 156 | size_t NumArgs() const { |
| 157 | return num_args_; |
| 158 | } |
| 159 | size_t NumLongOrDoubleArgs() const { |
| 160 | return num_long_or_double_args_; |
| 161 | } |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 162 | size_t NumFloatOrDoubleArgs() const { |
| 163 | return num_float_or_double_args_; |
| 164 | } |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 165 | size_t NumReferenceArgs() const { |
| 166 | return num_ref_args_; |
| 167 | } |
| 168 | size_t ParamSize(unsigned int param) const { |
| 169 | DCHECK_LT(param, NumArgs()); |
| 170 | if (IsStatic()) { |
| 171 | param++; // 0th argument must skip return value at start of the shorty |
| 172 | } else if (param == 0) { |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 173 | return frame_pointer_size_; // this argument |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 174 | } |
| 175 | size_t result = Primitive::ComponentSize(Primitive::GetType(shorty_[param])); |
| 176 | if (result >= 1 && result < 4) { |
| 177 | result = 4; |
| 178 | } |
| 179 | return result; |
| 180 | } |
| 181 | const char* GetShorty() const { |
| 182 | return shorty_.c_str(); |
| 183 | } |
Shih-wei Liao | 5381cf9 | 2011-07-27 00:28:04 -0700 | [diff] [blame] | 184 | // The slot number for current calling_convention argument. |
| 185 | // Note that each slot is 32-bit. When the current argument is bigger |
| 186 | // than 32 bits, return the first slot number for this argument. |
| 187 | unsigned int itr_slots_; |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 188 | // The number of references iterated past. |
Ian Rogers | 7a99c11 | 2011-09-07 12:48:27 -0700 | [diff] [blame] | 189 | unsigned int itr_refs_; |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 190 | // The argument number along argument list for current argument. |
Shih-wei Liao | 5381cf9 | 2011-07-27 00:28:04 -0700 | [diff] [blame] | 191 | unsigned int itr_args_; |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 192 | // Number of longs and doubles seen along argument list. |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 193 | unsigned int itr_longs_and_doubles_; |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 194 | // Number of float and doubles seen along argument list. |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 195 | unsigned int itr_float_and_doubles_; |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 196 | // Space for frames below this on the stack. |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 197 | FrameOffset displacement_; |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 198 | // The size of a reference. |
| 199 | const size_t frame_pointer_size_; |
| 200 | // The size of a reference entry within the SIRT. |
| 201 | const size_t sirt_pointer_size_; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 202 | |
| 203 | private: |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 204 | const bool is_static_; |
| 205 | const bool is_synchronized_; |
| 206 | std::string shorty_; |
| 207 | size_t num_args_; |
| 208 | size_t num_ref_args_; |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 209 | size_t num_float_or_double_args_; |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 210 | size_t num_long_or_double_args_; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | // Abstraction for managed code's calling conventions |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 214 | // | { Incoming stack args } | |
| 215 | // | { Prior Method* } | <-- Prior SP |
| 216 | // | { Return address } | |
| 217 | // | { Callee saves } | |
| 218 | // | { Spills ... } | |
| 219 | // | { Outgoing stack args } | |
| 220 | // | { Method* } | <-- SP |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 221 | class ManagedRuntimeCallingConvention : public CallingConvention { |
| 222 | public: |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 223 | static ManagedRuntimeCallingConvention* Create(bool is_static, bool is_synchronized, |
| 224 | const char* shorty, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 225 | InstructionSet instruction_set); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 226 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 227 | // Register that holds the incoming method argument |
| 228 | virtual ManagedRegister MethodRegister() = 0; |
| 229 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 230 | // Iterator interface |
| 231 | bool HasNext(); |
| 232 | void Next(); |
| 233 | bool IsCurrentParamAReference(); |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 234 | bool IsCurrentParamAFloatOrDouble(); |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 235 | bool IsCurrentParamADouble(); |
| 236 | bool IsCurrentParamALong(); |
Ian Rogers | 7a99c11 | 2011-09-07 12:48:27 -0700 | [diff] [blame] | 237 | bool IsCurrentArgExplicit(); // ie a non-implict argument such as this |
| 238 | bool IsCurrentArgPossiblyNull(); |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 239 | size_t CurrentParamSize(); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 240 | virtual bool IsCurrentParamInRegister() = 0; |
| 241 | virtual bool IsCurrentParamOnStack() = 0; |
| 242 | virtual ManagedRegister CurrentParamRegister() = 0; |
| 243 | virtual FrameOffset CurrentParamStackOffset() = 0; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 244 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 245 | virtual ~ManagedRuntimeCallingConvention() {} |
| 246 | |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 247 | // Registers to spill to caller's out registers on entry. |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 248 | virtual const ManagedRegisterEntrySpills& EntrySpills() = 0; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 249 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 250 | protected: |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 251 | ManagedRuntimeCallingConvention(bool is_static, bool is_synchronized, const char* shorty, |
| 252 | size_t frame_pointer_size) |
| 253 | : CallingConvention(is_static, is_synchronized, shorty, frame_pointer_size) {} |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
| 256 | // Abstraction for JNI calling conventions |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 257 | // | { Incoming stack args } | <-- Prior SP |
| 258 | // | { Return address } | |
| 259 | // | { Callee saves } | ([1]) |
| 260 | // | { Return value spill } | (live on return slow paths) |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 261 | // | { Local Ref. Table State } | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 262 | // | { Stack Indirect Ref. Table | |
| 263 | // | num. refs./link } | (here to prior SP is frame size) |
| 264 | // | { Method* } | <-- Anchor SP written to thread |
| 265 | // | { Outgoing stack args } | <-- SP at point of call |
| 266 | // | Native frame | |
| 267 | // |
| 268 | // [1] We must save all callee saves here to enable any exception throws to restore |
| 269 | // callee saves for frames above this one. |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 270 | class JniCallingConvention : public CallingConvention { |
| 271 | public: |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 272 | static JniCallingConvention* Create(bool is_static, bool is_synchronized, const char* shorty, |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 273 | InstructionSet instruction_set); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 274 | |
| 275 | // Size of frame excluding space for outgoing args (its assumed Method* is |
| 276 | // always at the bottom of a frame, but this doesn't work for outgoing |
| 277 | // native args). Includes alignment. |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 278 | virtual size_t FrameSize() = 0; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 279 | // Size of outgoing arguments, including alignment |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 280 | virtual size_t OutArgSize() = 0; |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 281 | // Number of references in stack indirect reference table |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 282 | size_t ReferenceCount() const; |
| 283 | // Location where the segment state of the local indirect reference table is saved |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame] | 284 | FrameOffset SavedLocalReferenceCookieOffset() const; |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 285 | // Location where the return value of a call can be squirreled if another |
| 286 | // call is made following the native call |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 287 | FrameOffset ReturnValueSaveLocation() const; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 288 | // Register that holds result if it is integer. |
| 289 | virtual ManagedRegister IntReturnRegister() = 0; |
Andreas Gampe | d110432 | 2014-05-01 14:38:56 -0700 | [diff] [blame] | 290 | // Whether the compiler needs to ensure zero-/sign-extension of a small result type |
| 291 | virtual bool RequiresSmallResultTypeExtension() const = 0; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 292 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 293 | // Callee save registers to spill prior to native code (which may clobber) |
| 294 | virtual const std::vector<ManagedRegister>& CalleeSaveRegisters() const = 0; |
| 295 | |
| 296 | // Spill mask values |
| 297 | virtual uint32_t CoreSpillMask() const = 0; |
| 298 | virtual uint32_t FpSpillMask() const = 0; |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 299 | |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 300 | // An extra scratch register live after the call |
| 301 | virtual ManagedRegister ReturnScratchRegister() const = 0; |
| 302 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 303 | // Iterator interface |
| 304 | bool HasNext(); |
Ian Rogers | 67375ac | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 305 | virtual void Next(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 306 | bool IsCurrentParamAReference(); |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 307 | bool IsCurrentParamAFloatOrDouble(); |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 308 | bool IsCurrentParamADouble(); |
| 309 | bool IsCurrentParamALong(); |
| 310 | bool IsCurrentParamJniEnv(); |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 311 | size_t CurrentParamSize(); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 312 | virtual bool IsCurrentParamInRegister() = 0; |
| 313 | virtual bool IsCurrentParamOnStack() = 0; |
| 314 | virtual ManagedRegister CurrentParamRegister() = 0; |
| 315 | virtual FrameOffset CurrentParamStackOffset() = 0; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 316 | |
| 317 | // Iterator interface extension for JNI |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 318 | FrameOffset CurrentParamSirtEntryOffset(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 319 | |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 320 | // Position of SIRT and interior fields |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 321 | FrameOffset SirtOffset() const { |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 322 | return FrameOffset(this->displacement_.Int32Value() + frame_pointer_size_); // above Method* |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 323 | } |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 324 | |
| 325 | FrameOffset SirtLinkOffset() const { |
| 326 | return FrameOffset(SirtOffset().Int32Value() + |
Dmitry Petrochenko | 135016a | 2014-04-03 14:35:54 +0700 | [diff] [blame] | 327 | StackIndirectReferenceTable::LinkOffset(frame_pointer_size_)); |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 328 | } |
| 329 | |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 330 | FrameOffset SirtNumRefsOffset() const { |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 331 | return FrameOffset(SirtOffset().Int32Value() + |
Dmitry Petrochenko | 135016a | 2014-04-03 14:35:54 +0700 | [diff] [blame] | 332 | StackIndirectReferenceTable::NumberOfReferencesOffset(frame_pointer_size_)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 333 | } |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 334 | |
| 335 | FrameOffset SirtReferencesOffset() const { |
Dmitry Petrochenko | f0513c5 | 2014-03-31 09:12:31 +0700 | [diff] [blame] | 336 | return FrameOffset(SirtOffset().Int32Value() + |
Dmitry Petrochenko | 135016a | 2014-04-03 14:35:54 +0700 | [diff] [blame] | 337 | StackIndirectReferenceTable::ReferencesOffset(frame_pointer_size_)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 340 | virtual ~JniCallingConvention() {} |
| 341 | |
| 342 | protected: |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 343 | // Named iterator positions |
| 344 | enum IteratorPos { |
| 345 | kJniEnv = 0, |
| 346 | kObjectOrClass = 1 |
| 347 | }; |
| 348 | |
Ian Rogers | 790a6b7 | 2014-04-01 10:36:00 -0700 | [diff] [blame] | 349 | explicit JniCallingConvention(bool is_static, bool is_synchronized, const char* shorty, |
| 350 | size_t frame_pointer_size) |
| 351 | : CallingConvention(is_static, is_synchronized, shorty, frame_pointer_size) {} |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 352 | |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 353 | // Number of stack slots for outgoing arguments, above which the SIRT is |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 354 | // located |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 355 | virtual size_t NumberOfOutgoingStackArgs() = 0; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 356 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 357 | protected: |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 358 | size_t NumberOfExtraArgumentsForJni(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 359 | }; |
| 360 | |
| 361 | } // namespace art |
| 362 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 363 | #endif // ART_COMPILER_JNI_QUICK_CALLING_CONVENTION_H_ |