diff options
author | 2022-04-14 10:59:53 +0100 | |
---|---|---|
committer | 2022-04-21 11:01:45 +0000 | |
commit | 10137abcd09d51f263f56d64bb0b41fb4f8e5070 (patch) | |
tree | 5ed1f202dcaae81e60e24f32a3579731ba4a86f3 /runtime/class_table-inl.h | |
parent | 86f1b3f30fa72c3f3e712c930c4444c51054b615 (diff) |
Move descriptor hashing to `mirror::Class`.
We may want to reuse the hashing for image classes which are
not closely related with the `ClassTable` where the hashing
was previously.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 181943478
Change-Id: Icf1b51085829509f58e7685dc1e9cf2b0583d107
Diffstat (limited to 'runtime/class_table-inl.h')
-rw-r--r-- | runtime/class_table-inl.h | 39 |
1 files changed, 5 insertions, 34 deletions
diff --git a/runtime/class_table-inl.h b/runtime/class_table-inl.h index ff775d774f..071376cd77 100644 --- a/runtime/class_table-inl.h +++ b/runtime/class_table-inl.h @@ -29,41 +29,12 @@ 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; -} + : TableSlot(klass, klass->DescriptorHash()) {} inline uint32_t ClassTable::ClassDescriptorHash::operator()(const TableSlot& slot) const { // 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>()); + // and retrieval of constant primitive data. See `ReadBarrierOption` and `Class::DescriptorHash()`. + return slot.Read<kWithoutReadBarrier>()->DescriptorHash(); } inline uint32_t ClassTable::ClassDescriptorHash::operator()(const DescriptorHashPair& pair) const { @@ -202,7 +173,7 @@ inline uint32_t ClassTable::TableSlot::Encode(ObjPtr<mirror::Class> klass, uint3 inline ClassTable::TableSlot::TableSlot(ObjPtr<mirror::Class> klass, uint32_t descriptor_hash) : data_(Encode(klass, MaskHash(descriptor_hash))) { - DCHECK_EQ(descriptor_hash, HashDescriptor(klass)); + DCHECK_EQ(descriptor_hash, klass->DescriptorHash()); } template <typename Filter> @@ -213,9 +184,9 @@ inline void ClassTable::RemoveStrongRoots(const Filter& filter) { } inline ObjPtr<mirror::Class> ClassTable::LookupByDescriptor(ObjPtr<mirror::Class> klass) { + uint32_t hash = klass->DescriptorHash(); std::string temp; const char* descriptor = klass->GetDescriptor(&temp); - uint32_t hash = TableSlot::HashDescriptor(klass); return Lookup(descriptor, hash); } |