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