diff options
author | 2024-05-13 12:27:42 +0000 | |
---|---|---|
committer | 2024-05-14 09:33:18 +0000 | |
commit | 7143edc113406fcd76ea677da88d8dfd6afff6c9 (patch) | |
tree | add59554ea62f40735d425024a58bd36ff950bb4 | |
parent | 678691f70aab81905a96734b51dab99c0439635a (diff) |
Add `ArtField::GetDeclaringClassDescriptor{,View}()`.
And clean up related `ArtField` and `ArtMethod` functions
for dex file descriptor and name access.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 338123769
Change-Id: I3bf9c3b6135ea8e6b018ec41c93c847446918169
-rw-r--r-- | libdexfile/dex/dex_file-inl.h | 67 | ||||
-rw-r--r-- | libdexfile/dex/dex_file.h | 21 | ||||
-rw-r--r-- | openjdkjvmti/ti_redefine.cc | 3 | ||||
-rw-r--r-- | runtime/art_field-inl.h | 53 | ||||
-rw-r--r-- | runtime/art_field.cc | 1 | ||||
-rw-r--r-- | runtime/art_field.h | 5 | ||||
-rw-r--r-- | runtime/art_method-inl.h | 23 | ||||
-rw-r--r-- | runtime/art_method.cc | 6 | ||||
-rw-r--r-- | runtime/art_method.h | 2 | ||||
-rw-r--r-- | runtime/common_dex_operations.h | 4 | ||||
-rw-r--r-- | runtime/hidden_api.cc | 9 | ||||
-rw-r--r-- | runtime/jni/java_vm_ext.cc | 2 | ||||
-rw-r--r-- | runtime/oat/aot_class_linker.cc | 6 | ||||
-rw-r--r-- | runtime/oat/aot_class_linker.h | 6 | ||||
-rw-r--r-- | runtime/proxy_test.cc | 2 | ||||
-rw-r--r-- | runtime/sdk_checker.cc | 21 |
16 files changed, 161 insertions, 70 deletions
diff --git a/libdexfile/dex/dex_file-inl.h b/libdexfile/dex/dex_file-inl.h index dce8a85217..ad6c8c31ba 100644 --- a/libdexfile/dex/dex_file-inl.h +++ b/libdexfile/dex/dex_file-inl.h @@ -115,28 +115,71 @@ inline std::string_view DexFile::GetTypeDescriptorView(dex::TypeIndex type_idx) return GetTypeDescriptorView(GetTypeId(type_idx)); } +inline const char* DexFile::GetFieldDeclaringClassDescriptor(const dex::FieldId& field_id) const { + return GetTypeDescriptor(field_id.class_idx_); +} + +inline const char* DexFile::GetFieldDeclaringClassDescriptor(uint32_t field_idx) const { + return GetFieldDeclaringClassDescriptor(GetFieldId(field_idx)); +} + +inline std::string_view DexFile::GetFieldDeclaringClassDescriptorView( + const dex::FieldId& field_id) const { + return GetTypeDescriptorView(field_id.class_idx_); +} + +inline std::string_view DexFile::GetFieldDeclaringClassDescriptorView(uint32_t field_idx) const { + return GetFieldDeclaringClassDescriptorView(GetFieldId(field_idx)); +} + inline const char* DexFile::GetFieldTypeDescriptor(const dex::FieldId& field_id) const { - const dex::TypeId& type_id = GetTypeId(field_id.type_idx_); - return GetTypeDescriptor(type_id); + return GetTypeDescriptor(field_id.type_idx_); +} + +inline const char* DexFile::GetFieldTypeDescriptor(uint32_t field_idx) const { + return GetFieldTypeDescriptor(GetFieldId(field_idx)); } inline std::string_view DexFile::GetFieldTypeDescriptorView(const dex::FieldId& field_id) const { - const dex::TypeId& type_id = GetTypeId(field_id.type_idx_); - return GetTypeDescriptorView(type_id); + return GetTypeDescriptorView(field_id.type_idx_); +} + +inline std::string_view DexFile::GetFieldTypeDescriptorView(uint32_t field_idx) const { + return GetFieldTypeDescriptorView(GetFieldId(field_idx)); } inline const char* DexFile::GetFieldName(const dex::FieldId& field_id) const { return GetStringData(field_id.name_idx_); } +inline const char* DexFile::GetFieldName(uint32_t field_idx) const { + return GetFieldName(GetFieldId(field_idx)); +} + inline std::string_view DexFile::GetFieldNameView(const dex::FieldId& field_id) const { return GetStringView(field_id.name_idx_); } -inline const char* DexFile::GetMethodDeclaringClassDescriptor(const dex::MethodId& method_id) - const { - const dex::TypeId& type_id = GetTypeId(method_id.class_idx_); - return GetTypeDescriptor(type_id); +inline std::string_view DexFile::GetFieldNameView(uint32_t field_idx) const { + return GetFieldNameView(GetFieldId(field_idx)); +} + +inline const char* DexFile::GetMethodDeclaringClassDescriptor( + const dex::MethodId& method_id) const { + return GetTypeDescriptor(method_id.class_idx_); +} + +inline const char* DexFile::GetMethodDeclaringClassDescriptor(uint32_t method_idx) const { + return GetMethodDeclaringClassDescriptor(GetMethodId(method_idx)); +} + +inline std::string_view DexFile::GetMethodDeclaringClassDescriptorView( + const dex::MethodId& method_id) const { + return GetTypeDescriptorView(method_id.class_idx_); +} + +inline std::string_view DexFile::GetMethodDeclaringClassDescriptorView(uint32_t method_idx) const { + return GetMethodDeclaringClassDescriptorView(GetMethodId(method_idx)); } inline const Signature DexFile::GetMethodSignature(const dex::MethodId& method_id) const { @@ -156,8 +199,8 @@ inline const char* DexFile::GetMethodName(const dex::MethodId& method_id, uint32 return GetStringDataAndUtf16Length(method_id.name_idx_, utf_length); } -inline const char* DexFile::GetMethodName(uint32_t idx) const { - return GetStringData(GetMethodId(idx).name_idx_); +inline const char* DexFile::GetMethodName(uint32_t method_idx) const { + return GetStringData(GetMethodId(method_idx).name_idx_); } inline const char* DexFile::GetMethodName(uint32_t idx, uint32_t* utf_length) const { @@ -170,8 +213,8 @@ inline std::string_view DexFile::GetMethodNameView(const dex::MethodId& method_i } ALWAYS_INLINE -inline std::string_view DexFile::GetMethodNameView(uint32_t idx) const { - return GetMethodNameView(GetMethodId(idx)); +inline std::string_view DexFile::GetMethodNameView(uint32_t method_idx) const { + return GetMethodNameView(GetMethodId(method_idx)); } inline const char* DexFile::GetMethodShorty(uint32_t idx) const { diff --git a/libdexfile/dex/dex_file.h b/libdexfile/dex/dex_file.h index 1069da12c1..b79c72079d 100644 --- a/libdexfile/dex/dex_file.h +++ b/libdexfile/dex/dex_file.h @@ -433,18 +433,22 @@ class DexFile { virtual uint32_t GetCodeItemSize(const dex::CodeItem& disk_code_item) const = 0; // Returns the declaring class descriptor string of a field id. - const char* GetFieldDeclaringClassDescriptor(const dex::FieldId& field_id) const { - const dex::TypeId& type_id = GetTypeId(field_id.class_idx_); - return GetTypeDescriptor(type_id); - } + const char* GetFieldDeclaringClassDescriptor(const dex::FieldId& field_id) const; + const char* GetFieldDeclaringClassDescriptor(uint32_t field_idx) const; + std::string_view GetFieldDeclaringClassDescriptorView(const dex::FieldId& field_id) const; + std::string_view GetFieldDeclaringClassDescriptorView(uint32_t field_idx) const; // Returns the class descriptor string of a field id. const char* GetFieldTypeDescriptor(const dex::FieldId& field_id) const; + const char* GetFieldTypeDescriptor(uint32_t field_idx) const; std::string_view GetFieldTypeDescriptorView(const dex::FieldId& field_id) const; + std::string_view GetFieldTypeDescriptorView(uint32_t field_idx) const; // Returns the name of a field id. const char* GetFieldName(const dex::FieldId& field_id) const; + const char* GetFieldName(uint32_t field_idx) const; std::string_view GetFieldNameView(const dex::FieldId& field_id) const; + std::string_view GetFieldNameView(uint32_t field_idx) const; // Returns the number of method identifiers in the .dex file. size_t NumMethodIds() const { @@ -475,6 +479,9 @@ class DexFile { // Returns the declaring class descriptor string of a method id. const char* GetMethodDeclaringClassDescriptor(const dex::MethodId& method_id) const; + const char* GetMethodDeclaringClassDescriptor(uint32_t method_idx) const; + std::string_view GetMethodDeclaringClassDescriptorView(const dex::MethodId& method_id) const; + std::string_view GetMethodDeclaringClassDescriptorView(uint32_t method_idx) const; // Returns the prototype of a method id. const dex::ProtoId& GetMethodPrototype(const dex::MethodId& method_id) const { @@ -490,10 +497,10 @@ class DexFile { // Returns the name of a method id. const char* GetMethodName(const dex::MethodId& method_id) const; const char* GetMethodName(const dex::MethodId& method_id, uint32_t* utf_length) const; - const char* GetMethodName(uint32_t idx) const; - const char* GetMethodName(uint32_t idx, uint32_t* utf_length) const; + const char* GetMethodName(uint32_t method_idx) const; + const char* GetMethodName(uint32_t method_idx, uint32_t* utf_length) const; std::string_view GetMethodNameView(const dex::MethodId& method_id) const; - std::string_view GetMethodNameView(uint32_t idx) const; + std::string_view GetMethodNameView(uint32_t method_idx) const; // Returns the shorty of a method by its index. const char* GetMethodShorty(uint32_t idx) const; diff --git a/openjdkjvmti/ti_redefine.cc b/openjdkjvmti/ti_redefine.cc index 60e8193f5d..a16a560424 100644 --- a/openjdkjvmti/ti_redefine.cc +++ b/openjdkjvmti/ti_redefine.cc @@ -2586,9 +2586,8 @@ void Redefiner::ClassRedefinition::UpdateFields(art::ObjPtr<art::mirror::Class> // TODO The IFields & SFields pointers should be combined like the methods_ arrays were. for (auto fields_iter : {mclass->GetIFields(), mclass->GetSFields()}) { for (art::ArtField& field : fields_iter) { - std::string declaring_class_name; const art::dex::TypeId* new_declaring_id = - dex_file_->FindTypeId(field.GetDeclaringClass()->GetDescriptor(&declaring_class_name)); + dex_file_->FindTypeId(field.GetDeclaringClassDescriptor()); const art::dex::StringId* new_name_id = dex_file_->FindStringId(field.GetName()); const art::dex::TypeId* new_type_id = dex_file_->FindTypeId(field.GetTypeDescriptor()); CHECK(new_name_id != nullptr && new_type_id != nullptr && new_declaring_id != nullptr); diff --git a/runtime/art_field-inl.h b/runtime/art_field-inl.h index 7137658387..cbe38db80e 100644 --- a/runtime/art_field-inl.h +++ b/runtime/art_field-inl.h @@ -318,18 +318,27 @@ inline void ArtField::SetObject(ObjPtr<mirror::Object> object, ObjPtr<mirror::Ob SetObj<kTransactionActive>(object, l); } -inline const char* ArtField::GetName() REQUIRES_SHARED(Locks::mutator_lock_) { +inline const char* ArtField::GetName() { uint32_t field_index = GetDexFieldIndex(); if (UNLIKELY(IsProxyField())) { DCHECK(IsStatic()); DCHECK_LT(field_index, 2U); return field_index == 0 ? "interfaces" : "throws"; } - const DexFile* dex_file = GetDexFile(); - return dex_file->GetFieldName(dex_file->GetFieldId(field_index)); + return GetDexFile()->GetFieldName(field_index); } -inline const char* ArtField::GetTypeDescriptor() REQUIRES_SHARED(Locks::mutator_lock_) { +inline std::string_view ArtField::GetNameView() { + uint32_t field_index = GetDexFieldIndex(); + if (UNLIKELY(IsProxyField())) { + DCHECK(IsStatic()); + DCHECK_LT(field_index, 2U); + return field_index == 0 ? "interfaces" : "throws"; + } + return GetDexFile()->GetFieldNameView(field_index); +} + +inline const char* ArtField::GetTypeDescriptor() { uint32_t field_index = GetDexFieldIndex(); if (UNLIKELY(IsProxyField())) { DCHECK(IsStatic()); @@ -337,17 +346,25 @@ inline const char* ArtField::GetTypeDescriptor() REQUIRES_SHARED(Locks::mutator_ // 0 == Class[] interfaces; 1 == Class[][] throws; return field_index == 0 ? "[Ljava/lang/Class;" : "[[Ljava/lang/Class;"; } - const DexFile* dex_file = GetDexFile(); - const dex::FieldId& field_id = dex_file->GetFieldId(field_index); - return dex_file->GetFieldTypeDescriptor(field_id); + return GetDexFile()->GetFieldTypeDescriptor(field_index); } -inline Primitive::Type ArtField::GetTypeAsPrimitiveType() - REQUIRES_SHARED(Locks::mutator_lock_) { +inline std::string_view ArtField::GetTypeDescriptorView() { + uint32_t field_index = GetDexFieldIndex(); + if (UNLIKELY(IsProxyField())) { + DCHECK(IsStatic()); + DCHECK_LT(field_index, 2U); + // 0 == Class[] interfaces; 1 == Class[][] throws; + return field_index == 0 ? "[Ljava/lang/Class;" : "[[Ljava/lang/Class;"; + } + return GetDexFile()->GetFieldTypeDescriptorView(field_index); +} + +inline Primitive::Type ArtField::GetTypeAsPrimitiveType() { return Primitive::GetType(GetTypeDescriptor()[0]); } -inline bool ArtField::IsPrimitiveType() REQUIRES_SHARED(Locks::mutator_lock_) { +inline bool ArtField::IsPrimitiveType() { return GetTypeAsPrimitiveType() != Primitive::kPrimNot; } @@ -372,20 +389,30 @@ inline ObjPtr<mirror::Class> ArtField::ResolveType() { return type; } -inline size_t ArtField::FieldSize() REQUIRES_SHARED(Locks::mutator_lock_) { +inline size_t ArtField::FieldSize() { return Primitive::ComponentSize(GetTypeAsPrimitiveType()); } template <ReadBarrierOption kReadBarrierOption> -inline ObjPtr<mirror::DexCache> ArtField::GetDexCache() REQUIRES_SHARED(Locks::mutator_lock_) { +inline ObjPtr<mirror::DexCache> ArtField::GetDexCache() { ObjPtr<mirror::Class> klass = GetDeclaringClass<kReadBarrierOption>(); return klass->GetDexCache<kDefaultVerifyFlags, kReadBarrierOption>(); } -inline const DexFile* ArtField::GetDexFile() REQUIRES_SHARED(Locks::mutator_lock_) { +inline const DexFile* ArtField::GetDexFile() { return GetDexCache<kWithoutReadBarrier>()->GetDexFile(); } +inline const char* ArtField::GetDeclaringClassDescriptor() { + DCHECK(!IsProxyField()); + return GetDexFile()->GetFieldDeclaringClassDescriptor(GetDexFieldIndex()); +} + +inline std::string_view ArtField::GetDeclaringClassDescriptorView() { + DCHECK(!IsProxyField()); + return GetDexFile()->GetFieldDeclaringClassDescriptorView(GetDexFieldIndex()); +} + inline ObjPtr<mirror::String> ArtField::ResolveNameString() { uint32_t dex_field_index = GetDexFieldIndex(); CHECK_NE(dex_field_index, dex::kDexNoIndex); diff --git a/runtime/art_field.cc b/runtime/art_field.cc index dcfd7582fe..70d6d2ba94 100644 --- a/runtime/art_field.cc +++ b/runtime/art_field.cc @@ -60,6 +60,7 @@ std::string ArtField::PrettyField(bool with_type) { result += PrettyDescriptor(GetTypeDescriptor()); result += ' '; } + // Note: `GetDeclaringClassDescriptor()` does not support proxy classes. std::string temp; result += PrettyDescriptor(GetDeclaringClass()->GetDescriptor(&temp)); result += '.'; diff --git a/runtime/art_field.h b/runtime/art_field.h index 49899dafd6..141de5650d 100644 --- a/runtime/art_field.h +++ b/runtime/art_field.h @@ -214,11 +214,13 @@ class EXPORT ArtField final { REQUIRES_SHARED(Locks::mutator_lock_); const char* GetName() REQUIRES_SHARED(Locks::mutator_lock_); + std::string_view GetNameView() REQUIRES_SHARED(Locks::mutator_lock_); // Resolves / returns the name from the dex cache. ObjPtr<mirror::String> ResolveNameString() REQUIRES_SHARED(Locks::mutator_lock_); const char* GetTypeDescriptor() REQUIRES_SHARED(Locks::mutator_lock_); + std::string_view GetTypeDescriptorView() REQUIRES_SHARED(Locks::mutator_lock_); Primitive::Type GetTypeAsPrimitiveType() REQUIRES_SHARED(Locks::mutator_lock_); @@ -234,6 +236,9 @@ class EXPORT ArtField final { const DexFile* GetDexFile() REQUIRES_SHARED(Locks::mutator_lock_); + const char* GetDeclaringClassDescriptor() REQUIRES_SHARED(Locks::mutator_lock_); + std::string_view GetDeclaringClassDescriptorView() REQUIRES_SHARED(Locks::mutator_lock_); + GcRoot<mirror::Class>& DeclaringClassRoot() { return declaring_class_; } diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h index 2c6a07126b..b2711d968a 100644 --- a/runtime/art_method-inl.h +++ b/runtime/art_method-inl.h @@ -381,13 +381,15 @@ inline const DexFile* ArtMethod::GetDexFile() { } inline const char* ArtMethod::GetDeclaringClassDescriptor() { - uint32_t dex_method_idx = GetDexMethodIndex(); - if (UNLIKELY(dex_method_idx == dex::kDexNoIndex)) { - return "<runtime method>"; - } + DCHECK(!IsRuntimeMethod()); DCHECK(!IsProxyMethod()); - const DexFile* dex_file = GetDexFile(); - return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx)); + return GetDexFile()->GetMethodDeclaringClassDescriptor(GetDexMethodIndex()); +} + +inline std::string_view ArtMethod::GetDeclaringClassDescriptorView() { + DCHECK(!IsRuntimeMethod()); + DCHECK(!IsProxyMethod()); + return GetDexFile()->GetMethodDeclaringClassDescriptorView(GetDexMethodIndex()); } inline const char* ArtMethod::GetShorty() { @@ -515,9 +517,11 @@ inline size_t ArtMethod::GetNumberOfParameters() { } inline const char* ArtMethod::GetReturnTypeDescriptor() { - DCHECK(!IsProxyMethod()); - const DexFile* dex_file = GetDexFile(); - return dex_file->GetTypeDescriptor(dex_file->GetTypeId(GetReturnTypeIndex())); + return GetDexFile()->GetTypeDescriptor(GetReturnTypeIndex()); +} + +inline std::string_view ArtMethod::GetReturnTypeDescriptorView() { + return GetDexFile()->GetTypeDescriptorView(GetReturnTypeIndex()); } inline Primitive::Type ArtMethod::GetReturnTypePrimitive() { @@ -573,6 +577,7 @@ inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(PointerSize pointer_size) } inline dex::TypeIndex ArtMethod::GetReturnTypeIndex() { + DCHECK(!IsRuntimeMethod()); DCHECK(!IsProxyMethod()); const DexFile* dex_file = GetDexFile(); const dex::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); diff --git a/runtime/art_method.cc b/runtime/art_method.cc index c8b16990b2..2b59f38ed6 100644 --- a/runtime/art_method.cc +++ b/runtime/art_method.cc @@ -487,9 +487,8 @@ static const OatFile::OatMethod FindOatMethodFromDexFileFor(ArtMethod* method, b const DexFile* dex_file = method->GetDexFile(); // recreate the class_def_index from the descriptor. - std::string descriptor_storage; const dex::TypeId* declaring_class_type_id = - dex_file->FindTypeId(method->GetDeclaringClass()->GetDescriptor(&descriptor_storage)); + dex_file->FindTypeId(method->GetDeclaringClassDescriptor()); CHECK(declaring_class_type_id != nullptr); dex::TypeIndex declaring_class_type_index = dex_file->GetIndexForTypeId(*declaring_class_type_id); const dex::ClassDef* declaring_class_type_def = @@ -846,8 +845,7 @@ std::string ArtMethod::PrettyMethod(ArtMethod* m, bool with_signature) { std::string ArtMethod::PrettyMethod(bool with_signature) { if (UNLIKELY(IsRuntimeMethod())) { - std::string result = GetDeclaringClassDescriptor(); - result += '.'; + std::string result = "<runtime method>."; result += GetName(); // Do not add "<no signature>" even if `with_signature` is true. return result; diff --git a/runtime/art_method.h b/runtime/art_method.h index a612c81b75..96a204055b 100644 --- a/runtime/art_method.h +++ b/runtime/art_method.h @@ -907,6 +907,7 @@ class EXPORT ArtMethod final { const DexFile* GetDexFile() REQUIRES_SHARED(Locks::mutator_lock_); const char* GetDeclaringClassDescriptor() REQUIRES_SHARED(Locks::mutator_lock_); + std::string_view GetDeclaringClassDescriptorView() REQUIRES_SHARED(Locks::mutator_lock_); ALWAYS_INLINE const char* GetShorty() REQUIRES_SHARED(Locks::mutator_lock_); @@ -941,6 +942,7 @@ class EXPORT ArtMethod final { ALWAYS_INLINE size_t GetNumberOfParameters() REQUIRES_SHARED(Locks::mutator_lock_); const char* GetReturnTypeDescriptor() REQUIRES_SHARED(Locks::mutator_lock_); + std::string_view GetReturnTypeDescriptorView() REQUIRES_SHARED(Locks::mutator_lock_); ALWAYS_INLINE Primitive::Type GetReturnTypePrimitive() REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/runtime/common_dex_operations.h b/runtime/common_dex_operations.h index 58b54af078..67d38ec105 100644 --- a/runtime/common_dex_operations.h +++ b/runtime/common_dex_operations.h @@ -255,12 +255,12 @@ ALWAYS_INLINE bool DoFieldPutCommon(Thread* self, } if (UNLIKELY(!reg->VerifierInstanceOf(field_class))) { // This should never happen. - std::string temp1, temp2, temp3; + std::string temp1, temp2; self->ThrowNewExceptionF("Ljava/lang/InternalError;", "Put '%s' that is not instance of field '%s' in '%s'", reg->GetClass()->GetDescriptor(&temp1), field_class->GetDescriptor(&temp2), - field->GetDeclaringClass()->GetDescriptor(&temp3)); + field->GetDeclaringClassDescriptor()); return false; } } diff --git a/runtime/hidden_api.cc b/runtime/hidden_api.cc index c2884d65fc..495b38404c 100644 --- a/runtime/hidden_api.cc +++ b/runtime/hidden_api.cc @@ -251,17 +251,18 @@ enum AccessContextFlags { }; MemberSignature::MemberSignature(ArtField* field) { + // Note: `ArtField::GetDeclaringClassDescriptor()` does not support proxy classes. class_name_ = field->GetDeclaringClass()->GetDescriptor(&tmp_); - member_name_ = field->GetName(); - type_signature_ = field->GetTypeDescriptor(); + member_name_ = field->GetNameView(); + type_signature_ = field->GetTypeDescriptorView(); type_ = kField; } MemberSignature::MemberSignature(ArtMethod* method) { DCHECK(method == method->GetInterfaceMethodIfProxy(kRuntimePointerSize)) << "Caller should have replaced proxy method with interface method"; - class_name_ = method->GetDeclaringClass()->GetDescriptor(&tmp_); - member_name_ = method->GetName(); + class_name_ = method->GetDeclaringClassDescriptor(); + member_name_ = method->GetNameView(); type_signature_ = method->GetSignature().ToString(); type_ = kMethod; } diff --git a/runtime/jni/java_vm_ext.cc b/runtime/jni/java_vm_ext.cc index bbe3970839..4b58fd883e 100644 --- a/runtime/jni/java_vm_ext.cc +++ b/runtime/jni/java_vm_ext.cc @@ -620,7 +620,7 @@ bool JavaVMExt::ShouldTrace(ArtMethod* method) { return false; } // Perform checks based on class name. - std::string_view class_name(method->GetDeclaringClassDescriptor()); + std::string_view class_name = method->GetDeclaringClassDescriptorView(); if (!trace_.empty() && class_name.find(trace_) != std::string_view::npos) { return true; } diff --git a/runtime/oat/aot_class_linker.cc b/runtime/oat/aot_class_linker.cc index 09fb92452d..15bddb9333 100644 --- a/runtime/oat/aot_class_linker.cc +++ b/runtime/oat/aot_class_linker.cc @@ -235,12 +235,10 @@ const SdkChecker* AotClassLinker::GetSdkChecker() const { return sdk_checker_.get(); } -bool AotClassLinker::DenyAccessBasedOnPublicSdk(ArtMethod* art_method) const - REQUIRES_SHARED(Locks::mutator_lock_) { +bool AotClassLinker::DenyAccessBasedOnPublicSdk(ArtMethod* art_method) const { return sdk_checker_ != nullptr && sdk_checker_->ShouldDenyAccess(art_method); } -bool AotClassLinker::DenyAccessBasedOnPublicSdk(ArtField* art_field) const - REQUIRES_SHARED(Locks::mutator_lock_) { +bool AotClassLinker::DenyAccessBasedOnPublicSdk(ArtField* art_field) const { return sdk_checker_ != nullptr && sdk_checker_->ShouldDenyAccess(art_field); } bool AotClassLinker::DenyAccessBasedOnPublicSdk(const char* type_descriptor) const { diff --git a/runtime/oat/aot_class_linker.h b/runtime/oat/aot_class_linker.h index 18689bed7f..d74103260b 100644 --- a/runtime/oat/aot_class_linker.h +++ b/runtime/oat/aot_class_linker.h @@ -43,11 +43,11 @@ class AotClassLinker : public ClassLinker { EXPORT void SetSdkChecker(std::unique_ptr<SdkChecker>&& sdk_checker_); const SdkChecker* GetSdkChecker() const; - bool DenyAccessBasedOnPublicSdk([[maybe_unused]] ArtMethod* art_method) const override + bool DenyAccessBasedOnPublicSdk(ArtMethod* art_method) const override REQUIRES_SHARED(Locks::mutator_lock_); - bool DenyAccessBasedOnPublicSdk([[maybe_unused]] ArtField* art_field) const override + bool DenyAccessBasedOnPublicSdk(ArtField* art_field) const override REQUIRES_SHARED(Locks::mutator_lock_); - bool DenyAccessBasedOnPublicSdk([[maybe_unused]] const char* type_descriptor) const override; + bool DenyAccessBasedOnPublicSdk(const char* type_descriptor) const override; void SetEnablePublicSdkChecks(bool enabled) override; // Transaction constraint checks for AOT compilation. diff --git a/runtime/proxy_test.cc b/runtime/proxy_test.cc index d950675b14..fb877d3ec5 100644 --- a/runtime/proxy_test.cc +++ b/runtime/proxy_test.cc @@ -114,6 +114,7 @@ TEST_F(ProxyTest, ProxyFieldHelper) { ArtField* field = &static_fields->At(0); EXPECT_STREQ("interfaces", field->GetName()); EXPECT_STREQ("[Ljava/lang/Class;", field->GetTypeDescriptor()); + EXPECT_EQ("[Ljava/lang/Class;", field->GetTypeDescriptorView()); EXPECT_OBJ_PTR_EQ(interfacesFieldClass.Get(), field->ResolveType()); std::string temp; EXPECT_STREQ("L$Proxy1234;", field->GetDeclaringClass()->GetDescriptor(&temp)); @@ -123,6 +124,7 @@ TEST_F(ProxyTest, ProxyFieldHelper) { field = &static_fields->At(1); EXPECT_STREQ("throws", field->GetName()); EXPECT_STREQ("[[Ljava/lang/Class;", field->GetTypeDescriptor()); + EXPECT_EQ("[[Ljava/lang/Class;", field->GetTypeDescriptorView()); EXPECT_OBJ_PTR_EQ(throwsFieldClass.Get(), field->ResolveType()); EXPECT_STREQ("L$Proxy1234;", field->GetDeclaringClass()->GetDescriptor(&temp)); EXPECT_FALSE(field->IsPrimitiveType()); diff --git a/runtime/sdk_checker.cc b/runtime/sdk_checker.cc index 0ad8ce5c9e..58a9d081bb 100644 --- a/runtime/sdk_checker.cc +++ b/runtime/sdk_checker.cc @@ -47,14 +47,16 @@ bool SdkChecker::ShouldDenyAccess(ArtMethod* art_method) const { return false; } + const char* declaring_class_descriptor = art_method->GetDeclaringClassDescriptor(); + const char* name = art_method->GetName(); + bool found = false; for (const std::unique_ptr<const DexFile>& dex_file : sdk_dex_files_) { - const dex::TypeId* declaring_type_id = - dex_file->FindTypeId(art_method->GetDeclaringClassDescriptor()); + const dex::TypeId* declaring_type_id = dex_file->FindTypeId(declaring_class_descriptor); if (declaring_type_id == nullptr) { continue; } - const dex::StringId* name_id = dex_file->FindStringId(art_method->GetName()); + const dex::StringId* name_id = dex_file->FindStringId(name); if (name_id == nullptr) { continue; } @@ -91,20 +93,21 @@ bool SdkChecker::ShouldDenyAccess(ArtField* art_field) const { return false; } + const char* declaring_class_descriptor = art_field->GetDeclaringClassDescriptor(); + const char* name = art_field->GetName(); + const char* type_descriptor = art_field->GetTypeDescriptor(); + bool found = false; for (const std::unique_ptr<const DexFile>& dex_file : sdk_dex_files_) { - std::string declaring_class; - - const dex::TypeId* declaring_type_id = - dex_file->FindTypeId(art_field->GetDeclaringClass()->GetDescriptor(&declaring_class)); + const dex::TypeId* declaring_type_id = dex_file->FindTypeId(declaring_class_descriptor); if (declaring_type_id == nullptr) { continue; } - const dex::StringId* name_id = dex_file->FindStringId(art_field->GetName()); + const dex::StringId* name_id = dex_file->FindStringId(name); if (name_id == nullptr) { continue; } - const dex::TypeId* type_id = dex_file->FindTypeId(art_field->GetTypeDescriptor()); + const dex::TypeId* type_id = dex_file->FindTypeId(type_descriptor); if (type_id == nullptr) { continue; } |