From 1415413bddb3a9cd9432de3381ef27e5181e58cc Mon Sep 17 00:00:00 2001 From: Aart Bik Date: Thu, 2 Jun 2016 17:53:58 -0700 Subject: Do not place null check from unresolved field access. Rationale: These accesses go though the runtime anyway where various checks are done, including null check. Since particular checks, like access checks, need to occur prior to the null check (to ensure link errors are not masked by a null reference), the explicit null check should not occur in the HIR. BUG=29068831 Change-Id: I30fc9cb8cf4993e4176e235ceba3a38aef98d503 --- compiler/optimizing/instruction_builder.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'compiler/optimizing/instruction_builder.cc') diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc index aaddc01f1f..5e691c7f5f 100644 --- a/compiler/optimizing/instruction_builder.cc +++ b/compiler/optimizing/instruction_builder.cc @@ -1204,7 +1204,12 @@ bool HInstructionBuilder::BuildInstanceFieldAccess(const Instruction& instructio compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa); - HInstruction* object = LoadNullCheckedLocal(obj_reg, dex_pc); + // Generate an explicit null check on the reference, unless the field access + // is unresolved. In that case, we rely on the runtime to perform various + // checks first, followed by a null check. + HInstruction* object = (resolved_field == nullptr) + ? LoadLocal(obj_reg, Primitive::kPrimNot) + : LoadNullCheckedLocal(obj_reg, dex_pc); Primitive::Type field_type = (resolved_field == nullptr) ? GetFieldAccessType(*dex_file_, field_index) -- cgit v1.2.3-59-g8ed1b