Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2 | * Copyright (C) 2014 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 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 17 | #include "builder.h" |
| 18 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 19 | #include "art_field-inl.h" |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame^] | 20 | #include "base/arena_bit_vector.h" |
| 21 | #include "base/bit_vector-inl.h" |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 22 | #include "base/logging.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 23 | #include "class_linker.h" |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 24 | #include "dex/verified_method.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 25 | #include "dex_file-inl.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 26 | #include "dex_instruction-inl.h" |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 27 | #include "dex/verified_method.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 28 | #include "driver/compiler_driver-inl.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 29 | #include "driver/compiler_options.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 30 | #include "mirror/class_loader.h" |
| 31 | #include "mirror/dex_cache.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 32 | #include "nodes.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 33 | #include "primitive.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 34 | #include "scoped_thread_state_change.h" |
| 35 | #include "thread.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 36 | #include "utils/dex_cache_arrays_layout-inl.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 37 | |
| 38 | namespace art { |
| 39 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 40 | /** |
| 41 | * Helper class to add HTemporary instructions. This class is used when |
| 42 | * converting a DEX instruction to multiple HInstruction, and where those |
| 43 | * instructions do not die at the following instruction, but instead spans |
| 44 | * multiple instructions. |
| 45 | */ |
| 46 | class Temporaries : public ValueObject { |
| 47 | public: |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 48 | explicit Temporaries(HGraph* graph) : graph_(graph), index_(0) {} |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
| 50 | void Add(HInstruction* instruction) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 51 | HInstruction* temp = new (graph_->GetArena()) HTemporary(index_, instruction->GetDexPc()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 52 | instruction->GetBlock()->AddInstruction(temp); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 53 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 54 | DCHECK(temp->GetPrevious() == instruction); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 55 | |
| 56 | size_t offset; |
| 57 | if (instruction->GetType() == Primitive::kPrimLong |
| 58 | || instruction->GetType() == Primitive::kPrimDouble) { |
| 59 | offset = 2; |
| 60 | } else { |
| 61 | offset = 1; |
| 62 | } |
| 63 | index_ += offset; |
| 64 | |
| 65 | graph_->UpdateTemporariesVRegSlots(index_); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | private: |
| 69 | HGraph* const graph_; |
| 70 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 71 | // Current index in the temporary stack, updated by `Add`. |
| 72 | size_t index_; |
| 73 | }; |
| 74 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 75 | class SwitchTable : public ValueObject { |
| 76 | public: |
| 77 | SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse) |
| 78 | : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) { |
| 79 | int32_t table_offset = instruction.VRegB_31t(); |
| 80 | const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset; |
| 81 | if (sparse) { |
| 82 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 83 | } else { |
| 84 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 85 | } |
| 86 | num_entries_ = table[1]; |
| 87 | values_ = reinterpret_cast<const int32_t*>(&table[2]); |
| 88 | } |
| 89 | |
| 90 | uint16_t GetNumEntries() const { |
| 91 | return num_entries_; |
| 92 | } |
| 93 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 94 | void CheckIndex(size_t index) const { |
| 95 | if (sparse_) { |
| 96 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 97 | DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_)); |
| 98 | } else { |
| 99 | // In a packed table, we have the starting key and num_entries_ values. |
| 100 | DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_)); |
| 101 | } |
| 102 | } |
| 103 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 104 | int32_t GetEntryAt(size_t index) const { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 105 | CheckIndex(index); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 106 | return values_[index]; |
| 107 | } |
| 108 | |
| 109 | uint32_t GetDexPcForIndex(size_t index) const { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 110 | CheckIndex(index); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 111 | return dex_pc_ + |
| 112 | (reinterpret_cast<const int16_t*>(values_ + index) - |
| 113 | reinterpret_cast<const int16_t*>(&instruction_)); |
| 114 | } |
| 115 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 116 | // Index of the first value in the table. |
| 117 | size_t GetFirstValueIndex() const { |
| 118 | if (sparse_) { |
| 119 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 120 | return num_entries_; |
| 121 | } else { |
| 122 | // In a packed table, we have the starting key and num_entries_ values. |
| 123 | return 1; |
| 124 | } |
| 125 | } |
| 126 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 127 | private: |
| 128 | const Instruction& instruction_; |
| 129 | const uint32_t dex_pc_; |
| 130 | |
| 131 | // Whether this is a sparse-switch table (or a packed-switch one). |
| 132 | const bool sparse_; |
| 133 | |
| 134 | // This can't be const as it needs to be computed off of the given instruction, and complicated |
| 135 | // expressions in the initializer list seemed very ugly. |
| 136 | uint16_t num_entries_; |
| 137 | |
| 138 | const int32_t* values_; |
| 139 | |
| 140 | DISALLOW_COPY_AND_ASSIGN(SwitchTable); |
| 141 | }; |
| 142 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 143 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 144 | graph_->SetNumberOfVRegs(count); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 145 | locals_.resize(count); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 146 | for (int i = 0; i < count; i++) { |
| 147 | HLocal* local = new (arena_) HLocal(i); |
| 148 | entry_block_->AddInstruction(local); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 149 | locals_[i] = local; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 153 | void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 154 | // dex_compilation_unit_ is null only when unit testing. |
| 155 | if (dex_compilation_unit_ == nullptr) { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 156 | return; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 160 | const char* shorty = dex_compilation_unit_->GetShorty(); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 161 | int locals_index = locals_.size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 162 | int parameter_index = 0; |
| 163 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 164 | const DexFile::MethodId& referrer_method_id = |
| 165 | dex_file_->GetMethodId(dex_compilation_unit_->GetDexMethodIndex()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 166 | if (!dex_compilation_unit_->IsStatic()) { |
| 167 | // Add the implicit 'this' argument, not expressed in the signature. |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 168 | HParameterValue* parameter = new (arena_) HParameterValue(*dex_file_, |
| 169 | referrer_method_id.class_idx_, |
| 170 | parameter_index++, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 171 | Primitive::kPrimNot, |
| 172 | true); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 173 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 174 | HLocal* local = GetLocalAt(locals_index++); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 175 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter, local->GetDexPc())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 176 | number_of_parameters--; |
| 177 | } |
| 178 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 179 | const DexFile::ProtoId& proto = dex_file_->GetMethodPrototype(referrer_method_id); |
| 180 | const DexFile::TypeList* arg_types = dex_file_->GetProtoParameters(proto); |
| 181 | for (int i = 0, shorty_pos = 1; i < number_of_parameters; i++) { |
| 182 | HParameterValue* parameter = new (arena_) HParameterValue( |
| 183 | *dex_file_, |
| 184 | arg_types->GetTypeItem(shorty_pos - 1).type_idx_, |
| 185 | parameter_index++, |
| 186 | Primitive::GetType(shorty[shorty_pos]), |
| 187 | false); |
| 188 | ++shorty_pos; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 189 | entry_block_->AddInstruction(parameter); |
| 190 | HLocal* local = GetLocalAt(locals_index++); |
| 191 | // Store the parameter value in the local that the dex code will use |
| 192 | // to reference that parameter. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 193 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter, local->GetDexPc())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 194 | bool is_wide = (parameter->GetType() == Primitive::kPrimLong) |
| 195 | || (parameter->GetType() == Primitive::kPrimDouble); |
| 196 | if (is_wide) { |
| 197 | i++; |
| 198 | locals_index++; |
| 199 | parameter_index++; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 200 | } |
| 201 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 202 | } |
| 203 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 204 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 205 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 206 | int32_t target_offset = instruction.GetTargetOffset(); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 207 | HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset); |
| 208 | HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 209 | DCHECK(branch_target != nullptr); |
| 210 | DCHECK(fallthrough_target != nullptr); |
| 211 | PotentiallyAddSuspendCheck(branch_target, dex_pc); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 212 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
| 213 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 214 | T* comparison = new (arena_) T(first, second, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 215 | current_block_->AddInstruction(comparison); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 216 | HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 217 | current_block_->AddInstruction(ifinst); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 218 | current_block_->AddSuccessor(branch_target); |
| 219 | current_block_->AddSuccessor(fallthrough_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 220 | current_block_ = nullptr; |
| 221 | } |
| 222 | |
| 223 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 224 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 225 | int32_t target_offset = instruction.GetTargetOffset(); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 226 | HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset); |
| 227 | HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 228 | DCHECK(branch_target != nullptr); |
| 229 | DCHECK(fallthrough_target != nullptr); |
| 230 | PotentiallyAddSuspendCheck(branch_target, dex_pc); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 231 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
| 232 | T* comparison = new (arena_) T(value, graph_->GetIntConstant(0, dex_pc), dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 233 | current_block_->AddInstruction(comparison); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 234 | HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 235 | current_block_->AddInstruction(ifinst); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 236 | current_block_->AddSuccessor(branch_target); |
| 237 | current_block_->AddSuccessor(fallthrough_target); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 238 | current_block_ = nullptr; |
| 239 | } |
| 240 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 241 | void HGraphBuilder::MaybeRecordStat(MethodCompilationStat compilation_stat) { |
| 242 | if (compilation_stats_ != nullptr) { |
| 243 | compilation_stats_->RecordStat(compilation_stat); |
| 244 | } |
| 245 | } |
| 246 | |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 247 | bool HGraphBuilder::SkipCompilation(const DexFile::CodeItem& code_item, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 248 | size_t number_of_branches) { |
| 249 | const CompilerOptions& compiler_options = compiler_driver_->GetCompilerOptions(); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 250 | CompilerOptions::CompilerFilter compiler_filter = compiler_options.GetCompilerFilter(); |
| 251 | if (compiler_filter == CompilerOptions::kEverything) { |
| 252 | return false; |
| 253 | } |
| 254 | |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 255 | if (compiler_options.IsHugeMethod(code_item.insns_size_in_code_units_)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 256 | VLOG(compiler) << "Skip compilation of huge method " |
| 257 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 258 | << ": " << code_item.insns_size_in_code_units_ << " code units"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 259 | MaybeRecordStat(MethodCompilationStat::kNotCompiledHugeMethod); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 260 | return true; |
| 261 | } |
| 262 | |
| 263 | // If it's large and contains no branches, it's likely to be machine generated initialization. |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 264 | if (compiler_options.IsLargeMethod(code_item.insns_size_in_code_units_) |
| 265 | && (number_of_branches == 0)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 266 | VLOG(compiler) << "Skip compilation of large method with no branch " |
| 267 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 268 | << ": " << code_item.insns_size_in_code_units_ << " code units"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 269 | MaybeRecordStat(MethodCompilationStat::kNotCompiledLargeMethodNoBranches); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 270 | return true; |
| 271 | } |
| 272 | |
| 273 | return false; |
| 274 | } |
| 275 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 276 | void HGraphBuilder::CreateBlocksForTryCatch(const DexFile::CodeItem& code_item) { |
| 277 | if (code_item.tries_size_ == 0) { |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | // Create branch targets at the start/end of the TryItem range. These are |
| 282 | // places where the program might fall through into/out of the a block and |
| 283 | // where TryBoundary instructions will be inserted later. Other edges which |
| 284 | // enter/exit the try blocks are a result of branches/switches. |
| 285 | for (size_t idx = 0; idx < code_item.tries_size_; ++idx) { |
| 286 | const DexFile::TryItem* try_item = DexFile::GetTryItems(code_item, idx); |
| 287 | uint32_t dex_pc_start = try_item->start_addr_; |
| 288 | uint32_t dex_pc_end = dex_pc_start + try_item->insn_count_; |
| 289 | FindOrCreateBlockStartingAt(dex_pc_start); |
| 290 | if (dex_pc_end < code_item.insns_size_in_code_units_) { |
| 291 | // TODO: Do not create block if the last instruction cannot fall through. |
| 292 | FindOrCreateBlockStartingAt(dex_pc_end); |
| 293 | } else { |
| 294 | // The TryItem spans until the very end of the CodeItem (or beyond if |
| 295 | // invalid) and therefore cannot have any code afterwards. |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // Create branch targets for exception handlers. |
| 300 | const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0); |
| 301 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 302 | for (uint32_t idx = 0; idx < handlers_size; ++idx) { |
| 303 | CatchHandlerIterator iterator(handlers_ptr); |
| 304 | for (; iterator.HasNext(); iterator.Next()) { |
| 305 | uint32_t address = iterator.GetHandlerAddress(); |
| 306 | HBasicBlock* block = FindOrCreateBlockStartingAt(address); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 307 | block->SetTryCatchInformation( |
| 308 | new (arena_) TryCatchInformation(iterator.GetHandlerTypeIndex(), *dex_file_)); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 309 | } |
| 310 | handlers_ptr = iterator.EndDataPointer(); |
| 311 | } |
| 312 | } |
| 313 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 314 | // Returns the TryItem stored for `block` or nullptr if there is no info for it. |
| 315 | static const DexFile::TryItem* GetTryItem( |
| 316 | HBasicBlock* block, |
| 317 | const ArenaSafeMap<uint32_t, const DexFile::TryItem*>& try_block_info) { |
| 318 | auto iterator = try_block_info.find(block->GetBlockId()); |
| 319 | return (iterator == try_block_info.end()) ? nullptr : iterator->second; |
| 320 | } |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 321 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 322 | void HGraphBuilder::LinkToCatchBlocks(HTryBoundary* try_boundary, |
| 323 | const DexFile::CodeItem& code_item, |
| 324 | const DexFile::TryItem* try_item) { |
| 325 | for (CatchHandlerIterator it(code_item, *try_item); it.HasNext(); it.Next()) { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 326 | try_boundary->AddExceptionHandler(FindBlockStartingAt(it.GetHandlerAddress())); |
| 327 | } |
| 328 | } |
| 329 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 330 | void HGraphBuilder::InsertTryBoundaryBlocks(const DexFile::CodeItem& code_item) { |
| 331 | if (code_item.tries_size_ == 0) { |
| 332 | return; |
| 333 | } |
| 334 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 335 | // Keep a map of all try blocks and their respective TryItems. We do not use |
| 336 | // the block's pointer but rather its id to ensure deterministic iteration. |
| 337 | ArenaSafeMap<uint32_t, const DexFile::TryItem*> try_block_info( |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 338 | std::less<uint32_t>(), arena_->Adapter(kArenaAllocGraphBuilder)); |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 339 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 340 | // Obtain TryItem information for blocks with throwing instructions, and split |
| 341 | // blocks which are both try & catch to simplify the graph. |
| 342 | // NOTE: We are appending new blocks inside the loop, so we need to use index |
| 343 | // because iterators can be invalidated. We remember the initial size to avoid |
| 344 | // iterating over the new blocks which cannot throw. |
| 345 | for (size_t i = 0, e = graph_->GetBlocks().size(); i < e; ++i) { |
| 346 | HBasicBlock* block = graph_->GetBlocks()[i]; |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 347 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 348 | // Do not bother creating exceptional edges for try blocks which have no |
| 349 | // throwing instructions. In that case we simply assume that the block is |
| 350 | // not covered by a TryItem. This prevents us from creating a throw-catch |
| 351 | // loop for synchronized blocks. |
| 352 | if (block->HasThrowingInstructions()) { |
| 353 | // Try to find a TryItem covering the block. |
| 354 | DCHECK_NE(block->GetDexPc(), kNoDexPc) << "Block must have a dec_pc to find its TryItem."; |
| 355 | const int32_t try_item_idx = DexFile::FindTryItem(code_item, block->GetDexPc()); |
| 356 | if (try_item_idx != -1) { |
| 357 | // Block throwing and in a TryItem. Store the try block information. |
| 358 | HBasicBlock* throwing_block = block; |
| 359 | if (block->IsCatchBlock()) { |
| 360 | // Simplify blocks which are both try and catch, otherwise we would |
| 361 | // need a strategy for splitting exceptional edges. We split the block |
| 362 | // after the move-exception (if present) and mark the first part not |
| 363 | // throwing. The normal-flow edge between them will be split later. |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 364 | throwing_block = block->SplitCatchBlockAfterMoveException(); |
| 365 | // Move-exception does not throw and the block has throwing insructions |
| 366 | // so it must have been possible to split it. |
| 367 | DCHECK(throwing_block != nullptr); |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 368 | } |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 369 | |
| 370 | try_block_info.Put(throwing_block->GetBlockId(), |
| 371 | DexFile::GetTryItems(code_item, try_item_idx)); |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 372 | } |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 373 | } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 374 | } |
| 375 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 376 | // Do a pass over the try blocks and insert entering TryBoundaries where at |
| 377 | // least one predecessor is not covered by the same TryItem as the try block. |
| 378 | // We do not split each edge separately, but rather create one boundary block |
| 379 | // that all predecessors are relinked to. This preserves loop headers (b/23895756). |
| 380 | for (auto entry : try_block_info) { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 381 | HBasicBlock* try_block = graph_->GetBlocks()[entry.first]; |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 382 | for (HBasicBlock* predecessor : try_block->GetPredecessors()) { |
| 383 | if (GetTryItem(predecessor, try_block_info) != entry.second) { |
| 384 | // Found a predecessor not covered by the same TryItem. Insert entering |
| 385 | // boundary block. |
| 386 | HTryBoundary* try_entry = |
| 387 | new (arena_) HTryBoundary(HTryBoundary::kEntry, try_block->GetDexPc()); |
| 388 | try_block->CreateImmediateDominator()->AddInstruction(try_entry); |
| 389 | LinkToCatchBlocks(try_entry, code_item, entry.second); |
| 390 | break; |
| 391 | } |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 392 | } |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 393 | } |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 394 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 395 | // Do a second pass over the try blocks and insert exit TryBoundaries where |
| 396 | // the successor is not in the same TryItem. |
| 397 | for (auto entry : try_block_info) { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 398 | HBasicBlock* try_block = graph_->GetBlocks()[entry.first]; |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 399 | // NOTE: Do not use iterators because SplitEdge would invalidate them. |
| 400 | for (size_t i = 0, e = try_block->GetSuccessors().size(); i < e; ++i) { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 401 | HBasicBlock* successor = try_block->GetSuccessors()[i]; |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 402 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 403 | // If the successor is a try block, all of its predecessors must be |
| 404 | // covered by the same TryItem. Otherwise the previous pass would have |
| 405 | // created a non-throwing boundary block. |
| 406 | if (GetTryItem(successor, try_block_info) != nullptr) { |
| 407 | DCHECK_EQ(entry.second, GetTryItem(successor, try_block_info)); |
David Brazdil | 72783ff | 2015-07-09 14:36:05 +0100 | [diff] [blame] | 408 | continue; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 409 | } |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 410 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 411 | // Preserve the invariant that Return(Void) always jumps to Exit by moving |
| 412 | // it outside the try block if necessary. |
| 413 | HInstruction* last_instruction = try_block->GetLastInstruction(); |
| 414 | if (last_instruction->IsReturn() || last_instruction->IsReturnVoid()) { |
| 415 | DCHECK_EQ(successor, exit_block_); |
| 416 | successor = try_block->SplitBefore(last_instruction); |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 417 | } |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 418 | |
| 419 | // Insert TryBoundary and link to catch blocks. |
| 420 | HTryBoundary* try_exit = |
| 421 | new (arena_) HTryBoundary(HTryBoundary::kExit, successor->GetDexPc()); |
| 422 | graph_->SplitEdge(try_block, successor)->AddInstruction(try_exit); |
| 423 | LinkToCatchBlocks(try_exit, code_item, entry.second); |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 424 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 428 | bool HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 429 | DCHECK(graph_->GetBlocks().empty()); |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 430 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 431 | const uint16_t* code_ptr = code_item.insns_; |
| 432 | const uint16_t* code_end = code_item.insns_ + code_item.insns_size_in_code_units_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 433 | code_start_ = code_ptr; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 434 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 435 | // Setup the graph with the entry block and exit block. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 436 | entry_block_ = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 437 | graph_->AddBlock(entry_block_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 438 | exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 439 | graph_->SetEntryBlock(entry_block_); |
| 440 | graph_->SetExitBlock(exit_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 441 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 442 | graph_->SetHasTryCatch(code_item.tries_size_ != 0); |
| 443 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 444 | InitializeLocals(code_item.registers_size_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 445 | graph_->SetMaximumNumberOfOutVRegs(code_item.outs_size_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 446 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 447 | // Compute the number of dex instructions, blocks, and branches. We will |
| 448 | // check these values against limits given to the compiler. |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 449 | size_t number_of_branches = 0; |
| 450 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 451 | // To avoid splitting blocks, we compute ahead of time the instructions that |
| 452 | // start a new block, and create these blocks. |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 453 | if (!ComputeBranchTargets(code_ptr, code_end, &number_of_branches)) { |
| 454 | MaybeRecordStat(MethodCompilationStat::kNotCompiledBranchOutsideMethodCode); |
| 455 | return false; |
| 456 | } |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 457 | |
| 458 | // Note that the compiler driver is null when unit testing. |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 459 | if ((compiler_driver_ != nullptr) && SkipCompilation(code_item, number_of_branches)) { |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 460 | return false; |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 461 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 462 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame^] | 463 | // Find locations where we want to generate extra stackmaps for native debugging. |
| 464 | // This allows us to generate the info only at interesting points (for example, |
| 465 | // at start of java statement) rather than before every dex instruction. |
| 466 | const bool native_debuggable = compiler_driver_ != nullptr && |
| 467 | compiler_driver_->GetCompilerOptions().GetNativeDebuggable(); |
| 468 | ArenaBitVector* native_debug_info_locations; |
| 469 | if (native_debuggable) { |
| 470 | const uint32_t num_instructions = code_item.insns_size_in_code_units_; |
| 471 | native_debug_info_locations = new (arena_) ArenaBitVector (arena_, num_instructions, false); |
| 472 | native_debug_info_locations->ClearAllBits(); |
| 473 | FindNativeDebugInfoLocations(code_item, native_debug_info_locations); |
| 474 | } |
| 475 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 476 | CreateBlocksForTryCatch(code_item); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 477 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 478 | InitializeParameters(code_item.ins_size_); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 479 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 480 | size_t dex_pc = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 481 | while (code_ptr < code_end) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 482 | // Update the current block if dex_pc starts a new block. |
| 483 | MaybeUpdateCurrentBlock(dex_pc); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 484 | const Instruction& instruction = *Instruction::At(code_ptr); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame^] | 485 | if (native_debuggable && native_debug_info_locations->IsBitSet(dex_pc)) { |
| 486 | if (current_block_ != nullptr) { |
| 487 | current_block_->AddInstruction(new (arena_) HNativeDebugInfo(dex_pc)); |
| 488 | } |
| 489 | } |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 490 | if (!AnalyzeDexInstruction(instruction, dex_pc)) { |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 491 | return false; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 492 | } |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 493 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 494 | code_ptr += instruction.SizeInCodeUnits(); |
| 495 | } |
| 496 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 497 | // Add Exit to the exit block. |
David Brazdil | 3e18738 | 2015-06-26 09:59:52 +0000 | [diff] [blame] | 498 | exit_block_->AddInstruction(new (arena_) HExit()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 499 | // Add the suspend check to the entry block. |
| 500 | entry_block_->AddInstruction(new (arena_) HSuspendCheck(0)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 501 | entry_block_->AddInstruction(new (arena_) HGoto()); |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 502 | // Add the exit block at the end. |
| 503 | graph_->AddBlock(exit_block_); |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 504 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 505 | // Iterate over blocks covered by TryItems and insert TryBoundaries at entry |
| 506 | // and exit points. This requires all control-flow instructions and |
| 507 | // non-exceptional edges to have been created. |
| 508 | InsertTryBoundaryBlocks(code_item); |
| 509 | |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 510 | return true; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 511 | } |
| 512 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 513 | void HGraphBuilder::MaybeUpdateCurrentBlock(size_t dex_pc) { |
| 514 | HBasicBlock* block = FindBlockStartingAt(dex_pc); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 515 | if (block == nullptr) { |
| 516 | return; |
| 517 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 518 | |
| 519 | if (current_block_ != nullptr) { |
| 520 | // Branching instructions clear current_block, so we know |
| 521 | // the last instruction of the current block is not a branching |
| 522 | // instruction. We add an unconditional goto to the found block. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 523 | current_block_->AddInstruction(new (arena_) HGoto(dex_pc)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 524 | current_block_->AddSuccessor(block); |
| 525 | } |
| 526 | graph_->AddBlock(block); |
| 527 | current_block_ = block; |
| 528 | } |
| 529 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame^] | 530 | void HGraphBuilder::FindNativeDebugInfoLocations(const DexFile::CodeItem& code_item, |
| 531 | ArenaBitVector* locations) { |
| 532 | // The callback gets called when the line number changes. |
| 533 | // In other words, it marks the start of new java statement. |
| 534 | struct Callback { |
| 535 | static bool Position(void* ctx, const DexFile::PositionInfo& entry) { |
| 536 | static_cast<ArenaBitVector*>(ctx)->SetBit(entry.address_); |
| 537 | return false; |
| 538 | } |
| 539 | }; |
| 540 | dex_file_->DecodeDebugPositionInfo(&code_item, Callback::Position, locations); |
| 541 | // Add native debug info at the start of every basic block. |
| 542 | for (uint32_t pc = 0; pc < code_item.insns_size_in_code_units_; pc++) { |
| 543 | if (FindBlockStartingAt(pc) != nullptr) { |
| 544 | locations->SetBit(pc); |
| 545 | } |
| 546 | } |
| 547 | // Instruction-specific tweaks. |
| 548 | const Instruction* const begin = Instruction::At(code_item.insns_); |
| 549 | const Instruction* const end = begin->RelativeAt(code_item.insns_size_in_code_units_); |
| 550 | for (const Instruction* inst = begin; inst < end; inst = inst->Next()) { |
| 551 | switch (inst->Opcode()) { |
| 552 | case Instruction::MOVE_EXCEPTION: |
| 553 | case Instruction::MOVE_RESULT: |
| 554 | case Instruction::MOVE_RESULT_WIDE: |
| 555 | case Instruction::MOVE_RESULT_OBJECT: { |
| 556 | // The compiler checks that there are no instructions before those. |
| 557 | // So generate HNativeDebugInfo after them instead. |
| 558 | locations->ClearBit(inst->GetDexPc(code_item.insns_)); |
| 559 | const Instruction* next = inst->Next(); |
| 560 | if (next < end) { |
| 561 | locations->SetBit(next->GetDexPc(code_item.insns_)); |
| 562 | } |
| 563 | break; |
| 564 | } |
| 565 | default: |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 571 | bool HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 572 | const uint16_t* code_end, |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 573 | size_t* number_of_branches) { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 574 | branch_targets_.resize(code_end - code_ptr, nullptr); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 575 | |
| 576 | // Create the first block for the dex instructions, single successor of the entry block. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 577 | HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 578 | branch_targets_[0] = block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 579 | entry_block_->AddSuccessor(block); |
| 580 | |
| 581 | // Iterate over all instructions and find branching instructions. Create blocks for |
| 582 | // the locations these instructions branch to. |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 583 | uint32_t dex_pc = 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 584 | while (code_ptr < code_end) { |
| 585 | const Instruction& instruction = *Instruction::At(code_ptr); |
| 586 | if (instruction.IsBranch()) { |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 587 | (*number_of_branches)++; |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 588 | int32_t target = instruction.GetTargetOffset() + dex_pc; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 589 | // Create a block for the target instruction. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 590 | FindOrCreateBlockStartingAt(target); |
| 591 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 592 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 593 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 594 | |
David Brazdil | fe65946 | 2015-06-24 14:23:56 +0100 | [diff] [blame] | 595 | if (instruction.CanFlowThrough()) { |
| 596 | if (code_ptr >= code_end) { |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 597 | // In the normal case we should never hit this but someone can artificially forge a dex |
| 598 | // file to fall-through out the method code. In this case we bail out compilation. |
| 599 | return false; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 600 | } else { |
| 601 | FindOrCreateBlockStartingAt(dex_pc); |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 602 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 603 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 604 | } else if (instruction.IsSwitch()) { |
| 605 | SwitchTable table(instruction, dex_pc, instruction.Opcode() == Instruction::SPARSE_SWITCH); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 606 | |
| 607 | uint16_t num_entries = table.GetNumEntries(); |
| 608 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 609 | // In a packed-switch, the entry at index 0 is the starting key. In a sparse-switch, the |
| 610 | // entry at index 0 is the first key, and values are after *all* keys. |
| 611 | size_t offset = table.GetFirstValueIndex(); |
| 612 | |
| 613 | // Use a larger loop counter type to avoid overflow issues. |
| 614 | for (size_t i = 0; i < num_entries; ++i) { |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 615 | // The target of the case. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 616 | uint32_t target = dex_pc + table.GetEntryAt(i + offset); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 617 | FindOrCreateBlockStartingAt(target); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 618 | |
David Brazdil | 281a632 | 2015-07-03 10:34:57 +0100 | [diff] [blame] | 619 | // Create a block for the switch-case logic. The block gets the dex_pc |
| 620 | // of the SWITCH instruction because it is part of its semantics. |
| 621 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 622 | branch_targets_[table.GetDexPcForIndex(i)] = block; |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | // Fall-through. Add a block if there is more code afterwards. |
| 626 | dex_pc += instruction.SizeInCodeUnits(); |
| 627 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 628 | if (code_ptr >= code_end) { |
| 629 | // In the normal case we should never hit this but someone can artificially forge a dex |
| 630 | // file to fall-through out the method code. In this case we bail out compilation. |
| 631 | // (A switch can fall-through so we don't need to check CanFlowThrough().) |
| 632 | return false; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 633 | } else { |
| 634 | FindOrCreateBlockStartingAt(dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 635 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 636 | } else { |
| 637 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 638 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 639 | } |
| 640 | } |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 641 | return true; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 642 | } |
| 643 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 644 | HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t dex_pc) const { |
| 645 | DCHECK_GE(dex_pc, 0); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 646 | return branch_targets_[dex_pc]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | HBasicBlock* HGraphBuilder::FindOrCreateBlockStartingAt(int32_t dex_pc) { |
| 650 | HBasicBlock* block = FindBlockStartingAt(dex_pc); |
| 651 | if (block == nullptr) { |
| 652 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 653 | branch_targets_[dex_pc] = block; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 654 | } |
| 655 | return block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 658 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 659 | void HGraphBuilder::Unop_12x(const Instruction& instruction, |
| 660 | Primitive::Type type, |
| 661 | uint32_t dex_pc) { |
| 662 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 663 | current_block_->AddInstruction(new (arena_) T(type, first, dex_pc)); |
| 664 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 665 | } |
| 666 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 667 | void HGraphBuilder::Conversion_12x(const Instruction& instruction, |
| 668 | Primitive::Type input_type, |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 669 | Primitive::Type result_type, |
| 670 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 671 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type, dex_pc); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 672 | current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 673 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 677 | void HGraphBuilder::Binop_23x(const Instruction& instruction, |
| 678 | Primitive::Type type, |
| 679 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 680 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 681 | HInstruction* second = LoadLocal(instruction.VRegC(), type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 682 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 683 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 687 | void HGraphBuilder::Binop_23x_shift(const Instruction& instruction, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 688 | Primitive::Type type, |
| 689 | uint32_t dex_pc) { |
| 690 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 691 | HInstruction* second = LoadLocal(instruction.VRegC(), Primitive::kPrimInt, dex_pc); |
| 692 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 693 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 696 | void HGraphBuilder::Binop_23x_cmp(const Instruction& instruction, |
| 697 | Primitive::Type type, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 698 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 699 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 700 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 701 | HInstruction* second = LoadLocal(instruction.VRegC(), type, dex_pc); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 702 | current_block_->AddInstruction(new (arena_) HCompare(type, first, second, bias, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 703 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 706 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 707 | void HGraphBuilder::Binop_12x_shift(const Instruction& instruction, Primitive::Type type, |
| 708 | uint32_t dex_pc) { |
| 709 | HInstruction* first = LoadLocal(instruction.VRegA(), type, dex_pc); |
| 710 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 711 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 712 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 716 | void HGraphBuilder::Binop_12x(const Instruction& instruction, |
| 717 | Primitive::Type type, |
| 718 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 719 | HInstruction* first = LoadLocal(instruction.VRegA(), type, dex_pc); |
| 720 | HInstruction* second = LoadLocal(instruction.VRegB(), type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 721 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 722 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 726 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse, uint32_t dex_pc) { |
| 727 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 728 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22s(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 729 | if (reverse) { |
| 730 | std::swap(first, second); |
| 731 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 732 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second, dex_pc)); |
| 733 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 737 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse, uint32_t dex_pc) { |
| 738 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 739 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22b(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 740 | if (reverse) { |
| 741 | std::swap(first, second); |
| 742 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 743 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second, dex_pc)); |
| 744 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 745 | } |
| 746 | |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 747 | static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, const CompilerDriver& driver) { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 748 | Thread* self = Thread::Current(); |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 749 | return cu->IsConstructor() |
| 750 | && driver.RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 751 | } |
| 752 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 753 | void HGraphBuilder::BuildReturn(const Instruction& instruction, |
| 754 | Primitive::Type type, |
| 755 | uint32_t dex_pc) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 756 | if (type == Primitive::kPrimVoid) { |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 757 | if (graph_->ShouldGenerateConstructorBarrier()) { |
| 758 | // The compilation unit is null during testing. |
| 759 | if (dex_compilation_unit_ != nullptr) { |
| 760 | DCHECK(RequiresConstructorBarrier(dex_compilation_unit_, *compiler_driver_)) |
| 761 | << "Inconsistent use of ShouldGenerateConstructorBarrier. Should not generate a barrier."; |
| 762 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 763 | current_block_->AddInstruction(new (arena_) HMemoryBarrier(kStoreStore, dex_pc)); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 764 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 765 | current_block_->AddInstruction(new (arena_) HReturnVoid(dex_pc)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 766 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 767 | HInstruction* value = LoadLocal(instruction.VRegA(), type, dex_pc); |
| 768 | current_block_->AddInstruction(new (arena_) HReturn(value, dex_pc)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 769 | } |
| 770 | current_block_->AddSuccessor(exit_block_); |
| 771 | current_block_ = nullptr; |
| 772 | } |
| 773 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 774 | static InvokeType GetInvokeTypeFromOpCode(Instruction::Code opcode) { |
| 775 | switch (opcode) { |
| 776 | case Instruction::INVOKE_STATIC: |
| 777 | case Instruction::INVOKE_STATIC_RANGE: |
| 778 | return kStatic; |
| 779 | case Instruction::INVOKE_DIRECT: |
| 780 | case Instruction::INVOKE_DIRECT_RANGE: |
| 781 | return kDirect; |
| 782 | case Instruction::INVOKE_VIRTUAL: |
| 783 | case Instruction::INVOKE_VIRTUAL_QUICK: |
| 784 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 785 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: |
| 786 | return kVirtual; |
| 787 | case Instruction::INVOKE_INTERFACE: |
| 788 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 789 | return kInterface; |
| 790 | case Instruction::INVOKE_SUPER_RANGE: |
| 791 | case Instruction::INVOKE_SUPER: |
| 792 | return kSuper; |
| 793 | default: |
| 794 | LOG(FATAL) << "Unexpected invoke opcode: " << opcode; |
| 795 | UNREACHABLE(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 796 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 797 | } |
| 798 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 799 | ArtMethod* HGraphBuilder::ResolveMethod(uint16_t method_idx, InvokeType invoke_type) { |
| 800 | ScopedObjectAccess soa(Thread::Current()); |
| 801 | StackHandleScope<2> hs(soa.Self()); |
| 802 | |
| 803 | ClassLinker* class_linker = dex_compilation_unit_->GetClassLinker(); |
| 804 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 805 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 806 | Handle<mirror::Class> compiling_class(hs.NewHandle(GetCompilingClass())); |
| 807 | |
Andreas Gampe | dae2414 | 2015-12-03 17:27:32 -0800 | [diff] [blame] | 808 | ArtMethod* resolved_method = class_linker->ResolveMethod<ClassLinker::kForceICCECheck>( |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 809 | *dex_compilation_unit_->GetDexFile(), |
| 810 | method_idx, |
| 811 | dex_compilation_unit_->GetDexCache(), |
| 812 | class_loader, |
| 813 | /* referrer */ nullptr, |
| 814 | invoke_type); |
| 815 | |
| 816 | if (UNLIKELY(resolved_method == nullptr)) { |
| 817 | // Clean up any exception left by type resolution. |
| 818 | soa.Self()->ClearException(); |
| 819 | return nullptr; |
| 820 | } |
| 821 | |
| 822 | // Check access. The class linker has a fast path for looking into the dex cache |
| 823 | // and does not check the access if it hits it. |
| 824 | if (compiling_class.Get() == nullptr) { |
| 825 | if (!resolved_method->IsPublic()) { |
| 826 | return nullptr; |
| 827 | } |
| 828 | } else if (!compiling_class->CanAccessResolvedMethod(resolved_method->GetDeclaringClass(), |
| 829 | resolved_method, |
| 830 | dex_compilation_unit_->GetDexCache().Get(), |
| 831 | method_idx)) { |
| 832 | return nullptr; |
| 833 | } |
| 834 | |
| 835 | // We have to special case the invoke-super case, as ClassLinker::ResolveMethod does not. |
| 836 | // We need to look at the referrer's super class vtable. |
| 837 | if (invoke_type == kSuper) { |
| 838 | if (compiling_class.Get() == nullptr) { |
| 839 | // Invoking a super method requires knowing the actual super class. If we did not resolve |
| 840 | // the compiling method's declaring class (which only happens for ahead of time compilation), |
| 841 | // bail out. |
| 842 | DCHECK(Runtime::Current()->IsAotCompiler()); |
| 843 | return nullptr; |
| 844 | } |
| 845 | uint16_t vtable_index = resolved_method->GetMethodIndex(); |
| 846 | ArtMethod* actual_method = compiling_class->GetSuperClass()->GetVTableEntry( |
| 847 | vtable_index, class_linker->GetImagePointerSize()); |
| 848 | if (actual_method != resolved_method && |
Nicolas Geoffray | 41844e5 | 2015-12-10 15:06:15 +0000 | [diff] [blame] | 849 | !IsSameDexFile(*actual_method->GetDexFile(), *dex_compilation_unit_->GetDexFile())) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 850 | // TODO: The actual method could still be referenced in the current dex file, so we |
| 851 | // could try locating it. |
| 852 | // TODO: Remove the dex_file restriction. |
| 853 | return nullptr; |
| 854 | } |
| 855 | if (!actual_method->IsInvokable()) { |
| 856 | // Fail if the actual method cannot be invoked. Otherwise, the runtime resolution stub |
| 857 | // could resolve the callee to the wrong method. |
| 858 | return nullptr; |
| 859 | } |
| 860 | resolved_method = actual_method; |
| 861 | } |
| 862 | |
| 863 | // Check for incompatible class changes. The class linker has a fast path for |
| 864 | // looking into the dex cache and does not check incompatible class changes if it hits it. |
| 865 | if (resolved_method->CheckIncompatibleClassChange(invoke_type)) { |
| 866 | return nullptr; |
| 867 | } |
| 868 | |
| 869 | return resolved_method; |
| 870 | } |
| 871 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 872 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
| 873 | uint32_t dex_pc, |
| 874 | uint32_t method_idx, |
| 875 | uint32_t number_of_vreg_arguments, |
| 876 | bool is_range, |
| 877 | uint32_t* args, |
| 878 | uint32_t register_index) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 879 | InvokeType invoke_type = GetInvokeTypeFromOpCode(instruction.Opcode()); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 880 | const char* descriptor = dex_file_->GetMethodShorty(method_idx); |
| 881 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
| 882 | |
| 883 | // Remove the return type from the 'proto'. |
| 884 | size_t number_of_arguments = strlen(descriptor) - 1; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 885 | if (invoke_type != kStatic) { // instance call |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 886 | // One extra argument for 'this'. |
| 887 | number_of_arguments++; |
| 888 | } |
| 889 | |
| 890 | MethodReference target_method(dex_file_, method_idx); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 891 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 892 | // Special handling for string init. |
| 893 | int32_t string_init_offset = 0; |
| 894 | bool is_string_init = compiler_driver_->IsStringInit(method_idx, |
| 895 | dex_file_, |
| 896 | &string_init_offset); |
| 897 | // Replace calls to String.<init> with StringFactory. |
| 898 | if (is_string_init) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 899 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
| 900 | HInvokeStaticOrDirect::MethodLoadKind::kStringInit, |
| 901 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 902 | dchecked_integral_cast<uint64_t>(string_init_offset), |
| 903 | 0U |
| 904 | }; |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 905 | HInvoke* invoke = new (arena_) HInvokeStaticOrDirect( |
| 906 | arena_, |
| 907 | number_of_arguments - 1, |
| 908 | Primitive::kPrimNot /*return_type */, |
| 909 | dex_pc, |
| 910 | method_idx, |
| 911 | target_method, |
| 912 | dispatch_info, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 913 | invoke_type, |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 914 | kStatic /* optimized_invoke_type */, |
| 915 | HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit); |
| 916 | return HandleStringInit(invoke, |
| 917 | number_of_vreg_arguments, |
| 918 | args, |
| 919 | register_index, |
| 920 | is_range, |
| 921 | descriptor); |
| 922 | } |
| 923 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 924 | ArtMethod* resolved_method = ResolveMethod(method_idx, invoke_type); |
| 925 | |
| 926 | if (resolved_method == nullptr) { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 927 | MaybeRecordStat(MethodCompilationStat::kUnresolvedMethod); |
| 928 | HInvoke* invoke = new (arena_) HInvokeUnresolved(arena_, |
| 929 | number_of_arguments, |
| 930 | return_type, |
| 931 | dex_pc, |
| 932 | method_idx, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 933 | invoke_type); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 934 | return HandleInvoke(invoke, |
| 935 | number_of_vreg_arguments, |
| 936 | args, |
| 937 | register_index, |
| 938 | is_range, |
| 939 | descriptor, |
| 940 | nullptr /* clinit_check */); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 941 | } |
| 942 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 943 | // Potential class initialization check, in the case of a static method call. |
| 944 | HClinitCheck* clinit_check = nullptr; |
| 945 | HInvoke* invoke = nullptr; |
| 946 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 947 | if (invoke_type == kDirect || invoke_type == kStatic || invoke_type == kSuper) { |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 948 | // By default, consider that the called method implicitly requires |
| 949 | // an initialization check of its declaring method. |
| 950 | HInvokeStaticOrDirect::ClinitCheckRequirement clinit_check_requirement |
| 951 | = HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 952 | ScopedObjectAccess soa(Thread::Current()); |
| 953 | if (invoke_type == kStatic) { |
| 954 | clinit_check = ProcessClinitCheckForInvoke( |
| 955 | dex_pc, resolved_method, method_idx, &clinit_check_requirement); |
| 956 | } else if (invoke_type == kSuper) { |
| 957 | if (IsSameDexFile(*resolved_method->GetDexFile(), *dex_compilation_unit_->GetDexFile())) { |
| 958 | // Update the target method to the one resolved. Note that this may be a no-op if |
| 959 | // we resolved to the method referenced by the instruction. |
| 960 | method_idx = resolved_method->GetDexMethodIndex(); |
| 961 | target_method = MethodReference(dex_file_, method_idx); |
| 962 | } |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 963 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 964 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 965 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
| 966 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, |
| 967 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 968 | 0u, |
| 969 | 0U |
| 970 | }; |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 971 | invoke = new (arena_) HInvokeStaticOrDirect(arena_, |
| 972 | number_of_arguments, |
| 973 | return_type, |
| 974 | dex_pc, |
| 975 | method_idx, |
| 976 | target_method, |
| 977 | dispatch_info, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 978 | invoke_type, |
| 979 | invoke_type, |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 980 | clinit_check_requirement); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 981 | } else if (invoke_type == kVirtual) { |
| 982 | ScopedObjectAccess soa(Thread::Current()); // Needed for the method index |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 983 | invoke = new (arena_) HInvokeVirtual(arena_, |
| 984 | number_of_arguments, |
| 985 | return_type, |
| 986 | dex_pc, |
| 987 | method_idx, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 988 | resolved_method->GetMethodIndex()); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 989 | } else { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 990 | DCHECK_EQ(invoke_type, kInterface); |
| 991 | ScopedObjectAccess soa(Thread::Current()); // Needed for the method index |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 992 | invoke = new (arena_) HInvokeInterface(arena_, |
| 993 | number_of_arguments, |
| 994 | return_type, |
| 995 | dex_pc, |
| 996 | method_idx, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 997 | resolved_method->GetDexMethodIndex()); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 998 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 999 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1000 | return HandleInvoke(invoke, |
| 1001 | number_of_vreg_arguments, |
| 1002 | args, |
| 1003 | register_index, |
| 1004 | is_range, |
| 1005 | descriptor, |
| 1006 | clinit_check); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1007 | } |
| 1008 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1009 | bool HGraphBuilder::BuildNewInstance(uint16_t type_index, uint32_t dex_pc) { |
| 1010 | bool finalizable; |
| 1011 | bool can_throw = NeedsAccessCheck(type_index, &finalizable); |
| 1012 | |
| 1013 | // Only the non-resolved entrypoint handles the finalizable class case. If we |
| 1014 | // need access checks, then we haven't resolved the method and the class may |
| 1015 | // again be finalizable. |
| 1016 | QuickEntrypointEnum entrypoint = (finalizable || can_throw) |
| 1017 | ? kQuickAllocObject |
| 1018 | : kQuickAllocObjectInitialized; |
| 1019 | |
| 1020 | ScopedObjectAccess soa(Thread::Current()); |
| 1021 | StackHandleScope<3> hs(soa.Self()); |
| 1022 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 1023 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 1024 | soa.Self(), *dex_compilation_unit_->GetDexFile()))); |
| 1025 | Handle<mirror::Class> resolved_class(hs.NewHandle(dex_cache->GetResolvedType(type_index))); |
| 1026 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 1027 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
| 1028 | outer_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), outer_dex_file))); |
| 1029 | |
| 1030 | if (outer_dex_cache.Get() != dex_cache.Get()) { |
| 1031 | // We currently do not support inlining allocations across dex files. |
| 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | HLoadClass* load_class = new (arena_) HLoadClass( |
| 1036 | graph_->GetCurrentMethod(), |
| 1037 | type_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1038 | outer_dex_file, |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1039 | IsOutermostCompilingClass(type_index), |
| 1040 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1041 | /*needs_access_check*/ can_throw, |
| 1042 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(outer_dex_file, type_index)); |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1043 | |
| 1044 | current_block_->AddInstruction(load_class); |
| 1045 | HInstruction* cls = load_class; |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1046 | if (!IsInitialized(resolved_class)) { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1047 | cls = new (arena_) HClinitCheck(load_class, dex_pc); |
| 1048 | current_block_->AddInstruction(cls); |
| 1049 | } |
| 1050 | |
| 1051 | current_block_->AddInstruction(new (arena_) HNewInstance( |
| 1052 | cls, |
| 1053 | graph_->GetCurrentMethod(), |
| 1054 | dex_pc, |
| 1055 | type_index, |
| 1056 | *dex_compilation_unit_->GetDexFile(), |
| 1057 | can_throw, |
| 1058 | finalizable, |
| 1059 | entrypoint)); |
| 1060 | return true; |
| 1061 | } |
| 1062 | |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1063 | static bool IsSubClass(mirror::Class* to_test, mirror::Class* super_class) |
| 1064 | SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1065 | return to_test != nullptr && !to_test->IsInterface() && to_test->IsSubClass(super_class); |
| 1066 | } |
| 1067 | |
| 1068 | bool HGraphBuilder::IsInitialized(Handle<mirror::Class> cls) const { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1069 | if (cls.Get() == nullptr) { |
| 1070 | return false; |
| 1071 | } |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1072 | |
| 1073 | // `CanAssumeClassIsLoaded` will return true if we're JITting, or will |
| 1074 | // check whether the class is in an image for the AOT compilation. |
| 1075 | if (cls->IsInitialized() && |
| 1076 | compiler_driver_->CanAssumeClassIsLoaded(cls.Get())) { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1077 | return true; |
| 1078 | } |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1079 | |
| 1080 | if (IsSubClass(GetOutermostCompilingClass(), cls.Get())) { |
| 1081 | return true; |
| 1082 | } |
| 1083 | |
| 1084 | // TODO: We should walk over the inlined methods, but we don't pass |
| 1085 | // that information to the builder. |
| 1086 | if (IsSubClass(GetCompilingClass(), cls.Get())) { |
| 1087 | return true; |
| 1088 | } |
| 1089 | |
| 1090 | return false; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1093 | HClinitCheck* HGraphBuilder::ProcessClinitCheckForInvoke( |
| 1094 | uint32_t dex_pc, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1095 | ArtMethod* resolved_method, |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1096 | uint32_t method_idx, |
| 1097 | HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1098 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 1099 | Thread* self = Thread::Current(); |
| 1100 | StackHandleScope<4> hs(self); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1101 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 1102 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1103 | self, *dex_compilation_unit_->GetDexFile()))); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1104 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1105 | outer_compilation_unit_->GetClassLinker()->FindDexCache( |
| 1106 | self, outer_dex_file))); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1107 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1108 | Handle<mirror::Class> resolved_method_class(hs.NewHandle(resolved_method->GetDeclaringClass())); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1109 | |
| 1110 | // The index at which the method's class is stored in the DexCache's type array. |
| 1111 | uint32_t storage_index = DexFile::kDexNoIndex; |
| 1112 | bool is_outer_class = (resolved_method->GetDeclaringClass() == outer_class.Get()); |
| 1113 | if (is_outer_class) { |
| 1114 | storage_index = outer_class->GetDexTypeIndex(); |
| 1115 | } else if (outer_dex_cache.Get() == dex_cache.Get()) { |
| 1116 | // Get `storage_index` from IsClassOfStaticMethodAvailableToReferrer. |
| 1117 | compiler_driver_->IsClassOfStaticMethodAvailableToReferrer(outer_dex_cache.Get(), |
| 1118 | GetCompilingClass(), |
| 1119 | resolved_method, |
| 1120 | method_idx, |
| 1121 | &storage_index); |
| 1122 | } |
| 1123 | |
| 1124 | HClinitCheck* clinit_check = nullptr; |
| 1125 | |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1126 | if (IsInitialized(resolved_method_class)) { |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1127 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
| 1128 | } else if (storage_index != DexFile::kDexNoIndex) { |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1129 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit; |
| 1130 | HLoadClass* load_class = new (arena_) HLoadClass( |
| 1131 | graph_->GetCurrentMethod(), |
| 1132 | storage_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1133 | outer_dex_file, |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1134 | is_outer_class, |
| 1135 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1136 | /*needs_access_check*/ false, |
| 1137 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(outer_dex_file, storage_index)); |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1138 | current_block_->AddInstruction(load_class); |
| 1139 | clinit_check = new (arena_) HClinitCheck(load_class, dex_pc); |
| 1140 | current_block_->AddInstruction(clinit_check); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1141 | } |
| 1142 | return clinit_check; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1143 | } |
| 1144 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1145 | bool HGraphBuilder::SetupInvokeArguments(HInvoke* invoke, |
| 1146 | uint32_t number_of_vreg_arguments, |
| 1147 | uint32_t* args, |
| 1148 | uint32_t register_index, |
| 1149 | bool is_range, |
| 1150 | const char* descriptor, |
| 1151 | size_t start_index, |
| 1152 | size_t* argument_index) { |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1153 | uint32_t descriptor_index = 1; // Skip the return type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1154 | uint32_t dex_pc = invoke->GetDexPc(); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1155 | |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 1156 | for (size_t i = start_index; |
| 1157 | // Make sure we don't go over the expected arguments or over the number of |
| 1158 | // dex registers given. If the instruction was seen as dead by the verifier, |
| 1159 | // it hasn't been properly checked. |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1160 | (i < number_of_vreg_arguments) && (*argument_index < invoke->GetNumberOfArguments()); |
| 1161 | i++, (*argument_index)++) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1162 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1163 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 1164 | if (!is_range |
| 1165 | && is_wide |
| 1166 | && ((i + 1 == number_of_vreg_arguments) || (args[i] + 1 != args[i + 1]))) { |
| 1167 | // Longs and doubles should be in pairs, that is, sequential registers. The verifier should |
| 1168 | // reject any class where this is violated. However, the verifier only does these checks |
| 1169 | // on non trivially dead instructions, so we just bailout the compilation. |
| 1170 | VLOG(compiler) << "Did not compile " |
| 1171 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 1172 | << " because of non-sequential dex register pair in wide argument"; |
| 1173 | MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 1174 | return false; |
| 1175 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1176 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type, dex_pc); |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1177 | invoke->SetArgumentAt(*argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1178 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1179 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1180 | } |
| 1181 | } |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 1182 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1183 | if (*argument_index != invoke->GetNumberOfArguments()) { |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 1184 | VLOG(compiler) << "Did not compile " |
| 1185 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 1186 | << " because of wrong number of arguments in invoke instruction"; |
| 1187 | MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 1188 | return false; |
| 1189 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1190 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 1191 | if (invoke->IsInvokeStaticOrDirect() && |
| 1192 | HInvokeStaticOrDirect::NeedsCurrentMethodInput( |
| 1193 | invoke->AsInvokeStaticOrDirect()->GetMethodLoadKind())) { |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1194 | invoke->SetArgumentAt(*argument_index, graph_->GetCurrentMethod()); |
| 1195 | (*argument_index)++; |
| 1196 | } |
| 1197 | |
| 1198 | return true; |
| 1199 | } |
| 1200 | |
| 1201 | bool HGraphBuilder::HandleInvoke(HInvoke* invoke, |
| 1202 | uint32_t number_of_vreg_arguments, |
| 1203 | uint32_t* args, |
| 1204 | uint32_t register_index, |
| 1205 | bool is_range, |
| 1206 | const char* descriptor, |
| 1207 | HClinitCheck* clinit_check) { |
| 1208 | DCHECK(!invoke->IsInvokeStaticOrDirect() || !invoke->AsInvokeStaticOrDirect()->IsStringInit()); |
| 1209 | |
| 1210 | size_t start_index = 0; |
| 1211 | size_t argument_index = 0; |
| 1212 | if (invoke->GetOriginalInvokeType() != InvokeType::kStatic) { // Instance call. |
| 1213 | Temporaries temps(graph_); |
| 1214 | HInstruction* arg = LoadLocal( |
| 1215 | is_range ? register_index : args[0], Primitive::kPrimNot, invoke->GetDexPc()); |
| 1216 | HNullCheck* null_check = new (arena_) HNullCheck(arg, invoke->GetDexPc()); |
| 1217 | current_block_->AddInstruction(null_check); |
| 1218 | temps.Add(null_check); |
| 1219 | invoke->SetArgumentAt(0, null_check); |
| 1220 | start_index = 1; |
| 1221 | argument_index = 1; |
| 1222 | } |
| 1223 | |
| 1224 | if (!SetupInvokeArguments(invoke, |
| 1225 | number_of_vreg_arguments, |
| 1226 | args, |
| 1227 | register_index, |
| 1228 | is_range, |
| 1229 | descriptor, |
| 1230 | start_index, |
| 1231 | &argument_index)) { |
| 1232 | return false; |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1233 | } |
| 1234 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1235 | if (clinit_check != nullptr) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1236 | // Add the class initialization check as last input of `invoke`. |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1237 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 1238 | DCHECK(invoke->AsInvokeStaticOrDirect()->GetClinitCheckRequirement() |
| 1239 | == HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1240 | invoke->SetArgumentAt(argument_index, clinit_check); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1241 | argument_index++; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1242 | } |
| 1243 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1244 | current_block_->AddInstruction(invoke); |
| 1245 | latest_result_ = invoke; |
| 1246 | |
| 1247 | return true; |
| 1248 | } |
| 1249 | |
| 1250 | bool HGraphBuilder::HandleStringInit(HInvoke* invoke, |
| 1251 | uint32_t number_of_vreg_arguments, |
| 1252 | uint32_t* args, |
| 1253 | uint32_t register_index, |
| 1254 | bool is_range, |
| 1255 | const char* descriptor) { |
| 1256 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 1257 | DCHECK(invoke->AsInvokeStaticOrDirect()->IsStringInit()); |
| 1258 | |
| 1259 | size_t start_index = 1; |
| 1260 | size_t argument_index = 0; |
| 1261 | if (!SetupInvokeArguments(invoke, |
| 1262 | number_of_vreg_arguments, |
| 1263 | args, |
| 1264 | register_index, |
| 1265 | is_range, |
| 1266 | descriptor, |
| 1267 | start_index, |
| 1268 | &argument_index)) { |
| 1269 | return false; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1270 | } |
Calin Juravle | 0eedd7e | 2015-08-20 14:48:00 +0100 | [diff] [blame] | 1271 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 1272 | // Add move-result for StringFactory method. |
| 1273 | uint32_t orig_this_reg = is_range ? register_index : args[0]; |
| 1274 | HInstruction* fake_string = LoadLocal(orig_this_reg, Primitive::kPrimNot, invoke->GetDexPc()); |
| 1275 | invoke->SetArgumentAt(argument_index, fake_string); |
| 1276 | current_block_->AddInstruction(invoke); |
| 1277 | PotentiallySimplifyFakeString(orig_this_reg, invoke->GetDexPc(), invoke); |
| 1278 | |
Calin Juravle | 0eedd7e | 2015-08-20 14:48:00 +0100 | [diff] [blame] | 1279 | latest_result_ = invoke; |
| 1280 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1281 | return true; |
| 1282 | } |
| 1283 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1284 | void HGraphBuilder::PotentiallySimplifyFakeString(uint16_t original_dex_register, |
| 1285 | uint32_t dex_pc, |
| 1286 | HInvoke* actual_string) { |
| 1287 | if (!graph_->IsDebuggable()) { |
| 1288 | // Notify that we cannot compile with baseline. The dex registers aliasing |
| 1289 | // with `original_dex_register` will be handled when we optimize |
| 1290 | // (see HInstructionSimplifer::VisitFakeString). |
| 1291 | can_use_baseline_for_string_init_ = false; |
| 1292 | return; |
| 1293 | } |
| 1294 | const VerifiedMethod* verified_method = |
| 1295 | compiler_driver_->GetVerifiedMethod(dex_file_, dex_compilation_unit_->GetDexMethodIndex()); |
| 1296 | if (verified_method != nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1297 | UpdateLocal(original_dex_register, actual_string, dex_pc); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1298 | const SafeMap<uint32_t, std::set<uint32_t>>& string_init_map = |
| 1299 | verified_method->GetStringInitPcRegMap(); |
| 1300 | auto map_it = string_init_map.find(dex_pc); |
| 1301 | if (map_it != string_init_map.end()) { |
Vladimir Marko | dbc2337 | 2015-10-12 12:45:52 +0100 | [diff] [blame] | 1302 | for (uint32_t reg : map_it->second) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1303 | HInstruction* load_local = LoadLocal(original_dex_register, Primitive::kPrimNot, dex_pc); |
Vladimir Marko | dbc2337 | 2015-10-12 12:45:52 +0100 | [diff] [blame] | 1304 | UpdateLocal(reg, load_local, dex_pc); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 1305 | } |
| 1306 | } |
| 1307 | } else { |
| 1308 | can_use_baseline_for_string_init_ = false; |
| 1309 | } |
| 1310 | } |
| 1311 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1312 | static Primitive::Type GetFieldAccessType(const DexFile& dex_file, uint16_t field_index) { |
| 1313 | const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); |
| 1314 | const char* type = dex_file.GetFieldTypeDescriptor(field_id); |
| 1315 | return Primitive::GetType(type[0]); |
| 1316 | } |
| 1317 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1318 | bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1319 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1320 | bool is_put) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1321 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 1322 | uint32_t obj_reg = instruction.VRegB_22c(); |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1323 | uint16_t field_index; |
| 1324 | if (instruction.IsQuickened()) { |
| 1325 | if (!CanDecodeQuickenedInfo()) { |
| 1326 | return false; |
| 1327 | } |
| 1328 | field_index = LookupQuickenedInfo(dex_pc); |
| 1329 | } else { |
| 1330 | field_index = instruction.VRegC_22c(); |
| 1331 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1332 | |
| 1333 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1334 | ArtField* resolved_field = |
| 1335 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1336 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1337 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1338 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot, dex_pc); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1339 | HInstruction* null_check = new (arena_) HNullCheck(object, dex_pc); |
| 1340 | current_block_->AddInstruction(null_check); |
| 1341 | |
| 1342 | Primitive::Type field_type = (resolved_field == nullptr) |
| 1343 | ? GetFieldAccessType(*dex_file_, field_index) |
| 1344 | : resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1345 | if (is_put) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1346 | Temporaries temps(graph_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1347 | // We need one temporary for the null check. |
| 1348 | temps.Add(null_check); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1349 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1350 | HInstruction* field_set = nullptr; |
| 1351 | if (resolved_field == nullptr) { |
| 1352 | MaybeRecordStat(MethodCompilationStat::kUnresolvedField); |
| 1353 | field_set = new (arena_) HUnresolvedInstanceFieldSet(null_check, |
| 1354 | value, |
| 1355 | field_type, |
| 1356 | field_index, |
| 1357 | dex_pc); |
| 1358 | } else { |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1359 | uint16_t class_def_index = resolved_field->GetDeclaringClass()->GetDexClassDefIndex(); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1360 | field_set = new (arena_) HInstanceFieldSet(null_check, |
| 1361 | value, |
| 1362 | field_type, |
| 1363 | resolved_field->GetOffset(), |
| 1364 | resolved_field->IsVolatile(), |
| 1365 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1366 | class_def_index, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1367 | *dex_file_, |
| 1368 | dex_compilation_unit_->GetDexCache(), |
| 1369 | dex_pc); |
| 1370 | } |
| 1371 | current_block_->AddInstruction(field_set); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1372 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1373 | HInstruction* field_get = nullptr; |
| 1374 | if (resolved_field == nullptr) { |
| 1375 | MaybeRecordStat(MethodCompilationStat::kUnresolvedField); |
| 1376 | field_get = new (arena_) HUnresolvedInstanceFieldGet(null_check, |
| 1377 | field_type, |
| 1378 | field_index, |
| 1379 | dex_pc); |
| 1380 | } else { |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1381 | uint16_t class_def_index = resolved_field->GetDeclaringClass()->GetDexClassDefIndex(); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1382 | field_get = new (arena_) HInstanceFieldGet(null_check, |
| 1383 | field_type, |
| 1384 | resolved_field->GetOffset(), |
| 1385 | resolved_field->IsVolatile(), |
| 1386 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1387 | class_def_index, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1388 | *dex_file_, |
| 1389 | dex_compilation_unit_->GetDexCache(), |
| 1390 | dex_pc); |
| 1391 | } |
| 1392 | current_block_->AddInstruction(field_get); |
| 1393 | UpdateLocal(source_or_dest_reg, field_get, dex_pc); |
Calin Juravle | e6f49b4 | 2015-09-17 14:04:33 +0000 | [diff] [blame] | 1394 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1395 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1396 | return true; |
| 1397 | } |
| 1398 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1399 | static mirror::Class* GetClassFrom(CompilerDriver* driver, |
| 1400 | const DexCompilationUnit& compilation_unit) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1401 | ScopedObjectAccess soa(Thread::Current()); |
| 1402 | StackHandleScope<2> hs(soa.Self()); |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1403 | const DexFile& dex_file = *compilation_unit.GetDexFile(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1404 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1405 | soa.Decode<mirror::ClassLoader*>(compilation_unit.GetClassLoader()))); |
| 1406 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1407 | compilation_unit.GetClassLinker()->FindDexCache(soa.Self(), dex_file))); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1408 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1409 | return driver->ResolveCompilingMethodsClass(soa, dex_cache, class_loader, &compilation_unit); |
| 1410 | } |
| 1411 | |
| 1412 | mirror::Class* HGraphBuilder::GetOutermostCompilingClass() const { |
| 1413 | return GetClassFrom(compiler_driver_, *outer_compilation_unit_); |
| 1414 | } |
| 1415 | |
| 1416 | mirror::Class* HGraphBuilder::GetCompilingClass() const { |
| 1417 | return GetClassFrom(compiler_driver_, *dex_compilation_unit_); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | bool HGraphBuilder::IsOutermostCompilingClass(uint16_t type_index) const { |
| 1421 | ScopedObjectAccess soa(Thread::Current()); |
| 1422 | StackHandleScope<4> hs(soa.Self()); |
| 1423 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1424 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 1425 | soa.Self(), *dex_compilation_unit_->GetDexFile()))); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1426 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 1427 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 1428 | Handle<mirror::Class> cls(hs.NewHandle(compiler_driver_->ResolveClass( |
| 1429 | soa, dex_cache, class_loader, type_index, dex_compilation_unit_))); |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 1430 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1431 | |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 1432 | // GetOutermostCompilingClass returns null when the class is unresolved |
| 1433 | // (e.g. if it derives from an unresolved class). This is bogus knowing that |
| 1434 | // we are compiling it. |
| 1435 | // When this happens we cannot establish a direct relation between the current |
| 1436 | // class and the outer class, so we return false. |
| 1437 | // (Note that this is only used for optimizing invokes and field accesses) |
| 1438 | return (cls.Get() != nullptr) && (outer_class.Get() == cls.Get()); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1441 | void HGraphBuilder::BuildUnresolvedStaticFieldAccess(const Instruction& instruction, |
| 1442 | uint32_t dex_pc, |
| 1443 | bool is_put, |
| 1444 | Primitive::Type field_type) { |
| 1445 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1446 | uint16_t field_index = instruction.VRegB_21c(); |
| 1447 | |
| 1448 | if (is_put) { |
| 1449 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc); |
| 1450 | current_block_->AddInstruction( |
| 1451 | new (arena_) HUnresolvedStaticFieldSet(value, field_type, field_index, dex_pc)); |
| 1452 | } else { |
| 1453 | current_block_->AddInstruction( |
| 1454 | new (arena_) HUnresolvedStaticFieldGet(field_type, field_index, dex_pc)); |
| 1455 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc); |
| 1456 | } |
| 1457 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1458 | bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1459 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1460 | bool is_put) { |
| 1461 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1462 | uint16_t field_index = instruction.VRegB_21c(); |
| 1463 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1464 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1465 | StackHandleScope<5> hs(soa.Self()); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1466 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1467 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 1468 | soa.Self(), *dex_compilation_unit_->GetDexFile()))); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1469 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 1470 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1471 | ArtField* resolved_field = compiler_driver_->ResolveField( |
| 1472 | soa, dex_cache, class_loader, dex_compilation_unit_, field_index, true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1473 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1474 | if (resolved_field == nullptr) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1475 | MaybeRecordStat(MethodCompilationStat::kUnresolvedField); |
| 1476 | Primitive::Type field_type = GetFieldAccessType(*dex_file_, field_index); |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1477 | BuildUnresolvedStaticFieldAccess(instruction, dex_pc, is_put, field_type); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1478 | return true; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1479 | } |
| 1480 | |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1481 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1482 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 1483 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1484 | outer_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), outer_dex_file))); |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1485 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1486 | |
| 1487 | // The index at which the field's class is stored in the DexCache's type array. |
| 1488 | uint32_t storage_index; |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1489 | bool is_outer_class = (outer_class.Get() == resolved_field->GetDeclaringClass()); |
| 1490 | if (is_outer_class) { |
| 1491 | storage_index = outer_class->GetDexTypeIndex(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1492 | } else if (outer_dex_cache.Get() != dex_cache.Get()) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1493 | // The compiler driver cannot currently understand multiple dex caches involved. Just bailout. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1494 | return false; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1495 | } else { |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1496 | // TODO: This is rather expensive. Perf it and cache the results if needed. |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1497 | std::pair<bool, bool> pair = compiler_driver_->IsFastStaticField( |
| 1498 | outer_dex_cache.Get(), |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1499 | GetCompilingClass(), |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1500 | resolved_field, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1501 | field_index, |
| 1502 | &storage_index); |
| 1503 | bool can_easily_access = is_put ? pair.second : pair.first; |
| 1504 | if (!can_easily_access) { |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1505 | MaybeRecordStat(MethodCompilationStat::kUnresolvedFieldNotAFastAccess); |
| 1506 | BuildUnresolvedStaticFieldAccess(instruction, dex_pc, is_put, field_type); |
| 1507 | return true; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1508 | } |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1511 | bool is_in_cache = |
| 1512 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(outer_dex_file, storage_index); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1513 | HLoadClass* constant = new (arena_) HLoadClass(graph_->GetCurrentMethod(), |
| 1514 | storage_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1515 | outer_dex_file, |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1516 | is_outer_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1517 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1518 | /*needs_access_check*/ false, |
| 1519 | is_in_cache); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1520 | current_block_->AddInstruction(constant); |
| 1521 | |
| 1522 | HInstruction* cls = constant; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1523 | |
| 1524 | Handle<mirror::Class> klass(hs.NewHandle(resolved_field->GetDeclaringClass())); |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1525 | if (!IsInitialized(klass)) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1526 | cls = new (arena_) HClinitCheck(constant, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1527 | current_block_->AddInstruction(cls); |
| 1528 | } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1529 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1530 | uint16_t class_def_index = klass->GetDexClassDefIndex(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1531 | if (is_put) { |
| 1532 | // We need to keep the class alive before loading the value. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1533 | Temporaries temps(graph_); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1534 | temps.Add(cls); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1535 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1536 | DCHECK_EQ(value->GetType(), field_type); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1537 | current_block_->AddInstruction(new (arena_) HStaticFieldSet(cls, |
| 1538 | value, |
| 1539 | field_type, |
| 1540 | resolved_field->GetOffset(), |
| 1541 | resolved_field->IsVolatile(), |
| 1542 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1543 | class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 1544 | *dex_file_, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1545 | dex_cache_, |
| 1546 | dex_pc)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1547 | } else { |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1548 | current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls, |
| 1549 | field_type, |
| 1550 | resolved_field->GetOffset(), |
| 1551 | resolved_field->IsVolatile(), |
| 1552 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1553 | class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 1554 | *dex_file_, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1555 | dex_cache_, |
| 1556 | dex_pc)); |
| 1557 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1558 | } |
| 1559 | return true; |
| 1560 | } |
| 1561 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1562 | void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg, |
| 1563 | uint16_t first_vreg, |
| 1564 | int64_t second_vreg_or_constant, |
| 1565 | uint32_t dex_pc, |
| 1566 | Primitive::Type type, |
| 1567 | bool second_is_constant, |
| 1568 | bool isDiv) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1569 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1570 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1571 | HInstruction* first = LoadLocal(first_vreg, type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1572 | HInstruction* second = nullptr; |
| 1573 | if (second_is_constant) { |
| 1574 | if (type == Primitive::kPrimInt) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1575 | second = graph_->GetIntConstant(second_vreg_or_constant, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1576 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1577 | second = graph_->GetLongConstant(second_vreg_or_constant, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1578 | } |
| 1579 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1580 | second = LoadLocal(second_vreg_or_constant, type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | if (!second_is_constant |
| 1584 | || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0) |
| 1585 | || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) { |
| 1586 | second = new (arena_) HDivZeroCheck(second, dex_pc); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1587 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1588 | current_block_->AddInstruction(second); |
| 1589 | temps.Add(current_block_->GetLastInstruction()); |
| 1590 | } |
| 1591 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1592 | if (isDiv) { |
| 1593 | current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc)); |
| 1594 | } else { |
| 1595 | current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc)); |
| 1596 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1597 | UpdateLocal(out_vreg, current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1600 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1601 | uint32_t dex_pc, |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1602 | bool is_put, |
| 1603 | Primitive::Type anticipated_type) { |
| 1604 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 1605 | uint8_t array_reg = instruction.VRegB_23x(); |
| 1606 | uint8_t index_reg = instruction.VRegC_23x(); |
| 1607 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1608 | // We need one temporary for the null check, one for the index, and one for the length. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1609 | Temporaries temps(graph_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1610 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1611 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1612 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1613 | current_block_->AddInstruction(object); |
| 1614 | temps.Add(object); |
| 1615 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1616 | HInstruction* length = new (arena_) HArrayLength(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1617 | current_block_->AddInstruction(length); |
| 1618 | temps.Add(length); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1619 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1620 | index = new (arena_) HBoundsCheck(index, length, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1621 | current_block_->AddInstruction(index); |
| 1622 | temps.Add(index); |
| 1623 | if (is_put) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1624 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1625 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1626 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1627 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1628 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1629 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type, dex_pc)); |
| 1630 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1631 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1632 | graph_->SetHasBoundsChecks(true); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1633 | } |
| 1634 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1635 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1636 | uint32_t type_index, |
| 1637 | uint32_t number_of_vreg_arguments, |
| 1638 | bool is_range, |
| 1639 | uint32_t* args, |
| 1640 | uint32_t register_index) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1641 | HInstruction* length = graph_->GetIntConstant(number_of_vreg_arguments, dex_pc); |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 1642 | bool finalizable; |
| 1643 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index, &finalizable) |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1644 | ? kQuickAllocArrayWithAccessCheck |
| 1645 | : kQuickAllocArray; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 1646 | HInstruction* object = new (arena_) HNewArray(length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 1647 | graph_->GetCurrentMethod(), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 1648 | dex_pc, |
| 1649 | type_index, |
| 1650 | *dex_compilation_unit_->GetDexFile(), |
| 1651 | entrypoint); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1652 | current_block_->AddInstruction(object); |
| 1653 | |
| 1654 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 1655 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 1656 | char primitive = descriptor[1]; |
| 1657 | DCHECK(primitive == 'I' |
| 1658 | || primitive == 'L' |
| 1659 | || primitive == '[') << descriptor; |
| 1660 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 1661 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 1662 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1663 | Temporaries temps(graph_); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1664 | temps.Add(object); |
| 1665 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1666 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type, dex_pc); |
| 1667 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1668 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1669 | new (arena_) HArraySet(object, index, value, type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1670 | } |
| 1671 | latest_result_ = object; |
| 1672 | } |
| 1673 | |
| 1674 | template <typename T> |
| 1675 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 1676 | const T* data, |
| 1677 | uint32_t element_count, |
| 1678 | Primitive::Type anticipated_type, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1679 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1680 | for (uint32_t i = 0; i < element_count; ++i) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1681 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
| 1682 | HInstruction* value = graph_->GetIntConstant(data[i], dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1683 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1684 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1685 | } |
| 1686 | } |
| 1687 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1688 | void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1689 | Temporaries temps(graph_); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1690 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1691 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1692 | current_block_->AddInstruction(null_check); |
| 1693 | temps.Add(null_check); |
| 1694 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1695 | HInstruction* length = new (arena_) HArrayLength(null_check, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1696 | current_block_->AddInstruction(length); |
| 1697 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1698 | int32_t payload_offset = instruction.VRegB_31t() + dex_pc; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1699 | const Instruction::ArrayDataPayload* payload = |
| 1700 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 1701 | const uint8_t* data = payload->data; |
| 1702 | uint32_t element_count = payload->element_count; |
| 1703 | |
| 1704 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 1705 | // done before doing any stores. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1706 | HInstruction* last_index = graph_->GetIntConstant(payload->element_count - 1, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1707 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc)); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1708 | |
| 1709 | switch (payload->element_width) { |
| 1710 | case 1: |
| 1711 | BuildFillArrayData(null_check, |
| 1712 | reinterpret_cast<const int8_t*>(data), |
| 1713 | element_count, |
| 1714 | Primitive::kPrimByte, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1715 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1716 | break; |
| 1717 | case 2: |
| 1718 | BuildFillArrayData(null_check, |
| 1719 | reinterpret_cast<const int16_t*>(data), |
| 1720 | element_count, |
| 1721 | Primitive::kPrimShort, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1722 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1723 | break; |
| 1724 | case 4: |
| 1725 | BuildFillArrayData(null_check, |
| 1726 | reinterpret_cast<const int32_t*>(data), |
| 1727 | element_count, |
| 1728 | Primitive::kPrimInt, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1729 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1730 | break; |
| 1731 | case 8: |
| 1732 | BuildFillWideArrayData(null_check, |
| 1733 | reinterpret_cast<const int64_t*>(data), |
| 1734 | element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1735 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1736 | break; |
| 1737 | default: |
| 1738 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 1739 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1740 | graph_->SetHasBoundsChecks(true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1743 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 1744 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1745 | uint32_t element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1746 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1747 | for (uint32_t i = 0; i < element_count; ++i) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1748 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
| 1749 | HInstruction* value = graph_->GetLongConstant(data[i], dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1750 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1751 | object, index, value, Primitive::kPrimLong, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1752 | } |
| 1753 | } |
| 1754 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1755 | static TypeCheckKind ComputeTypeCheckKind(Handle<mirror::Class> cls) |
| 1756 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1757 | if (cls.Get() == nullptr) { |
| 1758 | return TypeCheckKind::kUnresolvedCheck; |
| 1759 | } else if (cls->IsInterface()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1760 | return TypeCheckKind::kInterfaceCheck; |
| 1761 | } else if (cls->IsArrayClass()) { |
| 1762 | if (cls->GetComponentType()->IsObjectClass()) { |
| 1763 | return TypeCheckKind::kArrayObjectCheck; |
| 1764 | } else if (cls->CannotBeAssignedFromOtherTypes()) { |
| 1765 | return TypeCheckKind::kExactCheck; |
| 1766 | } else { |
| 1767 | return TypeCheckKind::kArrayCheck; |
| 1768 | } |
| 1769 | } else if (cls->IsFinal()) { |
| 1770 | return TypeCheckKind::kExactCheck; |
| 1771 | } else if (cls->IsAbstract()) { |
| 1772 | return TypeCheckKind::kAbstractClassCheck; |
| 1773 | } else { |
| 1774 | return TypeCheckKind::kClassHierarchyCheck; |
| 1775 | } |
| 1776 | } |
| 1777 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1778 | void HGraphBuilder::BuildTypeCheck(const Instruction& instruction, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1779 | uint8_t destination, |
| 1780 | uint8_t reference, |
| 1781 | uint16_t type_index, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1782 | uint32_t dex_pc) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1783 | bool type_known_final, type_known_abstract, use_declaring_class; |
| 1784 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1785 | dex_compilation_unit_->GetDexMethodIndex(), |
| 1786 | *dex_compilation_unit_->GetDexFile(), |
| 1787 | type_index, |
| 1788 | &type_known_final, |
| 1789 | &type_known_abstract, |
| 1790 | &use_declaring_class); |
| 1791 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1792 | ScopedObjectAccess soa(Thread::Current()); |
| 1793 | StackHandleScope<2> hs(soa.Self()); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1794 | const DexFile& dex_file = *dex_compilation_unit_->GetDexFile(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1795 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1796 | dex_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), dex_file))); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1797 | Handle<mirror::Class> resolved_class(hs.NewHandle(dex_cache->GetResolvedType(type_index))); |
| 1798 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1799 | HInstruction* object = LoadLocal(reference, Primitive::kPrimNot, dex_pc); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1800 | HLoadClass* cls = new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1801 | graph_->GetCurrentMethod(), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 1802 | type_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1803 | dex_file, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 1804 | IsOutermostCompilingClass(type_index), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1805 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1806 | !can_access, |
| 1807 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(dex_file, type_index)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1808 | current_block_->AddInstruction(cls); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1809 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1810 | // The class needs a temporary before being used by the type check. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1811 | Temporaries temps(graph_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1812 | temps.Add(cls); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1813 | |
| 1814 | TypeCheckKind check_kind = ComputeTypeCheckKind(resolved_class); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1815 | if (instruction.Opcode() == Instruction::INSTANCE_OF) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1816 | current_block_->AddInstruction(new (arena_) HInstanceOf(object, cls, check_kind, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1817 | UpdateLocal(destination, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1818 | } else { |
| 1819 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1820 | current_block_->AddInstruction(new (arena_) HCheckCast(object, cls, check_kind, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1821 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 1824 | bool HGraphBuilder::NeedsAccessCheck(uint32_t type_index, bool* finalizable) const { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1825 | return !compiler_driver_->CanAccessInstantiableTypeWithoutChecks( |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 1826 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, finalizable); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1829 | void HGraphBuilder::BuildSwitchJumpTable(const SwitchTable& table, |
| 1830 | const Instruction& instruction, |
| 1831 | HInstruction* value, |
| 1832 | uint32_t dex_pc) { |
| 1833 | // Add the successor blocks to the current block. |
| 1834 | uint16_t num_entries = table.GetNumEntries(); |
| 1835 | for (size_t i = 1; i <= num_entries; i++) { |
| 1836 | int32_t target_offset = table.GetEntryAt(i); |
| 1837 | HBasicBlock* case_target = FindBlockStartingAt(dex_pc + target_offset); |
| 1838 | DCHECK(case_target != nullptr); |
| 1839 | |
| 1840 | // Add the target block as a successor. |
| 1841 | current_block_->AddSuccessor(case_target); |
| 1842 | } |
| 1843 | |
| 1844 | // Add the default target block as the last successor. |
| 1845 | HBasicBlock* default_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 1846 | DCHECK(default_target != nullptr); |
| 1847 | current_block_->AddSuccessor(default_target); |
| 1848 | |
| 1849 | // Now add the Switch instruction. |
| 1850 | int32_t starting_key = table.GetEntryAt(0); |
| 1851 | current_block_->AddInstruction( |
| 1852 | new (arena_) HPackedSwitch(starting_key, num_entries, value, dex_pc)); |
| 1853 | // This block ends with control flow. |
| 1854 | current_block_ = nullptr; |
| 1855 | } |
| 1856 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1857 | void HGraphBuilder::BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc) { |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1858 | // Verifier guarantees that the payload for PackedSwitch contains: |
| 1859 | // (a) number of entries (may be zero) |
| 1860 | // (b) first and lowest switch case value (entry 0, always present) |
| 1861 | // (c) list of target pcs (entries 1 <= i <= N) |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1862 | SwitchTable table(instruction, dex_pc, false); |
| 1863 | |
| 1864 | // Value to test against. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1865 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1866 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1867 | // Starting key value. |
| 1868 | int32_t starting_key = table.GetEntryAt(0); |
| 1869 | |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1870 | // Retrieve number of entries. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1871 | uint16_t num_entries = table.GetNumEntries(); |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1872 | if (num_entries == 0) { |
| 1873 | return; |
| 1874 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1875 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1876 | // Don't use a packed switch if there are very few entries. |
| 1877 | if (num_entries > kSmallSwitchThreshold) { |
| 1878 | BuildSwitchJumpTable(table, instruction, value, dex_pc); |
| 1879 | } else { |
| 1880 | // Chained cmp-and-branch, starting from starting_key. |
| 1881 | for (size_t i = 1; i <= num_entries; i++) { |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 1882 | BuildSwitchCaseHelper(instruction, |
| 1883 | i, |
| 1884 | i == num_entries, |
| 1885 | table, |
| 1886 | value, |
| 1887 | starting_key + i - 1, |
| 1888 | table.GetEntryAt(i), |
| 1889 | dex_pc); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1890 | } |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1891 | } |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1892 | } |
| 1893 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1894 | void HGraphBuilder::BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc) { |
David Brazdil | 2ef645b | 2015-06-17 18:20:52 +0100 | [diff] [blame] | 1895 | // Verifier guarantees that the payload for SparseSwitch contains: |
| 1896 | // (a) number of entries (may be zero) |
| 1897 | // (b) sorted key values (entries 0 <= i < N) |
| 1898 | // (c) target pcs corresponding to the switch values (entries N <= i < 2*N) |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1899 | SwitchTable table(instruction, dex_pc, true); |
| 1900 | |
| 1901 | // Value to test against. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1902 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1903 | |
| 1904 | uint16_t num_entries = table.GetNumEntries(); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1905 | |
| 1906 | for (size_t i = 0; i < num_entries; i++) { |
| 1907 | BuildSwitchCaseHelper(instruction, i, i == static_cast<size_t>(num_entries) - 1, table, value, |
| 1908 | table.GetEntryAt(i), table.GetEntryAt(i + num_entries), dex_pc); |
| 1909 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | void HGraphBuilder::BuildSwitchCaseHelper(const Instruction& instruction, size_t index, |
| 1913 | bool is_last_case, const SwitchTable& table, |
| 1914 | HInstruction* value, int32_t case_value_int, |
| 1915 | int32_t target_offset, uint32_t dex_pc) { |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1916 | HBasicBlock* case_target = FindBlockStartingAt(dex_pc + target_offset); |
| 1917 | DCHECK(case_target != nullptr); |
| 1918 | PotentiallyAddSuspendCheck(case_target, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1919 | |
| 1920 | // The current case's value. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1921 | HInstruction* this_case_value = graph_->GetIntConstant(case_value_int, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1922 | |
| 1923 | // Compare value and this_case_value. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1924 | HEqual* comparison = new (arena_) HEqual(value, this_case_value, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1925 | current_block_->AddInstruction(comparison); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1926 | HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1927 | current_block_->AddInstruction(ifinst); |
| 1928 | |
| 1929 | // Case hit: use the target offset to determine where to go. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1930 | current_block_->AddSuccessor(case_target); |
| 1931 | |
| 1932 | // Case miss: go to the next case (or default fall-through). |
| 1933 | // When there is a next case, we use the block stored with the table offset representing this |
| 1934 | // case (that is where we registered them in ComputeBranchTargets). |
| 1935 | // When there is no next case, we use the following instruction. |
| 1936 | // TODO: Find a good way to peel the last iteration to avoid conditional, but still have re-use. |
| 1937 | if (!is_last_case) { |
| 1938 | HBasicBlock* next_case_target = FindBlockStartingAt(table.GetDexPcForIndex(index)); |
| 1939 | DCHECK(next_case_target != nullptr); |
| 1940 | current_block_->AddSuccessor(next_case_target); |
| 1941 | |
| 1942 | // Need to manually add the block, as there is no dex-pc transition for the cases. |
| 1943 | graph_->AddBlock(next_case_target); |
| 1944 | |
| 1945 | current_block_ = next_case_target; |
| 1946 | } else { |
| 1947 | HBasicBlock* default_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 1948 | DCHECK(default_target != nullptr); |
| 1949 | current_block_->AddSuccessor(default_target); |
| 1950 | current_block_ = nullptr; |
| 1951 | } |
| 1952 | } |
| 1953 | |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1954 | void HGraphBuilder::PotentiallyAddSuspendCheck(HBasicBlock* target, uint32_t dex_pc) { |
| 1955 | int32_t target_offset = target->GetDexPc() - dex_pc; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1956 | if (target_offset <= 0) { |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1957 | // DX generates back edges to the first encountered return. We can save |
| 1958 | // time of later passes by not adding redundant suspend checks. |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame] | 1959 | HInstruction* last_in_target = target->GetLastInstruction(); |
| 1960 | if (last_in_target != nullptr && |
| 1961 | (last_in_target->IsReturn() || last_in_target->IsReturnVoid())) { |
| 1962 | return; |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | // Add a suspend check to backward branches which may potentially loop. We |
| 1966 | // can remove them after we recognize loops in the graph. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1967 | current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_pc)); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1968 | } |
| 1969 | } |
| 1970 | |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1971 | bool HGraphBuilder::CanDecodeQuickenedInfo() const { |
| 1972 | return interpreter_metadata_ != nullptr; |
| 1973 | } |
| 1974 | |
| 1975 | uint16_t HGraphBuilder::LookupQuickenedInfo(uint32_t dex_pc) { |
| 1976 | DCHECK(interpreter_metadata_ != nullptr); |
| 1977 | uint32_t dex_pc_in_map = DecodeUnsignedLeb128(&interpreter_metadata_); |
| 1978 | DCHECK_EQ(dex_pc, dex_pc_in_map); |
| 1979 | return DecodeUnsignedLeb128(&interpreter_metadata_); |
| 1980 | } |
| 1981 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1982 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1983 | if (current_block_ == nullptr) { |
| 1984 | return true; // Dead code |
| 1985 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1986 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1987 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1988 | case Instruction::CONST_4: { |
| 1989 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1990 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n(), dex_pc); |
| 1991 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1992 | break; |
| 1993 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1994 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1995 | case Instruction::CONST_16: { |
| 1996 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1997 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21s(), dex_pc); |
| 1998 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1999 | break; |
| 2000 | } |
| 2001 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2002 | case Instruction::CONST: { |
| 2003 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2004 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_31i(), dex_pc); |
| 2005 | UpdateLocal(register_index, constant, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2006 | break; |
| 2007 | } |
| 2008 | |
| 2009 | case Instruction::CONST_HIGH16: { |
| 2010 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2011 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21h() << 16, dex_pc); |
| 2012 | UpdateLocal(register_index, constant, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2013 | break; |
| 2014 | } |
| 2015 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2016 | case Instruction::CONST_WIDE_16: { |
| 2017 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2018 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 2019 | int64_t value = instruction.VRegB_21s(); |
| 2020 | value <<= 48; |
| 2021 | value >>= 48; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2022 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 2023 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2024 | break; |
| 2025 | } |
| 2026 | |
| 2027 | case Instruction::CONST_WIDE_32: { |
| 2028 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2029 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 2030 | int64_t value = instruction.VRegB_31i(); |
| 2031 | value <<= 32; |
| 2032 | value >>= 32; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2033 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 2034 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2035 | break; |
| 2036 | } |
| 2037 | |
| 2038 | case Instruction::CONST_WIDE: { |
| 2039 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2040 | HLongConstant* constant = graph_->GetLongConstant(instruction.VRegB_51l(), dex_pc); |
| 2041 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2042 | break; |
| 2043 | } |
| 2044 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2045 | case Instruction::CONST_WIDE_HIGH16: { |
| 2046 | int32_t register_index = instruction.VRegA(); |
| 2047 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2048 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 2049 | UpdateLocal(register_index, constant, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2050 | break; |
| 2051 | } |
| 2052 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 2053 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2054 | case Instruction::MOVE: |
| 2055 | case Instruction::MOVE_FROM16: |
| 2056 | case Instruction::MOVE_16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2057 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 2058 | UpdateLocal(instruction.VRegA(), value, dex_pc); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2059 | break; |
| 2060 | } |
| 2061 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 2062 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2063 | case Instruction::MOVE_WIDE: |
| 2064 | case Instruction::MOVE_WIDE_FROM16: |
| 2065 | case Instruction::MOVE_WIDE_16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2066 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong, dex_pc); |
| 2067 | UpdateLocal(instruction.VRegA(), value, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2068 | break; |
| 2069 | } |
| 2070 | |
| 2071 | case Instruction::MOVE_OBJECT: |
| 2072 | case Instruction::MOVE_OBJECT_16: |
| 2073 | case Instruction::MOVE_OBJECT_FROM16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2074 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot, dex_pc); |
| 2075 | UpdateLocal(instruction.VRegA(), value, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2076 | break; |
| 2077 | } |
| 2078 | |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2079 | case Instruction::RETURN_VOID_NO_BARRIER: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2080 | case Instruction::RETURN_VOID: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2081 | BuildReturn(instruction, Primitive::kPrimVoid, dex_pc); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2082 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2083 | } |
| 2084 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2085 | #define IF_XX(comparison, cond) \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2086 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \ |
| 2087 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2088 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2089 | IF_XX(HEqual, EQ); |
| 2090 | IF_XX(HNotEqual, NE); |
| 2091 | IF_XX(HLessThan, LT); |
| 2092 | IF_XX(HLessThanOrEqual, LE); |
| 2093 | IF_XX(HGreaterThan, GT); |
| 2094 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2095 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2096 | case Instruction::GOTO: |
| 2097 | case Instruction::GOTO_16: |
| 2098 | case Instruction::GOTO_32: { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2099 | int32_t offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2100 | HBasicBlock* target = FindBlockStartingAt(offset + dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2101 | DCHECK(target != nullptr); |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 2102 | PotentiallyAddSuspendCheck(target, dex_pc); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2103 | current_block_->AddInstruction(new (arena_) HGoto(dex_pc)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2104 | current_block_->AddSuccessor(target); |
| 2105 | current_block_ = nullptr; |
| 2106 | break; |
| 2107 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2108 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2109 | case Instruction::RETURN: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2110 | BuildReturn(instruction, return_type_, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2111 | break; |
| 2112 | } |
| 2113 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2114 | case Instruction::RETURN_OBJECT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2115 | BuildReturn(instruction, return_type_, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2116 | break; |
| 2117 | } |
| 2118 | |
| 2119 | case Instruction::RETURN_WIDE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2120 | BuildReturn(instruction, return_type_, dex_pc); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2121 | break; |
| 2122 | } |
| 2123 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2124 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 2125 | case Instruction::INVOKE_INTERFACE: |
| 2126 | case Instruction::INVOKE_STATIC: |
| 2127 | case Instruction::INVOKE_SUPER: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2128 | case Instruction::INVOKE_VIRTUAL: |
| 2129 | case Instruction::INVOKE_VIRTUAL_QUICK: { |
| 2130 | uint16_t method_idx; |
| 2131 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_QUICK) { |
| 2132 | if (!CanDecodeQuickenedInfo()) { |
| 2133 | return false; |
| 2134 | } |
| 2135 | method_idx = LookupQuickenedInfo(dex_pc); |
| 2136 | } else { |
| 2137 | method_idx = instruction.VRegB_35c(); |
| 2138 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2139 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2140 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 2141 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2142 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 2143 | number_of_vreg_arguments, false, args, -1)) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2144 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2145 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2146 | break; |
| 2147 | } |
| 2148 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2149 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 2150 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 2151 | case Instruction::INVOKE_STATIC_RANGE: |
| 2152 | case Instruction::INVOKE_SUPER_RANGE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2153 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 2154 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: { |
| 2155 | uint16_t method_idx; |
| 2156 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK) { |
| 2157 | if (!CanDecodeQuickenedInfo()) { |
| 2158 | return false; |
| 2159 | } |
| 2160 | method_idx = LookupQuickenedInfo(dex_pc); |
| 2161 | } else { |
| 2162 | method_idx = instruction.VRegB_3rc(); |
| 2163 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2164 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 2165 | uint32_t register_index = instruction.VRegC(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2166 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2167 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2168 | return false; |
| 2169 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2170 | break; |
| 2171 | } |
| 2172 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2173 | case Instruction::NEG_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2174 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2175 | break; |
| 2176 | } |
| 2177 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2178 | case Instruction::NEG_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2179 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2180 | break; |
| 2181 | } |
| 2182 | |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2183 | case Instruction::NEG_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2184 | Unop_12x<HNeg>(instruction, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2185 | break; |
| 2186 | } |
| 2187 | |
| 2188 | case Instruction::NEG_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2189 | Unop_12x<HNeg>(instruction, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2190 | break; |
| 2191 | } |
| 2192 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2193 | case Instruction::NOT_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2194 | Unop_12x<HNot>(instruction, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2195 | break; |
| 2196 | } |
| 2197 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2198 | case Instruction::NOT_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2199 | Unop_12x<HNot>(instruction, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2200 | break; |
| 2201 | } |
| 2202 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2203 | case Instruction::INT_TO_LONG: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2204 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong, dex_pc); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2205 | break; |
| 2206 | } |
| 2207 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2208 | case Instruction::INT_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2209 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2210 | break; |
| 2211 | } |
| 2212 | |
| 2213 | case Instruction::INT_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2214 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2215 | break; |
| 2216 | } |
| 2217 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2218 | case Instruction::LONG_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2219 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2220 | break; |
| 2221 | } |
| 2222 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2223 | case Instruction::LONG_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2224 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2225 | break; |
| 2226 | } |
| 2227 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2228 | case Instruction::LONG_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2229 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | } |
| 2232 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2233 | case Instruction::FLOAT_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2234 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimInt, dex_pc); |
| 2235 | break; |
| 2236 | } |
| 2237 | |
| 2238 | case Instruction::FLOAT_TO_LONG: { |
| 2239 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2240 | break; |
| 2241 | } |
| 2242 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2243 | case Instruction::FLOAT_TO_DOUBLE: { |
| 2244 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimDouble, dex_pc); |
| 2245 | break; |
| 2246 | } |
| 2247 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2248 | case Instruction::DOUBLE_TO_INT: { |
| 2249 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimInt, dex_pc); |
| 2250 | break; |
| 2251 | } |
| 2252 | |
| 2253 | case Instruction::DOUBLE_TO_LONG: { |
| 2254 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimLong, dex_pc); |
| 2255 | break; |
| 2256 | } |
| 2257 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2258 | case Instruction::DOUBLE_TO_FLOAT: { |
| 2259 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimFloat, dex_pc); |
| 2260 | break; |
| 2261 | } |
| 2262 | |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2263 | case Instruction::INT_TO_BYTE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2264 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte, dex_pc); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2265 | break; |
| 2266 | } |
| 2267 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2268 | case Instruction::INT_TO_SHORT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2269 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort, dex_pc); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2270 | break; |
| 2271 | } |
| 2272 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2273 | case Instruction::INT_TO_CHAR: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2274 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar, dex_pc); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2275 | break; |
| 2276 | } |
| 2277 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2278 | case Instruction::ADD_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2279 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2280 | break; |
| 2281 | } |
| 2282 | |
| 2283 | case Instruction::ADD_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2284 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2285 | break; |
| 2286 | } |
| 2287 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2288 | case Instruction::ADD_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2289 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2290 | break; |
| 2291 | } |
| 2292 | |
| 2293 | case Instruction::ADD_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2294 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2295 | break; |
| 2296 | } |
| 2297 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2298 | case Instruction::SUB_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2299 | Binop_23x<HSub>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2300 | break; |
| 2301 | } |
| 2302 | |
| 2303 | case Instruction::SUB_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2304 | Binop_23x<HSub>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2305 | break; |
| 2306 | } |
| 2307 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2308 | case Instruction::SUB_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2309 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2310 | break; |
| 2311 | } |
| 2312 | |
| 2313 | case Instruction::SUB_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2314 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2315 | break; |
| 2316 | } |
| 2317 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2318 | case Instruction::ADD_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2319 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2320 | break; |
| 2321 | } |
| 2322 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2323 | case Instruction::MUL_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2324 | Binop_23x<HMul>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2325 | break; |
| 2326 | } |
| 2327 | |
| 2328 | case Instruction::MUL_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2329 | Binop_23x<HMul>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2330 | break; |
| 2331 | } |
| 2332 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2333 | case Instruction::MUL_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2334 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2335 | break; |
| 2336 | } |
| 2337 | |
| 2338 | case Instruction::MUL_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2339 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2340 | break; |
| 2341 | } |
| 2342 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2343 | case Instruction::DIV_INT: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2344 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2345 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2346 | break; |
| 2347 | } |
| 2348 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2349 | case Instruction::DIV_LONG: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2350 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2351 | dex_pc, Primitive::kPrimLong, false, true); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2352 | break; |
| 2353 | } |
| 2354 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2355 | case Instruction::DIV_FLOAT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2356 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2357 | break; |
| 2358 | } |
| 2359 | |
| 2360 | case Instruction::DIV_DOUBLE: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2361 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2362 | break; |
| 2363 | } |
| 2364 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2365 | case Instruction::REM_INT: { |
| 2366 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2367 | dex_pc, Primitive::kPrimInt, false, false); |
| 2368 | break; |
| 2369 | } |
| 2370 | |
| 2371 | case Instruction::REM_LONG: { |
| 2372 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2373 | dex_pc, Primitive::kPrimLong, false, false); |
| 2374 | break; |
| 2375 | } |
| 2376 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2377 | case Instruction::REM_FLOAT: { |
| 2378 | Binop_23x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 2379 | break; |
| 2380 | } |
| 2381 | |
| 2382 | case Instruction::REM_DOUBLE: { |
| 2383 | Binop_23x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 2384 | break; |
| 2385 | } |
| 2386 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2387 | case Instruction::AND_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2388 | Binop_23x<HAnd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2389 | break; |
| 2390 | } |
| 2391 | |
| 2392 | case Instruction::AND_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2393 | Binop_23x<HAnd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2394 | break; |
| 2395 | } |
| 2396 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2397 | case Instruction::SHL_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2398 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2399 | break; |
| 2400 | } |
| 2401 | |
| 2402 | case Instruction::SHL_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2403 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2404 | break; |
| 2405 | } |
| 2406 | |
| 2407 | case Instruction::SHR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2408 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2409 | break; |
| 2410 | } |
| 2411 | |
| 2412 | case Instruction::SHR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2413 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2414 | break; |
| 2415 | } |
| 2416 | |
| 2417 | case Instruction::USHR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2418 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2419 | break; |
| 2420 | } |
| 2421 | |
| 2422 | case Instruction::USHR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2423 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2424 | break; |
| 2425 | } |
| 2426 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2427 | case Instruction::OR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2428 | Binop_23x<HOr>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2429 | break; |
| 2430 | } |
| 2431 | |
| 2432 | case Instruction::OR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2433 | Binop_23x<HOr>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2434 | break; |
| 2435 | } |
| 2436 | |
| 2437 | case Instruction::XOR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2438 | Binop_23x<HXor>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2439 | break; |
| 2440 | } |
| 2441 | |
| 2442 | case Instruction::XOR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2443 | Binop_23x<HXor>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2444 | break; |
| 2445 | } |
| 2446 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2447 | case Instruction::ADD_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2448 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2449 | break; |
| 2450 | } |
| 2451 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2452 | case Instruction::ADD_DOUBLE_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2453 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2454 | break; |
| 2455 | } |
| 2456 | |
| 2457 | case Instruction::ADD_FLOAT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2458 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2459 | break; |
| 2460 | } |
| 2461 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2462 | case Instruction::SUB_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2463 | Binop_12x<HSub>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2464 | break; |
| 2465 | } |
| 2466 | |
| 2467 | case Instruction::SUB_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2468 | Binop_12x<HSub>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2469 | break; |
| 2470 | } |
| 2471 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2472 | case Instruction::SUB_FLOAT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2473 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2474 | break; |
| 2475 | } |
| 2476 | |
| 2477 | case Instruction::SUB_DOUBLE_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2478 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 2479 | break; |
| 2480 | } |
| 2481 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2482 | case Instruction::MUL_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2483 | Binop_12x<HMul>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2484 | break; |
| 2485 | } |
| 2486 | |
| 2487 | case Instruction::MUL_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2488 | Binop_12x<HMul>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2489 | break; |
| 2490 | } |
| 2491 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2492 | case Instruction::MUL_FLOAT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2493 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2494 | break; |
| 2495 | } |
| 2496 | |
| 2497 | case Instruction::MUL_DOUBLE_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2498 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2499 | break; |
| 2500 | } |
| 2501 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 2502 | case Instruction::DIV_INT_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2503 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2504 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 2505 | break; |
| 2506 | } |
| 2507 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2508 | case Instruction::DIV_LONG_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2509 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2510 | dex_pc, Primitive::kPrimLong, false, true); |
| 2511 | break; |
| 2512 | } |
| 2513 | |
| 2514 | case Instruction::REM_INT_2ADDR: { |
| 2515 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2516 | dex_pc, Primitive::kPrimInt, false, false); |
| 2517 | break; |
| 2518 | } |
| 2519 | |
| 2520 | case Instruction::REM_LONG_2ADDR: { |
| 2521 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2522 | dex_pc, Primitive::kPrimLong, false, false); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2523 | break; |
| 2524 | } |
| 2525 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2526 | case Instruction::REM_FLOAT_2ADDR: { |
| 2527 | Binop_12x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 2528 | break; |
| 2529 | } |
| 2530 | |
| 2531 | case Instruction::REM_DOUBLE_2ADDR: { |
| 2532 | Binop_12x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 2533 | break; |
| 2534 | } |
| 2535 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2536 | case Instruction::SHL_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2537 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | } |
| 2540 | |
| 2541 | case Instruction::SHL_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2542 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2543 | break; |
| 2544 | } |
| 2545 | |
| 2546 | case Instruction::SHR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2547 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2548 | break; |
| 2549 | } |
| 2550 | |
| 2551 | case Instruction::SHR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2552 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2553 | break; |
| 2554 | } |
| 2555 | |
| 2556 | case Instruction::USHR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2557 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2558 | break; |
| 2559 | } |
| 2560 | |
| 2561 | case Instruction::USHR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2562 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2563 | break; |
| 2564 | } |
| 2565 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2566 | case Instruction::DIV_FLOAT_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2567 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2568 | break; |
| 2569 | } |
| 2570 | |
| 2571 | case Instruction::DIV_DOUBLE_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2572 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2573 | break; |
| 2574 | } |
| 2575 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2576 | case Instruction::AND_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2577 | Binop_12x<HAnd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2578 | break; |
| 2579 | } |
| 2580 | |
| 2581 | case Instruction::AND_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2582 | Binop_12x<HAnd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2583 | break; |
| 2584 | } |
| 2585 | |
| 2586 | case Instruction::OR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2587 | Binop_12x<HOr>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2588 | break; |
| 2589 | } |
| 2590 | |
| 2591 | case Instruction::OR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2592 | Binop_12x<HOr>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2593 | break; |
| 2594 | } |
| 2595 | |
| 2596 | case Instruction::XOR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2597 | Binop_12x<HXor>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2598 | break; |
| 2599 | } |
| 2600 | |
| 2601 | case Instruction::XOR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2602 | Binop_12x<HXor>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2603 | break; |
| 2604 | } |
| 2605 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2606 | case Instruction::ADD_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2607 | Binop_22s<HAdd>(instruction, false, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2608 | break; |
| 2609 | } |
| 2610 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2611 | case Instruction::AND_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2612 | Binop_22s<HAnd>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2613 | break; |
| 2614 | } |
| 2615 | |
| 2616 | case Instruction::OR_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2617 | Binop_22s<HOr>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2618 | break; |
| 2619 | } |
| 2620 | |
| 2621 | case Instruction::XOR_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2622 | Binop_22s<HXor>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2623 | break; |
| 2624 | } |
| 2625 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2626 | case Instruction::RSUB_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2627 | Binop_22s<HSub>(instruction, true, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2628 | break; |
| 2629 | } |
| 2630 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2631 | case Instruction::MUL_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2632 | Binop_22s<HMul>(instruction, false, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2633 | break; |
| 2634 | } |
| 2635 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2636 | case Instruction::ADD_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2637 | Binop_22b<HAdd>(instruction, false, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2638 | break; |
| 2639 | } |
| 2640 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2641 | case Instruction::AND_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2642 | Binop_22b<HAnd>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2643 | break; |
| 2644 | } |
| 2645 | |
| 2646 | case Instruction::OR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2647 | Binop_22b<HOr>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2648 | break; |
| 2649 | } |
| 2650 | |
| 2651 | case Instruction::XOR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2652 | Binop_22b<HXor>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2653 | break; |
| 2654 | } |
| 2655 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2656 | case Instruction::RSUB_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2657 | Binop_22b<HSub>(instruction, true, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2658 | break; |
| 2659 | } |
| 2660 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2661 | case Instruction::MUL_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2662 | Binop_22b<HMul>(instruction, false, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2663 | break; |
| 2664 | } |
| 2665 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2666 | case Instruction::DIV_INT_LIT16: |
| 2667 | case Instruction::DIV_INT_LIT8: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2668 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2669 | dex_pc, Primitive::kPrimInt, true, true); |
| 2670 | break; |
| 2671 | } |
| 2672 | |
| 2673 | case Instruction::REM_INT_LIT16: |
| 2674 | case Instruction::REM_INT_LIT8: { |
| 2675 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2676 | dex_pc, Primitive::kPrimInt, true, false); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2677 | break; |
| 2678 | } |
| 2679 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2680 | case Instruction::SHL_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2681 | Binop_22b<HShl>(instruction, false, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2682 | break; |
| 2683 | } |
| 2684 | |
| 2685 | case Instruction::SHR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2686 | Binop_22b<HShr>(instruction, false, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2687 | break; |
| 2688 | } |
| 2689 | |
| 2690 | case Instruction::USHR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2691 | Binop_22b<HUShr>(instruction, false, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2692 | break; |
| 2693 | } |
| 2694 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2695 | case Instruction::NEW_INSTANCE: { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2696 | uint16_t type_index = instruction.VRegB_21c(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2697 | if (compiler_driver_->IsStringTypeIndex(type_index, dex_file_)) { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2698 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2699 | HFakeString* fake_string = new (arena_) HFakeString(dex_pc); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 2700 | current_block_->AddInstruction(fake_string); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2701 | UpdateLocal(register_index, fake_string, dex_pc); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2702 | } else { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 2703 | if (!BuildNewInstance(type_index, dex_pc)) { |
| 2704 | return false; |
| 2705 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2706 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2707 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2708 | break; |
| 2709 | } |
| 2710 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2711 | case Instruction::NEW_ARRAY: { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2712 | uint16_t type_index = instruction.VRegC_22c(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2713 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt, dex_pc); |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 2714 | bool finalizable; |
| 2715 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index, &finalizable) |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2716 | ? kQuickAllocArrayWithAccessCheck |
| 2717 | : kQuickAllocArray; |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 2718 | current_block_->AddInstruction(new (arena_) HNewArray(length, |
| 2719 | graph_->GetCurrentMethod(), |
| 2720 | dex_pc, |
| 2721 | type_index, |
| 2722 | *dex_compilation_unit_->GetDexFile(), |
| 2723 | entrypoint)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2724 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2725 | break; |
| 2726 | } |
| 2727 | |
| 2728 | case Instruction::FILLED_NEW_ARRAY: { |
| 2729 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 2730 | uint32_t type_index = instruction.VRegB_35c(); |
| 2731 | uint32_t args[5]; |
| 2732 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2733 | BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2734 | break; |
| 2735 | } |
| 2736 | |
| 2737 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 2738 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 2739 | uint32_t type_index = instruction.VRegB_3rc(); |
| 2740 | uint32_t register_index = instruction.VRegC_3rc(); |
| 2741 | BuildFilledNewArray( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2742 | dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2743 | break; |
| 2744 | } |
| 2745 | |
| 2746 | case Instruction::FILL_ARRAY_DATA: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2747 | BuildFillArrayData(instruction, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2748 | break; |
| 2749 | } |
| 2750 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2751 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2752 | case Instruction::MOVE_RESULT_WIDE: |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2753 | case Instruction::MOVE_RESULT_OBJECT: { |
Nicolas Geoffray | 1efcc22 | 2015-06-24 12:41:20 +0100 | [diff] [blame] | 2754 | if (latest_result_ == nullptr) { |
| 2755 | // Only dead code can lead to this situation, where the verifier |
| 2756 | // does not reject the method. |
| 2757 | } else { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2758 | // An Invoke/FilledNewArray and its MoveResult could have landed in |
| 2759 | // different blocks if there was a try/catch block boundary between |
| 2760 | // them. For Invoke, we insert a StoreLocal after the instruction. For |
| 2761 | // FilledNewArray, the local needs to be updated after the array was |
| 2762 | // filled, otherwise we might overwrite an input vreg. |
| 2763 | HStoreLocal* update_local = |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2764 | new (arena_) HStoreLocal(GetLocalAt(instruction.VRegA()), latest_result_, dex_pc); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2765 | HBasicBlock* block = latest_result_->GetBlock(); |
| 2766 | if (block == current_block_) { |
| 2767 | // MoveResult and the previous instruction are in the same block. |
| 2768 | current_block_->AddInstruction(update_local); |
| 2769 | } else { |
| 2770 | // The two instructions are in different blocks. Insert the MoveResult |
| 2771 | // before the final control-flow instruction of the previous block. |
| 2772 | DCHECK(block->EndsWithControlFlowInstruction()); |
| 2773 | DCHECK(current_block_->GetInstructions().IsEmpty()); |
| 2774 | block->InsertInstructionBefore(update_local, block->GetLastInstruction()); |
| 2775 | } |
Nicolas Geoffray | 1efcc22 | 2015-06-24 12:41:20 +0100 | [diff] [blame] | 2776 | latest_result_ = nullptr; |
| 2777 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2778 | break; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2779 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2780 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2781 | case Instruction::CMP_LONG: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2782 | Binop_23x_cmp(instruction, Primitive::kPrimLong, ComparisonBias::kNoBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2783 | break; |
| 2784 | } |
| 2785 | |
| 2786 | case Instruction::CMPG_FLOAT: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2787 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kGtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2788 | break; |
| 2789 | } |
| 2790 | |
| 2791 | case Instruction::CMPG_DOUBLE: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2792 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kGtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2793 | break; |
| 2794 | } |
| 2795 | |
| 2796 | case Instruction::CMPL_FLOAT: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2797 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kLtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2798 | break; |
| 2799 | } |
| 2800 | |
| 2801 | case Instruction::CMPL_DOUBLE: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2802 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kLtBias, dex_pc); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2803 | break; |
| 2804 | } |
| 2805 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2806 | case Instruction::NOP: |
| 2807 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2808 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2809 | case Instruction::IGET: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2810 | case Instruction::IGET_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2811 | case Instruction::IGET_WIDE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2812 | case Instruction::IGET_WIDE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2813 | case Instruction::IGET_OBJECT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2814 | case Instruction::IGET_OBJECT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2815 | case Instruction::IGET_BOOLEAN: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2816 | case Instruction::IGET_BOOLEAN_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2817 | case Instruction::IGET_BYTE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2818 | case Instruction::IGET_BYTE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2819 | case Instruction::IGET_CHAR: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2820 | case Instruction::IGET_CHAR_QUICK: |
| 2821 | case Instruction::IGET_SHORT: |
| 2822 | case Instruction::IGET_SHORT_QUICK: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2823 | if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2824 | return false; |
| 2825 | } |
| 2826 | break; |
| 2827 | } |
| 2828 | |
| 2829 | case Instruction::IPUT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2830 | case Instruction::IPUT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2831 | case Instruction::IPUT_WIDE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2832 | case Instruction::IPUT_WIDE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2833 | case Instruction::IPUT_OBJECT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2834 | case Instruction::IPUT_OBJECT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2835 | case Instruction::IPUT_BOOLEAN: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2836 | case Instruction::IPUT_BOOLEAN_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2837 | case Instruction::IPUT_BYTE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2838 | case Instruction::IPUT_BYTE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2839 | case Instruction::IPUT_CHAR: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2840 | case Instruction::IPUT_CHAR_QUICK: |
| 2841 | case Instruction::IPUT_SHORT: |
| 2842 | case Instruction::IPUT_SHORT_QUICK: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2843 | if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2844 | return false; |
| 2845 | } |
| 2846 | break; |
| 2847 | } |
| 2848 | |
| 2849 | case Instruction::SGET: |
| 2850 | case Instruction::SGET_WIDE: |
| 2851 | case Instruction::SGET_OBJECT: |
| 2852 | case Instruction::SGET_BOOLEAN: |
| 2853 | case Instruction::SGET_BYTE: |
| 2854 | case Instruction::SGET_CHAR: |
| 2855 | case Instruction::SGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2856 | if (!BuildStaticFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2857 | return false; |
| 2858 | } |
| 2859 | break; |
| 2860 | } |
| 2861 | |
| 2862 | case Instruction::SPUT: |
| 2863 | case Instruction::SPUT_WIDE: |
| 2864 | case Instruction::SPUT_OBJECT: |
| 2865 | case Instruction::SPUT_BOOLEAN: |
| 2866 | case Instruction::SPUT_BYTE: |
| 2867 | case Instruction::SPUT_CHAR: |
| 2868 | case Instruction::SPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2869 | if (!BuildStaticFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2870 | return false; |
| 2871 | } |
| 2872 | break; |
| 2873 | } |
| 2874 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2875 | #define ARRAY_XX(kind, anticipated_type) \ |
| 2876 | case Instruction::AGET##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2877 | BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2878 | break; \ |
| 2879 | } \ |
| 2880 | case Instruction::APUT##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2881 | BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2882 | break; \ |
| 2883 | } |
| 2884 | |
| 2885 | ARRAY_XX(, Primitive::kPrimInt); |
| 2886 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 2887 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 2888 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 2889 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 2890 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 2891 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 2892 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2893 | case Instruction::ARRAY_LENGTH: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2894 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot, dex_pc); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2895 | // No need for a temporary for the null check, it is the only input of the following |
| 2896 | // instruction. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2897 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2898 | current_block_->AddInstruction(object); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2899 | current_block_->AddInstruction(new (arena_) HArrayLength(object, dex_pc)); |
| 2900 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2901 | break; |
| 2902 | } |
| 2903 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2904 | case Instruction::CONST_STRING: { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 2905 | uint32_t string_index = instruction.VRegB_21c(); |
| 2906 | bool in_dex_cache = compiler_driver_->CanAssumeStringIsPresentInDexCache( |
| 2907 | *dex_file_, string_index); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 2908 | current_block_->AddInstruction( |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 2909 | new (arena_) HLoadString(graph_->GetCurrentMethod(), string_index, dex_pc, in_dex_cache)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2910 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2911 | break; |
| 2912 | } |
| 2913 | |
| 2914 | case Instruction::CONST_STRING_JUMBO: { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 2915 | uint32_t string_index = instruction.VRegB_31c(); |
| 2916 | bool in_dex_cache = compiler_driver_->CanAssumeStringIsPresentInDexCache( |
| 2917 | *dex_file_, string_index); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 2918 | current_block_->AddInstruction( |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 2919 | new (arena_) HLoadString(graph_->GetCurrentMethod(), string_index, dex_pc, in_dex_cache)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2920 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2921 | break; |
| 2922 | } |
| 2923 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2924 | case Instruction::CONST_CLASS: { |
| 2925 | uint16_t type_index = instruction.VRegB_21c(); |
| 2926 | bool type_known_final; |
| 2927 | bool type_known_abstract; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2928 | bool dont_use_is_referrers_class; |
| 2929 | // `CanAccessTypeWithoutChecks` will tell whether the method being |
| 2930 | // built is trying to access its own class, so that the generated |
| 2931 | // code can optimize for this case. However, the optimization does not |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2932 | // work for inlining, so we use `IsOutermostCompilingClass` instead. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2933 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 2934 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2935 | &type_known_final, &type_known_abstract, &dont_use_is_referrers_class); |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2936 | current_block_->AddInstruction(new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2937 | graph_->GetCurrentMethod(), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2938 | type_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 2939 | *dex_file_, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2940 | IsOutermostCompilingClass(type_index), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2941 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 2942 | !can_access, |
| 2943 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(*dex_file_, type_index))); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2944 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2945 | break; |
| 2946 | } |
| 2947 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2948 | case Instruction::MOVE_EXCEPTION: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2949 | current_block_->AddInstruction(new (arena_) HLoadException(dex_pc)); |
| 2950 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction(), dex_pc); |
| 2951 | current_block_->AddInstruction(new (arena_) HClearException(dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2952 | break; |
| 2953 | } |
| 2954 | |
| 2955 | case Instruction::THROW: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2956 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2957 | current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2958 | // A throw instruction must branch to the exit block. |
| 2959 | current_block_->AddSuccessor(exit_block_); |
| 2960 | // We finished building this block. Set the current block to null to avoid |
| 2961 | // adding dead instructions to it. |
| 2962 | current_block_ = nullptr; |
| 2963 | break; |
| 2964 | } |
| 2965 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2966 | case Instruction::INSTANCE_OF: { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2967 | uint8_t destination = instruction.VRegA_22c(); |
| 2968 | uint8_t reference = instruction.VRegB_22c(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2969 | uint16_t type_index = instruction.VRegC_22c(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2970 | BuildTypeCheck(instruction, destination, reference, type_index, dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2971 | break; |
| 2972 | } |
| 2973 | |
| 2974 | case Instruction::CHECK_CAST: { |
| 2975 | uint8_t reference = instruction.VRegA_21c(); |
| 2976 | uint16_t type_index = instruction.VRegB_21c(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2977 | BuildTypeCheck(instruction, -1, reference, type_index, dex_pc); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2978 | break; |
| 2979 | } |
| 2980 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2981 | case Instruction::MONITOR_ENTER: { |
| 2982 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2983 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc), |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2984 | HMonitorOperation::kEnter, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2985 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2986 | break; |
| 2987 | } |
| 2988 | |
| 2989 | case Instruction::MONITOR_EXIT: { |
| 2990 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2991 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc), |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2992 | HMonitorOperation::kExit, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2993 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2994 | break; |
| 2995 | } |
| 2996 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2997 | case Instruction::PACKED_SWITCH: { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2998 | BuildPackedSwitch(instruction, dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2999 | break; |
| 3000 | } |
| 3001 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 3002 | case Instruction::SPARSE_SWITCH: { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 3003 | BuildSparseSwitch(instruction, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 3004 | break; |
| 3005 | } |
| 3006 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3007 | default: |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 3008 | VLOG(compiler) << "Did not compile " |
| 3009 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 3010 | << " because of unhandled instruction " |
| 3011 | << instruction.Name(); |
| 3012 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnhandledInstruction); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3013 | return false; |
| 3014 | } |
| 3015 | return true; |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 3016 | } // NOLINT(readability/fn_size) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3017 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 3018 | HLocal* HGraphBuilder::GetLocalAt(uint32_t register_index) const { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 3019 | return locals_[register_index]; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3020 | } |
| 3021 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 3022 | void HGraphBuilder::UpdateLocal(uint32_t register_index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3023 | HInstruction* instruction, |
| 3024 | uint32_t dex_pc) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3025 | HLocal* local = GetLocalAt(register_index); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3026 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction, dex_pc)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 3029 | HInstruction* HGraphBuilder::LoadLocal(uint32_t register_index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3030 | Primitive::Type type, |
| 3031 | uint32_t dex_pc) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3032 | HLocal* local = GetLocalAt(register_index); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3033 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type, dex_pc)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3034 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3035 | } |
| 3036 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 3037 | } // namespace art |