diff options
author | 2017-03-14 14:18:46 +0000 | |
---|---|---|
committer | 2017-03-14 19:03:20 +0000 | |
commit | f44d36c8423f81cbb5e9f55d8813e26ffa1a7f3b (patch) | |
tree | 324b41485ce6c414c1a006c72cbcc5ed9f466138 /runtime/class_linker.cc | |
parent | 8d6768d47b66a688d35399d524ad5a5450e9d9d4 (diff) |
Revert^2 "Hash-based DexCache field array."
Test: testrunner.py --host --interpreter
Bug: 30627598
This reverts commit 6374c58f2ea403b3a05fb27376110fe4d0fc8e3f.
Change-Id: I275508e288a85d3aa08f7405a1a4f362af43b775
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r-- | runtime/class_linker.cc | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 5b7d56644e..952a71793c 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -1280,7 +1280,10 @@ bool ClassLinker::UpdateAppImageClassLoadersAndDexCaches( num_types = dex_file->NumTypeIds(); } const size_t num_methods = dex_file->NumMethodIds(); - const size_t num_fields = dex_file->NumFieldIds(); + size_t num_fields = mirror::DexCache::kDexCacheFieldCacheSize; + if (dex_file->NumFieldIds() < num_fields) { + num_fields = dex_file->NumFieldIds(); + } size_t num_method_types = mirror::DexCache::kDexCacheMethodTypeCacheSize; if (dex_file->NumProtoIds() < num_method_types) { num_method_types = dex_file->NumProtoIds(); @@ -1324,17 +1327,22 @@ bool ClassLinker::UpdateAppImageClassLoadersAndDexCaches( dex_cache->SetResolvedMethods(methods); } if (num_fields != 0u) { - ArtField** const fields = - reinterpret_cast<ArtField**>(raw_arrays + layout.FieldsOffset()); - for (size_t j = 0; kIsDebugBuild && j < num_fields; ++j) { - DCHECK(fields[j] == nullptr); + mirror::FieldDexCacheType* const image_resolved_fields = dex_cache->GetResolvedFields(); + mirror::FieldDexCacheType* const fields = + reinterpret_cast<mirror::FieldDexCacheType*>(raw_arrays + layout.FieldsOffset()); + for (size_t j = 0; j < num_fields; ++j) { + DCHECK_EQ(mirror::DexCache::GetNativePairPtrSize(fields, j, image_pointer_size_).index, + 0u); + DCHECK(mirror::DexCache::GetNativePairPtrSize(fields, j, image_pointer_size_).object == + nullptr); + mirror::DexCache::SetNativePairPtrSize( + fields, + j, + mirror::DexCache::GetNativePairPtrSize(image_resolved_fields, + j, + image_pointer_size_), + image_pointer_size_); } - CopyNonNull(dex_cache->GetResolvedFields(), - num_fields, - fields, - [] (const ArtField* field) { - return field == nullptr; - }); dex_cache->SetResolvedFields(fields); } if (num_method_types != 0u) { @@ -8150,6 +8158,43 @@ ArtMethod* ClassLinker::ResolveMethodWithoutInvokeType(const DexFile& dex_file, return resolved; } +ArtField* ClassLinker::LookupResolvedField(uint32_t field_idx, + ObjPtr<mirror::DexCache> dex_cache, + ObjPtr<mirror::ClassLoader> class_loader, + bool is_static) { + const DexFile& dex_file = *dex_cache->GetDexFile(); + const DexFile::FieldId& field_id = dex_file.GetFieldId(field_idx); + ObjPtr<mirror::Class> klass = dex_cache->GetResolvedType(field_id.class_idx_); + if (klass == nullptr) { + klass = LookupResolvedType(dex_file, field_id.class_idx_, dex_cache, class_loader); + } + if (klass == nullptr) { + // The class has not been resolved yet, so the field is also unresolved. + return nullptr; + } + DCHECK(klass->IsResolved()); + Thread* self = is_static ? Thread::Current() : nullptr; + + // First try to find a field declared directly by `klass` by the field index. + ArtField* resolved_field = is_static + ? mirror::Class::FindStaticField(self, klass, dex_cache, field_idx) + : klass->FindInstanceField(dex_cache, field_idx); + + if (resolved_field == nullptr) { + // If not found in `klass` by field index, search the class hierarchy using the name and type. + const char* name = dex_file.GetFieldName(field_id); + const char* type = dex_file.GetFieldTypeDescriptor(field_id); + resolved_field = is_static + ? mirror::Class::FindStaticField(self, klass, name, type) + : klass->FindInstanceField(name, type); + } + + if (resolved_field != nullptr) { + dex_cache->SetResolvedField(field_idx, resolved_field, image_pointer_size_); + } + return resolved_field; +} + ArtField* ClassLinker::ResolveField(const DexFile& dex_file, uint32_t field_idx, Handle<mirror::DexCache> dex_cache, @@ -8210,9 +8255,8 @@ ArtField* ClassLinker::ResolveFieldJLS(const DexFile& dex_file, return nullptr; } - StringPiece name(dex_file.StringDataByIdx(field_id.name_idx_)); - StringPiece type(dex_file.StringDataByIdx( - dex_file.GetTypeId(field_id.type_idx_).descriptor_idx_)); + StringPiece name(dex_file.GetFieldName(field_id)); + StringPiece type(dex_file.GetFieldTypeDescriptor(field_id)); resolved = mirror::Class::FindField(self, klass, name, type); if (resolved != nullptr) { dex_cache->SetResolvedField(field_idx, resolved, image_pointer_size_); |