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" |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 23 | #include "bytecode_utils.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 24 | #include "class_linker.h" |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 25 | #include "dex/verified_method.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 26 | #include "dex_file-inl.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 27 | #include "dex_instruction-inl.h" |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 28 | #include "dex/verified_method.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 29 | #include "driver/compiler_driver-inl.h" |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 30 | #include "driver/compiler_options.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 31 | #include "mirror/class_loader.h" |
| 32 | #include "mirror/dex_cache.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 33 | #include "nodes.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 34 | #include "primitive.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 35 | #include "scoped_thread_state_change.h" |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 36 | #include "ssa_builder.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 37 | #include "thread.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 38 | #include "utils/dex_cache_arrays_layout-inl.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 39 | |
| 40 | namespace art { |
| 41 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 42 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 43 | graph_->SetNumberOfVRegs(count); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 44 | locals_.resize(count); |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 45 | HBasicBlock* entry_block = graph_->GetEntryBlock(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 46 | for (int i = 0; i < count; i++) { |
| 47 | HLocal* local = new (arena_) HLocal(i); |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 48 | entry_block->AddInstruction(local); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 49 | locals_[i] = local; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 53 | void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 54 | // dex_compilation_unit_ is null only when unit testing. |
| 55 | if (dex_compilation_unit_ == nullptr) { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 56 | return; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 57 | } |
| 58 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 59 | HBasicBlock* entry_block = graph_->GetEntryBlock(); |
| 60 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 61 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 62 | const char* shorty = dex_compilation_unit_->GetShorty(); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 63 | int locals_index = locals_.size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 64 | int parameter_index = 0; |
| 65 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 66 | const DexFile::MethodId& referrer_method_id = |
| 67 | dex_file_->GetMethodId(dex_compilation_unit_->GetDexMethodIndex()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 68 | if (!dex_compilation_unit_->IsStatic()) { |
| 69 | // Add the implicit 'this' argument, not expressed in the signature. |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 70 | HParameterValue* parameter = new (arena_) HParameterValue(*dex_file_, |
| 71 | referrer_method_id.class_idx_, |
| 72 | parameter_index++, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 73 | Primitive::kPrimNot, |
| 74 | true); |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 75 | entry_block->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 76 | HLocal* local = GetLocalAt(locals_index++); |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 77 | entry_block->AddInstruction(new (arena_) HStoreLocal(local, parameter, local->GetDexPc())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 78 | number_of_parameters--; |
| 79 | } |
| 80 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 81 | const DexFile::ProtoId& proto = dex_file_->GetMethodPrototype(referrer_method_id); |
| 82 | const DexFile::TypeList* arg_types = dex_file_->GetProtoParameters(proto); |
| 83 | for (int i = 0, shorty_pos = 1; i < number_of_parameters; i++) { |
| 84 | HParameterValue* parameter = new (arena_) HParameterValue( |
| 85 | *dex_file_, |
| 86 | arg_types->GetTypeItem(shorty_pos - 1).type_idx_, |
| 87 | parameter_index++, |
| 88 | Primitive::GetType(shorty[shorty_pos]), |
| 89 | false); |
| 90 | ++shorty_pos; |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 91 | entry_block->AddInstruction(parameter); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 92 | HLocal* local = GetLocalAt(locals_index++); |
| 93 | // Store the parameter value in the local that the dex code will use |
| 94 | // to reference that parameter. |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 95 | entry_block->AddInstruction(new (arena_) HStoreLocal(local, parameter, local->GetDexPc())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 96 | bool is_wide = (parameter->GetType() == Primitive::kPrimLong) |
| 97 | || (parameter->GetType() == Primitive::kPrimDouble); |
| 98 | if (is_wide) { |
| 99 | i++; |
| 100 | locals_index++; |
| 101 | parameter_index++; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 102 | } |
| 103 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 104 | } |
| 105 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 106 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 107 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 108 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
| 109 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 110 | T* comparison = new (arena_) T(first, second, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 111 | current_block_->AddInstruction(comparison); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 112 | HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 113 | current_block_->AddInstruction(ifinst); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 114 | current_block_ = nullptr; |
| 115 | } |
| 116 | |
| 117 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 118 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 119 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
| 120 | 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] | 121 | current_block_->AddInstruction(comparison); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 122 | HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 123 | current_block_->AddInstruction(ifinst); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 124 | current_block_ = nullptr; |
| 125 | } |
| 126 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 127 | void HGraphBuilder::MaybeRecordStat(MethodCompilationStat compilation_stat) { |
| 128 | if (compilation_stats_ != nullptr) { |
| 129 | compilation_stats_->RecordStat(compilation_stat); |
| 130 | } |
| 131 | } |
| 132 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 133 | bool HGraphBuilder::SkipCompilation(size_t number_of_branches) { |
| 134 | if (compiler_driver_ == nullptr) { |
| 135 | // Note that the compiler driver is null when unit testing. |
| 136 | return false; |
| 137 | } |
| 138 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 139 | const CompilerOptions& compiler_options = compiler_driver_->GetCompilerOptions(); |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 140 | CompilerFilter::Filter compiler_filter = compiler_options.GetCompilerFilter(); |
| 141 | if (compiler_filter == CompilerFilter::kEverything) { |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 142 | return false; |
| 143 | } |
| 144 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 145 | if (compiler_options.IsHugeMethod(code_item_.insns_size_in_code_units_)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 146 | VLOG(compiler) << "Skip compilation of huge method " |
| 147 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 148 | << ": " << code_item_.insns_size_in_code_units_ << " code units"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 149 | MaybeRecordStat(MethodCompilationStat::kNotCompiledHugeMethod); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 150 | return true; |
| 151 | } |
| 152 | |
| 153 | // If it's large and contains no branches, it's likely to be machine generated initialization. |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 154 | if (compiler_options.IsLargeMethod(code_item_.insns_size_in_code_units_) |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 155 | && (number_of_branches == 0)) { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 156 | VLOG(compiler) << "Skip compilation of large method with no branch " |
| 157 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 158 | << ": " << code_item_.insns_size_in_code_units_ << " code units"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 159 | MaybeRecordStat(MethodCompilationStat::kNotCompiledLargeMethodNoBranches); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 160 | return true; |
| 161 | } |
| 162 | |
| 163 | return false; |
| 164 | } |
| 165 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 166 | static bool BlockIsNotPopulated(HBasicBlock* block) { |
| 167 | if (!block->GetPhis().IsEmpty()) { |
| 168 | return false; |
| 169 | } else if (block->IsLoopHeader()) { |
| 170 | // Suspend checks were inserted into loop headers during building of dominator tree. |
| 171 | DCHECK(block->GetFirstInstruction()->IsSuspendCheck()); |
| 172 | return block->GetFirstInstruction() == block->GetLastInstruction(); |
| 173 | } else { |
| 174 | return block->GetInstructions().IsEmpty(); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 178 | bool HGraphBuilder::GenerateInstructions() { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 179 | // Find locations where we want to generate extra stackmaps for native debugging. |
| 180 | // This allows us to generate the info only at interesting points (for example, |
| 181 | // at start of java statement) rather than before every dex instruction. |
| 182 | const bool native_debuggable = compiler_driver_ != nullptr && |
| 183 | compiler_driver_->GetCompilerOptions().GetNativeDebuggable(); |
| 184 | ArenaBitVector* native_debug_info_locations; |
| 185 | if (native_debuggable) { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 186 | const uint32_t num_instructions = code_item_.insns_size_in_code_units_; |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 187 | native_debug_info_locations = |
| 188 | ArenaBitVector::Create(arena_, num_instructions, false, kArenaAllocGraphBuilder); |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 189 | FindNativeDebugInfoLocations(native_debug_info_locations); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 190 | } |
| 191 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 192 | InitializeLocals(code_item_.registers_size_); |
| 193 | InitializeParameters(code_item_.ins_size_); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 194 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 195 | // Add the suspend check to the entry block. |
| 196 | current_block_ = graph_->GetEntryBlock(); |
| 197 | current_block_->AddInstruction(new (arena_) HSuspendCheck(0)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 198 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 199 | for (CodeItemIterator it(code_item_); !it.Done(); it.Advance()) { |
| 200 | uint32_t dex_pc = it.CurrentDexPc(); |
| 201 | |
| 202 | HBasicBlock* next_block = FindBlockStartingAt(dex_pc); |
| 203 | if (next_block != nullptr && next_block->GetGraph() != nullptr) { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 204 | if (current_block_ != nullptr) { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 205 | // Branching instructions clear current_block, so we know |
| 206 | // the last instruction of the current block is not a branching |
| 207 | // instruction. We add an unconditional goto to the found block. |
| 208 | current_block_->AddInstruction(new (arena_) HGoto(dex_pc)); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 209 | } |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 210 | DCHECK(BlockIsNotPopulated(next_block)); |
| 211 | current_block_ = next_block; |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 212 | } |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 213 | |
| 214 | if (current_block_ == nullptr) { |
| 215 | // Unreachable code. |
| 216 | continue; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 217 | } |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 218 | |
| 219 | if (native_debuggable && native_debug_info_locations->IsBitSet(dex_pc)) { |
| 220 | current_block_->AddInstruction(new (arena_) HNativeDebugInfo(dex_pc)); |
| 221 | } |
| 222 | |
| 223 | if (!AnalyzeDexInstruction(it.CurrentInstruction(), dex_pc)) { |
| 224 | return false; |
| 225 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 226 | } |
| 227 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 228 | // Add Exit to the exit block. |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 229 | HBasicBlock* exit_block = graph_->GetExitBlock(); |
| 230 | if (exit_block == nullptr) { |
| 231 | // Unreachable exit block was removed. |
| 232 | } else { |
| 233 | exit_block->AddInstruction(new (arena_) HExit()); |
| 234 | } |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 235 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 236 | return true; |
| 237 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 238 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 239 | GraphAnalysisResult HGraphBuilder::BuildGraph(StackHandleScopeCollection* handles) { |
| 240 | DCHECK(graph_->GetBlocks().empty()); |
| 241 | graph_->SetMaximumNumberOfOutVRegs(code_item_.outs_size_); |
| 242 | graph_->SetHasTryCatch(code_item_.tries_size_ != 0); |
| 243 | graph_->InitializeInexactObjectRTI(handles); |
| 244 | |
| 245 | // 1) Create basic blocks and link them together. Basic blocks are left |
| 246 | // unpopulated with the exception of synthetic blocks, e.g. HTryBoundaries. |
| 247 | if (!block_builder_.Build()) { |
| 248 | return kAnalysisInvalidBytecode; |
| 249 | } |
| 250 | |
| 251 | // 2) Decide whether to skip this method based on its code size and number |
| 252 | // of branches. |
| 253 | if (SkipCompilation(block_builder_.GetNumberOfBranches())) { |
| 254 | return kAnalysisSkipped; |
| 255 | } |
| 256 | |
| 257 | // 3) Build the dominator tree and fill in loop and try/catch metadata. |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 258 | GraphAnalysisResult result = graph_->BuildDominatorTree(); |
| 259 | if (result != kAnalysisSuccess) { |
| 260 | return result; |
| 261 | } |
| 262 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 263 | // 4) Populate basic blocks with instructions. |
| 264 | if (!GenerateInstructions()) { |
| 265 | return kAnalysisInvalidBytecode; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 266 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 267 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 268 | // 5) Type the graph and eliminate dead/redundant phis. |
| 269 | return SsaBuilder(graph_, code_item_, handles).BuildSsa(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 270 | } |
| 271 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 272 | void HGraphBuilder::FindNativeDebugInfoLocations(ArenaBitVector* locations) { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 273 | // The callback gets called when the line number changes. |
| 274 | // In other words, it marks the start of new java statement. |
| 275 | struct Callback { |
| 276 | static bool Position(void* ctx, const DexFile::PositionInfo& entry) { |
| 277 | static_cast<ArenaBitVector*>(ctx)->SetBit(entry.address_); |
| 278 | return false; |
| 279 | } |
| 280 | }; |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 281 | dex_file_->DecodeDebugPositionInfo(&code_item_, Callback::Position, locations); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 282 | // Instruction-specific tweaks. |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 283 | const Instruction* const begin = Instruction::At(code_item_.insns_); |
| 284 | const Instruction* const end = begin->RelativeAt(code_item_.insns_size_in_code_units_); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 285 | for (const Instruction* inst = begin; inst < end; inst = inst->Next()) { |
| 286 | switch (inst->Opcode()) { |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 287 | case Instruction::MOVE_EXCEPTION: { |
| 288 | // Stop in native debugger after the exception has been moved. |
| 289 | // The compiler also expects the move at the start of basic block so |
| 290 | // we do not want to interfere by inserting native-debug-info before it. |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 291 | locations->ClearBit(inst->GetDexPc(code_item_.insns_)); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 292 | const Instruction* next = inst->Next(); |
| 293 | if (next < end) { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 294 | locations->SetBit(next->GetDexPc(code_item_.insns_)); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 295 | } |
| 296 | break; |
| 297 | } |
| 298 | default: |
| 299 | break; |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 304 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 305 | void HGraphBuilder::Unop_12x(const Instruction& instruction, |
| 306 | Primitive::Type type, |
| 307 | uint32_t dex_pc) { |
| 308 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 309 | current_block_->AddInstruction(new (arena_) T(type, first, dex_pc)); |
| 310 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 311 | } |
| 312 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 313 | void HGraphBuilder::Conversion_12x(const Instruction& instruction, |
| 314 | Primitive::Type input_type, |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 315 | Primitive::Type result_type, |
| 316 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 317 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type, dex_pc); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 318 | current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 319 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 323 | void HGraphBuilder::Binop_23x(const Instruction& instruction, |
| 324 | Primitive::Type type, |
| 325 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 326 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 327 | HInstruction* second = LoadLocal(instruction.VRegC(), type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 328 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 329 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 333 | void HGraphBuilder::Binop_23x_shift(const Instruction& instruction, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 334 | Primitive::Type type, |
| 335 | uint32_t dex_pc) { |
| 336 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 337 | HInstruction* second = LoadLocal(instruction.VRegC(), Primitive::kPrimInt, dex_pc); |
| 338 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 339 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 342 | void HGraphBuilder::Binop_23x_cmp(const Instruction& instruction, |
| 343 | Primitive::Type type, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 344 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 345 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 346 | HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc); |
| 347 | HInstruction* second = LoadLocal(instruction.VRegC(), type, dex_pc); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 348 | current_block_->AddInstruction(new (arena_) HCompare(type, first, second, bias, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 349 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 352 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 353 | void HGraphBuilder::Binop_12x_shift(const Instruction& instruction, Primitive::Type type, |
| 354 | uint32_t dex_pc) { |
| 355 | HInstruction* first = LoadLocal(instruction.VRegA(), type, dex_pc); |
| 356 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 357 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 358 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 362 | void HGraphBuilder::Binop_12x(const Instruction& instruction, |
| 363 | Primitive::Type type, |
| 364 | uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 365 | HInstruction* first = LoadLocal(instruction.VRegA(), type, dex_pc); |
| 366 | HInstruction* second = LoadLocal(instruction.VRegB(), type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 367 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 368 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 372 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse, uint32_t dex_pc) { |
| 373 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 374 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22s(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 375 | if (reverse) { |
| 376 | std::swap(first, second); |
| 377 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 378 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second, dex_pc)); |
| 379 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 383 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse, uint32_t dex_pc) { |
| 384 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 385 | HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22b(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 386 | if (reverse) { |
| 387 | std::swap(first, second); |
| 388 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 389 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second, dex_pc)); |
| 390 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 393 | static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, const CompilerDriver& driver) { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 394 | Thread* self = Thread::Current(); |
Calin Juravle | 0c25d10 | 2015-04-20 14:49:09 +0100 | [diff] [blame] | 395 | return cu->IsConstructor() |
| 396 | && driver.RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 397 | } |
| 398 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 399 | // Returns true if `block` has only one successor which starts at the next |
| 400 | // dex_pc after `instruction` at `dex_pc`. |
| 401 | static bool IsFallthroughInstruction(const Instruction& instruction, |
| 402 | uint32_t dex_pc, |
| 403 | HBasicBlock* block) { |
| 404 | uint32_t next_dex_pc = dex_pc + instruction.SizeInCodeUnits(); |
| 405 | return block->GetSingleSuccessor()->GetDexPc() == next_dex_pc; |
| 406 | } |
| 407 | |
| 408 | void HGraphBuilder::BuildSwitch(const Instruction& instruction, uint32_t dex_pc) { |
| 409 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc); |
| 410 | DexSwitchTable table(instruction, dex_pc); |
| 411 | |
| 412 | if (table.GetNumEntries() == 0) { |
| 413 | // Empty Switch. Code falls through to the next block. |
| 414 | DCHECK(IsFallthroughInstruction(instruction, dex_pc, current_block_)); |
| 415 | current_block_->AddInstruction(new (arena_) HGoto(dex_pc)); |
| 416 | } else if (table.ShouldBuildDecisionTree()) { |
| 417 | for (DexSwitchTableIterator it(table); !it.Done(); it.Advance()) { |
| 418 | HInstruction* case_value = graph_->GetIntConstant(it.CurrentKey(), dex_pc); |
| 419 | HEqual* comparison = new (arena_) HEqual(value, case_value, dex_pc); |
| 420 | current_block_->AddInstruction(comparison); |
| 421 | HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc); |
| 422 | current_block_->AddInstruction(ifinst); |
| 423 | |
| 424 | if (!it.IsLast()) { |
| 425 | current_block_ = FindBlockStartingAt(it.GetDexPcForCurrentIndex()); |
| 426 | } |
| 427 | } |
| 428 | } else { |
| 429 | current_block_->AddInstruction( |
| 430 | new (arena_) HPackedSwitch(table.GetEntryAt(0), table.GetNumEntries(), value, dex_pc)); |
| 431 | } |
| 432 | |
| 433 | current_block_ = nullptr; |
| 434 | } |
| 435 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 436 | void HGraphBuilder::BuildReturn(const Instruction& instruction, |
| 437 | Primitive::Type type, |
| 438 | uint32_t dex_pc) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 439 | if (type == Primitive::kPrimVoid) { |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 440 | if (graph_->ShouldGenerateConstructorBarrier()) { |
| 441 | // The compilation unit is null during testing. |
| 442 | if (dex_compilation_unit_ != nullptr) { |
| 443 | DCHECK(RequiresConstructorBarrier(dex_compilation_unit_, *compiler_driver_)) |
| 444 | << "Inconsistent use of ShouldGenerateConstructorBarrier. Should not generate a barrier."; |
| 445 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 446 | current_block_->AddInstruction(new (arena_) HMemoryBarrier(kStoreStore, dex_pc)); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 447 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 448 | current_block_->AddInstruction(new (arena_) HReturnVoid(dex_pc)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 449 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 450 | HInstruction* value = LoadLocal(instruction.VRegA(), type, dex_pc); |
| 451 | current_block_->AddInstruction(new (arena_) HReturn(value, dex_pc)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 452 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 453 | current_block_ = nullptr; |
| 454 | } |
| 455 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 456 | static InvokeType GetInvokeTypeFromOpCode(Instruction::Code opcode) { |
| 457 | switch (opcode) { |
| 458 | case Instruction::INVOKE_STATIC: |
| 459 | case Instruction::INVOKE_STATIC_RANGE: |
| 460 | return kStatic; |
| 461 | case Instruction::INVOKE_DIRECT: |
| 462 | case Instruction::INVOKE_DIRECT_RANGE: |
| 463 | return kDirect; |
| 464 | case Instruction::INVOKE_VIRTUAL: |
| 465 | case Instruction::INVOKE_VIRTUAL_QUICK: |
| 466 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 467 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: |
| 468 | return kVirtual; |
| 469 | case Instruction::INVOKE_INTERFACE: |
| 470 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 471 | return kInterface; |
| 472 | case Instruction::INVOKE_SUPER_RANGE: |
| 473 | case Instruction::INVOKE_SUPER: |
| 474 | return kSuper; |
| 475 | default: |
| 476 | LOG(FATAL) << "Unexpected invoke opcode: " << opcode; |
| 477 | UNREACHABLE(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 478 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 481 | ArtMethod* HGraphBuilder::ResolveMethod(uint16_t method_idx, InvokeType invoke_type) { |
| 482 | ScopedObjectAccess soa(Thread::Current()); |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 483 | StackHandleScope<3> hs(soa.Self()); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 484 | |
| 485 | ClassLinker* class_linker = dex_compilation_unit_->GetClassLinker(); |
| 486 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 487 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 488 | Handle<mirror::Class> compiling_class(hs.NewHandle(GetCompilingClass())); |
| 489 | |
Andreas Gampe | dae2414 | 2015-12-03 17:27:32 -0800 | [diff] [blame] | 490 | ArtMethod* resolved_method = class_linker->ResolveMethod<ClassLinker::kForceICCECheck>( |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 491 | *dex_compilation_unit_->GetDexFile(), |
| 492 | method_idx, |
| 493 | dex_compilation_unit_->GetDexCache(), |
| 494 | class_loader, |
| 495 | /* referrer */ nullptr, |
| 496 | invoke_type); |
| 497 | |
| 498 | if (UNLIKELY(resolved_method == nullptr)) { |
| 499 | // Clean up any exception left by type resolution. |
| 500 | soa.Self()->ClearException(); |
| 501 | return nullptr; |
| 502 | } |
| 503 | |
| 504 | // Check access. The class linker has a fast path for looking into the dex cache |
| 505 | // and does not check the access if it hits it. |
| 506 | if (compiling_class.Get() == nullptr) { |
| 507 | if (!resolved_method->IsPublic()) { |
| 508 | return nullptr; |
| 509 | } |
| 510 | } else if (!compiling_class->CanAccessResolvedMethod(resolved_method->GetDeclaringClass(), |
| 511 | resolved_method, |
| 512 | dex_compilation_unit_->GetDexCache().Get(), |
| 513 | method_idx)) { |
| 514 | return nullptr; |
| 515 | } |
| 516 | |
| 517 | // We have to special case the invoke-super case, as ClassLinker::ResolveMethod does not. |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 518 | // We need to look at the referrer's super class vtable. We need to do this to know if we need to |
| 519 | // make this an invoke-unresolved to handle cross-dex invokes or abstract super methods, both of |
| 520 | // which require runtime handling. |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 521 | if (invoke_type == kSuper) { |
| 522 | if (compiling_class.Get() == nullptr) { |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 523 | // We could not determine the method's class we need to wait until runtime. |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 524 | DCHECK(Runtime::Current()->IsAotCompiler()); |
| 525 | return nullptr; |
| 526 | } |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 527 | ArtMethod* current_method = graph_->GetArtMethod(); |
| 528 | DCHECK(current_method != nullptr); |
| 529 | Handle<mirror::Class> methods_class(hs.NewHandle( |
| 530 | dex_compilation_unit_->GetClassLinker()->ResolveReferencedClassOfMethod(Thread::Current(), |
| 531 | method_idx, |
| 532 | current_method))); |
| 533 | if (methods_class.Get() == nullptr) { |
| 534 | // Invoking a super method requires knowing the actual super class. If we did not resolve |
| 535 | // the compiling method's declaring class (which only happens for ahead of time |
| 536 | // compilation), bail out. |
| 537 | DCHECK(Runtime::Current()->IsAotCompiler()); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 538 | return nullptr; |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 539 | } else { |
| 540 | ArtMethod* actual_method; |
| 541 | if (methods_class->IsInterface()) { |
| 542 | actual_method = methods_class->FindVirtualMethodForInterfaceSuper( |
| 543 | resolved_method, class_linker->GetImagePointerSize()); |
| 544 | } else { |
| 545 | uint16_t vtable_index = resolved_method->GetMethodIndex(); |
| 546 | actual_method = compiling_class->GetSuperClass()->GetVTableEntry( |
| 547 | vtable_index, class_linker->GetImagePointerSize()); |
| 548 | } |
| 549 | if (actual_method != resolved_method && |
| 550 | !IsSameDexFile(*actual_method->GetDexFile(), *dex_compilation_unit_->GetDexFile())) { |
| 551 | // The back-end code generator relies on this check in order to ensure that it will not |
| 552 | // attempt to read the dex_cache with a dex_method_index that is not from the correct |
| 553 | // dex_file. If we didn't do this check then the dex_method_index will not be updated in the |
| 554 | // builder, which means that the code-generator (and compiler driver during sharpening and |
| 555 | // inliner, maybe) might invoke an incorrect method. |
| 556 | // TODO: The actual method could still be referenced in the current dex file, so we |
| 557 | // could try locating it. |
| 558 | // TODO: Remove the dex_file restriction. |
| 559 | return nullptr; |
| 560 | } |
| 561 | if (!actual_method->IsInvokable()) { |
| 562 | // Fail if the actual method cannot be invoked. Otherwise, the runtime resolution stub |
| 563 | // could resolve the callee to the wrong method. |
| 564 | return nullptr; |
| 565 | } |
| 566 | resolved_method = actual_method; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 567 | } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | // Check for incompatible class changes. The class linker has a fast path for |
| 571 | // looking into the dex cache and does not check incompatible class changes if it hits it. |
| 572 | if (resolved_method->CheckIncompatibleClassChange(invoke_type)) { |
| 573 | return nullptr; |
| 574 | } |
| 575 | |
| 576 | return resolved_method; |
| 577 | } |
| 578 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 579 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
| 580 | uint32_t dex_pc, |
| 581 | uint32_t method_idx, |
| 582 | uint32_t number_of_vreg_arguments, |
| 583 | bool is_range, |
| 584 | uint32_t* args, |
| 585 | uint32_t register_index) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 586 | InvokeType invoke_type = GetInvokeTypeFromOpCode(instruction.Opcode()); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 587 | const char* descriptor = dex_file_->GetMethodShorty(method_idx); |
| 588 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
| 589 | |
| 590 | // Remove the return type from the 'proto'. |
| 591 | size_t number_of_arguments = strlen(descriptor) - 1; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 592 | if (invoke_type != kStatic) { // instance call |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 593 | // One extra argument for 'this'. |
| 594 | number_of_arguments++; |
| 595 | } |
| 596 | |
| 597 | MethodReference target_method(dex_file_, method_idx); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 598 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 599 | // Special handling for string init. |
| 600 | int32_t string_init_offset = 0; |
| 601 | bool is_string_init = compiler_driver_->IsStringInit(method_idx, |
| 602 | dex_file_, |
| 603 | &string_init_offset); |
| 604 | // Replace calls to String.<init> with StringFactory. |
| 605 | if (is_string_init) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 606 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
| 607 | HInvokeStaticOrDirect::MethodLoadKind::kStringInit, |
| 608 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 609 | dchecked_integral_cast<uint64_t>(string_init_offset), |
| 610 | 0U |
| 611 | }; |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 612 | HInvoke* invoke = new (arena_) HInvokeStaticOrDirect( |
| 613 | arena_, |
| 614 | number_of_arguments - 1, |
| 615 | Primitive::kPrimNot /*return_type */, |
| 616 | dex_pc, |
| 617 | method_idx, |
| 618 | target_method, |
| 619 | dispatch_info, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 620 | invoke_type, |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 621 | kStatic /* optimized_invoke_type */, |
| 622 | HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit); |
| 623 | return HandleStringInit(invoke, |
| 624 | number_of_vreg_arguments, |
| 625 | args, |
| 626 | register_index, |
| 627 | is_range, |
| 628 | descriptor); |
| 629 | } |
| 630 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 631 | ArtMethod* resolved_method = ResolveMethod(method_idx, invoke_type); |
| 632 | |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 633 | if (UNLIKELY(resolved_method == nullptr)) { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 634 | MaybeRecordStat(MethodCompilationStat::kUnresolvedMethod); |
| 635 | HInvoke* invoke = new (arena_) HInvokeUnresolved(arena_, |
| 636 | number_of_arguments, |
| 637 | return_type, |
| 638 | dex_pc, |
| 639 | method_idx, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 640 | invoke_type); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 641 | return HandleInvoke(invoke, |
| 642 | number_of_vreg_arguments, |
| 643 | args, |
| 644 | register_index, |
| 645 | is_range, |
| 646 | descriptor, |
| 647 | nullptr /* clinit_check */); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 648 | } |
| 649 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 650 | // Potential class initialization check, in the case of a static method call. |
| 651 | HClinitCheck* clinit_check = nullptr; |
| 652 | HInvoke* invoke = nullptr; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 653 | if (invoke_type == kDirect || invoke_type == kStatic || invoke_type == kSuper) { |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 654 | // By default, consider that the called method implicitly requires |
| 655 | // an initialization check of its declaring method. |
| 656 | HInvokeStaticOrDirect::ClinitCheckRequirement clinit_check_requirement |
| 657 | = HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 658 | ScopedObjectAccess soa(Thread::Current()); |
| 659 | if (invoke_type == kStatic) { |
| 660 | clinit_check = ProcessClinitCheckForInvoke( |
| 661 | dex_pc, resolved_method, method_idx, &clinit_check_requirement); |
| 662 | } else if (invoke_type == kSuper) { |
| 663 | if (IsSameDexFile(*resolved_method->GetDexFile(), *dex_compilation_unit_->GetDexFile())) { |
| 664 | // Update the target method to the one resolved. Note that this may be a no-op if |
| 665 | // we resolved to the method referenced by the instruction. |
| 666 | method_idx = resolved_method->GetDexMethodIndex(); |
| 667 | target_method = MethodReference(dex_file_, method_idx); |
| 668 | } |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 669 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 670 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 671 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = { |
| 672 | HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod, |
| 673 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 674 | 0u, |
| 675 | 0U |
| 676 | }; |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 677 | invoke = new (arena_) HInvokeStaticOrDirect(arena_, |
| 678 | number_of_arguments, |
| 679 | return_type, |
| 680 | dex_pc, |
| 681 | method_idx, |
| 682 | target_method, |
| 683 | dispatch_info, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 684 | invoke_type, |
| 685 | invoke_type, |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 686 | clinit_check_requirement); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 687 | } else if (invoke_type == kVirtual) { |
| 688 | ScopedObjectAccess soa(Thread::Current()); // Needed for the method index |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 689 | invoke = new (arena_) HInvokeVirtual(arena_, |
| 690 | number_of_arguments, |
| 691 | return_type, |
| 692 | dex_pc, |
| 693 | method_idx, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 694 | resolved_method->GetMethodIndex()); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 695 | } else { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 696 | DCHECK_EQ(invoke_type, kInterface); |
| 697 | ScopedObjectAccess soa(Thread::Current()); // Needed for the method index |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 698 | invoke = new (arena_) HInvokeInterface(arena_, |
| 699 | number_of_arguments, |
| 700 | return_type, |
| 701 | dex_pc, |
| 702 | method_idx, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 703 | resolved_method->GetDexMethodIndex()); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 704 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 705 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 706 | return HandleInvoke(invoke, |
| 707 | number_of_vreg_arguments, |
| 708 | args, |
| 709 | register_index, |
| 710 | is_range, |
| 711 | descriptor, |
| 712 | clinit_check); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 713 | } |
| 714 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 715 | bool HGraphBuilder::BuildNewInstance(uint16_t type_index, uint32_t dex_pc) { |
| 716 | bool finalizable; |
| 717 | bool can_throw = NeedsAccessCheck(type_index, &finalizable); |
| 718 | |
| 719 | // Only the non-resolved entrypoint handles the finalizable class case. If we |
| 720 | // need access checks, then we haven't resolved the method and the class may |
| 721 | // again be finalizable. |
| 722 | QuickEntrypointEnum entrypoint = (finalizable || can_throw) |
| 723 | ? kQuickAllocObject |
| 724 | : kQuickAllocObjectInitialized; |
| 725 | |
| 726 | ScopedObjectAccess soa(Thread::Current()); |
| 727 | StackHandleScope<3> hs(soa.Self()); |
| 728 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 729 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 730 | soa.Self(), *dex_compilation_unit_->GetDexFile()))); |
| 731 | Handle<mirror::Class> resolved_class(hs.NewHandle(dex_cache->GetResolvedType(type_index))); |
| 732 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 733 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
| 734 | outer_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), outer_dex_file))); |
| 735 | |
| 736 | if (outer_dex_cache.Get() != dex_cache.Get()) { |
| 737 | // We currently do not support inlining allocations across dex files. |
| 738 | return false; |
| 739 | } |
| 740 | |
| 741 | HLoadClass* load_class = new (arena_) HLoadClass( |
| 742 | graph_->GetCurrentMethod(), |
| 743 | type_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 744 | outer_dex_file, |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 745 | IsOutermostCompilingClass(type_index), |
| 746 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 747 | /*needs_access_check*/ can_throw, |
| 748 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(outer_dex_file, type_index)); |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 749 | |
| 750 | current_block_->AddInstruction(load_class); |
| 751 | HInstruction* cls = load_class; |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 752 | if (!IsInitialized(resolved_class)) { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 753 | cls = new (arena_) HClinitCheck(load_class, dex_pc); |
| 754 | current_block_->AddInstruction(cls); |
| 755 | } |
| 756 | |
| 757 | current_block_->AddInstruction(new (arena_) HNewInstance( |
| 758 | cls, |
| 759 | graph_->GetCurrentMethod(), |
| 760 | dex_pc, |
| 761 | type_index, |
| 762 | *dex_compilation_unit_->GetDexFile(), |
| 763 | can_throw, |
| 764 | finalizable, |
| 765 | entrypoint)); |
| 766 | return true; |
| 767 | } |
| 768 | |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 769 | static bool IsSubClass(mirror::Class* to_test, mirror::Class* super_class) |
| 770 | SHARED_REQUIRES(Locks::mutator_lock_) { |
| 771 | return to_test != nullptr && !to_test->IsInterface() && to_test->IsSubClass(super_class); |
| 772 | } |
| 773 | |
| 774 | bool HGraphBuilder::IsInitialized(Handle<mirror::Class> cls) const { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 775 | if (cls.Get() == nullptr) { |
| 776 | return false; |
| 777 | } |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 778 | |
| 779 | // `CanAssumeClassIsLoaded` will return true if we're JITting, or will |
| 780 | // check whether the class is in an image for the AOT compilation. |
| 781 | if (cls->IsInitialized() && |
| 782 | compiler_driver_->CanAssumeClassIsLoaded(cls.Get())) { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 783 | return true; |
| 784 | } |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 785 | |
| 786 | if (IsSubClass(GetOutermostCompilingClass(), cls.Get())) { |
| 787 | return true; |
| 788 | } |
| 789 | |
| 790 | // TODO: We should walk over the inlined methods, but we don't pass |
| 791 | // that information to the builder. |
| 792 | if (IsSubClass(GetCompilingClass(), cls.Get())) { |
| 793 | return true; |
| 794 | } |
| 795 | |
| 796 | return false; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 799 | HClinitCheck* HGraphBuilder::ProcessClinitCheckForInvoke( |
| 800 | uint32_t dex_pc, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 801 | ArtMethod* resolved_method, |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 802 | uint32_t method_idx, |
| 803 | HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 804 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 805 | Thread* self = Thread::Current(); |
| 806 | StackHandleScope<4> hs(self); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 807 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
| 808 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 809 | self, *dex_compilation_unit_->GetDexFile()))); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 810 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 811 | outer_compilation_unit_->GetClassLinker()->FindDexCache( |
| 812 | self, outer_dex_file))); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 813 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 814 | Handle<mirror::Class> resolved_method_class(hs.NewHandle(resolved_method->GetDeclaringClass())); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 815 | |
| 816 | // The index at which the method's class is stored in the DexCache's type array. |
| 817 | uint32_t storage_index = DexFile::kDexNoIndex; |
| 818 | bool is_outer_class = (resolved_method->GetDeclaringClass() == outer_class.Get()); |
| 819 | if (is_outer_class) { |
| 820 | storage_index = outer_class->GetDexTypeIndex(); |
| 821 | } else if (outer_dex_cache.Get() == dex_cache.Get()) { |
| 822 | // Get `storage_index` from IsClassOfStaticMethodAvailableToReferrer. |
| 823 | compiler_driver_->IsClassOfStaticMethodAvailableToReferrer(outer_dex_cache.Get(), |
| 824 | GetCompilingClass(), |
| 825 | resolved_method, |
| 826 | method_idx, |
| 827 | &storage_index); |
| 828 | } |
| 829 | |
| 830 | HClinitCheck* clinit_check = nullptr; |
| 831 | |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 832 | if (IsInitialized(resolved_method_class)) { |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 833 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone; |
| 834 | } else if (storage_index != DexFile::kDexNoIndex) { |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 835 | *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit; |
| 836 | HLoadClass* load_class = new (arena_) HLoadClass( |
| 837 | graph_->GetCurrentMethod(), |
| 838 | storage_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 839 | outer_dex_file, |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 840 | is_outer_class, |
| 841 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 842 | /*needs_access_check*/ false, |
| 843 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(outer_dex_file, storage_index)); |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 844 | current_block_->AddInstruction(load_class); |
| 845 | clinit_check = new (arena_) HClinitCheck(load_class, dex_pc); |
| 846 | current_block_->AddInstruction(clinit_check); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 847 | } |
| 848 | return clinit_check; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 849 | } |
| 850 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 851 | bool HGraphBuilder::SetupInvokeArguments(HInvoke* invoke, |
| 852 | uint32_t number_of_vreg_arguments, |
| 853 | uint32_t* args, |
| 854 | uint32_t register_index, |
| 855 | bool is_range, |
| 856 | const char* descriptor, |
| 857 | size_t start_index, |
| 858 | size_t* argument_index) { |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 859 | uint32_t descriptor_index = 1; // Skip the return type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 860 | uint32_t dex_pc = invoke->GetDexPc(); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 861 | |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 862 | for (size_t i = start_index; |
| 863 | // Make sure we don't go over the expected arguments or over the number of |
| 864 | // dex registers given. If the instruction was seen as dead by the verifier, |
| 865 | // it hasn't been properly checked. |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 866 | (i < number_of_vreg_arguments) && (*argument_index < invoke->GetNumberOfArguments()); |
| 867 | i++, (*argument_index)++) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 868 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 869 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 870 | if (!is_range |
| 871 | && is_wide |
| 872 | && ((i + 1 == number_of_vreg_arguments) || (args[i] + 1 != args[i + 1]))) { |
| 873 | // Longs and doubles should be in pairs, that is, sequential registers. The verifier should |
| 874 | // reject any class where this is violated. However, the verifier only does these checks |
| 875 | // on non trivially dead instructions, so we just bailout the compilation. |
| 876 | VLOG(compiler) << "Did not compile " |
| 877 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 878 | << " because of non-sequential dex register pair in wide argument"; |
| 879 | MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 880 | return false; |
| 881 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 882 | 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] | 883 | invoke->SetArgumentAt(*argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 884 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 885 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 886 | } |
| 887 | } |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 888 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 889 | if (*argument_index != invoke->GetNumberOfArguments()) { |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 890 | VLOG(compiler) << "Did not compile " |
| 891 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 892 | << " because of wrong number of arguments in invoke instruction"; |
| 893 | MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode); |
| 894 | return false; |
| 895 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 896 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 897 | if (invoke->IsInvokeStaticOrDirect() && |
| 898 | HInvokeStaticOrDirect::NeedsCurrentMethodInput( |
| 899 | invoke->AsInvokeStaticOrDirect()->GetMethodLoadKind())) { |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 900 | invoke->SetArgumentAt(*argument_index, graph_->GetCurrentMethod()); |
| 901 | (*argument_index)++; |
| 902 | } |
| 903 | |
| 904 | return true; |
| 905 | } |
| 906 | |
| 907 | bool HGraphBuilder::HandleInvoke(HInvoke* invoke, |
| 908 | uint32_t number_of_vreg_arguments, |
| 909 | uint32_t* args, |
| 910 | uint32_t register_index, |
| 911 | bool is_range, |
| 912 | const char* descriptor, |
| 913 | HClinitCheck* clinit_check) { |
| 914 | DCHECK(!invoke->IsInvokeStaticOrDirect() || !invoke->AsInvokeStaticOrDirect()->IsStringInit()); |
| 915 | |
| 916 | size_t start_index = 0; |
| 917 | size_t argument_index = 0; |
| 918 | if (invoke->GetOriginalInvokeType() != InvokeType::kStatic) { // Instance call. |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 919 | HInstruction* arg = LoadLocal( |
| 920 | is_range ? register_index : args[0], Primitive::kPrimNot, invoke->GetDexPc()); |
| 921 | HNullCheck* null_check = new (arena_) HNullCheck(arg, invoke->GetDexPc()); |
| 922 | current_block_->AddInstruction(null_check); |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 923 | invoke->SetArgumentAt(0, null_check); |
| 924 | start_index = 1; |
| 925 | argument_index = 1; |
| 926 | } |
| 927 | |
| 928 | if (!SetupInvokeArguments(invoke, |
| 929 | number_of_vreg_arguments, |
| 930 | args, |
| 931 | register_index, |
| 932 | is_range, |
| 933 | descriptor, |
| 934 | start_index, |
| 935 | &argument_index)) { |
| 936 | return false; |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 937 | } |
| 938 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 939 | if (clinit_check != nullptr) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 940 | // Add the class initialization check as last input of `invoke`. |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 941 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 942 | DCHECK(invoke->AsInvokeStaticOrDirect()->GetClinitCheckRequirement() |
| 943 | == HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 944 | invoke->SetArgumentAt(argument_index, clinit_check); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 945 | argument_index++; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 946 | } |
| 947 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 948 | current_block_->AddInstruction(invoke); |
| 949 | latest_result_ = invoke; |
| 950 | |
| 951 | return true; |
| 952 | } |
| 953 | |
| 954 | bool HGraphBuilder::HandleStringInit(HInvoke* invoke, |
| 955 | uint32_t number_of_vreg_arguments, |
| 956 | uint32_t* args, |
| 957 | uint32_t register_index, |
| 958 | bool is_range, |
| 959 | const char* descriptor) { |
| 960 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 961 | DCHECK(invoke->AsInvokeStaticOrDirect()->IsStringInit()); |
| 962 | |
| 963 | size_t start_index = 1; |
| 964 | size_t argument_index = 0; |
| 965 | if (!SetupInvokeArguments(invoke, |
| 966 | number_of_vreg_arguments, |
| 967 | args, |
| 968 | register_index, |
| 969 | is_range, |
| 970 | descriptor, |
| 971 | start_index, |
| 972 | &argument_index)) { |
| 973 | return false; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 974 | } |
Calin Juravle | 0eedd7e | 2015-08-20 14:48:00 +0100 | [diff] [blame] | 975 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 976 | // Add move-result for StringFactory method. |
| 977 | uint32_t orig_this_reg = is_range ? register_index : args[0]; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 978 | HInstruction* new_instance = LoadLocal(orig_this_reg, Primitive::kPrimNot, invoke->GetDexPc()); |
| 979 | invoke->SetArgumentAt(argument_index, new_instance); |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 980 | current_block_->AddInstruction(invoke); |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 981 | |
Calin Juravle | 0eedd7e | 2015-08-20 14:48:00 +0100 | [diff] [blame] | 982 | latest_result_ = invoke; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 983 | return true; |
| 984 | } |
| 985 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 986 | static Primitive::Type GetFieldAccessType(const DexFile& dex_file, uint16_t field_index) { |
| 987 | const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index); |
| 988 | const char* type = dex_file.GetFieldTypeDescriptor(field_id); |
| 989 | return Primitive::GetType(type[0]); |
| 990 | } |
| 991 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 992 | bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 993 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 994 | bool is_put) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 995 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 996 | uint32_t obj_reg = instruction.VRegB_22c(); |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 997 | uint16_t field_index; |
| 998 | if (instruction.IsQuickened()) { |
| 999 | if (!CanDecodeQuickenedInfo()) { |
| 1000 | return false; |
| 1001 | } |
| 1002 | field_index = LookupQuickenedInfo(dex_pc); |
| 1003 | } else { |
| 1004 | field_index = instruction.VRegC_22c(); |
| 1005 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1006 | |
| 1007 | ScopedObjectAccess soa(Thread::Current()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1008 | ArtField* resolved_field = |
| 1009 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1010 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 1011 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1012 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot, dex_pc); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1013 | HInstruction* null_check = new (arena_) HNullCheck(object, dex_pc); |
| 1014 | current_block_->AddInstruction(null_check); |
| 1015 | |
| 1016 | Primitive::Type field_type = (resolved_field == nullptr) |
| 1017 | ? GetFieldAccessType(*dex_file_, field_index) |
| 1018 | : resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1019 | if (is_put) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1020 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1021 | HInstruction* field_set = nullptr; |
| 1022 | if (resolved_field == nullptr) { |
| 1023 | MaybeRecordStat(MethodCompilationStat::kUnresolvedField); |
| 1024 | field_set = new (arena_) HUnresolvedInstanceFieldSet(null_check, |
| 1025 | value, |
| 1026 | field_type, |
| 1027 | field_index, |
| 1028 | dex_pc); |
| 1029 | } else { |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1030 | uint16_t class_def_index = resolved_field->GetDeclaringClass()->GetDexClassDefIndex(); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1031 | field_set = new (arena_) HInstanceFieldSet(null_check, |
| 1032 | value, |
| 1033 | field_type, |
| 1034 | resolved_field->GetOffset(), |
| 1035 | resolved_field->IsVolatile(), |
| 1036 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1037 | class_def_index, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1038 | *dex_file_, |
| 1039 | dex_compilation_unit_->GetDexCache(), |
| 1040 | dex_pc); |
| 1041 | } |
| 1042 | current_block_->AddInstruction(field_set); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1043 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1044 | HInstruction* field_get = nullptr; |
| 1045 | if (resolved_field == nullptr) { |
| 1046 | MaybeRecordStat(MethodCompilationStat::kUnresolvedField); |
| 1047 | field_get = new (arena_) HUnresolvedInstanceFieldGet(null_check, |
| 1048 | field_type, |
| 1049 | field_index, |
| 1050 | dex_pc); |
| 1051 | } else { |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1052 | uint16_t class_def_index = resolved_field->GetDeclaringClass()->GetDexClassDefIndex(); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1053 | field_get = new (arena_) HInstanceFieldGet(null_check, |
| 1054 | field_type, |
| 1055 | resolved_field->GetOffset(), |
| 1056 | resolved_field->IsVolatile(), |
| 1057 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1058 | class_def_index, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1059 | *dex_file_, |
| 1060 | dex_compilation_unit_->GetDexCache(), |
| 1061 | dex_pc); |
| 1062 | } |
| 1063 | current_block_->AddInstruction(field_get); |
| 1064 | UpdateLocal(source_or_dest_reg, field_get, dex_pc); |
Calin Juravle | e6f49b4 | 2015-09-17 14:04:33 +0000 | [diff] [blame] | 1065 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1066 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1067 | return true; |
| 1068 | } |
| 1069 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1070 | static mirror::Class* GetClassFrom(CompilerDriver* driver, |
| 1071 | const DexCompilationUnit& compilation_unit) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1072 | ScopedObjectAccess soa(Thread::Current()); |
| 1073 | StackHandleScope<2> hs(soa.Self()); |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1074 | const DexFile& dex_file = *compilation_unit.GetDexFile(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1075 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1076 | soa.Decode<mirror::ClassLoader*>(compilation_unit.GetClassLoader()))); |
| 1077 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1078 | compilation_unit.GetClassLinker()->FindDexCache(soa.Self(), dex_file))); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1079 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1080 | return driver->ResolveCompilingMethodsClass(soa, dex_cache, class_loader, &compilation_unit); |
| 1081 | } |
| 1082 | |
| 1083 | mirror::Class* HGraphBuilder::GetOutermostCompilingClass() const { |
| 1084 | return GetClassFrom(compiler_driver_, *outer_compilation_unit_); |
| 1085 | } |
| 1086 | |
| 1087 | mirror::Class* HGraphBuilder::GetCompilingClass() const { |
| 1088 | return GetClassFrom(compiler_driver_, *dex_compilation_unit_); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | bool HGraphBuilder::IsOutermostCompilingClass(uint16_t type_index) const { |
| 1092 | ScopedObjectAccess soa(Thread::Current()); |
| 1093 | StackHandleScope<4> hs(soa.Self()); |
| 1094 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1095 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 1096 | soa.Self(), *dex_compilation_unit_->GetDexFile()))); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1097 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 1098 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
| 1099 | Handle<mirror::Class> cls(hs.NewHandle(compiler_driver_->ResolveClass( |
| 1100 | soa, dex_cache, class_loader, type_index, dex_compilation_unit_))); |
Nicolas Geoffray | afd0641 | 2015-06-20 22:44:47 +0100 | [diff] [blame] | 1101 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1102 | |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 1103 | // GetOutermostCompilingClass returns null when the class is unresolved |
| 1104 | // (e.g. if it derives from an unresolved class). This is bogus knowing that |
| 1105 | // we are compiling it. |
| 1106 | // When this happens we cannot establish a direct relation between the current |
| 1107 | // class and the outer class, so we return false. |
| 1108 | // (Note that this is only used for optimizing invokes and field accesses) |
| 1109 | return (cls.Get() != nullptr) && (outer_class.Get() == cls.Get()); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1112 | void HGraphBuilder::BuildUnresolvedStaticFieldAccess(const Instruction& instruction, |
| 1113 | uint32_t dex_pc, |
| 1114 | bool is_put, |
| 1115 | Primitive::Type field_type) { |
| 1116 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1117 | uint16_t field_index = instruction.VRegB_21c(); |
| 1118 | |
| 1119 | if (is_put) { |
| 1120 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc); |
| 1121 | current_block_->AddInstruction( |
| 1122 | new (arena_) HUnresolvedStaticFieldSet(value, field_type, field_index, dex_pc)); |
| 1123 | } else { |
| 1124 | current_block_->AddInstruction( |
| 1125 | new (arena_) HUnresolvedStaticFieldGet(field_type, field_index, dex_pc)); |
| 1126 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc); |
| 1127 | } |
| 1128 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1129 | bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1130 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1131 | bool is_put) { |
| 1132 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 1133 | uint16_t field_index = instruction.VRegB_21c(); |
| 1134 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1135 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1136 | StackHandleScope<5> hs(soa.Self()); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1137 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1138 | dex_compilation_unit_->GetClassLinker()->FindDexCache( |
| 1139 | soa.Self(), *dex_compilation_unit_->GetDexFile()))); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1140 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle( |
| 1141 | soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader()))); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1142 | ArtField* resolved_field = compiler_driver_->ResolveField( |
| 1143 | soa, dex_cache, class_loader, dex_compilation_unit_, field_index, true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1144 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1145 | if (resolved_field == nullptr) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1146 | MaybeRecordStat(MethodCompilationStat::kUnresolvedField); |
| 1147 | Primitive::Type field_type = GetFieldAccessType(*dex_file_, field_index); |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1148 | BuildUnresolvedStaticFieldAccess(instruction, dex_pc, is_put, field_type); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1149 | return true; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1150 | } |
| 1151 | |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1152 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1153 | const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile(); |
| 1154 | Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle( |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1155 | outer_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), outer_dex_file))); |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1156 | Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass())); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1157 | |
| 1158 | // The index at which the field's class is stored in the DexCache's type array. |
| 1159 | uint32_t storage_index; |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1160 | bool is_outer_class = (outer_class.Get() == resolved_field->GetDeclaringClass()); |
| 1161 | if (is_outer_class) { |
| 1162 | storage_index = outer_class->GetDexTypeIndex(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1163 | } else if (outer_dex_cache.Get() != dex_cache.Get()) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1164 | // The compiler driver cannot currently understand multiple dex caches involved. Just bailout. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1165 | return false; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1166 | } else { |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1167 | // 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] | 1168 | std::pair<bool, bool> pair = compiler_driver_->IsFastStaticField( |
| 1169 | outer_dex_cache.Get(), |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1170 | GetCompilingClass(), |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 1171 | resolved_field, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1172 | field_index, |
| 1173 | &storage_index); |
| 1174 | bool can_easily_access = is_put ? pair.second : pair.first; |
| 1175 | if (!can_easily_access) { |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 1176 | MaybeRecordStat(MethodCompilationStat::kUnresolvedFieldNotAFastAccess); |
| 1177 | BuildUnresolvedStaticFieldAccess(instruction, dex_pc, is_put, field_type); |
| 1178 | return true; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1179 | } |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1182 | bool is_in_cache = |
| 1183 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(outer_dex_file, storage_index); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1184 | HLoadClass* constant = new (arena_) HLoadClass(graph_->GetCurrentMethod(), |
| 1185 | storage_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1186 | outer_dex_file, |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 1187 | is_outer_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1188 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1189 | /*needs_access_check*/ false, |
| 1190 | is_in_cache); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1191 | current_block_->AddInstruction(constant); |
| 1192 | |
| 1193 | HInstruction* cls = constant; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1194 | |
| 1195 | Handle<mirror::Class> klass(hs.NewHandle(resolved_field->GetDeclaringClass())); |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 1196 | if (!IsInitialized(klass)) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1197 | cls = new (arena_) HClinitCheck(constant, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1198 | current_block_->AddInstruction(cls); |
| 1199 | } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1200 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 1201 | uint16_t class_def_index = klass->GetDexClassDefIndex(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1202 | if (is_put) { |
| 1203 | // We need to keep the class alive before loading the value. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1204 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1205 | DCHECK_EQ(value->GetType(), field_type); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1206 | current_block_->AddInstruction(new (arena_) HStaticFieldSet(cls, |
| 1207 | value, |
| 1208 | field_type, |
| 1209 | resolved_field->GetOffset(), |
| 1210 | resolved_field->IsVolatile(), |
| 1211 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1212 | class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 1213 | *dex_file_, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1214 | dex_cache_, |
| 1215 | dex_pc)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1216 | } else { |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 1217 | current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls, |
| 1218 | field_type, |
| 1219 | resolved_field->GetOffset(), |
| 1220 | resolved_field->IsVolatile(), |
| 1221 | field_index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 1222 | class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 1223 | *dex_file_, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1224 | dex_cache_, |
| 1225 | dex_pc)); |
| 1226 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1227 | } |
| 1228 | return true; |
| 1229 | } |
| 1230 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1231 | void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg, |
| 1232 | uint16_t first_vreg, |
| 1233 | int64_t second_vreg_or_constant, |
| 1234 | uint32_t dex_pc, |
| 1235 | Primitive::Type type, |
| 1236 | bool second_is_constant, |
| 1237 | bool isDiv) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1238 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1239 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1240 | HInstruction* first = LoadLocal(first_vreg, type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1241 | HInstruction* second = nullptr; |
| 1242 | if (second_is_constant) { |
| 1243 | if (type == Primitive::kPrimInt) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1244 | second = graph_->GetIntConstant(second_vreg_or_constant, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1245 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1246 | second = graph_->GetLongConstant(second_vreg_or_constant, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1247 | } |
| 1248 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1249 | second = LoadLocal(second_vreg_or_constant, type, dex_pc); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | if (!second_is_constant |
| 1253 | || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0) |
| 1254 | || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) { |
| 1255 | second = new (arena_) HDivZeroCheck(second, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1256 | current_block_->AddInstruction(second); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1259 | if (isDiv) { |
| 1260 | current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc)); |
| 1261 | } else { |
| 1262 | current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc)); |
| 1263 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1264 | UpdateLocal(out_vreg, current_block_->GetLastInstruction(), dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1267 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1268 | uint32_t dex_pc, |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1269 | bool is_put, |
| 1270 | Primitive::Type anticipated_type) { |
| 1271 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 1272 | uint8_t array_reg = instruction.VRegB_23x(); |
| 1273 | uint8_t index_reg = instruction.VRegC_23x(); |
| 1274 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1275 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1276 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1277 | current_block_->AddInstruction(object); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1278 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1279 | HInstruction* length = new (arena_) HArrayLength(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1280 | current_block_->AddInstruction(length); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1281 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1282 | index = new (arena_) HBoundsCheck(index, length, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1283 | current_block_->AddInstruction(index); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1284 | if (is_put) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1285 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1286 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1287 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1288 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1289 | } else { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1290 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type, dex_pc)); |
| 1291 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1292 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1293 | graph_->SetHasBoundsChecks(true); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1294 | } |
| 1295 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1296 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1297 | uint32_t type_index, |
| 1298 | uint32_t number_of_vreg_arguments, |
| 1299 | bool is_range, |
| 1300 | uint32_t* args, |
| 1301 | uint32_t register_index) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1302 | HInstruction* length = graph_->GetIntConstant(number_of_vreg_arguments, dex_pc); |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 1303 | bool finalizable; |
| 1304 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index, &finalizable) |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1305 | ? kQuickAllocArrayWithAccessCheck |
| 1306 | : kQuickAllocArray; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 1307 | HInstruction* object = new (arena_) HNewArray(length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 1308 | graph_->GetCurrentMethod(), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 1309 | dex_pc, |
| 1310 | type_index, |
| 1311 | *dex_compilation_unit_->GetDexFile(), |
| 1312 | entrypoint); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1313 | current_block_->AddInstruction(object); |
| 1314 | |
| 1315 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 1316 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 1317 | char primitive = descriptor[1]; |
| 1318 | DCHECK(primitive == 'I' |
| 1319 | || primitive == 'L' |
| 1320 | || primitive == '[') << descriptor; |
| 1321 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 1322 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 1323 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1324 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1325 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type, dex_pc); |
| 1326 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1327 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1328 | new (arena_) HArraySet(object, index, value, type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1329 | } |
| 1330 | latest_result_ = object; |
| 1331 | } |
| 1332 | |
| 1333 | template <typename T> |
| 1334 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 1335 | const T* data, |
| 1336 | uint32_t element_count, |
| 1337 | Primitive::Type anticipated_type, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1338 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1339 | for (uint32_t i = 0; i < element_count; ++i) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1340 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
| 1341 | HInstruction* value = graph_->GetIntConstant(data[i], dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1342 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1343 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1344 | } |
| 1345 | } |
| 1346 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1347 | void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1348 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1349 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1350 | current_block_->AddInstruction(null_check); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1351 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1352 | HInstruction* length = new (arena_) HArrayLength(null_check, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1353 | current_block_->AddInstruction(length); |
| 1354 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1355 | int32_t payload_offset = instruction.VRegB_31t() + dex_pc; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1356 | const Instruction::ArrayDataPayload* payload = |
| 1357 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 1358 | const uint8_t* data = payload->data; |
| 1359 | uint32_t element_count = payload->element_count; |
| 1360 | |
| 1361 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 1362 | // done before doing any stores. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1363 | HInstruction* last_index = graph_->GetIntConstant(payload->element_count - 1, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1364 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc)); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1365 | |
| 1366 | switch (payload->element_width) { |
| 1367 | case 1: |
| 1368 | BuildFillArrayData(null_check, |
| 1369 | reinterpret_cast<const int8_t*>(data), |
| 1370 | element_count, |
| 1371 | Primitive::kPrimByte, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1372 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1373 | break; |
| 1374 | case 2: |
| 1375 | BuildFillArrayData(null_check, |
| 1376 | reinterpret_cast<const int16_t*>(data), |
| 1377 | element_count, |
| 1378 | Primitive::kPrimShort, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1379 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1380 | break; |
| 1381 | case 4: |
| 1382 | BuildFillArrayData(null_check, |
| 1383 | reinterpret_cast<const int32_t*>(data), |
| 1384 | element_count, |
| 1385 | Primitive::kPrimInt, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1386 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1387 | break; |
| 1388 | case 8: |
| 1389 | BuildFillWideArrayData(null_check, |
| 1390 | reinterpret_cast<const int64_t*>(data), |
| 1391 | element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1392 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1393 | break; |
| 1394 | default: |
| 1395 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 1396 | } |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 1397 | graph_->SetHasBoundsChecks(true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1400 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 1401 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1402 | uint32_t element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1403 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1404 | for (uint32_t i = 0; i < element_count; ++i) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1405 | HInstruction* index = graph_->GetIntConstant(i, dex_pc); |
| 1406 | HInstruction* value = graph_->GetLongConstant(data[i], dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1407 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1408 | object, index, value, Primitive::kPrimLong, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1409 | } |
| 1410 | } |
| 1411 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1412 | static TypeCheckKind ComputeTypeCheckKind(Handle<mirror::Class> cls) |
| 1413 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1414 | if (cls.Get() == nullptr) { |
| 1415 | return TypeCheckKind::kUnresolvedCheck; |
| 1416 | } else if (cls->IsInterface()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1417 | return TypeCheckKind::kInterfaceCheck; |
| 1418 | } else if (cls->IsArrayClass()) { |
| 1419 | if (cls->GetComponentType()->IsObjectClass()) { |
| 1420 | return TypeCheckKind::kArrayObjectCheck; |
| 1421 | } else if (cls->CannotBeAssignedFromOtherTypes()) { |
| 1422 | return TypeCheckKind::kExactCheck; |
| 1423 | } else { |
| 1424 | return TypeCheckKind::kArrayCheck; |
| 1425 | } |
| 1426 | } else if (cls->IsFinal()) { |
| 1427 | return TypeCheckKind::kExactCheck; |
| 1428 | } else if (cls->IsAbstract()) { |
| 1429 | return TypeCheckKind::kAbstractClassCheck; |
| 1430 | } else { |
| 1431 | return TypeCheckKind::kClassHierarchyCheck; |
| 1432 | } |
| 1433 | } |
| 1434 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1435 | void HGraphBuilder::BuildTypeCheck(const Instruction& instruction, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1436 | uint8_t destination, |
| 1437 | uint8_t reference, |
| 1438 | uint16_t type_index, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1439 | uint32_t dex_pc) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1440 | bool type_known_final, type_known_abstract, use_declaring_class; |
| 1441 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1442 | dex_compilation_unit_->GetDexMethodIndex(), |
| 1443 | *dex_compilation_unit_->GetDexFile(), |
| 1444 | type_index, |
| 1445 | &type_known_final, |
| 1446 | &type_known_abstract, |
| 1447 | &use_declaring_class); |
| 1448 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1449 | ScopedObjectAccess soa(Thread::Current()); |
| 1450 | StackHandleScope<2> hs(soa.Self()); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1451 | const DexFile& dex_file = *dex_compilation_unit_->GetDexFile(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1452 | Handle<mirror::DexCache> dex_cache(hs.NewHandle( |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1453 | dex_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), dex_file))); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1454 | Handle<mirror::Class> resolved_class(hs.NewHandle(dex_cache->GetResolvedType(type_index))); |
| 1455 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1456 | HInstruction* object = LoadLocal(reference, Primitive::kPrimNot, dex_pc); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1457 | HLoadClass* cls = new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1458 | graph_->GetCurrentMethod(), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 1459 | type_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1460 | dex_file, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 1461 | IsOutermostCompilingClass(type_index), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 1462 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 1463 | !can_access, |
| 1464 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(dex_file, type_index)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1465 | current_block_->AddInstruction(cls); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1466 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1467 | TypeCheckKind check_kind = ComputeTypeCheckKind(resolved_class); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1468 | if (instruction.Opcode() == Instruction::INSTANCE_OF) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1469 | current_block_->AddInstruction(new (arena_) HInstanceOf(object, cls, check_kind, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1470 | UpdateLocal(destination, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1471 | } else { |
| 1472 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 1473 | // We emit a CheckCast followed by a BoundType. CheckCast is a statement |
| 1474 | // which may throw. If it succeeds BoundType sets the new type of `object` |
| 1475 | // for all subsequent uses. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 1476 | current_block_->AddInstruction(new (arena_) HCheckCast(object, cls, check_kind, dex_pc)); |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 1477 | current_block_->AddInstruction(new (arena_) HBoundType(object, dex_pc)); |
| 1478 | UpdateLocal(reference, current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1479 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 1482 | bool HGraphBuilder::NeedsAccessCheck(uint32_t type_index, bool* finalizable) const { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1483 | return !compiler_driver_->CanAccessInstantiableTypeWithoutChecks( |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 1484 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, finalizable); |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1487 | bool HGraphBuilder::CanDecodeQuickenedInfo() const { |
| 1488 | return interpreter_metadata_ != nullptr; |
| 1489 | } |
| 1490 | |
| 1491 | uint16_t HGraphBuilder::LookupQuickenedInfo(uint32_t dex_pc) { |
| 1492 | DCHECK(interpreter_metadata_ != nullptr); |
| 1493 | uint32_t dex_pc_in_map = DecodeUnsignedLeb128(&interpreter_metadata_); |
| 1494 | DCHECK_EQ(dex_pc, dex_pc_in_map); |
| 1495 | return DecodeUnsignedLeb128(&interpreter_metadata_); |
| 1496 | } |
| 1497 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1498 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1499 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1500 | case Instruction::CONST_4: { |
| 1501 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1502 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n(), dex_pc); |
| 1503 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1504 | break; |
| 1505 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1506 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1507 | case Instruction::CONST_16: { |
| 1508 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1509 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21s(), dex_pc); |
| 1510 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1511 | break; |
| 1512 | } |
| 1513 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1514 | case Instruction::CONST: { |
| 1515 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1516 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_31i(), dex_pc); |
| 1517 | UpdateLocal(register_index, constant, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1518 | break; |
| 1519 | } |
| 1520 | |
| 1521 | case Instruction::CONST_HIGH16: { |
| 1522 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1523 | HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21h() << 16, dex_pc); |
| 1524 | UpdateLocal(register_index, constant, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1525 | break; |
| 1526 | } |
| 1527 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1528 | case Instruction::CONST_WIDE_16: { |
| 1529 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1530 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 1531 | int64_t value = instruction.VRegB_21s(); |
| 1532 | value <<= 48; |
| 1533 | value >>= 48; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1534 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 1535 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1536 | break; |
| 1537 | } |
| 1538 | |
| 1539 | case Instruction::CONST_WIDE_32: { |
| 1540 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1541 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 1542 | int64_t value = instruction.VRegB_31i(); |
| 1543 | value <<= 32; |
| 1544 | value >>= 32; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1545 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 1546 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1547 | break; |
| 1548 | } |
| 1549 | |
| 1550 | case Instruction::CONST_WIDE: { |
| 1551 | int32_t register_index = instruction.VRegA(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1552 | HLongConstant* constant = graph_->GetLongConstant(instruction.VRegB_51l(), dex_pc); |
| 1553 | UpdateLocal(register_index, constant, dex_pc); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1554 | break; |
| 1555 | } |
| 1556 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1557 | case Instruction::CONST_WIDE_HIGH16: { |
| 1558 | int32_t register_index = instruction.VRegA(); |
| 1559 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1560 | HLongConstant* constant = graph_->GetLongConstant(value, dex_pc); |
| 1561 | UpdateLocal(register_index, constant, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1562 | break; |
| 1563 | } |
| 1564 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1565 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1566 | case Instruction::MOVE: |
| 1567 | case Instruction::MOVE_FROM16: |
| 1568 | case Instruction::MOVE_16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1569 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc); |
| 1570 | UpdateLocal(instruction.VRegA(), value, dex_pc); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1571 | break; |
| 1572 | } |
| 1573 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1574 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1575 | case Instruction::MOVE_WIDE: |
| 1576 | case Instruction::MOVE_WIDE_FROM16: |
| 1577 | case Instruction::MOVE_WIDE_16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1578 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong, dex_pc); |
| 1579 | UpdateLocal(instruction.VRegA(), value, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1580 | break; |
| 1581 | } |
| 1582 | |
| 1583 | case Instruction::MOVE_OBJECT: |
| 1584 | case Instruction::MOVE_OBJECT_16: |
| 1585 | case Instruction::MOVE_OBJECT_FROM16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1586 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot, dex_pc); |
| 1587 | UpdateLocal(instruction.VRegA(), value, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1588 | break; |
| 1589 | } |
| 1590 | |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1591 | case Instruction::RETURN_VOID_NO_BARRIER: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1592 | case Instruction::RETURN_VOID: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1593 | BuildReturn(instruction, Primitive::kPrimVoid, dex_pc); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1594 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1597 | #define IF_XX(comparison, cond) \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1598 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \ |
| 1599 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1600 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1601 | IF_XX(HEqual, EQ); |
| 1602 | IF_XX(HNotEqual, NE); |
| 1603 | IF_XX(HLessThan, LT); |
| 1604 | IF_XX(HLessThanOrEqual, LE); |
| 1605 | IF_XX(HGreaterThan, GT); |
| 1606 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1607 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1608 | case Instruction::GOTO: |
| 1609 | case Instruction::GOTO_16: |
| 1610 | case Instruction::GOTO_32: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1611 | current_block_->AddInstruction(new (arena_) HGoto(dex_pc)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1612 | current_block_ = nullptr; |
| 1613 | break; |
| 1614 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1615 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1616 | case Instruction::RETURN: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1617 | BuildReturn(instruction, return_type_, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1618 | break; |
| 1619 | } |
| 1620 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1621 | case Instruction::RETURN_OBJECT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1622 | BuildReturn(instruction, return_type_, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1623 | break; |
| 1624 | } |
| 1625 | |
| 1626 | case Instruction::RETURN_WIDE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1627 | BuildReturn(instruction, return_type_, dex_pc); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1628 | break; |
| 1629 | } |
| 1630 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1631 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1632 | case Instruction::INVOKE_INTERFACE: |
| 1633 | case Instruction::INVOKE_STATIC: |
| 1634 | case Instruction::INVOKE_SUPER: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1635 | case Instruction::INVOKE_VIRTUAL: |
| 1636 | case Instruction::INVOKE_VIRTUAL_QUICK: { |
| 1637 | uint16_t method_idx; |
| 1638 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_QUICK) { |
| 1639 | if (!CanDecodeQuickenedInfo()) { |
| 1640 | return false; |
| 1641 | } |
| 1642 | method_idx = LookupQuickenedInfo(dex_pc); |
| 1643 | } else { |
| 1644 | method_idx = instruction.VRegB_35c(); |
| 1645 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1646 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1647 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 1648 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1649 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1650 | number_of_vreg_arguments, false, args, -1)) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1651 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1652 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1653 | break; |
| 1654 | } |
| 1655 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1656 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1657 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 1658 | case Instruction::INVOKE_STATIC_RANGE: |
| 1659 | case Instruction::INVOKE_SUPER_RANGE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 1660 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 1661 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: { |
| 1662 | uint16_t method_idx; |
| 1663 | if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK) { |
| 1664 | if (!CanDecodeQuickenedInfo()) { |
| 1665 | return false; |
| 1666 | } |
| 1667 | method_idx = LookupQuickenedInfo(dex_pc); |
| 1668 | } else { |
| 1669 | method_idx = instruction.VRegB_3rc(); |
| 1670 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1671 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1672 | uint32_t register_index = instruction.VRegC(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1673 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1674 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1675 | return false; |
| 1676 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1677 | break; |
| 1678 | } |
| 1679 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1680 | case Instruction::NEG_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1681 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1682 | break; |
| 1683 | } |
| 1684 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1685 | case Instruction::NEG_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1686 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1687 | break; |
| 1688 | } |
| 1689 | |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1690 | case Instruction::NEG_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1691 | Unop_12x<HNeg>(instruction, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1692 | break; |
| 1693 | } |
| 1694 | |
| 1695 | case Instruction::NEG_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1696 | Unop_12x<HNeg>(instruction, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1697 | break; |
| 1698 | } |
| 1699 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1700 | case Instruction::NOT_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1701 | Unop_12x<HNot>(instruction, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1702 | break; |
| 1703 | } |
| 1704 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1705 | case Instruction::NOT_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1706 | Unop_12x<HNot>(instruction, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1707 | break; |
| 1708 | } |
| 1709 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1710 | case Instruction::INT_TO_LONG: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1711 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong, dex_pc); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1712 | break; |
| 1713 | } |
| 1714 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1715 | case Instruction::INT_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1716 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1717 | break; |
| 1718 | } |
| 1719 | |
| 1720 | case Instruction::INT_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1721 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1722 | break; |
| 1723 | } |
| 1724 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1725 | case Instruction::LONG_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1726 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1727 | break; |
| 1728 | } |
| 1729 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1730 | case Instruction::LONG_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1731 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1732 | break; |
| 1733 | } |
| 1734 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1735 | case Instruction::LONG_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1736 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1737 | break; |
| 1738 | } |
| 1739 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1740 | case Instruction::FLOAT_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1741 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimInt, dex_pc); |
| 1742 | break; |
| 1743 | } |
| 1744 | |
| 1745 | case Instruction::FLOAT_TO_LONG: { |
| 1746 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1747 | break; |
| 1748 | } |
| 1749 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1750 | case Instruction::FLOAT_TO_DOUBLE: { |
| 1751 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimDouble, dex_pc); |
| 1752 | break; |
| 1753 | } |
| 1754 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1755 | case Instruction::DOUBLE_TO_INT: { |
| 1756 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimInt, dex_pc); |
| 1757 | break; |
| 1758 | } |
| 1759 | |
| 1760 | case Instruction::DOUBLE_TO_LONG: { |
| 1761 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimLong, dex_pc); |
| 1762 | break; |
| 1763 | } |
| 1764 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1765 | case Instruction::DOUBLE_TO_FLOAT: { |
| 1766 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimFloat, dex_pc); |
| 1767 | break; |
| 1768 | } |
| 1769 | |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1770 | case Instruction::INT_TO_BYTE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1771 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte, dex_pc); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1772 | break; |
| 1773 | } |
| 1774 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1775 | case Instruction::INT_TO_SHORT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1776 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort, dex_pc); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1777 | break; |
| 1778 | } |
| 1779 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1780 | case Instruction::INT_TO_CHAR: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1781 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar, dex_pc); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1782 | break; |
| 1783 | } |
| 1784 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1785 | case Instruction::ADD_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1786 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1787 | break; |
| 1788 | } |
| 1789 | |
| 1790 | case Instruction::ADD_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1791 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1792 | break; |
| 1793 | } |
| 1794 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1795 | case Instruction::ADD_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1796 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1797 | break; |
| 1798 | } |
| 1799 | |
| 1800 | case Instruction::ADD_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1801 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1802 | break; |
| 1803 | } |
| 1804 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1805 | case Instruction::SUB_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1806 | Binop_23x<HSub>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1807 | break; |
| 1808 | } |
| 1809 | |
| 1810 | case Instruction::SUB_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1811 | Binop_23x<HSub>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1812 | break; |
| 1813 | } |
| 1814 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1815 | case Instruction::SUB_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1816 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1817 | break; |
| 1818 | } |
| 1819 | |
| 1820 | case Instruction::SUB_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1821 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1822 | break; |
| 1823 | } |
| 1824 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1825 | case Instruction::ADD_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1826 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1827 | break; |
| 1828 | } |
| 1829 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1830 | case Instruction::MUL_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1831 | Binop_23x<HMul>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1832 | break; |
| 1833 | } |
| 1834 | |
| 1835 | case Instruction::MUL_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1836 | Binop_23x<HMul>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1837 | break; |
| 1838 | } |
| 1839 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1840 | case Instruction::MUL_FLOAT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1841 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1842 | break; |
| 1843 | } |
| 1844 | |
| 1845 | case Instruction::MUL_DOUBLE: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1846 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1847 | break; |
| 1848 | } |
| 1849 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1850 | case Instruction::DIV_INT: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1851 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1852 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1853 | break; |
| 1854 | } |
| 1855 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1856 | case Instruction::DIV_LONG: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1857 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1858 | dex_pc, Primitive::kPrimLong, false, true); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1859 | break; |
| 1860 | } |
| 1861 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1862 | case Instruction::DIV_FLOAT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1863 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1864 | break; |
| 1865 | } |
| 1866 | |
| 1867 | case Instruction::DIV_DOUBLE: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1868 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1869 | break; |
| 1870 | } |
| 1871 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1872 | case Instruction::REM_INT: { |
| 1873 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1874 | dex_pc, Primitive::kPrimInt, false, false); |
| 1875 | break; |
| 1876 | } |
| 1877 | |
| 1878 | case Instruction::REM_LONG: { |
| 1879 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1880 | dex_pc, Primitive::kPrimLong, false, false); |
| 1881 | break; |
| 1882 | } |
| 1883 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 1884 | case Instruction::REM_FLOAT: { |
| 1885 | Binop_23x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 1886 | break; |
| 1887 | } |
| 1888 | |
| 1889 | case Instruction::REM_DOUBLE: { |
| 1890 | Binop_23x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 1891 | break; |
| 1892 | } |
| 1893 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1894 | case Instruction::AND_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1895 | Binop_23x<HAnd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1896 | break; |
| 1897 | } |
| 1898 | |
| 1899 | case Instruction::AND_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1900 | Binop_23x<HAnd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1901 | break; |
| 1902 | } |
| 1903 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1904 | case Instruction::SHL_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1905 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1906 | break; |
| 1907 | } |
| 1908 | |
| 1909 | case Instruction::SHL_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1910 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1911 | break; |
| 1912 | } |
| 1913 | |
| 1914 | case Instruction::SHR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1915 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1916 | break; |
| 1917 | } |
| 1918 | |
| 1919 | case Instruction::SHR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1920 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1921 | break; |
| 1922 | } |
| 1923 | |
| 1924 | case Instruction::USHR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1925 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1926 | break; |
| 1927 | } |
| 1928 | |
| 1929 | case Instruction::USHR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1930 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1931 | break; |
| 1932 | } |
| 1933 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1934 | case Instruction::OR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1935 | Binop_23x<HOr>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1936 | break; |
| 1937 | } |
| 1938 | |
| 1939 | case Instruction::OR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1940 | Binop_23x<HOr>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1941 | break; |
| 1942 | } |
| 1943 | |
| 1944 | case Instruction::XOR_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1945 | Binop_23x<HXor>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1946 | break; |
| 1947 | } |
| 1948 | |
| 1949 | case Instruction::XOR_LONG: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1950 | Binop_23x<HXor>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1951 | break; |
| 1952 | } |
| 1953 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1954 | case Instruction::ADD_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1955 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1956 | break; |
| 1957 | } |
| 1958 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1959 | case Instruction::ADD_DOUBLE_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1960 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1961 | break; |
| 1962 | } |
| 1963 | |
| 1964 | case Instruction::ADD_FLOAT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1965 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat, dex_pc); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1966 | break; |
| 1967 | } |
| 1968 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1969 | case Instruction::SUB_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1970 | Binop_12x<HSub>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1971 | break; |
| 1972 | } |
| 1973 | |
| 1974 | case Instruction::SUB_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1975 | Binop_12x<HSub>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1976 | break; |
| 1977 | } |
| 1978 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1979 | case Instruction::SUB_FLOAT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1980 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1981 | break; |
| 1982 | } |
| 1983 | |
| 1984 | case Instruction::SUB_DOUBLE_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1985 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1986 | break; |
| 1987 | } |
| 1988 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1989 | case Instruction::MUL_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1990 | Binop_12x<HMul>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1991 | break; |
| 1992 | } |
| 1993 | |
| 1994 | case Instruction::MUL_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1995 | Binop_12x<HMul>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1996 | break; |
| 1997 | } |
| 1998 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1999 | case Instruction::MUL_FLOAT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2000 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2001 | break; |
| 2002 | } |
| 2003 | |
| 2004 | case Instruction::MUL_DOUBLE_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2005 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2006 | break; |
| 2007 | } |
| 2008 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 2009 | case Instruction::DIV_INT_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2010 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2011 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 2012 | break; |
| 2013 | } |
| 2014 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2015 | case Instruction::DIV_LONG_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2016 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2017 | dex_pc, Primitive::kPrimLong, false, true); |
| 2018 | break; |
| 2019 | } |
| 2020 | |
| 2021 | case Instruction::REM_INT_2ADDR: { |
| 2022 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2023 | dex_pc, Primitive::kPrimInt, false, false); |
| 2024 | break; |
| 2025 | } |
| 2026 | |
| 2027 | case Instruction::REM_LONG_2ADDR: { |
| 2028 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 2029 | dex_pc, Primitive::kPrimLong, false, false); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2030 | break; |
| 2031 | } |
| 2032 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2033 | case Instruction::REM_FLOAT_2ADDR: { |
| 2034 | Binop_12x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 2035 | break; |
| 2036 | } |
| 2037 | |
| 2038 | case Instruction::REM_DOUBLE_2ADDR: { |
| 2039 | Binop_12x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 2040 | break; |
| 2041 | } |
| 2042 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2043 | case Instruction::SHL_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2044 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2045 | break; |
| 2046 | } |
| 2047 | |
| 2048 | case Instruction::SHL_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2049 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2050 | break; |
| 2051 | } |
| 2052 | |
| 2053 | case Instruction::SHR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2054 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2055 | break; |
| 2056 | } |
| 2057 | |
| 2058 | case Instruction::SHR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2059 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2060 | break; |
| 2061 | } |
| 2062 | |
| 2063 | case Instruction::USHR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2064 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimInt, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2065 | break; |
| 2066 | } |
| 2067 | |
| 2068 | case Instruction::USHR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2069 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimLong, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2070 | break; |
| 2071 | } |
| 2072 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2073 | case Instruction::DIV_FLOAT_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2074 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2075 | break; |
| 2076 | } |
| 2077 | |
| 2078 | case Instruction::DIV_DOUBLE_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2079 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2080 | break; |
| 2081 | } |
| 2082 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2083 | case Instruction::AND_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2084 | Binop_12x<HAnd>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2085 | break; |
| 2086 | } |
| 2087 | |
| 2088 | case Instruction::AND_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2089 | Binop_12x<HAnd>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2090 | break; |
| 2091 | } |
| 2092 | |
| 2093 | case Instruction::OR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2094 | Binop_12x<HOr>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2095 | break; |
| 2096 | } |
| 2097 | |
| 2098 | case Instruction::OR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2099 | Binop_12x<HOr>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2100 | break; |
| 2101 | } |
| 2102 | |
| 2103 | case Instruction::XOR_INT_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2104 | Binop_12x<HXor>(instruction, Primitive::kPrimInt, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2105 | break; |
| 2106 | } |
| 2107 | |
| 2108 | case Instruction::XOR_LONG_2ADDR: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2109 | Binop_12x<HXor>(instruction, Primitive::kPrimLong, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2110 | break; |
| 2111 | } |
| 2112 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2113 | case Instruction::ADD_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2114 | Binop_22s<HAdd>(instruction, false, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2115 | break; |
| 2116 | } |
| 2117 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2118 | case Instruction::AND_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2119 | Binop_22s<HAnd>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2120 | break; |
| 2121 | } |
| 2122 | |
| 2123 | case Instruction::OR_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2124 | Binop_22s<HOr>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2125 | break; |
| 2126 | } |
| 2127 | |
| 2128 | case Instruction::XOR_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2129 | Binop_22s<HXor>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2130 | break; |
| 2131 | } |
| 2132 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2133 | case Instruction::RSUB_INT: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2134 | Binop_22s<HSub>(instruction, true, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2135 | break; |
| 2136 | } |
| 2137 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2138 | case Instruction::MUL_INT_LIT16: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2139 | Binop_22s<HMul>(instruction, false, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2140 | break; |
| 2141 | } |
| 2142 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2143 | case Instruction::ADD_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2144 | Binop_22b<HAdd>(instruction, false, dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2145 | break; |
| 2146 | } |
| 2147 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2148 | case Instruction::AND_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2149 | Binop_22b<HAnd>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2150 | break; |
| 2151 | } |
| 2152 | |
| 2153 | case Instruction::OR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2154 | Binop_22b<HOr>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2155 | break; |
| 2156 | } |
| 2157 | |
| 2158 | case Instruction::XOR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2159 | Binop_22b<HXor>(instruction, false, dex_pc); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2160 | break; |
| 2161 | } |
| 2162 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2163 | case Instruction::RSUB_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2164 | Binop_22b<HSub>(instruction, true, dex_pc); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2165 | break; |
| 2166 | } |
| 2167 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2168 | case Instruction::MUL_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2169 | Binop_22b<HMul>(instruction, false, dex_pc); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2170 | break; |
| 2171 | } |
| 2172 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2173 | case Instruction::DIV_INT_LIT16: |
| 2174 | case Instruction::DIV_INT_LIT8: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2175 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2176 | dex_pc, Primitive::kPrimInt, true, true); |
| 2177 | break; |
| 2178 | } |
| 2179 | |
| 2180 | case Instruction::REM_INT_LIT16: |
| 2181 | case Instruction::REM_INT_LIT8: { |
| 2182 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 2183 | dex_pc, Primitive::kPrimInt, true, false); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2184 | break; |
| 2185 | } |
| 2186 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2187 | case Instruction::SHL_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2188 | Binop_22b<HShl>(instruction, false, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2189 | break; |
| 2190 | } |
| 2191 | |
| 2192 | case Instruction::SHR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2193 | Binop_22b<HShr>(instruction, false, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2194 | break; |
| 2195 | } |
| 2196 | |
| 2197 | case Instruction::USHR_INT_LIT8: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2198 | Binop_22b<HUShr>(instruction, false, dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2199 | break; |
| 2200 | } |
| 2201 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2202 | case Instruction::NEW_INSTANCE: { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 2203 | if (!BuildNewInstance(instruction.VRegB_21c(), dex_pc)) { |
| 2204 | return false; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2205 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 2206 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2207 | break; |
| 2208 | } |
| 2209 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2210 | case Instruction::NEW_ARRAY: { |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2211 | uint16_t type_index = instruction.VRegC_22c(); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2212 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt, dex_pc); |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 2213 | bool finalizable; |
| 2214 | QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index, &finalizable) |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2215 | ? kQuickAllocArrayWithAccessCheck |
| 2216 | : kQuickAllocArray; |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 2217 | current_block_->AddInstruction(new (arena_) HNewArray(length, |
| 2218 | graph_->GetCurrentMethod(), |
| 2219 | dex_pc, |
| 2220 | type_index, |
| 2221 | *dex_compilation_unit_->GetDexFile(), |
| 2222 | entrypoint)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2223 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2224 | break; |
| 2225 | } |
| 2226 | |
| 2227 | case Instruction::FILLED_NEW_ARRAY: { |
| 2228 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 2229 | uint32_t type_index = instruction.VRegB_35c(); |
| 2230 | uint32_t args[5]; |
| 2231 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2232 | BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2233 | break; |
| 2234 | } |
| 2235 | |
| 2236 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 2237 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 2238 | uint32_t type_index = instruction.VRegB_3rc(); |
| 2239 | uint32_t register_index = instruction.VRegC_3rc(); |
| 2240 | BuildFilledNewArray( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2241 | dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2242 | break; |
| 2243 | } |
| 2244 | |
| 2245 | case Instruction::FILL_ARRAY_DATA: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2246 | BuildFillArrayData(instruction, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2247 | break; |
| 2248 | } |
| 2249 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2250 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2251 | case Instruction::MOVE_RESULT_WIDE: |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2252 | case Instruction::MOVE_RESULT_OBJECT: { |
Nicolas Geoffray | 1efcc22 | 2015-06-24 12:41:20 +0100 | [diff] [blame] | 2253 | if (latest_result_ == nullptr) { |
| 2254 | // Only dead code can lead to this situation, where the verifier |
| 2255 | // does not reject the method. |
| 2256 | } else { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2257 | // An Invoke/FilledNewArray and its MoveResult could have landed in |
| 2258 | // different blocks if there was a try/catch block boundary between |
| 2259 | // them. For Invoke, we insert a StoreLocal after the instruction. For |
| 2260 | // FilledNewArray, the local needs to be updated after the array was |
| 2261 | // filled, otherwise we might overwrite an input vreg. |
| 2262 | HStoreLocal* update_local = |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2263 | new (arena_) HStoreLocal(GetLocalAt(instruction.VRegA()), latest_result_, dex_pc); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2264 | HBasicBlock* block = latest_result_->GetBlock(); |
| 2265 | if (block == current_block_) { |
| 2266 | // MoveResult and the previous instruction are in the same block. |
| 2267 | current_block_->AddInstruction(update_local); |
| 2268 | } else { |
| 2269 | // The two instructions are in different blocks. Insert the MoveResult |
| 2270 | // before the final control-flow instruction of the previous block. |
| 2271 | DCHECK(block->EndsWithControlFlowInstruction()); |
| 2272 | DCHECK(current_block_->GetInstructions().IsEmpty()); |
| 2273 | block->InsertInstructionBefore(update_local, block->GetLastInstruction()); |
| 2274 | } |
Nicolas Geoffray | 1efcc22 | 2015-06-24 12:41:20 +0100 | [diff] [blame] | 2275 | latest_result_ = nullptr; |
| 2276 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2277 | break; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2278 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2279 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2280 | case Instruction::CMP_LONG: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2281 | Binop_23x_cmp(instruction, Primitive::kPrimLong, ComparisonBias::kNoBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2282 | break; |
| 2283 | } |
| 2284 | |
| 2285 | case Instruction::CMPG_FLOAT: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2286 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kGtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2287 | break; |
| 2288 | } |
| 2289 | |
| 2290 | case Instruction::CMPG_DOUBLE: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2291 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kGtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2292 | break; |
| 2293 | } |
| 2294 | |
| 2295 | case Instruction::CMPL_FLOAT: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2296 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kLtBias, dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2297 | break; |
| 2298 | } |
| 2299 | |
| 2300 | case Instruction::CMPL_DOUBLE: { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2301 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kLtBias, dex_pc); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2302 | break; |
| 2303 | } |
| 2304 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2305 | case Instruction::NOP: |
| 2306 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2307 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2308 | case Instruction::IGET: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2309 | case Instruction::IGET_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2310 | case Instruction::IGET_WIDE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2311 | case Instruction::IGET_WIDE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2312 | case Instruction::IGET_OBJECT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2313 | case Instruction::IGET_OBJECT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2314 | case Instruction::IGET_BOOLEAN: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2315 | case Instruction::IGET_BOOLEAN_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2316 | case Instruction::IGET_BYTE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2317 | case Instruction::IGET_BYTE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2318 | case Instruction::IGET_CHAR: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2319 | case Instruction::IGET_CHAR_QUICK: |
| 2320 | case Instruction::IGET_SHORT: |
| 2321 | case Instruction::IGET_SHORT_QUICK: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2322 | if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2323 | return false; |
| 2324 | } |
| 2325 | break; |
| 2326 | } |
| 2327 | |
| 2328 | case Instruction::IPUT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2329 | case Instruction::IPUT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2330 | case Instruction::IPUT_WIDE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2331 | case Instruction::IPUT_WIDE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2332 | case Instruction::IPUT_OBJECT: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2333 | case Instruction::IPUT_OBJECT_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2334 | case Instruction::IPUT_BOOLEAN: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2335 | case Instruction::IPUT_BOOLEAN_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2336 | case Instruction::IPUT_BYTE: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2337 | case Instruction::IPUT_BYTE_QUICK: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2338 | case Instruction::IPUT_CHAR: |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 2339 | case Instruction::IPUT_CHAR_QUICK: |
| 2340 | case Instruction::IPUT_SHORT: |
| 2341 | case Instruction::IPUT_SHORT_QUICK: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2342 | if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2343 | return false; |
| 2344 | } |
| 2345 | break; |
| 2346 | } |
| 2347 | |
| 2348 | case Instruction::SGET: |
| 2349 | case Instruction::SGET_WIDE: |
| 2350 | case Instruction::SGET_OBJECT: |
| 2351 | case Instruction::SGET_BOOLEAN: |
| 2352 | case Instruction::SGET_BYTE: |
| 2353 | case Instruction::SGET_CHAR: |
| 2354 | case Instruction::SGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2355 | if (!BuildStaticFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2356 | return false; |
| 2357 | } |
| 2358 | break; |
| 2359 | } |
| 2360 | |
| 2361 | case Instruction::SPUT: |
| 2362 | case Instruction::SPUT_WIDE: |
| 2363 | case Instruction::SPUT_OBJECT: |
| 2364 | case Instruction::SPUT_BOOLEAN: |
| 2365 | case Instruction::SPUT_BYTE: |
| 2366 | case Instruction::SPUT_CHAR: |
| 2367 | case Instruction::SPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2368 | if (!BuildStaticFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2369 | return false; |
| 2370 | } |
| 2371 | break; |
| 2372 | } |
| 2373 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2374 | #define ARRAY_XX(kind, anticipated_type) \ |
| 2375 | case Instruction::AGET##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2376 | BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2377 | break; \ |
| 2378 | } \ |
| 2379 | case Instruction::APUT##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2380 | BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2381 | break; \ |
| 2382 | } |
| 2383 | |
| 2384 | ARRAY_XX(, Primitive::kPrimInt); |
| 2385 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 2386 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 2387 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 2388 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 2389 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 2390 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 2391 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2392 | case Instruction::ARRAY_LENGTH: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2393 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2394 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2395 | current_block_->AddInstruction(object); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2396 | current_block_->AddInstruction(new (arena_) HArrayLength(object, dex_pc)); |
| 2397 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2398 | break; |
| 2399 | } |
| 2400 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2401 | case Instruction::CONST_STRING: { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 2402 | uint32_t string_index = instruction.VRegB_21c(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 2403 | current_block_->AddInstruction( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2404 | new (arena_) HLoadString(graph_->GetCurrentMethod(), string_index, *dex_file_, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2405 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2406 | break; |
| 2407 | } |
| 2408 | |
| 2409 | case Instruction::CONST_STRING_JUMBO: { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 2410 | uint32_t string_index = instruction.VRegB_31c(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 2411 | current_block_->AddInstruction( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2412 | new (arena_) HLoadString(graph_->GetCurrentMethod(), string_index, *dex_file_, dex_pc)); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2413 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2414 | break; |
| 2415 | } |
| 2416 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2417 | case Instruction::CONST_CLASS: { |
| 2418 | uint16_t type_index = instruction.VRegB_21c(); |
| 2419 | bool type_known_final; |
| 2420 | bool type_known_abstract; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2421 | bool dont_use_is_referrers_class; |
| 2422 | // `CanAccessTypeWithoutChecks` will tell whether the method being |
| 2423 | // built is trying to access its own class, so that the generated |
| 2424 | // code can optimize for this case. However, the optimization does not |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2425 | // work for inlining, so we use `IsOutermostCompilingClass` instead. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2426 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 2427 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2428 | &type_known_final, &type_known_abstract, &dont_use_is_referrers_class); |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2429 | current_block_->AddInstruction(new (arena_) HLoadClass( |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2430 | graph_->GetCurrentMethod(), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2431 | type_index, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 2432 | *dex_file_, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2433 | IsOutermostCompilingClass(type_index), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2434 | dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 2435 | !can_access, |
| 2436 | compiler_driver_->CanAssumeTypeIsPresentInDexCache(*dex_file_, type_index))); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2437 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction(), dex_pc); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2438 | break; |
| 2439 | } |
| 2440 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2441 | case Instruction::MOVE_EXCEPTION: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2442 | current_block_->AddInstruction(new (arena_) HLoadException(dex_pc)); |
| 2443 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction(), dex_pc); |
| 2444 | current_block_->AddInstruction(new (arena_) HClearException(dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2445 | break; |
| 2446 | } |
| 2447 | |
| 2448 | case Instruction::THROW: { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2449 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2450 | current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2451 | // We finished building this block. Set the current block to null to avoid |
| 2452 | // adding dead instructions to it. |
| 2453 | current_block_ = nullptr; |
| 2454 | break; |
| 2455 | } |
| 2456 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2457 | case Instruction::INSTANCE_OF: { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2458 | uint8_t destination = instruction.VRegA_22c(); |
| 2459 | uint8_t reference = instruction.VRegB_22c(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2460 | uint16_t type_index = instruction.VRegC_22c(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2461 | BuildTypeCheck(instruction, destination, reference, type_index, dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2462 | break; |
| 2463 | } |
| 2464 | |
| 2465 | case Instruction::CHECK_CAST: { |
| 2466 | uint8_t reference = instruction.VRegA_21c(); |
| 2467 | uint16_t type_index = instruction.VRegB_21c(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 2468 | BuildTypeCheck(instruction, -1, reference, type_index, dex_pc); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2469 | break; |
| 2470 | } |
| 2471 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2472 | case Instruction::MONITOR_ENTER: { |
| 2473 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2474 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2475 | HMonitorOperation::OperationKind::kEnter, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2476 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2477 | break; |
| 2478 | } |
| 2479 | |
| 2480 | case Instruction::MONITOR_EXIT: { |
| 2481 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2482 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2483 | HMonitorOperation::OperationKind::kExit, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 2484 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2485 | break; |
| 2486 | } |
| 2487 | |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 2488 | case Instruction::SPARSE_SWITCH: |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 2489 | case Instruction::PACKED_SWITCH: { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame^] | 2490 | BuildSwitch(instruction, dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 2491 | break; |
| 2492 | } |
| 2493 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2494 | default: |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 2495 | VLOG(compiler) << "Did not compile " |
| 2496 | << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_) |
| 2497 | << " because of unhandled instruction " |
| 2498 | << instruction.Name(); |
| 2499 | MaybeRecordStat(MethodCompilationStat::kNotCompiledUnhandledInstruction); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2500 | return false; |
| 2501 | } |
| 2502 | return true; |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 2503 | } // NOLINT(readability/fn_size) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2504 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 2505 | HLocal* HGraphBuilder::GetLocalAt(uint32_t register_index) const { |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 2506 | return locals_[register_index]; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2507 | } |
| 2508 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 2509 | void HGraphBuilder::UpdateLocal(uint32_t register_index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2510 | HInstruction* instruction, |
| 2511 | uint32_t dex_pc) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2512 | HLocal* local = GetLocalAt(register_index); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2513 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction, dex_pc)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 2516 | HInstruction* HGraphBuilder::LoadLocal(uint32_t register_index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2517 | Primitive::Type type, |
| 2518 | uint32_t dex_pc) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2519 | HLocal* local = GetLocalAt(register_index); |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2520 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type, dex_pc)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2521 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2524 | } // namespace art |