diff options
author | 2022-04-06 09:30:50 +0000 | |
---|---|---|
committer | 2024-11-05 15:24:05 +0000 | |
commit | 29ec7aef84f4b47d89edee274562b22a177b00b8 (patch) | |
tree | f958dafda289458ce7dac0ad86f7596636ee7ecf /runtime/native/java_lang_VMClassLoader.cc | |
parent | 96dc77238e2b5a962911a6da06d5e1b869dc92f8 (diff) |
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
Diffstat (limited to 'runtime/native/java_lang_VMClassLoader.cc')
-rw-r--r-- | runtime/native/java_lang_VMClassLoader.cc | 7 |
1 files changed, 5 insertions, 2 deletions
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<mirror::Class> FindClassInPathClassLoader(ClassLinker* cl, Thread* self, const char* descriptor, + size_t descriptor_length, size_t hash, Handle<mirror::ClassLoader> class_loader) REQUIRES_SHARED(Locks::mutator_lock_) { ObjPtr<mirror::Class> 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<mirror::Class> 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) { |