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