Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "inline_method_analyser.h" |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame^] | 18 | |
| 19 | #include "art_field-inl.h" |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 20 | #include "dex_file-inl.h" |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 21 | #include "dex_instruction.h" |
| 22 | #include "dex_instruction-inl.h" |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 23 | #include "mirror/art_method-inl.h" |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 24 | #include "mirror/class-inl.h" |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 25 | #include "mirror/dex_cache-inl.h" |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 26 | #include "verifier/method_verifier-inl.h" |
| 27 | |
| 28 | /* |
| 29 | * NOTE: This code is part of the quick compiler. It lives in the runtime |
| 30 | * only to allow the debugger to check whether a method has been inlined. |
| 31 | */ |
| 32 | |
| 33 | namespace art { |
| 34 | |
Andreas Gampe | 575e78c | 2014-11-03 23:41:03 -0800 | [diff] [blame] | 35 | static_assert(InlineMethodAnalyser::IsInstructionIGet(Instruction::IGET), "iget type"); |
| 36 | static_assert(InlineMethodAnalyser::IsInstructionIGet(Instruction::IGET_WIDE), "iget_wide type"); |
| 37 | static_assert(InlineMethodAnalyser::IsInstructionIGet(Instruction::IGET_OBJECT), |
| 38 | "iget_object type"); |
| 39 | static_assert(InlineMethodAnalyser::IsInstructionIGet(Instruction::IGET_BOOLEAN), |
| 40 | "iget_boolean type"); |
| 41 | static_assert(InlineMethodAnalyser::IsInstructionIGet(Instruction::IGET_BYTE), "iget_byte type"); |
| 42 | static_assert(InlineMethodAnalyser::IsInstructionIGet(Instruction::IGET_CHAR), "iget_char type"); |
| 43 | static_assert(InlineMethodAnalyser::IsInstructionIGet(Instruction::IGET_SHORT), "iget_short type"); |
| 44 | static_assert(InlineMethodAnalyser::IsInstructionIPut(Instruction::IPUT), "iput type"); |
| 45 | static_assert(InlineMethodAnalyser::IsInstructionIPut(Instruction::IPUT_WIDE), "iput_wide type"); |
| 46 | static_assert(InlineMethodAnalyser::IsInstructionIPut(Instruction::IPUT_OBJECT), |
| 47 | "iput_object type"); |
| 48 | static_assert(InlineMethodAnalyser::IsInstructionIPut(Instruction::IPUT_BOOLEAN), |
| 49 | "iput_boolean type"); |
| 50 | static_assert(InlineMethodAnalyser::IsInstructionIPut(Instruction::IPUT_BYTE), "iput_byte type"); |
| 51 | static_assert(InlineMethodAnalyser::IsInstructionIPut(Instruction::IPUT_CHAR), "iput_char type"); |
| 52 | static_assert(InlineMethodAnalyser::IsInstructionIPut(Instruction::IPUT_SHORT), "iput_short type"); |
| 53 | static_assert(InlineMethodAnalyser::IGetVariant(Instruction::IGET) == |
| 54 | InlineMethodAnalyser::IPutVariant(Instruction::IPUT), "iget/iput variant"); |
| 55 | static_assert(InlineMethodAnalyser::IGetVariant(Instruction::IGET_WIDE) == |
| 56 | InlineMethodAnalyser::IPutVariant(Instruction::IPUT_WIDE), "iget/iput_wide variant"); |
| 57 | static_assert(InlineMethodAnalyser::IGetVariant(Instruction::IGET_OBJECT) == |
| 58 | InlineMethodAnalyser::IPutVariant(Instruction::IPUT_OBJECT), "iget/iput_object variant"); |
| 59 | static_assert(InlineMethodAnalyser::IGetVariant(Instruction::IGET_BOOLEAN) == |
| 60 | InlineMethodAnalyser::IPutVariant(Instruction::IPUT_BOOLEAN), "iget/iput_boolean variant"); |
| 61 | static_assert(InlineMethodAnalyser::IGetVariant(Instruction::IGET_BYTE) == |
| 62 | InlineMethodAnalyser::IPutVariant(Instruction::IPUT_BYTE), "iget/iput_byte variant"); |
| 63 | static_assert(InlineMethodAnalyser::IGetVariant(Instruction::IGET_CHAR) == |
| 64 | InlineMethodAnalyser::IPutVariant(Instruction::IPUT_CHAR), "iget/iput_char variant"); |
| 65 | static_assert(InlineMethodAnalyser::IGetVariant(Instruction::IGET_SHORT) == |
| 66 | InlineMethodAnalyser::IPutVariant(Instruction::IPUT_SHORT), "iget/iput_short variant"); |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 67 | |
Sebastien Hertz | 2c87c4d | 2014-03-21 11:31:51 +0100 | [diff] [blame] | 68 | // This is used by compiler and debugger. We look into the dex cache for resolved methods and |
| 69 | // fields. However, in the context of the debugger, not all methods and fields are resolved. Since |
| 70 | // we need to be able to detect possibly inlined method, we pass a null inline method to indicate |
| 71 | // we don't want to take unresolved methods and fields into account during analysis. |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 72 | bool InlineMethodAnalyser::AnalyseMethodCode(verifier::MethodVerifier* verifier, |
| 73 | InlineMethod* method) { |
Sebastien Hertz | 2c87c4d | 2014-03-21 11:31:51 +0100 | [diff] [blame] | 74 | DCHECK(verifier != nullptr); |
| 75 | DCHECK_EQ(Runtime::Current()->IsCompiler(), method != nullptr); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 76 | if (!Runtime::Current()->UseJit()) { |
| 77 | DCHECK_EQ(verifier->CanLoadClasses(), method != nullptr); |
| 78 | } |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 79 | // We currently support only plain return or 2-instruction methods. |
| 80 | |
| 81 | const DexFile::CodeItem* code_item = verifier->CodeItem(); |
| 82 | DCHECK_NE(code_item->insns_size_in_code_units_, 0u); |
| 83 | const Instruction* instruction = Instruction::At(code_item->insns_); |
| 84 | Instruction::Code opcode = instruction->Opcode(); |
| 85 | |
| 86 | switch (opcode) { |
| 87 | case Instruction::RETURN_VOID: |
Sebastien Hertz | 2c87c4d | 2014-03-21 11:31:51 +0100 | [diff] [blame] | 88 | if (method != nullptr) { |
| 89 | method->opcode = kInlineOpNop; |
| 90 | method->flags = kInlineSpecial; |
| 91 | method->d.data = 0u; |
| 92 | } |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 93 | return true; |
| 94 | case Instruction::RETURN: |
| 95 | case Instruction::RETURN_OBJECT: |
| 96 | case Instruction::RETURN_WIDE: |
| 97 | return AnalyseReturnMethod(code_item, method); |
| 98 | case Instruction::CONST: |
| 99 | case Instruction::CONST_4: |
| 100 | case Instruction::CONST_16: |
| 101 | case Instruction::CONST_HIGH16: |
| 102 | // TODO: Support wide constants (RETURN_WIDE). |
| 103 | return AnalyseConstMethod(code_item, method); |
| 104 | case Instruction::IGET: |
| 105 | case Instruction::IGET_OBJECT: |
| 106 | case Instruction::IGET_BOOLEAN: |
| 107 | case Instruction::IGET_BYTE: |
| 108 | case Instruction::IGET_CHAR: |
| 109 | case Instruction::IGET_SHORT: |
| 110 | case Instruction::IGET_WIDE: |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 111 | // TODO: Add handling for JIT. |
| 112 | // case Instruction::IGET_QUICK: |
| 113 | // case Instruction::IGET_WIDE_QUICK: |
| 114 | // case Instruction::IGET_OBJECT_QUICK: |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 115 | return AnalyseIGetMethod(verifier, method); |
| 116 | case Instruction::IPUT: |
| 117 | case Instruction::IPUT_OBJECT: |
| 118 | case Instruction::IPUT_BOOLEAN: |
| 119 | case Instruction::IPUT_BYTE: |
| 120 | case Instruction::IPUT_CHAR: |
| 121 | case Instruction::IPUT_SHORT: |
| 122 | case Instruction::IPUT_WIDE: |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 123 | // TODO: Add handling for JIT. |
| 124 | // case Instruction::IPUT_QUICK: |
| 125 | // case Instruction::IPUT_WIDE_QUICK: |
| 126 | // case Instruction::IPUT_OBJECT_QUICK: |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 127 | return AnalyseIPutMethod(verifier, method); |
| 128 | default: |
| 129 | return false; |
| 130 | } |
| 131 | } |
| 132 | |
Vladimir Marko | c8f60a6 | 2014-04-02 15:24:05 +0100 | [diff] [blame] | 133 | bool InlineMethodAnalyser::IsSyntheticAccessor(MethodReference ref) { |
| 134 | const DexFile::MethodId& method_id = ref.dex_file->GetMethodId(ref.dex_method_index); |
| 135 | const char* method_name = ref.dex_file->GetMethodName(method_id); |
| 136 | return strncmp(method_name, "access$", strlen("access$")) == 0; |
| 137 | } |
| 138 | |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 139 | bool InlineMethodAnalyser::AnalyseReturnMethod(const DexFile::CodeItem* code_item, |
| 140 | InlineMethod* result) { |
| 141 | const Instruction* return_instruction = Instruction::At(code_item->insns_); |
| 142 | Instruction::Code return_opcode = return_instruction->Opcode(); |
| 143 | uint32_t reg = return_instruction->VRegA_11x(); |
| 144 | uint32_t arg_start = code_item->registers_size_ - code_item->ins_size_; |
| 145 | DCHECK_GE(reg, arg_start); |
| 146 | DCHECK_LT((return_opcode == Instruction::RETURN_WIDE) ? reg + 1 : reg, |
| 147 | code_item->registers_size_); |
| 148 | |
Sebastien Hertz | 2c87c4d | 2014-03-21 11:31:51 +0100 | [diff] [blame] | 149 | if (result != nullptr) { |
| 150 | result->opcode = kInlineOpReturnArg; |
| 151 | result->flags = kInlineSpecial; |
| 152 | InlineReturnArgData* data = &result->d.return_data; |
| 153 | data->arg = reg - arg_start; |
| 154 | data->is_wide = (return_opcode == Instruction::RETURN_WIDE) ? 1u : 0u; |
| 155 | data->is_object = (return_opcode == Instruction::RETURN_OBJECT) ? 1u : 0u; |
| 156 | data->reserved = 0u; |
| 157 | data->reserved2 = 0u; |
| 158 | } |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 159 | return true; |
| 160 | } |
| 161 | |
| 162 | bool InlineMethodAnalyser::AnalyseConstMethod(const DexFile::CodeItem* code_item, |
| 163 | InlineMethod* result) { |
| 164 | const Instruction* instruction = Instruction::At(code_item->insns_); |
| 165 | const Instruction* return_instruction = instruction->Next(); |
| 166 | Instruction::Code return_opcode = return_instruction->Opcode(); |
| 167 | if (return_opcode != Instruction::RETURN && |
| 168 | return_opcode != Instruction::RETURN_OBJECT) { |
| 169 | return false; |
| 170 | } |
| 171 | |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 172 | int32_t return_reg = return_instruction->VRegA_11x(); |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 173 | DCHECK_LT(return_reg, code_item->registers_size_); |
| 174 | |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 175 | int32_t const_value = instruction->VRegB(); |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 176 | if (instruction->Opcode() == Instruction::CONST_HIGH16) { |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 177 | const_value <<= 16; |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 178 | } |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 179 | DCHECK_LT(instruction->VRegA(), code_item->registers_size_); |
| 180 | if (instruction->VRegA() != return_reg) { |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 181 | return false; // Not returning the value set by const? |
| 182 | } |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 183 | if (return_opcode == Instruction::RETURN_OBJECT && const_value != 0) { |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 184 | return false; // Returning non-null reference constant? |
| 185 | } |
Sebastien Hertz | 2c87c4d | 2014-03-21 11:31:51 +0100 | [diff] [blame] | 186 | if (result != nullptr) { |
| 187 | result->opcode = kInlineOpNonWideConst; |
| 188 | result->flags = kInlineSpecial; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 189 | result->d.data = static_cast<uint64_t>(const_value); |
Sebastien Hertz | 2c87c4d | 2014-03-21 11:31:51 +0100 | [diff] [blame] | 190 | } |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 191 | return true; |
| 192 | } |
| 193 | |
| 194 | bool InlineMethodAnalyser::AnalyseIGetMethod(verifier::MethodVerifier* verifier, |
| 195 | InlineMethod* result) { |
| 196 | const DexFile::CodeItem* code_item = verifier->CodeItem(); |
| 197 | const Instruction* instruction = Instruction::At(code_item->insns_); |
| 198 | Instruction::Code opcode = instruction->Opcode(); |
| 199 | DCHECK(IsInstructionIGet(opcode)); |
| 200 | |
| 201 | const Instruction* return_instruction = instruction->Next(); |
| 202 | Instruction::Code return_opcode = return_instruction->Opcode(); |
| 203 | if (!(return_opcode == Instruction::RETURN_WIDE && opcode == Instruction::IGET_WIDE) && |
| 204 | !(return_opcode == Instruction::RETURN_OBJECT && opcode == Instruction::IGET_OBJECT) && |
| 205 | !(return_opcode == Instruction::RETURN && opcode != Instruction::IGET_WIDE && |
| 206 | opcode != Instruction::IGET_OBJECT)) { |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | uint32_t return_reg = return_instruction->VRegA_11x(); |
| 211 | DCHECK_LT(return_opcode == Instruction::RETURN_WIDE ? return_reg + 1 : return_reg, |
| 212 | code_item->registers_size_); |
| 213 | |
| 214 | uint32_t dst_reg = instruction->VRegA_22c(); |
| 215 | uint32_t object_reg = instruction->VRegB_22c(); |
| 216 | uint32_t field_idx = instruction->VRegC_22c(); |
| 217 | uint32_t arg_start = code_item->registers_size_ - code_item->ins_size_; |
| 218 | DCHECK_GE(object_reg, arg_start); |
| 219 | DCHECK_LT(object_reg, code_item->registers_size_); |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 220 | uint32_t object_arg = object_reg - arg_start; |
| 221 | |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 222 | DCHECK_LT(opcode == Instruction::IGET_WIDE ? dst_reg + 1 : dst_reg, code_item->registers_size_); |
| 223 | if (dst_reg != return_reg) { |
| 224 | return false; // Not returning the value retrieved by IGET? |
| 225 | } |
| 226 | |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 227 | if ((verifier->GetAccessFlags() & kAccStatic) != 0u || object_arg != 0u) { |
Vladimir Marko | c8f60a6 | 2014-04-02 15:24:05 +0100 | [diff] [blame] | 228 | // TODO: Implement inlining of IGET on non-"this" registers (needs correct stack trace for NPE). |
| 229 | // Allow synthetic accessors. We don't care about losing their stack frame in NPE. |
| 230 | if (!IsSyntheticAccessor(verifier->GetMethodReference())) { |
| 231 | return false; |
| 232 | } |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 235 | // InlineIGetIPutData::object_arg is only 4 bits wide. |
| 236 | static constexpr uint16_t kMaxObjectArg = 15u; |
| 237 | if (object_arg > kMaxObjectArg) { |
| 238 | return false; |
| 239 | } |
| 240 | |
Sebastien Hertz | 2c87c4d | 2014-03-21 11:31:51 +0100 | [diff] [blame] | 241 | if (result != nullptr) { |
| 242 | InlineIGetIPutData* data = &result->d.ifield_data; |
| 243 | if (!ComputeSpecialAccessorInfo(field_idx, false, verifier, data)) { |
| 244 | return false; |
| 245 | } |
| 246 | result->opcode = kInlineOpIGet; |
| 247 | result->flags = kInlineSpecial; |
| 248 | data->op_variant = IGetVariant(opcode); |
Vladimir Marko | c8f60a6 | 2014-04-02 15:24:05 +0100 | [diff] [blame] | 249 | data->method_is_static = (verifier->GetAccessFlags() & kAccStatic) != 0u ? 1u : 0u; |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 250 | data->object_arg = object_arg; // Allow IGET on any register, not just "this". |
Vladimir Marko | c8f60a6 | 2014-04-02 15:24:05 +0100 | [diff] [blame] | 251 | data->src_arg = 0u; |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 252 | data->return_arg_plus1 = 0u; |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 253 | } |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 254 | return true; |
| 255 | } |
| 256 | |
| 257 | bool InlineMethodAnalyser::AnalyseIPutMethod(verifier::MethodVerifier* verifier, |
| 258 | InlineMethod* result) { |
| 259 | const DexFile::CodeItem* code_item = verifier->CodeItem(); |
| 260 | const Instruction* instruction = Instruction::At(code_item->insns_); |
| 261 | Instruction::Code opcode = instruction->Opcode(); |
| 262 | DCHECK(IsInstructionIPut(opcode)); |
| 263 | |
| 264 | const Instruction* return_instruction = instruction->Next(); |
| 265 | Instruction::Code return_opcode = return_instruction->Opcode(); |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 266 | uint32_t arg_start = code_item->registers_size_ - code_item->ins_size_; |
| 267 | uint16_t return_arg_plus1 = 0u; |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 268 | if (return_opcode != Instruction::RETURN_VOID) { |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 269 | if (return_opcode != Instruction::RETURN && |
| 270 | return_opcode != Instruction::RETURN_OBJECT && |
| 271 | return_opcode != Instruction::RETURN_WIDE) { |
| 272 | return false; |
| 273 | } |
| 274 | // Returning an argument. |
| 275 | uint32_t return_reg = return_instruction->VRegA_11x(); |
| 276 | DCHECK_GE(return_reg, arg_start); |
| 277 | DCHECK_LT(return_opcode == Instruction::RETURN_WIDE ? return_reg + 1u : return_reg, |
| 278 | code_item->registers_size_); |
| 279 | return_arg_plus1 = return_reg - arg_start + 1u; |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | uint32_t src_reg = instruction->VRegA_22c(); |
| 283 | uint32_t object_reg = instruction->VRegB_22c(); |
| 284 | uint32_t field_idx = instruction->VRegC_22c(); |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 285 | DCHECK_GE(object_reg, arg_start); |
| 286 | DCHECK_LT(object_reg, code_item->registers_size_); |
| 287 | DCHECK_GE(src_reg, arg_start); |
| 288 | DCHECK_LT(opcode == Instruction::IPUT_WIDE ? src_reg + 1 : src_reg, code_item->registers_size_); |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 289 | uint32_t object_arg = object_reg - arg_start; |
| 290 | uint32_t src_arg = src_reg - arg_start; |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 291 | |
Vladimir Marko | c8f60a6 | 2014-04-02 15:24:05 +0100 | [diff] [blame] | 292 | if ((verifier->GetAccessFlags() & kAccStatic) != 0u || object_arg != 0u) { |
| 293 | // TODO: Implement inlining of IPUT on non-"this" registers (needs correct stack trace for NPE). |
| 294 | // Allow synthetic accessors. We don't care about losing their stack frame in NPE. |
| 295 | if (!IsSyntheticAccessor(verifier->GetMethodReference())) { |
| 296 | return false; |
| 297 | } |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 300 | // InlineIGetIPutData::object_arg/src_arg/return_arg_plus1 are each only 4 bits wide. |
| 301 | static constexpr uint16_t kMaxObjectArg = 15u; |
| 302 | static constexpr uint16_t kMaxSrcArg = 15u; |
| 303 | static constexpr uint16_t kMaxReturnArgPlus1 = 15u; |
| 304 | if (object_arg > kMaxObjectArg || src_arg > kMaxSrcArg || return_arg_plus1 > kMaxReturnArgPlus1) { |
| 305 | return false; |
| 306 | } |
| 307 | |
Sebastien Hertz | 2c87c4d | 2014-03-21 11:31:51 +0100 | [diff] [blame] | 308 | if (result != nullptr) { |
| 309 | InlineIGetIPutData* data = &result->d.ifield_data; |
| 310 | if (!ComputeSpecialAccessorInfo(field_idx, true, verifier, data)) { |
| 311 | return false; |
| 312 | } |
| 313 | result->opcode = kInlineOpIPut; |
| 314 | result->flags = kInlineSpecial; |
| 315 | data->op_variant = IPutVariant(opcode); |
Vladimir Marko | c8f60a6 | 2014-04-02 15:24:05 +0100 | [diff] [blame] | 316 | data->method_is_static = (verifier->GetAccessFlags() & kAccStatic) != 0u ? 1u : 0u; |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 317 | data->object_arg = object_arg; // Allow IPUT on any register, not just "this". |
| 318 | data->src_arg = src_arg; |
| 319 | data->return_arg_plus1 = return_arg_plus1; |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 320 | } |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 321 | return true; |
| 322 | } |
| 323 | |
| 324 | bool InlineMethodAnalyser::ComputeSpecialAccessorInfo(uint32_t field_idx, bool is_put, |
| 325 | verifier::MethodVerifier* verifier, |
| 326 | InlineIGetIPutData* result) { |
| 327 | mirror::DexCache* dex_cache = verifier->GetDexCache(); |
| 328 | uint32_t method_idx = verifier->GetMethodReference().dex_method_index; |
| 329 | mirror::ArtMethod* method = dex_cache->GetResolvedMethod(method_idx); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame^] | 330 | ArtField* field = Runtime::Current()->GetClassLinker()->GetResolvedField(field_idx, dex_cache); |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 331 | if (method == nullptr || field == nullptr || field->IsStatic()) { |
| 332 | return false; |
| 333 | } |
| 334 | mirror::Class* method_class = method->GetDeclaringClass(); |
| 335 | mirror::Class* field_class = field->GetDeclaringClass(); |
| 336 | if (!method_class->CanAccessResolvedField(field_class, field, dex_cache, field_idx) || |
| 337 | (is_put && field->IsFinal() && method_class != field_class)) { |
| 338 | return false; |
| 339 | } |
| 340 | DCHECK_GE(field->GetOffset().Int32Value(), 0); |
| 341 | result->field_idx = field_idx; |
| 342 | result->field_offset = field->GetOffset().Int32Value(); |
| 343 | result->is_volatile = field->IsVolatile(); |
| 344 | return true; |
| 345 | } |
| 346 | |
| 347 | } // namespace art |