summaryrefslogtreecommitdiff
path: root/runtime/class_table.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2022-03-31 12:39:21 +0000
committer Vladimir Marko <vmarko@google.com> 2022-04-04 08:21:08 +0000
commit65258db896c8270873f362d95204336d7d1e333d (patch)
treec3975d3849fe798dfae91343e48d4c06369d8930 /runtime/class_table.cc
parent4ebfcac9d1e32c84ebe583f1d9c9b532a1b1c05d (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.cc')
-rw-r--r--runtime/class_table.cc37
1 files changed, 29 insertions, 8 deletions
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<mirror::Class> 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<mirror::String> name = proxy_class->GetName<kVerifyNone, kWithoutReadBarrier>();
+ 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<const char*>(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<mirror::Class> klass)
- : TableSlot(klass, HashDescriptor(klass)) {}
-
-uint32_t ClassTable::TableSlot::HashDescriptor(ObjPtr<mirror::Class> klass) {
- std::string temp;
- return ComputeModifiedUtf8Hash(klass->GetDescriptor(&temp));
-}
-
} // namespace art