diff options
author | 2022-03-31 12:39:21 +0000 | |
---|---|---|
committer | 2022-04-04 08:21:08 +0000 | |
commit | 65258db896c8270873f362d95204336d7d1e333d (patch) | |
tree | c3975d3849fe798dfae91343e48d4c06369d8930 /runtime/class_table-inl.h | |
parent | 4ebfcac9d1e32c84ebe583f1d9c9b532a1b1c05d (diff) |
Faster class descriptor hashing.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 181943478
Change-Id: I94612e8229b6d21abd51ade36ed88c1b5db77764
Diffstat (limited to 'runtime/class_table-inl.h')
-rw-r--r-- | runtime/class_table-inl.h | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/runtime/class_table-inl.h b/runtime/class_table-inl.h index 088ad3dbd8..ff775d774f 100644 --- a/runtime/class_table-inl.h +++ b/runtime/class_table-inl.h @@ -28,11 +28,42 @@ namespace art { +inline ClassTable::TableSlot::TableSlot(ObjPtr<mirror::Class> klass) + : TableSlot(klass, HashDescriptor(klass)) {} + +inline uint32_t ClassTable::TableSlot::HashDescriptor(ObjPtr<mirror::Class> klass) { + // No read barriers needed, we're reading a chain of constant references for comparison with null + // and retrieval of constant primitive data. See `ReadBarrierOption` and `Class::GetDescriptor()`. + DCHECK(klass != nullptr); + ObjPtr<mirror::Class> orig_klass = klass; // For debug check. + uint32_t hash = StartModifiedUtf8Hash(); + while (klass->IsArrayClass()) { + klass = klass->GetComponentType<kDefaultVerifyFlags, kWithoutReadBarrier>(); + hash = UpdateModifiedUtf8Hash(hash, '['); + } + if (UNLIKELY(klass->IsProxyClass())) { + hash = UpdateHashForProxyClass(hash, klass); + } else if (klass->IsPrimitive()) { + hash = UpdateModifiedUtf8Hash(hash, Primitive::Descriptor(klass->GetPrimitiveType())[0]); + } else { + const DexFile& dex_file = klass->GetDexFile(); + const dex::TypeId& type_id = dex_file.GetTypeId(klass->GetDexTypeIndex()); + std::string_view descriptor = dex_file.GetTypeDescriptorView(type_id); + hash = UpdateModifiedUtf8Hash(hash, descriptor); + } + + if (kIsDebugBuild) { + std::string temp; + CHECK_EQ(hash, ComputeModifiedUtf8Hash(orig_klass->GetDescriptor(&temp))); + } + + return hash; +} + inline uint32_t ClassTable::ClassDescriptorHash::operator()(const TableSlot& slot) const { - std::string temp; - // No read barrier needed, we're reading a chain of constant references for comparison - // with null and retrieval of constant primitive data. See ReadBarrierOption. - return ComputeModifiedUtf8Hash(slot.Read<kWithoutReadBarrier>()->GetDescriptor(&temp)); + // No read barriers needed, we're reading a chain of constant references for comparison with null + // and retrieval of constant primitive data. See `ReadBarrierOption` and `Class::GetDescriptor()`. + return TableSlot::HashDescriptor(slot.Read<kWithoutReadBarrier>()); } inline uint32_t ClassTable::ClassDescriptorHash::operator()(const DescriptorHashPair& pair) const { |