Fix a stale reference use.
It is unsafe to use an expression like
klass.Get() == ResolveType()
where the `ResolveType()` call can invalidate the plain
pointer already retrieved from a Handle<>.
We fix this in HInstructionBuilder::BuildLoadClass() by
reordering the code and we change the prefix of related
functions from "Get" to "Resolve" to better express their
semantics. We also pass the ScopedObjectAccess helper all
the way to the `ResolveClassFrom()` to avoid constructing
a new one.
Test: m test-art-host-gtest
Test: testrunner.py --host
Bug: 31113334
Change-Id: I13c1ea356386f28fdc9548da781982f9774080f1
diff --git a/compiler/optimizing/instruction_builder.h b/compiler/optimizing/instruction_builder.h
index 578172a..af1b86c 100644
--- a/compiler/optimizing/instruction_builder.h
+++ b/compiler/optimizing/instruction_builder.h
@@ -219,7 +219,8 @@
// Builds a `HLoadClass` loading the given `type_index`.
HLoadClass* BuildLoadClass(dex::TypeIndex type_index, uint32_t dex_pc);
- HLoadClass* BuildLoadClass(dex::TypeIndex type_index,
+ HLoadClass* BuildLoadClass(ScopedObjectAccess& soa,
+ dex::TypeIndex type_index,
const DexFile& dex_file,
Handle<mirror::Class> klass,
uint32_t dex_pc,
@@ -229,7 +230,7 @@
Handle<mirror::Class> ResolveClass(ScopedObjectAccess& soa, dex::TypeIndex type_index)
REQUIRES_SHARED(Locks::mutator_lock_);
- bool LoadClassNeedsAccessCheck(Handle<mirror::Class> klass)
+ bool LoadClassNeedsAccessCheck(ScopedObjectAccess& soa, Handle<mirror::Class> klass)
REQUIRES_SHARED(Locks::mutator_lock_);
// Builds a `HLoadMethodHandle` loading the given `method_handle_index`.
@@ -239,10 +240,12 @@
void BuildLoadMethodType(dex::ProtoIndex proto_index, uint32_t dex_pc);
// Returns the outer-most compiling method's class.
- ObjPtr<mirror::Class> GetOutermostCompilingClass() const;
+ ObjPtr<mirror::Class> ResolveOutermostCompilingClass(ScopedObjectAccess& soa) const
+ REQUIRES_SHARED(Locks::mutator_lock_);
// Returns the class whose method is being compiled.
- ObjPtr<mirror::Class> GetCompilingClass() const;
+ ObjPtr<mirror::Class> ResolveCompilingClass(ScopedObjectAccess& soa) const
+ REQUIRES_SHARED(Locks::mutator_lock_);
// Returns whether `type_index` points to the outer-most compiling method's class.
bool IsOutermostCompilingClass(dex::TypeIndex type_index) const;
@@ -269,6 +272,7 @@
void HandleStringInitResult(HInvokeStaticOrDirect* invoke);
HClinitCheck* ProcessClinitCheckForInvoke(
+ ScopedObjectAccess& soa,
uint32_t dex_pc,
ArtMethod* method,
HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement)
@@ -282,7 +286,8 @@
void BuildConstructorFenceForAllocation(HInstruction* allocation);
// Return whether the compiler can assume `cls` is initialized.
- bool IsInitialized(Handle<mirror::Class> cls) const REQUIRES_SHARED(Locks::mutator_lock_);
+ bool IsInitialized(ScopedObjectAccess& soa, Handle<mirror::Class> cls) const
+ REQUIRES_SHARED(Locks::mutator_lock_);
// Try to resolve a method using the class linker. Return null if a method could
// not be resolved.