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