From 65258db896c8270873f362d95204336d7d1e333d Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Thu, 31 Mar 2022 12:39:21 +0000 Subject: Faster class descriptor hashing. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 181943478 Change-Id: I94612e8229b6d21abd51ade36ed88c1b5db77764 --- runtime/class_table.cc | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'runtime/class_table.cc') diff --git a/runtime/class_table.cc b/runtime/class_table.cc index bd5d38f80d..acfbcb09a3 100644 --- a/runtime/class_table.cc +++ b/runtime/class_table.cc @@ -18,10 +18,39 @@ #include "base/stl_util.h" #include "mirror/class-inl.h" +#include "mirror/string-inl.h" #include "oat_file.h" namespace art { +uint32_t ClassTable::TableSlot::UpdateHashForProxyClass( + uint32_t hash, ObjPtr proxy_class) { + // No read barrier needed, the `name` field is constant for proxy classes and + // the contents of the String are also constant. See ReadBarrierOption. + // Note: The `proxy_class` can be a from-space reference. + DCHECK(proxy_class->IsProxyClass()); + ObjPtr name = proxy_class->GetName(); + DCHECK(name != nullptr); + // Update hash for characters we would get from `DotToDescriptor(name->ToModifiedUtf8())`. + DCHECK_NE(name->GetLength(), 0); + DCHECK_NE(name->CharAt(0), '['); + hash = UpdateModifiedUtf8Hash(hash, 'L'); + if (name->IsCompressed()) { + std::string_view dot_name(reinterpret_cast(name->GetValueCompressed()), + name->GetLength()); + for (char c : dot_name) { + hash = UpdateModifiedUtf8Hash(hash, (c != '.') ? c : '/'); + } + } else { + std::string dot_name = name->ToModifiedUtf8(); + for (char c : dot_name) { + hash = UpdateModifiedUtf8Hash(hash, (c != '.') ? c : '/'); + } + } + hash = UpdateModifiedUtf8Hash(hash, ';'); + return hash; +} + ClassTable::ClassTable() : lock_("Class loader classes", kClassLoaderClassesLock) { Runtime* const runtime = Runtime::Current(); classes_.push_back(ClassSet(runtime->GetHashTableMinLoadFactor(), @@ -189,12 +218,4 @@ void ClassTable::ClearStrongRoots() { strong_roots_.clear(); } -ClassTable::TableSlot::TableSlot(ObjPtr klass) - : TableSlot(klass, HashDescriptor(klass)) {} - -uint32_t ClassTable::TableSlot::HashDescriptor(ObjPtr klass) { - std::string temp; - return ComputeModifiedUtf8Hash(klass->GetDescriptor(&temp)); -} - } // namespace art -- cgit v1.2.3-59-g8ed1b