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" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 25 | #include "mirror/array-inl.h" |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 26 | #include "stack.h" |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 27 | #include "unstarted_runtime.h" |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 28 | #include "verifier/method_verifier.h" |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 29 | |
| 30 | namespace art { |
| 31 | namespace interpreter { |
| 32 | |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 33 | void ThrowNullPointerExceptionFromInterpreter() { |
| 34 | ThrowNullPointerExceptionFromDexPC(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check> |
| 38 | bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, |
| 39 | uint16_t inst_data) { |
| 40 | const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead); |
| 41 | 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] | 42 | ArtField* f = |
| 43 | FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self, |
| 44 | Primitive::ComponentSize(field_type)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 45 | if (UNLIKELY(f == nullptr)) { |
| 46 | CHECK(self->IsExceptionPending()); |
| 47 | return false; |
| 48 | } |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 49 | ObjPtr<Object> obj; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 50 | if (is_static) { |
| 51 | obj = f->GetDeclaringClass(); |
| 52 | } else { |
| 53 | obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
| 54 | if (UNLIKELY(obj == nullptr)) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 55 | ThrowNullPointerExceptionForFieldAccess(f, true); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 56 | return false; |
| 57 | } |
| 58 | } |
Sebastien Hertz | 1edbd8e | 2014-07-16 20:00:11 +0200 | [diff] [blame] | 59 | f->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 60 | // Report this field access to instrumentation if needed. |
| 61 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 62 | if (UNLIKELY(instrumentation->HasFieldReadListeners())) { |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 63 | ObjPtr<Object> this_object; |
| 64 | if (!f->IsStatic()) { |
| 65 | this_object = obj; |
| 66 | } |
| 67 | instrumentation->FieldReadEvent(self, |
| 68 | this_object.Decode(), |
| 69 | shadow_frame.GetMethod(), |
| 70 | shadow_frame.GetDexPC(), |
| 71 | f); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 72 | } |
| 73 | uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); |
| 74 | switch (field_type) { |
| 75 | case Primitive::kPrimBoolean: |
| 76 | shadow_frame.SetVReg(vregA, f->GetBoolean(obj)); |
| 77 | break; |
| 78 | case Primitive::kPrimByte: |
| 79 | shadow_frame.SetVReg(vregA, f->GetByte(obj)); |
| 80 | break; |
| 81 | case Primitive::kPrimChar: |
| 82 | shadow_frame.SetVReg(vregA, f->GetChar(obj)); |
| 83 | break; |
| 84 | case Primitive::kPrimShort: |
| 85 | shadow_frame.SetVReg(vregA, f->GetShort(obj)); |
| 86 | break; |
| 87 | case Primitive::kPrimInt: |
| 88 | shadow_frame.SetVReg(vregA, f->GetInt(obj)); |
| 89 | break; |
| 90 | case Primitive::kPrimLong: |
| 91 | shadow_frame.SetVRegLong(vregA, f->GetLong(obj)); |
| 92 | break; |
| 93 | case Primitive::kPrimNot: |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 94 | shadow_frame.SetVRegReference(vregA, f->GetObject(obj).Decode()); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 95 | break; |
| 96 | default: |
| 97 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 98 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 99 | } |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | // Explicitly instantiate all DoFieldGet functions. |
| 104 | #define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \ |
| 105 | template bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, \ |
| 106 | ShadowFrame& shadow_frame, \ |
| 107 | const Instruction* inst, \ |
| 108 | uint16_t inst_data) |
| 109 | |
| 110 | #define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \ |
| 111 | EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \ |
| 112 | EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true); |
| 113 | |
| 114 | // iget-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 115 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean) |
| 116 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte) |
| 117 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar) |
| 118 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort) |
| 119 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt) |
| 120 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong) |
| 121 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 122 | |
| 123 | // sget-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 124 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean) |
| 125 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte) |
| 126 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar) |
| 127 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort) |
| 128 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt) |
| 129 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong) |
| 130 | EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 131 | |
| 132 | #undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL |
| 133 | #undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL |
| 134 | |
| 135 | // Handles iget-quick, iget-wide-quick and iget-object-quick instructions. |
| 136 | // Returns true on success, otherwise throws an exception and returns false. |
| 137 | template<Primitive::Type field_type> |
| 138 | bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) { |
| 139 | Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
| 140 | if (UNLIKELY(obj == nullptr)) { |
| 141 | // We lost the reference to the field index so we cannot get a more |
| 142 | // precised exception message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 143 | ThrowNullPointerExceptionFromDexPC(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 144 | return false; |
| 145 | } |
| 146 | MemberOffset field_offset(inst->VRegC_22c()); |
| 147 | // Report this field access to instrumentation if needed. Since we only have the offset of |
| 148 | // the field from the base of the object, we need to look for it first. |
| 149 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 150 | if (UNLIKELY(instrumentation->HasFieldReadListeners())) { |
| 151 | ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), |
| 152 | field_offset.Uint32Value()); |
| 153 | DCHECK(f != nullptr); |
| 154 | DCHECK(!f->IsStatic()); |
| 155 | instrumentation->FieldReadEvent(Thread::Current(), obj, shadow_frame.GetMethod(), |
| 156 | shadow_frame.GetDexPC(), f); |
| 157 | } |
| 158 | // Note: iget-x-quick instructions are only for non-volatile fields. |
| 159 | const uint32_t vregA = inst->VRegA_22c(inst_data); |
| 160 | switch (field_type) { |
| 161 | case Primitive::kPrimInt: |
| 162 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset))); |
| 163 | break; |
Mathieu Chartier | ffc605c | 2014-12-10 10:35:44 -0800 | [diff] [blame] | 164 | case Primitive::kPrimBoolean: |
| 165 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldBoolean(field_offset))); |
| 166 | break; |
| 167 | case Primitive::kPrimByte: |
| 168 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldByte(field_offset))); |
| 169 | break; |
| 170 | case Primitive::kPrimChar: |
| 171 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldChar(field_offset))); |
| 172 | break; |
| 173 | case Primitive::kPrimShort: |
| 174 | shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldShort(field_offset))); |
| 175 | break; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 176 | case Primitive::kPrimLong: |
| 177 | shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset))); |
| 178 | break; |
| 179 | case Primitive::kPrimNot: |
| 180 | shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset)); |
| 181 | break; |
| 182 | default: |
| 183 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 184 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 185 | } |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | // Explicitly instantiate all DoIGetQuick functions. |
| 190 | #define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \ |
| 191 | template bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \ |
| 192 | uint16_t inst_data) |
| 193 | |
Mathieu Chartier | ffc605c | 2014-12-10 10:35:44 -0800 | [diff] [blame] | 194 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick. |
| 195 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimBoolean); // iget-boolean-quick. |
| 196 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimByte); // iget-byte-quick. |
| 197 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimChar); // iget-char-quick. |
| 198 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimShort); // iget-short-quick. |
| 199 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick. |
| 200 | EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick. |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 201 | #undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL |
| 202 | |
| 203 | template<Primitive::Type field_type> |
| 204 | static JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 205 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 206 | JValue field_value; |
| 207 | switch (field_type) { |
| 208 | case Primitive::kPrimBoolean: |
| 209 | field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg))); |
| 210 | break; |
| 211 | case Primitive::kPrimByte: |
| 212 | field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg))); |
| 213 | break; |
| 214 | case Primitive::kPrimChar: |
| 215 | field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg))); |
| 216 | break; |
| 217 | case Primitive::kPrimShort: |
| 218 | field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg))); |
| 219 | break; |
| 220 | case Primitive::kPrimInt: |
| 221 | field_value.SetI(shadow_frame.GetVReg(vreg)); |
| 222 | break; |
| 223 | case Primitive::kPrimLong: |
| 224 | field_value.SetJ(shadow_frame.GetVRegLong(vreg)); |
| 225 | break; |
| 226 | case Primitive::kPrimNot: |
| 227 | field_value.SetL(shadow_frame.GetVRegReference(vreg)); |
| 228 | break; |
| 229 | default: |
| 230 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 231 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 232 | } |
| 233 | return field_value; |
| 234 | } |
| 235 | |
| 236 | template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, |
| 237 | bool transaction_active> |
| 238 | bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst, |
| 239 | uint16_t inst_data) { |
| 240 | bool do_assignability_check = do_access_check; |
| 241 | bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite); |
| 242 | uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c(); |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 243 | ArtField* f = |
| 244 | FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self, |
| 245 | Primitive::ComponentSize(field_type)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 246 | if (UNLIKELY(f == nullptr)) { |
| 247 | CHECK(self->IsExceptionPending()); |
| 248 | return false; |
| 249 | } |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 250 | ObjPtr<Object> obj; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 251 | if (is_static) { |
| 252 | obj = f->GetDeclaringClass(); |
| 253 | } else { |
| 254 | obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
| 255 | if (UNLIKELY(obj == nullptr)) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 256 | ThrowNullPointerExceptionForFieldAccess(f, false); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 257 | return false; |
| 258 | } |
| 259 | } |
Sebastien Hertz | 1edbd8e | 2014-07-16 20:00:11 +0200 | [diff] [blame] | 260 | f->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 261 | uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); |
| 262 | // Report this field access to instrumentation if needed. Since we only have the offset of |
| 263 | // the field from the base of the object, we need to look for it first. |
| 264 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 265 | if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { |
| 266 | JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 267 | ObjPtr<Object> this_object = f->IsStatic() ? nullptr : obj; |
| 268 | instrumentation->FieldWriteEvent(self, this_object.Decode(), |
| 269 | shadow_frame.GetMethod(), |
| 270 | shadow_frame.GetDexPC(), |
| 271 | f, |
| 272 | field_value); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 273 | } |
| 274 | switch (field_type) { |
| 275 | case Primitive::kPrimBoolean: |
| 276 | f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
| 277 | break; |
| 278 | case Primitive::kPrimByte: |
| 279 | f->SetByte<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
| 280 | break; |
| 281 | case Primitive::kPrimChar: |
| 282 | f->SetChar<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
| 283 | break; |
| 284 | case Primitive::kPrimShort: |
| 285 | f->SetShort<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
| 286 | break; |
| 287 | case Primitive::kPrimInt: |
| 288 | f->SetInt<transaction_active>(obj, shadow_frame.GetVReg(vregA)); |
| 289 | break; |
| 290 | case Primitive::kPrimLong: |
| 291 | f->SetLong<transaction_active>(obj, shadow_frame.GetVRegLong(vregA)); |
| 292 | break; |
| 293 | case Primitive::kPrimNot: { |
| 294 | Object* reg = shadow_frame.GetVRegReference(vregA); |
| 295 | if (do_assignability_check && reg != nullptr) { |
| 296 | // FieldHelper::GetType can resolve classes, use a handle wrapper which will restore the |
| 297 | // object in the destructor. |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 298 | ObjPtr<Class> field_class; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 299 | { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 300 | StackHandleScope<2> hs(self); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 301 | HandleWrapper<mirror::Object> h_reg(hs.NewHandleWrapper(®)); |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 302 | HandleWrapperObjPtr<mirror::Object> h_obj(hs.NewHandleWrapper(&obj)); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 303 | field_class = f->GetType<true>(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 304 | } |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 305 | if (!reg->VerifierInstanceOf(field_class.Decode())) { |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 306 | // This should never happen. |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 307 | std::string temp1, temp2, temp3; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 308 | self->ThrowNewExceptionF("Ljava/lang/VirtualMachineError;", |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 309 | "Put '%s' that is not instance of field '%s' in '%s'", |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 310 | reg->GetClass()->GetDescriptor(&temp1), |
| 311 | field_class->GetDescriptor(&temp2), |
| 312 | f->GetDeclaringClass()->GetDescriptor(&temp3)); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 313 | return false; |
| 314 | } |
| 315 | } |
| 316 | f->SetObj<transaction_active>(obj, reg); |
| 317 | break; |
| 318 | } |
| 319 | default: |
| 320 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 321 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 322 | } |
| 323 | return true; |
| 324 | } |
| 325 | |
| 326 | // Explicitly instantiate all DoFieldPut functions. |
| 327 | #define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \ |
| 328 | template bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \ |
| 329 | const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) |
| 330 | |
| 331 | #define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \ |
| 332 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \ |
| 333 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \ |
| 334 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \ |
| 335 | EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true); |
| 336 | |
| 337 | // iput-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 338 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean) |
| 339 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte) |
| 340 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar) |
| 341 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort) |
| 342 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt) |
| 343 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong) |
| 344 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 345 | |
| 346 | // sput-XXX |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 347 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean) |
| 348 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte) |
| 349 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar) |
| 350 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort) |
| 351 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt) |
| 352 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong) |
| 353 | EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot) |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 354 | |
| 355 | #undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL |
| 356 | #undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL |
| 357 | |
| 358 | template<Primitive::Type field_type, bool transaction_active> |
| 359 | bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) { |
| 360 | Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); |
| 361 | if (UNLIKELY(obj == nullptr)) { |
| 362 | // We lost the reference to the field index so we cannot get a more |
| 363 | // precised exception message. |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 364 | ThrowNullPointerExceptionFromDexPC(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 365 | return false; |
| 366 | } |
| 367 | MemberOffset field_offset(inst->VRegC_22c()); |
| 368 | const uint32_t vregA = inst->VRegA_22c(inst_data); |
| 369 | // Report this field modification to instrumentation if needed. Since we only have the offset of |
| 370 | // the field from the base of the object, we need to look for it first. |
| 371 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 372 | if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { |
| 373 | ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), |
| 374 | field_offset.Uint32Value()); |
| 375 | DCHECK(f != nullptr); |
| 376 | DCHECK(!f->IsStatic()); |
| 377 | JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); |
| 378 | instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(), |
| 379 | shadow_frame.GetDexPC(), f, field_value); |
| 380 | } |
| 381 | // Note: iput-x-quick instructions are only for non-volatile fields. |
| 382 | switch (field_type) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 383 | case Primitive::kPrimBoolean: |
| 384 | obj->SetFieldBoolean<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 385 | break; |
| 386 | case Primitive::kPrimByte: |
| 387 | obj->SetFieldByte<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 388 | break; |
| 389 | case Primitive::kPrimChar: |
| 390 | obj->SetFieldChar<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 391 | break; |
| 392 | case Primitive::kPrimShort: |
| 393 | obj->SetFieldShort<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 394 | break; |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 395 | case Primitive::kPrimInt: |
| 396 | obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); |
| 397 | break; |
| 398 | case Primitive::kPrimLong: |
| 399 | obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA)); |
| 400 | break; |
| 401 | case Primitive::kPrimNot: |
| 402 | obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA)); |
| 403 | break; |
| 404 | default: |
| 405 | LOG(FATAL) << "Unreachable: " << field_type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 406 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 407 | } |
| 408 | return true; |
| 409 | } |
| 410 | |
| 411 | // Explicitly instantiate all DoIPutQuick functions. |
| 412 | #define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \ |
| 413 | template bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \ |
| 414 | const Instruction* inst, \ |
| 415 | uint16_t inst_data) |
| 416 | |
| 417 | #define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \ |
| 418 | EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \ |
| 419 | EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true); |
| 420 | |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 421 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt) // iput-quick. |
| 422 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimBoolean) // iput-boolean-quick. |
| 423 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimByte) // iput-byte-quick. |
| 424 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimChar) // iput-char-quick. |
| 425 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimShort) // iput-short-quick. |
| 426 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong) // iput-wide-quick. |
| 427 | EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot) // iput-object-quick. |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 428 | #undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL |
| 429 | #undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL |
| 430 | |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 431 | // 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] | 432 | uint32_t FindNextInstructionFollowingException( |
| 433 | Thread* self, ShadowFrame& shadow_frame, uint32_t dex_pc, |
| 434 | const instrumentation::Instrumentation* instrumentation) { |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 435 | self->VerifyStack(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 436 | StackHandleScope<2> hs(self); |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 437 | Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException())); |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 438 | if (instrumentation != nullptr && instrumentation->HasExceptionCaughtListeners() |
Nicolas Geoffray | 7642cfc | 2015-02-26 10:56:09 +0000 | [diff] [blame] | 439 | && self->IsExceptionThrownByCurrentMethod(exception.Get())) { |
Nicolas Geoffray | 14691c5 | 2015-03-05 10:40:17 +0000 | [diff] [blame] | 440 | instrumentation->ExceptionCaughtEvent(self, exception.Get()); |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 441 | } |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 442 | bool clear_exception = false; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 443 | uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock( |
| 444 | hs.NewHandle(exception->GetClass()), dex_pc, &clear_exception); |
Sebastien Hertz | 520633b | 2015-09-08 17:03:36 +0200 | [diff] [blame] | 445 | if (found_dex_pc == DexFile::kDexNoIndex && instrumentation != nullptr) { |
Nicolas Geoffray | 7642cfc | 2015-02-26 10:56:09 +0000 | [diff] [blame] | 446 | // Exception is not caught by the current method. We will unwind to the |
| 447 | // caller. Notify any instrumentation listener. |
Sebastien Hertz | 9f10203 | 2014-05-23 08:59:42 +0200 | [diff] [blame] | 448 | instrumentation->MethodUnwindEvent(self, shadow_frame.GetThisObject(), |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 449 | shadow_frame.GetMethod(), dex_pc); |
| 450 | } else { |
Nicolas Geoffray | 7642cfc | 2015-02-26 10:56:09 +0000 | [diff] [blame] | 451 | // 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] | 452 | if (clear_exception) { |
| 453 | self->ClearException(); |
| 454 | } |
| 455 | } |
| 456 | return found_dex_pc; |
| 457 | } |
| 458 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 459 | void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame) { |
| 460 | LOG(FATAL) << "Unexpected instruction: " |
| 461 | << inst->DumpString(shadow_frame.GetMethod()->GetDexFile()); |
| 462 | UNREACHABLE(); |
Ian Rogers | 5487494 | 2014-06-10 16:31:03 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 465 | // Assign register 'src_reg' from shadow_frame to register 'dest_reg' into new_shadow_frame. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 466 | static inline void AssignRegister(ShadowFrame* new_shadow_frame, const ShadowFrame& shadow_frame, |
| 467 | size_t dest_reg, size_t src_reg) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 468 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 7104cbf | 2014-03-21 11:44:43 -0700 | [diff] [blame] | 469 | // Uint required, so that sign extension does not make this wrong on 64b systems |
| 470 | uint32_t src_value = shadow_frame.GetVReg(src_reg); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 471 | mirror::Object* o = shadow_frame.GetVRegReference<kVerifyNone>(src_reg); |
Igor Murashkin | c449e8b | 2015-06-10 15:56:42 -0700 | [diff] [blame] | 472 | |
| 473 | // If both register locations contains the same value, the register probably holds a reference. |
| 474 | // Note: As an optimization, non-moving collectors leave a stale reference value |
| 475 | // in the references array even after the original vreg was overwritten to a non-reference. |
Andreas Gampe | 7104cbf | 2014-03-21 11:44:43 -0700 | [diff] [blame] | 476 | if (src_value == reinterpret_cast<uintptr_t>(o)) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 477 | new_shadow_frame->SetVRegReference(dest_reg, o); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 478 | } else { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 479 | new_shadow_frame->SetVReg(dest_reg, src_value); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
Sebastien Hertz | 45b1597 | 2015-04-03 16:07:05 +0200 | [diff] [blame] | 483 | void AbortTransactionF(Thread* self, const char* fmt, ...) { |
Mathieu Chartier | b2c7ead | 2014-04-29 11:13:16 -0700 | [diff] [blame] | 484 | va_list args; |
| 485 | va_start(args, fmt); |
Sebastien Hertz | 45b1597 | 2015-04-03 16:07:05 +0200 | [diff] [blame] | 486 | AbortTransactionV(self, fmt, args); |
| 487 | va_end(args); |
| 488 | } |
| 489 | |
| 490 | void AbortTransactionV(Thread* self, const char* fmt, va_list args) { |
| 491 | CHECK(Runtime::Current()->IsActiveTransaction()); |
| 492 | // Constructs abort message. |
Sebastien Hertz | 1c80bec | 2015-02-03 11:58:06 +0100 | [diff] [blame] | 493 | std::string abort_msg; |
| 494 | StringAppendV(&abort_msg, fmt, args); |
| 495 | // 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] | 496 | Runtime::Current()->AbortTransactionAndThrowAbortError(self, abort_msg); |
Mathieu Chartier | b2c7ead | 2014-04-29 11:13:16 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 499 | // Separate declaration is required solely for the attributes. |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 500 | template <bool is_range, |
| 501 | bool do_assignability_check, |
| 502 | size_t kVarArgMax> |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 503 | REQUIRES_SHARED(Locks::mutator_lock_) |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 504 | static inline bool DoCallCommon(ArtMethod* called_method, |
| 505 | Thread* self, |
| 506 | ShadowFrame& shadow_frame, |
| 507 | JValue* result, |
| 508 | uint16_t number_of_inputs, |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 509 | uint32_t (&arg)[kVarArgMax], |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 510 | uint32_t vregC) ALWAYS_INLINE; |
| 511 | |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 512 | void ArtInterpreterToCompiledCodeBridge(Thread* self, |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 513 | ArtMethod* caller, |
Siva Chandra | 05d2415 | 2016-01-05 17:43:17 -0800 | [diff] [blame] | 514 | const DexFile::CodeItem* code_item, |
| 515 | ShadowFrame* shadow_frame, |
| 516 | JValue* result) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 517 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 518 | ArtMethod* method = shadow_frame->GetMethod(); |
| 519 | // Ensure static methods are initialized. |
| 520 | if (method->IsStatic()) { |
| 521 | mirror::Class* declaringClass = method->GetDeclaringClass(); |
| 522 | if (UNLIKELY(!declaringClass->IsInitialized())) { |
| 523 | self->PushShadowFrame(shadow_frame); |
| 524 | StackHandleScope<1> hs(self); |
| 525 | Handle<mirror::Class> h_class(hs.NewHandle(declaringClass)); |
| 526 | if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true, |
| 527 | true))) { |
| 528 | self->PopShadowFrame(); |
| 529 | DCHECK(self->IsExceptionPending()); |
| 530 | return; |
| 531 | } |
| 532 | self->PopShadowFrame(); |
| 533 | CHECK(h_class->IsInitializing()); |
| 534 | // Reload from shadow frame in case the method moved, this is faster than adding a handle. |
| 535 | method = shadow_frame->GetMethod(); |
| 536 | } |
| 537 | } |
| 538 | uint16_t arg_offset = (code_item == nullptr) |
| 539 | ? 0 |
| 540 | : code_item->registers_size_ - code_item->ins_size_; |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 541 | jit::Jit* jit = Runtime::Current()->GetJit(); |
| 542 | if (jit != nullptr && caller != nullptr) { |
| 543 | jit->NotifyInterpreterToCompiledCodeTransition(self, caller); |
| 544 | } |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 545 | method->Invoke(self, shadow_frame->GetVRegArgs(arg_offset), |
| 546 | (shadow_frame->NumberOfVRegs() - arg_offset) * sizeof(uint32_t), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 547 | result, method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty()); |
Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 550 | void SetStringInitValueToAllAliases(ShadowFrame* shadow_frame, |
| 551 | uint16_t this_obj_vreg, |
| 552 | JValue result) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 553 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 554 | Object* existing = shadow_frame->GetVRegReference(this_obj_vreg); |
| 555 | if (existing == nullptr) { |
| 556 | // If it's null, we come from compiled code that was deoptimized. Nothing to do, |
| 557 | // as the compiler verified there was no alias. |
| 558 | // Set the new string result of the StringFactory. |
| 559 | shadow_frame->SetVRegReference(this_obj_vreg, result.GetL()); |
| 560 | return; |
| 561 | } |
| 562 | // Set the string init result into all aliases. |
| 563 | for (uint32_t i = 0, e = shadow_frame->NumberOfVRegs(); i < e; ++i) { |
| 564 | if (shadow_frame->GetVRegReference(i) == existing) { |
| 565 | DCHECK_EQ(shadow_frame->GetVRegReference(i), |
| 566 | reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i))); |
| 567 | shadow_frame->SetVRegReference(i, result.GetL()); |
| 568 | DCHECK_EQ(shadow_frame->GetVRegReference(i), |
| 569 | reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i))); |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 574 | template <bool is_range, |
| 575 | bool do_assignability_check, |
| 576 | size_t kVarArgMax> |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 577 | static inline bool DoCallCommon(ArtMethod* called_method, |
| 578 | Thread* self, |
| 579 | ShadowFrame& shadow_frame, |
| 580 | JValue* result, |
| 581 | uint16_t number_of_inputs, |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 582 | uint32_t (&arg)[kVarArgMax], |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 583 | uint32_t vregC) { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 584 | bool string_init = false; |
| 585 | // Replace calls to String.<init> with equivalent StringFactory call. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 586 | if (UNLIKELY(called_method->GetDeclaringClass()->IsStringClass() |
| 587 | && called_method->IsConstructor())) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 588 | called_method = WellKnownClasses::StringInitToStringFactory(called_method); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 589 | string_init = true; |
| 590 | } |
| 591 | |
Alex Light | daf58c8 | 2016-03-16 23:00:49 +0000 | [diff] [blame] | 592 | // Compute method information. |
| 593 | const DexFile::CodeItem* code_item = called_method->GetCodeItem(); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 594 | |
| 595 | // Number of registers for the callee's call frame. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 596 | uint16_t num_regs; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 597 | if (LIKELY(code_item != nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 598 | num_regs = code_item->registers_size_; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 599 | 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] | 600 | } else { |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 601 | DCHECK(called_method->IsNative() || called_method->IsProxyMethod()); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 602 | num_regs = number_of_inputs; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 603 | } |
| 604 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 605 | // Hack for String init: |
| 606 | // |
| 607 | // Rewrite invoke-x java.lang.String.<init>(this, a, b, c, ...) into: |
| 608 | // invoke-x StringFactory(a, b, c, ...) |
| 609 | // by effectively dropping the first virtual register from the invoke. |
| 610 | // |
| 611 | // (at this point the ArtMethod has already been replaced, |
| 612 | // so we just need to fix-up the arguments) |
David Brazdil | 65902e8 | 2016-01-15 09:35:13 +0000 | [diff] [blame] | 613 | // |
| 614 | // Note that FindMethodFromCode in entrypoint_utils-inl.h was also special-cased |
| 615 | // to handle the compiler optimization of replacing `this` with null without |
| 616 | // throwing NullPointerException. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 617 | uint32_t string_init_vreg_this = is_range ? vregC : arg[0]; |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 618 | if (UNLIKELY(string_init)) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 619 | 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] | 620 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 621 | // The new StringFactory call is static and has one fewer argument. |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 622 | if (code_item == nullptr) { |
| 623 | DCHECK(called_method->IsNative() || called_method->IsProxyMethod()); |
| 624 | num_regs--; |
| 625 | } // 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] | 626 | number_of_inputs--; |
| 627 | |
| 628 | // Rewrite the var-args, dropping the 0th argument ("this") |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 629 | for (uint32_t i = 1; i < arraysize(arg); ++i) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 630 | arg[i - 1] = arg[i]; |
| 631 | } |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 632 | arg[arraysize(arg) - 1] = 0; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 633 | |
| 634 | // Rewrite the non-var-arg case |
| 635 | vregC++; // Skips the 0th vreg in the range ("this"). |
| 636 | } |
| 637 | |
| 638 | // Parameter registers go at the end of the shadow frame. |
| 639 | DCHECK_GE(num_regs, number_of_inputs); |
| 640 | size_t first_dest_reg = num_regs - number_of_inputs; |
| 641 | DCHECK_NE(first_dest_reg, (size_t)-1); |
| 642 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 643 | // Allocate shadow frame on the stack. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 644 | const char* old_cause = self->StartAssertNoThreadSuspension("DoCallCommon"); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 645 | ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr = |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 646 | CREATE_SHADOW_FRAME(num_regs, &shadow_frame, called_method, /* dex pc */ 0); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 647 | ShadowFrame* new_shadow_frame = shadow_frame_unique_ptr.get(); |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 648 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 649 | // 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] | 650 | if (do_assignability_check) { |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 651 | // Slow path. |
| 652 | // We might need to do class loading, which incurs a thread state change to kNative. So |
| 653 | // register the shadow frame as under construction and allow suspension again. |
Mingyao Yang | 1f2d3ba | 2015-05-18 12:12:50 -0700 | [diff] [blame] | 654 | ScopedStackedShadowFramePusher pusher( |
Sebastien Hertz | f795869 | 2015-06-09 14:09:14 +0200 | [diff] [blame] | 655 | self, new_shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction); |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 656 | self->EndAssertNoThreadSuspension(old_cause); |
| 657 | |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 658 | // ArtMethod here is needed to check type information of the call site against the callee. |
| 659 | // Type information is retrieved from a DexFile/DexCache for that respective declared method. |
| 660 | // |
| 661 | // As a special case for proxy methods, which are not dex-backed, |
| 662 | // we have to retrieve type information from the proxy's method |
| 663 | // interface method instead (which is dex backed since proxies are never interfaces). |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 664 | ArtMethod* method = |
| 665 | new_shadow_frame->GetMethod()->GetInterfaceMethodIfProxy(kRuntimePointerSize); |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 666 | |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 667 | // 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] | 668 | // to get the exact type of each reference argument. |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 669 | const DexFile::TypeList* params = method->GetParameterTypeList(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 670 | uint32_t shorty_len = 0; |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 671 | const char* shorty = method->GetShorty(&shorty_len); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 672 | |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 673 | // Handle receiver apart since it's not part of the shorty. |
| 674 | size_t dest_reg = first_dest_reg; |
| 675 | size_t arg_offset = 0; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 676 | |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 677 | if (!method->IsStatic()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 678 | size_t receiver_reg = is_range ? vregC : arg[0]; |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 679 | new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg)); |
| 680 | ++dest_reg; |
| 681 | ++arg_offset; |
Igor Murashkin | a06b49b | 2015-06-25 15:18:12 -0700 | [diff] [blame] | 682 | DCHECK(!string_init); // All StringFactory methods are static. |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 683 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 684 | |
| 685 | // Copy the caller's invoke-* arguments into the callee's parameter registers. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 686 | 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] | 687 | // Skip the 0th 'shorty' type since it represents the return type. |
| 688 | DCHECK_LT(shorty_pos + 1, shorty_len) << "for shorty '" << shorty << "'"; |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 689 | const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset]; |
| 690 | switch (shorty[shorty_pos + 1]) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 691 | // Handle Object references. 1 virtual register slot. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 692 | case 'L': { |
| 693 | Object* o = shadow_frame.GetVRegReference(src_reg); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 694 | if (do_assignability_check && o != nullptr) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 695 | PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize(); |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 696 | Class* arg_type = |
Igor Murashkin | 9f95ba7 | 2016-02-01 14:21:25 -0800 | [diff] [blame] | 697 | method->GetClassFromTypeIndex( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 698 | params->GetTypeItem(shorty_pos).type_idx_, true /* resolve */, pointer_size); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 699 | if (arg_type == nullptr) { |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 700 | CHECK(self->IsExceptionPending()); |
| 701 | return false; |
| 702 | } |
| 703 | if (!o->VerifierInstanceOf(arg_type)) { |
| 704 | // This should never happen. |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 705 | std::string temp1, temp2; |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 706 | self->ThrowNewExceptionF("Ljava/lang/VirtualMachineError;", |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 707 | "Invoking %s with bad arg %d, type '%s' not instance of '%s'", |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 708 | new_shadow_frame->GetMethod()->GetName(), shorty_pos, |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 709 | o->GetClass()->GetDescriptor(&temp1), |
| 710 | arg_type->GetDescriptor(&temp2)); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 711 | return false; |
| 712 | } |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 713 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 714 | new_shadow_frame->SetVRegReference(dest_reg, o); |
| 715 | break; |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 716 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 717 | // Handle doubles and longs. 2 consecutive virtual register slots. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 718 | case 'J': case 'D': { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 719 | uint64_t wide_value = |
| 720 | (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << BitSizeOf<uint32_t>()) | |
| 721 | static_cast<uint32_t>(shadow_frame.GetVReg(src_reg)); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 722 | new_shadow_frame->SetVRegLong(dest_reg, wide_value); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 723 | // Skip the next virtual register slot since we already used it. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 724 | ++dest_reg; |
| 725 | ++arg_offset; |
| 726 | break; |
| 727 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 728 | // Handle all other primitives that are always 1 virtual register slot. |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 729 | default: |
| 730 | new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg)); |
| 731 | break; |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 732 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 733 | } |
| 734 | } else { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 735 | size_t arg_index = 0; |
| 736 | |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 737 | // Fast path: no extra checks. |
| 738 | if (is_range) { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 739 | uint16_t first_src_reg = vregC; |
| 740 | |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 741 | for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < num_regs; |
| 742 | ++dest_reg, ++src_reg) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 743 | AssignRegister(new_shadow_frame, shadow_frame, dest_reg, src_reg); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 744 | } |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 745 | } else { |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 746 | DCHECK_LE(number_of_inputs, arraysize(arg)); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 747 | |
| 748 | for (; arg_index < number_of_inputs; ++arg_index) { |
| 749 | AssignRegister(new_shadow_frame, shadow_frame, first_dest_reg + arg_index, arg[arg_index]); |
Sebastien Hertz | 9ace87b | 2013-09-27 11:48:09 +0200 | [diff] [blame] | 750 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 751 | } |
Andreas Gampe | 2a0d4ec | 2014-06-02 22:05:22 -0700 | [diff] [blame] | 752 | self->EndAssertNoThreadSuspension(old_cause); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 753 | } |
| 754 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 755 | // Do the call now. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 756 | if (LIKELY(Runtime::Current()->IsStarted())) { |
Tamas Berghammer | dd5e5e9 | 2016-02-12 16:29:00 +0000 | [diff] [blame] | 757 | ArtMethod* target = new_shadow_frame->GetMethod(); |
| 758 | if (ClassLinker::ShouldUseInterpreterEntrypoint( |
| 759 | target, |
| 760 | target->GetEntryPointFromQuickCompiledCode())) { |
Tamas Berghammer | c94a61f | 2016-02-05 18:09:08 +0000 | [diff] [blame] | 761 | ArtInterpreterToInterpreterBridge(self, code_item, new_shadow_frame, result); |
Tamas Berghammer | 3a98aae | 2016-02-08 20:21:54 +0000 | [diff] [blame] | 762 | } else { |
Nicolas Geoffray | 71cd50f | 2016-04-14 15:00:33 +0100 | [diff] [blame] | 763 | ArtInterpreterToCompiledCodeBridge( |
| 764 | self, shadow_frame.GetMethod(), code_item, new_shadow_frame, result); |
Nicolas Geoffray | 7070ccd | 2015-07-08 09:41:54 +0000 | [diff] [blame] | 765 | } |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 766 | } else { |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 767 | UnstartedRuntime::Invoke(self, code_item, new_shadow_frame, result, first_dest_reg); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 768 | } |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 769 | |
| 770 | if (string_init && !self->IsExceptionPending()) { |
Mingyao Yang | ffedec5 | 2016-05-19 10:48:40 -0700 | [diff] [blame] | 771 | SetStringInitValueToAllAliases(&shadow_frame, string_init_vreg_this, *result); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 772 | } |
| 773 | |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 774 | return !self->IsExceptionPending(); |
| 775 | } |
| 776 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 777 | template<bool is_range, bool do_assignability_check> |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 778 | bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame, |
| 779 | const Instruction* inst, uint16_t inst_data, JValue* result) { |
| 780 | // Argument word count. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 781 | const uint16_t number_of_inputs = |
| 782 | (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data); |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 783 | |
| 784 | // TODO: find a cleaner way to separate non-range and range information without duplicating |
| 785 | // code. |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 786 | uint32_t arg[Instruction::kMaxVarArgRegs] = {}; // only used in invoke-XXX. |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 787 | uint32_t vregC = 0; |
| 788 | if (is_range) { |
| 789 | vregC = inst->VRegC_3rc(); |
| 790 | } else { |
| 791 | vregC = inst->VRegC_35c(); |
| 792 | inst->GetVarArgs(arg, inst_data); |
| 793 | } |
| 794 | |
| 795 | return DoCallCommon<is_range, do_assignability_check>( |
| 796 | called_method, self, shadow_frame, |
| 797 | result, number_of_inputs, arg, vregC); |
| 798 | } |
| 799 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 800 | template <bool is_range, bool do_access_check, bool transaction_active> |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 801 | bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame, |
| 802 | Thread* self, JValue* result) { |
| 803 | DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY || |
| 804 | inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE); |
| 805 | const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c(); |
| 806 | if (!is_range) { |
| 807 | // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments. |
| 808 | CHECK_LE(length, 5); |
| 809 | } |
| 810 | if (UNLIKELY(length < 0)) { |
| 811 | ThrowNegativeArraySizeException(length); |
| 812 | return false; |
| 813 | } |
| 814 | uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 815 | Class* array_class = ResolveVerifyAndClinit(type_idx, shadow_frame.GetMethod(), |
| 816 | self, false, do_access_check); |
| 817 | if (UNLIKELY(array_class == nullptr)) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 818 | DCHECK(self->IsExceptionPending()); |
| 819 | return false; |
| 820 | } |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 821 | CHECK(array_class->IsArrayClass()); |
| 822 | Class* component_class = array_class->GetComponentType(); |
| 823 | const bool is_primitive_int_component = component_class->IsPrimitiveInt(); |
| 824 | if (UNLIKELY(component_class->IsPrimitive() && !is_primitive_int_component)) { |
| 825 | if (component_class->IsPrimitiveLong() || component_class->IsPrimitiveDouble()) { |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 826 | ThrowRuntimeException("Bad filled array request for type %s", |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 827 | PrettyDescriptor(component_class).c_str()); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 828 | } else { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 829 | self->ThrowNewExceptionF("Ljava/lang/InternalError;", |
Brian Carlstrom | 4fa0bcd | 2013-12-10 11:24:21 -0800 | [diff] [blame] | 830 | "Found type %s; filled-new-array not implemented for anything but 'int'", |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 831 | PrettyDescriptor(component_class).c_str()); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 832 | } |
| 833 | return false; |
| 834 | } |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 835 | Object* new_array = Array::Alloc<true>(self, array_class, length, |
| 836 | array_class->GetComponentSizeShift(), |
| 837 | Runtime::Current()->GetHeap()->GetCurrentAllocator()); |
| 838 | if (UNLIKELY(new_array == nullptr)) { |
| 839 | self->AssertPendingOOMException(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 840 | return false; |
| 841 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 842 | uint32_t arg[Instruction::kMaxVarArgRegs]; // only used in filled-new-array. |
| 843 | uint32_t vregC = 0; // only used in filled-new-array-range. |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 844 | if (is_range) { |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 845 | vregC = inst->VRegC_3rc(); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 846 | } else { |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 847 | inst->GetVarArgs(arg); |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 848 | } |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 849 | for (int32_t i = 0; i < length; ++i) { |
| 850 | size_t src_reg = is_range ? vregC + i : arg[i]; |
| 851 | if (is_primitive_int_component) { |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 852 | new_array->AsIntArray()->SetWithoutChecks<transaction_active>( |
| 853 | i, shadow_frame.GetVReg(src_reg)); |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 854 | } else { |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 855 | new_array->AsObjectArray<Object>()->SetWithoutChecks<transaction_active>( |
| 856 | i, shadow_frame.GetVRegReference(src_reg)); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | |
Mathieu Chartier | 52ea33b | 2015-06-18 16:48:52 -0700 | [diff] [blame] | 860 | result->SetL(new_array); |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 861 | return true; |
| 862 | } |
| 863 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 864 | // TODO fix thread analysis: should be REQUIRES_SHARED(Locks::mutator_lock_). |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 865 | template<typename T> |
| 866 | static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array, int32_t count) |
| 867 | NO_THREAD_SAFETY_ANALYSIS { |
| 868 | Runtime* runtime = Runtime::Current(); |
| 869 | for (int32_t i = 0; i < count; ++i) { |
| 870 | runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i)); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 875 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 876 | DCHECK(Runtime::Current()->IsActiveTransaction()); |
| 877 | DCHECK(array != nullptr); |
| 878 | DCHECK_LE(count, array->GetLength()); |
| 879 | Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType(); |
| 880 | switch (primitive_component_type) { |
| 881 | case Primitive::kPrimBoolean: |
| 882 | RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count); |
| 883 | break; |
| 884 | case Primitive::kPrimByte: |
| 885 | RecordArrayElementsInTransactionImpl(array->AsByteArray(), count); |
| 886 | break; |
| 887 | case Primitive::kPrimChar: |
| 888 | RecordArrayElementsInTransactionImpl(array->AsCharArray(), count); |
| 889 | break; |
| 890 | case Primitive::kPrimShort: |
| 891 | RecordArrayElementsInTransactionImpl(array->AsShortArray(), count); |
| 892 | break; |
| 893 | case Primitive::kPrimInt: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 894 | RecordArrayElementsInTransactionImpl(array->AsIntArray(), count); |
| 895 | break; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 896 | case Primitive::kPrimFloat: |
| 897 | RecordArrayElementsInTransactionImpl(array->AsFloatArray(), count); |
| 898 | break; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 899 | case Primitive::kPrimLong: |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 900 | RecordArrayElementsInTransactionImpl(array->AsLongArray(), count); |
| 901 | break; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 902 | case Primitive::kPrimDouble: |
| 903 | RecordArrayElementsInTransactionImpl(array->AsDoubleArray(), count); |
| 904 | break; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 905 | default: |
| 906 | LOG(FATAL) << "Unsupported primitive type " << primitive_component_type |
| 907 | << " in fill-array-data"; |
| 908 | break; |
| 909 | } |
| 910 | } |
| 911 | |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 912 | // Explicit DoCall template function declarations. |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 913 | #define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \ |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 914 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
Sebastien Hertz | 9119c5f | 2013-12-16 11:31:45 +0100 | [diff] [blame] | 915 | bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \ |
| 916 | ShadowFrame& shadow_frame, \ |
Sebastien Hertz | c671485 | 2013-09-30 16:42:32 +0200 | [diff] [blame] | 917 | const Instruction* inst, uint16_t inst_data, \ |
| 918 | JValue* result) |
Sebastien Hertz | c61124b | 2013-09-10 11:44:19 +0200 | [diff] [blame] | 919 | EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false); |
| 920 | EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true); |
| 921 | EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false); |
| 922 | EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true); |
| 923 | #undef EXPLICIT_DO_CALL_TEMPLATE_DECL |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 924 | |
| 925 | // Explicit DoFilledNewArray template function declarations. |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 926 | #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] | 927 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 928 | bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \ |
| 929 | const ShadowFrame& shadow_frame, \ |
| 930 | Thread* self, JValue* result) |
| 931 | #define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \ |
| 932 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \ |
| 933 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \ |
| 934 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \ |
| 935 | EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active) |
| 936 | EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false); |
| 937 | EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true); |
| 938 | #undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL |
Sebastien Hertz | 8ece050 | 2013-08-07 11:26:41 +0200 | [diff] [blame] | 939 | #undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL |
| 940 | |
| 941 | } // namespace interpreter |
| 942 | } // namespace art |