blob: cc452fc1ae9e6ab320140b38a2c2c492b4cc52a2 [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 Chartier0021feb2017-11-07 00:08:52 -0800115 IterationRange<DexInstructionIterator> instructions = unit_.GetCodeItem()->Instructions();
116 for (DexInstructionIterator it = instructions.begin(); it != instructions.end(); ++it) {
117 const uint32_t dex_pc = it.DexPc();
118 Instruction* inst = const_cast<Instruction*>(&it.Inst());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700119 switch (inst->Opcode()) {
120 case Instruction::RETURN_VOID:
121 CompileReturnVoid(inst, dex_pc);
122 break;
123
Sebastien Hertz543959c2013-07-03 12:00:19 +0200124 case Instruction::CHECK_CAST:
125 inst = CompileCheckCast(inst, dex_pc);
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700126 if (inst->Opcode() == Instruction::NOP) {
127 // We turned the CHECK_CAST into two NOPs, avoid visiting the second NOP twice since this
128 // would add 2 quickening info entries.
Mathieu Chartier0021feb2017-11-07 00:08:52 -0800129 ++it;
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700130 }
Sebastien Hertz543959c2013-07-03 12:00:19 +0200131 break;
132
Brian Carlstrom7940e442013-07-12 13:46:57 -0700133 case Instruction::IGET:
134 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_QUICK, false);
135 break;
136
137 case Instruction::IGET_WIDE:
138 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_WIDE_QUICK, false);
139 break;
140
141 case Instruction::IGET_OBJECT:
142 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_OBJECT_QUICK, false);
143 break;
144
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800145 case Instruction::IGET_BOOLEAN:
146 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_BOOLEAN_QUICK, false);
147 break;
148
149 case Instruction::IGET_BYTE:
150 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_BYTE_QUICK, false);
151 break;
152
153 case Instruction::IGET_CHAR:
154 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_CHAR_QUICK, false);
155 break;
156
157 case Instruction::IGET_SHORT:
158 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_SHORT_QUICK, false);
159 break;
160
Brian Carlstrom7940e442013-07-12 13:46:57 -0700161 case Instruction::IPUT:
Brian Carlstrom7940e442013-07-12 13:46:57 -0700162 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_QUICK, true);
163 break;
164
Fred Shih37f05ef2014-07-16 18:38:08 -0700165 case Instruction::IPUT_BOOLEAN:
166 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_BOOLEAN_QUICK, true);
167 break;
168
169 case Instruction::IPUT_BYTE:
170 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_BYTE_QUICK, true);
171 break;
172
173 case Instruction::IPUT_CHAR:
174 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_CHAR_QUICK, true);
175 break;
176
177 case Instruction::IPUT_SHORT:
178 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_SHORT_QUICK, true);
179 break;
180
Brian Carlstrom7940e442013-07-12 13:46:57 -0700181 case Instruction::IPUT_WIDE:
182 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_WIDE_QUICK, true);
183 break;
184
185 case Instruction::IPUT_OBJECT:
186 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_OBJECT_QUICK, true);
187 break;
188
189 case Instruction::INVOKE_VIRTUAL:
190 CompileInvokeVirtual(inst, dex_pc, Instruction::INVOKE_VIRTUAL_QUICK, false);
191 break;
192
193 case Instruction::INVOKE_VIRTUAL_RANGE:
194 CompileInvokeVirtual(inst, dex_pc, Instruction::INVOKE_VIRTUAL_RANGE_QUICK, true);
195 break;
196
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700197 case Instruction::NOP:
198 // We need to differentiate between check cast inserted NOP and normal NOP, put an invalid
199 // index in the map for normal nops. This should be rare in real code.
200 quickened_info_.push_back(QuickenedInfo(dex_pc, DexFile::kDexNoIndex16));
201 break;
202
Brian Carlstrom7940e442013-07-12 13:46:57 -0700203 default:
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700204 DCHECK(!inst->IsQuickened());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700205 // Nothing to do.
206 break;
207 }
208 }
209}
210
211void DexCompiler::CompileReturnVoid(Instruction* inst, uint32_t dex_pc) {
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700212 DCHECK_EQ(inst->Opcode(), Instruction::RETURN_VOID);
213 if (unit_.IsConstructor()) {
214 // Are we compiling a non clinit constructor which needs a barrier ?
215 if (!unit_.IsStatic() &&
216 driver_.RequiresConstructorBarrier(Thread::Current(), unit_.GetDexFile(),
217 unit_.GetClassDefIndex())) {
218 return;
219 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700220 }
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700221 // Replace RETURN_VOID by RETURN_VOID_NO_BARRIER.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200222 VLOG(compiler) << "Replacing " << Instruction::Name(inst->Opcode())
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700223 << " by " << Instruction::Name(Instruction::RETURN_VOID_NO_BARRIER)
Sebastien Hertz543959c2013-07-03 12:00:19 +0200224 << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700225 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700226 inst->SetOpcode(Instruction::RETURN_VOID_NO_BARRIER);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700227}
228
Sebastien Hertz543959c2013-07-03 12:00:19 +0200229Instruction* DexCompiler::CompileCheckCast(Instruction* inst, uint32_t dex_pc) {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700230 if (!kEnableCheckCastEllision) {
Sebastien Hertz543959c2013-07-03 12:00:19 +0200231 return inst;
232 }
Vladimir Marko2730db02014-01-27 11:15:17 +0000233 if (!driver_.IsSafeCast(&unit_, dex_pc)) {
Sebastien Hertz543959c2013-07-03 12:00:19 +0200234 return inst;
235 }
236 // Ok, this is a safe cast. Since the "check-cast" instruction size is 2 code
237 // units and a "nop" instruction size is 1 code unit, we need to replace it by
238 // 2 consecutive NOP instructions.
239 // Because the caller loops over instructions by calling Instruction::Next onto
240 // the current instruction, we need to return the 2nd NOP instruction. Indeed,
241 // its next instruction is the former check-cast's next instruction.
242 VLOG(compiler) << "Removing " << Instruction::Name(inst->Opcode())
243 << " by replacing it with 2 NOPs at dex pc "
244 << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700245 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Nicolas Geoffray01b70e82016-11-17 10:58:36 +0000246 quickened_info_.push_back(QuickenedInfo(dex_pc, inst->VRegA_21c()));
247 quickened_info_.push_back(QuickenedInfo(dex_pc, inst->VRegB_21c()));
Sebastien Hertz543959c2013-07-03 12:00:19 +0200248 // We are modifying 4 consecutive bytes.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200249 inst->SetOpcode(Instruction::NOP);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700250 inst->SetVRegA_10x(0u); // keep compliant with verifier.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200251 // Get to next instruction which is the second half of check-cast and replace
252 // it by a NOP.
253 inst = const_cast<Instruction*>(inst->Next());
254 inst->SetOpcode(Instruction::NOP);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700255 inst->SetVRegA_10x(0u); // keep compliant with verifier.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200256 return inst;
257}
258
Brian Carlstrom7940e442013-07-12 13:46:57 -0700259void DexCompiler::CompileInstanceFieldAccess(Instruction* inst,
260 uint32_t dex_pc,
261 Instruction::Code new_opcode,
262 bool is_put) {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700263 if (!kEnableQuickening) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700264 return;
265 }
266 uint32_t field_idx = inst->VRegC_22c();
Vladimir Markobe0e5462014-02-26 11:24:15 +0000267 MemberOffset field_offset(0u);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700268 bool is_volatile;
Ian Rogers9b297bf2013-09-06 11:11:25 -0700269 bool fast_path = driver_.ComputeInstanceFieldInfo(field_idx, &unit_, is_put,
270 &field_offset, &is_volatile);
Andreas Gampeab1eb0d2015-02-13 19:23:55 -0800271 if (fast_path && !is_volatile && IsUint<16>(field_offset.Int32Value())) {
Sebastien Hertz543959c2013-07-03 12:00:19 +0200272 VLOG(compiler) << "Quickening " << Instruction::Name(inst->Opcode())
273 << " to " << Instruction::Name(new_opcode)
274 << " by replacing field index " << field_idx
Vladimir Markobe0e5462014-02-26 11:24:15 +0000275 << " by field offset " << field_offset.Int32Value()
Sebastien Hertz543959c2013-07-03 12:00:19 +0200276 << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700277 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700278 // We are modifying 4 consecutive bytes.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700279 inst->SetOpcode(new_opcode);
280 // Replace field index by field offset.
Vladimir Markobe0e5462014-02-26 11:24:15 +0000281 inst->SetVRegC_22c(static_cast<uint16_t>(field_offset.Int32Value()));
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100282 quickened_info_.push_back(QuickenedInfo(dex_pc, field_idx));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700283 }
284}
285
Mathieu Chartier091d2382015-03-06 10:59:06 -0800286void DexCompiler::CompileInvokeVirtual(Instruction* inst, uint32_t dex_pc,
287 Instruction::Code new_opcode, bool is_range) {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700288 if (!kEnableQuickening) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700289 return;
290 }
291 uint32_t method_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100292 ScopedObjectAccess soa(Thread::Current());
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100293
294 ClassLinker* class_linker = unit_.GetClassLinker();
Vladimir Markoba118822017-06-12 15:41:56 +0100295 ArtMethod* resolved_method =
296 class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>(
297 GetDexFile(),
298 method_idx,
299 unit_.GetDexCache(),
300 unit_.GetClassLoader(),
301 /* referrer */ nullptr,
302 kVirtual);
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100303
304 if (UNLIKELY(resolved_method == nullptr)) {
305 // Clean up any exception left by type resolution.
306 soa.Self()->ClearException();
307 return;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700308 }
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100309
310 uint32_t vtable_idx = resolved_method->GetMethodIndex();
311 DCHECK(IsUint<16>(vtable_idx));
312 VLOG(compiler) << "Quickening " << Instruction::Name(inst->Opcode())
David Sehr709b0702016-10-13 09:12:37 -0700313 << "(" << GetDexFile().PrettyMethod(method_idx, true) << ")"
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100314 << " to " << Instruction::Name(new_opcode)
315 << " by replacing method index " << method_idx
316 << " by vtable index " << vtable_idx
317 << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700318 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100319 // We are modifying 4 consecutive bytes.
320 inst->SetOpcode(new_opcode);
321 // Replace method index by vtable index.
322 if (is_range) {
323 inst->SetVRegB_3rc(static_cast<uint16_t>(vtable_idx));
324 } else {
325 inst->SetVRegB_35c(static_cast<uint16_t>(vtable_idx));
326 }
327 quickened_info_.push_back(QuickenedInfo(dex_pc, method_idx));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700328}
329
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700330CompiledMethod* ArtCompileDEX(
331 CompilerDriver* driver,
332 const DexFile::CodeItem* code_item,
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100333 uint32_t access_flags,
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700334 InvokeType invoke_type ATTRIBUTE_UNUSED,
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100335 uint16_t class_def_idx,
336 uint32_t method_idx,
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000337 Handle<mirror::ClassLoader> class_loader,
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700338 const DexFile& dex_file,
339 DexToDexCompilationLevel dex_to_dex_compilation_level) {
340 DCHECK(driver != nullptr);
341 if (dex_to_dex_compilation_level != DexToDexCompilationLevel::kDontDexToDexCompile) {
Mathieu Chartier736b5602015-09-02 14:54:11 -0700342 ScopedObjectAccess soa(Thread::Current());
343 StackHandleScope<1> hs(soa.Self());
344 ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
Vladimir Markodf739842016-03-23 16:59:07 +0000345 art::DexCompilationUnit unit(
346 class_loader,
347 class_linker,
348 dex_file,
349 code_item,
350 class_def_idx,
351 method_idx,
352 access_flags,
353 driver->GetVerifiedMethod(&dex_file, method_idx),
354 hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file)));
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700355 art::optimizer::DexCompiler dex_compiler(*driver, unit, dex_to_dex_compilation_level);
Sebastien Hertz75021222013-07-16 18:34:50 +0200356 dex_compiler.Compile();
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100357 if (dex_compiler.GetQuickenedInfo().empty()) {
358 // No need to create a CompiledMethod if there are no quickened opcodes.
359 return nullptr;
360 }
361
362 // Create a `CompiledMethod`, with the quickened information in the vmap table.
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700363 if (kIsDebugBuild) {
364 // Double check that the counts line up with the size of the quicken info.
365 size_t quicken_count = 0;
Mathieu Chartier0021feb2017-11-07 00:08:52 -0800366 for (const DexInstructionPcPair& pair : code_item->Instructions()) {
367 if (QuickenInfoTable::NeedsIndexForInstruction(&pair.Inst())) {
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700368 ++quicken_count;
369 }
370 }
371 CHECK_EQ(quicken_count, dex_compiler.GetQuickenedInfo().size());
372 }
373 std::vector<uint8_t> quicken_data;
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100374 for (QuickenedInfo info : dex_compiler.GetQuickenedInfo()) {
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700375 // Dex pc is not serialized, only used for checking the instructions. Since we access the
376 // array based on the index of the quickened instruction, the indexes must line up perfectly.
377 // The reader side uses the NeedsIndexForInstruction function too.
Mathieu Chartier1d2d4ff2017-09-23 16:11:06 -0700378 const Instruction& inst = code_item->InstructionAt(info.dex_pc);
379 CHECK(QuickenInfoTable::NeedsIndexForInstruction(&inst)) << inst.Opcode();
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700380 // Add the index.
381 quicken_data.push_back(static_cast<uint8_t>(info.dex_member_index >> 0));
382 quicken_data.push_back(static_cast<uint8_t>(info.dex_member_index >> 8));
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100383 }
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700384 InstructionSet instruction_set = driver->GetInstructionSet();
Vladimir Marko33bff252017-11-01 14:35:42 +0000385 if (instruction_set == InstructionSet::kThumb2) {
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100386 // Don't use the thumb2 instruction set to avoid the one off code delta.
Vladimir Marko33bff252017-11-01 14:35:42 +0000387 instruction_set = InstructionSet::kArm;
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100388 }
389 return CompiledMethod::SwapAllocCompiledMethod(
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700390 driver,
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100391 instruction_set,
392 ArrayRef<const uint8_t>(), // no code
393 0,
394 0,
395 0,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700396 ArrayRef<const uint8_t>(), // method_info
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700397 ArrayRef<const uint8_t>(quicken_data), // vmap_table
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100398 ArrayRef<const uint8_t>(), // cfi data
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100399 ArrayRef<const linker::LinkerPatch>());
Sebastien Hertz75021222013-07-16 18:34:50 +0200400 }
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100401 return nullptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700402}
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100403
404} // namespace optimizer
405
406} // namespace art