diff options
author | Andra Danciu <andradanciu@google.com> | 2020-08-25 15:09:43 +0000 |
---|---|---|
committer | Orion Hodson <oth@google.com> | 2020-08-26 11:04:50 +0000 |
commit | aa3588350bd483db207055b9481b0a57b2245122 (patch) | |
tree | a5e55d47aae2e172fbba1c96226739ecbadfbff6 /compiler/optimizing/instruction_builder.cc | |
parent | 9e3fe99cba7dd3a1dba2439d86697a293dc003ba (diff) |
Revert^2 "X86: VarHandle.get() for reference type static fields."
This reverts commit 6a6cca588df43a180534db0b49475a8a5ab4c35a.
This commit extends the VarHandle.get() implementation to work with
reference type fields, not only primitive types.
Test: ART_HEAP_POISONING=true art/test.py --host --32 -r -t 712-varhandle-invocations
Bug: 65872996
Reason for revert: Fix loading the reference field.
Change-Id: Ide1f13fb9c6a4e97876862fb4772e9d543847f1f
Diffstat (limited to 'compiler/optimizing/instruction_builder.cc')
-rw-r--r-- | compiler/optimizing/instruction_builder.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc index 6839292397..1993fa2512 100644 --- a/compiler/optimizing/instruction_builder.cc +++ b/compiler/optimizing/instruction_builder.cc @@ -1148,6 +1148,10 @@ bool HInstructionBuilder::BuildInvokePolymorphic(uint32_t dex_pc, DCHECK_EQ(1 + ArtMethod::NumArgRegisters(shorty), operands.GetNumberOfOperands()); DataType::Type return_type = DataType::FromShorty(shorty[0]); size_t number_of_arguments = strlen(shorty); + // Other inputs are needed to propagate type information regarding the MethodType of the + // call site. We need this when generating code to check that VarHandle accessors are + // called correctly (for references). + size_t number_of_other_inputs = 0u; // We use ResolveMethod which is also used in BuildInvoke in order to // not duplicate code. As such, we need to provide is_string_constructor // even if we don't need it afterwards. @@ -1159,12 +1163,36 @@ bool HInstructionBuilder::BuildInvokePolymorphic(uint32_t dex_pc, &invoke_type, /* target_method= */ nullptr, &is_string_constructor); + + bool needs_other_inputs = + resolved_method->GetIntrinsic() == static_cast<uint32_t>(Intrinsics::kVarHandleGet) && + return_type == DataType::Type::kReference && + number_of_arguments == 1u; + if (needs_other_inputs) { + // The extra argument here is the loaded callsite return type, which needs to be checked + // against the runtime VarHandle type. + number_of_other_inputs++; + } + HInvoke* invoke = new (allocator_) HInvokePolymorphic(allocator_, number_of_arguments, + number_of_other_inputs, return_type, dex_pc, method_idx, resolved_method); + + if (needs_other_inputs) { + ScopedObjectAccess soa(Thread::Current()); + ArtMethod* referrer = graph_->GetArtMethod(); + dex::TypeIndex ret_type_index = referrer->GetDexFile()->GetProtoId(proto_idx).return_type_idx_; + HLoadClass* load_cls = BuildLoadClass(ret_type_index, dex_pc); + size_t last_index = invoke->InputCount() - 1; + + DCHECK(invoke->InputAt(last_index) == nullptr); + invoke->SetRawInputAt(last_index, load_cls); + } + return HandleInvoke(invoke, operands, shorty, /* is_unresolved= */ false); } |