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