diff options
-rw-r--r-- | libdexfile/dex/dex_file-inl.h | 13 | ||||
-rw-r--r-- | libdexfile/dex/dex_file.h | 1 | ||||
-rw-r--r-- | runtime/art_method-inl.h | 31 | ||||
-rw-r--r-- | runtime/art_method.cc | 23 | ||||
-rw-r--r-- | runtime/art_method.h | 5 | ||||
-rw-r--r-- | runtime/mirror/class.cc | 8 |
6 files changed, 58 insertions, 23 deletions
diff --git a/libdexfile/dex/dex_file-inl.h b/libdexfile/dex/dex_file-inl.h index b777ef7ac1..61c45934e8 100644 --- a/libdexfile/dex/dex_file-inl.h +++ b/libdexfile/dex/dex_file-inl.h @@ -32,6 +32,13 @@ namespace art { +inline std::string_view StringViewFromUtf16Length(const char* utf8_data, size_t utf16_length) { + size_t utf8_length = LIKELY(utf8_data[utf16_length] == 0) // Is ASCII? + ? utf16_length + : utf16_length + strlen(utf8_data + utf16_length); + return std::string_view(utf8_data, utf8_length); +} + inline int32_t DexFile::GetStringLength(const dex::StringId& string_id) const { const uint8_t* ptr = DataBegin() + string_id.string_data_off_; return DecodeUnsignedLeb128(&ptr); @@ -65,6 +72,12 @@ inline const char* DexFile::StringDataByIdx(dex::StringIndex idx) const { return StringDataAndUtf16LengthByIdx(idx, &unicode_length); } +inline std::string_view DexFile::StringViewByIdx(dex::StringIndex idx) const { + uint32_t unicode_length; + const char* data = StringDataAndUtf16LengthByIdx(idx, &unicode_length); + return data != nullptr ? StringViewFromUtf16Length(data, unicode_length) : std::string_view(""); +} + inline const char* DexFile::StringByTypeIdx(dex::TypeIndex idx, uint32_t* unicode_length) const { if (!idx.IsValid()) { return nullptr; diff --git a/libdexfile/dex/dex_file.h b/libdexfile/dex/dex_file.h index 5cfbc1f024..ca95e0e618 100644 --- a/libdexfile/dex/dex_file.h +++ b/libdexfile/dex/dex_file.h @@ -265,6 +265,7 @@ class DexFile { const char* StringDataAndUtf16LengthByIdx(dex::StringIndex idx, uint32_t* utf16_length) const; const char* StringDataByIdx(dex::StringIndex idx) const; + std::string_view StringViewByIdx(dex::StringIndex idx) const; // Looks up a string id for a given modified utf8 string. const dex::StringId* FindStringId(const char* string) const; diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h index 61c261c52c..6bbccb8c4d 100644 --- a/runtime/art_method-inl.h +++ b/runtime/art_method-inl.h @@ -200,26 +200,19 @@ inline const char* ArtMethod::GetName() { const DexFile* dex_file = GetDexFile(); return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx)); } - Runtime* const runtime = Runtime::Current(); - if (this == runtime->GetResolutionMethod()) { - return "<runtime internal resolution method>"; - } else if (this == runtime->GetImtConflictMethod()) { - return "<runtime internal imt conflict method>"; - } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveAllCalleeSaves)) { - return "<runtime internal callee-save all registers method>"; - } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsOnly)) { - return "<runtime internal callee-save reference registers method>"; - } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs)) { - return "<runtime internal callee-save reference and argument registers method>"; - } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverything)) { - return "<runtime internal save-every-register method>"; - } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverythingForClinit)) { - return "<runtime internal save-every-register method for clinit>"; - } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverythingForSuspendCheck)) { - return "<runtime internal save-every-register method for suspend check>"; - } else { - return "<unknown runtime internal method>"; + return GetRuntimeMethodName(); +} + +inline std::string_view ArtMethod::GetNameView() { + uint32_t dex_method_idx = GetDexMethodIndex(); + if (LIKELY(dex_method_idx != dex::kDexNoIndex)) { + DCHECK(!IsProxyMethod()); + const DexFile* dex_file = GetDexFile(); + uint32_t length = 0; + const char* name = dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx), &length); + return StringViewFromUtf16Length(name, length); } + return GetRuntimeMethodName(); } inline ObjPtr<mirror::String> ArtMethod::ResolveNameString() { diff --git a/runtime/art_method.cc b/runtime/art_method.cc index 18fcfb2eab..0890da8c83 100644 --- a/runtime/art_method.cc +++ b/runtime/art_method.cc @@ -839,6 +839,29 @@ std::string ArtMethod::JniLongName() { return long_name; } +const char* ArtMethod::GetRuntimeMethodName() { + Runtime* const runtime = Runtime::Current(); + if (this == runtime->GetResolutionMethod()) { + return "<runtime internal resolution method>"; + } else if (this == runtime->GetImtConflictMethod()) { + return "<runtime internal imt conflict method>"; + } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveAllCalleeSaves)) { + return "<runtime internal callee-save all registers method>"; + } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsOnly)) { + return "<runtime internal callee-save reference registers method>"; + } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs)) { + return "<runtime internal callee-save reference and argument registers method>"; + } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverything)) { + return "<runtime internal save-every-register method>"; + } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverythingForClinit)) { + return "<runtime internal save-every-register method for clinit>"; + } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverythingForSuspendCheck)) { + return "<runtime internal save-every-register method for suspend check>"; + } else { + return "<unknown runtime internal method>"; + } +} + // AssertSharedHeld doesn't work in GetAccessFlags, so use a NO_THREAD_SAFETY_ANALYSIS helper. // TODO: Figure out why ASSERT_SHARED_CAPABILITY doesn't work. template <ReadBarrierOption kReadBarrierOption> diff --git a/runtime/art_method.h b/runtime/art_method.h index 23c1fe9493..5dc43a31e1 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -586,6 +586,8 @@ class ArtMethod final { ALWAYS_INLINE const char* GetName() REQUIRES_SHARED(Locks::mutator_lock_); + ALWAYS_INLINE std::string_view GetNameView() REQUIRES_SHARED(Locks::mutator_lock_); + ObjPtr<mirror::String> ResolveNameString() REQUIRES_SHARED(Locks::mutator_lock_); const dex::CodeItem* GetCodeItem() REQUIRES_SHARED(Locks::mutator_lock_); @@ -855,6 +857,9 @@ class ArtMethod final { } while (!access_flags_.compare_exchange_weak(old_access_flags, new_access_flags)); } + // Used by GetName and GetNameView to share common code. + const char* GetRuntimeMethodName() REQUIRES_SHARED(Locks::mutator_lock_); + DISALLOW_COPY_AND_ASSIGN(ArtMethod); // Need to use CopyFrom to deal with 32 vs 64 bits. }; diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc index 5025c0295c..ec07a50b0e 100644 --- a/runtime/mirror/class.cc +++ b/runtime/mirror/class.cc @@ -446,7 +446,7 @@ static inline ArtMethod* FindInterfaceMethodWithSignature(ObjPtr<Class> klass, // Search declared methods, both direct and virtual. // (This lookup is used also for invoke-static on interface classes.) for (ArtMethod& method : klass->GetDeclaredMethodsSlice(pointer_size)) { - if (method.GetName() == name && method.GetSignature() == signature) { + if (method.GetNameView() == name && method.GetSignature() == signature) { return &method; } } @@ -458,7 +458,7 @@ static inline ArtMethod* FindInterfaceMethodWithSignature(ObjPtr<Class> klass, for (int32_t i = 0, iftable_count = iftable->Count(); i < iftable_count; ++i) { ObjPtr<Class> iface = iftable->GetInterface(i); for (ArtMethod& method : iface->GetVirtualMethodsSlice(pointer_size)) { - if (method.GetName() == name && method.GetSignature() == signature) { + if (method.GetNameView() == name && method.GetSignature() == signature) { return &method; } } @@ -470,7 +470,7 @@ static inline ArtMethod* FindInterfaceMethodWithSignature(ObjPtr<Class> klass, DCHECK(object_class->IsObjectClass()); for (ArtMethod& method : object_class->GetDeclaredMethodsSlice(pointer_size)) { if (method.IsPublic() && !method.IsStatic() && - method.GetName() == name && method.GetSignature() == signature) { + method.GetNameView() == name && method.GetSignature() == signature) { return &method; } } @@ -496,7 +496,7 @@ ArtMethod* Class::FindInterfaceMethod(ObjPtr<DexCache> dex_cache, // We always search by name and signature, ignoring the type index in the MethodId. const DexFile& dex_file = *dex_cache->GetDexFile(); const dex::MethodId& method_id = dex_file.GetMethodId(dex_method_idx); - std::string_view name = dex_file.StringDataByIdx(method_id.name_idx_); + std::string_view name = dex_file.StringViewByIdx(method_id.name_idx_); const Signature signature = dex_file.GetMethodSignature(method_id); return FindInterfaceMethod(name, signature, pointer_size); } |