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