Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | #include "interpreter_common.h" |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 18 | |
Andreas Gampe | f0e128a | 2015-02-27 20:08:34 -0800 | [diff] [blame] | 19 | #include <cmath> |
| 20 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 21 | #include "base/enums.h" |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 22 | #include "debugger.h" |
Nicolas Geoffray | 7bf2b4f | 2015-07-08 10:11:59 +0000 | [diff] [blame] | 23 | #include "entrypoints/runtime_asm_entrypoints.h" |
Tamas Berghammer | dd5e5e9 | 2016-02-12 16:29:00 +0000 | [diff] [blame] | 24 | #include "jit/jit.h" |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 25 | #include "jvalue.h" |
| 26 | #include "method_handles.h" |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 27 | #include "method_handles-inl.h" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 29 | #include "mirror/class.h" |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 30 | #include "mirror/emulated_stack_frame.h" |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 31 | #include "mirror/method_handle_impl.h" |
| 32 | #include "reflection.h" |
| 33 | #include "reflection-inl.h" |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 34 | #include "stack.h" |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 35 | #include "unstarted_runtime.h" |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 36 | #include "verifier/method_verifier.h" |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 37 | #include "well_known_classes.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | namespace interpreter { |
| 41 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 42 | void ThrowNullPointerExceptionFromInterpreter() { |
| 43 | ThrowNullPointerExceptionFromDexPC(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check> |
| 47 | bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, |
| 48 | uint16_t inst_data) { |
| 49 | const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead); |
| 50 | const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c(); |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 51 | ArtField* f = |
| 52 | FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self, |
| 53 | Primitive::ComponentSize(field_type)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 54 | if (UNLIKELY(f == nullptr)) { |
| 55 | CHECK(self->IsExceptionPending()); |
| 56 | return false; |
| 57 | } |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 58 | ObjPtr<mirror::Object> obj; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 59 | if (is_static) { |
| 60 | obj = f->GetDeclaringClass(); |
| 61 | } else { |
| 62 | obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
| 63 | if (UNLIKELY(obj == nullptr)) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 64 | ThrowNullPointerExceptionForFieldAccess(f, true); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 65 | return false; |
| 66 | } |
| 67 | } |
Sebastien Hertz | 1edbd8e | 2014-07-16 20:00:11 +0200 | [diff] [blame] | 68 | f->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 69 | // Report this field access to instrumentation if needed. |
| 70 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 71 | if (UNLIKELY(instrumentation->HasFieldReadListeners())) { |
Mathieu Chartier | 0715c0b | 2016-10-03 22:49:46 -0700 | [diff] [blame] | 72 | StackHandleScope<1> hs(self); |
| 73 | // Wrap in handle wrapper in case the listener does thread suspension. |
| 74 | HandleWrapperObjPtr<mirror::Object> h(hs.NewHandleWrapper(&obj)); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 75 | ObjPtr<mirror::Object> this_object; |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 76 | if (!f->IsStatic()) { |
| 77 | this_object = obj; |
| 78 | } |
| 79 | instrumentation->FieldReadEvent(self, |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 80 | this_object.Ptr(), |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 81 | shadow_frame.GetMethod(), |
| 82 | shadow_frame.GetDexPC(), |
| 83 | f); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 84 | } |
| 85 | uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); |
| 86 | switch (field_type) { |
| 87 | case Primitive::kPrimBoolean: |
| 88 | shadow_frame.SetVReg(vregA, f->GetBoolean(obj)); |
| 89 | break; |
| 90 | case Primitive::kPrimByte: |
| 91 | shadow_frame.SetVReg(vregA, f->GetByte(obj)); |
| 92 | break; |
| 93 | case Primitive::kPrimChar: |
| 94 | shadow_frame.SetVReg(vregA, f->GetChar(obj)); |
| 95 | break; |
| 96 | case Primitive::kPrimShort: |
| 97 | shadow_frame.SetVReg(vregA, f->GetShort(obj)); |
| 98 | break; |
| 99 | case Primitive::kPrimInt: |
| 100 | shadow_frame.SetVReg(vregA, f->GetInt(obj)); |
| 101 | break; |
| 102 | case Primitive::kPrimLong: |
| 103 | shadow_frame.SetVRegLong(vregA, f->GetLong(obj)); |
| 104 | break; |
| 105 | case Primitive::kPrimNot: |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 106 | shadow_frame.SetVRegReference(vregA, f->GetObject(obj).Ptr()); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 107 | break; |
| 108 | default: |
| 109 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 110 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 111 | } |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | // Explicitly instantiate all DoFieldGet functions. |
| 116 | #define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \ |
| 117 | template bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, \ |
| 118 | ShadowFrame& shadow_frame, \ |
| 119 | const Instruction* inst, \ |
| 120 | uint16_t inst_data) |
| 121 | |
| 122 | #define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \ |
| 123 | EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \ |
| 124 | EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true); |
| 125 | |
| 126 | // iget-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 127 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean) |
| 128 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte) |
| 129 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar) |
| 130 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort) |
| 131 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt) |
| 132 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong) |
| 133 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 134 | |
| 135 | // sget-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 136 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean) |
| 137 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte) |
| 138 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar) |
| 139 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort) |
| 140 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt) |
| 141 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong) |
| 142 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 143 | |
| 144 | #undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL |
| 145 | #undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL |
| 146 | |
| 147 | // Handles iget-quick, iget-wide-quick and iget-object-quick instructions. |
| 148 | // Returns true on success, otherwise throws an exception and returns false. |
| 149 | template<Primitive::Type field_type> |
| 150 | bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 151 | ObjPtr<mirror::Object> obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 152 | if (UNLIKELY(obj == nullptr)) { |
| 153 | // We lost the reference to the field index so we cannot get a more |
| 154 | // precised exception message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 155 | ThrowNullPointerExceptionFromDexPC(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 156 | return false; |
| 157 | } |
| 158 | MemberOffset field_offset(inst->VRegC_22c()); |
| 159 | // Report this field access to instrumentation if needed. Since we only have the offset of |
| 160 | // the field from the base of the object, we need to look for it first. |
| 161 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 162 | if (UNLIKELY(instrumentation->HasFieldReadListeners())) { |
| 163 | ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), |
| 164 | field_offset.Uint32Value()); |
| 165 | DCHECK(f != nullptr); |
| 166 | DCHECK(!f->IsStatic()); |
Mathieu Chartier | a314773 | 2016-10-26 22:57:02 -0700 | [diff] [blame] | 167 | StackHandleScope<1> hs(Thread::Current()); |
| 168 | // Save obj in case the instrumentation event has thread suspension. |
| 169 | HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&obj); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 170 | instrumentation->FieldReadEvent(Thread::Current(), |
| 171 | obj.Ptr(), |
| 172 | shadow_frame.GetMethod(), |
| 173 | shadow_frame.GetDexPC(), |
| 174 | f); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 175 | } |
| 176 | // Note: iget-x-quick instructions are only for non-volatile fields. |
| 177 | const uint32_t vregA = inst->VRegA_22c(inst_data); |
| 178 | switch (field_type) { |
| 179 | case Primitive::kPrimInt: |
| 180 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset))); |
| 181 | break; |
Mathieu Chartier | ffc605c | 2014-12-10 10:35:44 -0800 | [diff] [blame] | 182 | case Primitive::kPrimBoolean: |
| 183 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldBoolean(field_offset))); |
| 184 | break; |
| 185 | case Primitive::kPrimByte: |
| 186 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldByte(field_offset))); |
| 187 | break; |
| 188 | case Primitive::kPrimChar: |
| 189 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldChar(field_offset))); |
| 190 | break; |
| 191 | case Primitive::kPrimShort: |
| 192 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldShort(field_offset))); |
| 193 | break; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 194 | case Primitive::kPrimLong: |
| 195 | shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset))); |
| 196 | break; |
| 197 | case Primitive::kPrimNot: |
| 198 | shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset)); |
| 199 | break; |
| 200 | default: |
| 201 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 202 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 203 | } |
| 204 | return true; |
| 205 | } |
| 206 | |
| 207 | // Explicitly instantiate all DoIGetQuick functions. |
| 208 | #define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \ |
| 209 | template bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \ |
| 210 | uint16_t inst_data) |
| 211 | |
Mathieu Chartier | ffc605c | 2014-12-10 10:35:44 -0800 | [diff] [blame] | 212 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick. |
| 213 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimBoolean); // iget-boolean-quick. |
| 214 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimByte); // iget-byte-quick. |
| 215 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimChar); // iget-char-quick. |
| 216 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimShort); // iget-short-quick. |
| 217 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick. |
| 218 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick. |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 219 | #undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL |
| 220 | |
| 221 | template<Primitive::Type field_type> |
| 222 | static JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 223 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 224 | JValue field_value; |
| 225 | switch (field_type) { |
| 226 | case Primitive::kPrimBoolean: |
| 227 | field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg))); |
| 228 | break; |
| 229 | case Primitive::kPrimByte: |
| 230 | field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg))); |
| 231 | break; |
| 232 | case Primitive::kPrimChar: |
| 233 | field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg))); |
| 234 | break; |
| 235 | case Primitive::kPrimShort: |
| 236 | field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg))); |
| 237 | break; |
| 238 | case Primitive::kPrimInt: |
| 239 | field_value.SetI(shadow_frame.GetVReg(vreg)); |
| 240 | break; |
| 241 | case Primitive::kPrimLong: |
| 242 | field_value.SetJ(shadow_frame.GetVRegLong(vreg)); |
| 243 | break; |
| 244 | case Primitive::kPrimNot: |
| 245 | field_value.SetL(shadow_frame.GetVRegReference(vreg)); |
| 246 | break; |
| 247 | default: |
| 248 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 249 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 250 | } |
| 251 | return field_value; |
| 252 | } |
| 253 | |
| 254 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, |
| 255 | bool transaction_active> |
| 256 | bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst, |
| 257 | uint16_t inst_data) { |
| 258 | bool do_assignability_check = do_access_check; |
| 259 | bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite); |
| 260 | uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c(); |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 261 | ArtField* f = |
| 262 | FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self, |
| 263 | Primitive::ComponentSize(field_type)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 264 | if (UNLIKELY(f == nullptr)) { |
| 265 | CHECK(self->IsExceptionPending()); |
| 266 | return false; |
| 267 | } |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 268 | ObjPtr<mirror::Object> obj; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 269 | if (is_static) { |
| 270 | obj = f->GetDeclaringClass(); |
| 271 | } else { |
| 272 | obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
| 273 | if (UNLIKELY(obj == nullptr)) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 274 | ThrowNullPointerExceptionForFieldAccess(f, false); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 275 | return false; |
| 276 | } |
| 277 | } |
Sebastien Hertz | 1edbd8e | 2014-07-16 20:00:11 +0200 | [diff] [blame] | 278 | f->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 279 | uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); |
| 280 | // Report this field access to instrumentation if needed. Since we only have the offset of |
| 281 | // the field from the base of the object, we need to look for it first. |
| 282 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 283 | if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { |
Mathieu Chartier | 0715c0b | 2016-10-03 22:49:46 -0700 | [diff] [blame] | 284 | StackHandleScope<1> hs(self); |
| 285 | // Wrap in handle wrapper in case the listener does thread suspension. |
| 286 | HandleWrapperObjPtr<mirror::Object> h(hs.NewHandleWrapper(&obj)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 287 | JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 288 | ObjPtr<mirror::Object> this_object = f->IsStatic() ? nullptr : obj; |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 289 | instrumentation->FieldWriteEvent(self, this_object.Ptr(), |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 290 | shadow_frame.GetMethod(), |
| 291 | shadow_frame.GetDexPC(), |
| 292 | f, |
| 293 | field_value); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 294 | } |
| 295 | switch (field_type) { |
| 296 | case Primitive::kPrimBoolean: |
| 297 | f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
| 298 | break; |
| 299 | case Primitive::kPrimByte: |
| 300 | f->SetByte<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
| 301 | break; |
| 302 | case Primitive::kPrimChar: |
| 303 | f->SetChar<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
| 304 | break; |
| 305 | case Primitive::kPrimShort: |
| 306 | f->SetShort<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
| 307 | break; |
| 308 | case Primitive::kPrimInt: |
| 309 | f->SetInt<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
| 310 | break; |
| 311 | case Primitive::kPrimLong: |
| 312 | f->SetLong<transaction_active>(obj, shadow_frame.GetVRegLong(vregA)); |
| 313 | break; |
| 314 | case Primitive::kPrimNot: { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 315 | ObjPtr<mirror::Object> reg = shadow_frame.GetVRegReference(vregA); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 316 | if (do_assignability_check && reg != nullptr) { |
| 317 | // FieldHelper::GetType can resolve classes, use a handle wrapper which will restore the |
| 318 | // object in the destructor. |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 319 | ObjPtr<mirror::Class> field_class; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 320 | { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 321 | StackHandleScope<2> hs(self); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 322 | HandleWrapperObjPtr<mirror::Object> h_reg(hs.NewHandleWrapper(®)); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 323 | HandleWrapperObjPtr<mirror::Object> h_obj(hs.NewHandleWrapper(&obj)); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 324 | field_class = f->GetType<true>(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 325 | } |
Mathieu Chartier | 1cc62e4 | 2016-10-03 18:01:28 -0700 | [diff] [blame] | 326 | if (!reg->VerifierInstanceOf(field_class.Ptr())) { |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 327 | // This should never happen. |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 328 | std::string temp1, temp2, temp3; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 329 | self->ThrowNewExceptionF("Ljava/lang/VirtualMachineError;", |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 330 | "Put '%s' that is not instance of field '%s' in '%s'", |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 331 | reg->GetClass()->GetDescriptor(&temp1), |
| 332 | field_class->GetDescriptor(&temp2), |
| 333 | f->GetDeclaringClass()->GetDescriptor(&temp3)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 334 | return false; |
| 335 | } |
| 336 | } |
| 337 | f->SetObj<transaction_active>(obj, reg); |
| 338 | break; |
| 339 | } |
| 340 | default: |
| 341 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 342 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 343 | } |
| 344 | return true; |
| 345 | } |
| 346 | |
| 347 | // Explicitly instantiate all DoFieldPut functions. |
| 348 | #define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \ |
| 349 | template bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \ |
| 350 | const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) |
| 351 | |
| 352 | #define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \ |
| 353 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \ |
| 354 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \ |
| 355 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \ |
| 356 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true); |
| 357 | |
| 358 | // iput-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 359 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean) |
| 360 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte) |
| 361 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar) |
| 362 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort) |
| 363 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt) |
| 364 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong) |
| 365 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 366 | |
| 367 | // sput-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 368 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean) |
| 369 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte) |
| 370 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar) |
| 371 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort) |
| 372 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt) |
| 373 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong) |
| 374 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 375 | |
| 376 | #undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL |
| 377 | #undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL |
| 378 | |
| 379 | template<Primitive::Type field_type, bool transaction_active> |
| 380 | bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 381 | ObjPtr<mirror::Object> obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 382 | if (UNLIKELY(obj == nullptr)) { |
| 383 | // We lost the reference to the field index so we cannot get a more |
| 384 | // precised exception message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 385 | ThrowNullPointerExceptionFromDexPC(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 386 | return false; |
| 387 | } |
| 388 | MemberOffset field_offset(inst->VRegC_22c()); |
| 389 | const uint32_t vregA = inst->VRegA_22c(inst_data); |
| 390 | // Report this field modification to instrumentation if needed. Since we only have the offset of |
| 391 | // the field from the base of the object, we need to look for it first. |
| 392 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 393 | if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { |
| 394 | ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), |
| 395 | field_offset.Uint32Value()); |
| 396 | DCHECK(f != nullptr); |
| 397 | DCHECK(!f->IsStatic()); |
| 398 | JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); |
Mathieu Chartier | a314773 | 2016-10-26 22:57:02 -0700 | [diff] [blame] | 399 | StackHandleScope<1> hs(Thread::Current()); |
| 400 | // Save obj in case the instrumentation event has thread suspension. |
| 401 | HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&obj); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 402 | instrumentation->FieldWriteEvent(Thread::Current(), |
| 403 | obj.Ptr(), |
| 404 | shadow_frame.GetMethod(), |
| 405 | shadow_frame.GetDexPC(), |
| 406 | f, |
| 407 | field_value); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 408 | } |
| 409 | // Note: iput-x-quick instructions are only for non-volatile fields. |
| 410 | switch (field_type) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 411 | case Primitive::kPrimBoolean: |
| 412 | obj->SetFieldBoolean<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 413 | break; |
| 414 | case Primitive::kPrimByte: |
| 415 | obj->SetFieldByte<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 416 | break; |
| 417 | case Primitive::kPrimChar: |
| 418 | obj->SetFieldChar<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 419 | break; |
| 420 | case Primitive::kPrimShort: |
| 421 | obj->SetFieldShort<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 422 | break; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 423 | case Primitive::kPrimInt: |
| 424 | obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 425 | break; |
| 426 | case Primitive::kPrimLong: |
| 427 | obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA)); |
| 428 | break; |
| 429 | case Primitive::kPrimNot: |
| 430 | obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA)); |
| 431 | break; |
| 432 | default: |
| 433 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 434 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 435 | } |
| 436 | return true; |
| 437 | } |
| 438 | |
| 439 | // Explicitly instantiate all DoIPutQuick functions. |
| 440 | #define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \ |
| 441 | template bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \ |
| 442 | const Instruction* inst, \ |
| 443 | uint16_t inst_data) |
| 444 | |
| 445 | #define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \ |
| 446 | EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \ |
| 447 | EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true); |
| 448 | |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 449 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt) // iput-quick. |
| 450 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimBoolean) // iput-boolean-quick. |
| 451 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimByte) // iput-byte-quick. |
| 452 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimChar) // iput-char-quick. |
| 453 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimShort) // iput-short-quick. |
| 454 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong) // iput-wide-quick. |
| 455 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot) // iput-object-quick. |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 456 | #undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL |
| 457 | #undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL |
| 458 | |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 459 | // We accept a null Instrumentation* meaning we must not report anything to the instrumentation. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 460 | uint32_t FindNextInstructionFollowingException( |
| 461 | Thread* self, ShadowFrame& shadow_frame, uint32_t dex_pc, |
| 462 | const instrumentation::Instrumentation* instrumentation) { |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 463 | self->VerifyStack(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 464 | StackHandleScope<2> hs(self); |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 465 | Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException())); |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 466 | if (instrumentation != nullptr && instrumentation->HasExceptionCaughtListeners() |
Nicolas Geoffray | 7642cfc | 2015-02-26 10:56:09 +0000 | [diff] [blame] | 467 | && self->IsExceptionThrownByCurrentMethod(exception.Get())) { |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 468 | instrumentation->ExceptionCaughtEvent(self, exception.Get()); |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 469 | } |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 470 | bool clear_exception = false; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 471 | uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock( |
| 472 | hs.NewHandle(exception->GetClass()), dex_pc, &clear_exception); |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 473 | if (found_dex_pc == DexFile::kDexNoIndex && instrumentation != nullptr) { |
Nicolas Geoffray | 7642cfc | 2015-02-26 10:56:09 +0000 | [diff] [blame] | 474 | // Exception is not caught by the current method. We will unwind to the |
| 475 | // caller. Notify any instrumentation listener. |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 476 | instrumentation->MethodUnwindEvent(self, shadow_frame.GetThisObject(), |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 477 | shadow_frame.GetMethod(), dex_pc); |
| 478 | } else { |
Nicolas Geoffray | 7642cfc | 2015-02-26 10:56:09 +0000 | [diff] [blame] | 479 | // Exception is caught in the current method. We will jump to the found_dex_pc. |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 480 | if (clear_exception) { |
| 481 | self->ClearException(); |
| 482 | } |
| 483 | } |
| 484 | return found_dex_pc; |
| 485 | } |
| 486 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 487 | void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame) { |
| 488 | LOG(FATAL) << "Unexpected instruction: " |
| 489 | << inst->DumpString(shadow_frame.GetMethod()->GetDexFile()); |
| 490 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Sebastien Hertz | 45b1597 | 2015-04-03 16:07:05 +0200 | [diff] [blame] | 493 | void AbortTransactionF(Thread* self, const char* fmt, ...) { |
Mathieu Chartier | b2c7ead | 2014-04-29 11:13:16 -0700 | [diff] [blame] | 494 | va_list args; |
| 495 | va_start(args, fmt); |
Sebastien Hertz | 45b1597 | 2015-04-03 16:07:05 +0200 | [diff] [blame] | 496 | AbortTransactionV(self, fmt, args); |
| 497 | va_end(args); |
| 498 | } |
| 499 | |
| 500 | void AbortTransactionV(Thread* self, const char* fmt, va_list args) { |
| 501 | CHECK(Runtime::Current()->IsActiveTransaction()); |
| 502 | // Constructs abort message. |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 503 | std::string abort_msg; |
| 504 | StringAppendV(&abort_msg, fmt, args); |
| 505 | // Throws an exception so we can abort the transaction and rollback every change. |
Sebastien Hertz | 2fd7e69 | 2015-04-02 11:11:19 +0200 | [diff] [blame] | 506 | Runtime::Current()->AbortTransactionAndThrowAbortError(self, abort_msg); |
Mathieu Chartier | b2c7ead | 2014-04-29 11:13:16 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 509 | // START DECLARATIONS : |
| 510 | // |
| 511 | // These additional declarations are required because clang complains |
| 512 | // about ALWAYS_INLINE (-Werror, -Wgcc-compat) in definitions. |
| 513 | // |
| 514 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 515 | template <bool is_range, bool do_assignability_check> |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 516 | REQUIRES_SHARED(Locks::mutator_lock_) |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 517 | static inline bool DoCallCommon(ArtMethod* called_method, |
| 518 | Thread* self, |
| 519 | ShadowFrame& shadow_frame, |
| 520 | JValue* result, |
| 521 | uint16_t number_of_inputs, |
Narayan Kamath | 370423d | 2016-10-03 16:51:22 +0100 | [diff] [blame] | 522 | uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 523 | uint32_t vregC) ALWAYS_INLINE; |
| 524 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 525 | template <bool is_range> REQUIRES_SHARED(Locks::mutator_lock_) |
| 526 | static inline bool DoCallPolymorphic(ArtMethod* called_method, |
| 527 | Handle<mirror::MethodType> callsite_type, |
| 528 | Handle<mirror::MethodType> target_type, |
| 529 | Thread* self, |
| 530 | ShadowFrame& shadow_frame, |
| 531 | JValue* result, |
| 532 | uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 533 | uint32_t vregC, |
| 534 | const MethodHandleKind handle_kind) ALWAYS_INLINE; |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 535 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 536 | template <bool is_range> REQUIRES_SHARED(Locks::mutator_lock_) |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 537 | static inline bool DoCallTransform(ArtMethod* called_method, |
| 538 | Handle<mirror::MethodType> callsite_type, |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 539 | Handle<mirror::MethodType> callee_type, |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 540 | Thread* self, |
| 541 | ShadowFrame& shadow_frame, |
| 542 | Handle<mirror::MethodHandleImpl> receiver, |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 543 | JValue* result, |
| 544 | uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
| 545 | uint32_t vregC) ALWAYS_INLINE; |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 546 | |
| 547 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 548 | inline void PerformCall(Thread* self, |
| 549 | const DexFile::CodeItem* code_item, |
| 550 | ArtMethod* caller_method, |
| 551 | const size_t first_dest_reg, |
| 552 | ShadowFrame* callee_frame, |
| 553 | JValue* result) ALWAYS_INLINE; |
| 554 | |
| 555 | template <bool is_range> |
| 556 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 557 | inline void CopyRegisters(ShadowFrame& caller_frame, |
| 558 | ShadowFrame* callee_frame, |
| 559 | const uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
| 560 | const size_t first_src_reg, |
| 561 | const size_t first_dest_reg, |
| 562 | const size_t num_regs) ALWAYS_INLINE; |
| 563 | |
| 564 | // END DECLARATIONS. |
| 565 | |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 566 | void ArtInterpreterToCompiledCodeBridge(Thread* self, |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 567 | ArtMethod* caller, |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 568 | const DexFile::CodeItem* code_item, |
| 569 | ShadowFrame* shadow_frame, |
| 570 | JValue* result) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 571 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 572 | ArtMethod* method = shadow_frame->GetMethod(); |
| 573 | // Ensure static methods are initialized. |
| 574 | if (method->IsStatic()) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 575 | ObjPtr<mirror::Class> declaringClass = method->GetDeclaringClass(); |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 576 | if (UNLIKELY(!declaringClass->IsInitialized())) { |
| 577 | self->PushShadowFrame(shadow_frame); |
| 578 | StackHandleScope<1> hs(self); |
| 579 | Handle<mirror::Class> h_class(hs.NewHandle(declaringClass)); |
| 580 | if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true, |
| 581 | true))) { |
| 582 | self->PopShadowFrame(); |
| 583 | DCHECK(self->IsExceptionPending()); |
| 584 | return; |
| 585 | } |
| 586 | self->PopShadowFrame(); |
| 587 | CHECK(h_class->IsInitializing()); |
| 588 | // Reload from shadow frame in case the method moved, this is faster than adding a handle. |
| 589 | method = shadow_frame->GetMethod(); |
| 590 | } |
| 591 | } |
| 592 | uint16_t arg_offset = (code_item == nullptr) |
| 593 | ? 0 |
| 594 | : code_item->registers_size_ - code_item->ins_size_; |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 595 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 596 | if (jit != nullptr && caller != nullptr) { |
| 597 | jit->NotifyInterpreterToCompiledCodeTransition(self, caller); |
| 598 | } |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 599 | method->Invoke(self, shadow_frame->GetVRegArgs(arg_offset), |
| 600 | (shadow_frame->NumberOfVRegs() - arg_offset) * sizeof(uint32_t), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 601 | result, method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty()); |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 604 | void SetStringInitValueToAllAliases(ShadowFrame* shadow_frame, |
| 605 | uint16_t this_obj_vreg, |
| 606 | JValue result) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 607 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 608 | ObjPtr<mirror::Object> existing = shadow_frame->GetVRegReference(this_obj_vreg); |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 609 | if (existing == nullptr) { |
| 610 | // If it's null, we come from compiled code that was deoptimized. Nothing to do, |
| 611 | // as the compiler verified there was no alias. |
| 612 | // Set the new string result of the StringFactory. |
| 613 | shadow_frame->SetVRegReference(this_obj_vreg, result.GetL()); |
| 614 | return; |
| 615 | } |
| 616 | // Set the string init result into all aliases. |
| 617 | for (uint32_t i = 0, e = shadow_frame->NumberOfVRegs(); i < e; ++i) { |
| 618 | if (shadow_frame->GetVRegReference(i) == existing) { |
| 619 | DCHECK_EQ(shadow_frame->GetVRegReference(i), |
| 620 | reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i))); |
| 621 | shadow_frame->SetVRegReference(i, result.GetL()); |
| 622 | DCHECK_EQ(shadow_frame->GetVRegReference(i), |
| 623 | reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i))); |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 628 | template<bool is_range, bool do_access_check> |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 629 | inline bool DoInvokePolymorphic(Thread* self, |
| 630 | ShadowFrame& shadow_frame, |
| 631 | const Instruction* inst, |
| 632 | uint16_t inst_data, |
| 633 | JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) { |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 634 | // Invoke-polymorphic instructions always take a receiver. i.e, they are never static. |
| 635 | const uint32_t vRegC = (is_range) ? inst->VRegC_4rcc() : inst->VRegC_45cc(); |
| 636 | |
| 637 | // The method_idx here is the name of the signature polymorphic method that |
| 638 | // was symbolically invoked in bytecode (say MethodHandle.invoke or MethodHandle.invokeExact) |
| 639 | // and not the method that we'll dispatch to in the end. |
| 640 | // |
| 641 | // TODO(narayan) We'll have to check in the verifier that this is in fact a |
| 642 | // signature polymorphic method so that we disallow calls via invoke-polymorphic |
| 643 | // to non sig-poly methods. This would also have the side effect of verifying |
| 644 | // that vRegC really is a reference type. |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 645 | StackHandleScope<6> hs(self); |
| 646 | Handle<mirror::MethodHandleImpl> method_handle(hs.NewHandle( |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 647 | ObjPtr<mirror::MethodHandleImpl>::DownCast( |
| 648 | MakeObjPtr(shadow_frame.GetVRegReference(vRegC))))); |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 649 | if (UNLIKELY(method_handle.Get() == nullptr)) { |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 650 | const int method_idx = (is_range) ? inst->VRegB_4rcc() : inst->VRegB_45cc(); |
| 651 | // Note that the invoke type is kVirtual here because a call to a signature |
| 652 | // polymorphic method is shaped like a virtual call at the bytecode level. |
| 653 | ThrowNullPointerExceptionForMethodAccess(method_idx, InvokeType::kVirtual); |
| 654 | |
| 655 | result->SetJ(0); |
| 656 | return false; |
| 657 | } |
| 658 | |
| 659 | // The vRegH value gives the index of the proto_id associated with this |
| 660 | // signature polymorphic callsite. |
| 661 | const uint32_t callsite_proto_id = (is_range) ? inst->VRegH_4rcc() : inst->VRegH_45cc(); |
| 662 | |
| 663 | // Call through to the classlinker and ask it to resolve the static type associated |
| 664 | // with the callsite. This information is stored in the dex cache so it's |
| 665 | // guaranteed to be fast after the first resolution. |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 666 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 667 | Handle<mirror::Class> caller_class(hs.NewHandle(shadow_frame.GetMethod()->GetDeclaringClass())); |
| 668 | Handle<mirror::MethodType> callsite_type(hs.NewHandle(class_linker->ResolveMethodType( |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 669 | caller_class->GetDexFile(), callsite_proto_id, |
| 670 | hs.NewHandle<mirror::DexCache>(caller_class->GetDexCache()), |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 671 | hs.NewHandle<mirror::ClassLoader>(caller_class->GetClassLoader())))); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 672 | |
| 673 | // This implies we couldn't resolve one or more types in this method handle. |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 674 | if (UNLIKELY(callsite_type.Get() == nullptr)) { |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 675 | CHECK(self->IsExceptionPending()); |
| 676 | result->SetJ(0); |
| 677 | return false; |
| 678 | } |
| 679 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 680 | // Get the method we're actually invoking along with the kind of |
| 681 | // invoke that is desired. We don't need to perform access checks at this |
| 682 | // point because they would have been performed on our behalf at the point |
| 683 | // of creation of the method handle. |
| 684 | ArtMethod* called_method = method_handle->GetTargetMethod(); |
| 685 | const MethodHandleKind handle_kind = method_handle->GetHandleKind(); |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 686 | Handle<mirror::MethodType> handle_type(hs.NewHandle(method_handle->GetMethodType())); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 687 | CHECK(called_method != nullptr); |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 688 | CHECK(handle_type.Get() != nullptr); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 689 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 690 | uint32_t arg[Instruction::kMaxVarArgRegs] = {}; |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 691 | uint32_t first_src_reg = 0; |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 692 | if (is_range) { |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 693 | first_src_reg = (inst->VRegC_4rcc() + 1); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 694 | } else { |
| 695 | inst->GetVarArgs(arg, inst_data); |
| 696 | arg[0] = arg[1]; |
| 697 | arg[1] = arg[2]; |
| 698 | arg[2] = arg[3]; |
| 699 | arg[3] = arg[4]; |
| 700 | arg[4] = 0; |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 701 | first_src_reg = arg[0]; |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | if (IsInvoke(handle_kind)) { |
| 705 | if (handle_kind == kInvokeVirtual || handle_kind == kInvokeInterface) { |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 706 | // TODO: Unfortunately, we have to postpone dynamic receiver based checks |
| 707 | // because the receiver might be cast or might come from an emulated stack |
| 708 | // frame, which means that it is unknown at this point. We perform these |
| 709 | // checks inside DoCallPolymorphic right before we do the actualy invoke. |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 710 | } else if (handle_kind == kInvokeDirect) { |
Narayan Kamath | 9bdaeeb | 2016-10-20 10:57:45 +0100 | [diff] [blame] | 711 | if (called_method->IsConstructor()) { |
| 712 | // TODO(narayan) : We need to handle the case where the target method is a |
| 713 | // constructor here. |
| 714 | UNIMPLEMENTED(FATAL) << "Direct invokes for constructors are not implemented yet."; |
| 715 | return false; |
| 716 | } |
| 717 | |
| 718 | // Nothing special to do in the case where we're not dealing with a |
| 719 | // constructor. It's a private method, and we've already access checked at |
| 720 | // the point of creating the handle. |
| 721 | } else if (handle_kind == kInvokeSuper) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 722 | ObjPtr<mirror::Class> declaring_class = called_method->GetDeclaringClass(); |
Narayan Kamath | 9bdaeeb | 2016-10-20 10:57:45 +0100 | [diff] [blame] | 723 | |
| 724 | // Note that we're not dynamically dispatching on the type of the receiver |
| 725 | // here. We use the static type of the "receiver" object that we've |
| 726 | // recorded in the method handle's type, which will be the same as the |
| 727 | // special caller that was specified at the point of lookup. |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 728 | ObjPtr<mirror::Class> referrer_class = handle_type->GetPTypes()->Get(0); |
Narayan Kamath | 9bdaeeb | 2016-10-20 10:57:45 +0100 | [diff] [blame] | 729 | if (!declaring_class->IsInterface()) { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 730 | ObjPtr<mirror::Class> super_class = referrer_class->GetSuperClass(); |
Narayan Kamath | 9bdaeeb | 2016-10-20 10:57:45 +0100 | [diff] [blame] | 731 | uint16_t vtable_index = called_method->GetMethodIndex(); |
| 732 | DCHECK(super_class != nullptr); |
| 733 | DCHECK(super_class->HasVTable()); |
| 734 | // Note that super_class is a super of referrer_class and called_method |
| 735 | // will always be declared by super_class (or one of its super classes). |
| 736 | DCHECK_LT(vtable_index, super_class->GetVTableLength()); |
| 737 | called_method = super_class->GetVTableEntry(vtable_index, kRuntimePointerSize); |
| 738 | } else { |
| 739 | called_method = referrer_class->FindVirtualMethodForInterfaceSuper( |
| 740 | called_method, kRuntimePointerSize); |
| 741 | } |
| 742 | |
| 743 | CHECK(called_method != nullptr); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 744 | } |
| 745 | |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 746 | if (handle_kind == kInvokeTransform) { |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 747 | return DoCallTransform<is_range>(called_method, |
| 748 | callsite_type, |
| 749 | handle_type, |
| 750 | self, |
| 751 | shadow_frame, |
| 752 | method_handle /* receiver */, |
| 753 | result, |
| 754 | arg, |
| 755 | first_src_reg); |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 756 | } else { |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 757 | return DoCallPolymorphic<is_range>(called_method, |
| 758 | callsite_type, |
| 759 | handle_type, |
| 760 | self, |
| 761 | shadow_frame, |
| 762 | result, |
| 763 | arg, |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 764 | first_src_reg, |
| 765 | handle_kind); |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 766 | } |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 767 | } else { |
| 768 | // TODO(narayan): Implement field getters and setters. |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 769 | UNIMPLEMENTED(FATAL) << "Field references in method handles are not implemented yet."; |
| 770 | return false; |
| 771 | } |
| 772 | } |
| 773 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 774 | // Calculate the number of ins for a proxy or native method, where we |
| 775 | // can't just look at the code item. |
| 776 | static inline size_t GetInsForProxyOrNativeMethod(ArtMethod* method) |
| 777 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 778 | DCHECK(method->IsNative() || method->IsProxyMethod()); |
| 779 | |
| 780 | method = method->GetInterfaceMethodIfProxy(kRuntimePointerSize); |
| 781 | size_t num_ins = 0; |
| 782 | // Separate accounting for the receiver, which isn't a part of the |
| 783 | // shorty. |
| 784 | if (!method->IsStatic()) { |
| 785 | ++num_ins; |
| 786 | } |
| 787 | |
| 788 | uint32_t shorty_len = 0; |
| 789 | const char* shorty = method->GetShorty(&shorty_len); |
| 790 | for (size_t i = 1; i < shorty_len; ++i) { |
| 791 | const char c = shorty[i]; |
| 792 | ++num_ins; |
| 793 | if (c == 'J' || c == 'D') { |
| 794 | ++num_ins; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | return num_ins; |
| 799 | } |
| 800 | |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 801 | |
| 802 | inline void PerformCall(Thread* self, |
| 803 | const DexFile::CodeItem* code_item, |
| 804 | ArtMethod* caller_method, |
| 805 | const size_t first_dest_reg, |
| 806 | ShadowFrame* callee_frame, |
| 807 | JValue* result) { |
| 808 | if (LIKELY(Runtime::Current()->IsStarted())) { |
| 809 | ArtMethod* target = callee_frame->GetMethod(); |
| 810 | if (ClassLinker::ShouldUseInterpreterEntrypoint( |
| 811 | target, |
| 812 | target->GetEntryPointFromQuickCompiledCode())) { |
| 813 | ArtInterpreterToInterpreterBridge(self, code_item, callee_frame, result); |
| 814 | } else { |
| 815 | ArtInterpreterToCompiledCodeBridge( |
| 816 | self, caller_method, code_item, callee_frame, result); |
| 817 | } |
| 818 | } else { |
| 819 | UnstartedRuntime::Invoke(self, code_item, callee_frame, result, first_dest_reg); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | template <bool is_range> |
| 824 | inline void CopyRegisters(ShadowFrame& caller_frame, |
| 825 | ShadowFrame* callee_frame, |
| 826 | const uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
| 827 | const size_t first_src_reg, |
| 828 | const size_t first_dest_reg, |
| 829 | const size_t num_regs) { |
| 830 | if (is_range) { |
| 831 | const size_t dest_reg_bound = first_dest_reg + num_regs; |
| 832 | for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < dest_reg_bound; |
| 833 | ++dest_reg, ++src_reg) { |
| 834 | AssignRegister(callee_frame, caller_frame, dest_reg, src_reg); |
| 835 | } |
| 836 | } else { |
| 837 | DCHECK_LE(num_regs, arraysize(arg)); |
| 838 | |
| 839 | for (size_t arg_index = 0; arg_index < num_regs; ++arg_index) { |
| 840 | AssignRegister(callee_frame, caller_frame, first_dest_reg + arg_index, arg[arg_index]); |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | // Returns true iff. the callsite type for a polymorphic invoke is transformer |
| 846 | // like, i.e that it has a single input argument whose type is |
| 847 | // dalvik.system.EmulatedStackFrame. |
| 848 | static inline bool IsCallerTransformer(Handle<mirror::MethodType> callsite_type) |
| 849 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 850 | ObjPtr<mirror::ObjectArray<mirror::Class>> param_types(callsite_type->GetPTypes()); |
| 851 | if (param_types->GetLength() == 1) { |
| 852 | ObjPtr<mirror::Class> param(param_types->GetWithoutChecks(0)); |
| 853 | return param == WellKnownClasses::ToClass(WellKnownClasses::dalvik_system_EmulatedStackFrame); |
| 854 | } |
| 855 | |
| 856 | return false; |
| 857 | } |
| 858 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 859 | template <bool is_range> |
| 860 | static inline bool DoCallPolymorphic(ArtMethod* called_method, |
| 861 | Handle<mirror::MethodType> callsite_type, |
| 862 | Handle<mirror::MethodType> target_type, |
| 863 | Thread* self, |
| 864 | ShadowFrame& shadow_frame, |
| 865 | JValue* result, |
| 866 | uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 867 | uint32_t first_src_reg, |
| 868 | const MethodHandleKind handle_kind) { |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 869 | // TODO(narayan): Wire in the String.init hacks. |
| 870 | |
| 871 | // Compute method information. |
| 872 | const DexFile::CodeItem* code_item = called_method->GetCodeItem(); |
| 873 | |
| 874 | // Number of registers for the callee's call frame. Note that for non-exact |
| 875 | // invokes, we always derive this information from the callee method. We |
| 876 | // cannot guarantee during verification that the number of registers encoded |
| 877 | // in the invoke is equal to the number of ins for the callee. This is because |
| 878 | // some transformations (such as boxing a long -> Long or wideining an |
| 879 | // int -> long will change that number. |
| 880 | uint16_t num_regs; |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 881 | size_t num_input_regs; |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 882 | size_t first_dest_reg; |
| 883 | if (LIKELY(code_item != nullptr)) { |
| 884 | num_regs = code_item->registers_size_; |
| 885 | first_dest_reg = num_regs - code_item->ins_size_; |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 886 | num_input_regs = code_item->ins_size_; |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 887 | // Parameter registers go at the end of the shadow frame. |
| 888 | DCHECK_NE(first_dest_reg, (size_t)-1); |
| 889 | } else { |
| 890 | // No local regs for proxy and native methods. |
| 891 | DCHECK(called_method->IsNative() || called_method->IsProxyMethod()); |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 892 | num_regs = num_input_regs = GetInsForProxyOrNativeMethod(called_method); |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 893 | first_dest_reg = 0; |
| 894 | } |
| 895 | |
| 896 | // Allocate shadow frame on the stack. |
| 897 | ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr = |
| 898 | CREATE_SHADOW_FRAME(num_regs, &shadow_frame, called_method, /* dex pc */ 0); |
| 899 | ShadowFrame* new_shadow_frame = shadow_frame_unique_ptr.get(); |
| 900 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 901 | // Whether this polymorphic invoke was issued by a transformer method. |
| 902 | bool is_caller_transformer = false; |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 903 | // Thread might be suspended during PerformArgumentConversions due to the |
| 904 | // allocations performed during boxing. |
| 905 | { |
| 906 | ScopedStackedShadowFramePusher pusher( |
| 907 | self, new_shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction); |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 908 | if (callsite_type->IsExactMatch(target_type.Get())) { |
| 909 | // This is an exact invoke, we can take the fast path of just copying all |
| 910 | // registers without performing any argument conversions. |
| 911 | CopyRegisters<is_range>(shadow_frame, |
| 912 | new_shadow_frame, |
| 913 | arg, |
| 914 | first_src_reg, |
| 915 | first_dest_reg, |
| 916 | num_input_regs); |
| 917 | } else { |
| 918 | // This includes the case where we're entering this invoke-polymorphic |
| 919 | // from a transformer method. In that case, the callsite_type will contain |
| 920 | // a single argument of type dalvik.system.EmulatedStackFrame. In that |
| 921 | // case, we'll have to unmarshal the EmulatedStackFrame into the |
| 922 | // new_shadow_frame and perform argument conversions on it. |
| 923 | if (IsCallerTransformer(callsite_type)) { |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 924 | is_caller_transformer = true; |
| 925 | // The emulated stack frame is the first and only argument when we're coming |
| 926 | // through from a transformer. |
| 927 | ObjPtr<mirror::EmulatedStackFrame> emulated_stack_frame( |
| 928 | reinterpret_cast<mirror::EmulatedStackFrame*>( |
| 929 | shadow_frame.GetVRegReference(first_src_reg))); |
| 930 | if (!emulated_stack_frame->WriteToShadowFrame(self, |
| 931 | target_type, |
| 932 | first_dest_reg, |
| 933 | new_shadow_frame)) { |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 934 | DCHECK(self->IsExceptionPending()); |
| 935 | result->SetL(0); |
| 936 | return false; |
| 937 | } |
| 938 | } else if (!ConvertAndCopyArgumentsFromCallerFrame<is_range>(self, |
| 939 | callsite_type, |
| 940 | target_type, |
| 941 | shadow_frame, |
| 942 | first_src_reg, |
| 943 | first_dest_reg, |
| 944 | arg, |
| 945 | new_shadow_frame)) { |
| 946 | DCHECK(self->IsExceptionPending()); |
| 947 | result->SetL(0); |
| 948 | return false; |
| 949 | } |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 953 | // See TODO in DoInvokePolymorphic : We need to perform this dynamic, receiver |
| 954 | // based dispatch right before we perform the actual call, because the |
| 955 | // receiver isn't known very early. |
| 956 | if (handle_kind == kInvokeVirtual || handle_kind == kInvokeInterface) { |
| 957 | ObjPtr<mirror::Object> receiver(new_shadow_frame->GetVRegReference(first_dest_reg)); |
| 958 | ObjPtr<mirror::Class> declaring_class(called_method->GetDeclaringClass()); |
| 959 | // Verify that _vRegC is an object reference and of the type expected by |
| 960 | // the receiver. |
| 961 | if (!VerifyObjectIsClass(receiver, declaring_class)) { |
| 962 | DCHECK(self->IsExceptionPending()); |
| 963 | return false; |
| 964 | } |
| 965 | |
| 966 | called_method = receiver->GetClass()->FindVirtualMethodForVirtualOrInterface( |
| 967 | called_method, kRuntimePointerSize); |
| 968 | } |
| 969 | |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 970 | PerformCall(self, code_item, shadow_frame.GetMethod(), first_dest_reg, new_shadow_frame, result); |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 971 | |
| 972 | // TODO(narayan): Perform return value conversions. |
| 973 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 974 | // If the caller of this signature polymorphic method was a transformer, |
| 975 | // we need to copy the result back out to the emulated stack frame. |
| 976 | if (is_caller_transformer && !self->IsExceptionPending()) { |
| 977 | ObjPtr<mirror::EmulatedStackFrame> emulated_stack_frame( |
| 978 | reinterpret_cast<mirror::EmulatedStackFrame*>( |
| 979 | shadow_frame.GetVRegReference(first_src_reg))); |
| 980 | |
| 981 | emulated_stack_frame->SetReturnValue(self, *result); |
| 982 | } |
| 983 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 984 | return !self->IsExceptionPending(); |
| 985 | } |
| 986 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 987 | template <bool is_range> |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 988 | static inline bool DoCallTransform(ArtMethod* called_method, |
| 989 | Handle<mirror::MethodType> callsite_type, |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 990 | Handle<mirror::MethodType> callee_type, |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 991 | Thread* self, |
| 992 | ShadowFrame& shadow_frame, |
| 993 | Handle<mirror::MethodHandleImpl> receiver, |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 994 | JValue* result, |
| 995 | uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
| 996 | uint32_t first_src_reg) { |
| 997 | // This can be fixed to two, because the method we're calling here |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 998 | // (MethodHandle.transformInternal) doesn't have any locals and the signature |
| 999 | // is known : |
| 1000 | // |
| 1001 | // private MethodHandle.transformInternal(EmulatedStackFrame sf); |
| 1002 | // |
| 1003 | // This means we need only two vregs : |
| 1004 | // - One for the receiver object. |
| 1005 | // - One for the only method argument (an EmulatedStackFrame). |
| 1006 | static constexpr size_t kNumRegsForTransform = 2; |
| 1007 | |
| 1008 | const DexFile::CodeItem* code_item = called_method->GetCodeItem(); |
| 1009 | DCHECK(code_item != nullptr); |
| 1010 | DCHECK_EQ(kNumRegsForTransform, code_item->registers_size_); |
| 1011 | DCHECK_EQ(kNumRegsForTransform, code_item->ins_size_); |
| 1012 | |
| 1013 | ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr = |
| 1014 | CREATE_SHADOW_FRAME(kNumRegsForTransform, &shadow_frame, called_method, /* dex pc */ 0); |
| 1015 | ShadowFrame* new_shadow_frame = shadow_frame_unique_ptr.get(); |
| 1016 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 1017 | StackHandleScope<1> hs(self); |
| 1018 | MutableHandle<mirror::EmulatedStackFrame> sf(hs.NewHandle<mirror::EmulatedStackFrame>(nullptr)); |
| 1019 | if (IsCallerTransformer(callsite_type)) { |
| 1020 | // If we're entering this transformer from another transformer, we can pass |
| 1021 | // through the handle directly to the callee, instead of having to |
| 1022 | // instantiate a new stack frame based on the shadow frame. |
| 1023 | sf.Assign(reinterpret_cast<mirror::EmulatedStackFrame*>( |
| 1024 | shadow_frame.GetVRegReference(first_src_reg))); |
| 1025 | } else { |
| 1026 | sf.Assign(mirror::EmulatedStackFrame::CreateFromShadowFrameAndArgs<is_range>( |
| 1027 | self, |
| 1028 | callsite_type, |
| 1029 | callee_type, |
| 1030 | shadow_frame, |
| 1031 | first_src_reg, |
| 1032 | arg)); |
| 1033 | |
| 1034 | // Something went wrong while creating the emulated stack frame, we should |
| 1035 | // throw the pending exception. |
| 1036 | if (sf.Get() == nullptr) { |
| 1037 | DCHECK(self->IsExceptionPending()); |
| 1038 | return false; |
| 1039 | } |
| 1040 | } |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 1041 | |
| 1042 | new_shadow_frame->SetVRegReference(0, receiver.Get()); |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 1043 | new_shadow_frame->SetVRegReference(1, sf.Get()); |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 1044 | |
| 1045 | PerformCall(self, |
| 1046 | code_item, |
| 1047 | shadow_frame.GetMethod(), |
| 1048 | 0 /* first dest reg */, |
| 1049 | new_shadow_frame, |
| 1050 | result); |
| 1051 | |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame^] | 1052 | // If the called transformer method we called has returned a value, then we |
| 1053 | // need to copy it back to |result|. |
| 1054 | if (!self->IsExceptionPending()) { |
| 1055 | sf->GetReturnValue(self, result); |
| 1056 | } |
| 1057 | |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 1058 | return !self->IsExceptionPending(); |
| 1059 | } |
| 1060 | |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 1061 | template <bool is_range, |
Narayan Kamath | 370423d | 2016-10-03 16:51:22 +0100 | [diff] [blame] | 1062 | bool do_assignability_check> |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1063 | static inline bool DoCallCommon(ArtMethod* called_method, |
| 1064 | Thread* self, |
| 1065 | ShadowFrame& shadow_frame, |
| 1066 | JValue* result, |
| 1067 | uint16_t number_of_inputs, |
Narayan Kamath | 370423d | 2016-10-03 16:51:22 +0100 | [diff] [blame] | 1068 | uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1069 | uint32_t vregC) { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1070 | bool string_init = false; |
| 1071 | // Replace calls to String.<init> with equivalent StringFactory call. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1072 | if (UNLIKELY(called_method->GetDeclaringClass()->IsStringClass() |
| 1073 | && called_method->IsConstructor())) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1074 | called_method = WellKnownClasses::StringInitToStringFactory(called_method); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1075 | string_init = true; |
| 1076 | } |
| 1077 | |
Alex Light | daf58c8 | 2016-03-16 23:00:49 +0000 | [diff] [blame] | 1078 | // Compute method information. |
| 1079 | const DexFile::CodeItem* code_item = called_method->GetCodeItem(); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1080 | |
| 1081 | // Number of registers for the callee's call frame. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1082 | uint16_t num_regs; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1083 | if (LIKELY(code_item != nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1084 | num_regs = code_item->registers_size_; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1085 | DCHECK_EQ(string_init ? number_of_inputs - 1 : number_of_inputs, code_item->ins_size_); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1086 | } else { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 1087 | DCHECK(called_method->IsNative() || called_method->IsProxyMethod()); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1088 | num_regs = number_of_inputs; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1091 | // Hack for String init: |
| 1092 | // |
| 1093 | // Rewrite invoke-x java.lang.String.<init>(this, a, b, c, ...) into: |
| 1094 | // invoke-x StringFactory(a, b, c, ...) |
| 1095 | // by effectively dropping the first virtual register from the invoke. |
| 1096 | // |
| 1097 | // (at this point the ArtMethod has already been replaced, |
| 1098 | // so we just need to fix-up the arguments) |
David Brazdil | 65902e8 | 2016-01-15 09:35:13 +0000 | [diff] [blame] | 1099 | // |
| 1100 | // Note that FindMethodFromCode in entrypoint_utils-inl.h was also special-cased |
| 1101 | // to handle the compiler optimization of replacing `this` with null without |
| 1102 | // throwing NullPointerException. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1103 | uint32_t string_init_vreg_this = is_range ? vregC : arg[0]; |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 1104 | if (UNLIKELY(string_init)) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1105 | DCHECK_GT(num_regs, 0u); // As the method is an instance method, there should be at least 1. |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 1106 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1107 | // The new StringFactory call is static and has one fewer argument. |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 1108 | if (code_item == nullptr) { |
| 1109 | DCHECK(called_method->IsNative() || called_method->IsProxyMethod()); |
| 1110 | num_regs--; |
| 1111 | } // else ... don't need to change num_regs since it comes up from the string_init's code item |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1112 | number_of_inputs--; |
| 1113 | |
| 1114 | // Rewrite the var-args, dropping the 0th argument ("this") |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 1115 | for (uint32_t i = 1; i < arraysize(arg); ++i) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1116 | arg[i - 1] = arg[i]; |
| 1117 | } |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 1118 | arg[arraysize(arg) - 1] = 0; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1119 | |
| 1120 | // Rewrite the non-var-arg case |
| 1121 | vregC++; // Skips the 0th vreg in the range ("this"). |
| 1122 | } |
| 1123 | |
| 1124 | // Parameter registers go at the end of the shadow frame. |
| 1125 | DCHECK_GE(num_regs, number_of_inputs); |
| 1126 | size_t first_dest_reg = num_regs - number_of_inputs; |
| 1127 | DCHECK_NE(first_dest_reg, (size_t)-1); |
| 1128 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 1129 | // Allocate shadow frame on the stack. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1130 | const char* old_cause = self->StartAssertNoThreadSuspension("DoCallCommon"); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 1131 | ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr = |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 1132 | CREATE_SHADOW_FRAME(num_regs, &shadow_frame, called_method, /* dex pc */ 0); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 1133 | ShadowFrame* new_shadow_frame = shadow_frame_unique_ptr.get(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 1134 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1135 | // Initialize new shadow frame by copying the registers from the callee shadow frame. |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 1136 | if (do_assignability_check) { |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 1137 | // Slow path. |
| 1138 | // We might need to do class loading, which incurs a thread state change to kNative. So |
| 1139 | // register the shadow frame as under construction and allow suspension again. |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 1140 | ScopedStackedShadowFramePusher pusher( |
Sebastien Hertz | f795869 | 2015-06-09 14:09:14 +0200 | [diff] [blame] | 1141 | self, new_shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction); |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 1142 | self->EndAssertNoThreadSuspension(old_cause); |
| 1143 | |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 1144 | // ArtMethod here is needed to check type information of the call site against the callee. |
| 1145 | // Type information is retrieved from a DexFile/DexCache for that respective declared method. |
| 1146 | // |
| 1147 | // As a special case for proxy methods, which are not dex-backed, |
| 1148 | // we have to retrieve type information from the proxy's method |
| 1149 | // interface method instead (which is dex backed since proxies are never interfaces). |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1150 | ArtMethod* method = |
| 1151 | new_shadow_frame->GetMethod()->GetInterfaceMethodIfProxy(kRuntimePointerSize); |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 1152 | |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 1153 | // We need to do runtime check on reference assignment. We need to load the shorty |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1154 | // to get the exact type of each reference argument. |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 1155 | const DexFile::TypeList* params = method->GetParameterTypeList(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 1156 | uint32_t shorty_len = 0; |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 1157 | const char* shorty = method->GetShorty(&shorty_len); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1158 | |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 1159 | // Handle receiver apart since it's not part of the shorty. |
| 1160 | size_t dest_reg = first_dest_reg; |
| 1161 | size_t arg_offset = 0; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1162 | |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 1163 | if (!method->IsStatic()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 1164 | size_t receiver_reg = is_range ? vregC : arg[0]; |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 1165 | new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg)); |
| 1166 | ++dest_reg; |
| 1167 | ++arg_offset; |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 1168 | DCHECK(!string_init); // All StringFactory methods are static. |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 1169 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1170 | |
| 1171 | // Copy the caller's invoke-* arguments into the callee's parameter registers. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1172 | for (uint32_t shorty_pos = 0; dest_reg < num_regs; ++shorty_pos, ++dest_reg, ++arg_offset) { |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 1173 | // Skip the 0th 'shorty' type since it represents the return type. |
| 1174 | DCHECK_LT(shorty_pos + 1, shorty_len) << "for shorty '" << shorty << "'"; |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1175 | const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset]; |
| 1176 | switch (shorty[shorty_pos + 1]) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1177 | // Handle Object references. 1 virtual register slot. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1178 | case 'L': { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1179 | ObjPtr<mirror::Object> o = shadow_frame.GetVRegReference(src_reg); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1180 | if (do_assignability_check && o != nullptr) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1181 | PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize(); |
Mathieu Chartier | e22305b | 2016-10-26 21:04:58 -0700 | [diff] [blame] | 1182 | const uint32_t type_idx = params->GetTypeItem(shorty_pos).type_idx_; |
| 1183 | ObjPtr<mirror::Class> arg_type = method->GetDexCacheResolvedType(type_idx, |
| 1184 | pointer_size); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1185 | if (arg_type == nullptr) { |
Mathieu Chartier | e22305b | 2016-10-26 21:04:58 -0700 | [diff] [blame] | 1186 | StackHandleScope<1> hs(self); |
| 1187 | // Preserve o since it is used below and GetClassFromTypeIndex may cause thread |
| 1188 | // suspension. |
| 1189 | HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&o); |
| 1190 | arg_type = method->GetClassFromTypeIndex(type_idx, true /* resolve */, pointer_size); |
| 1191 | if (arg_type == nullptr) { |
| 1192 | CHECK(self->IsExceptionPending()); |
| 1193 | return false; |
| 1194 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1195 | } |
| 1196 | if (!o->VerifierInstanceOf(arg_type)) { |
| 1197 | // This should never happen. |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 1198 | std::string temp1, temp2; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 1199 | self->ThrowNewExceptionF("Ljava/lang/VirtualMachineError;", |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1200 | "Invoking %s with bad arg %d, type '%s' not instance of '%s'", |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 1201 | new_shadow_frame->GetMethod()->GetName(), shorty_pos, |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 1202 | o->GetClass()->GetDescriptor(&temp1), |
| 1203 | arg_type->GetDescriptor(&temp2)); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1204 | return false; |
| 1205 | } |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 1206 | } |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1207 | new_shadow_frame->SetVRegReference(dest_reg, o.Ptr()); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1208 | break; |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 1209 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1210 | // Handle doubles and longs. 2 consecutive virtual register slots. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1211 | case 'J': case 'D': { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1212 | uint64_t wide_value = |
| 1213 | (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << BitSizeOf<uint32_t>()) | |
| 1214 | static_cast<uint32_t>(shadow_frame.GetVReg(src_reg)); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1215 | new_shadow_frame->SetVRegLong(dest_reg, wide_value); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1216 | // Skip the next virtual register slot since we already used it. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1217 | ++dest_reg; |
| 1218 | ++arg_offset; |
| 1219 | break; |
| 1220 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1221 | // Handle all other primitives that are always 1 virtual register slot. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1222 | default: |
| 1223 | new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg)); |
| 1224 | break; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1225 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1226 | } |
| 1227 | } else { |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 1228 | if (is_range) { |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 1229 | DCHECK_EQ(num_regs, first_dest_reg + number_of_inputs); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1230 | } |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 1231 | |
| 1232 | CopyRegisters<is_range>(shadow_frame, |
| 1233 | new_shadow_frame, |
| 1234 | arg, |
| 1235 | vregC, |
| 1236 | first_dest_reg, |
| 1237 | number_of_inputs); |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 1238 | self->EndAssertNoThreadSuspension(old_cause); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1239 | } |
| 1240 | |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 1241 | PerformCall(self, code_item, shadow_frame.GetMethod(), first_dest_reg, new_shadow_frame, result); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1242 | |
| 1243 | if (string_init && !self->IsExceptionPending()) { |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 1244 | SetStringInitValueToAllAliases(&shadow_frame, string_init_vreg_this, *result); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1247 | return !self->IsExceptionPending(); |
| 1248 | } |
| 1249 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1250 | template<bool is_range, bool do_assignability_check> |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1251 | bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame, |
| 1252 | const Instruction* inst, uint16_t inst_data, JValue* result) { |
| 1253 | // Argument word count. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1254 | const uint16_t number_of_inputs = |
| 1255 | (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1256 | |
| 1257 | // TODO: find a cleaner way to separate non-range and range information without duplicating |
| 1258 | // code. |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 1259 | uint32_t arg[Instruction::kMaxVarArgRegs] = {}; // only used in invoke-XXX. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1260 | uint32_t vregC = 0; |
| 1261 | if (is_range) { |
| 1262 | vregC = inst->VRegC_3rc(); |
| 1263 | } else { |
| 1264 | vregC = inst->VRegC_35c(); |
| 1265 | inst->GetVarArgs(arg, inst_data); |
| 1266 | } |
| 1267 | |
| 1268 | return DoCallCommon<is_range, do_assignability_check>( |
| 1269 | called_method, self, shadow_frame, |
| 1270 | result, number_of_inputs, arg, vregC); |
| 1271 | } |
| 1272 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1273 | template <bool is_range, bool do_access_check, bool transaction_active> |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1274 | bool DoFilledNewArray(const Instruction* inst, |
| 1275 | const ShadowFrame& shadow_frame, |
| 1276 | Thread* self, |
| 1277 | JValue* result) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1278 | DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY || |
| 1279 | inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE); |
| 1280 | const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c(); |
| 1281 | if (!is_range) { |
| 1282 | // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments. |
| 1283 | CHECK_LE(length, 5); |
| 1284 | } |
| 1285 | if (UNLIKELY(length < 0)) { |
| 1286 | ThrowNegativeArraySizeException(length); |
| 1287 | return false; |
| 1288 | } |
| 1289 | uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1290 | ObjPtr<mirror::Class> array_class = ResolveVerifyAndClinit(type_idx, |
| 1291 | shadow_frame.GetMethod(), |
| 1292 | self, |
| 1293 | false, |
| 1294 | do_access_check); |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1295 | if (UNLIKELY(array_class == nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1296 | DCHECK(self->IsExceptionPending()); |
| 1297 | return false; |
| 1298 | } |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1299 | CHECK(array_class->IsArrayClass()); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1300 | ObjPtr<mirror::Class> component_class = array_class->GetComponentType(); |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1301 | const bool is_primitive_int_component = component_class->IsPrimitiveInt(); |
| 1302 | if (UNLIKELY(component_class->IsPrimitive() && !is_primitive_int_component)) { |
| 1303 | if (component_class->IsPrimitiveLong() || component_class->IsPrimitiveDouble()) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1304 | ThrowRuntimeException("Bad filled array request for type %s", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1305 | component_class->PrettyDescriptor().c_str()); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1306 | } else { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 1307 | self->ThrowNewExceptionF("Ljava/lang/InternalError;", |
Brian Carlstrom | 4fa0bcd | 2013-12-10 11:24:21 -0800 | [diff] [blame] | 1308 | "Found type %s; filled-new-array not implemented for anything but 'int'", |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1309 | component_class->PrettyDescriptor().c_str()); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1310 | } |
| 1311 | return false; |
| 1312 | } |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1313 | ObjPtr<mirror::Object> new_array = mirror::Array::Alloc<true>( |
| 1314 | self, |
| 1315 | array_class, |
| 1316 | length, |
| 1317 | array_class->GetComponentSizeShift(), |
| 1318 | Runtime::Current()->GetHeap()->GetCurrentAllocator()); |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1319 | if (UNLIKELY(new_array == nullptr)) { |
| 1320 | self->AssertPendingOOMException(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1321 | return false; |
| 1322 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 1323 | uint32_t arg[Instruction::kMaxVarArgRegs]; // only used in filled-new-array. |
| 1324 | uint32_t vregC = 0; // only used in filled-new-array-range. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1325 | if (is_range) { |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 1326 | vregC = inst->VRegC_3rc(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1327 | } else { |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 1328 | inst->GetVarArgs(arg); |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 1329 | } |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 1330 | for (int32_t i = 0; i < length; ++i) { |
| 1331 | size_t src_reg = is_range ? vregC + i : arg[i]; |
| 1332 | if (is_primitive_int_component) { |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1333 | new_array->AsIntArray()->SetWithoutChecks<transaction_active>( |
| 1334 | i, shadow_frame.GetVReg(src_reg)); |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 1335 | } else { |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1336 | new_array->AsObjectArray<mirror::Object>()->SetWithoutChecks<transaction_active>( |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1337 | i, shadow_frame.GetVRegReference(src_reg)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 1341 | result->SetL(new_array); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1342 | return true; |
| 1343 | } |
| 1344 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1345 | // TODO: Use ObjPtr here. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1346 | template<typename T> |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1347 | static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array, |
| 1348 | int32_t count) |
| 1349 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1350 | Runtime* runtime = Runtime::Current(); |
| 1351 | for (int32_t i = 0; i < count; ++i) { |
| 1352 | runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i)); |
| 1353 | } |
| 1354 | } |
| 1355 | |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 1356 | void RecordArrayElementsInTransaction(ObjPtr<mirror::Array> array, int32_t count) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1357 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1358 | DCHECK(Runtime::Current()->IsActiveTransaction()); |
| 1359 | DCHECK(array != nullptr); |
| 1360 | DCHECK_LE(count, array->GetLength()); |
| 1361 | Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType(); |
| 1362 | switch (primitive_component_type) { |
| 1363 | case Primitive::kPrimBoolean: |
| 1364 | RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count); |
| 1365 | break; |
| 1366 | case Primitive::kPrimByte: |
| 1367 | RecordArrayElementsInTransactionImpl(array->AsByteArray(), count); |
| 1368 | break; |
| 1369 | case Primitive::kPrimChar: |
| 1370 | RecordArrayElementsInTransactionImpl(array->AsCharArray(), count); |
| 1371 | break; |
| 1372 | case Primitive::kPrimShort: |
| 1373 | RecordArrayElementsInTransactionImpl(array->AsShortArray(), count); |
| 1374 | break; |
| 1375 | case Primitive::kPrimInt: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1376 | RecordArrayElementsInTransactionImpl(array->AsIntArray(), count); |
| 1377 | break; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1378 | case Primitive::kPrimFloat: |
| 1379 | RecordArrayElementsInTransactionImpl(array->AsFloatArray(), count); |
| 1380 | break; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1381 | case Primitive::kPrimLong: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1382 | RecordArrayElementsInTransactionImpl(array->AsLongArray(), count); |
| 1383 | break; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1384 | case Primitive::kPrimDouble: |
| 1385 | RecordArrayElementsInTransactionImpl(array->AsDoubleArray(), count); |
| 1386 | break; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1387 | default: |
| 1388 | LOG(FATAL) << "Unsupported primitive type " << primitive_component_type |
| 1389 | << " in fill-array-data"; |
| 1390 | break; |
| 1391 | } |
| 1392 | } |
| 1393 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 1394 | // Explicit DoCall template function declarations. |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 1395 | #define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \ |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1396 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 1397 | bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \ |
| 1398 | ShadowFrame& shadow_frame, \ |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 1399 | const Instruction* inst, uint16_t inst_data, \ |
| 1400 | JValue* result) |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 1401 | EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false); |
| 1402 | EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true); |
| 1403 | EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false); |
| 1404 | EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true); |
| 1405 | #undef EXPLICIT_DO_CALL_TEMPLATE_DECL |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1406 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 1407 | // Explicit DoInvokePolymorphic template function declarations. |
| 1408 | #define EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(_is_range, _do_assignability_check) \ |
| 1409 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
| 1410 | bool DoInvokePolymorphic<_is_range, _do_assignability_check>( \ |
| 1411 | Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \ |
| 1412 | uint16_t inst_data, JValue* result) |
| 1413 | |
| 1414 | EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(false, false); |
| 1415 | EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(false, true); |
| 1416 | EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(true, false); |
| 1417 | EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(true, true); |
| 1418 | #undef EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL |
| 1419 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1420 | // Explicit DoFilledNewArray template function declarations. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1421 | #define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \ |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1422 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 1423 | bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \ |
| 1424 | const ShadowFrame& shadow_frame, \ |
| 1425 | Thread* self, JValue* result) |
| 1426 | #define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \ |
| 1427 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \ |
| 1428 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \ |
| 1429 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \ |
| 1430 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active) |
| 1431 | EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false); |
| 1432 | EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true); |
| 1433 | #undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 1434 | #undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL |
| 1435 | |
| 1436 | } // namespace interpreter |
| 1437 | } // namespace art |