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