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