Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +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 "verified_method.h" |
| 18 | |
| 19 | #include <algorithm> |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 20 | #include <memory> |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
| 23 | #include "base/logging.h" |
| 24 | #include "base/stl_util.h" |
| 25 | #include "dex_file.h" |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 26 | #include "dex_instruction-inl.h" |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 27 | #include "mirror/art_method-inl.h" |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 29 | #include "mirror/dex_cache-inl.h" |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 30 | #include "mirror/object-inl.h" |
Andreas Gampe | 0b9203e | 2015-01-22 20:39:27 -0800 | [diff] [blame^] | 31 | #include "utils.h" |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 32 | #include "verifier/dex_gc_map.h" |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 33 | #include "verifier/method_verifier-inl.h" |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 34 | #include "verifier/reg_type-inl.h" |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 35 | #include "verifier/register_line-inl.h" |
| 36 | |
| 37 | namespace art { |
| 38 | |
| 39 | const VerifiedMethod* VerifiedMethod::Create(verifier::MethodVerifier* method_verifier, |
| 40 | bool compile) { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 41 | std::unique_ptr<VerifiedMethod> verified_method(new VerifiedMethod); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 42 | if (compile) { |
| 43 | /* Generate a register map. */ |
| 44 | if (!verified_method->GenerateGcMap(method_verifier)) { |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 45 | return nullptr; // Not a real failure, but a failure to encode. |
| 46 | } |
| 47 | if (kIsDebugBuild) { |
| 48 | VerifyGcMap(method_verifier, verified_method->dex_gc_map_); |
| 49 | } |
| 50 | |
| 51 | // TODO: move this out when DEX-to-DEX supports devirtualization. |
| 52 | if (method_verifier->HasVirtualOrInterfaceInvokes()) { |
| 53 | verified_method->GenerateDevirtMap(method_verifier); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if (method_verifier->HasCheckCasts()) { |
| 58 | verified_method->GenerateSafeCastSet(method_verifier); |
| 59 | } |
| 60 | return verified_method.release(); |
| 61 | } |
| 62 | |
| 63 | const MethodReference* VerifiedMethod::GetDevirtTarget(uint32_t dex_pc) const { |
| 64 | auto it = devirt_map_.find(dex_pc); |
| 65 | return (it != devirt_map_.end()) ? &it->second : nullptr; |
| 66 | } |
| 67 | |
| 68 | bool VerifiedMethod::IsSafeCast(uint32_t pc) const { |
| 69 | return std::binary_search(safe_cast_set_.begin(), safe_cast_set_.end(), pc); |
| 70 | } |
| 71 | |
| 72 | bool VerifiedMethod::GenerateGcMap(verifier::MethodVerifier* method_verifier) { |
| 73 | DCHECK(dex_gc_map_.empty()); |
| 74 | size_t num_entries, ref_bitmap_bits, pc_bits; |
| 75 | ComputeGcMapSizes(method_verifier, &num_entries, &ref_bitmap_bits, &pc_bits); |
| 76 | // There's a single byte to encode the size of each bitmap. |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 77 | if (ref_bitmap_bits >= kBitsPerByte * 8192 /* 13-bit size */) { |
Andreas Gampe | 6c170c9 | 2014-12-17 14:35:46 -0800 | [diff] [blame] | 78 | LOG(WARNING) << "Cannot encode GC map for method with " << ref_bitmap_bits << " registers: " |
| 79 | << PrettyMethod(method_verifier->GetMethodReference().dex_method_index, |
| 80 | *method_verifier->GetMethodReference().dex_file); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 81 | return false; |
| 82 | } |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 83 | size_t ref_bitmap_bytes = RoundUp(ref_bitmap_bits, kBitsPerByte) / kBitsPerByte; |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 84 | // There are 2 bytes to encode the number of entries. |
| 85 | if (num_entries >= 65536) { |
Andreas Gampe | 6c170c9 | 2014-12-17 14:35:46 -0800 | [diff] [blame] | 86 | LOG(WARNING) << "Cannot encode GC map for method with " << num_entries << " entries: " |
| 87 | << PrettyMethod(method_verifier->GetMethodReference().dex_method_index, |
| 88 | *method_verifier->GetMethodReference().dex_file); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 89 | return false; |
| 90 | } |
| 91 | size_t pc_bytes; |
| 92 | verifier::RegisterMapFormat format; |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 93 | if (pc_bits <= kBitsPerByte) { |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 94 | format = verifier::kRegMapFormatCompact8; |
| 95 | pc_bytes = 1; |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 96 | } else if (pc_bits <= kBitsPerByte * 2) { |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 97 | format = verifier::kRegMapFormatCompact16; |
| 98 | pc_bytes = 2; |
| 99 | } else { |
Andreas Gampe | 6c170c9 | 2014-12-17 14:35:46 -0800 | [diff] [blame] | 100 | LOG(WARNING) << "Cannot encode GC map for method with " |
| 101 | << (1 << pc_bits) << " instructions (number is rounded up to nearest power of 2): " |
| 102 | << PrettyMethod(method_verifier->GetMethodReference().dex_method_index, |
| 103 | *method_verifier->GetMethodReference().dex_file); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 104 | return false; |
| 105 | } |
| 106 | size_t table_size = ((pc_bytes + ref_bitmap_bytes) * num_entries) + 4; |
| 107 | dex_gc_map_.reserve(table_size); |
| 108 | // Write table header. |
| 109 | dex_gc_map_.push_back(format | ((ref_bitmap_bytes & ~0xFF) >> 5)); |
| 110 | dex_gc_map_.push_back(ref_bitmap_bytes & 0xFF); |
| 111 | dex_gc_map_.push_back(num_entries & 0xFF); |
| 112 | dex_gc_map_.push_back((num_entries >> 8) & 0xFF); |
| 113 | // Write table data. |
| 114 | const DexFile::CodeItem* code_item = method_verifier->CodeItem(); |
| 115 | for (size_t i = 0; i < code_item->insns_size_in_code_units_; i++) { |
| 116 | if (method_verifier->GetInstructionFlags(i).IsCompileTimeInfoPoint()) { |
| 117 | dex_gc_map_.push_back(i & 0xFF); |
| 118 | if (pc_bytes == 2) { |
| 119 | dex_gc_map_.push_back((i >> 8) & 0xFF); |
| 120 | } |
| 121 | verifier::RegisterLine* line = method_verifier->GetRegLine(i); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 122 | line->WriteReferenceBitMap(method_verifier, &dex_gc_map_, ref_bitmap_bytes); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | DCHECK_EQ(dex_gc_map_.size(), table_size); |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | void VerifiedMethod::VerifyGcMap(verifier::MethodVerifier* method_verifier, |
| 130 | const std::vector<uint8_t>& data) { |
| 131 | // Check that for every GC point there is a map entry, there aren't entries for non-GC points, |
| 132 | // that the table data is well formed and all references are marked (or not) in the bitmap. |
| 133 | verifier::DexPcToReferenceMap map(&data[0]); |
| 134 | DCHECK_EQ(data.size(), map.RawSize()); |
| 135 | size_t map_index = 0; |
| 136 | const DexFile::CodeItem* code_item = method_verifier->CodeItem(); |
| 137 | for (size_t i = 0; i < code_item->insns_size_in_code_units_; i++) { |
| 138 | const uint8_t* reg_bitmap = map.FindBitMap(i, false); |
| 139 | if (method_verifier->GetInstructionFlags(i).IsCompileTimeInfoPoint()) { |
| 140 | DCHECK_LT(map_index, map.NumEntries()); |
| 141 | DCHECK_EQ(map.GetDexPc(map_index), i); |
| 142 | DCHECK_EQ(map.GetBitMap(map_index), reg_bitmap); |
| 143 | map_index++; |
| 144 | verifier::RegisterLine* line = method_verifier->GetRegLine(i); |
| 145 | for (size_t j = 0; j < code_item->registers_size_; j++) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 146 | if (line->GetRegisterType(method_verifier, j).IsNonZeroReferenceTypes()) { |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 147 | DCHECK_LT(j / kBitsPerByte, map.RegWidth()); |
| 148 | DCHECK_EQ((reg_bitmap[j / kBitsPerByte] >> (j % kBitsPerByte)) & 1, 1); |
| 149 | } else if ((j / kBitsPerByte) < map.RegWidth()) { |
| 150 | DCHECK_EQ((reg_bitmap[j / kBitsPerByte] >> (j % kBitsPerByte)) & 1, 0); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 151 | } else { |
| 152 | // If a register doesn't contain a reference then the bitmap may be shorter than the line. |
| 153 | } |
| 154 | } |
| 155 | } else { |
Andreas Gampe | 6c170c9 | 2014-12-17 14:35:46 -0800 | [diff] [blame] | 156 | DCHECK(i >= 65536 || reg_bitmap == NULL); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void VerifiedMethod::ComputeGcMapSizes(verifier::MethodVerifier* method_verifier, |
| 162 | size_t* gc_points, size_t* ref_bitmap_bits, |
| 163 | size_t* log2_max_gc_pc) { |
| 164 | size_t local_gc_points = 0; |
| 165 | size_t max_insn = 0; |
| 166 | size_t max_ref_reg = -1; |
| 167 | const DexFile::CodeItem* code_item = method_verifier->CodeItem(); |
| 168 | for (size_t i = 0; i < code_item->insns_size_in_code_units_; i++) { |
| 169 | if (method_verifier->GetInstructionFlags(i).IsCompileTimeInfoPoint()) { |
| 170 | local_gc_points++; |
| 171 | max_insn = i; |
| 172 | verifier::RegisterLine* line = method_verifier->GetRegLine(i); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 173 | max_ref_reg = line->GetMaxNonZeroReferenceReg(method_verifier, max_ref_reg); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | *gc_points = local_gc_points; |
| 177 | *ref_bitmap_bits = max_ref_reg + 1; // If max register is 0 we need 1 bit to encode (ie +1). |
| 178 | size_t i = 0; |
| 179 | while ((1U << i) <= max_insn) { |
| 180 | i++; |
| 181 | } |
| 182 | *log2_max_gc_pc = i; |
| 183 | } |
| 184 | |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 185 | void VerifiedMethod::GenerateDeQuickenMap(verifier::MethodVerifier* method_verifier) { |
| 186 | if (method_verifier->HasFailures()) { |
| 187 | return; |
| 188 | } |
| 189 | const DexFile::CodeItem* code_item = method_verifier->CodeItem(); |
| 190 | const uint16_t* insns = code_item->insns_; |
| 191 | const Instruction* inst = Instruction::At(insns); |
| 192 | const Instruction* end = Instruction::At(insns + code_item->insns_size_in_code_units_); |
| 193 | for (; inst < end; inst = inst->Next()) { |
| 194 | const bool is_virtual_quick = inst->Opcode() == Instruction::INVOKE_VIRTUAL_QUICK; |
| 195 | const bool is_range_quick = inst->Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK; |
| 196 | if (is_virtual_quick || is_range_quick) { |
| 197 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 198 | verifier::RegisterLine* line = method_verifier->GetRegLine(dex_pc); |
| 199 | mirror::ArtMethod* method = method_verifier->GetQuickInvokedMethod(inst, line, |
| 200 | is_range_quick); |
| 201 | CHECK(method != nullptr); |
| 202 | // The verifier must know what the type of the object was or else we would have gotten a |
| 203 | // failure. Put the dex method index in the dequicken map since we need this to get number of |
| 204 | // arguments in the compiler. |
| 205 | dequicken_map_.Put(dex_pc, method->ToMethodReference()); |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 210 | void VerifiedMethod::GenerateDevirtMap(verifier::MethodVerifier* method_verifier) { |
| 211 | // It is risky to rely on reg_types for sharpening in cases of soft |
| 212 | // verification, we might end up sharpening to a wrong implementation. Just abort. |
| 213 | if (method_verifier->HasFailures()) { |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | const DexFile::CodeItem* code_item = method_verifier->CodeItem(); |
| 218 | const uint16_t* insns = code_item->insns_; |
| 219 | const Instruction* inst = Instruction::At(insns); |
| 220 | const Instruction* end = Instruction::At(insns + code_item->insns_size_in_code_units_); |
| 221 | |
| 222 | for (; inst < end; inst = inst->Next()) { |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 223 | const bool is_virtual = inst->Opcode() == Instruction::INVOKE_VIRTUAL || |
| 224 | inst->Opcode() == Instruction::INVOKE_VIRTUAL_RANGE; |
| 225 | const bool is_interface = inst->Opcode() == Instruction::INVOKE_INTERFACE || |
| 226 | inst->Opcode() == Instruction::INVOKE_INTERFACE_RANGE; |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 227 | |
| 228 | if (!is_interface && !is_virtual) { |
| 229 | continue; |
| 230 | } |
| 231 | // Get reg type for register holding the reference to the object that will be dispatched upon. |
| 232 | uint32_t dex_pc = inst->GetDexPc(insns); |
| 233 | verifier::RegisterLine* line = method_verifier->GetRegLine(dex_pc); |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 234 | const bool is_range = inst->Opcode() == Instruction::INVOKE_VIRTUAL_RANGE || |
| 235 | inst->Opcode() == Instruction::INVOKE_INTERFACE_RANGE; |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 236 | const verifier::RegType& |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 237 | reg_type(line->GetRegisterType(method_verifier, |
| 238 | is_range ? inst->VRegC_3rc() : inst->VRegC_35c())); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 239 | |
| 240 | if (!reg_type.HasClass()) { |
| 241 | // We will compute devirtualization information only when we know the Class of the reg type. |
| 242 | continue; |
| 243 | } |
| 244 | mirror::Class* reg_class = reg_type.GetClass(); |
| 245 | if (reg_class->IsInterface()) { |
| 246 | // We can't devirtualize when the known type of the register is an interface. |
| 247 | continue; |
| 248 | } |
| 249 | if (reg_class->IsAbstract() && !reg_class->IsArrayClass()) { |
| 250 | // We can't devirtualize abstract classes except on arrays of abstract classes. |
| 251 | continue; |
| 252 | } |
| 253 | mirror::ArtMethod* abstract_method = method_verifier->GetDexCache()->GetResolvedMethod( |
| 254 | is_range ? inst->VRegB_3rc() : inst->VRegB_35c()); |
| 255 | if (abstract_method == NULL) { |
| 256 | // If the method is not found in the cache this means that it was never found |
| 257 | // by ResolveMethodAndCheckAccess() called when verifying invoke_*. |
| 258 | continue; |
| 259 | } |
| 260 | // Find the concrete method. |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 261 | mirror::ArtMethod* concrete_method = nullptr; |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 262 | if (is_interface) { |
| 263 | concrete_method = reg_type.GetClass()->FindVirtualMethodForInterface(abstract_method); |
| 264 | } |
| 265 | if (is_virtual) { |
| 266 | concrete_method = reg_type.GetClass()->FindVirtualMethodForVirtual(abstract_method); |
| 267 | } |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 268 | if (concrete_method == nullptr || concrete_method->IsAbstract()) { |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 269 | // In cases where concrete_method is not found, or is abstract, continue to the next invoke. |
| 270 | continue; |
| 271 | } |
| 272 | if (reg_type.IsPreciseReference() || concrete_method->IsFinal() || |
| 273 | concrete_method->GetDeclaringClass()->IsFinal()) { |
| 274 | // If we knew exactly the class being dispatched upon, or if the target method cannot be |
| 275 | // overridden record the target to be used in the compiler driver. |
Mathieu Chartier | 36b58f5 | 2014-12-10 12:06:45 -0800 | [diff] [blame] | 276 | devirt_map_.Put(dex_pc, concrete_method->ToMethodReference()); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | void VerifiedMethod::GenerateSafeCastSet(verifier::MethodVerifier* method_verifier) { |
| 282 | /* |
| 283 | * Walks over the method code and adds any cast instructions in which |
| 284 | * the type cast is implicit to a set, which is used in the code generation |
| 285 | * to elide these casts. |
| 286 | */ |
| 287 | if (method_verifier->HasFailures()) { |
| 288 | return; |
| 289 | } |
| 290 | const DexFile::CodeItem* code_item = method_verifier->CodeItem(); |
| 291 | const Instruction* inst = Instruction::At(code_item->insns_); |
| 292 | const Instruction* end = Instruction::At(code_item->insns_ + |
| 293 | code_item->insns_size_in_code_units_); |
| 294 | |
| 295 | for (; inst < end; inst = inst->Next()) { |
| 296 | Instruction::Code code = inst->Opcode(); |
| 297 | if ((code == Instruction::CHECK_CAST) || (code == Instruction::APUT_OBJECT)) { |
| 298 | uint32_t dex_pc = inst->GetDexPc(code_item->insns_); |
Stephen Kyle | 40d3518 | 2014-10-03 13:47:56 +0100 | [diff] [blame] | 299 | if (!method_verifier->GetInstructionFlags(dex_pc).IsVisited()) { |
| 300 | // Do not attempt to quicken this instruction, it's unreachable anyway. |
| 301 | continue; |
| 302 | } |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 303 | const verifier::RegisterLine* line = method_verifier->GetRegLine(dex_pc); |
| 304 | bool is_safe_cast = false; |
| 305 | if (code == Instruction::CHECK_CAST) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 306 | const verifier::RegType& reg_type(line->GetRegisterType(method_verifier, |
| 307 | inst->VRegA_21c())); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 308 | const verifier::RegType& cast_type = |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 309 | method_verifier->ResolveCheckedClass(inst->VRegB_21c()); |
| 310 | is_safe_cast = cast_type.IsStrictlyAssignableFrom(reg_type); |
| 311 | } else { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 312 | const verifier::RegType& array_type(line->GetRegisterType(method_verifier, |
| 313 | inst->VRegB_23x())); |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 314 | // We only know its safe to assign to an array if the array type is precise. For example, |
| 315 | // an Object[] can have any type of object stored in it, but it may also be assigned a |
| 316 | // String[] in which case the stores need to be of Strings. |
| 317 | if (array_type.IsPreciseReference()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 318 | const verifier::RegType& value_type(line->GetRegisterType(method_verifier, |
| 319 | inst->VRegA_23x())); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 320 | const verifier::RegType& component_type = method_verifier->GetRegTypeCache() |
Vladimir Marko | c7f8320 | 2014-01-24 17:55:18 +0000 | [diff] [blame] | 321 | ->GetComponentType(array_type, method_verifier->GetClassLoader()); |
| 322 | is_safe_cast = component_type.IsStrictlyAssignableFrom(value_type); |
| 323 | } |
| 324 | } |
| 325 | if (is_safe_cast) { |
| 326 | // Verify ordering for push_back() to the sorted vector. |
| 327 | DCHECK(safe_cast_set_.empty() || safe_cast_set_.back() < dex_pc); |
| 328 | safe_cast_set_.push_back(dex_pc); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | } // namespace art |