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
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index 6839292..1993fa2 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -1148,6 +1148,10 @@
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 @@
&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);
}