diff options
author | 2024-11-05 14:43:07 +0000 | |
---|---|---|
committer | 2024-11-28 14:38:30 +0000 | |
commit | 6963ab426aca2058ab5c4cd575beaf7d1a63547b (patch) | |
tree | d88567cb70778f3352eeb5c4043a339b50c2750f /compiler/optimizing/instruction_builder.cc | |
parent | 2191e733117542a684c7e6c87a5d8d6881ae5936 (diff) |
Refactor ResolveMethod.
Introduce ResolveMethodId and ResolveMethodWithChecks to make it more
explicit at the call site. This also simplifies the implementation of
ResolveMethodWithChecks.
Also avoid creating handles in ResolveField when the dex cache already
contains the field.
Test: test.py
Change-Id: Ie722c6d7ecadf7c6dbd780f0fc58dfae89140a01
Diffstat (limited to 'compiler/optimizing/instruction_builder.cc')
-rw-r--r-- | compiler/optimizing/instruction_builder.cc | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc index b2179e69bb..c66fd3bb26 100644 --- a/compiler/optimizing/instruction_builder.cc +++ b/compiler/optimizing/instruction_builder.cc @@ -937,13 +937,20 @@ static ArtMethod* ResolveMethod(uint16_t method_idx, ClassLinker* class_linker = dex_compilation_unit.GetClassLinker(); Handle<mirror::ClassLoader> class_loader = dex_compilation_unit.GetClassLoader(); - ArtMethod* resolved_method = - class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( + ArtMethod* resolved_method = nullptr; + if (referrer == nullptr) { + // The referrer may be unresolved for AOT if we're compiling a class that cannot be + // resolved because, for example, we don't find a superclass in the classpath. + resolved_method = class_linker->ResolveMethodId( + method_idx, dex_compilation_unit.GetDexCache(), class_loader); + } else if (referrer->SkipAccessChecks()) { + resolved_method = class_linker->ResolveMethodId(method_idx, referrer); + } else { + resolved_method = class_linker->ResolveMethodWithChecks( method_idx, - dex_compilation_unit.GetDexCache(), - class_loader, referrer, *invoke_type); + } if (UNLIKELY(resolved_method == nullptr)) { // Clean up any exception left by type resolution. @@ -952,9 +959,18 @@ static ArtMethod* ResolveMethod(uint16_t method_idx, } DCHECK(!soa.Self()->IsExceptionPending()); - // The referrer may be unresolved for AOT if we're compiling a class that cannot be - // resolved because, for example, we don't find a superclass in the classpath. if (referrer == nullptr) { + ObjPtr<mirror::Class> referenced_class = class_linker->LookupResolvedType( + dex_compilation_unit.GetDexFile()->GetMethodId(method_idx).class_idx_, + dex_compilation_unit.GetDexCache().Get(), + class_loader.Get()); + DCHECK(referenced_class != nullptr); // Must have been resolved when resolving the method. + if (class_linker->ThrowIfInvokeClassMismatch(referenced_class, + *dex_compilation_unit.GetDexFile(), + *invoke_type)) { + soa.Self()->ClearException(); + return nullptr; + } // The class linker cannot check access without a referrer, so we have to do it. // Check if the declaring class or referencing class is accessible. SamePackageCompare same_package(dex_compilation_unit); @@ -963,11 +979,6 @@ static ArtMethod* ResolveMethod(uint16_t method_idx, if (!declaring_class_accessible) { // It is possible to access members from an inaccessible superclass // by referencing them through an accessible subclass. - ObjPtr<mirror::Class> referenced_class = class_linker->LookupResolvedType( - dex_compilation_unit.GetDexFile()->GetMethodId(method_idx).class_idx_, - dex_compilation_unit.GetDexCache().Get(), - class_loader.Get()); - DCHECK(referenced_class != nullptr); // Must have been resolved when resolving the method. if (!referenced_class->IsPublic() && !same_package(referenced_class)) { return nullptr; } |