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