blob: a94dbe94ff64470f6c19b6db4f56b403ebff6daa [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2011 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
Andreas Gampe5eb0d382015-07-23 01:19:26 -070017#include "dex_to_dex_compiler.h"
18
Andreas Gampe46ee31b2016-12-14 10:11:49 -080019#include "android-base/stringprintf.h"
20
Mathieu Chartierc7853442015-03-27 14:35:38 -070021#include "art_field-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070022#include "art_method-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070023#include "base/logging.h"
24#include "base/mutex.h"
Mathieu Chartierde4b08f2017-07-10 14:13:41 -070025#include "bytecode_utils.h"
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010026#include "compiled_method.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070027#include "dex_file-inl.h"
28#include "dex_instruction-inl.h"
29#include "driver/compiler_driver.h"
30#include "driver/dex_compilation_unit.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070031#include "mirror/dex_cache.h"
Mathieu Chartierde4b08f2017-07-10 14:13:41 -070032#include "quicken_info.h"
Andreas Gampeb486a982017-06-01 13:45:54 -070033#include "thread-current-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070034
35namespace art {
36namespace optimizer {
37
Andreas Gampe46ee31b2016-12-14 10:11:49 -080038using android::base::StringPrintf;
39
Brian Carlstrom7940e442013-07-12 13:46:57 -070040// Controls quickening activation.
41const bool kEnableQuickening = true;
Sebastien Hertz543959c2013-07-03 12:00:19 +020042// Control check-cast elision.
43const bool kEnableCheckCastEllision = true;
Brian Carlstrom7940e442013-07-12 13:46:57 -070044
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010045struct QuickenedInfo {
46 QuickenedInfo(uint32_t pc, uint16_t index) : dex_pc(pc), dex_member_index(index) {}
47
48 uint32_t dex_pc;
49 uint16_t dex_member_index;
50};
51
Brian Carlstrom7940e442013-07-12 13:46:57 -070052class DexCompiler {
53 public:
54 DexCompiler(art::CompilerDriver& compiler,
Sebastien Hertz75021222013-07-16 18:34:50 +020055 const DexCompilationUnit& unit,
56 DexToDexCompilationLevel dex_to_dex_compilation_level)
Brian Carlstrom7940e442013-07-12 13:46:57 -070057 : driver_(compiler),
Sebastien Hertz75021222013-07-16 18:34:50 +020058 unit_(unit),
59 dex_to_dex_compilation_level_(dex_to_dex_compilation_level) {}
Brian Carlstrom7940e442013-07-12 13:46:57 -070060
Brian Carlstrom9b7085a2013-07-18 15:15:21 -070061 ~DexCompiler() {}
Brian Carlstrom7940e442013-07-12 13:46:57 -070062
63 void Compile();
64
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010065 const std::vector<QuickenedInfo>& GetQuickenedInfo() const {
66 return quickened_info_;
67 }
68
Brian Carlstrom7940e442013-07-12 13:46:57 -070069 private:
70 const DexFile& GetDexFile() const {
71 return *unit_.GetDexFile();
72 }
73
Brian Carlstrom7940e442013-07-12 13:46:57 -070074 // Compiles a RETURN-VOID into a RETURN-VOID-BARRIER within a constructor where
75 // a barrier is required.
76 void CompileReturnVoid(Instruction* inst, uint32_t dex_pc);
77
Sebastien Hertz543959c2013-07-03 12:00:19 +020078 // Compiles a CHECK-CAST into 2 NOP instructions if it is known to be safe. In
79 // this case, returns the second NOP instruction pointer. Otherwise, returns
80 // the given "inst".
81 Instruction* CompileCheckCast(Instruction* inst, uint32_t dex_pc);
82
Brian Carlstrom7940e442013-07-12 13:46:57 -070083 // Compiles a field access into a quick field access.
84 // The field index is replaced by an offset within an Object where we can read
85 // from / write to this field. Therefore, this does not involve any resolution
86 // at runtime.
87 // Since the field index is encoded with 16 bits, we can replace it only if the
88 // field offset can be encoded with 16 bits too.
89 void CompileInstanceFieldAccess(Instruction* inst, uint32_t dex_pc,
90 Instruction::Code new_opcode, bool is_put);
91
92 // Compiles a virtual method invocation into a quick virtual method invocation.
93 // The method index is replaced by the vtable index where the corresponding
Neil Fuller0e844392016-09-08 13:43:31 +010094 // Executable can be found. Therefore, this does not involve any resolution
Brian Carlstrom7940e442013-07-12 13:46:57 -070095 // at runtime.
96 // Since the method index is encoded with 16 bits, we can replace it only if the
97 // vtable index can be encoded with 16 bits too.
98 void CompileInvokeVirtual(Instruction* inst, uint32_t dex_pc,
99 Instruction::Code new_opcode, bool is_range);
100
101 CompilerDriver& driver_;
102 const DexCompilationUnit& unit_;
Sebastien Hertz75021222013-07-16 18:34:50 +0200103 const DexToDexCompilationLevel dex_to_dex_compilation_level_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700104
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100105 // Filled by the compiler when quickening, in order to encode that information
106 // in the .oat file. The runtime will use that information to get to the original
107 // opcodes.
108 std::vector<QuickenedInfo> quickened_info_;
109
Brian Carlstrom7940e442013-07-12 13:46:57 -0700110 DISALLOW_COPY_AND_ASSIGN(DexCompiler);
111};
112
Brian Carlstrom7940e442013-07-12 13:46:57 -0700113void DexCompiler::Compile() {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700114 DCHECK_EQ(dex_to_dex_compilation_level_, DexToDexCompilationLevel::kOptimize);
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700115 for (CodeItemIterator it(*unit_.GetCodeItem()); !it.Done(); it.Advance()) {
116 Instruction* inst = const_cast<Instruction*>(&it.CurrentInstruction());
117 const uint32_t dex_pc = it.CurrentDexPc();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700118 switch (inst->Opcode()) {
119 case Instruction::RETURN_VOID:
120 CompileReturnVoid(inst, dex_pc);
121 break;
122
Sebastien Hertz543959c2013-07-03 12:00:19 +0200123 case Instruction::CHECK_CAST:
124 inst = CompileCheckCast(inst, dex_pc);
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700125 if (inst->Opcode() == Instruction::NOP) {
126 // We turned the CHECK_CAST into two NOPs, avoid visiting the second NOP twice since this
127 // would add 2 quickening info entries.
128 it.Advance();
129 }
Sebastien Hertz543959c2013-07-03 12:00:19 +0200130 break;
131
Brian Carlstrom7940e442013-07-12 13:46:57 -0700132 case Instruction::IGET:
133 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_QUICK, false);
134 break;
135
136 case Instruction::IGET_WIDE:
137 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_WIDE_QUICK, false);
138 break;
139
140 case Instruction::IGET_OBJECT:
141 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_OBJECT_QUICK, false);
142 break;
143
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800144 case Instruction::IGET_BOOLEAN:
145 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_BOOLEAN_QUICK, false);
146 break;
147
148 case Instruction::IGET_BYTE:
149 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_BYTE_QUICK, false);
150 break;
151
152 case Instruction::IGET_CHAR:
153 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_CHAR_QUICK, false);
154 break;
155
156 case Instruction::IGET_SHORT:
157 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_SHORT_QUICK, false);
158 break;
159
Brian Carlstrom7940e442013-07-12 13:46:57 -0700160 case Instruction::IPUT:
Brian Carlstrom7940e442013-07-12 13:46:57 -0700161 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_QUICK, true);
162 break;
163
Fred Shih37f05ef2014-07-16 18:38:08 -0700164 case Instruction::IPUT_BOOLEAN:
165 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_BOOLEAN_QUICK, true);
166 break;
167
168 case Instruction::IPUT_BYTE:
169 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_BYTE_QUICK, true);
170 break;
171
172 case Instruction::IPUT_CHAR:
173 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_CHAR_QUICK, true);
174 break;
175
176 case Instruction::IPUT_SHORT:
177 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_SHORT_QUICK, true);
178 break;
179
Brian Carlstrom7940e442013-07-12 13:46:57 -0700180 case Instruction::IPUT_WIDE:
181 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_WIDE_QUICK, true);
182 break;
183
184 case Instruction::IPUT_OBJECT:
185 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_OBJECT_QUICK, true);
186 break;
187
188 case Instruction::INVOKE_VIRTUAL:
189 CompileInvokeVirtual(inst, dex_pc, Instruction::INVOKE_VIRTUAL_QUICK, false);
190 break;
191
192 case Instruction::INVOKE_VIRTUAL_RANGE:
193 CompileInvokeVirtual(inst, dex_pc, Instruction::INVOKE_VIRTUAL_RANGE_QUICK, true);
194 break;
195
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700196 case Instruction::NOP:
197 // We need to differentiate between check cast inserted NOP and normal NOP, put an invalid
198 // index in the map for normal nops. This should be rare in real code.
199 quickened_info_.push_back(QuickenedInfo(dex_pc, DexFile::kDexNoIndex16));
200 break;
201
Brian Carlstrom7940e442013-07-12 13:46:57 -0700202 default:
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700203 DCHECK(!inst->IsQuickened());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700204 // Nothing to do.
205 break;
206 }
207 }
208}
209
210void DexCompiler::CompileReturnVoid(Instruction* inst, uint32_t dex_pc) {
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700211 DCHECK_EQ(inst->Opcode(), Instruction::RETURN_VOID);
212 if (unit_.IsConstructor()) {
213 // Are we compiling a non clinit constructor which needs a barrier ?
214 if (!unit_.IsStatic() &&
215 driver_.RequiresConstructorBarrier(Thread::Current(), unit_.GetDexFile(),
216 unit_.GetClassDefIndex())) {
217 return;
218 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700219 }
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700220 // Replace RETURN_VOID by RETURN_VOID_NO_BARRIER.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200221 VLOG(compiler) << "Replacing " << Instruction::Name(inst->Opcode())
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700222 << " by " << Instruction::Name(Instruction::RETURN_VOID_NO_BARRIER)
Sebastien Hertz543959c2013-07-03 12:00:19 +0200223 << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700224 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700225 inst->SetOpcode(Instruction::RETURN_VOID_NO_BARRIER);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700226}
227
Sebastien Hertz543959c2013-07-03 12:00:19 +0200228Instruction* DexCompiler::CompileCheckCast(Instruction* inst, uint32_t dex_pc) {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700229 if (!kEnableCheckCastEllision) {
Sebastien Hertz543959c2013-07-03 12:00:19 +0200230 return inst;
231 }
Vladimir Marko2730db02014-01-27 11:15:17 +0000232 if (!driver_.IsSafeCast(&unit_, dex_pc)) {
Sebastien Hertz543959c2013-07-03 12:00:19 +0200233 return inst;
234 }
235 // Ok, this is a safe cast. Since the "check-cast" instruction size is 2 code
236 // units and a "nop" instruction size is 1 code unit, we need to replace it by
237 // 2 consecutive NOP instructions.
238 // Because the caller loops over instructions by calling Instruction::Next onto
239 // the current instruction, we need to return the 2nd NOP instruction. Indeed,
240 // its next instruction is the former check-cast's next instruction.
241 VLOG(compiler) << "Removing " << Instruction::Name(inst->Opcode())
242 << " by replacing it with 2 NOPs at dex pc "
243 << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700244 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Nicolas Geoffray01b70e82016-11-17 10:58:36 +0000245 quickened_info_.push_back(QuickenedInfo(dex_pc, inst->VRegA_21c()));
246 quickened_info_.push_back(QuickenedInfo(dex_pc, inst->VRegB_21c()));
Sebastien Hertz543959c2013-07-03 12:00:19 +0200247 // We are modifying 4 consecutive bytes.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200248 inst->SetOpcode(Instruction::NOP);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700249 inst->SetVRegA_10x(0u); // keep compliant with verifier.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200250 // Get to next instruction which is the second half of check-cast and replace
251 // it by a NOP.
252 inst = const_cast<Instruction*>(inst->Next());
253 inst->SetOpcode(Instruction::NOP);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700254 inst->SetVRegA_10x(0u); // keep compliant with verifier.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200255 return inst;
256}
257
Brian Carlstrom7940e442013-07-12 13:46:57 -0700258void DexCompiler::CompileInstanceFieldAccess(Instruction* inst,
259 uint32_t dex_pc,
260 Instruction::Code new_opcode,
261 bool is_put) {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700262 if (!kEnableQuickening) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700263 return;
264 }
265 uint32_t field_idx = inst->VRegC_22c();
Vladimir Markobe0e5462014-02-26 11:24:15 +0000266 MemberOffset field_offset(0u);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700267 bool is_volatile;
Ian Rogers9b297bf2013-09-06 11:11:25 -0700268 bool fast_path = driver_.ComputeInstanceFieldInfo(field_idx, &unit_, is_put,
269 &field_offset, &is_volatile);
Andreas Gampeab1eb0d2015-02-13 19:23:55 -0800270 if (fast_path && !is_volatile && IsUint<16>(field_offset.Int32Value())) {
Sebastien Hertz543959c2013-07-03 12:00:19 +0200271 VLOG(compiler) << "Quickening " << Instruction::Name(inst->Opcode())
272 << " to " << Instruction::Name(new_opcode)
273 << " by replacing field index " << field_idx
Vladimir Markobe0e5462014-02-26 11:24:15 +0000274 << " by field offset " << field_offset.Int32Value()
Sebastien Hertz543959c2013-07-03 12:00:19 +0200275 << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700276 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700277 // We are modifying 4 consecutive bytes.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700278 inst->SetOpcode(new_opcode);
279 // Replace field index by field offset.
Vladimir Markobe0e5462014-02-26 11:24:15 +0000280 inst->SetVRegC_22c(static_cast<uint16_t>(field_offset.Int32Value()));
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100281 quickened_info_.push_back(QuickenedInfo(dex_pc, field_idx));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700282 }
283}
284
Mathieu Chartier091d2382015-03-06 10:59:06 -0800285void DexCompiler::CompileInvokeVirtual(Instruction* inst, uint32_t dex_pc,
286 Instruction::Code new_opcode, bool is_range) {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700287 if (!kEnableQuickening) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700288 return;
289 }
290 uint32_t method_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100291 ScopedObjectAccess soa(Thread::Current());
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100292
293 ClassLinker* class_linker = unit_.GetClassLinker();
Vladimir Markoba118822017-06-12 15:41:56 +0100294 ArtMethod* resolved_method =
295 class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>(
296 GetDexFile(),
297 method_idx,
298 unit_.GetDexCache(),
299 unit_.GetClassLoader(),
300 /* referrer */ nullptr,
301 kVirtual);
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100302
303 if (UNLIKELY(resolved_method == nullptr)) {
304 // Clean up any exception left by type resolution.
305 soa.Self()->ClearException();
306 return;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700307 }
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100308
309 uint32_t vtable_idx = resolved_method->GetMethodIndex();
310 DCHECK(IsUint<16>(vtable_idx));
311 VLOG(compiler) << "Quickening " << Instruction::Name(inst->Opcode())
David Sehr709b0702016-10-13 09:12:37 -0700312 << "(" << GetDexFile().PrettyMethod(method_idx, true) << ")"
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100313 << " to " << Instruction::Name(new_opcode)
314 << " by replacing method index " << method_idx
315 << " by vtable index " << vtable_idx
316 << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700317 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100318 // We are modifying 4 consecutive bytes.
319 inst->SetOpcode(new_opcode);
320 // Replace method index by vtable index.
321 if (is_range) {
322 inst->SetVRegB_3rc(static_cast<uint16_t>(vtable_idx));
323 } else {
324 inst->SetVRegB_35c(static_cast<uint16_t>(vtable_idx));
325 }
326 quickened_info_.push_back(QuickenedInfo(dex_pc, method_idx));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700327}
328
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700329CompiledMethod* ArtCompileDEX(
330 CompilerDriver* driver,
331 const DexFile::CodeItem* code_item,
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100332 uint32_t access_flags,
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700333 InvokeType invoke_type ATTRIBUTE_UNUSED,
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100334 uint16_t class_def_idx,
335 uint32_t method_idx,
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000336 Handle<mirror::ClassLoader> class_loader,
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700337 const DexFile& dex_file,
338 DexToDexCompilationLevel dex_to_dex_compilation_level) {
339 DCHECK(driver != nullptr);
340 if (dex_to_dex_compilation_level != DexToDexCompilationLevel::kDontDexToDexCompile) {
Mathieu Chartier736b5602015-09-02 14:54:11 -0700341 ScopedObjectAccess soa(Thread::Current());
342 StackHandleScope<1> hs(soa.Self());
343 ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
Vladimir Markodf739842016-03-23 16:59:07 +0000344 art::DexCompilationUnit unit(
345 class_loader,
346 class_linker,
347 dex_file,
348 code_item,
349 class_def_idx,
350 method_idx,
351 access_flags,
352 driver->GetVerifiedMethod(&dex_file, method_idx),
353 hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file)));
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700354 art::optimizer::DexCompiler dex_compiler(*driver, unit, dex_to_dex_compilation_level);
Sebastien Hertz75021222013-07-16 18:34:50 +0200355 dex_compiler.Compile();
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100356 if (dex_compiler.GetQuickenedInfo().empty()) {
357 // No need to create a CompiledMethod if there are no quickened opcodes.
358 return nullptr;
359 }
360
361 // Create a `CompiledMethod`, with the quickened information in the vmap table.
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700362 if (kIsDebugBuild) {
363 // Double check that the counts line up with the size of the quicken info.
364 size_t quicken_count = 0;
365 for (CodeItemIterator it(*code_item); !it.Done(); it.Advance()) {
366 if (QuickenInfoTable::NeedsIndexForInstruction(&it.CurrentInstruction())) {
367 ++quicken_count;
368 }
369 }
370 CHECK_EQ(quicken_count, dex_compiler.GetQuickenedInfo().size());
371 }
372 std::vector<uint8_t> quicken_data;
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100373 for (QuickenedInfo info : dex_compiler.GetQuickenedInfo()) {
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700374 // Dex pc is not serialized, only used for checking the instructions. Since we access the
375 // array based on the index of the quickened instruction, the indexes must line up perfectly.
376 // The reader side uses the NeedsIndexForInstruction function too.
Mathieu Chartier1d2d4ff2017-09-23 16:11:06 -0700377 const Instruction& inst = code_item->InstructionAt(info.dex_pc);
378 CHECK(QuickenInfoTable::NeedsIndexForInstruction(&inst)) << inst.Opcode();
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700379 // Add the index.
380 quicken_data.push_back(static_cast<uint8_t>(info.dex_member_index >> 0));
381 quicken_data.push_back(static_cast<uint8_t>(info.dex_member_index >> 8));
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100382 }
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700383 InstructionSet instruction_set = driver->GetInstructionSet();
Vladimir Marko33bff252017-11-01 14:35:42 +0000384 if (instruction_set == InstructionSet::kThumb2) {
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100385 // Don't use the thumb2 instruction set to avoid the one off code delta.
Vladimir Marko33bff252017-11-01 14:35:42 +0000386 instruction_set = InstructionSet::kArm;
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100387 }
388 return CompiledMethod::SwapAllocCompiledMethod(
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700389 driver,
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100390 instruction_set,
391 ArrayRef<const uint8_t>(), // no code
392 0,
393 0,
394 0,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700395 ArrayRef<const uint8_t>(), // method_info
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700396 ArrayRef<const uint8_t>(quicken_data), // vmap_table
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100397 ArrayRef<const uint8_t>(), // cfi data
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100398 ArrayRef<const linker::LinkerPatch>());
Sebastien Hertz75021222013-07-16 18:34:50 +0200399 }
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100400 return nullptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700401}
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100402
403} // namespace optimizer
404
405} // namespace art