From 29ec7aef84f4b47d89edee274562b22a177b00b8 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 6 Apr 2022 09:30:50 +0000 Subject: Use `std::string_view` for `ClassTable` operations. Use `std::string_view` instead of `const char*` descriptor. This uses faster `memcmp` instead of the slower`strcmp` for descriptor comparison. Note that the `ScopedTrace` passes `const char*` across the `libartpalette` boundary, so we cannot easily replace the `const char* descriptor` with `std::string_view descriptor` in certain `ClassLinker` functions because we actually need to pass a null-terminated string and the `string_view` API does not technically guarantee null-terminated data. Therefore we resort to explicitly passing around the descriptor and its length as separate arguments. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 181943478 Bug: 338123769 Change-Id: Ie3fa251390acc582c54b4686d18696eb89b32361 --- runtime/native/java_lang_VMClassLoader.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'runtime/native/java_lang_VMClassLoader.cc') diff --git a/runtime/native/java_lang_VMClassLoader.cc b/runtime/native/java_lang_VMClassLoader.cc index ba1fde00d3..a735765bdd 100644 --- a/runtime/native/java_lang_VMClassLoader.cc +++ b/runtime/native/java_lang_VMClassLoader.cc @@ -56,11 +56,13 @@ class VMClassLoader { static ObjPtr FindClassInPathClassLoader(ClassLinker* cl, Thread* self, const char* descriptor, + size_t descriptor_length, size_t hash, Handle class_loader) REQUIRES_SHARED(Locks::mutator_lock_) { ObjPtr result; - if (cl->FindClassInBaseDexClassLoader(self, descriptor, hash, class_loader, &result)) { + if (cl->FindClassInBaseDexClassLoader( + self, descriptor, descriptor_length, hash, class_loader, &result)) { DCHECK(!self->IsExceptionPending()); return result; } @@ -83,7 +85,7 @@ static jclass VMClassLoader_findLoadedClass(JNIEnv* env, jclass, jobject javaLoa // Compute hash once. std::string descriptor(DotToDescriptor(name.c_str())); - const size_t descriptor_hash = ComputeModifiedUtf8Hash(descriptor.c_str()); + const size_t descriptor_hash = ComputeModifiedUtf8Hash(descriptor); ObjPtr c = VMClassLoader::LookupClass(cl, soa.Self(), @@ -115,6 +117,7 @@ static jclass VMClassLoader_findLoadedClass(JNIEnv* env, jclass, jobject javaLoa c = VMClassLoader::FindClassInPathClassLoader(cl, soa.Self(), descriptor.c_str(), + descriptor.length(), descriptor_hash, hs.NewHandle(loader)); if (c != nullptr) { -- cgit v1.2.3-59-g8ed1b