From fca0b491a34144acf6769ab9c5fb528ac81bd325 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Mon, 23 Jul 2018 15:30:52 +0100 Subject: 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 --- compiler/optimizing/instruction_builder.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'compiler/optimizing/instruction_builder.h') diff --git a/compiler/optimizing/instruction_builder.h b/compiler/optimizing/instruction_builder.h index 578172a18e..af1b86ca6f 100644 --- a/compiler/optimizing/instruction_builder.h +++ b/compiler/optimizing/instruction_builder.h @@ -219,7 +219,8 @@ class HInstructionBuilder : public ValueObject { // 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 klass, uint32_t dex_pc, @@ -229,7 +230,7 @@ class HInstructionBuilder : public ValueObject { Handle ResolveClass(ScopedObjectAccess& soa, dex::TypeIndex type_index) REQUIRES_SHARED(Locks::mutator_lock_); - bool LoadClassNeedsAccessCheck(Handle klass) + bool LoadClassNeedsAccessCheck(ScopedObjectAccess& soa, Handle klass) REQUIRES_SHARED(Locks::mutator_lock_); // Builds a `HLoadMethodHandle` loading the given `method_handle_index`. @@ -239,10 +240,12 @@ class HInstructionBuilder : public ValueObject { void BuildLoadMethodType(dex::ProtoIndex proto_index, uint32_t dex_pc); // Returns the outer-most compiling method's class. - ObjPtr GetOutermostCompilingClass() const; + ObjPtr ResolveOutermostCompilingClass(ScopedObjectAccess& soa) const + REQUIRES_SHARED(Locks::mutator_lock_); // Returns the class whose method is being compiled. - ObjPtr GetCompilingClass() const; + ObjPtr 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 @@ class HInstructionBuilder : public ValueObject { void HandleStringInitResult(HInvokeStaticOrDirect* invoke); HClinitCheck* ProcessClinitCheckForInvoke( + ScopedObjectAccess& soa, uint32_t dex_pc, ArtMethod* method, HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement) @@ -282,7 +286,8 @@ class HInstructionBuilder : public ValueObject { void BuildConstructorFenceForAllocation(HInstruction* allocation); // Return whether the compiler can assume `cls` is initialized. - bool IsInitialized(Handle cls) const REQUIRES_SHARED(Locks::mutator_lock_); + bool IsInitialized(ScopedObjectAccess& soa, Handle 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. -- cgit v1.2.3-59-g8ed1b