David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 "instruction_builder.h" |
| 18 | |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 19 | #include "art_method-inl.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 20 | #include "base/arena_bit_vector.h" |
| 21 | #include "base/bit_vector-inl.h" |
Andreas Gampe | 85f1c57 | 2018-11-21 13:52:48 -0800 | [diff] [blame] | 22 | #include "base/logging.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 23 | #include "block_builder.h" |
Vladimir Marko | 3b50620 | 2018-10-31 14:33:58 +0000 | [diff] [blame] | 24 | #include "class_linker-inl.h" |
| 25 | #include "code_generator.h" |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 26 | #include "data_type-inl.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 27 | #include "dex/bytecode_utils.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 28 | #include "dex/dex_instruction-inl.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 29 | #include "driver/dex_compilation_unit.h" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 30 | #include "driver/compiler_options.h" |
Andreas Gampe | 75a7db6 | 2016-09-26 12:04:26 -0700 | [diff] [blame] | 31 | #include "imtable-inl.h" |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 32 | #include "jit/jit.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 33 | #include "mirror/dex_cache.h" |
Nicolas Geoffray | 58cc1cb | 2017-11-20 13:27:29 +0000 | [diff] [blame] | 34 | #include "oat_file.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 35 | #include "optimizing_compiler_stats.h" |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 36 | #include "quicken_info.h" |
Nicolas Geoffray | 396198b | 2020-06-16 12:02:45 +0100 | [diff] [blame] | 37 | #include "reflective_handle_scope-inl.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 38 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 39 | #include "sharpening.h" |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 40 | #include "ssa_builder.h" |
Andreas Gampe | a7c83ac | 2017-09-11 08:14:23 -0700 | [diff] [blame] | 41 | #include "well_known_classes.h" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 42 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 43 | namespace art { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 44 | |
Vladimir Marko | cfd6580 | 2020-08-18 09:29:51 +0100 | [diff] [blame] | 45 | namespace { |
| 46 | |
| 47 | class SamePackageCompare { |
| 48 | public: |
| 49 | explicit SamePackageCompare(const DexCompilationUnit& dex_compilation_unit) |
| 50 | : dex_compilation_unit_(dex_compilation_unit) {} |
| 51 | |
| 52 | bool operator()(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 53 | if (klass->GetClassLoader() != dex_compilation_unit_.GetClassLoader().Get()) { |
| 54 | return false; |
| 55 | } |
| 56 | if (referrers_descriptor_ == nullptr) { |
| 57 | const DexFile* dex_file = dex_compilation_unit_.GetDexFile(); |
| 58 | uint32_t referrers_method_idx = dex_compilation_unit_.GetDexMethodIndex(); |
| 59 | referrers_descriptor_ = |
| 60 | dex_file->StringByTypeIdx(dex_file->GetMethodId(referrers_method_idx).class_idx_); |
| 61 | referrers_package_length_ = PackageLength(referrers_descriptor_); |
| 62 | } |
| 63 | std::string temp; |
| 64 | const char* klass_descriptor = klass->GetDescriptor(&temp); |
| 65 | size_t klass_package_length = PackageLength(klass_descriptor); |
| 66 | return (referrers_package_length_ == klass_package_length) && |
| 67 | memcmp(referrers_descriptor_, klass_descriptor, referrers_package_length_) == 0; |
| 68 | }; |
| 69 | |
| 70 | private: |
| 71 | static size_t PackageLength(const char* descriptor) { |
| 72 | const char* slash_pos = strrchr(descriptor, '/'); |
| 73 | return (slash_pos != nullptr) ? static_cast<size_t>(slash_pos - descriptor) : 0u; |
| 74 | } |
| 75 | |
| 76 | const DexCompilationUnit& dex_compilation_unit_; |
| 77 | const char* referrers_descriptor_ = nullptr; |
| 78 | size_t referrers_package_length_ = 0u; |
| 79 | }; |
| 80 | |
| 81 | } // anonymous namespace |
| 82 | |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 83 | HInstructionBuilder::HInstructionBuilder(HGraph* graph, |
| 84 | HBasicBlockBuilder* block_builder, |
| 85 | SsaBuilder* ssa_builder, |
| 86 | const DexFile* dex_file, |
| 87 | const CodeItemDebugInfoAccessor& accessor, |
| 88 | DataType::Type return_type, |
| 89 | const DexCompilationUnit* dex_compilation_unit, |
| 90 | const DexCompilationUnit* outer_compilation_unit, |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 91 | CodeGenerator* code_generator, |
Mathieu Chartier | 210531f | 2018-01-12 10:15:51 -0800 | [diff] [blame] | 92 | ArrayRef<const uint8_t> interpreter_metadata, |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 93 | OptimizingCompilerStats* compiler_stats, |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 94 | ScopedArenaAllocator* local_allocator) |
| 95 | : allocator_(graph->GetAllocator()), |
| 96 | graph_(graph), |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 97 | dex_file_(dex_file), |
| 98 | code_item_accessor_(accessor), |
| 99 | return_type_(return_type), |
| 100 | block_builder_(block_builder), |
| 101 | ssa_builder_(ssa_builder), |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 102 | code_generator_(code_generator), |
| 103 | dex_compilation_unit_(dex_compilation_unit), |
| 104 | outer_compilation_unit_(outer_compilation_unit), |
| 105 | quicken_info_(interpreter_metadata), |
| 106 | compilation_stats_(compiler_stats), |
| 107 | local_allocator_(local_allocator), |
| 108 | locals_for_(local_allocator->Adapter(kArenaAllocGraphBuilder)), |
| 109 | current_block_(nullptr), |
| 110 | current_locals_(nullptr), |
| 111 | latest_result_(nullptr), |
| 112 | current_this_parameter_(nullptr), |
Vladimir Marko | 3b50620 | 2018-10-31 14:33:58 +0000 | [diff] [blame] | 113 | loop_headers_(local_allocator->Adapter(kArenaAllocGraphBuilder)), |
| 114 | class_cache_(std::less<dex::TypeIndex>(), local_allocator->Adapter(kArenaAllocGraphBuilder)) { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 115 | loop_headers_.reserve(kDefaultNumberOfLoops); |
| 116 | } |
| 117 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 118 | HBasicBlock* HInstructionBuilder::FindBlockStartingAt(uint32_t dex_pc) const { |
| 119 | return block_builder_->GetBlockAt(dex_pc); |
| 120 | } |
| 121 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 122 | inline ScopedArenaVector<HInstruction*>* HInstructionBuilder::GetLocalsFor(HBasicBlock* block) { |
| 123 | ScopedArenaVector<HInstruction*>* locals = &locals_for_[block->GetBlockId()]; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 124 | const size_t vregs = graph_->GetNumberOfVRegs(); |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 125 | if (locals->size() == vregs) { |
| 126 | return locals; |
| 127 | } |
| 128 | return GetLocalsForWithAllocation(block, locals, vregs); |
| 129 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 130 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 131 | ScopedArenaVector<HInstruction*>* HInstructionBuilder::GetLocalsForWithAllocation( |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 132 | HBasicBlock* block, |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 133 | ScopedArenaVector<HInstruction*>* locals, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 134 | const size_t vregs) { |
| 135 | DCHECK_NE(locals->size(), vregs); |
| 136 | locals->resize(vregs, nullptr); |
| 137 | if (block->IsCatchBlock()) { |
| 138 | // We record incoming inputs of catch phis at throwing instructions and |
| 139 | // must therefore eagerly create the phis. Phis for undefined vregs will |
| 140 | // be deleted when the first throwing instruction with the vreg undefined |
| 141 | // is encountered. Unused phis will be removed by dead phi analysis. |
| 142 | for (size_t i = 0; i < vregs; ++i) { |
| 143 | // No point in creating the catch phi if it is already undefined at |
| 144 | // the first throwing instruction. |
| 145 | HInstruction* current_local_value = (*current_locals_)[i]; |
| 146 | if (current_local_value != nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 147 | HPhi* phi = new (allocator_) HPhi( |
| 148 | allocator_, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 149 | i, |
| 150 | 0, |
| 151 | current_local_value->GetType()); |
| 152 | block->AddPhi(phi); |
| 153 | (*locals)[i] = phi; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | } |
| 157 | return locals; |
| 158 | } |
| 159 | |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 160 | inline HInstruction* HInstructionBuilder::ValueOfLocalAt(HBasicBlock* block, size_t local) { |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 161 | ScopedArenaVector<HInstruction*>* locals = GetLocalsFor(block); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 162 | return (*locals)[local]; |
| 163 | } |
| 164 | |
| 165 | void HInstructionBuilder::InitializeBlockLocals() { |
| 166 | current_locals_ = GetLocalsFor(current_block_); |
| 167 | |
| 168 | if (current_block_->IsCatchBlock()) { |
| 169 | // Catch phis were already created and inputs collected from throwing sites. |
| 170 | if (kIsDebugBuild) { |
| 171 | // Make sure there was at least one throwing instruction which initialized |
| 172 | // locals (guaranteed by HGraphBuilder) and that all try blocks have been |
| 173 | // visited already (from HTryBoundary scoping and reverse post order). |
| 174 | bool catch_block_visited = false; |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 175 | for (HBasicBlock* current : graph_->GetReversePostOrder()) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 176 | if (current == current_block_) { |
| 177 | catch_block_visited = true; |
| 178 | } else if (current->IsTryBlock()) { |
| 179 | const HTryBoundary& try_entry = current->GetTryCatchInformation()->GetTryEntry(); |
| 180 | if (try_entry.HasExceptionHandler(*current_block_)) { |
| 181 | DCHECK(!catch_block_visited) << "Catch block visited before its try block."; |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | DCHECK_EQ(current_locals_->size(), graph_->GetNumberOfVRegs()) |
| 186 | << "No instructions throwing into a live catch block."; |
| 187 | } |
| 188 | } else if (current_block_->IsLoopHeader()) { |
| 189 | // If the block is a loop header, we know we only have visited the pre header |
| 190 | // because we are visiting in reverse post order. We create phis for all initialized |
| 191 | // locals from the pre header. Their inputs will be populated at the end of |
| 192 | // the analysis. |
| 193 | for (size_t local = 0; local < current_locals_->size(); ++local) { |
| 194 | HInstruction* incoming = |
| 195 | ValueOfLocalAt(current_block_->GetLoopInformation()->GetPreHeader(), local); |
| 196 | if (incoming != nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 197 | HPhi* phi = new (allocator_) HPhi( |
| 198 | allocator_, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 199 | local, |
| 200 | 0, |
| 201 | incoming->GetType()); |
| 202 | current_block_->AddPhi(phi); |
| 203 | (*current_locals_)[local] = phi; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | // Save the loop header so that the last phase of the analysis knows which |
| 208 | // blocks need to be updated. |
| 209 | loop_headers_.push_back(current_block_); |
| 210 | } else if (current_block_->GetPredecessors().size() > 0) { |
| 211 | // All predecessors have already been visited because we are visiting in reverse post order. |
| 212 | // We merge the values of all locals, creating phis if those values differ. |
| 213 | for (size_t local = 0; local < current_locals_->size(); ++local) { |
| 214 | bool one_predecessor_has_no_value = false; |
| 215 | bool is_different = false; |
| 216 | HInstruction* value = ValueOfLocalAt(current_block_->GetPredecessors()[0], local); |
| 217 | |
| 218 | for (HBasicBlock* predecessor : current_block_->GetPredecessors()) { |
| 219 | HInstruction* current = ValueOfLocalAt(predecessor, local); |
| 220 | if (current == nullptr) { |
| 221 | one_predecessor_has_no_value = true; |
| 222 | break; |
| 223 | } else if (current != value) { |
| 224 | is_different = true; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | if (one_predecessor_has_no_value) { |
| 229 | // If one predecessor has no value for this local, we trust the verifier has |
| 230 | // successfully checked that there is a store dominating any read after this block. |
| 231 | continue; |
| 232 | } |
| 233 | |
| 234 | if (is_different) { |
| 235 | HInstruction* first_input = ValueOfLocalAt(current_block_->GetPredecessors()[0], local); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 236 | HPhi* phi = new (allocator_) HPhi( |
| 237 | allocator_, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 238 | local, |
| 239 | current_block_->GetPredecessors().size(), |
| 240 | first_input->GetType()); |
| 241 | for (size_t i = 0; i < current_block_->GetPredecessors().size(); i++) { |
| 242 | HInstruction* pred_value = ValueOfLocalAt(current_block_->GetPredecessors()[i], local); |
| 243 | phi->SetRawInputAt(i, pred_value); |
| 244 | } |
| 245 | current_block_->AddPhi(phi); |
| 246 | value = phi; |
| 247 | } |
| 248 | (*current_locals_)[local] = value; |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | void HInstructionBuilder::PropagateLocalsToCatchBlocks() { |
| 254 | const HTryBoundary& try_entry = current_block_->GetTryCatchInformation()->GetTryEntry(); |
| 255 | for (HBasicBlock* catch_block : try_entry.GetExceptionHandlers()) { |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 256 | ScopedArenaVector<HInstruction*>* handler_locals = GetLocalsFor(catch_block); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 257 | DCHECK_EQ(handler_locals->size(), current_locals_->size()); |
| 258 | for (size_t vreg = 0, e = current_locals_->size(); vreg < e; ++vreg) { |
| 259 | HInstruction* handler_value = (*handler_locals)[vreg]; |
| 260 | if (handler_value == nullptr) { |
| 261 | // Vreg was undefined at a previously encountered throwing instruction |
| 262 | // and the catch phi was deleted. Do not record the local value. |
| 263 | continue; |
| 264 | } |
| 265 | DCHECK(handler_value->IsPhi()); |
| 266 | |
| 267 | HInstruction* local_value = (*current_locals_)[vreg]; |
| 268 | if (local_value == nullptr) { |
| 269 | // This is the first instruction throwing into `catch_block` where |
| 270 | // `vreg` is undefined. Delete the catch phi. |
| 271 | catch_block->RemovePhi(handler_value->AsPhi()); |
| 272 | (*handler_locals)[vreg] = nullptr; |
| 273 | } else { |
| 274 | // Vreg has been defined at all instructions throwing into `catch_block` |
| 275 | // encountered so far. Record the local value in the catch phi. |
| 276 | handler_value->AsPhi()->AddInput(local_value); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | void HInstructionBuilder::AppendInstruction(HInstruction* instruction) { |
| 283 | current_block_->AddInstruction(instruction); |
| 284 | InitializeInstruction(instruction); |
| 285 | } |
| 286 | |
| 287 | void HInstructionBuilder::InsertInstructionAtTop(HInstruction* instruction) { |
| 288 | if (current_block_->GetInstructions().IsEmpty()) { |
| 289 | current_block_->AddInstruction(instruction); |
| 290 | } else { |
| 291 | current_block_->InsertInstructionBefore(instruction, current_block_->GetFirstInstruction()); |
| 292 | } |
| 293 | InitializeInstruction(instruction); |
| 294 | } |
| 295 | |
| 296 | void HInstructionBuilder::InitializeInstruction(HInstruction* instruction) { |
| 297 | if (instruction->NeedsEnvironment()) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 298 | HEnvironment* environment = new (allocator_) HEnvironment( |
| 299 | allocator_, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 300 | current_locals_->size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 301 | graph_->GetArtMethod(), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 302 | instruction->GetDexPc(), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 303 | instruction); |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 304 | environment->CopyFrom(ArrayRef<HInstruction* const>(*current_locals_)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 305 | instruction->SetRawEnvironment(environment); |
| 306 | } |
| 307 | } |
| 308 | |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 309 | HInstruction* HInstructionBuilder::LoadNullCheckedLocal(uint32_t register_index, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 310 | HInstruction* ref = LoadLocal(register_index, DataType::Type::kReference); |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 311 | if (!ref->CanBeNull()) { |
| 312 | return ref; |
| 313 | } |
| 314 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 315 | HNullCheck* null_check = new (allocator_) HNullCheck(ref, dex_pc); |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 316 | AppendInstruction(null_check); |
| 317 | return null_check; |
| 318 | } |
| 319 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 320 | void HInstructionBuilder::SetLoopHeaderPhiInputs() { |
| 321 | for (size_t i = loop_headers_.size(); i > 0; --i) { |
| 322 | HBasicBlock* block = loop_headers_[i - 1]; |
| 323 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
| 324 | HPhi* phi = it.Current()->AsPhi(); |
| 325 | size_t vreg = phi->GetRegNumber(); |
| 326 | for (HBasicBlock* predecessor : block->GetPredecessors()) { |
| 327 | HInstruction* value = ValueOfLocalAt(predecessor, vreg); |
| 328 | if (value == nullptr) { |
| 329 | // Vreg is undefined at this predecessor. Mark it dead and leave with |
| 330 | // fewer inputs than predecessors. SsaChecker will fail if not removed. |
| 331 | phi->SetDead(); |
| 332 | break; |
| 333 | } else { |
| 334 | phi->AddInput(value); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | static bool IsBlockPopulated(HBasicBlock* block) { |
| 342 | if (block->IsLoopHeader()) { |
| 343 | // Suspend checks were inserted into loop headers during building of dominator tree. |
| 344 | DCHECK(block->GetFirstInstruction()->IsSuspendCheck()); |
| 345 | return block->GetFirstInstruction() != block->GetLastInstruction(); |
| 346 | } else { |
| 347 | return !block->GetInstructions().IsEmpty(); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | bool HInstructionBuilder::Build() { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 352 | DCHECK(code_item_accessor_.HasCodeItem()); |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 353 | locals_for_.resize( |
| 354 | graph_->GetBlocks().size(), |
| 355 | ScopedArenaVector<HInstruction*>(local_allocator_->Adapter(kArenaAllocGraphBuilder))); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 356 | |
| 357 | // Find locations where we want to generate extra stackmaps for native debugging. |
| 358 | // This allows us to generate the info only at interesting points (for example, |
| 359 | // at start of java statement) rather than before every dex instruction. |
Vladimir Marko | 3b50620 | 2018-10-31 14:33:58 +0000 | [diff] [blame] | 360 | const bool native_debuggable = code_generator_ != nullptr && |
| 361 | code_generator_->GetCompilerOptions().GetNativeDebuggable(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 362 | ArenaBitVector* native_debug_info_locations = nullptr; |
| 363 | if (native_debuggable) { |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 364 | native_debug_info_locations = FindNativeDebugInfoLocations(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 367 | for (HBasicBlock* block : graph_->GetReversePostOrder()) { |
| 368 | current_block_ = block; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 369 | uint32_t block_dex_pc = current_block_->GetDexPc(); |
| 370 | |
| 371 | InitializeBlockLocals(); |
| 372 | |
| 373 | if (current_block_->IsEntryBlock()) { |
| 374 | InitializeParameters(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 375 | AppendInstruction(new (allocator_) HSuspendCheck(0u)); |
| 376 | AppendInstruction(new (allocator_) HGoto(0u)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 377 | continue; |
| 378 | } else if (current_block_->IsExitBlock()) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 379 | AppendInstruction(new (allocator_) HExit()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 380 | continue; |
| 381 | } else if (current_block_->IsLoopHeader()) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 382 | HSuspendCheck* suspend_check = new (allocator_) HSuspendCheck(current_block_->GetDexPc()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 383 | current_block_->GetLoopInformation()->SetSuspendCheck(suspend_check); |
| 384 | // This is slightly odd because the loop header might not be empty (TryBoundary). |
| 385 | // But we're still creating the environment with locals from the top of the block. |
| 386 | InsertInstructionAtTop(suspend_check); |
| 387 | } |
| 388 | |
| 389 | if (block_dex_pc == kNoDexPc || current_block_ != block_builder_->GetBlockAt(block_dex_pc)) { |
| 390 | // Synthetic block that does not need to be populated. |
| 391 | DCHECK(IsBlockPopulated(current_block_)); |
| 392 | continue; |
| 393 | } |
| 394 | |
| 395 | DCHECK(!IsBlockPopulated(current_block_)); |
| 396 | |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 397 | uint32_t quicken_index = 0; |
| 398 | if (CanDecodeQuickenedInfo()) { |
| 399 | quicken_index = block_builder_->GetQuickenIndex(block_dex_pc); |
| 400 | } |
| 401 | |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 402 | for (const DexInstructionPcPair& pair : code_item_accessor_.InstructionsFrom(block_dex_pc)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 403 | if (current_block_ == nullptr) { |
| 404 | // The previous instruction ended this block. |
| 405 | break; |
| 406 | } |
| 407 | |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 408 | const uint32_t dex_pc = pair.DexPc(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 409 | if (dex_pc != block_dex_pc && FindBlockStartingAt(dex_pc) != nullptr) { |
| 410 | // This dex_pc starts a new basic block. |
| 411 | break; |
| 412 | } |
| 413 | |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 414 | if (current_block_->IsTryBlock() && IsThrowingDexInstruction(pair.Inst())) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 415 | PropagateLocalsToCatchBlocks(); |
| 416 | } |
| 417 | |
| 418 | if (native_debuggable && native_debug_info_locations->IsBitSet(dex_pc)) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 419 | AppendInstruction(new (allocator_) HNativeDebugInfo(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 422 | // Note: There may be no Thread for gtests. |
| 423 | DCHECK(Thread::Current() == nullptr || !Thread::Current()->IsExceptionPending()) |
Nicolas Geoffray | 605c591 | 2020-04-08 15:12:39 +0100 | [diff] [blame] | 424 | << dex_file_->PrettyMethod(dex_compilation_unit_->GetDexMethodIndex()) |
| 425 | << " " << pair.Inst().Name() << "@" << dex_pc; |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 426 | if (!ProcessDexInstruction(pair.Inst(), dex_pc, quicken_index)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 427 | return false; |
| 428 | } |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 429 | DCHECK(Thread::Current() == nullptr || !Thread::Current()->IsExceptionPending()) |
Nicolas Geoffray | fbf53b5 | 2020-04-01 15:20:14 +0100 | [diff] [blame] | 430 | << dex_file_->PrettyMethod(dex_compilation_unit_->GetDexMethodIndex()) |
Nicolas Geoffray | 605c591 | 2020-04-08 15:12:39 +0100 | [diff] [blame] | 431 | << " " << pair.Inst().Name() << "@" << dex_pc; |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 432 | |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 433 | if (QuickenInfoTable::NeedsIndexForInstruction(&pair.Inst())) { |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 434 | ++quicken_index; |
| 435 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | if (current_block_ != nullptr) { |
| 439 | // Branching instructions clear current_block, so we know the last |
| 440 | // instruction of the current block is not a branching instruction. |
| 441 | // We add an unconditional Goto to the next block. |
| 442 | DCHECK_EQ(current_block_->GetSuccessors().size(), 1u); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 443 | AppendInstruction(new (allocator_) HGoto()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
| 447 | SetLoopHeaderPhiInputs(); |
| 448 | |
| 449 | return true; |
| 450 | } |
| 451 | |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 452 | void HInstructionBuilder::BuildIntrinsic(ArtMethod* method) { |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 453 | DCHECK(!code_item_accessor_.HasCodeItem()); |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 454 | DCHECK(method->IsIntrinsic()); |
Vladimir Marko | 43d5755 | 2020-09-07 12:30:17 +0000 | [diff] [blame] | 455 | if (kIsDebugBuild) { |
| 456 | ScopedObjectAccess soa(Thread::Current()); |
| 457 | CHECK(!method->IsSignaturePolymorphic()); |
| 458 | } |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 459 | |
| 460 | locals_for_.resize( |
| 461 | graph_->GetBlocks().size(), |
| 462 | ScopedArenaVector<HInstruction*>(local_allocator_->Adapter(kArenaAllocGraphBuilder))); |
| 463 | |
| 464 | // Fill the entry block. Do not add suspend check, we do not want a suspend |
| 465 | // check in intrinsics; intrinsic methods are supposed to be fast. |
| 466 | current_block_ = graph_->GetEntryBlock(); |
| 467 | InitializeBlockLocals(); |
| 468 | InitializeParameters(); |
| 469 | AppendInstruction(new (allocator_) HGoto(0u)); |
| 470 | |
| 471 | // Fill the body. |
| 472 | current_block_ = current_block_->GetSingleSuccessor(); |
| 473 | InitializeBlockLocals(); |
| 474 | DCHECK(!IsBlockPopulated(current_block_)); |
| 475 | |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 476 | // Add the intermediate representation, if available, or invoke instruction. |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 477 | size_t in_vregs = graph_->GetNumberOfInVRegs(); |
| 478 | size_t number_of_arguments = |
| 479 | in_vregs - std::count(current_locals_->end() - in_vregs, current_locals_->end(), nullptr); |
| 480 | uint32_t method_idx = dex_compilation_unit_->GetDexMethodIndex(); |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 481 | const char* shorty = dex_file_->GetMethodShorty(method_idx); |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 482 | RangeInstructionOperands operands(graph_->GetNumberOfVRegs() - in_vregs, in_vregs); |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 483 | if (!BuildSimpleIntrinsic(method, kNoDexPc, operands, shorty)) { |
| 484 | // Some intrinsics without intermediate representation still yield a leaf method, |
| 485 | // so build the invoke. Use HInvokeStaticOrDirect even for methods that would |
| 486 | // normally use an HInvokeVirtual (sharpen the call). |
| 487 | MethodReference target_method(dex_file_, method_idx); |
| 488 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
| 489 | HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall, |
| 490 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 491 | /* method_load_data= */ 0u |
| 492 | }; |
| 493 | InvokeType invoke_type = dex_compilation_unit_->IsStatic() ? kStatic : kDirect; |
| 494 | HInvokeStaticOrDirect* invoke = new (allocator_) HInvokeStaticOrDirect( |
| 495 | allocator_, |
| 496 | number_of_arguments, |
| 497 | return_type_, |
| 498 | kNoDexPc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 499 | target_method, |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 500 | method, |
| 501 | dispatch_info, |
| 502 | invoke_type, |
| 503 | target_method, |
| 504 | HInvokeStaticOrDirect::ClinitCheckRequirement::kNone); |
| 505 | HandleInvoke(invoke, operands, shorty, /* is_unresolved= */ false); |
| 506 | } |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 507 | |
| 508 | // Add the return instruction. |
| 509 | if (return_type_ == DataType::Type::kVoid) { |
| 510 | AppendInstruction(new (allocator_) HReturnVoid()); |
| 511 | } else { |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 512 | AppendInstruction(new (allocator_) HReturn(latest_result_)); |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | // Fill the exit block. |
| 516 | DCHECK_EQ(current_block_->GetSingleSuccessor(), graph_->GetExitBlock()); |
| 517 | current_block_ = graph_->GetExitBlock(); |
| 518 | InitializeBlockLocals(); |
| 519 | AppendInstruction(new (allocator_) HExit()); |
| 520 | } |
| 521 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 522 | ArenaBitVector* HInstructionBuilder::FindNativeDebugInfoLocations() { |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 523 | ArenaBitVector* locations = ArenaBitVector::Create(local_allocator_, |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 524 | code_item_accessor_.InsnsSizeInCodeUnits(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 525 | /* expandable= */ false, |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 526 | kArenaAllocGraphBuilder); |
| 527 | locations->ClearAllBits(); |
Mathieu Chartier | 3e2e123 | 2018-09-11 12:35:30 -0700 | [diff] [blame] | 528 | // The visitor gets called when the line number changes. |
| 529 | // In other words, it marks the start of new java statement. |
| 530 | code_item_accessor_.DecodeDebugPositionInfo([&](const DexFile::PositionInfo& entry) { |
| 531 | locations->SetBit(entry.address_); |
| 532 | return false; |
| 533 | }); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 534 | // Instruction-specific tweaks. |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 535 | for (const DexInstructionPcPair& inst : code_item_accessor_) { |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 536 | switch (inst->Opcode()) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 537 | case Instruction::MOVE_EXCEPTION: { |
| 538 | // Stop in native debugger after the exception has been moved. |
| 539 | // The compiler also expects the move at the start of basic block so |
| 540 | // we do not want to interfere by inserting native-debug-info before it. |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 541 | locations->ClearBit(inst.DexPc()); |
| 542 | DexInstructionIterator next = std::next(DexInstructionIterator(inst)); |
| 543 | DCHECK(next.DexPc() != inst.DexPc()); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 544 | if (next != code_item_accessor_.end()) { |
Mathieu Chartier | 2b2bef2 | 2017-10-26 17:10:19 -0700 | [diff] [blame] | 545 | locations->SetBit(next.DexPc()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 546 | } |
| 547 | break; |
| 548 | } |
| 549 | default: |
| 550 | break; |
| 551 | } |
| 552 | } |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 553 | return locations; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 556 | HInstruction* HInstructionBuilder::LoadLocal(uint32_t reg_number, DataType::Type type) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 557 | HInstruction* value = (*current_locals_)[reg_number]; |
| 558 | DCHECK(value != nullptr); |
| 559 | |
| 560 | // If the operation requests a specific type, we make sure its input is of that type. |
| 561 | if (type != value->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 562 | if (DataType::IsFloatingPointType(type)) { |
Aart Bik | 3188364 | 2016-06-06 15:02:44 -0700 | [diff] [blame] | 563 | value = ssa_builder_->GetFloatOrDoubleEquivalent(value, type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 564 | } else if (type == DataType::Type::kReference) { |
Aart Bik | 3188364 | 2016-06-06 15:02:44 -0700 | [diff] [blame] | 565 | value = ssa_builder_->GetReferenceTypeEquivalent(value); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 566 | } |
Aart Bik | 3188364 | 2016-06-06 15:02:44 -0700 | [diff] [blame] | 567 | DCHECK(value != nullptr); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | return value; |
| 571 | } |
| 572 | |
| 573 | void HInstructionBuilder::UpdateLocal(uint32_t reg_number, HInstruction* stored_value) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 574 | DataType::Type stored_type = stored_value->GetType(); |
| 575 | DCHECK_NE(stored_type, DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 576 | |
| 577 | // Storing into vreg `reg_number` may implicitly invalidate the surrounding |
| 578 | // registers. Consider the following cases: |
| 579 | // (1) Storing a wide value must overwrite previous values in both `reg_number` |
| 580 | // and `reg_number+1`. We store `nullptr` in `reg_number+1`. |
| 581 | // (2) If vreg `reg_number-1` holds a wide value, writing into `reg_number` |
| 582 | // must invalidate it. We store `nullptr` in `reg_number-1`. |
| 583 | // Consequently, storing a wide value into the high vreg of another wide value |
| 584 | // will invalidate both `reg_number-1` and `reg_number+1`. |
| 585 | |
| 586 | if (reg_number != 0) { |
| 587 | HInstruction* local_low = (*current_locals_)[reg_number - 1]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 588 | if (local_low != nullptr && DataType::Is64BitType(local_low->GetType())) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 589 | // The vreg we are storing into was previously the high vreg of a pair. |
| 590 | // We need to invalidate its low vreg. |
| 591 | DCHECK((*current_locals_)[reg_number] == nullptr); |
| 592 | (*current_locals_)[reg_number - 1] = nullptr; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | (*current_locals_)[reg_number] = stored_value; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 597 | if (DataType::Is64BitType(stored_type)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 598 | // We are storing a pair. Invalidate the instruction in the high vreg. |
| 599 | (*current_locals_)[reg_number + 1] = nullptr; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | void HInstructionBuilder::InitializeParameters() { |
| 604 | DCHECK(current_block_->IsEntryBlock()); |
| 605 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 606 | // outer_compilation_unit_ is null only when unit testing. |
| 607 | if (outer_compilation_unit_ == nullptr) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 608 | return; |
| 609 | } |
| 610 | |
| 611 | const char* shorty = dex_compilation_unit_->GetShorty(); |
| 612 | uint16_t number_of_parameters = graph_->GetNumberOfInVRegs(); |
| 613 | uint16_t locals_index = graph_->GetNumberOfLocalVRegs(); |
| 614 | uint16_t parameter_index = 0; |
| 615 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 616 | const dex::MethodId& referrer_method_id = |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 617 | dex_file_->GetMethodId(dex_compilation_unit_->GetDexMethodIndex()); |
| 618 | if (!dex_compilation_unit_->IsStatic()) { |
| 619 | // Add the implicit 'this' argument, not expressed in the signature. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 620 | HParameterValue* parameter = new (allocator_) HParameterValue(*dex_file_, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 621 | referrer_method_id.class_idx_, |
| 622 | parameter_index++, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 623 | DataType::Type::kReference, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 624 | /* is_this= */ true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 625 | AppendInstruction(parameter); |
| 626 | UpdateLocal(locals_index++, parameter); |
| 627 | number_of_parameters--; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 628 | current_this_parameter_ = parameter; |
| 629 | } else { |
| 630 | DCHECK(current_this_parameter_ == nullptr); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 633 | const dex::ProtoId& proto = dex_file_->GetMethodPrototype(referrer_method_id); |
| 634 | const dex::TypeList* arg_types = dex_file_->GetProtoParameters(proto); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 635 | for (int i = 0, shorty_pos = 1; i < number_of_parameters; i++) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 636 | HParameterValue* parameter = new (allocator_) HParameterValue( |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 637 | *dex_file_, |
| 638 | arg_types->GetTypeItem(shorty_pos - 1).type_idx_, |
| 639 | parameter_index++, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 640 | DataType::FromShorty(shorty[shorty_pos]), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 641 | /* is_this= */ false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 642 | ++shorty_pos; |
| 643 | AppendInstruction(parameter); |
| 644 | // Store the parameter value in the local that the dex code will use |
| 645 | // to reference that parameter. |
| 646 | UpdateLocal(locals_index++, parameter); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 647 | if (DataType::Is64BitType(parameter->GetType())) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 648 | i++; |
| 649 | locals_index++; |
| 650 | parameter_index++; |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | template<typename T> |
| 656 | void HInstructionBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 657 | HInstruction* first = LoadLocal(instruction.VRegA(), DataType::Type::kInt32); |
| 658 | HInstruction* second = LoadLocal(instruction.VRegB(), DataType::Type::kInt32); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 659 | T* comparison = new (allocator_) T(first, second, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 660 | AppendInstruction(comparison); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 661 | AppendInstruction(new (allocator_) HIf(comparison, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 662 | current_block_ = nullptr; |
| 663 | } |
| 664 | |
| 665 | template<typename T> |
| 666 | void HInstructionBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 667 | HInstruction* value = LoadLocal(instruction.VRegA(), DataType::Type::kInt32); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 668 | T* comparison = new (allocator_) T(value, graph_->GetIntConstant(0, dex_pc), dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 669 | AppendInstruction(comparison); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 670 | AppendInstruction(new (allocator_) HIf(comparison, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 671 | current_block_ = nullptr; |
| 672 | } |
| 673 | |
| 674 | template<typename T> |
| 675 | void HInstructionBuilder::Unop_12x(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 676 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 677 | uint32_t dex_pc) { |
| 678 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 679 | AppendInstruction(new (allocator_) T(type, first, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 680 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 681 | } |
| 682 | |
| 683 | void HInstructionBuilder::Conversion_12x(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 684 | DataType::Type input_type, |
| 685 | DataType::Type result_type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 686 | uint32_t dex_pc) { |
| 687 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 688 | AppendInstruction(new (allocator_) HTypeConversion(result_type, first, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 689 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 690 | } |
| 691 | |
| 692 | template<typename T> |
| 693 | void HInstructionBuilder::Binop_23x(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 694 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 695 | uint32_t dex_pc) { |
| 696 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 697 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 698 | AppendInstruction(new (allocator_) T(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 699 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 700 | } |
| 701 | |
| 702 | template<typename T> |
| 703 | void HInstructionBuilder::Binop_23x_shift(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 704 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 705 | uint32_t dex_pc) { |
| 706 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 707 | HInstruction* second = LoadLocal(instruction.VRegC(), DataType::Type::kInt32); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 708 | AppendInstruction(new (allocator_) T(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 709 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 710 | } |
| 711 | |
| 712 | void HInstructionBuilder::Binop_23x_cmp(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 713 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 714 | ComparisonBias bias, |
| 715 | uint32_t dex_pc) { |
| 716 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 717 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 718 | AppendInstruction(new (allocator_) HCompare(type, first, second, bias, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 719 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 720 | } |
| 721 | |
| 722 | template<typename T> |
| 723 | void HInstructionBuilder::Binop_12x_shift(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 724 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 725 | uint32_t dex_pc) { |
| 726 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 727 | HInstruction* second = LoadLocal(instruction.VRegB(), DataType::Type::kInt32); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 728 | AppendInstruction(new (allocator_) T(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 729 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 730 | } |
| 731 | |
| 732 | template<typename T> |
| 733 | void HInstructionBuilder::Binop_12x(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 734 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 735 | uint32_t dex_pc) { |
| 736 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 737 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 738 | AppendInstruction(new (allocator_) T(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 739 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 740 | } |
| 741 | |
| 742 | template<typename T> |
| 743 | void HInstructionBuilder::Binop_22s(const Instruction& instruction, bool reverse, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 744 | HInstruction* first = LoadLocal(instruction.VRegB(), DataType::Type::kInt32); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 745 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22s(), dex_pc); |
| 746 | if (reverse) { |
| 747 | std::swap(first, second); |
| 748 | } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 749 | AppendInstruction(new (allocator_) T(DataType::Type::kInt32, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 750 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 751 | } |
| 752 | |
| 753 | template<typename T> |
| 754 | void HInstructionBuilder::Binop_22b(const Instruction& instruction, bool reverse, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 755 | HInstruction* first = LoadLocal(instruction.VRegB(), DataType::Type::kInt32); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 756 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22b(), dex_pc); |
| 757 | if (reverse) { |
| 758 | std::swap(first, second); |
| 759 | } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 760 | AppendInstruction(new (allocator_) T(DataType::Type::kInt32, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 761 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 762 | } |
| 763 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 764 | // Does the method being compiled need any constructor barriers being inserted? |
| 765 | // (Always 'false' for methods that aren't <init>.) |
Vladimir Marko | c1c3452 | 2018-10-31 13:56:49 +0000 | [diff] [blame] | 766 | static bool RequiresConstructorBarrier(const DexCompilationUnit* cu) { |
Igor Murashkin | 032cacd | 2017-04-06 14:40:08 -0700 | [diff] [blame] | 767 | // Can be null in unit tests only. |
| 768 | if (UNLIKELY(cu == nullptr)) { |
| 769 | return false; |
| 770 | } |
| 771 | |
Vladimir Marko | c1c3452 | 2018-10-31 13:56:49 +0000 | [diff] [blame] | 772 | // Constructor barriers are applicable only for <init> methods. |
| 773 | if (LIKELY(!cu->IsConstructor() || cu->IsStatic())) { |
| 774 | return false; |
| 775 | } |
| 776 | |
| 777 | return cu->RequiresConstructorBarrier(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | // Returns true if `block` has only one successor which starts at the next |
| 781 | // dex_pc after `instruction` at `dex_pc`. |
| 782 | static bool IsFallthroughInstruction(const Instruction& instruction, |
| 783 | uint32_t dex_pc, |
| 784 | HBasicBlock* block) { |
| 785 | uint32_t next_dex_pc = dex_pc + instruction.SizeInCodeUnits(); |
| 786 | return block->GetSingleSuccessor()->GetDexPc() == next_dex_pc; |
| 787 | } |
| 788 | |
| 789 | void HInstructionBuilder::BuildSwitch(const Instruction& instruction, uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 790 | HInstruction* value = LoadLocal(instruction.VRegA(), DataType::Type::kInt32); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 791 | DexSwitchTable table(instruction, dex_pc); |
| 792 | |
| 793 | if (table.GetNumEntries() == 0) { |
| 794 | // Empty Switch. Code falls through to the next block. |
| 795 | DCHECK(IsFallthroughInstruction(instruction, dex_pc, current_block_)); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 796 | AppendInstruction(new (allocator_) HGoto(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 797 | } else if (table.ShouldBuildDecisionTree()) { |
| 798 | for (DexSwitchTableIterator it(table); !it.Done(); it.Advance()) { |
| 799 | HInstruction* case_value = graph_->GetIntConstant(it.CurrentKey(), dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 800 | HEqual* comparison = new (allocator_) HEqual(value, case_value, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 801 | AppendInstruction(comparison); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 802 | AppendInstruction(new (allocator_) HIf(comparison, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 803 | |
| 804 | if (!it.IsLast()) { |
| 805 | current_block_ = FindBlockStartingAt(it.GetDexPcForCurrentIndex()); |
| 806 | } |
| 807 | } |
| 808 | } else { |
| 809 | AppendInstruction( |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 810 | new (allocator_) HPackedSwitch(table.GetEntryAt(0), table.GetNumEntries(), value, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | current_block_ = nullptr; |
| 814 | } |
| 815 | |
| 816 | void HInstructionBuilder::BuildReturn(const Instruction& instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 817 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 818 | uint32_t dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 819 | if (type == DataType::Type::kVoid) { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 820 | // Only <init> (which is a return-void) could possibly have a constructor fence. |
Igor Murashkin | 032cacd | 2017-04-06 14:40:08 -0700 | [diff] [blame] | 821 | // This may insert additional redundant constructor fences from the super constructors. |
| 822 | // TODO: remove redundant constructor fences (b/36656456). |
Vladimir Marko | c1c3452 | 2018-10-31 13:56:49 +0000 | [diff] [blame] | 823 | if (RequiresConstructorBarrier(dex_compilation_unit_)) { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 824 | // Compiling instance constructor. |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 825 | DCHECK_STREQ("<init>", graph_->GetMethodName()); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 826 | |
| 827 | HInstruction* fence_target = current_this_parameter_; |
| 828 | DCHECK(fence_target != nullptr); |
| 829 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 830 | AppendInstruction(new (allocator_) HConstructorFence(fence_target, dex_pc, allocator_)); |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 831 | MaybeRecordStat( |
| 832 | compilation_stats_, |
| 833 | MethodCompilationStat::kConstructorFenceGeneratedFinal); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 834 | } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 835 | AppendInstruction(new (allocator_) HReturnVoid(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 836 | } else { |
Vladimir Marko | c1c3452 | 2018-10-31 13:56:49 +0000 | [diff] [blame] | 837 | DCHECK(!RequiresConstructorBarrier(dex_compilation_unit_)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 838 | HInstruction* value = LoadLocal(instruction.VRegA(), type); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 839 | AppendInstruction(new (allocator_) HReturn(value, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 840 | } |
| 841 | current_block_ = nullptr; |
| 842 | } |
| 843 | |
| 844 | static InvokeType GetInvokeTypeFromOpCode(Instruction::Code opcode) { |
| 845 | switch (opcode) { |
| 846 | case Instruction::INVOKE_STATIC: |
| 847 | case Instruction::INVOKE_STATIC_RANGE: |
| 848 | return kStatic; |
| 849 | case Instruction::INVOKE_DIRECT: |
| 850 | case Instruction::INVOKE_DIRECT_RANGE: |
| 851 | return kDirect; |
| 852 | case Instruction::INVOKE_VIRTUAL: |
| 853 | case Instruction::INVOKE_VIRTUAL_QUICK: |
| 854 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 855 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: |
| 856 | return kVirtual; |
| 857 | case Instruction::INVOKE_INTERFACE: |
| 858 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 859 | return kInterface; |
| 860 | case Instruction::INVOKE_SUPER_RANGE: |
| 861 | case Instruction::INVOKE_SUPER: |
| 862 | return kSuper; |
| 863 | default: |
| 864 | LOG(FATAL) << "Unexpected invoke opcode: " << opcode; |
| 865 | UNREACHABLE(); |
| 866 | } |
| 867 | } |
| 868 | |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 869 | // Try to resolve a method using the class linker. Return null if a method could |
| 870 | // not be resolved or the resolved method cannot be used for some reason. |
| 871 | // Also retrieve method data needed for creating the invoke intermediate |
| 872 | // representation while we hold the mutator lock here. |
| 873 | static ArtMethod* ResolveMethod(uint16_t method_idx, |
| 874 | ArtMethod* referrer, |
| 875 | const DexCompilationUnit& dex_compilation_unit, |
| 876 | /*inout*/InvokeType* invoke_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 877 | /*out*/MethodReference* method_info, |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 878 | /*out*/bool* is_string_constructor) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 879 | ScopedObjectAccess soa(Thread::Current()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 880 | |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 881 | ClassLinker* class_linker = dex_compilation_unit.GetClassLinker(); |
| 882 | Handle<mirror::ClassLoader> class_loader = dex_compilation_unit.GetClassLoader(); |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 883 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 884 | ArtMethod* resolved_method = |
| 885 | class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 886 | method_idx, |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 887 | dex_compilation_unit.GetDexCache(), |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 888 | class_loader, |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 889 | referrer, |
| 890 | *invoke_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 891 | |
| 892 | if (UNLIKELY(resolved_method == nullptr)) { |
| 893 | // Clean up any exception left by type resolution. |
| 894 | soa.Self()->ClearException(); |
| 895 | return nullptr; |
| 896 | } |
Nicolas Geoffray | 605c591 | 2020-04-08 15:12:39 +0100 | [diff] [blame] | 897 | DCHECK(!soa.Self()->IsExceptionPending()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 898 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 899 | // The referrer may be unresolved for AOT if we're compiling a class that cannot be |
| 900 | // resolved because, for example, we don't find a superclass in the classpath. |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 901 | if (referrer == nullptr) { |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 902 | // The class linker cannot check access without a referrer, so we have to do it. |
Vladimir Marko | cfd6580 | 2020-08-18 09:29:51 +0100 | [diff] [blame] | 903 | // Check if the declaring class or referencing class is accessible. |
| 904 | SamePackageCompare same_package(dex_compilation_unit); |
| 905 | ObjPtr<mirror::Class> declaring_class = resolved_method->GetDeclaringClass(); |
| 906 | bool declaring_class_accessible = declaring_class->IsPublic() || same_package(declaring_class); |
| 907 | if (!declaring_class_accessible) { |
| 908 | // It is possible to access members from an inaccessible superclass |
| 909 | // by referencing them through an accessible subclass. |
| 910 | ObjPtr<mirror::Class> referenced_class = class_linker->LookupResolvedType( |
| 911 | dex_compilation_unit.GetDexFile()->GetMethodId(method_idx).class_idx_, |
| 912 | dex_compilation_unit.GetDexCache().Get(), |
| 913 | class_loader.Get()); |
| 914 | DCHECK(referenced_class != nullptr); // Must have been resolved when resolving the method. |
| 915 | if (!referenced_class->IsPublic() && !same_package(referenced_class)) { |
| 916 | return nullptr; |
| 917 | } |
| 918 | } |
| 919 | // Check whether the method itself is accessible. |
| 920 | // Since the referrer is unresolved but the method is resolved, it cannot be |
| 921 | // inside the same class, so a private method is known to be inaccessible. |
| 922 | // And without a resolved referrer, we cannot check for protected member access |
| 923 | // in superlass, so we handle only access to public member or within the package. |
| 924 | if (resolved_method->IsPrivate() || |
| 925 | (!resolved_method->IsPublic() && !declaring_class_accessible)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 926 | return nullptr; |
| 927 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | // We have to special case the invoke-super case, as ClassLinker::ResolveMethod does not. |
| 931 | // We need to look at the referrer's super class vtable. We need to do this to know if we need to |
| 932 | // make this an invoke-unresolved to handle cross-dex invokes or abstract super methods, both of |
| 933 | // which require runtime handling. |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 934 | if (*invoke_type == kSuper) { |
| 935 | ObjPtr<mirror::Class> compiling_class = dex_compilation_unit.GetCompilingClass().Get(); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 936 | if (compiling_class == nullptr) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 937 | // We could not determine the method's class we need to wait until runtime. |
| 938 | DCHECK(Runtime::Current()->IsAotCompiler()); |
| 939 | return nullptr; |
| 940 | } |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 941 | ObjPtr<mirror::Class> referenced_class = class_linker->LookupResolvedType( |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 942 | dex_compilation_unit.GetDexFile()->GetMethodId(method_idx).class_idx_, |
| 943 | dex_compilation_unit.GetDexCache().Get(), |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 944 | class_loader.Get()); |
| 945 | DCHECK(referenced_class != nullptr); // We have already resolved a method from this class. |
| 946 | if (!referenced_class->IsAssignableFrom(compiling_class)) { |
Aart Bik | f663e34 | 2016-04-04 17:28:59 -0700 | [diff] [blame] | 947 | // We cannot statically determine the target method. The runtime will throw a |
| 948 | // NoSuchMethodError on this one. |
| 949 | return nullptr; |
| 950 | } |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 951 | ArtMethod* actual_method; |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 952 | if (referenced_class->IsInterface()) { |
| 953 | actual_method = referenced_class->FindVirtualMethodForInterfaceSuper( |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 954 | resolved_method, class_linker->GetImagePointerSize()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 955 | } else { |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 956 | uint16_t vtable_index = resolved_method->GetMethodIndex(); |
| 957 | actual_method = compiling_class->GetSuperClass()->GetVTableEntry( |
| 958 | vtable_index, class_linker->GetImagePointerSize()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 959 | } |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 960 | if (actual_method != resolved_method && |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 961 | !IsSameDexFile(*actual_method->GetDexFile(), *dex_compilation_unit.GetDexFile())) { |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 962 | // The back-end code generator relies on this check in order to ensure that it will not |
| 963 | // attempt to read the dex_cache with a dex_method_index that is not from the correct |
| 964 | // dex_file. If we didn't do this check then the dex_method_index will not be updated in the |
Vladimir Marko | c1c3452 | 2018-10-31 13:56:49 +0000 | [diff] [blame] | 965 | // builder, which means that the code-generator (and sharpening and inliner, maybe) |
| 966 | // might invoke an incorrect method. |
Nicolas Geoffray | 393fdb8 | 2016-04-25 14:58:06 +0100 | [diff] [blame] | 967 | // TODO: The actual method could still be referenced in the current dex file, so we |
| 968 | // could try locating it. |
| 969 | // TODO: Remove the dex_file restriction. |
| 970 | return nullptr; |
| 971 | } |
| 972 | if (!actual_method->IsInvokable()) { |
| 973 | // Fail if the actual method cannot be invoked. Otherwise, the runtime resolution stub |
| 974 | // could resolve the callee to the wrong method. |
| 975 | return nullptr; |
| 976 | } |
| 977 | resolved_method = actual_method; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 978 | } |
| 979 | |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 980 | if (*invoke_type == kInterface) { |
| 981 | if (resolved_method->GetDeclaringClass()->IsObjectClass()) { |
| 982 | // If the resolved method is from j.l.Object, emit a virtual call instead. |
| 983 | // The IMT conflict stub only handles interface methods. |
| 984 | *invoke_type = kVirtual; |
| 985 | } else { |
| 986 | DCHECK(resolved_method->GetDeclaringClass()->IsInterface()); |
| 987 | } |
| 988 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 989 | |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 990 | if (*invoke_type == kDirect || *invoke_type == kStatic || *invoke_type == kSuper) { |
| 991 | // Record the target method needed for HInvokeStaticOrDirect. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 992 | *method_info = |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 993 | MethodReference(resolved_method->GetDexFile(), resolved_method->GetDexMethodIndex()); |
| 994 | } else if (*invoke_type == kVirtual) { |
| 995 | // For HInvokeVirtual we need the vtable index. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 996 | *method_info = MethodReference(/*file=*/ nullptr, resolved_method->GetVtableIndex()); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 997 | } else if (*invoke_type == kInterface) { |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 998 | // For HInvokeInterface we need the IMT index. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 999 | *method_info = MethodReference(/*file=*/ nullptr, ImTable::GetImtIndex(resolved_method)); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 1000 | } else { |
| 1001 | // For HInvokePolymorphic we don't need the target method yet |
| 1002 | DCHECK_EQ(*invoke_type, kPolymorphic); |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1003 | DCHECK(method_info == nullptr); |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | *is_string_constructor = |
| 1007 | resolved_method->IsConstructor() && resolved_method->GetDeclaringClass()->IsStringClass(); |
| 1008 | |
| 1009 | return resolved_method; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1012 | bool HInstructionBuilder::BuildInvoke(const Instruction& instruction, |
| 1013 | uint32_t dex_pc, |
| 1014 | uint32_t method_idx, |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 1015 | const InstructionOperands& operands) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1016 | InvokeType invoke_type = GetInvokeTypeFromOpCode(instruction.Opcode()); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1017 | const char* shorty = dex_file_->GetMethodShorty(method_idx); |
| 1018 | DataType::Type return_type = DataType::FromShorty(shorty[0]); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1019 | |
| 1020 | // Remove the return type from the 'proto'. |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1021 | size_t number_of_arguments = strlen(shorty) - 1; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1022 | if (invoke_type != kStatic) { // instance call |
| 1023 | // One extra argument for 'this'. |
| 1024 | number_of_arguments++; |
| 1025 | } |
| 1026 | |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1027 | MethodReference method_info(nullptr, 0u); |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1028 | bool is_string_constructor = false; |
| 1029 | ArtMethod* resolved_method = ResolveMethod(method_idx, |
| 1030 | graph_->GetArtMethod(), |
| 1031 | *dex_compilation_unit_, |
| 1032 | &invoke_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1033 | &method_info, |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1034 | &is_string_constructor); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1035 | |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1036 | MethodReference method_reference(&graph_->GetDexFile(), method_idx); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1037 | if (UNLIKELY(resolved_method == nullptr)) { |
Nicolas Geoffray | 605c591 | 2020-04-08 15:12:39 +0100 | [diff] [blame] | 1038 | DCHECK(!Thread::Current()->IsExceptionPending()); |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 1039 | MaybeRecordStat(compilation_stats_, |
| 1040 | MethodCompilationStat::kUnresolvedMethod); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1041 | HInvoke* invoke = new (allocator_) HInvokeUnresolved(allocator_, |
| 1042 | number_of_arguments, |
| 1043 | return_type, |
| 1044 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1045 | method_reference, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1046 | invoke_type); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1047 | return HandleInvoke(invoke, operands, shorty, /* is_unresolved= */ true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1050 | // Replace calls to String.<init> with StringFactory. |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1051 | if (is_string_constructor) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1052 | uint32_t string_init_entry_point = WellKnownClasses::StringInitToEntryPoint(resolved_method); |
| 1053 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
| 1054 | HInvokeStaticOrDirect::MethodLoadKind::kStringInit, |
| 1055 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 1056 | dchecked_integral_cast<uint64_t>(string_init_entry_point) |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1057 | }; |
Nicolas Geoffray | f665f84 | 2018-02-15 12:29:06 +0000 | [diff] [blame] | 1058 | // We pass null for the resolved_method to ensure optimizations |
| 1059 | // don't rely on it. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1060 | HInvoke* invoke = new (allocator_) HInvokeStaticOrDirect( |
| 1061 | allocator_, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1062 | number_of_arguments - 1, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1063 | /* return_type= */ DataType::Type::kReference, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1064 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1065 | method_reference, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1066 | /* resolved_method= */ nullptr, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1067 | dispatch_info, |
| 1068 | invoke_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1069 | method_info, |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1070 | HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1071 | return HandleStringInit(invoke, operands, shorty); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1074 | // Potential class initialization check, in the case of a static method call. |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1075 | HInvokeStaticOrDirect::ClinitCheckRequirement clinit_check_requirement = |
| 1076 | HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1077 | HClinitCheck* clinit_check = nullptr; |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1078 | if (invoke_type == kStatic) { |
| 1079 | clinit_check = ProcessClinitCheckForInvoke(dex_pc, resolved_method, &clinit_check_requirement); |
| 1080 | } |
| 1081 | |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1082 | // Try to build an HIR replacement for the intrinsic. |
| 1083 | if (UNLIKELY(resolved_method->IsIntrinsic())) { |
| 1084 | // All intrinsics are in the primary boot image, so their class can always be referenced |
| 1085 | // and we do not need to rely on the implicit class initialization check. The class should |
| 1086 | // be initialized but we do not require that here. |
| 1087 | DCHECK_NE(clinit_check_requirement, HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit); |
| 1088 | if (BuildSimpleIntrinsic(resolved_method, dex_pc, operands, shorty)) { |
| 1089 | return true; |
| 1090 | } |
| 1091 | } |
| 1092 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1093 | HInvoke* invoke = nullptr; |
| 1094 | if (invoke_type == kDirect || invoke_type == kStatic || invoke_type == kSuper) { |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1095 | if (invoke_type == kSuper) { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1096 | if (IsSameDexFile(*method_info.dex_file, *dex_compilation_unit_->GetDexFile())) { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 1097 | // Update the method index to the one resolved. Note that this may be a no-op if |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1098 | // we resolved to the method referenced by the instruction. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1099 | method_reference.index = method_info.index; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1100 | } |
| 1101 | } |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 1102 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = |
| 1103 | HSharpening::SharpenInvokeStaticOrDirect(resolved_method, code_generator_); |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 1104 | if (dispatch_info.code_ptr_location == |
| 1105 | HInvokeStaticOrDirect::CodePtrLocation::kCallCriticalNative) { |
| 1106 | graph_->SetHasDirectCriticalNativeCall(true); |
| 1107 | } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1108 | invoke = new (allocator_) HInvokeStaticOrDirect(allocator_, |
| 1109 | number_of_arguments, |
| 1110 | return_type, |
| 1111 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1112 | method_reference, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1113 | resolved_method, |
| 1114 | dispatch_info, |
| 1115 | invoke_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1116 | method_info, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1117 | clinit_check_requirement); |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1118 | if (clinit_check != nullptr) { |
| 1119 | // Add the class initialization check as last input of `invoke`. |
| 1120 | DCHECK_EQ(clinit_check_requirement, HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit); |
| 1121 | size_t clinit_check_index = invoke->InputCount() - 1u; |
| 1122 | DCHECK(invoke->InputAt(clinit_check_index) == nullptr); |
| 1123 | invoke->SetArgumentAt(clinit_check_index, clinit_check); |
| 1124 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1125 | } else if (invoke_type == kVirtual) { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1126 | DCHECK(method_info.dex_file == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1127 | invoke = new (allocator_) HInvokeVirtual(allocator_, |
| 1128 | number_of_arguments, |
| 1129 | return_type, |
| 1130 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1131 | method_reference, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1132 | resolved_method, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1133 | /*vtable_index=*/ method_info.index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1134 | } else { |
| 1135 | DCHECK_EQ(invoke_type, kInterface); |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1136 | invoke = new (allocator_) HInvokeInterface(allocator_, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1137 | number_of_arguments, |
| 1138 | return_type, |
| 1139 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1140 | method_reference, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1141 | resolved_method, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1142 | /*imt_index=*/ method_info.index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1143 | } |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1144 | return HandleInvoke(invoke, operands, shorty, /* is_unresolved= */ false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1147 | bool HInstructionBuilder::BuildInvokePolymorphic(uint32_t dex_pc, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1148 | uint32_t method_idx, |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 1149 | dex::ProtoIndex proto_idx, |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 1150 | const InstructionOperands& operands) { |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1151 | const char* shorty = dex_file_->GetShorty(proto_idx); |
| 1152 | DCHECK_EQ(1 + ArtMethod::NumArgRegisters(shorty), operands.GetNumberOfOperands()); |
| 1153 | DataType::Type return_type = DataType::FromShorty(shorty[0]); |
| 1154 | size_t number_of_arguments = strlen(shorty); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 1155 | // We use ResolveMethod which is also used in BuildInvoke in order to |
| 1156 | // not duplicate code. As such, we need to provide is_string_constructor |
| 1157 | // even if we don't need it afterwards. |
| 1158 | InvokeType invoke_type = InvokeType::kPolymorphic; |
| 1159 | bool is_string_constructor = false; |
| 1160 | ArtMethod* resolved_method = ResolveMethod(method_idx, |
| 1161 | graph_->GetArtMethod(), |
| 1162 | *dex_compilation_unit_, |
| 1163 | &invoke_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1164 | /* method_info= */ nullptr, |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 1165 | &is_string_constructor); |
Andra Danciu | aa35883 | 2020-08-25 15:09:43 +0000 | [diff] [blame] | 1166 | |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1167 | MethodReference method_reference(&graph_->GetDexFile(), method_idx); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1168 | HInvoke* invoke = new (allocator_) HInvokePolymorphic(allocator_, |
| 1169 | number_of_arguments, |
| 1170 | return_type, |
| 1171 | dex_pc, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1172 | method_reference, |
Andra Danciu | 73c3180 | 2020-09-01 13:17:05 +0000 | [diff] [blame] | 1173 | resolved_method, |
| 1174 | proto_idx); |
Andra Danciu | 49a19f3 | 2020-08-27 12:44:25 +0000 | [diff] [blame] | 1175 | if (!HandleInvoke(invoke, operands, shorty, /* is_unresolved= */ false)) { |
| 1176 | return false; |
| 1177 | } |
| 1178 | |
| 1179 | bool needs_ret_type_check = |
| 1180 | resolved_method->GetIntrinsic() == static_cast<uint32_t>(Intrinsics::kVarHandleGet) && |
| 1181 | return_type == DataType::Type::kReference && |
Andra Danciu | 0875b0a | 2020-08-28 11:49:44 +0000 | [diff] [blame] | 1182 | // VarHandle.get() is only implemented for fields now. |
| 1183 | number_of_arguments < 3u; |
Andra Danciu | 49a19f3 | 2020-08-27 12:44:25 +0000 | [diff] [blame] | 1184 | if (needs_ret_type_check) { |
Andra Danciu | aa35883 | 2020-08-25 15:09:43 +0000 | [diff] [blame] | 1185 | ScopedObjectAccess soa(Thread::Current()); |
| 1186 | ArtMethod* referrer = graph_->GetArtMethod(); |
| 1187 | dex::TypeIndex ret_type_index = referrer->GetDexFile()->GetProtoId(proto_idx).return_type_idx_; |
Andra Danciu | aa35883 | 2020-08-25 15:09:43 +0000 | [diff] [blame] | 1188 | |
Andra Danciu | 49a19f3 | 2020-08-27 12:44:25 +0000 | [diff] [blame] | 1189 | // Type check is needed because intrinsic implementations do not type check the retrieved |
| 1190 | // reference. |
| 1191 | BuildTypeCheck(/* is_instance_of= */ false, invoke, ret_type_index, dex_pc); |
| 1192 | latest_result_ = current_block_->GetLastInstruction(); |
Andra Danciu | aa35883 | 2020-08-25 15:09:43 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Andra Danciu | 49a19f3 | 2020-08-27 12:44:25 +0000 | [diff] [blame] | 1195 | return true; |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | |
| 1199 | bool HInstructionBuilder::BuildInvokeCustom(uint32_t dex_pc, |
| 1200 | uint32_t call_site_idx, |
| 1201 | const InstructionOperands& operands) { |
| 1202 | dex::ProtoIndex proto_idx = dex_file_->GetProtoIndexForCallSite(call_site_idx); |
| 1203 | const char* shorty = dex_file_->GetShorty(proto_idx); |
| 1204 | DataType::Type return_type = DataType::FromShorty(shorty[0]); |
| 1205 | size_t number_of_arguments = strlen(shorty) - 1; |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1206 | // HInvokeCustom takes a DexNoNoIndex method reference. |
| 1207 | MethodReference method_reference(&graph_->GetDexFile(), dex::kDexNoIndex); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1208 | HInvoke* invoke = new (allocator_) HInvokeCustom(allocator_, |
| 1209 | number_of_arguments, |
| 1210 | call_site_idx, |
| 1211 | return_type, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1212 | dex_pc, |
| 1213 | method_reference); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1214 | return HandleInvoke(invoke, operands, shorty, /* is_unresolved= */ false); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 1217 | HNewInstance* HInstructionBuilder::BuildNewInstance(dex::TypeIndex type_index, uint32_t dex_pc) { |
Vladimir Marko | 3cd50df | 2016-04-13 19:29:26 +0100 | [diff] [blame] | 1218 | ScopedObjectAccess soa(Thread::Current()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1219 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1220 | HLoadClass* load_class = BuildLoadClass(type_index, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1221 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1222 | HInstruction* cls = load_class; |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1223 | Handle<mirror::Class> klass = load_class->GetClass(); |
| 1224 | |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1225 | if (!IsInitialized(klass.Get())) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1226 | cls = new (allocator_) HClinitCheck(load_class, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1227 | AppendInstruction(cls); |
| 1228 | } |
| 1229 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1230 | // Only the access check entrypoint handles the finalizable class case. If we |
| 1231 | // need access checks, then we haven't resolved the method and the class may |
| 1232 | // again be finalizable. |
| 1233 | QuickEntrypointEnum entrypoint = kQuickAllocObjectInitialized; |
| 1234 | if (load_class->NeedsAccessCheck() || klass->IsFinalizable() || !klass->IsInstantiable()) { |
| 1235 | entrypoint = kQuickAllocObjectWithChecks; |
| 1236 | } |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 1237 | // We will always be able to resolve the string class since it is in the BCP. |
| 1238 | if (!klass.IsNull() && klass->IsStringClass()) { |
| 1239 | entrypoint = kQuickAllocStringObject; |
| 1240 | } |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1241 | |
| 1242 | // Consider classes we haven't resolved as potentially finalizable. |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 1243 | bool finalizable = (klass == nullptr) || klass->IsFinalizable(); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 1244 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1245 | HNewInstance* new_instance = new (allocator_) HNewInstance( |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1246 | cls, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1247 | dex_pc, |
| 1248 | type_index, |
| 1249 | *dex_compilation_unit_->GetDexFile(), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1250 | finalizable, |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 1251 | entrypoint); |
| 1252 | AppendInstruction(new_instance); |
| 1253 | |
| 1254 | return new_instance; |
| 1255 | } |
| 1256 | |
| 1257 | void HInstructionBuilder::BuildConstructorFenceForAllocation(HInstruction* allocation) { |
| 1258 | DCHECK(allocation != nullptr && |
George Burgess IV | f207299 | 2017-05-23 15:36:41 -0700 | [diff] [blame] | 1259 | (allocation->IsNewInstance() || |
| 1260 | allocation->IsNewArray())); // corresponding to "new" keyword in JLS. |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 1261 | |
| 1262 | if (allocation->IsNewInstance()) { |
| 1263 | // STRING SPECIAL HANDLING: |
| 1264 | // ------------------------------- |
| 1265 | // Strings have a real HNewInstance node but they end up always having 0 uses. |
| 1266 | // All uses of a String HNewInstance are always transformed to replace their input |
| 1267 | // of the HNewInstance with an input of the invoke to StringFactory. |
| 1268 | // |
| 1269 | // Do not emit an HConstructorFence here since it can inhibit some String new-instance |
| 1270 | // optimizations (to pass checker tests that rely on those optimizations). |
| 1271 | HNewInstance* new_inst = allocation->AsNewInstance(); |
| 1272 | HLoadClass* load_class = new_inst->GetLoadClass(); |
| 1273 | |
| 1274 | Thread* self = Thread::Current(); |
| 1275 | ScopedObjectAccess soa(self); |
| 1276 | StackHandleScope<1> hs(self); |
| 1277 | Handle<mirror::Class> klass = load_class->GetClass(); |
| 1278 | if (klass != nullptr && klass->IsStringClass()) { |
| 1279 | return; |
| 1280 | // Note: Do not use allocation->IsStringAlloc which requires |
| 1281 | // a valid ReferenceTypeInfo, but that doesn't get made until after reference type |
| 1282 | // propagation (and instruction builder is too early). |
| 1283 | } |
| 1284 | // (In terms of correctness, the StringFactory needs to provide its own |
| 1285 | // default initialization barrier, see below.) |
| 1286 | } |
| 1287 | |
| 1288 | // JLS 17.4.5 "Happens-before Order" describes: |
| 1289 | // |
| 1290 | // The default initialization of any object happens-before any other actions (other than |
| 1291 | // default-writes) of a program. |
| 1292 | // |
| 1293 | // In our implementation the default initialization of an object to type T means |
| 1294 | // setting all of its initial data (object[0..size)) to 0, and setting the |
| 1295 | // object's class header (i.e. object.getClass() == T.class). |
| 1296 | // |
| 1297 | // In practice this fence ensures that the writes to the object header |
| 1298 | // are visible to other threads if this object escapes the current thread. |
| 1299 | // (and in theory the 0-initializing, but that happens automatically |
| 1300 | // when new memory pages are mapped in by the OS). |
| 1301 | HConstructorFence* ctor_fence = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1302 | new (allocator_) HConstructorFence(allocation, allocation->GetDexPc(), allocator_); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 1303 | AppendInstruction(ctor_fence); |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 1304 | MaybeRecordStat( |
| 1305 | compilation_stats_, |
| 1306 | MethodCompilationStat::kConstructorFenceGeneratedNew); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 1309 | static bool IsInBootImage(ObjPtr<mirror::Class> cls, const CompilerOptions& compiler_options) |
| 1310 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Vladimir Marko | 6a67bea | 2020-01-20 13:05:55 +0000 | [diff] [blame] | 1311 | if (Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(cls)) { |
| 1312 | return true; |
| 1313 | } |
| 1314 | if (compiler_options.IsBootImage() || compiler_options.IsBootImageExtension()) { |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 1315 | std::string temp; |
| 1316 | const char* descriptor = cls->GetDescriptor(&temp); |
| 1317 | return compiler_options.IsImageClass(descriptor); |
| 1318 | } else { |
Vladimir Marko | 6a67bea | 2020-01-20 13:05:55 +0000 | [diff] [blame] | 1319 | return false; |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | static bool IsSubClass(ObjPtr<mirror::Class> to_test, ObjPtr<mirror::Class> super_class) |
| 1324 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1325 | return to_test != nullptr && !to_test->IsInterface() && to_test->IsSubClass(super_class); |
| 1326 | } |
| 1327 | |
| 1328 | static bool HasTrivialClinit(ObjPtr<mirror::Class> klass, PointerSize pointer_size) |
| 1329 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1330 | // Check if the class has encoded fields that trigger bytecode execution. |
| 1331 | // (Encoded fields are just a different representation of <clinit>.) |
| 1332 | if (klass->NumStaticFields() != 0u) { |
| 1333 | DCHECK(klass->GetClassDef() != nullptr); |
| 1334 | EncodedStaticFieldValueIterator it(klass->GetDexFile(), *klass->GetClassDef()); |
| 1335 | for (; it.HasNext(); it.Next()) { |
| 1336 | switch (it.GetValueType()) { |
| 1337 | case EncodedArrayValueIterator::ValueType::kBoolean: |
| 1338 | case EncodedArrayValueIterator::ValueType::kByte: |
| 1339 | case EncodedArrayValueIterator::ValueType::kShort: |
| 1340 | case EncodedArrayValueIterator::ValueType::kChar: |
| 1341 | case EncodedArrayValueIterator::ValueType::kInt: |
| 1342 | case EncodedArrayValueIterator::ValueType::kLong: |
| 1343 | case EncodedArrayValueIterator::ValueType::kFloat: |
| 1344 | case EncodedArrayValueIterator::ValueType::kDouble: |
| 1345 | case EncodedArrayValueIterator::ValueType::kNull: |
| 1346 | case EncodedArrayValueIterator::ValueType::kString: |
| 1347 | // Primitive, null or j.l.String initialization is permitted. |
| 1348 | break; |
| 1349 | case EncodedArrayValueIterator::ValueType::kType: |
| 1350 | // Type initialization can load classes and execute bytecode through a class loader |
| 1351 | // which can execute arbitrary bytecode. We do not optimize for known class loaders; |
| 1352 | // kType is rarely used (if ever). |
| 1353 | return false; |
| 1354 | default: |
| 1355 | // Other types in the encoded static field list are rejected by the DexFileVerifier. |
| 1356 | LOG(FATAL) << "Unexpected type " << it.GetValueType(); |
| 1357 | UNREACHABLE(); |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | // Check if the class has <clinit> that executes arbitrary code. |
| 1362 | // Initialization of static fields of the class itself with constants is allowed. |
| 1363 | ArtMethod* clinit = klass->FindClassInitializer(pointer_size); |
| 1364 | if (clinit != nullptr) { |
| 1365 | const DexFile& dex_file = *clinit->GetDexFile(); |
| 1366 | CodeItemInstructionAccessor accessor(dex_file, clinit->GetCodeItem()); |
| 1367 | for (DexInstructionPcPair it : accessor) { |
| 1368 | switch (it->Opcode()) { |
| 1369 | case Instruction::CONST_4: |
| 1370 | case Instruction::CONST_16: |
| 1371 | case Instruction::CONST: |
| 1372 | case Instruction::CONST_HIGH16: |
| 1373 | case Instruction::CONST_WIDE_16: |
| 1374 | case Instruction::CONST_WIDE_32: |
| 1375 | case Instruction::CONST_WIDE: |
| 1376 | case Instruction::CONST_WIDE_HIGH16: |
| 1377 | case Instruction::CONST_STRING: |
| 1378 | case Instruction::CONST_STRING_JUMBO: |
| 1379 | // Primitive, null or j.l.String initialization is permitted. |
| 1380 | break; |
| 1381 | case Instruction::RETURN_VOID: |
| 1382 | case Instruction::RETURN_VOID_NO_BARRIER: |
| 1383 | break; |
| 1384 | case Instruction::SPUT: |
| 1385 | case Instruction::SPUT_WIDE: |
| 1386 | case Instruction::SPUT_OBJECT: |
| 1387 | case Instruction::SPUT_BOOLEAN: |
| 1388 | case Instruction::SPUT_BYTE: |
| 1389 | case Instruction::SPUT_CHAR: |
| 1390 | case Instruction::SPUT_SHORT: |
| 1391 | // Only initialization of a static field of the same class is permitted. |
| 1392 | if (dex_file.GetFieldId(it->VRegB_21c()).class_idx_ != klass->GetDexTypeIndex()) { |
| 1393 | return false; |
| 1394 | } |
| 1395 | break; |
| 1396 | case Instruction::NEW_ARRAY: |
| 1397 | // Only primitive arrays are permitted. |
| 1398 | if (Primitive::GetType(dex_file.GetTypeDescriptor(dex_file.GetTypeId( |
| 1399 | dex::TypeIndex(it->VRegC_22c())))[1]) == Primitive::kPrimNot) { |
| 1400 | return false; |
| 1401 | } |
| 1402 | break; |
| 1403 | case Instruction::APUT: |
| 1404 | case Instruction::APUT_WIDE: |
| 1405 | case Instruction::APUT_BOOLEAN: |
| 1406 | case Instruction::APUT_BYTE: |
| 1407 | case Instruction::APUT_CHAR: |
| 1408 | case Instruction::APUT_SHORT: |
| 1409 | case Instruction::FILL_ARRAY_DATA: |
| 1410 | case Instruction::NOP: |
| 1411 | // Allow initialization of primitive arrays (only constants can be stored). |
| 1412 | // Note: We expect NOPs used for fill-array-data-payload but accept all NOPs |
| 1413 | // (even unreferenced switch payloads if they make it through the verifier). |
| 1414 | break; |
| 1415 | default: |
| 1416 | return false; |
| 1417 | } |
| 1418 | } |
| 1419 | } |
| 1420 | return true; |
| 1421 | } |
| 1422 | |
| 1423 | static bool HasTrivialInitialization(ObjPtr<mirror::Class> cls, |
| 1424 | const CompilerOptions& compiler_options) |
| 1425 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1426 | Runtime* runtime = Runtime::Current(); |
| 1427 | PointerSize pointer_size = runtime->GetClassLinker()->GetImagePointerSize(); |
| 1428 | |
| 1429 | // Check the superclass chain. |
| 1430 | for (ObjPtr<mirror::Class> klass = cls; klass != nullptr; klass = klass->GetSuperClass()) { |
| 1431 | if (klass->IsInitialized() && IsInBootImage(klass, compiler_options)) { |
| 1432 | break; // `klass` and its superclasses are already initialized in the boot image. |
| 1433 | } |
| 1434 | if (!HasTrivialClinit(klass, pointer_size)) { |
| 1435 | return false; |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | // Also check interfaces with default methods as they need to be initialized as well. |
| 1440 | ObjPtr<mirror::IfTable> iftable = cls->GetIfTable(); |
| 1441 | DCHECK(iftable != nullptr); |
| 1442 | for (int32_t i = 0, count = iftable->Count(); i != count; ++i) { |
| 1443 | ObjPtr<mirror::Class> iface = iftable->GetInterface(i); |
| 1444 | if (!iface->HasDefaultMethods()) { |
| 1445 | continue; // Initializing `cls` does not initialize this interface. |
| 1446 | } |
| 1447 | if (iface->IsInitialized() && IsInBootImage(iface, compiler_options)) { |
| 1448 | continue; // This interface is already initialized in the boot image. |
| 1449 | } |
| 1450 | if (!HasTrivialClinit(iface, pointer_size)) { |
| 1451 | return false; |
| 1452 | } |
| 1453 | } |
| 1454 | return true; |
| 1455 | } |
| 1456 | |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1457 | bool HInstructionBuilder::IsInitialized(ObjPtr<mirror::Class> cls) const { |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 1458 | if (cls == nullptr) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1459 | return false; |
| 1460 | } |
| 1461 | |
Vladimir Marko | 51b8aaf | 2017-06-09 15:17:05 +0100 | [diff] [blame] | 1462 | // Check if the class will be initialized at runtime. |
| 1463 | if (cls->IsInitialized()) { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1464 | const CompilerOptions& compiler_options = code_generator_->GetCompilerOptions(); |
| 1465 | if (compiler_options.IsAotCompiler()) { |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 1466 | // Assume loaded only if klass is in the boot image. App classes cannot be assumed |
| 1467 | // loaded because we don't even know what class loader will be used to load them. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1468 | if (IsInBootImage(cls, compiler_options)) { |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 1469 | return true; |
| 1470 | } |
| 1471 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1472 | DCHECK(compiler_options.IsJitCompiler()); |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 1473 | if (Runtime::Current()->GetJit()->CanAssumeInitialized( |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1474 | cls, |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1475 | compiler_options.IsJitCompilerForSharedCode())) { |
Nicolas Geoffray | a48c3df | 2019-06-27 13:11:12 +0000 | [diff] [blame] | 1476 | // For JIT, the class cannot revert to an uninitialized state. |
| 1477 | return true; |
| 1478 | } |
Vladimir Marko | 51b8aaf | 2017-06-09 15:17:05 +0100 | [diff] [blame] | 1479 | } |
| 1480 | } |
| 1481 | |
Vladimir Marko | 7f260d4 | 2018-10-30 18:09:55 +0000 | [diff] [blame] | 1482 | // We can avoid the class initialization check for `cls` in static methods and constructors |
| 1483 | // in the very same class; invoking a static method involves a class initialization check |
| 1484 | // and so does the instance allocation that must be executed before invoking a constructor. |
| 1485 | // Other instance methods of the same class can run on an escaped instance |
Vladimir Marko | 51b8aaf | 2017-06-09 15:17:05 +0100 | [diff] [blame] | 1486 | // of an erroneous class. Even a superclass may need to be checked as the subclass |
| 1487 | // can be completely initialized while the superclass is initializing and the subclass |
| 1488 | // remains initialized when the superclass initializer throws afterwards. b/62478025 |
| 1489 | // Note: The HClinitCheck+HInvokeStaticOrDirect merging can still apply. |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 1490 | auto is_static_method_or_constructor_of_cls = [cls](const DexCompilationUnit& compilation_unit) |
| 1491 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1492 | return (compilation_unit.GetAccessFlags() & (kAccStatic | kAccConstructor)) != 0u && |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1493 | compilation_unit.GetCompilingClass().Get() == cls; |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 1494 | }; |
| 1495 | if (is_static_method_or_constructor_of_cls(*outer_compilation_unit_) || |
| 1496 | // Check also the innermost method. Though excessive copies of ClinitCheck can be |
| 1497 | // eliminated by GVN, that happens only after the decision whether to inline the |
| 1498 | // graph or not and that may depend on the presence of the ClinitCheck. |
| 1499 | // TODO: We should walk over the entire inlined method chain, but we don't pass that |
| 1500 | // information to the builder. |
| 1501 | is_static_method_or_constructor_of_cls(*dex_compilation_unit_)) { |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 1502 | return true; |
| 1503 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1504 | |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 1505 | // Otherwise, we may be able to avoid the check if `cls` is a superclass of a method being |
| 1506 | // compiled here (anywhere in the inlining chain) as the `cls` must have started initializing |
| 1507 | // before calling any `cls` or subclass methods. Static methods require a clinit check and |
| 1508 | // instance methods require an instance which cannot be created before doing a clinit check. |
| 1509 | // When a subclass of `cls` starts initializing, it starts initializing its superclass |
| 1510 | // chain up to `cls` without running any bytecode, i.e. without any opportunity for circular |
| 1511 | // initialization weirdness. |
| 1512 | // |
| 1513 | // If the initialization of `cls` is trivial (`cls` and its superclasses and superinterfaces |
| 1514 | // with default methods initialize only their own static fields using constant values), it must |
| 1515 | // complete, either successfully or by throwing and marking `cls` erroneous, without allocating |
| 1516 | // any instances of `cls` or subclasses (or any other class) and without calling any methods. |
| 1517 | // If it completes by throwing, no instances of `cls` shall be created and no subclass method |
| 1518 | // bytecode shall execute (see above), therefore the instruction we're building shall be |
| 1519 | // unreachable. By reaching the instruction, we know that `cls` was initialized successfully. |
| 1520 | // |
| 1521 | // TODO: We should walk over the entire inlined methods chain, but we don't pass that |
| 1522 | // information to the builder. (We could also check if we're guaranteed a non-null instance |
| 1523 | // of `cls` at this location but that's outside the scope of the instruction builder.) |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1524 | bool is_subclass = IsSubClass(outer_compilation_unit_->GetCompilingClass().Get(), cls); |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 1525 | if (dex_compilation_unit_ != outer_compilation_unit_) { |
| 1526 | is_subclass = is_subclass || |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1527 | IsSubClass(dex_compilation_unit_->GetCompilingClass().Get(), cls); |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 1528 | } |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1529 | if (is_subclass && HasTrivialInitialization(cls, code_generator_->GetCompilerOptions())) { |
Vladimir Marko | 2ab1bdd | 2018-07-12 09:59:56 +0100 | [diff] [blame] | 1530 | return true; |
| 1531 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1532 | |
| 1533 | return false; |
| 1534 | } |
| 1535 | |
| 1536 | HClinitCheck* HInstructionBuilder::ProcessClinitCheckForInvoke( |
Vladimir Marko | fca0b49 | 2018-07-23 15:30:52 +0100 | [diff] [blame] | 1537 | uint32_t dex_pc, |
| 1538 | ArtMethod* resolved_method, |
| 1539 | HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement) { |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1540 | ScopedObjectAccess soa(Thread::Current()); |
| 1541 | ObjPtr<mirror::Class> klass = resolved_method->GetDeclaringClass(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1542 | |
| 1543 | HClinitCheck* clinit_check = nullptr; |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 1544 | if (IsInitialized(klass)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1545 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1546 | } else { |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 1547 | Handle<mirror::Class> h_klass = graph_->GetHandleCache()->NewHandle(klass); |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1548 | HLoadClass* cls = BuildLoadClass(h_klass->GetDexTypeIndex(), |
| 1549 | h_klass->GetDexFile(), |
| 1550 | h_klass, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1551 | dex_pc, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1552 | /* needs_access_check= */ false); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1553 | if (cls != nullptr) { |
| 1554 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1555 | clinit_check = new (allocator_) HClinitCheck(cls, dex_pc); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1556 | AppendInstruction(clinit_check); |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 1557 | } else { |
| 1558 | // Let the invoke handle this with an implicit class initialization check. |
| 1559 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit; |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1560 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1561 | } |
| 1562 | return clinit_check; |
| 1563 | } |
| 1564 | |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1565 | bool HInstructionBuilder::SetupInvokeArguments(HInstruction* invoke, |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 1566 | const InstructionOperands& operands, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1567 | const char* shorty, |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1568 | ReceiverArg receiver_arg) { |
| 1569 | // Note: The `invoke` can be an intrinsic replacement, so not necessaritly HInvoke. |
| 1570 | // In that case, do not log errors, they shall be reported when we try to build the HInvoke. |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1571 | uint32_t shorty_index = 1; // Skip the return type. |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 1572 | const size_t number_of_operands = operands.GetNumberOfOperands(); |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1573 | bool argument_length_error = false; |
| 1574 | |
| 1575 | size_t start_index = 0u; |
| 1576 | size_t argument_index = 0u; |
| 1577 | if (receiver_arg != ReceiverArg::kNone) { |
| 1578 | if (number_of_operands == 0u) { |
| 1579 | argument_length_error = true; |
| 1580 | } else { |
| 1581 | start_index = 1u; |
| 1582 | if (receiver_arg != ReceiverArg::kIgnored) { |
| 1583 | uint32_t obj_reg = operands.GetOperand(0u); |
| 1584 | HInstruction* arg = (receiver_arg == ReceiverArg::kPlainArg) |
| 1585 | ? LoadLocal(obj_reg, DataType::Type::kReference) |
| 1586 | : LoadNullCheckedLocal(obj_reg, invoke->GetDexPc()); |
| 1587 | if (receiver_arg != ReceiverArg::kNullCheckedOnly) { |
| 1588 | invoke->SetRawInputAt(0u, arg); |
| 1589 | argument_index = 1u; |
| 1590 | } |
| 1591 | } |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | for (size_t i = start_index; i < number_of_operands; ++i, ++argument_index) { |
| 1596 | // Make sure we don't go over the expected arguments or over the number of |
| 1597 | // dex registers given. If the instruction was seen as dead by the verifier, |
| 1598 | // it hasn't been properly checked. |
| 1599 | if (UNLIKELY(shorty[shorty_index] == 0)) { |
| 1600 | argument_length_error = true; |
| 1601 | break; |
| 1602 | } |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1603 | DataType::Type type = DataType::FromShorty(shorty[shorty_index++]); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1604 | bool is_wide = (type == DataType::Type::kInt64) || (type == DataType::Type::kFloat64); |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 1605 | if (is_wide && ((i + 1 == number_of_operands) || |
| 1606 | (operands.GetOperand(i) + 1 != operands.GetOperand(i + 1)))) { |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1607 | if (invoke->IsInvoke()) { |
| 1608 | // Longs and doubles should be in pairs, that is, sequential registers. The verifier should |
| 1609 | // reject any class where this is violated. However, the verifier only does these checks |
| 1610 | // on non trivially dead instructions, so we just bailout the compilation. |
| 1611 | VLOG(compiler) << "Did not compile " |
| 1612 | << dex_file_->PrettyMethod(dex_compilation_unit_->GetDexMethodIndex()) |
| 1613 | << " because of non-sequential dex register pair in wide argument"; |
| 1614 | MaybeRecordStat(compilation_stats_, |
| 1615 | MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 1616 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1617 | return false; |
| 1618 | } |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 1619 | HInstruction* arg = LoadLocal(operands.GetOperand(i), type); |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1620 | DCHECK(invoke->InputAt(argument_index) == nullptr); |
| 1621 | invoke->SetRawInputAt(argument_index, arg); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1622 | if (is_wide) { |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1623 | ++i; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1624 | } |
| 1625 | } |
| 1626 | |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1627 | argument_length_error = argument_length_error || shorty[shorty_index] != 0; |
| 1628 | if (argument_length_error) { |
| 1629 | if (invoke->IsInvoke()) { |
| 1630 | VLOG(compiler) << "Did not compile " |
| 1631 | << dex_file_->PrettyMethod(dex_compilation_unit_->GetDexMethodIndex()) |
| 1632 | << " because of wrong number of arguments in invoke instruction"; |
| 1633 | MaybeRecordStat(compilation_stats_, |
| 1634 | MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 1635 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1636 | return false; |
| 1637 | } |
| 1638 | |
| 1639 | if (invoke->IsInvokeStaticOrDirect() && |
| 1640 | HInvokeStaticOrDirect::NeedsCurrentMethodInput( |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1641 | invoke->AsInvokeStaticOrDirect()->GetDispatchInfo())) { |
| 1642 | DCHECK_EQ(argument_index, invoke->AsInvokeStaticOrDirect()->GetCurrentMethodIndex()); |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1643 | DCHECK(invoke->InputAt(argument_index) == nullptr); |
| 1644 | invoke->SetRawInputAt(argument_index, graph_->GetCurrentMethod()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | return true; |
| 1648 | } |
| 1649 | |
| 1650 | bool HInstructionBuilder::HandleInvoke(HInvoke* invoke, |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 1651 | const InstructionOperands& operands, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1652 | const char* shorty, |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1653 | bool is_unresolved) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1654 | DCHECK(!invoke->IsInvokeStaticOrDirect() || !invoke->AsInvokeStaticOrDirect()->IsStringInit()); |
| 1655 | |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1656 | ReceiverArg receiver_arg = (invoke->GetInvokeType() == InvokeType::kStatic) |
| 1657 | ? ReceiverArg::kNone |
| 1658 | : (is_unresolved ? ReceiverArg::kPlainArg : ReceiverArg::kNullCheckedArg); |
| 1659 | if (!SetupInvokeArguments(invoke, operands, shorty, receiver_arg)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1660 | return false; |
| 1661 | } |
| 1662 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1663 | AppendInstruction(invoke); |
| 1664 | latest_result_ = invoke; |
| 1665 | |
| 1666 | return true; |
| 1667 | } |
| 1668 | |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1669 | bool HInstructionBuilder::BuildSimpleIntrinsic(ArtMethod* method, |
| 1670 | uint32_t dex_pc, |
| 1671 | const InstructionOperands& operands, |
| 1672 | const char* shorty) { |
| 1673 | Intrinsics intrinsic = static_cast<Intrinsics>(method->GetIntrinsic()); |
| 1674 | DCHECK_NE(intrinsic, Intrinsics::kNone); |
| 1675 | constexpr DataType::Type kInt32 = DataType::Type::kInt32; |
| 1676 | constexpr DataType::Type kInt64 = DataType::Type::kInt64; |
| 1677 | constexpr DataType::Type kFloat32 = DataType::Type::kFloat32; |
| 1678 | constexpr DataType::Type kFloat64 = DataType::Type::kFloat64; |
| 1679 | ReceiverArg receiver_arg = method->IsStatic() ? ReceiverArg::kNone : ReceiverArg::kNullCheckedArg; |
| 1680 | HInstruction* instruction = nullptr; |
| 1681 | switch (intrinsic) { |
| 1682 | case Intrinsics::kIntegerRotateRight: |
| 1683 | case Intrinsics::kIntegerRotateLeft: |
| 1684 | // For rotate left, we negate the distance below. |
| 1685 | instruction = new (allocator_) HRor(kInt32, /*value=*/ nullptr, /*distance=*/ nullptr); |
| 1686 | break; |
| 1687 | case Intrinsics::kLongRotateRight: |
| 1688 | case Intrinsics::kLongRotateLeft: |
| 1689 | // For rotate left, we negate the distance below. |
| 1690 | instruction = new (allocator_) HRor(kInt64, /*value=*/ nullptr, /*distance=*/ nullptr); |
| 1691 | break; |
| 1692 | case Intrinsics::kIntegerCompare: |
| 1693 | instruction = new (allocator_) HCompare( |
| 1694 | kInt32, /*first=*/ nullptr, /*second=*/ nullptr, ComparisonBias::kNoBias, dex_pc); |
| 1695 | break; |
| 1696 | case Intrinsics::kLongCompare: |
| 1697 | instruction = new (allocator_) HCompare( |
| 1698 | kInt64, /*first=*/ nullptr, /*second=*/ nullptr, ComparisonBias::kNoBias, dex_pc); |
| 1699 | break; |
| 1700 | case Intrinsics::kIntegerSignum: |
| 1701 | instruction = new (allocator_) HCompare( |
| 1702 | kInt32, /*first=*/ nullptr, graph_->GetIntConstant(0), ComparisonBias::kNoBias, dex_pc); |
| 1703 | break; |
| 1704 | case Intrinsics::kLongSignum: |
| 1705 | instruction = new (allocator_) HCompare( |
| 1706 | kInt64, /*first=*/ nullptr, graph_->GetLongConstant(0), ComparisonBias::kNoBias, dex_pc); |
| 1707 | break; |
| 1708 | case Intrinsics::kFloatIsNaN: |
| 1709 | case Intrinsics::kDoubleIsNaN: { |
| 1710 | // IsNaN(x) is the same as x != x. |
| 1711 | instruction = new (allocator_) HNotEqual(/*first=*/ nullptr, /*second=*/ nullptr, dex_pc); |
| 1712 | instruction->AsCondition()->SetBias(ComparisonBias::kLtBias); |
| 1713 | break; |
| 1714 | } |
| 1715 | case Intrinsics::kStringCharAt: |
| 1716 | // We treat String as an array to allow DCE and BCE to seamlessly work on strings. |
| 1717 | instruction = new (allocator_) HArrayGet(/*array=*/ nullptr, |
| 1718 | /*index=*/ nullptr, |
| 1719 | DataType::Type::kUint16, |
| 1720 | SideEffects::None(), // Strings are immutable. |
| 1721 | dex_pc, |
| 1722 | /*is_string_char_at=*/ true); |
| 1723 | break; |
| 1724 | case Intrinsics::kStringIsEmpty: |
| 1725 | case Intrinsics::kStringLength: |
| 1726 | // We treat String as an array to allow DCE and BCE to seamlessly work on strings. |
| 1727 | // For String.isEmpty(), we add a comparison with 0 below. |
| 1728 | instruction = |
| 1729 | new (allocator_) HArrayLength(/*array=*/ nullptr, dex_pc, /* is_string_length= */ true); |
| 1730 | break; |
| 1731 | case Intrinsics::kUnsafeLoadFence: |
| 1732 | receiver_arg = ReceiverArg::kNullCheckedOnly; |
| 1733 | instruction = new (allocator_) HMemoryBarrier(MemBarrierKind::kLoadAny, dex_pc); |
| 1734 | break; |
| 1735 | case Intrinsics::kUnsafeStoreFence: |
| 1736 | receiver_arg = ReceiverArg::kNullCheckedOnly; |
| 1737 | instruction = new (allocator_) HMemoryBarrier(MemBarrierKind::kAnyStore, dex_pc); |
| 1738 | break; |
| 1739 | case Intrinsics::kUnsafeFullFence: |
| 1740 | receiver_arg = ReceiverArg::kNullCheckedOnly; |
| 1741 | instruction = new (allocator_) HMemoryBarrier(MemBarrierKind::kAnyAny, dex_pc); |
| 1742 | break; |
| 1743 | case Intrinsics::kVarHandleFullFence: |
| 1744 | instruction = new (allocator_) HMemoryBarrier(MemBarrierKind::kAnyAny, dex_pc); |
| 1745 | break; |
| 1746 | case Intrinsics::kVarHandleAcquireFence: |
| 1747 | instruction = new (allocator_) HMemoryBarrier(MemBarrierKind::kLoadAny, dex_pc); |
| 1748 | break; |
| 1749 | case Intrinsics::kVarHandleReleaseFence: |
| 1750 | instruction = new (allocator_) HMemoryBarrier(MemBarrierKind::kAnyStore, dex_pc); |
| 1751 | break; |
| 1752 | case Intrinsics::kVarHandleLoadLoadFence: |
| 1753 | instruction = new (allocator_) HMemoryBarrier(MemBarrierKind::kLoadAny, dex_pc); |
| 1754 | break; |
| 1755 | case Intrinsics::kVarHandleStoreStoreFence: |
| 1756 | instruction = new (allocator_) HMemoryBarrier(MemBarrierKind::kStoreStore, dex_pc); |
| 1757 | break; |
| 1758 | case Intrinsics::kMathMinIntInt: |
| 1759 | instruction = new (allocator_) HMin(kInt32, /*left=*/ nullptr, /*right=*/ nullptr, dex_pc); |
| 1760 | break; |
| 1761 | case Intrinsics::kMathMinLongLong: |
| 1762 | instruction = new (allocator_) HMin(kInt64, /*left=*/ nullptr, /*right=*/ nullptr, dex_pc); |
| 1763 | break; |
| 1764 | case Intrinsics::kMathMinFloatFloat: |
| 1765 | instruction = new (allocator_) HMin(kFloat32, /*left=*/ nullptr, /*right=*/ nullptr, dex_pc); |
| 1766 | break; |
| 1767 | case Intrinsics::kMathMinDoubleDouble: |
| 1768 | instruction = new (allocator_) HMin(kFloat64, /*left=*/ nullptr, /*right=*/ nullptr, dex_pc); |
| 1769 | break; |
| 1770 | case Intrinsics::kMathMaxIntInt: |
| 1771 | instruction = new (allocator_) HMax(kInt32, /*left=*/ nullptr, /*right=*/ nullptr, dex_pc); |
| 1772 | break; |
| 1773 | case Intrinsics::kMathMaxLongLong: |
| 1774 | instruction = new (allocator_) HMax(kInt64, /*left=*/ nullptr, /*right=*/ nullptr, dex_pc); |
| 1775 | break; |
| 1776 | case Intrinsics::kMathMaxFloatFloat: |
| 1777 | instruction = new (allocator_) HMax(kFloat32, /*left=*/ nullptr, /*right=*/ nullptr, dex_pc); |
| 1778 | break; |
| 1779 | case Intrinsics::kMathMaxDoubleDouble: |
| 1780 | instruction = new (allocator_) HMax(kFloat64, /*left=*/ nullptr, /*right=*/ nullptr, dex_pc); |
| 1781 | break; |
| 1782 | case Intrinsics::kMathAbsInt: |
| 1783 | instruction = new (allocator_) HAbs(kInt32, /*input=*/ nullptr, dex_pc); |
| 1784 | break; |
| 1785 | case Intrinsics::kMathAbsLong: |
| 1786 | instruction = new (allocator_) HAbs(kInt64, /*input=*/ nullptr, dex_pc); |
| 1787 | break; |
| 1788 | case Intrinsics::kMathAbsFloat: |
| 1789 | instruction = new (allocator_) HAbs(kFloat32, /*input=*/ nullptr, dex_pc); |
| 1790 | break; |
| 1791 | case Intrinsics::kMathAbsDouble: |
| 1792 | instruction = new (allocator_) HAbs(kFloat64, /*input=*/ nullptr, dex_pc); |
| 1793 | break; |
| 1794 | default: |
| 1795 | // We do not have intermediate representation for other intrinsics. |
| 1796 | return false; |
| 1797 | } |
| 1798 | DCHECK(instruction != nullptr); |
| 1799 | if (!SetupInvokeArguments(instruction, operands, shorty, receiver_arg)) { |
| 1800 | return false; |
| 1801 | } |
| 1802 | |
| 1803 | switch (intrinsic) { |
| 1804 | case Intrinsics::kIntegerRotateLeft: |
| 1805 | case Intrinsics::kLongRotateLeft: { |
| 1806 | // Negate the distance value for rotate left. |
| 1807 | DCHECK(instruction->IsRor()); |
| 1808 | HNeg* neg = new (allocator_) HNeg(kInt32, instruction->InputAt(1u)); |
| 1809 | AppendInstruction(neg); |
| 1810 | instruction->SetRawInputAt(1u, neg); |
| 1811 | break; |
| 1812 | } |
| 1813 | case Intrinsics::kFloatIsNaN: |
| 1814 | case Intrinsics::kDoubleIsNaN: |
| 1815 | // Set the second input to be the same as first. |
| 1816 | DCHECK(instruction->IsNotEqual()); |
| 1817 | DCHECK(instruction->InputAt(1u) == nullptr); |
| 1818 | instruction->SetRawInputAt(1u, instruction->InputAt(0u)); |
| 1819 | break; |
| 1820 | case Intrinsics::kStringCharAt: { |
| 1821 | // Add bounds check. |
| 1822 | HInstruction* array = instruction->InputAt(0u); |
| 1823 | HInstruction* index = instruction->InputAt(1u); |
| 1824 | HInstruction* length = |
| 1825 | new (allocator_) HArrayLength(array, dex_pc, /*is_string_length=*/ true); |
| 1826 | AppendInstruction(length); |
| 1827 | HBoundsCheck* bounds_check = |
| 1828 | new (allocator_) HBoundsCheck(index, length, dex_pc, /*is_string_char_at=*/ true); |
| 1829 | AppendInstruction(bounds_check); |
| 1830 | graph_->SetHasBoundsChecks(true); |
| 1831 | instruction->SetRawInputAt(1u, bounds_check); |
| 1832 | break; |
| 1833 | } |
| 1834 | case Intrinsics::kStringIsEmpty: { |
| 1835 | // Compare the length with 0. |
| 1836 | DCHECK(instruction->IsArrayLength()); |
| 1837 | AppendInstruction(instruction); |
| 1838 | HEqual* equal = new (allocator_) HEqual(instruction, graph_->GetIntConstant(0), dex_pc); |
| 1839 | instruction = equal; |
| 1840 | break; |
| 1841 | } |
| 1842 | default: |
| 1843 | break; |
| 1844 | } |
| 1845 | |
| 1846 | AppendInstruction(instruction); |
| 1847 | latest_result_ = instruction; |
| 1848 | |
| 1849 | return true; |
| 1850 | } |
| 1851 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1852 | bool HInstructionBuilder::HandleStringInit(HInvoke* invoke, |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 1853 | const InstructionOperands& operands, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1854 | const char* shorty) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1855 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 1856 | DCHECK(invoke->AsInvokeStaticOrDirect()->IsStringInit()); |
| 1857 | |
Vladimir Marko | 5f84607 | 2020-04-09 13:20:11 +0100 | [diff] [blame] | 1858 | if (!SetupInvokeArguments(invoke, operands, shorty, ReceiverArg::kIgnored)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1859 | return false; |
| 1860 | } |
| 1861 | |
| 1862 | AppendInstruction(invoke); |
| 1863 | |
| 1864 | // This is a StringFactory call, not an actual String constructor. Its result |
| 1865 | // replaces the empty String pre-allocated by NewInstance. |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 1866 | uint32_t orig_this_reg = operands.GetOperand(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1867 | HInstruction* arg_this = LoadLocal(orig_this_reg, DataType::Type::kReference); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1868 | |
| 1869 | // Replacing the NewInstance might render it redundant. Keep a list of these |
Nicolas Geoffray | 8a62a4c | 2018-07-03 09:39:07 +0100 | [diff] [blame] | 1870 | // to be visited once it is clear whether it has remaining uses. |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1871 | if (arg_this->IsNewInstance()) { |
| 1872 | ssa_builder_->AddUninitializedString(arg_this->AsNewInstance()); |
Nicolas Geoffray | 8a62a4c | 2018-07-03 09:39:07 +0100 | [diff] [blame] | 1873 | } else { |
| 1874 | DCHECK(arg_this->IsPhi()); |
| 1875 | // We can get a phi as input of a String.<init> if there is a loop between the |
| 1876 | // allocation and the String.<init> call. As we don't know which other phis might alias |
Nicolas Geoffray | 0846a8f | 2018-09-12 15:21:07 +0100 | [diff] [blame] | 1877 | // with `arg_this`, we keep a record of those invocations so we can later replace |
| 1878 | // the allocation with the invocation. |
| 1879 | // Add the actual 'this' input so the analysis knows what is the allocation instruction. |
| 1880 | // The input will be removed during the analysis. |
| 1881 | invoke->AddInput(arg_this); |
| 1882 | ssa_builder_->AddUninitializedStringPhi(invoke); |
| 1883 | } |
| 1884 | // Walk over all vregs and replace any occurrence of `arg_this` with `invoke`. |
| 1885 | for (size_t vreg = 0, e = current_locals_->size(); vreg < e; ++vreg) { |
| 1886 | if ((*current_locals_)[vreg] == arg_this) { |
| 1887 | (*current_locals_)[vreg] = invoke; |
| 1888 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1889 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1890 | return true; |
| 1891 | } |
| 1892 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1893 | static DataType::Type GetFieldAccessType(const DexFile& dex_file, uint16_t field_index) { |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 1894 | const dex::FieldId& field_id = dex_file.GetFieldId(field_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1895 | const char* type = dex_file.GetFieldTypeDescriptor(field_id); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1896 | return DataType::FromShorty(type[0]); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | bool HInstructionBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
| 1900 | uint32_t dex_pc, |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 1901 | bool is_put, |
| 1902 | size_t quicken_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1903 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 1904 | uint32_t obj_reg = instruction.VRegB_22c(); |
| 1905 | uint16_t field_index; |
| 1906 | if (instruction.IsQuickened()) { |
| 1907 | if (!CanDecodeQuickenedInfo()) { |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame] | 1908 | VLOG(compiler) << "Not compiled: Could not decode quickened instruction " |
| 1909 | << instruction.Opcode(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1910 | return false; |
| 1911 | } |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 1912 | field_index = LookupQuickenedInfo(quicken_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1913 | } else { |
| 1914 | field_index = instruction.VRegC_22c(); |
| 1915 | } |
| 1916 | |
| 1917 | ScopedObjectAccess soa(Thread::Current()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1918 | ArtField* resolved_field = ResolveField(field_index, /* is_static= */ false, is_put); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1919 | |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 1920 | // Generate an explicit null check on the reference, unless the field access |
| 1921 | // is unresolved. In that case, we rely on the runtime to perform various |
| 1922 | // checks first, followed by a null check. |
| 1923 | HInstruction* object = (resolved_field == nullptr) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1924 | ? LoadLocal(obj_reg, DataType::Type::kReference) |
Aart Bik | 1415413 | 2016-06-02 17:53:58 -0700 | [diff] [blame] | 1925 | : LoadNullCheckedLocal(obj_reg, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1926 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1927 | DataType::Type field_type = GetFieldAccessType(*dex_file_, field_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1928 | if (is_put) { |
| 1929 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 1930 | HInstruction* field_set = nullptr; |
| 1931 | if (resolved_field == nullptr) { |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 1932 | MaybeRecordStat(compilation_stats_, |
| 1933 | MethodCompilationStat::kUnresolvedField); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1934 | field_set = new (allocator_) HUnresolvedInstanceFieldSet(object, |
| 1935 | value, |
| 1936 | field_type, |
| 1937 | field_index, |
| 1938 | dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1939 | } else { |
| 1940 | uint16_t class_def_index = resolved_field->GetDeclaringClass()->GetDexClassDefIndex(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1941 | field_set = new (allocator_) HInstanceFieldSet(object, |
| 1942 | value, |
| 1943 | resolved_field, |
| 1944 | field_type, |
| 1945 | resolved_field->GetOffset(), |
| 1946 | resolved_field->IsVolatile(), |
| 1947 | field_index, |
| 1948 | class_def_index, |
| 1949 | *dex_file_, |
| 1950 | dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1951 | } |
| 1952 | AppendInstruction(field_set); |
| 1953 | } else { |
| 1954 | HInstruction* field_get = nullptr; |
| 1955 | if (resolved_field == nullptr) { |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 1956 | MaybeRecordStat(compilation_stats_, |
| 1957 | MethodCompilationStat::kUnresolvedField); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1958 | field_get = new (allocator_) HUnresolvedInstanceFieldGet(object, |
| 1959 | field_type, |
| 1960 | field_index, |
| 1961 | dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1962 | } else { |
| 1963 | uint16_t class_def_index = resolved_field->GetDeclaringClass()->GetDexClassDefIndex(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1964 | field_get = new (allocator_) HInstanceFieldGet(object, |
| 1965 | resolved_field, |
| 1966 | field_type, |
| 1967 | resolved_field->GetOffset(), |
| 1968 | resolved_field->IsVolatile(), |
| 1969 | field_index, |
| 1970 | class_def_index, |
| 1971 | *dex_file_, |
| 1972 | dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1973 | } |
| 1974 | AppendInstruction(field_get); |
| 1975 | UpdateLocal(source_or_dest_reg, field_get); |
| 1976 | } |
| 1977 | |
| 1978 | return true; |
| 1979 | } |
| 1980 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1981 | void HInstructionBuilder::BuildUnresolvedStaticFieldAccess(const Instruction& instruction, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 1982 | uint32_t dex_pc, |
| 1983 | bool is_put, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1984 | DataType::Type field_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1985 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1986 | uint16_t field_index = instruction.VRegB_21c(); |
| 1987 | |
| 1988 | if (is_put) { |
| 1989 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 1990 | AppendInstruction( |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1991 | new (allocator_) HUnresolvedStaticFieldSet(value, field_type, field_index, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1992 | } else { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1993 | AppendInstruction(new (allocator_) HUnresolvedStaticFieldGet(field_type, field_index, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 1994 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 1995 | } |
| 1996 | } |
| 1997 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 1998 | ArtField* HInstructionBuilder::ResolveField(uint16_t field_idx, bool is_static, bool is_put) { |
| 1999 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2000 | |
| 2001 | ClassLinker* class_linker = dex_compilation_unit_->GetClassLinker(); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 2002 | Handle<mirror::ClassLoader> class_loader = dex_compilation_unit_->GetClassLoader(); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2003 | |
Vladimir Marko | e11dd50 | 2017-12-08 14:09:45 +0000 | [diff] [blame] | 2004 | ArtField* resolved_field = class_linker->ResolveField(field_idx, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2005 | dex_compilation_unit_->GetDexCache(), |
| 2006 | class_loader, |
| 2007 | is_static); |
Nicolas Geoffray | f368882 | 2020-03-25 15:04:03 +0000 | [diff] [blame] | 2008 | DCHECK_EQ(resolved_field == nullptr, soa.Self()->IsExceptionPending()) |
| 2009 | << "field=" |
| 2010 | << ((resolved_field == nullptr) ? "null" : resolved_field->PrettyField()) |
| 2011 | << ", exception=" |
| 2012 | << (soa.Self()->IsExceptionPending() ? soa.Self()->GetException()->Dump() : "null"); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2013 | if (UNLIKELY(resolved_field == nullptr)) { |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 2014 | // Clean up any exception left by field resolution. |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2015 | soa.Self()->ClearException(); |
| 2016 | return nullptr; |
| 2017 | } |
| 2018 | |
| 2019 | // Check static/instance. The class linker has a fast path for looking into the dex cache |
| 2020 | // and does not check static/instance if it hits it. |
| 2021 | if (UNLIKELY(resolved_field->IsStatic() != is_static)) { |
| 2022 | return nullptr; |
| 2023 | } |
| 2024 | |
| 2025 | // Check access. |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 2026 | Handle<mirror::Class> compiling_class = dex_compilation_unit_->GetCompilingClass(); |
Andreas Gampe | fa4333d | 2017-02-14 11:10:34 -0800 | [diff] [blame] | 2027 | if (compiling_class == nullptr) { |
Vladimir Marko | 4100e5e | 2020-08-26 16:44:01 +0100 | [diff] [blame] | 2028 | // Check if the declaring class or referencing class is accessible. |
| 2029 | SamePackageCompare same_package(*dex_compilation_unit_); |
| 2030 | ObjPtr<mirror::Class> declaring_class = resolved_field->GetDeclaringClass(); |
| 2031 | bool declaring_class_accessible = declaring_class->IsPublic() || same_package(declaring_class); |
| 2032 | if (!declaring_class_accessible) { |
| 2033 | // It is possible to access members from an inaccessible superclass |
| 2034 | // by referencing them through an accessible subclass. |
| 2035 | ObjPtr<mirror::Class> referenced_class = class_linker->LookupResolvedType( |
| 2036 | dex_compilation_unit_->GetDexFile()->GetFieldId(field_idx).class_idx_, |
| 2037 | dex_compilation_unit_->GetDexCache().Get(), |
| 2038 | class_loader.Get()); |
| 2039 | DCHECK(referenced_class != nullptr); // Must have been resolved when resolving the field. |
| 2040 | if (!referenced_class->IsPublic() && !same_package(referenced_class)) { |
| 2041 | return nullptr; |
| 2042 | } |
| 2043 | } |
| 2044 | // Check whether the field itself is accessible. |
| 2045 | // Since the referrer is unresolved but the field is resolved, it cannot be |
| 2046 | // inside the same class, so a private field is known to be inaccessible. |
| 2047 | // And without a resolved referrer, we cannot check for protected member access |
| 2048 | // in superlass, so we handle only access to public member or within the package. |
| 2049 | if (resolved_field->IsPrivate() || |
| 2050 | (!resolved_field->IsPublic() && !declaring_class_accessible)) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2051 | return nullptr; |
| 2052 | } |
| 2053 | } else if (!compiling_class->CanAccessResolvedField(resolved_field->GetDeclaringClass(), |
| 2054 | resolved_field, |
| 2055 | dex_compilation_unit_->GetDexCache().Get(), |
| 2056 | field_idx)) { |
| 2057 | return nullptr; |
| 2058 | } |
| 2059 | |
| 2060 | if (is_put && |
| 2061 | resolved_field->IsFinal() && |
| 2062 | (compiling_class.Get() != resolved_field->GetDeclaringClass())) { |
| 2063 | // Final fields can only be updated within their own class. |
| 2064 | // TODO: Only allow it in constructors. b/34966607. |
| 2065 | return nullptr; |
| 2066 | } |
| 2067 | |
Nicolas Geoffray | 396198b | 2020-06-16 12:02:45 +0100 | [diff] [blame] | 2068 | StackArtFieldHandleScope<1> rhs(soa.Self()); |
| 2069 | ReflectiveHandle<ArtField> resolved_field_handle(rhs.NewHandle(resolved_field)); |
| 2070 | if (resolved_field->ResolveType().IsNull()) { |
| 2071 | // ArtField::ResolveType() may fail as evidenced with a dexing bug (b/78788577). |
| 2072 | soa.Self()->ClearException(); |
| 2073 | return nullptr; // Failure |
| 2074 | } |
| 2075 | return resolved_field_handle.Get(); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame] | 2078 | void HInstructionBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2079 | uint32_t dex_pc, |
| 2080 | bool is_put) { |
| 2081 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 2082 | uint16_t field_index = instruction.VRegB_21c(); |
| 2083 | |
| 2084 | ScopedObjectAccess soa(Thread::Current()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2085 | ArtField* resolved_field = ResolveField(field_index, /* is_static= */ true, is_put); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2086 | |
| 2087 | if (resolved_field == nullptr) { |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 2088 | MaybeRecordStat(compilation_stats_, |
| 2089 | MethodCompilationStat::kUnresolvedField); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2090 | DataType::Type field_type = GetFieldAccessType(*dex_file_, field_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2091 | BuildUnresolvedStaticFieldAccess(instruction, dex_pc, is_put, field_type); |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame] | 2092 | return; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2095 | DataType::Type field_type = GetFieldAccessType(*dex_file_, field_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2096 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 2097 | Handle<mirror::Class> klass = |
| 2098 | graph_->GetHandleCache()->NewHandle(resolved_field->GetDeclaringClass()); |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 2099 | HLoadClass* constant = BuildLoadClass(klass->GetDexTypeIndex(), |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2100 | klass->GetDexFile(), |
| 2101 | klass, |
| 2102 | dex_pc, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2103 | /* needs_access_check= */ false); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2104 | |
| 2105 | if (constant == nullptr) { |
| 2106 | // The class cannot be referenced from this compiled code. Generate |
| 2107 | // an unresolved access. |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 2108 | MaybeRecordStat(compilation_stats_, |
| 2109 | MethodCompilationStat::kUnresolvedFieldNotAFastAccess); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2110 | BuildUnresolvedStaticFieldAccess(instruction, dex_pc, is_put, field_type); |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame] | 2111 | return; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2112 | } |
| 2113 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2114 | HInstruction* cls = constant; |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 2115 | if (!IsInitialized(klass.Get())) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2116 | cls = new (allocator_) HClinitCheck(constant, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2117 | AppendInstruction(cls); |
| 2118 | } |
| 2119 | |
| 2120 | uint16_t class_def_index = klass->GetDexClassDefIndex(); |
| 2121 | if (is_put) { |
| 2122 | // We need to keep the class alive before loading the value. |
| 2123 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 2124 | DCHECK_EQ(HPhi::ToPhiType(value->GetType()), HPhi::ToPhiType(field_type)); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2125 | AppendInstruction(new (allocator_) HStaticFieldSet(cls, |
| 2126 | value, |
| 2127 | resolved_field, |
| 2128 | field_type, |
| 2129 | resolved_field->GetOffset(), |
| 2130 | resolved_field->IsVolatile(), |
| 2131 | field_index, |
| 2132 | class_def_index, |
| 2133 | *dex_file_, |
| 2134 | dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2135 | } else { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2136 | AppendInstruction(new (allocator_) HStaticFieldGet(cls, |
| 2137 | resolved_field, |
| 2138 | field_type, |
| 2139 | resolved_field->GetOffset(), |
| 2140 | resolved_field->IsVolatile(), |
| 2141 | field_index, |
| 2142 | class_def_index, |
| 2143 | *dex_file_, |
| 2144 | dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2145 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 2146 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | void HInstructionBuilder::BuildCheckedDivRem(uint16_t out_vreg, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2150 | uint16_t first_vreg, |
| 2151 | int64_t second_vreg_or_constant, |
| 2152 | uint32_t dex_pc, |
| 2153 | DataType::Type type, |
| 2154 | bool second_is_constant, |
| 2155 | bool isDiv) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2156 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2157 | |
| 2158 | HInstruction* first = LoadLocal(first_vreg, type); |
| 2159 | HInstruction* second = nullptr; |
| 2160 | if (second_is_constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2161 | if (type == DataType::Type::kInt32) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2162 | second = graph_->GetIntConstant(second_vreg_or_constant, dex_pc); |
| 2163 | } else { |
| 2164 | second = graph_->GetLongConstant(second_vreg_or_constant, dex_pc); |
| 2165 | } |
| 2166 | } else { |
| 2167 | second = LoadLocal(second_vreg_or_constant, type); |
| 2168 | } |
| 2169 | |
| 2170 | if (!second_is_constant |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2171 | || (type == DataType::Type::kInt32 && second->AsIntConstant()->GetValue() == 0) |
| 2172 | || (type == DataType::Type::kInt64 && second->AsLongConstant()->GetValue() == 0)) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2173 | second = new (allocator_) HDivZeroCheck(second, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2174 | AppendInstruction(second); |
| 2175 | } |
| 2176 | |
| 2177 | if (isDiv) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2178 | AppendInstruction(new (allocator_) HDiv(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2179 | } else { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2180 | AppendInstruction(new (allocator_) HRem(type, first, second, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2181 | } |
| 2182 | UpdateLocal(out_vreg, current_block_->GetLastInstruction()); |
| 2183 | } |
| 2184 | |
| 2185 | void HInstructionBuilder::BuildArrayAccess(const Instruction& instruction, |
| 2186 | uint32_t dex_pc, |
| 2187 | bool is_put, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2188 | DataType::Type anticipated_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2189 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 2190 | uint8_t array_reg = instruction.VRegB_23x(); |
| 2191 | uint8_t index_reg = instruction.VRegC_23x(); |
| 2192 | |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 2193 | HInstruction* object = LoadNullCheckedLocal(array_reg, dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2194 | HInstruction* length = new (allocator_) HArrayLength(object, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2195 | AppendInstruction(length); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2196 | HInstruction* index = LoadLocal(index_reg, DataType::Type::kInt32); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2197 | index = new (allocator_) HBoundsCheck(index, length, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2198 | AppendInstruction(index); |
| 2199 | if (is_put) { |
| 2200 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type); |
| 2201 | // TODO: Insert a type check node if the type is Object. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2202 | HArraySet* aset = new (allocator_) HArraySet(object, index, value, anticipated_type, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2203 | ssa_builder_->MaybeAddAmbiguousArraySet(aset); |
| 2204 | AppendInstruction(aset); |
| 2205 | } else { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2206 | HArrayGet* aget = new (allocator_) HArrayGet(object, index, anticipated_type, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2207 | ssa_builder_->MaybeAddAmbiguousArrayGet(aget); |
| 2208 | AppendInstruction(aget); |
| 2209 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 2210 | } |
| 2211 | graph_->SetHasBoundsChecks(true); |
| 2212 | } |
| 2213 | |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 2214 | HNewArray* HInstructionBuilder::BuildNewArray(uint32_t dex_pc, |
| 2215 | dex::TypeIndex type_index, |
| 2216 | HInstruction* length) { |
| 2217 | HLoadClass* cls = BuildLoadClass(type_index, dex_pc); |
| 2218 | |
| 2219 | const char* descriptor = dex_file_->GetTypeDescriptor(dex_file_->GetTypeId(type_index)); |
| 2220 | DCHECK_EQ(descriptor[0], '['); |
| 2221 | size_t component_type_shift = Primitive::ComponentSizeShift(Primitive::GetType(descriptor[1])); |
| 2222 | |
| 2223 | HNewArray* new_array = new (allocator_) HNewArray(cls, length, dex_pc, component_type_shift); |
| 2224 | AppendInstruction(new_array); |
| 2225 | return new_array; |
| 2226 | } |
| 2227 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 2228 | HNewArray* HInstructionBuilder::BuildFilledNewArray(uint32_t dex_pc, |
| 2229 | dex::TypeIndex type_index, |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 2230 | const InstructionOperands& operands) { |
| 2231 | const size_t number_of_operands = operands.GetNumberOfOperands(); |
| 2232 | HInstruction* length = graph_->GetIntConstant(number_of_operands, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2233 | |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 2234 | HNewArray* new_array = BuildNewArray(dex_pc, type_index, length); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2235 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 2236 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 2237 | char primitive = descriptor[1]; |
| 2238 | DCHECK(primitive == 'I' |
| 2239 | || primitive == 'L' |
| 2240 | || primitive == '[') << descriptor; |
| 2241 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2242 | DataType::Type type = is_reference_array ? DataType::Type::kReference : DataType::Type::kInt32; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2243 | |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 2244 | for (size_t i = 0; i < number_of_operands; ++i) { |
| 2245 | HInstruction* value = LoadLocal(operands.GetOperand(i), type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2246 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 2247 | HArraySet* aset = new (allocator_) HArraySet(new_array, index, value, type, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2248 | ssa_builder_->MaybeAddAmbiguousArraySet(aset); |
| 2249 | AppendInstruction(aset); |
| 2250 | } |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 2251 | latest_result_ = new_array; |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 2252 | |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 2253 | return new_array; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | template <typename T> |
| 2257 | void HInstructionBuilder::BuildFillArrayData(HInstruction* object, |
| 2258 | const T* data, |
| 2259 | uint32_t element_count, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2260 | DataType::Type anticipated_type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2261 | uint32_t dex_pc) { |
| 2262 | for (uint32_t i = 0; i < element_count; ++i) { |
| 2263 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
| 2264 | HInstruction* value = graph_->GetIntConstant(data[i], dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2265 | HArraySet* aset = new (allocator_) HArraySet(object, index, value, anticipated_type, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2266 | ssa_builder_->MaybeAddAmbiguousArraySet(aset); |
| 2267 | AppendInstruction(aset); |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | void HInstructionBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) { |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 2272 | HInstruction* array = LoadNullCheckedLocal(instruction.VRegA_31t(), dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2273 | |
| 2274 | int32_t payload_offset = instruction.VRegB_31t() + dex_pc; |
| 2275 | const Instruction::ArrayDataPayload* payload = |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 2276 | reinterpret_cast<const Instruction::ArrayDataPayload*>( |
| 2277 | code_item_accessor_.Insns() + payload_offset); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2278 | const uint8_t* data = payload->data; |
| 2279 | uint32_t element_count = payload->element_count; |
| 2280 | |
Vladimir Marko | c69fba2 | 2016-09-06 16:49:15 +0100 | [diff] [blame] | 2281 | if (element_count == 0u) { |
| 2282 | // For empty payload we emit only the null check above. |
| 2283 | return; |
| 2284 | } |
| 2285 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2286 | HInstruction* length = new (allocator_) HArrayLength(array, dex_pc); |
Vladimir Marko | c69fba2 | 2016-09-06 16:49:15 +0100 | [diff] [blame] | 2287 | AppendInstruction(length); |
| 2288 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2289 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 2290 | // done before doing any stores. |
| 2291 | HInstruction* last_index = graph_->GetIntConstant(payload->element_count - 1, dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2292 | AppendInstruction(new (allocator_) HBoundsCheck(last_index, length, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2293 | |
| 2294 | switch (payload->element_width) { |
| 2295 | case 1: |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 2296 | BuildFillArrayData(array, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2297 | reinterpret_cast<const int8_t*>(data), |
| 2298 | element_count, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2299 | DataType::Type::kInt8, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2300 | dex_pc); |
| 2301 | break; |
| 2302 | case 2: |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 2303 | BuildFillArrayData(array, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2304 | reinterpret_cast<const int16_t*>(data), |
| 2305 | element_count, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2306 | DataType::Type::kInt16, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2307 | dex_pc); |
| 2308 | break; |
| 2309 | case 4: |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 2310 | BuildFillArrayData(array, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2311 | reinterpret_cast<const int32_t*>(data), |
| 2312 | element_count, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2313 | DataType::Type::kInt32, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2314 | dex_pc); |
| 2315 | break; |
| 2316 | case 8: |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 2317 | BuildFillWideArrayData(array, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2318 | reinterpret_cast<const int64_t*>(data), |
| 2319 | element_count, |
| 2320 | dex_pc); |
| 2321 | break; |
| 2322 | default: |
| 2323 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 2324 | } |
| 2325 | graph_->SetHasBoundsChecks(true); |
| 2326 | } |
| 2327 | |
| 2328 | void HInstructionBuilder::BuildFillWideArrayData(HInstruction* object, |
| 2329 | const int64_t* data, |
| 2330 | uint32_t element_count, |
| 2331 | uint32_t dex_pc) { |
| 2332 | for (uint32_t i = 0; i < element_count; ++i) { |
| 2333 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
| 2334 | HInstruction* value = graph_->GetLongConstant(data[i], dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2335 | HArraySet* aset = |
| 2336 | new (allocator_) HArraySet(object, index, value, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2337 | ssa_builder_->MaybeAddAmbiguousArraySet(aset); |
| 2338 | AppendInstruction(aset); |
| 2339 | } |
| 2340 | } |
| 2341 | |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 2342 | void HInstructionBuilder::BuildLoadString(dex::StringIndex string_index, uint32_t dex_pc) { |
| 2343 | HLoadString* load_string = |
| 2344 | new (allocator_) HLoadString(graph_->GetCurrentMethod(), string_index, *dex_file_, dex_pc); |
| 2345 | HSharpening::ProcessLoadString(load_string, |
| 2346 | code_generator_, |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 2347 | *dex_compilation_unit_, |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 2348 | graph_->GetHandleCache()->GetHandles()); |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 2349 | AppendInstruction(load_string); |
| 2350 | } |
| 2351 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2352 | HLoadClass* HInstructionBuilder::BuildLoadClass(dex::TypeIndex type_index, uint32_t dex_pc) { |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 2353 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2354 | const DexFile& dex_file = *dex_compilation_unit_->GetDexFile(); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2355 | Handle<mirror::Class> klass = ResolveClass(soa, type_index); |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 2356 | bool needs_access_check = LoadClassNeedsAccessCheck(klass.Get()); |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 2357 | return BuildLoadClass(type_index, dex_file, klass, dex_pc, needs_access_check); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 2360 | HLoadClass* HInstructionBuilder::BuildLoadClass(dex::TypeIndex type_index, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2361 | const DexFile& dex_file, |
| 2362 | Handle<mirror::Class> klass, |
| 2363 | uint32_t dex_pc, |
| 2364 | bool needs_access_check) { |
| 2365 | // Try to find a reference in the compiling dex file. |
| 2366 | const DexFile* actual_dex_file = &dex_file; |
| 2367 | if (!IsSameDexFile(dex_file, *dex_compilation_unit_->GetDexFile())) { |
| 2368 | dex::TypeIndex local_type_index = |
| 2369 | klass->FindTypeIndexInOtherDexFile(*dex_compilation_unit_->GetDexFile()); |
| 2370 | if (local_type_index.IsValid()) { |
| 2371 | type_index = local_type_index; |
| 2372 | actual_dex_file = dex_compilation_unit_->GetDexFile(); |
| 2373 | } |
| 2374 | } |
| 2375 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 2376 | // Note: `klass` must be from `graph_->GetHandleCache()`. |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 2377 | bool is_referrers_class = |
| 2378 | (klass != nullptr) && (outer_compilation_unit_->GetCompilingClass().Get() == klass.Get()); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2379 | HLoadClass* load_class = new (allocator_) HLoadClass( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 2380 | graph_->GetCurrentMethod(), |
| 2381 | type_index, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2382 | *actual_dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 2383 | klass, |
Vladimir Marko | fca0b49 | 2018-07-23 15:30:52 +0100 | [diff] [blame] | 2384 | is_referrers_class, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 2385 | dex_pc, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2386 | needs_access_check); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 2387 | |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 2388 | HLoadClass::LoadKind load_kind = HSharpening::ComputeLoadClassKind(load_class, |
| 2389 | code_generator_, |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 2390 | *dex_compilation_unit_); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2391 | |
| 2392 | if (load_kind == HLoadClass::LoadKind::kInvalid) { |
| 2393 | // We actually cannot reference this class, we're forced to bail. |
| 2394 | return nullptr; |
| 2395 | } |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 2396 | // Load kind must be set before inserting the instruction into the graph. |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 2397 | load_class->SetLoadKind(load_kind); |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 2398 | AppendInstruction(load_class); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 2399 | return load_class; |
| 2400 | } |
| 2401 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2402 | Handle<mirror::Class> HInstructionBuilder::ResolveClass(ScopedObjectAccess& soa, |
| 2403 | dex::TypeIndex type_index) { |
Vladimir Marko | 3b50620 | 2018-10-31 14:33:58 +0000 | [diff] [blame] | 2404 | auto it = class_cache_.find(type_index); |
| 2405 | if (it != class_cache_.end()) { |
| 2406 | return it->second; |
| 2407 | } |
| 2408 | |
| 2409 | ObjPtr<mirror::Class> klass = dex_compilation_unit_->GetClassLinker()->ResolveType( |
| 2410 | type_index, dex_compilation_unit_->GetDexCache(), dex_compilation_unit_->GetClassLoader()); |
| 2411 | DCHECK_EQ(klass == nullptr, soa.Self()->IsExceptionPending()); |
| 2412 | soa.Self()->ClearException(); // Clean up the exception left by type resolution if any. |
| 2413 | |
Vladimir Marko | 02ca05a | 2020-05-12 13:58:51 +0100 | [diff] [blame] | 2414 | Handle<mirror::Class> h_klass = graph_->GetHandleCache()->NewHandle(klass); |
Vladimir Marko | 3b50620 | 2018-10-31 14:33:58 +0000 | [diff] [blame] | 2415 | class_cache_.Put(type_index, h_klass); |
| 2416 | return h_klass; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 2419 | bool HInstructionBuilder::LoadClassNeedsAccessCheck(ObjPtr<mirror::Class> klass) { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2420 | if (klass == nullptr) { |
| 2421 | return true; |
| 2422 | } else if (klass->IsPublic()) { |
| 2423 | return false; |
Vladimir Marko | 0280e5d | 2020-08-27 17:36:24 +0100 | [diff] [blame] | 2424 | } else if (dex_compilation_unit_->GetCompilingClass() != nullptr) { |
| 2425 | return !dex_compilation_unit_->GetCompilingClass()->CanAccess(klass); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2426 | } else { |
Vladimir Marko | 0280e5d | 2020-08-27 17:36:24 +0100 | [diff] [blame] | 2427 | SamePackageCompare same_package(*dex_compilation_unit_); |
| 2428 | return !same_package(klass); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2429 | } |
| 2430 | } |
| 2431 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 2432 | void HInstructionBuilder::BuildLoadMethodHandle(uint16_t method_handle_index, uint32_t dex_pc) { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 2433 | const DexFile& dex_file = *dex_compilation_unit_->GetDexFile(); |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 2434 | HLoadMethodHandle* load_method_handle = new (allocator_) HLoadMethodHandle( |
| 2435 | graph_->GetCurrentMethod(), method_handle_index, dex_file, dex_pc); |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 2436 | AppendInstruction(load_method_handle); |
| 2437 | } |
| 2438 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 2439 | void HInstructionBuilder::BuildLoadMethodType(dex::ProtoIndex proto_index, uint32_t dex_pc) { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 2440 | const DexFile& dex_file = *dex_compilation_unit_->GetDexFile(); |
| 2441 | HLoadMethodType* load_method_type = |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 2442 | new (allocator_) HLoadMethodType(graph_->GetCurrentMethod(), proto_index, dex_file, dex_pc); |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 2443 | AppendInstruction(load_method_type); |
| 2444 | } |
| 2445 | |
Andra Danciu | 49a19f3 | 2020-08-27 12:44:25 +0000 | [diff] [blame] | 2446 | void HInstructionBuilder::BuildTypeCheck(bool is_instance_of, |
| 2447 | HInstruction* object, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 2448 | dex::TypeIndex type_index, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2449 | uint32_t dex_pc) { |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 2450 | ScopedObjectAccess soa(Thread::Current()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2451 | const DexFile& dex_file = *dex_compilation_unit_->GetDexFile(); |
| 2452 | Handle<mirror::Class> klass = ResolveClass(soa, type_index); |
Vladimir Marko | 2f40d24 | 2020-04-08 12:56:45 +0100 | [diff] [blame] | 2453 | bool needs_access_check = LoadClassNeedsAccessCheck(klass.Get()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2454 | TypeCheckKind check_kind = HSharpening::ComputeTypeCheckKind( |
Vladimir Marko | dc4bcce | 2018-06-21 16:15:42 +0100 | [diff] [blame] | 2455 | klass.Get(), code_generator_, needs_access_check); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2456 | |
| 2457 | HInstruction* class_or_null = nullptr; |
| 2458 | HIntConstant* bitstring_path_to_root = nullptr; |
| 2459 | HIntConstant* bitstring_mask = nullptr; |
| 2460 | if (check_kind == TypeCheckKind::kBitstringCheck) { |
| 2461 | // TODO: Allow using the bitstring check also if we need an access check. |
| 2462 | DCHECK(!needs_access_check); |
| 2463 | class_or_null = graph_->GetNullConstant(dex_pc); |
| 2464 | MutexLock subtype_check_lock(Thread::Current(), *Locks::subtype_check_lock_); |
| 2465 | uint32_t path_to_root = |
| 2466 | SubtypeCheck<ObjPtr<mirror::Class>>::GetEncodedPathToRootForTarget(klass.Get()); |
| 2467 | uint32_t mask = SubtypeCheck<ObjPtr<mirror::Class>>::GetEncodedPathToRootMask(klass.Get()); |
| 2468 | bitstring_path_to_root = graph_->GetIntConstant(static_cast<int32_t>(path_to_root), dex_pc); |
| 2469 | bitstring_mask = graph_->GetIntConstant(static_cast<int32_t>(mask), dex_pc); |
| 2470 | } else { |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 2471 | class_or_null = BuildLoadClass(type_index, dex_file, klass, dex_pc, needs_access_check); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2472 | } |
| 2473 | DCHECK(class_or_null != nullptr); |
| 2474 | |
Andra Danciu | 49a19f3 | 2020-08-27 12:44:25 +0000 | [diff] [blame] | 2475 | if (is_instance_of) { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2476 | AppendInstruction(new (allocator_) HInstanceOf(object, |
| 2477 | class_or_null, |
| 2478 | check_kind, |
| 2479 | klass, |
| 2480 | dex_pc, |
| 2481 | allocator_, |
| 2482 | bitstring_path_to_root, |
| 2483 | bitstring_mask)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2484 | } else { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2485 | // We emit a CheckCast followed by a BoundType. CheckCast is a statement |
| 2486 | // which may throw. If it succeeds BoundType sets the new type of `object` |
| 2487 | // for all subsequent uses. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2488 | AppendInstruction( |
| 2489 | new (allocator_) HCheckCast(object, |
| 2490 | class_or_null, |
| 2491 | check_kind, |
| 2492 | klass, |
| 2493 | dex_pc, |
| 2494 | allocator_, |
| 2495 | bitstring_path_to_root, |
| 2496 | bitstring_mask)); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2497 | AppendInstruction(new (allocator_) HBoundType(object, dex_pc)); |
Andra Danciu | 49a19f3 | 2020-08-27 12:44:25 +0000 | [diff] [blame] | 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | void HInstructionBuilder::BuildTypeCheck(const Instruction& instruction, |
| 2502 | uint8_t destination, |
| 2503 | uint8_t reference, |
| 2504 | dex::TypeIndex type_index, |
| 2505 | uint32_t dex_pc) { |
| 2506 | HInstruction* object = LoadLocal(reference, DataType::Type::kReference); |
| 2507 | bool is_instance_of = instruction.Opcode() == Instruction::INSTANCE_OF; |
| 2508 | |
| 2509 | BuildTypeCheck(is_instance_of, object, type_index, dex_pc); |
| 2510 | |
| 2511 | if (is_instance_of) { |
| 2512 | UpdateLocal(destination, current_block_->GetLastInstruction()); |
| 2513 | } else { |
| 2514 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2515 | UpdateLocal(reference, current_block_->GetLastInstruction()); |
| 2516 | } |
| 2517 | } |
| 2518 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2519 | bool HInstructionBuilder::CanDecodeQuickenedInfo() const { |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 2520 | return !quicken_info_.IsNull(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 2523 | uint16_t HInstructionBuilder::LookupQuickenedInfo(uint32_t quicken_index) { |
| 2524 | DCHECK(CanDecodeQuickenedInfo()); |
| 2525 | return quicken_info_.GetData(quicken_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2526 | } |
| 2527 | |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 2528 | bool HInstructionBuilder::ProcessDexInstruction(const Instruction& instruction, |
| 2529 | uint32_t dex_pc, |
| 2530 | size_t quicken_index) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2531 | switch (instruction.Opcode()) { |
| 2532 | case Instruction::CONST_4: { |
| 2533 | int32_t register_index = instruction.VRegA(); |
| 2534 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n(), dex_pc); |
| 2535 | UpdateLocal(register_index, constant); |
| 2536 | break; |
| 2537 | } |
| 2538 | |
| 2539 | case Instruction::CONST_16: { |
| 2540 | int32_t register_index = instruction.VRegA(); |
| 2541 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21s(), dex_pc); |
| 2542 | UpdateLocal(register_index, constant); |
| 2543 | break; |
| 2544 | } |
| 2545 | |
| 2546 | case Instruction::CONST: { |
| 2547 | int32_t register_index = instruction.VRegA(); |
| 2548 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_31i(), dex_pc); |
| 2549 | UpdateLocal(register_index, constant); |
| 2550 | break; |
| 2551 | } |
| 2552 | |
| 2553 | case Instruction::CONST_HIGH16: { |
| 2554 | int32_t register_index = instruction.VRegA(); |
| 2555 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21h() << 16, dex_pc); |
| 2556 | UpdateLocal(register_index, constant); |
| 2557 | break; |
| 2558 | } |
| 2559 | |
| 2560 | case Instruction::CONST_WIDE_16: { |
| 2561 | int32_t register_index = instruction.VRegA(); |
| 2562 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 2563 | int64_t value = instruction.VRegB_21s(); |
| 2564 | value <<= 48; |
| 2565 | value >>= 48; |
| 2566 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 2567 | UpdateLocal(register_index, constant); |
| 2568 | break; |
| 2569 | } |
| 2570 | |
| 2571 | case Instruction::CONST_WIDE_32: { |
| 2572 | int32_t register_index = instruction.VRegA(); |
| 2573 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 2574 | int64_t value = instruction.VRegB_31i(); |
| 2575 | value <<= 32; |
| 2576 | value >>= 32; |
| 2577 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 2578 | UpdateLocal(register_index, constant); |
| 2579 | break; |
| 2580 | } |
| 2581 | |
| 2582 | case Instruction::CONST_WIDE: { |
| 2583 | int32_t register_index = instruction.VRegA(); |
| 2584 | HLongConstant* constant = graph_->GetLongConstant(instruction.VRegB_51l(), dex_pc); |
| 2585 | UpdateLocal(register_index, constant); |
| 2586 | break; |
| 2587 | } |
| 2588 | |
| 2589 | case Instruction::CONST_WIDE_HIGH16: { |
| 2590 | int32_t register_index = instruction.VRegA(); |
| 2591 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
| 2592 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 2593 | UpdateLocal(register_index, constant); |
| 2594 | break; |
| 2595 | } |
| 2596 | |
| 2597 | // Note that the SSA building will refine the types. |
| 2598 | case Instruction::MOVE: |
| 2599 | case Instruction::MOVE_FROM16: |
| 2600 | case Instruction::MOVE_16: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2601 | HInstruction* value = LoadLocal(instruction.VRegB(), DataType::Type::kInt32); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2602 | UpdateLocal(instruction.VRegA(), value); |
| 2603 | break; |
| 2604 | } |
| 2605 | |
| 2606 | // Note that the SSA building will refine the types. |
| 2607 | case Instruction::MOVE_WIDE: |
| 2608 | case Instruction::MOVE_WIDE_FROM16: |
| 2609 | case Instruction::MOVE_WIDE_16: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2610 | HInstruction* value = LoadLocal(instruction.VRegB(), DataType::Type::kInt64); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2611 | UpdateLocal(instruction.VRegA(), value); |
| 2612 | break; |
| 2613 | } |
| 2614 | |
| 2615 | case Instruction::MOVE_OBJECT: |
| 2616 | case Instruction::MOVE_OBJECT_16: |
| 2617 | case Instruction::MOVE_OBJECT_FROM16: { |
Nicolas Geoffray | 50a9ed0 | 2016-09-23 15:40:41 +0100 | [diff] [blame] | 2618 | // The verifier has no notion of a null type, so a move-object of constant 0 |
| 2619 | // will lead to the same constant 0 in the destination register. To mimic |
| 2620 | // this behavior, we just pretend we haven't seen a type change (int to reference) |
| 2621 | // for the 0 constant and phis. We rely on our type propagation to eventually get the |
| 2622 | // types correct. |
| 2623 | uint32_t reg_number = instruction.VRegB(); |
| 2624 | HInstruction* value = (*current_locals_)[reg_number]; |
| 2625 | if (value->IsIntConstant()) { |
| 2626 | DCHECK_EQ(value->AsIntConstant()->GetValue(), 0); |
| 2627 | } else if (value->IsPhi()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2628 | DCHECK(value->GetType() == DataType::Type::kInt32 || |
| 2629 | value->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 50a9ed0 | 2016-09-23 15:40:41 +0100 | [diff] [blame] | 2630 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2631 | value = LoadLocal(reg_number, DataType::Type::kReference); |
Nicolas Geoffray | 50a9ed0 | 2016-09-23 15:40:41 +0100 | [diff] [blame] | 2632 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2633 | UpdateLocal(instruction.VRegA(), value); |
| 2634 | break; |
| 2635 | } |
| 2636 | |
| 2637 | case Instruction::RETURN_VOID_NO_BARRIER: |
| 2638 | case Instruction::RETURN_VOID: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2639 | BuildReturn(instruction, DataType::Type::kVoid, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2640 | break; |
| 2641 | } |
| 2642 | |
| 2643 | #define IF_XX(comparison, cond) \ |
| 2644 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \ |
| 2645 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break |
| 2646 | |
| 2647 | IF_XX(HEqual, EQ); |
| 2648 | IF_XX(HNotEqual, NE); |
| 2649 | IF_XX(HLessThan, LT); |
| 2650 | IF_XX(HLessThanOrEqual, LE); |
| 2651 | IF_XX(HGreaterThan, GT); |
| 2652 | IF_XX(HGreaterThanOrEqual, GE); |
| 2653 | |
| 2654 | case Instruction::GOTO: |
| 2655 | case Instruction::GOTO_16: |
| 2656 | case Instruction::GOTO_32: { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2657 | AppendInstruction(new (allocator_) HGoto(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2658 | current_block_ = nullptr; |
| 2659 | break; |
| 2660 | } |
| 2661 | |
| 2662 | case Instruction::RETURN: { |
| 2663 | BuildReturn(instruction, return_type_, dex_pc); |
| 2664 | break; |
| 2665 | } |
| 2666 | |
| 2667 | case Instruction::RETURN_OBJECT: { |
| 2668 | BuildReturn(instruction, return_type_, dex_pc); |
| 2669 | break; |
| 2670 | } |
| 2671 | |
| 2672 | case Instruction::RETURN_WIDE: { |
| 2673 | BuildReturn(instruction, return_type_, dex_pc); |
| 2674 | break; |
| 2675 | } |
| 2676 | |
| 2677 | case Instruction::INVOKE_DIRECT: |
| 2678 | case Instruction::INVOKE_INTERFACE: |
| 2679 | case Instruction::INVOKE_STATIC: |
| 2680 | case Instruction::INVOKE_SUPER: |
| 2681 | case Instruction::INVOKE_VIRTUAL: |
| 2682 | case Instruction::INVOKE_VIRTUAL_QUICK: { |
| 2683 | uint16_t method_idx; |
| 2684 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_QUICK) { |
| 2685 | if (!CanDecodeQuickenedInfo()) { |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame] | 2686 | VLOG(compiler) << "Not compiled: Could not decode quickened instruction " |
| 2687 | << instruction.Opcode(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2688 | return false; |
| 2689 | } |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 2690 | method_idx = LookupQuickenedInfo(quicken_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2691 | } else { |
| 2692 | method_idx = instruction.VRegB_35c(); |
| 2693 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2694 | uint32_t args[5]; |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 2695 | uint32_t number_of_vreg_arguments = instruction.GetVarArgs(args); |
| 2696 | VarArgsInstructionOperands operands(args, number_of_vreg_arguments); |
| 2697 | if (!BuildInvoke(instruction, dex_pc, method_idx, operands)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2698 | return false; |
| 2699 | } |
| 2700 | break; |
| 2701 | } |
| 2702 | |
| 2703 | case Instruction::INVOKE_DIRECT_RANGE: |
| 2704 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 2705 | case Instruction::INVOKE_STATIC_RANGE: |
| 2706 | case Instruction::INVOKE_SUPER_RANGE: |
| 2707 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 2708 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: { |
| 2709 | uint16_t method_idx; |
| 2710 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK) { |
| 2711 | if (!CanDecodeQuickenedInfo()) { |
Nicolas Geoffray | dbb9aef | 2017-11-23 10:44:11 +0000 | [diff] [blame] | 2712 | VLOG(compiler) << "Not compiled: Could not decode quickened instruction " |
| 2713 | << instruction.Opcode(); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2714 | return false; |
| 2715 | } |
Mathieu Chartier | de4b08f | 2017-07-10 14:13:41 -0700 | [diff] [blame] | 2716 | method_idx = LookupQuickenedInfo(quicken_index); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2717 | } else { |
| 2718 | method_idx = instruction.VRegB_3rc(); |
| 2719 | } |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 2720 | RangeInstructionOperands operands(instruction.VRegC(), instruction.VRegA_3rc()); |
| 2721 | if (!BuildInvoke(instruction, dex_pc, method_idx, operands)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2722 | return false; |
| 2723 | } |
| 2724 | break; |
| 2725 | } |
| 2726 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2727 | case Instruction::INVOKE_POLYMORPHIC: { |
| 2728 | uint16_t method_idx = instruction.VRegB_45cc(); |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 2729 | dex::ProtoIndex proto_idx(instruction.VRegH_45cc()); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2730 | uint32_t args[5]; |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 2731 | uint32_t number_of_vreg_arguments = instruction.GetVarArgs(args); |
| 2732 | VarArgsInstructionOperands operands(args, number_of_vreg_arguments); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2733 | return BuildInvokePolymorphic(dex_pc, method_idx, proto_idx, operands); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | case Instruction::INVOKE_POLYMORPHIC_RANGE: { |
| 2737 | uint16_t method_idx = instruction.VRegB_4rcc(); |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 2738 | dex::ProtoIndex proto_idx(instruction.VRegH_4rcc()); |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 2739 | RangeInstructionOperands operands(instruction.VRegC_4rcc(), instruction.VRegA_4rcc()); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2740 | return BuildInvokePolymorphic(dex_pc, method_idx, proto_idx, operands); |
| 2741 | } |
| 2742 | |
| 2743 | case Instruction::INVOKE_CUSTOM: { |
| 2744 | uint16_t call_site_idx = instruction.VRegB_35c(); |
| 2745 | uint32_t args[5]; |
| 2746 | uint32_t number_of_vreg_arguments = instruction.GetVarArgs(args); |
| 2747 | VarArgsInstructionOperands operands(args, number_of_vreg_arguments); |
| 2748 | return BuildInvokeCustom(dex_pc, call_site_idx, operands); |
| 2749 | } |
| 2750 | |
| 2751 | case Instruction::INVOKE_CUSTOM_RANGE: { |
| 2752 | uint16_t call_site_idx = instruction.VRegB_3rc(); |
| 2753 | RangeInstructionOperands operands(instruction.VRegC_3rc(), instruction.VRegA_3rc()); |
| 2754 | return BuildInvokeCustom(dex_pc, call_site_idx, operands); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2755 | } |
| 2756 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2757 | case Instruction::NEG_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2758 | Unop_12x<HNeg>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2759 | break; |
| 2760 | } |
| 2761 | |
| 2762 | case Instruction::NEG_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2763 | Unop_12x<HNeg>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2764 | break; |
| 2765 | } |
| 2766 | |
| 2767 | case Instruction::NEG_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2768 | Unop_12x<HNeg>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2769 | break; |
| 2770 | } |
| 2771 | |
| 2772 | case Instruction::NEG_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2773 | Unop_12x<HNeg>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2774 | break; |
| 2775 | } |
| 2776 | |
| 2777 | case Instruction::NOT_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2778 | Unop_12x<HNot>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2779 | break; |
| 2780 | } |
| 2781 | |
| 2782 | case Instruction::NOT_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2783 | Unop_12x<HNot>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2784 | break; |
| 2785 | } |
| 2786 | |
| 2787 | case Instruction::INT_TO_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2788 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2789 | break; |
| 2790 | } |
| 2791 | |
| 2792 | case Instruction::INT_TO_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2793 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2794 | break; |
| 2795 | } |
| 2796 | |
| 2797 | case Instruction::INT_TO_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2798 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2799 | break; |
| 2800 | } |
| 2801 | |
| 2802 | case Instruction::LONG_TO_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2803 | Conversion_12x(instruction, DataType::Type::kInt64, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2804 | break; |
| 2805 | } |
| 2806 | |
| 2807 | case Instruction::LONG_TO_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2808 | Conversion_12x(instruction, DataType::Type::kInt64, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2809 | break; |
| 2810 | } |
| 2811 | |
| 2812 | case Instruction::LONG_TO_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2813 | Conversion_12x(instruction, DataType::Type::kInt64, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2814 | break; |
| 2815 | } |
| 2816 | |
| 2817 | case Instruction::FLOAT_TO_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2818 | Conversion_12x(instruction, DataType::Type::kFloat32, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2819 | break; |
| 2820 | } |
| 2821 | |
| 2822 | case Instruction::FLOAT_TO_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2823 | Conversion_12x(instruction, DataType::Type::kFloat32, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2824 | break; |
| 2825 | } |
| 2826 | |
| 2827 | case Instruction::FLOAT_TO_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2828 | Conversion_12x(instruction, DataType::Type::kFloat32, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2829 | break; |
| 2830 | } |
| 2831 | |
| 2832 | case Instruction::DOUBLE_TO_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2833 | Conversion_12x(instruction, DataType::Type::kFloat64, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2834 | break; |
| 2835 | } |
| 2836 | |
| 2837 | case Instruction::DOUBLE_TO_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2838 | Conversion_12x(instruction, DataType::Type::kFloat64, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2839 | break; |
| 2840 | } |
| 2841 | |
| 2842 | case Instruction::DOUBLE_TO_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2843 | Conversion_12x(instruction, DataType::Type::kFloat64, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2844 | break; |
| 2845 | } |
| 2846 | |
| 2847 | case Instruction::INT_TO_BYTE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2848 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kInt8, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2849 | break; |
| 2850 | } |
| 2851 | |
| 2852 | case Instruction::INT_TO_SHORT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2853 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kInt16, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2854 | break; |
| 2855 | } |
| 2856 | |
| 2857 | case Instruction::INT_TO_CHAR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2858 | Conversion_12x(instruction, DataType::Type::kInt32, DataType::Type::kUint16, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2859 | break; |
| 2860 | } |
| 2861 | |
| 2862 | case Instruction::ADD_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2863 | Binop_23x<HAdd>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2864 | break; |
| 2865 | } |
| 2866 | |
| 2867 | case Instruction::ADD_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2868 | Binop_23x<HAdd>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2869 | break; |
| 2870 | } |
| 2871 | |
| 2872 | case Instruction::ADD_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2873 | Binop_23x<HAdd>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2874 | break; |
| 2875 | } |
| 2876 | |
| 2877 | case Instruction::ADD_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2878 | Binop_23x<HAdd>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2879 | break; |
| 2880 | } |
| 2881 | |
| 2882 | case Instruction::SUB_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2883 | Binop_23x<HSub>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2884 | break; |
| 2885 | } |
| 2886 | |
| 2887 | case Instruction::SUB_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2888 | Binop_23x<HSub>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2889 | break; |
| 2890 | } |
| 2891 | |
| 2892 | case Instruction::SUB_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2893 | Binop_23x<HSub>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2894 | break; |
| 2895 | } |
| 2896 | |
| 2897 | case Instruction::SUB_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2898 | Binop_23x<HSub>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2899 | break; |
| 2900 | } |
| 2901 | |
| 2902 | case Instruction::ADD_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2903 | Binop_12x<HAdd>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2904 | break; |
| 2905 | } |
| 2906 | |
| 2907 | case Instruction::MUL_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2908 | Binop_23x<HMul>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2909 | break; |
| 2910 | } |
| 2911 | |
| 2912 | case Instruction::MUL_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2913 | Binop_23x<HMul>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2914 | break; |
| 2915 | } |
| 2916 | |
| 2917 | case Instruction::MUL_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2918 | Binop_23x<HMul>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2919 | break; |
| 2920 | } |
| 2921 | |
| 2922 | case Instruction::MUL_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2923 | Binop_23x<HMul>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2924 | break; |
| 2925 | } |
| 2926 | |
| 2927 | case Instruction::DIV_INT: { |
| 2928 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2929 | dex_pc, DataType::Type::kInt32, false, true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2930 | break; |
| 2931 | } |
| 2932 | |
| 2933 | case Instruction::DIV_LONG: { |
| 2934 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2935 | dex_pc, DataType::Type::kInt64, false, true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2936 | break; |
| 2937 | } |
| 2938 | |
| 2939 | case Instruction::DIV_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2940 | Binop_23x<HDiv>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2941 | break; |
| 2942 | } |
| 2943 | |
| 2944 | case Instruction::DIV_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2945 | Binop_23x<HDiv>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2946 | break; |
| 2947 | } |
| 2948 | |
| 2949 | case Instruction::REM_INT: { |
| 2950 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2951 | dex_pc, DataType::Type::kInt32, false, false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2952 | break; |
| 2953 | } |
| 2954 | |
| 2955 | case Instruction::REM_LONG: { |
| 2956 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2957 | dex_pc, DataType::Type::kInt64, false, false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2958 | break; |
| 2959 | } |
| 2960 | |
| 2961 | case Instruction::REM_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2962 | Binop_23x<HRem>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2963 | break; |
| 2964 | } |
| 2965 | |
| 2966 | case Instruction::REM_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2967 | Binop_23x<HRem>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2968 | break; |
| 2969 | } |
| 2970 | |
| 2971 | case Instruction::AND_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2972 | Binop_23x<HAnd>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2973 | break; |
| 2974 | } |
| 2975 | |
| 2976 | case Instruction::AND_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2977 | Binop_23x<HAnd>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2978 | break; |
| 2979 | } |
| 2980 | |
| 2981 | case Instruction::SHL_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2982 | Binop_23x_shift<HShl>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2983 | break; |
| 2984 | } |
| 2985 | |
| 2986 | case Instruction::SHL_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2987 | Binop_23x_shift<HShl>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2988 | break; |
| 2989 | } |
| 2990 | |
| 2991 | case Instruction::SHR_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2992 | Binop_23x_shift<HShr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2993 | break; |
| 2994 | } |
| 2995 | |
| 2996 | case Instruction::SHR_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2997 | Binop_23x_shift<HShr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2998 | break; |
| 2999 | } |
| 3000 | |
| 3001 | case Instruction::USHR_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3002 | Binop_23x_shift<HUShr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3003 | break; |
| 3004 | } |
| 3005 | |
| 3006 | case Instruction::USHR_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3007 | Binop_23x_shift<HUShr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3008 | break; |
| 3009 | } |
| 3010 | |
| 3011 | case Instruction::OR_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3012 | Binop_23x<HOr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3013 | break; |
| 3014 | } |
| 3015 | |
| 3016 | case Instruction::OR_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3017 | Binop_23x<HOr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3018 | break; |
| 3019 | } |
| 3020 | |
| 3021 | case Instruction::XOR_INT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3022 | Binop_23x<HXor>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3023 | break; |
| 3024 | } |
| 3025 | |
| 3026 | case Instruction::XOR_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3027 | Binop_23x<HXor>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3028 | break; |
| 3029 | } |
| 3030 | |
| 3031 | case Instruction::ADD_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3032 | Binop_12x<HAdd>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3033 | break; |
| 3034 | } |
| 3035 | |
| 3036 | case Instruction::ADD_DOUBLE_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3037 | Binop_12x<HAdd>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3038 | break; |
| 3039 | } |
| 3040 | |
| 3041 | case Instruction::ADD_FLOAT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3042 | Binop_12x<HAdd>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3043 | break; |
| 3044 | } |
| 3045 | |
| 3046 | case Instruction::SUB_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3047 | Binop_12x<HSub>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3048 | break; |
| 3049 | } |
| 3050 | |
| 3051 | case Instruction::SUB_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3052 | Binop_12x<HSub>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3053 | break; |
| 3054 | } |
| 3055 | |
| 3056 | case Instruction::SUB_FLOAT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3057 | Binop_12x<HSub>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3058 | break; |
| 3059 | } |
| 3060 | |
| 3061 | case Instruction::SUB_DOUBLE_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3062 | Binop_12x<HSub>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3063 | break; |
| 3064 | } |
| 3065 | |
| 3066 | case Instruction::MUL_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3067 | Binop_12x<HMul>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3068 | break; |
| 3069 | } |
| 3070 | |
| 3071 | case Instruction::MUL_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3072 | Binop_12x<HMul>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3073 | break; |
| 3074 | } |
| 3075 | |
| 3076 | case Instruction::MUL_FLOAT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3077 | Binop_12x<HMul>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3078 | break; |
| 3079 | } |
| 3080 | |
| 3081 | case Instruction::MUL_DOUBLE_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3082 | Binop_12x<HMul>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3083 | break; |
| 3084 | } |
| 3085 | |
| 3086 | case Instruction::DIV_INT_2ADDR: { |
| 3087 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3088 | dex_pc, DataType::Type::kInt32, false, true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3089 | break; |
| 3090 | } |
| 3091 | |
| 3092 | case Instruction::DIV_LONG_2ADDR: { |
| 3093 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3094 | dex_pc, DataType::Type::kInt64, false, true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3095 | break; |
| 3096 | } |
| 3097 | |
| 3098 | case Instruction::REM_INT_2ADDR: { |
| 3099 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3100 | dex_pc, DataType::Type::kInt32, false, false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3101 | break; |
| 3102 | } |
| 3103 | |
| 3104 | case Instruction::REM_LONG_2ADDR: { |
| 3105 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3106 | dex_pc, DataType::Type::kInt64, false, false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3107 | break; |
| 3108 | } |
| 3109 | |
| 3110 | case Instruction::REM_FLOAT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3111 | Binop_12x<HRem>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3112 | break; |
| 3113 | } |
| 3114 | |
| 3115 | case Instruction::REM_DOUBLE_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3116 | Binop_12x<HRem>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3117 | break; |
| 3118 | } |
| 3119 | |
| 3120 | case Instruction::SHL_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3121 | Binop_12x_shift<HShl>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3122 | break; |
| 3123 | } |
| 3124 | |
| 3125 | case Instruction::SHL_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3126 | Binop_12x_shift<HShl>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3127 | break; |
| 3128 | } |
| 3129 | |
| 3130 | case Instruction::SHR_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3131 | Binop_12x_shift<HShr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3132 | break; |
| 3133 | } |
| 3134 | |
| 3135 | case Instruction::SHR_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3136 | Binop_12x_shift<HShr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3137 | break; |
| 3138 | } |
| 3139 | |
| 3140 | case Instruction::USHR_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3141 | Binop_12x_shift<HUShr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3142 | break; |
| 3143 | } |
| 3144 | |
| 3145 | case Instruction::USHR_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3146 | Binop_12x_shift<HUShr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3147 | break; |
| 3148 | } |
| 3149 | |
| 3150 | case Instruction::DIV_FLOAT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3151 | Binop_12x<HDiv>(instruction, DataType::Type::kFloat32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3152 | break; |
| 3153 | } |
| 3154 | |
| 3155 | case Instruction::DIV_DOUBLE_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3156 | Binop_12x<HDiv>(instruction, DataType::Type::kFloat64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3157 | break; |
| 3158 | } |
| 3159 | |
| 3160 | case Instruction::AND_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3161 | Binop_12x<HAnd>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3162 | break; |
| 3163 | } |
| 3164 | |
| 3165 | case Instruction::AND_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3166 | Binop_12x<HAnd>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3167 | break; |
| 3168 | } |
| 3169 | |
| 3170 | case Instruction::OR_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3171 | Binop_12x<HOr>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3172 | break; |
| 3173 | } |
| 3174 | |
| 3175 | case Instruction::OR_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3176 | Binop_12x<HOr>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3177 | break; |
| 3178 | } |
| 3179 | |
| 3180 | case Instruction::XOR_INT_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3181 | Binop_12x<HXor>(instruction, DataType::Type::kInt32, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3182 | break; |
| 3183 | } |
| 3184 | |
| 3185 | case Instruction::XOR_LONG_2ADDR: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3186 | Binop_12x<HXor>(instruction, DataType::Type::kInt64, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3187 | break; |
| 3188 | } |
| 3189 | |
| 3190 | case Instruction::ADD_INT_LIT16: { |
| 3191 | Binop_22s<HAdd>(instruction, false, dex_pc); |
| 3192 | break; |
| 3193 | } |
| 3194 | |
| 3195 | case Instruction::AND_INT_LIT16: { |
| 3196 | Binop_22s<HAnd>(instruction, false, dex_pc); |
| 3197 | break; |
| 3198 | } |
| 3199 | |
| 3200 | case Instruction::OR_INT_LIT16: { |
| 3201 | Binop_22s<HOr>(instruction, false, dex_pc); |
| 3202 | break; |
| 3203 | } |
| 3204 | |
| 3205 | case Instruction::XOR_INT_LIT16: { |
| 3206 | Binop_22s<HXor>(instruction, false, dex_pc); |
| 3207 | break; |
| 3208 | } |
| 3209 | |
| 3210 | case Instruction::RSUB_INT: { |
| 3211 | Binop_22s<HSub>(instruction, true, dex_pc); |
| 3212 | break; |
| 3213 | } |
| 3214 | |
| 3215 | case Instruction::MUL_INT_LIT16: { |
| 3216 | Binop_22s<HMul>(instruction, false, dex_pc); |
| 3217 | break; |
| 3218 | } |
| 3219 | |
| 3220 | case Instruction::ADD_INT_LIT8: { |
| 3221 | Binop_22b<HAdd>(instruction, false, dex_pc); |
| 3222 | break; |
| 3223 | } |
| 3224 | |
| 3225 | case Instruction::AND_INT_LIT8: { |
| 3226 | Binop_22b<HAnd>(instruction, false, dex_pc); |
| 3227 | break; |
| 3228 | } |
| 3229 | |
| 3230 | case Instruction::OR_INT_LIT8: { |
| 3231 | Binop_22b<HOr>(instruction, false, dex_pc); |
| 3232 | break; |
| 3233 | } |
| 3234 | |
| 3235 | case Instruction::XOR_INT_LIT8: { |
| 3236 | Binop_22b<HXor>(instruction, false, dex_pc); |
| 3237 | break; |
| 3238 | } |
| 3239 | |
| 3240 | case Instruction::RSUB_INT_LIT8: { |
| 3241 | Binop_22b<HSub>(instruction, true, dex_pc); |
| 3242 | break; |
| 3243 | } |
| 3244 | |
| 3245 | case Instruction::MUL_INT_LIT8: { |
| 3246 | Binop_22b<HMul>(instruction, false, dex_pc); |
| 3247 | break; |
| 3248 | } |
| 3249 | |
| 3250 | case Instruction::DIV_INT_LIT16: |
| 3251 | case Instruction::DIV_INT_LIT8: { |
| 3252 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3253 | dex_pc, DataType::Type::kInt32, true, true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3254 | break; |
| 3255 | } |
| 3256 | |
| 3257 | case Instruction::REM_INT_LIT16: |
| 3258 | case Instruction::REM_INT_LIT8: { |
| 3259 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3260 | dex_pc, DataType::Type::kInt32, true, false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3261 | break; |
| 3262 | } |
| 3263 | |
| 3264 | case Instruction::SHL_INT_LIT8: { |
| 3265 | Binop_22b<HShl>(instruction, false, dex_pc); |
| 3266 | break; |
| 3267 | } |
| 3268 | |
| 3269 | case Instruction::SHR_INT_LIT8: { |
| 3270 | Binop_22b<HShr>(instruction, false, dex_pc); |
| 3271 | break; |
| 3272 | } |
| 3273 | |
| 3274 | case Instruction::USHR_INT_LIT8: { |
| 3275 | Binop_22b<HUShr>(instruction, false, dex_pc); |
| 3276 | break; |
| 3277 | } |
| 3278 | |
| 3279 | case Instruction::NEW_INSTANCE: { |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 3280 | HNewInstance* new_instance = |
| 3281 | BuildNewInstance(dex::TypeIndex(instruction.VRegB_21c()), dex_pc); |
| 3282 | DCHECK(new_instance != nullptr); |
| 3283 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3284 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 3285 | BuildConstructorFenceForAllocation(new_instance); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3286 | break; |
| 3287 | } |
| 3288 | |
| 3289 | case Instruction::NEW_ARRAY: { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3290 | dex::TypeIndex type_index(instruction.VRegC_22c()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3291 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), DataType::Type::kInt32); |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 3292 | HNewArray* new_array = BuildNewArray(dex_pc, type_index, length); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 3293 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3294 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 3295 | BuildConstructorFenceForAllocation(new_array); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3296 | break; |
| 3297 | } |
| 3298 | |
| 3299 | case Instruction::FILLED_NEW_ARRAY: { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3300 | dex::TypeIndex type_index(instruction.VRegB_35c()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3301 | uint32_t args[5]; |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 3302 | uint32_t number_of_vreg_arguments = instruction.GetVarArgs(args); |
| 3303 | VarArgsInstructionOperands operands(args, number_of_vreg_arguments); |
| 3304 | HNewArray* new_array = BuildFilledNewArray(dex_pc, type_index, operands); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 3305 | BuildConstructorFenceForAllocation(new_array); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3306 | break; |
| 3307 | } |
| 3308 | |
| 3309 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3310 | dex::TypeIndex type_index(instruction.VRegB_3rc()); |
Treehugger Robot | 2c5827a | 2018-05-17 22:26:08 +0000 | [diff] [blame] | 3311 | RangeInstructionOperands operands(instruction.VRegC_3rc(), instruction.VRegA_3rc()); |
| 3312 | HNewArray* new_array = BuildFilledNewArray(dex_pc, type_index, operands); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 3313 | BuildConstructorFenceForAllocation(new_array); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3314 | break; |
| 3315 | } |
| 3316 | |
| 3317 | case Instruction::FILL_ARRAY_DATA: { |
| 3318 | BuildFillArrayData(instruction, dex_pc); |
| 3319 | break; |
| 3320 | } |
| 3321 | |
| 3322 | case Instruction::MOVE_RESULT: |
| 3323 | case Instruction::MOVE_RESULT_WIDE: |
| 3324 | case Instruction::MOVE_RESULT_OBJECT: { |
| 3325 | DCHECK(latest_result_ != nullptr); |
| 3326 | UpdateLocal(instruction.VRegA(), latest_result_); |
| 3327 | latest_result_ = nullptr; |
| 3328 | break; |
| 3329 | } |
| 3330 | |
| 3331 | case Instruction::CMP_LONG: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3332 | Binop_23x_cmp(instruction, DataType::Type::kInt64, ComparisonBias::kNoBias, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3333 | break; |
| 3334 | } |
| 3335 | |
| 3336 | case Instruction::CMPG_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3337 | Binop_23x_cmp(instruction, DataType::Type::kFloat32, ComparisonBias::kGtBias, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3338 | break; |
| 3339 | } |
| 3340 | |
| 3341 | case Instruction::CMPG_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3342 | Binop_23x_cmp(instruction, DataType::Type::kFloat64, ComparisonBias::kGtBias, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3343 | break; |
| 3344 | } |
| 3345 | |
| 3346 | case Instruction::CMPL_FLOAT: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3347 | Binop_23x_cmp(instruction, DataType::Type::kFloat32, ComparisonBias::kLtBias, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3348 | break; |
| 3349 | } |
| 3350 | |
| 3351 | case Instruction::CMPL_DOUBLE: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3352 | Binop_23x_cmp(instruction, DataType::Type::kFloat64, ComparisonBias::kLtBias, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3353 | break; |
| 3354 | } |
| 3355 | |
| 3356 | case Instruction::NOP: |
| 3357 | break; |
| 3358 | |
| 3359 | case Instruction::IGET: |
| 3360 | case Instruction::IGET_QUICK: |
| 3361 | case Instruction::IGET_WIDE: |
| 3362 | case Instruction::IGET_WIDE_QUICK: |
| 3363 | case Instruction::IGET_OBJECT: |
| 3364 | case Instruction::IGET_OBJECT_QUICK: |
| 3365 | case Instruction::IGET_BOOLEAN: |
| 3366 | case Instruction::IGET_BOOLEAN_QUICK: |
| 3367 | case Instruction::IGET_BYTE: |
| 3368 | case Instruction::IGET_BYTE_QUICK: |
| 3369 | case Instruction::IGET_CHAR: |
| 3370 | case Instruction::IGET_CHAR_QUICK: |
| 3371 | case Instruction::IGET_SHORT: |
| 3372 | case Instruction::IGET_SHORT_QUICK: { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3373 | if (!BuildInstanceFieldAccess(instruction, dex_pc, /* is_put= */ false, quicken_index)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3374 | return false; |
| 3375 | } |
| 3376 | break; |
| 3377 | } |
| 3378 | |
| 3379 | case Instruction::IPUT: |
| 3380 | case Instruction::IPUT_QUICK: |
| 3381 | case Instruction::IPUT_WIDE: |
| 3382 | case Instruction::IPUT_WIDE_QUICK: |
| 3383 | case Instruction::IPUT_OBJECT: |
| 3384 | case Instruction::IPUT_OBJECT_QUICK: |
| 3385 | case Instruction::IPUT_BOOLEAN: |
| 3386 | case Instruction::IPUT_BOOLEAN_QUICK: |
| 3387 | case Instruction::IPUT_BYTE: |
| 3388 | case Instruction::IPUT_BYTE_QUICK: |
| 3389 | case Instruction::IPUT_CHAR: |
| 3390 | case Instruction::IPUT_CHAR_QUICK: |
| 3391 | case Instruction::IPUT_SHORT: |
| 3392 | case Instruction::IPUT_SHORT_QUICK: { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3393 | if (!BuildInstanceFieldAccess(instruction, dex_pc, /* is_put= */ true, quicken_index)) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3394 | return false; |
| 3395 | } |
| 3396 | break; |
| 3397 | } |
| 3398 | |
| 3399 | case Instruction::SGET: |
| 3400 | case Instruction::SGET_WIDE: |
| 3401 | case Instruction::SGET_OBJECT: |
| 3402 | case Instruction::SGET_BOOLEAN: |
| 3403 | case Instruction::SGET_BYTE: |
| 3404 | case Instruction::SGET_CHAR: |
| 3405 | case Instruction::SGET_SHORT: { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3406 | BuildStaticFieldAccess(instruction, dex_pc, /* is_put= */ false); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3407 | break; |
| 3408 | } |
| 3409 | |
| 3410 | case Instruction::SPUT: |
| 3411 | case Instruction::SPUT_WIDE: |
| 3412 | case Instruction::SPUT_OBJECT: |
| 3413 | case Instruction::SPUT_BOOLEAN: |
| 3414 | case Instruction::SPUT_BYTE: |
| 3415 | case Instruction::SPUT_CHAR: |
| 3416 | case Instruction::SPUT_SHORT: { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3417 | BuildStaticFieldAccess(instruction, dex_pc, /* is_put= */ true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3418 | break; |
| 3419 | } |
| 3420 | |
| 3421 | #define ARRAY_XX(kind, anticipated_type) \ |
| 3422 | case Instruction::AGET##kind: { \ |
| 3423 | BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \ |
| 3424 | break; \ |
| 3425 | } \ |
| 3426 | case Instruction::APUT##kind: { \ |
| 3427 | BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \ |
| 3428 | break; \ |
| 3429 | } |
| 3430 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3431 | ARRAY_XX(, DataType::Type::kInt32); |
| 3432 | ARRAY_XX(_WIDE, DataType::Type::kInt64); |
| 3433 | ARRAY_XX(_OBJECT, DataType::Type::kReference); |
| 3434 | ARRAY_XX(_BOOLEAN, DataType::Type::kBool); |
| 3435 | ARRAY_XX(_BYTE, DataType::Type::kInt8); |
| 3436 | ARRAY_XX(_CHAR, DataType::Type::kUint16); |
| 3437 | ARRAY_XX(_SHORT, DataType::Type::kInt16); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3438 | |
| 3439 | case Instruction::ARRAY_LENGTH: { |
David Brazdil | c120bbe | 2016-04-22 16:57:00 +0100 | [diff] [blame] | 3440 | HInstruction* object = LoadNullCheckedLocal(instruction.VRegB_12x(), dex_pc); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3441 | AppendInstruction(new (allocator_) HArrayLength(object, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3442 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction()); |
| 3443 | break; |
| 3444 | } |
| 3445 | |
| 3446 | case Instruction::CONST_STRING: { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 3447 | dex::StringIndex string_index(instruction.VRegB_21c()); |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 3448 | BuildLoadString(string_index, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3449 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 3450 | break; |
| 3451 | } |
| 3452 | |
| 3453 | case Instruction::CONST_STRING_JUMBO: { |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 3454 | dex::StringIndex string_index(instruction.VRegB_31c()); |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 3455 | BuildLoadString(string_index, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3456 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction()); |
| 3457 | break; |
| 3458 | } |
| 3459 | |
| 3460 | case Instruction::CONST_CLASS: { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3461 | dex::TypeIndex type_index(instruction.VRegB_21c()); |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 3462 | BuildLoadClass(type_index, dex_pc); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3463 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 3464 | break; |
| 3465 | } |
| 3466 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 3467 | case Instruction::CONST_METHOD_HANDLE: { |
| 3468 | uint16_t method_handle_idx = instruction.VRegB_21c(); |
| 3469 | BuildLoadMethodHandle(method_handle_idx, dex_pc); |
| 3470 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 3471 | break; |
| 3472 | } |
| 3473 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 3474 | case Instruction::CONST_METHOD_TYPE: { |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 3475 | dex::ProtoIndex proto_idx(instruction.VRegB_21c()); |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 3476 | BuildLoadMethodType(proto_idx, dex_pc); |
| 3477 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 3478 | break; |
| 3479 | } |
| 3480 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3481 | case Instruction::MOVE_EXCEPTION: { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3482 | AppendInstruction(new (allocator_) HLoadException(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3483 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction()); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3484 | AppendInstruction(new (allocator_) HClearException(dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3485 | break; |
| 3486 | } |
| 3487 | |
| 3488 | case Instruction::THROW: { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3489 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), DataType::Type::kReference); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3490 | AppendInstruction(new (allocator_) HThrow(exception, dex_pc)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3491 | // We finished building this block. Set the current block to null to avoid |
| 3492 | // adding dead instructions to it. |
| 3493 | current_block_ = nullptr; |
| 3494 | break; |
| 3495 | } |
| 3496 | |
| 3497 | case Instruction::INSTANCE_OF: { |
| 3498 | uint8_t destination = instruction.VRegA_22c(); |
| 3499 | uint8_t reference = instruction.VRegB_22c(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3500 | dex::TypeIndex type_index(instruction.VRegC_22c()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3501 | BuildTypeCheck(instruction, destination, reference, type_index, dex_pc); |
| 3502 | break; |
| 3503 | } |
| 3504 | |
| 3505 | case Instruction::CHECK_CAST: { |
| 3506 | uint8_t reference = instruction.VRegA_21c(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 3507 | dex::TypeIndex type_index(instruction.VRegB_21c()); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3508 | BuildTypeCheck(instruction, -1, reference, type_index, dex_pc); |
| 3509 | break; |
| 3510 | } |
| 3511 | |
| 3512 | case Instruction::MONITOR_ENTER: { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3513 | AppendInstruction(new (allocator_) HMonitorOperation( |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3514 | LoadLocal(instruction.VRegA_11x(), DataType::Type::kReference), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3515 | HMonitorOperation::OperationKind::kEnter, |
| 3516 | dex_pc)); |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 3517 | graph_->SetHasMonitorOperations(true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3518 | break; |
| 3519 | } |
| 3520 | |
| 3521 | case Instruction::MONITOR_EXIT: { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3522 | AppendInstruction(new (allocator_) HMonitorOperation( |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3523 | LoadLocal(instruction.VRegA_11x(), DataType::Type::kReference), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3524 | HMonitorOperation::OperationKind::kExit, |
| 3525 | dex_pc)); |
Artem Serov | 2808be8 | 2018-12-20 19:15:11 +0000 | [diff] [blame] | 3526 | graph_->SetHasMonitorOperations(true); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3527 | break; |
| 3528 | } |
| 3529 | |
| 3530 | case Instruction::SPARSE_SWITCH: |
| 3531 | case Instruction::PACKED_SWITCH: { |
| 3532 | BuildSwitch(instruction, dex_pc); |
| 3533 | break; |
| 3534 | } |
| 3535 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3536 | case Instruction::UNUSED_3E: |
| 3537 | case Instruction::UNUSED_3F: |
| 3538 | case Instruction::UNUSED_40: |
| 3539 | case Instruction::UNUSED_41: |
| 3540 | case Instruction::UNUSED_42: |
| 3541 | case Instruction::UNUSED_43: |
| 3542 | case Instruction::UNUSED_79: |
| 3543 | case Instruction::UNUSED_7A: |
| 3544 | case Instruction::UNUSED_F3: |
| 3545 | case Instruction::UNUSED_F4: |
| 3546 | case Instruction::UNUSED_F5: |
| 3547 | case Instruction::UNUSED_F6: |
| 3548 | case Instruction::UNUSED_F7: |
| 3549 | case Instruction::UNUSED_F8: |
| 3550 | case Instruction::UNUSED_F9: { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3551 | VLOG(compiler) << "Did not compile " |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 3552 | << dex_file_->PrettyMethod(dex_compilation_unit_->GetDexMethodIndex()) |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3553 | << " because of unhandled instruction " |
| 3554 | << instruction.Name(); |
Igor Murashkin | 1e065a5 | 2017-08-09 13:20:34 -0700 | [diff] [blame] | 3555 | MaybeRecordStat(compilation_stats_, |
| 3556 | MethodCompilationStat::kNotCompiledUnhandledInstruction); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3557 | return false; |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3558 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3559 | } |
| 3560 | return true; |
| 3561 | } // NOLINT(readability/fn_size) |
| 3562 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 3563 | ObjPtr<mirror::Class> HInstructionBuilder::LookupResolvedType( |
| 3564 | dex::TypeIndex type_index, |
| 3565 | const DexCompilationUnit& compilation_unit) const { |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 3566 | return compilation_unit.GetClassLinker()->LookupResolvedType( |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 3567 | type_index, compilation_unit.GetDexCache().Get(), compilation_unit.GetClassLoader().Get()); |
| 3568 | } |
| 3569 | |
| 3570 | ObjPtr<mirror::Class> HInstructionBuilder::LookupReferrerClass() const { |
| 3571 | // TODO: Cache the result in a Handle<mirror::Class>. |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 3572 | const dex::MethodId& method_id = |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 3573 | dex_compilation_unit_->GetDexFile()->GetMethodId(dex_compilation_unit_->GetDexMethodIndex()); |
| 3574 | return LookupResolvedType(method_id.class_idx_, *dex_compilation_unit_); |
| 3575 | } |
| 3576 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3577 | } // namespace art |