interpreter_common.cc revision 62327cda9a75e9d15daab0749b37257a146631f4
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" 18#include "mirror/array-inl.h" 19 20namespace art { 21namespace interpreter { 22 23void ThrowNullPointerExceptionFromInterpreter(const ShadowFrame& shadow_frame) { 24 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow()); 25} 26 27template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check> 28bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, 29 uint16_t inst_data) { 30 const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead); 31 const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c(); 32 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self, 33 Primitive::FieldSize(field_type)); 34 if (UNLIKELY(f == nullptr)) { 35 CHECK(self->IsExceptionPending()); 36 return false; 37 } 38 Object* obj; 39 if (is_static) { 40 obj = f->GetDeclaringClass(); 41 } else { 42 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); 43 if (UNLIKELY(obj == nullptr)) { 44 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(), f, true); 45 return false; 46 } 47 } 48 f->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self); 49 // Report this field access to instrumentation if needed. 50 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); 51 if (UNLIKELY(instrumentation->HasFieldReadListeners())) { 52 Object* this_object = f->IsStatic() ? nullptr : obj; 53 instrumentation->FieldReadEvent(self, this_object, shadow_frame.GetMethod(), 54 shadow_frame.GetDexPC(), f); 55 } 56 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); 57 switch (field_type) { 58 case Primitive::kPrimBoolean: 59 shadow_frame.SetVReg(vregA, f->GetBoolean(obj)); 60 break; 61 case Primitive::kPrimByte: 62 shadow_frame.SetVReg(vregA, f->GetByte(obj)); 63 break; 64 case Primitive::kPrimChar: 65 shadow_frame.SetVReg(vregA, f->GetChar(obj)); 66 break; 67 case Primitive::kPrimShort: 68 shadow_frame.SetVReg(vregA, f->GetShort(obj)); 69 break; 70 case Primitive::kPrimInt: 71 shadow_frame.SetVReg(vregA, f->GetInt(obj)); 72 break; 73 case Primitive::kPrimLong: 74 shadow_frame.SetVRegLong(vregA, f->GetLong(obj)); 75 break; 76 case Primitive::kPrimNot: 77 shadow_frame.SetVRegReference(vregA, f->GetObject(obj)); 78 break; 79 default: 80 LOG(FATAL) << "Unreachable: " << field_type; 81 } 82 return true; 83} 84 85// Explicitly instantiate all DoFieldGet functions. 86#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \ 87 template bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, \ 88 ShadowFrame& shadow_frame, \ 89 const Instruction* inst, \ 90 uint16_t inst_data) 91 92#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \ 93 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \ 94 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true); 95 96// iget-XXX 97EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean); 98EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte); 99EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar); 100EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort); 101EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt); 102EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong); 103EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot); 104 105// sget-XXX 106EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean); 107EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte); 108EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar); 109EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort); 110EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt); 111EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong); 112EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot); 113 114#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL 115#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL 116 117// Handles iget-quick, iget-wide-quick and iget-object-quick instructions. 118// Returns true on success, otherwise throws an exception and returns false. 119template<Primitive::Type field_type> 120bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) { 121 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); 122 if (UNLIKELY(obj == nullptr)) { 123 // We lost the reference to the field index so we cannot get a more 124 // precised exception message. 125 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow()); 126 return false; 127 } 128 MemberOffset field_offset(inst->VRegC_22c()); 129 // Report this field access to instrumentation if needed. Since we only have the offset of 130 // the field from the base of the object, we need to look for it first. 131 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); 132 if (UNLIKELY(instrumentation->HasFieldReadListeners())) { 133 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), 134 field_offset.Uint32Value()); 135 DCHECK(f != nullptr); 136 DCHECK(!f->IsStatic()); 137 instrumentation->FieldReadEvent(Thread::Current(), obj, shadow_frame.GetMethod(), 138 shadow_frame.GetDexPC(), f); 139 } 140 // Note: iget-x-quick instructions are only for non-volatile fields. 141 const uint32_t vregA = inst->VRegA_22c(inst_data); 142 switch (field_type) { 143 case Primitive::kPrimInt: 144 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset))); 145 break; 146 case Primitive::kPrimLong: 147 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset))); 148 break; 149 case Primitive::kPrimNot: 150 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset)); 151 break; 152 default: 153 LOG(FATAL) << "Unreachable: " << field_type; 154 } 155 return true; 156} 157 158// Explicitly instantiate all DoIGetQuick functions. 159#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \ 160 template bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \ 161 uint16_t inst_data) 162 163EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick. 164EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick. 165EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick. 166#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL 167 168template<Primitive::Type field_type> 169static JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg) 170 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 171 JValue field_value; 172 switch (field_type) { 173 case Primitive::kPrimBoolean: 174 field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg))); 175 break; 176 case Primitive::kPrimByte: 177 field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg))); 178 break; 179 case Primitive::kPrimChar: 180 field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg))); 181 break; 182 case Primitive::kPrimShort: 183 field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg))); 184 break; 185 case Primitive::kPrimInt: 186 field_value.SetI(shadow_frame.GetVReg(vreg)); 187 break; 188 case Primitive::kPrimLong: 189 field_value.SetJ(shadow_frame.GetVRegLong(vreg)); 190 break; 191 case Primitive::kPrimNot: 192 field_value.SetL(shadow_frame.GetVRegReference(vreg)); 193 break; 194 default: 195 LOG(FATAL) << "Unreachable: " << field_type; 196 break; 197 } 198 return field_value; 199} 200 201template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, 202 bool transaction_active> 203bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst, 204 uint16_t inst_data) { 205 bool do_assignability_check = do_access_check; 206 bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite); 207 uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c(); 208 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self, 209 Primitive::FieldSize(field_type)); 210 if (UNLIKELY(f == nullptr)) { 211 CHECK(self->IsExceptionPending()); 212 return false; 213 } 214 Object* obj; 215 if (is_static) { 216 obj = f->GetDeclaringClass(); 217 } else { 218 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); 219 if (UNLIKELY(obj == nullptr)) { 220 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(), 221 f, false); 222 return false; 223 } 224 } 225 f->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self); 226 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data); 227 // Report this field access to instrumentation if needed. Since we only have the offset of 228 // the field from the base of the object, we need to look for it first. 229 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); 230 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { 231 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); 232 Object* this_object = f->IsStatic() ? nullptr : obj; 233 instrumentation->FieldWriteEvent(self, this_object, shadow_frame.GetMethod(), 234 shadow_frame.GetDexPC(), f, field_value); 235 } 236 switch (field_type) { 237 case Primitive::kPrimBoolean: 238 f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA)); 239 break; 240 case Primitive::kPrimByte: 241 f->SetByte<transaction_active>(obj, shadow_frame.GetVReg(vregA)); 242 break; 243 case Primitive::kPrimChar: 244 f->SetChar<transaction_active>(obj, shadow_frame.GetVReg(vregA)); 245 break; 246 case Primitive::kPrimShort: 247 f->SetShort<transaction_active>(obj, shadow_frame.GetVReg(vregA)); 248 break; 249 case Primitive::kPrimInt: 250 f->SetInt<transaction_active>(obj, shadow_frame.GetVReg(vregA)); 251 break; 252 case Primitive::kPrimLong: 253 f->SetLong<transaction_active>(obj, shadow_frame.GetVRegLong(vregA)); 254 break; 255 case Primitive::kPrimNot: { 256 Object* reg = shadow_frame.GetVRegReference(vregA); 257 if (do_assignability_check && reg != nullptr) { 258 // FieldHelper::GetType can resolve classes, use a handle wrapper which will restore the 259 // object in the destructor. 260 Class* field_class; 261 { 262 StackHandleScope<3> hs(self); 263 HandleWrapper<mirror::ArtField> h_f(hs.NewHandleWrapper(&f)); 264 HandleWrapper<mirror::Object> h_reg(hs.NewHandleWrapper(®)); 265 HandleWrapper<mirror::Object> h_obj(hs.NewHandleWrapper(&obj)); 266 FieldHelper fh(h_f); 267 field_class = fh.GetType(); 268 } 269 if (!reg->VerifierInstanceOf(field_class)) { 270 // This should never happen. 271 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(), 272 "Ljava/lang/VirtualMachineError;", 273 "Put '%s' that is not instance of field '%s' in '%s'", 274 reg->GetClass()->GetDescriptor().c_str(), 275 field_class->GetDescriptor().c_str(), 276 f->GetDeclaringClass()->GetDescriptor().c_str()); 277 return false; 278 } 279 } 280 f->SetObj<transaction_active>(obj, reg); 281 break; 282 } 283 default: 284 LOG(FATAL) << "Unreachable: " << field_type; 285 } 286 return true; 287} 288 289// Explicitly instantiate all DoFieldPut functions. 290#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \ 291 template bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \ 292 const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) 293 294#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \ 295 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \ 296 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \ 297 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \ 298 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true); 299 300// iput-XXX 301EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean); 302EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte); 303EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar); 304EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort); 305EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt); 306EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong); 307EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot); 308 309// sput-XXX 310EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean); 311EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte); 312EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar); 313EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort); 314EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt); 315EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong); 316EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot); 317 318#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL 319#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL 320 321template<Primitive::Type field_type, bool transaction_active> 322bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) { 323 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data)); 324 if (UNLIKELY(obj == nullptr)) { 325 // We lost the reference to the field index so we cannot get a more 326 // precised exception message. 327 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow()); 328 return false; 329 } 330 MemberOffset field_offset(inst->VRegC_22c()); 331 const uint32_t vregA = inst->VRegA_22c(inst_data); 332 // Report this field modification to instrumentation if needed. Since we only have the offset of 333 // the field from the base of the object, we need to look for it first. 334 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); 335 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) { 336 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(), 337 field_offset.Uint32Value()); 338 DCHECK(f != nullptr); 339 DCHECK(!f->IsStatic()); 340 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA); 341 instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(), 342 shadow_frame.GetDexPC(), f, field_value); 343 } 344 // Note: iput-x-quick instructions are only for non-volatile fields. 345 switch (field_type) { 346 case Primitive::kPrimInt: 347 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA)); 348 break; 349 case Primitive::kPrimLong: 350 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA)); 351 break; 352 case Primitive::kPrimNot: 353 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA)); 354 break; 355 default: 356 LOG(FATAL) << "Unreachable: " << field_type; 357 } 358 return true; 359} 360 361// Explicitly instantiate all DoIPutQuick functions. 362#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \ 363 template bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \ 364 const Instruction* inst, \ 365 uint16_t inst_data) 366 367#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \ 368 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \ 369 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true); 370 371EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick. 372EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick. 373EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick. 374#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL 375#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL 376 377/** 378 * Finds the location where this exception will be caught. We search until we reach either the top 379 * frame or a native frame, in which cases this exception is considered uncaught. 380 */ 381class CatchLocationFinder : public StackVisitor { 382 public: 383 explicit CatchLocationFinder(Thread* self, Handle<mirror::Throwable>* exception) 384 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) 385 : StackVisitor(self, nullptr), self_(self), handle_scope_(self), exception_(exception), 386 catch_method_(handle_scope_.NewHandle<mirror::ArtMethod>(nullptr)), 387 catch_dex_pc_(DexFile::kDexNoIndex), clear_exception_(false) { 388 } 389 390 bool VisitFrame() OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 391 mirror::ArtMethod* method = GetMethod(); 392 if (method == nullptr) { 393 return true; 394 } 395 if (method->IsRuntimeMethod()) { 396 // Ignore callee save method. 397 DCHECK(method->IsCalleeSaveMethod()); 398 return true; 399 } 400 if (method->IsNative()) { 401 return false; // End stack walk. 402 } 403 DCHECK(!method->IsNative()); 404 uint32_t dex_pc = GetDexPc(); 405 if (dex_pc != DexFile::kDexNoIndex) { 406 uint32_t found_dex_pc; 407 { 408 StackHandleScope<3> hs(self_); 409 Handle<mirror::Class> exception_class(hs.NewHandle((*exception_)->GetClass())); 410 Handle<mirror::ArtMethod> h_method(hs.NewHandle(method)); 411 found_dex_pc = mirror::ArtMethod::FindCatchBlock(h_method, exception_class, dex_pc, 412 &clear_exception_); 413 } 414 if (found_dex_pc != DexFile::kDexNoIndex) { 415 catch_method_.Assign(method); 416 catch_dex_pc_ = found_dex_pc; 417 return false; // End stack walk. 418 } 419 } 420 return true; // Continue stack walk. 421 } 422 423 ArtMethod* GetCatchMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 424 return catch_method_.Get(); 425 } 426 427 uint32_t GetCatchDexPc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 428 return catch_dex_pc_; 429 } 430 431 bool NeedClearException() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 432 return clear_exception_; 433 } 434 435 private: 436 Thread* const self_; 437 StackHandleScope<1> handle_scope_; 438 Handle<mirror::Throwable>* exception_; 439 Handle<mirror::ArtMethod> catch_method_; 440 uint32_t catch_dex_pc_; 441 bool clear_exception_; 442 443 444 DISALLOW_COPY_AND_ASSIGN(CatchLocationFinder); 445}; 446 447uint32_t FindNextInstructionFollowingException(Thread* self, 448 ShadowFrame& shadow_frame, 449 uint32_t dex_pc, 450 const instrumentation::Instrumentation* instrumentation) { 451 self->VerifyStack(); 452 ThrowLocation throw_location; 453 StackHandleScope<3> hs(self); 454 Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException(&throw_location))); 455 if (!self->IsExceptionReportedToInstrumentation() && instrumentation->HasExceptionCaughtListeners()) { 456 CatchLocationFinder clf(self, &exception); 457 clf.WalkStack(false); 458 instrumentation->ExceptionCaughtEvent(self, throw_location, clf.GetCatchMethod(), 459 clf.GetCatchDexPc(), exception.Get()); 460 self->SetExceptionReportedToInstrumentation(true); 461 } 462 bool clear_exception = false; 463 uint32_t found_dex_pc; 464 { 465 Handle<mirror::Class> exception_class(hs.NewHandle(exception->GetClass())); 466 Handle<mirror::ArtMethod> h_method(hs.NewHandle(shadow_frame.GetMethod())); 467 found_dex_pc = mirror::ArtMethod::FindCatchBlock(h_method, exception_class, dex_pc, 468 &clear_exception); 469 } 470 if (found_dex_pc == DexFile::kDexNoIndex) { 471 instrumentation->MethodUnwindEvent(self, shadow_frame.GetThisObject(), 472 shadow_frame.GetMethod(), dex_pc); 473 } else { 474 if (self->IsExceptionReportedToInstrumentation()) { 475 instrumentation->MethodUnwindEvent(self, shadow_frame.GetThisObject(), 476 shadow_frame.GetMethod(), dex_pc); 477 } 478 if (clear_exception) { 479 self->ClearException(); 480 } 481 } 482 return found_dex_pc; 483} 484 485void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) { 486 LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(mh.GetMethod()->GetDexFile()); 487 exit(0); // Unreachable, keep GCC happy. 488} 489 490static void UnstartedRuntimeInvoke(Thread* self, MethodHelper& mh, 491 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame, 492 JValue* result, size_t arg_offset) 493 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 494 495// Assign register 'src_reg' from shadow_frame to register 'dest_reg' into new_shadow_frame. 496static inline void AssignRegister(ShadowFrame* new_shadow_frame, const ShadowFrame& shadow_frame, 497 size_t dest_reg, size_t src_reg) 498 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 499 // If both register locations contains the same value, the register probably holds a reference. 500 // Uint required, so that sign extension does not make this wrong on 64b systems 501 uint32_t src_value = shadow_frame.GetVReg(src_reg); 502 mirror::Object* o = shadow_frame.GetVRegReference<kVerifyNone>(src_reg); 503 if (src_value == reinterpret_cast<uintptr_t>(o)) { 504 new_shadow_frame->SetVRegReference(dest_reg, o); 505 } else { 506 new_shadow_frame->SetVReg(dest_reg, src_value); 507 } 508} 509 510void AbortTransaction(Thread* self, const char* fmt, ...) { 511 CHECK(Runtime::Current()->IsActiveTransaction()); 512 // Throw an exception so we can abort the transaction and undo every change. 513 va_list args; 514 va_start(args, fmt); 515 self->ThrowNewExceptionV(self->GetCurrentLocationForThrow(), "Ljava/lang/InternalError;", fmt, 516 args); 517 va_end(args); 518} 519 520template<bool is_range, bool do_assignability_check> 521bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame, 522 const Instruction* inst, uint16_t inst_data, JValue* result) { 523 // Compute method information. 524 const DexFile::CodeItem* code_item = method->GetCodeItem(); 525 const uint16_t num_ins = (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data); 526 uint16_t num_regs; 527 if (LIKELY(code_item != NULL)) { 528 num_regs = code_item->registers_size_; 529 DCHECK_EQ(num_ins, code_item->ins_size_); 530 } else { 531 DCHECK(method->IsNative() || method->IsProxyMethod()); 532 num_regs = num_ins; 533 } 534 535 // Allocate shadow frame on the stack. 536 const char* old_cause = self->StartAssertNoThreadSuspension("DoCall"); 537 void* memory = alloca(ShadowFrame::ComputeSize(num_regs)); 538 ShadowFrame* new_shadow_frame(ShadowFrame::Create(num_regs, &shadow_frame, method, 0, memory)); 539 540 // Initialize new shadow frame. 541 const size_t first_dest_reg = num_regs - num_ins; 542 StackHandleScope<1> hs(self); 543 MethodHelper mh(hs.NewHandle(method)); 544 if (do_assignability_check) { 545 // Slow path. 546 // We might need to do class loading, which incurs a thread state change to kNative. So 547 // register the shadow frame as under construction and allow suspension again. 548 self->SetShadowFrameUnderConstruction(new_shadow_frame); 549 self->EndAssertNoThreadSuspension(old_cause); 550 551 // We need to do runtime check on reference assignment. We need to load the shorty 552 // to get the exact type of each reference argument. 553 const DexFile::TypeList* params = method->GetParameterTypeList(); 554 uint32_t shorty_len = 0; 555 const char* shorty = method->GetShorty(&shorty_len); 556 557 // TODO: find a cleaner way to separate non-range and range information without duplicating code. 558 uint32_t arg[5]; // only used in invoke-XXX. 559 uint32_t vregC; // only used in invoke-XXX-range. 560 if (is_range) { 561 vregC = inst->VRegC_3rc(); 562 } else { 563 inst->GetVarArgs(arg, inst_data); 564 } 565 566 // Handle receiver apart since it's not part of the shorty. 567 size_t dest_reg = first_dest_reg; 568 size_t arg_offset = 0; 569 if (!method->IsStatic()) { 570 size_t receiver_reg = is_range ? vregC : arg[0]; 571 new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg)); 572 ++dest_reg; 573 ++arg_offset; 574 } 575 for (uint32_t shorty_pos = 0; dest_reg < num_regs; ++shorty_pos, ++dest_reg, ++arg_offset) { 576 DCHECK_LT(shorty_pos + 1, shorty_len); 577 const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset]; 578 switch (shorty[shorty_pos + 1]) { 579 case 'L': { 580 Object* o = shadow_frame.GetVRegReference(src_reg); 581 if (do_assignability_check && o != NULL) { 582 Class* arg_type = mh.GetClassFromTypeIdx(params->GetTypeItem(shorty_pos).type_idx_); 583 if (arg_type == NULL) { 584 CHECK(self->IsExceptionPending()); 585 return false; 586 } 587 if (!o->VerifierInstanceOf(arg_type)) { 588 // This should never happen. 589 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(), 590 "Ljava/lang/VirtualMachineError;", 591 "Invoking %s with bad arg %d, type '%s' not instance of '%s'", 592 method->GetName(), shorty_pos, 593 o->GetClass()->GetDescriptor().c_str(), 594 arg_type->GetDescriptor().c_str()); 595 return false; 596 } 597 } 598 new_shadow_frame->SetVRegReference(dest_reg, o); 599 break; 600 } 601 case 'J': case 'D': { 602 uint64_t wide_value = (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << 32) | 603 static_cast<uint32_t>(shadow_frame.GetVReg(src_reg)); 604 new_shadow_frame->SetVRegLong(dest_reg, wide_value); 605 ++dest_reg; 606 ++arg_offset; 607 break; 608 } 609 default: 610 new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg)); 611 break; 612 } 613 } 614 // We're done with the construction. 615 self->ClearShadowFrameUnderConstruction(); 616 } else { 617 // Fast path: no extra checks. 618 if (is_range) { 619 const uint16_t first_src_reg = inst->VRegC_3rc(); 620 for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < num_regs; 621 ++dest_reg, ++src_reg) { 622 AssignRegister(new_shadow_frame, shadow_frame, dest_reg, src_reg); 623 } 624 } else { 625 DCHECK_LE(num_ins, 5U); 626 uint16_t regList = inst->Fetch16(2); 627 uint16_t count = num_ins; 628 if (count == 5) { 629 AssignRegister(new_shadow_frame, shadow_frame, first_dest_reg + 4U, (inst_data >> 8) & 0x0f); 630 --count; 631 } 632 for (size_t arg_index = 0; arg_index < count; ++arg_index, regList >>= 4) { 633 AssignRegister(new_shadow_frame, shadow_frame, first_dest_reg + arg_index, regList & 0x0f); 634 } 635 } 636 self->EndAssertNoThreadSuspension(old_cause); 637 } 638 639 // Do the call now. 640 if (LIKELY(Runtime::Current()->IsStarted())) { 641 if (kIsDebugBuild && method->GetEntryPointFromInterpreter() == nullptr) { 642 LOG(FATAL) << "Attempt to invoke non-executable method: " << PrettyMethod(method); 643 } 644 if (kIsDebugBuild && Runtime::Current()->GetInstrumentation()->IsForcedInterpretOnly() && 645 !method->IsNative() && !method->IsProxyMethod() && 646 method->GetEntryPointFromInterpreter() == artInterpreterToCompiledCodeBridge) { 647 LOG(FATAL) << "Attempt to call compiled code when -Xint: " << PrettyMethod(method); 648 } 649 (method->GetEntryPointFromInterpreter())(self, mh, code_item, new_shadow_frame, result); 650 } else { 651 UnstartedRuntimeInvoke(self, mh, code_item, new_shadow_frame, result, first_dest_reg); 652 } 653 return !self->IsExceptionPending(); 654} 655 656template <bool is_range, bool do_access_check, bool transaction_active> 657bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame, 658 Thread* self, JValue* result) { 659 DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY || 660 inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE); 661 const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c(); 662 if (!is_range) { 663 // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments. 664 CHECK_LE(length, 5); 665 } 666 if (UNLIKELY(length < 0)) { 667 ThrowNegativeArraySizeException(length); 668 return false; 669 } 670 uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c(); 671 Class* arrayClass = ResolveVerifyAndClinit(type_idx, shadow_frame.GetMethod(), 672 self, false, do_access_check); 673 if (UNLIKELY(arrayClass == NULL)) { 674 DCHECK(self->IsExceptionPending()); 675 return false; 676 } 677 CHECK(arrayClass->IsArrayClass()); 678 Class* componentClass = arrayClass->GetComponentType(); 679 if (UNLIKELY(componentClass->IsPrimitive() && !componentClass->IsPrimitiveInt())) { 680 if (componentClass->IsPrimitiveLong() || componentClass->IsPrimitiveDouble()) { 681 ThrowRuntimeException("Bad filled array request for type %s", 682 PrettyDescriptor(componentClass).c_str()); 683 } else { 684 self->ThrowNewExceptionF(shadow_frame.GetCurrentLocationForThrow(), 685 "Ljava/lang/InternalError;", 686 "Found type %s; filled-new-array not implemented for anything but 'int'", 687 PrettyDescriptor(componentClass).c_str()); 688 } 689 return false; 690 } 691 Object* newArray = Array::Alloc<true>(self, arrayClass, length, arrayClass->GetComponentSize(), 692 Runtime::Current()->GetHeap()->GetCurrentAllocator()); 693 if (UNLIKELY(newArray == NULL)) { 694 DCHECK(self->IsExceptionPending()); 695 return false; 696 } 697 uint32_t arg[5]; // only used in filled-new-array. 698 uint32_t vregC; // only used in filled-new-array-range. 699 if (is_range) { 700 vregC = inst->VRegC_3rc(); 701 } else { 702 inst->GetVarArgs(arg); 703 } 704 const bool is_primitive_int_component = componentClass->IsPrimitiveInt(); 705 for (int32_t i = 0; i < length; ++i) { 706 size_t src_reg = is_range ? vregC + i : arg[i]; 707 if (is_primitive_int_component) { 708 newArray->AsIntArray()->SetWithoutChecks<transaction_active>(i, shadow_frame.GetVReg(src_reg)); 709 } else { 710 newArray->AsObjectArray<Object>()->SetWithoutChecks<transaction_active>(i, shadow_frame.GetVRegReference(src_reg)); 711 } 712 } 713 714 result->SetL(newArray); 715 return true; 716} 717 718// TODO fix thread analysis: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). 719template<typename T> 720static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array, int32_t count) 721 NO_THREAD_SAFETY_ANALYSIS { 722 Runtime* runtime = Runtime::Current(); 723 for (int32_t i = 0; i < count; ++i) { 724 runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i)); 725 } 726} 727 728void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count) 729 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 730 DCHECK(Runtime::Current()->IsActiveTransaction()); 731 DCHECK(array != nullptr); 732 DCHECK_LE(count, array->GetLength()); 733 Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType(); 734 switch (primitive_component_type) { 735 case Primitive::kPrimBoolean: 736 RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count); 737 break; 738 case Primitive::kPrimByte: 739 RecordArrayElementsInTransactionImpl(array->AsByteArray(), count); 740 break; 741 case Primitive::kPrimChar: 742 RecordArrayElementsInTransactionImpl(array->AsCharArray(), count); 743 break; 744 case Primitive::kPrimShort: 745 RecordArrayElementsInTransactionImpl(array->AsShortArray(), count); 746 break; 747 case Primitive::kPrimInt: 748 case Primitive::kPrimFloat: 749 RecordArrayElementsInTransactionImpl(array->AsIntArray(), count); 750 break; 751 case Primitive::kPrimLong: 752 case Primitive::kPrimDouble: 753 RecordArrayElementsInTransactionImpl(array->AsLongArray(), count); 754 break; 755 default: 756 LOG(FATAL) << "Unsupported primitive type " << primitive_component_type 757 << " in fill-array-data"; 758 break; 759 } 760} 761 762// Helper function to deal with class loading in an unstarted runtime. 763static void UnstartedRuntimeFindClass(Thread* self, Handle<mirror::String> className, 764 Handle<mirror::ClassLoader> class_loader, JValue* result, 765 const std::string& method_name, bool initialize_class, 766 bool abort_if_not_found) 767 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 768 CHECK(className.Get() != nullptr); 769 std::string descriptor(DotToDescriptor(className->ToModifiedUtf8().c_str())); 770 ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); 771 772 Class* found = class_linker->FindClass(self, descriptor.c_str(), class_loader); 773 if (found == nullptr && abort_if_not_found) { 774 if (!self->IsExceptionPending()) { 775 AbortTransaction(self, "%s failed in un-started runtime for class: %s", 776 method_name.c_str(), PrettyDescriptor(descriptor).c_str()); 777 } 778 return; 779 } 780 if (found != nullptr && initialize_class) { 781 StackHandleScope<1> hs(self); 782 Handle<mirror::Class> h_class(hs.NewHandle(found)); 783 if (!class_linker->EnsureInitialized(h_class, true, true)) { 784 CHECK(self->IsExceptionPending()); 785 return; 786 } 787 } 788 result->SetL(found); 789} 790 791static void UnstartedRuntimeInvoke(Thread* self, MethodHelper& mh, 792 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame, 793 JValue* result, size_t arg_offset) { 794 // In a runtime that's not started we intercept certain methods to avoid complicated dependency 795 // problems in core libraries. 796 std::string name(PrettyMethod(shadow_frame->GetMethod())); 797 if (name == "java.lang.Class java.lang.Class.forName(java.lang.String)") { 798 // TODO: Support for the other variants that take more arguments should also be added. 799 mirror::String* class_name = shadow_frame->GetVRegReference(arg_offset)->AsString(); 800 StackHandleScope<1> hs(self); 801 Handle<mirror::String> h_class_name(hs.NewHandle(class_name)); 802 UnstartedRuntimeFindClass(self, h_class_name, NullHandle<mirror::ClassLoader>(), result, name, 803 true, true); 804 } else if (name == "java.lang.Class java.lang.VMClassLoader.loadClass(java.lang.String, boolean)") { 805 mirror::String* class_name = shadow_frame->GetVRegReference(arg_offset)->AsString(); 806 StackHandleScope<1> hs(self); 807 Handle<mirror::String> h_class_name(hs.NewHandle(class_name)); 808 UnstartedRuntimeFindClass(self, h_class_name, NullHandle<mirror::ClassLoader>(), result, name, 809 false, true); 810 } else if (name == "java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String)") { 811 mirror::String* class_name = shadow_frame->GetVRegReference(arg_offset + 1)->AsString(); 812 mirror::ClassLoader* class_loader = 813 down_cast<mirror::ClassLoader*>(shadow_frame->GetVRegReference(arg_offset)); 814 StackHandleScope<2> hs(self); 815 Handle<mirror::String> h_class_name(hs.NewHandle(class_name)); 816 Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(class_loader)); 817 UnstartedRuntimeFindClass(self, h_class_name, h_class_loader, result, name, false, false); 818 } else if (name == "java.lang.Class java.lang.Void.lookupType()") { 819 result->SetL(Runtime::Current()->GetClassLinker()->FindPrimitiveClass('V')); 820 } else if (name == "java.lang.Object java.lang.Class.newInstance()") { 821 Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass(); 822 ArtMethod* c = klass->FindDeclaredDirectMethod("<init>", "()V"); 823 CHECK(c != NULL); 824 StackHandleScope<1> hs(self); 825 Handle<Object> obj(hs.NewHandle(klass->AllocObject(self))); 826 CHECK(obj.Get() != NULL); 827 EnterInterpreterFromInvoke(self, c, obj.Get(), NULL, NULL); 828 result->SetL(obj.Get()); 829 } else if (name == "java.lang.reflect.Field java.lang.Class.getDeclaredField(java.lang.String)") { 830 // Special managed code cut-out to allow field lookup in a un-started runtime that'd fail 831 // going the reflective Dex way. 832 Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass(); 833 String* name = shadow_frame->GetVRegReference(arg_offset + 1)->AsString(); 834 ArtField* found = NULL; 835 ObjectArray<ArtField>* fields = klass->GetIFields(); 836 for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) { 837 ArtField* f = fields->Get(i); 838 if (name->Equals(f->GetName())) { 839 found = f; 840 } 841 } 842 if (found == NULL) { 843 fields = klass->GetSFields(); 844 for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) { 845 ArtField* f = fields->Get(i); 846 if (name->Equals(f->GetName())) { 847 found = f; 848 } 849 } 850 } 851 CHECK(found != NULL) 852 << "Failed to find field in Class.getDeclaredField in un-started runtime. name=" 853 << name->ToModifiedUtf8() << " class=" << PrettyDescriptor(klass); 854 // TODO: getDeclaredField calls GetType once the field is found to ensure a 855 // NoClassDefFoundError is thrown if the field's type cannot be resolved. 856 Class* jlr_Field = self->DecodeJObject(WellKnownClasses::java_lang_reflect_Field)->AsClass(); 857 StackHandleScope<1> hs(self); 858 Handle<Object> field(hs.NewHandle(jlr_Field->AllocNonMovableObject(self))); 859 CHECK(field.Get() != NULL); 860 ArtMethod* c = jlr_Field->FindDeclaredDirectMethod("<init>", "(Ljava/lang/reflect/ArtField;)V"); 861 uint32_t args[1]; 862 args[0] = StackReference<mirror::Object>::FromMirrorPtr(found).AsVRegValue(); 863 EnterInterpreterFromInvoke(self, c, field.Get(), args, NULL); 864 result->SetL(field.Get()); 865 } else if (name == "int java.lang.Object.hashCode()") { 866 Object* obj = shadow_frame->GetVRegReference(arg_offset); 867 result->SetI(obj->IdentityHashCode()); 868 } else if (name == "java.lang.String java.lang.reflect.ArtMethod.getMethodName(java.lang.reflect.ArtMethod)") { 869 StackHandleScope<1> hs(self); 870 MethodHelper mh(hs.NewHandle(shadow_frame->GetVRegReference(arg_offset)->AsArtMethod())); 871 result->SetL(mh.GetNameAsString(self)); 872 } else if (name == "void java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int)" || 873 name == "void java.lang.System.arraycopy(char[], int, char[], int, int)") { 874 // Special case array copying without initializing System. 875 Class* ctype = shadow_frame->GetVRegReference(arg_offset)->GetClass()->GetComponentType(); 876 jint srcPos = shadow_frame->GetVReg(arg_offset + 1); 877 jint dstPos = shadow_frame->GetVReg(arg_offset + 3); 878 jint length = shadow_frame->GetVReg(arg_offset + 4); 879 if (!ctype->IsPrimitive()) { 880 ObjectArray<Object>* src = shadow_frame->GetVRegReference(arg_offset)->AsObjectArray<Object>(); 881 ObjectArray<Object>* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsObjectArray<Object>(); 882 for (jint i = 0; i < length; ++i) { 883 dst->Set(dstPos + i, src->Get(srcPos + i)); 884 } 885 } else if (ctype->IsPrimitiveChar()) { 886 CharArray* src = shadow_frame->GetVRegReference(arg_offset)->AsCharArray(); 887 CharArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsCharArray(); 888 for (jint i = 0; i < length; ++i) { 889 dst->Set(dstPos + i, src->Get(srcPos + i)); 890 } 891 } else if (ctype->IsPrimitiveInt()) { 892 IntArray* src = shadow_frame->GetVRegReference(arg_offset)->AsIntArray(); 893 IntArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsIntArray(); 894 for (jint i = 0; i < length; ++i) { 895 dst->Set(dstPos + i, src->Get(srcPos + i)); 896 } 897 } else { 898 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(), "Ljava/lang/InternalError;", 899 "Unimplemented System.arraycopy for type '%s'", 900 PrettyDescriptor(ctype).c_str()); 901 } 902 } else if (name == "java.lang.Object java.lang.ThreadLocal.get()") { 903 std::string caller(PrettyMethod(shadow_frame->GetLink()->GetMethod())); 904 if (caller == "java.lang.String java.lang.IntegralToString.convertInt(java.lang.AbstractStringBuilder, int)") { 905 // Allocate non-threadlocal buffer. 906 result->SetL(mirror::CharArray::Alloc(self, 11)); 907 } else { 908 self->ThrowNewException(self->GetCurrentLocationForThrow(), "Ljava/lang/InternalError;", 909 "Unimplemented ThreadLocal.get"); 910 } 911 } else { 912 // Not special, continue with regular interpreter execution. 913 artInterpreterToInterpreterBridge(self, mh, code_item, shadow_frame, result); 914 } 915} 916 917// Explicit DoCall template function declarations. 918#define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \ 919 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \ 920 bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \ 921 ShadowFrame& shadow_frame, \ 922 const Instruction* inst, uint16_t inst_data, \ 923 JValue* result) 924EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false); 925EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true); 926EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false); 927EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true); 928#undef EXPLICIT_DO_CALL_TEMPLATE_DECL 929 930// Explicit DoFilledNewArray template function declarations. 931#define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \ 932 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \ 933 bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \ 934 const ShadowFrame& shadow_frame, \ 935 Thread* self, JValue* result) 936#define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \ 937 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \ 938 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \ 939 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \ 940 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active) 941EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false); 942EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true); 943#undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL 944#undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL 945 946} // namespace interpreter 947} // namespace art 948