diff options
author | 2022-04-06 09:30:50 +0000 | |
---|---|---|
committer | 2024-11-05 15:24:05 +0000 | |
commit | 29ec7aef84f4b47d89edee274562b22a177b00b8 (patch) | |
tree | f958dafda289458ce7dac0ad86f7596636ee7ecf /runtime/class_linker.h | |
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/class_linker.h')
-rw-r--r-- | runtime/class_linker.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/runtime/class_linker.h b/runtime/class_linker.h index 35cdfbcdd3..ef8241ad2f 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -232,6 +232,7 @@ class ClassLinker { // Define a new a class based on a ClassDef from a DexFile ObjPtr<mirror::Class> DefineClass(Thread* self, const char* descriptor, + size_t descriptor_length, size_t hash, Handle<mirror::ClassLoader> class_loader, const DexFile& dex_file, @@ -242,7 +243,7 @@ class ClassLinker { // Finds a class by its descriptor, returning null if it isn't wasn't loaded // by the given 'class_loader'. EXPORT ObjPtr<mirror::Class> LookupClass(Thread* self, - const char* descriptor, + std::string_view descriptor, ObjPtr<mirror::ClassLoader> class_loader) REQUIRES(!Locks::classlinker_classes_lock_) REQUIRES_SHARED(Locks::mutator_lock_); @@ -659,7 +660,7 @@ class ClassLinker { // Attempts to insert a class into a class table. Returns null if // the class was inserted, otherwise returns an existing class with // the same descriptor and ClassLoader. - ObjPtr<mirror::Class> InsertClass(const char* descriptor, + ObjPtr<mirror::Class> InsertClass(std::string_view descriptor, ObjPtr<mirror::Class> klass, size_t hash) REQUIRES(!Locks::classlinker_classes_lock_) @@ -1135,6 +1136,7 @@ class ClassLinker { // PathClassLoader are supported). bool FindClassInBaseDexClassLoader(Thread* self, const char* descriptor, + size_t descriptor_length, size_t hash, Handle<mirror::ClassLoader> class_loader, /*out*/ ObjPtr<mirror::Class>* result) @@ -1143,6 +1145,7 @@ class ClassLinker { bool FindClassInSharedLibraries(Thread* self, const char* descriptor, + size_t descriptor_length, size_t hash, Handle<mirror::ClassLoader> class_loader, /*out*/ ObjPtr<mirror::Class>* result) @@ -1151,6 +1154,7 @@ class ClassLinker { bool FindClassInSharedLibrariesHelper(Thread* self, const char* descriptor, + size_t descriptor_length, size_t hash, Handle<mirror::ClassLoader> class_loader, ArtField* field, @@ -1160,6 +1164,7 @@ class ClassLinker { bool FindClassInSharedLibrariesAfter(Thread* self, const char* descriptor, + size_t descriptor_length, size_t hash, Handle<mirror::ClassLoader> class_loader, /*out*/ ObjPtr<mirror::Class>* result) @@ -1176,6 +1181,7 @@ class ClassLinker { bool FindClassInBaseDexClassLoaderClassPath( Thread* self, const char* descriptor, + size_t descriptor_length, size_t hash, Handle<mirror::ClassLoader> class_loader, /*out*/ ObjPtr<mirror::Class>* result) @@ -1188,6 +1194,7 @@ class ClassLinker { // boot class loader has a known lookup. bool FindClassInBootClassLoaderClassPath(Thread* self, const char* descriptor, + size_t descriptor_length, size_t hash, /*out*/ ObjPtr<mirror::Class>* result) REQUIRES_SHARED(Locks::mutator_lock_) @@ -1230,7 +1237,7 @@ class ClassLinker { // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded // by the given 'class_loader'. Uses the provided hash for the descriptor. ObjPtr<mirror::Class> LookupClass(Thread* self, - const char* descriptor, + std::string_view descriptor, size_t hash, ObjPtr<mirror::ClassLoader> class_loader) REQUIRES(!Locks::classlinker_classes_lock_) @@ -1341,7 +1348,7 @@ class ClassLinker { // retire a class, the version of the class in the table is returned and this may differ from // the class passed in. ObjPtr<mirror::Class> EnsureResolved(Thread* self, - const char* descriptor, + std::string_view descriptor, ObjPtr<mirror::Class> klass) WARN_UNUSED REQUIRES_SHARED(Locks::mutator_lock_) |