blob: eddc8ed132b4cf70ff3391f32fae38311975213b [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 Gampe57943812017-12-06 21:39:13 -080019#include <android-base/logging.h>
20#include <android-base/stringprintf.h>
Andreas Gampe46ee31b2016-12-14 10:11:49 -080021
Mathieu Chartierc7853442015-03-27 14:35:38 -070022#include "art_field-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070023#include "art_method-inl.h"
Andreas Gampe57943812017-12-06 21:39:13 -080024#include "base/macros.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070025#include "base/mutex.h"
Mathieu Chartierde4b08f2017-07-10 14:13:41 -070026#include "bytecode_utils.h"
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010027#include "compiled_method.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070028#include "dex_file-inl.h"
29#include "dex_instruction-inl.h"
30#include "driver/compiler_driver.h"
31#include "driver/dex_compilation_unit.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070032#include "mirror/dex_cache.h"
Mathieu Chartierde4b08f2017-07-10 14:13:41 -070033#include "quicken_info.h"
Andreas Gampeb486a982017-06-01 13:45:54 -070034#include "thread-current-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070035
36namespace art {
37namespace optimizer {
38
Andreas Gampe46ee31b2016-12-14 10:11:49 -080039using android::base::StringPrintf;
40
Brian Carlstrom7940e442013-07-12 13:46:57 -070041// Controls quickening activation.
42const bool kEnableQuickening = true;
Sebastien Hertz543959c2013-07-03 12:00:19 +020043// Control check-cast elision.
44const bool kEnableCheckCastEllision = true;
Brian Carlstrom7940e442013-07-12 13:46:57 -070045
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010046struct QuickenedInfo {
47 QuickenedInfo(uint32_t pc, uint16_t index) : dex_pc(pc), dex_member_index(index) {}
48
49 uint32_t dex_pc;
50 uint16_t dex_member_index;
51};
52
Brian Carlstrom7940e442013-07-12 13:46:57 -070053class DexCompiler {
54 public:
55 DexCompiler(art::CompilerDriver& compiler,
Sebastien Hertz75021222013-07-16 18:34:50 +020056 const DexCompilationUnit& unit,
57 DexToDexCompilationLevel dex_to_dex_compilation_level)
Brian Carlstrom7940e442013-07-12 13:46:57 -070058 : driver_(compiler),
Sebastien Hertz75021222013-07-16 18:34:50 +020059 unit_(unit),
60 dex_to_dex_compilation_level_(dex_to_dex_compilation_level) {}
Brian Carlstrom7940e442013-07-12 13:46:57 -070061
Brian Carlstrom9b7085a2013-07-18 15:15:21 -070062 ~DexCompiler() {}
Brian Carlstrom7940e442013-07-12 13:46:57 -070063
64 void Compile();
65
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +010066 const std::vector<QuickenedInfo>& GetQuickenedInfo() const {
67 return quickened_info_;
68 }
69
Brian Carlstrom7940e442013-07-12 13:46:57 -070070 private:
71 const DexFile& GetDexFile() const {
72 return *unit_.GetDexFile();
73 }
74
Brian Carlstrom7940e442013-07-12 13:46:57 -070075 // Compiles a RETURN-VOID into a RETURN-VOID-BARRIER within a constructor where
76 // a barrier is required.
77 void CompileReturnVoid(Instruction* inst, uint32_t dex_pc);
78
Sebastien Hertz543959c2013-07-03 12:00:19 +020079 // Compiles a CHECK-CAST into 2 NOP instructions if it is known to be safe. In
80 // this case, returns the second NOP instruction pointer. Otherwise, returns
81 // the given "inst".
82 Instruction* CompileCheckCast(Instruction* inst, uint32_t dex_pc);
83
Brian Carlstrom7940e442013-07-12 13:46:57 -070084 // Compiles a field access into a quick field access.
85 // The field index is replaced by an offset within an Object where we can read
86 // from / write to this field. Therefore, this does not involve any resolution
87 // at runtime.
88 // Since the field index is encoded with 16 bits, we can replace it only if the
89 // field offset can be encoded with 16 bits too.
90 void CompileInstanceFieldAccess(Instruction* inst, uint32_t dex_pc,
91 Instruction::Code new_opcode, bool is_put);
92
93 // Compiles a virtual method invocation into a quick virtual method invocation.
94 // The method index is replaced by the vtable index where the corresponding
Neil Fuller0e844392016-09-08 13:43:31 +010095 // Executable can be found. Therefore, this does not involve any resolution
Brian Carlstrom7940e442013-07-12 13:46:57 -070096 // at runtime.
97 // Since the method index is encoded with 16 bits, we can replace it only if the
98 // vtable index can be encoded with 16 bits too.
99 void CompileInvokeVirtual(Instruction* inst, uint32_t dex_pc,
100 Instruction::Code new_opcode, bool is_range);
101
102 CompilerDriver& driver_;
103 const DexCompilationUnit& unit_;
Sebastien Hertz75021222013-07-16 18:34:50 +0200104 const DexToDexCompilationLevel dex_to_dex_compilation_level_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700105
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100106 // Filled by the compiler when quickening, in order to encode that information
107 // in the .oat file. The runtime will use that information to get to the original
108 // opcodes.
109 std::vector<QuickenedInfo> quickened_info_;
110
Brian Carlstrom7940e442013-07-12 13:46:57 -0700111 DISALLOW_COPY_AND_ASSIGN(DexCompiler);
112};
113
Brian Carlstrom7940e442013-07-12 13:46:57 -0700114void DexCompiler::Compile() {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700115 DCHECK_EQ(dex_to_dex_compilation_level_, DexToDexCompilationLevel::kOptimize);
Mathieu Chartier0021feb2017-11-07 00:08:52 -0800116 IterationRange<DexInstructionIterator> instructions = unit_.GetCodeItem()->Instructions();
117 for (DexInstructionIterator it = instructions.begin(); it != instructions.end(); ++it) {
118 const uint32_t dex_pc = it.DexPc();
119 Instruction* inst = const_cast<Instruction*>(&it.Inst());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700120 switch (inst->Opcode()) {
121 case Instruction::RETURN_VOID:
122 CompileReturnVoid(inst, dex_pc);
123 break;
124
Sebastien Hertz543959c2013-07-03 12:00:19 +0200125 case Instruction::CHECK_CAST:
126 inst = CompileCheckCast(inst, dex_pc);
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700127 if (inst->Opcode() == Instruction::NOP) {
128 // We turned the CHECK_CAST into two NOPs, avoid visiting the second NOP twice since this
129 // would add 2 quickening info entries.
Mathieu Chartier0021feb2017-11-07 00:08:52 -0800130 ++it;
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700131 }
Sebastien Hertz543959c2013-07-03 12:00:19 +0200132 break;
133
Brian Carlstrom7940e442013-07-12 13:46:57 -0700134 case Instruction::IGET:
135 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_QUICK, false);
136 break;
137
138 case Instruction::IGET_WIDE:
139 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_WIDE_QUICK, false);
140 break;
141
142 case Instruction::IGET_OBJECT:
143 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_OBJECT_QUICK, false);
144 break;
145
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800146 case Instruction::IGET_BOOLEAN:
147 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_BOOLEAN_QUICK, false);
148 break;
149
150 case Instruction::IGET_BYTE:
151 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_BYTE_QUICK, false);
152 break;
153
154 case Instruction::IGET_CHAR:
155 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_CHAR_QUICK, false);
156 break;
157
158 case Instruction::IGET_SHORT:
159 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IGET_SHORT_QUICK, false);
160 break;
161
Brian Carlstrom7940e442013-07-12 13:46:57 -0700162 case Instruction::IPUT:
Brian Carlstrom7940e442013-07-12 13:46:57 -0700163 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_QUICK, true);
164 break;
165
Fred Shih37f05ef2014-07-16 18:38:08 -0700166 case Instruction::IPUT_BOOLEAN:
167 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_BOOLEAN_QUICK, true);
168 break;
169
170 case Instruction::IPUT_BYTE:
171 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_BYTE_QUICK, true);
172 break;
173
174 case Instruction::IPUT_CHAR:
175 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_CHAR_QUICK, true);
176 break;
177
178 case Instruction::IPUT_SHORT:
179 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_SHORT_QUICK, true);
180 break;
181
Brian Carlstrom7940e442013-07-12 13:46:57 -0700182 case Instruction::IPUT_WIDE:
183 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_WIDE_QUICK, true);
184 break;
185
186 case Instruction::IPUT_OBJECT:
187 CompileInstanceFieldAccess(inst, dex_pc, Instruction::IPUT_OBJECT_QUICK, true);
188 break;
189
190 case Instruction::INVOKE_VIRTUAL:
191 CompileInvokeVirtual(inst, dex_pc, Instruction::INVOKE_VIRTUAL_QUICK, false);
192 break;
193
194 case Instruction::INVOKE_VIRTUAL_RANGE:
195 CompileInvokeVirtual(inst, dex_pc, Instruction::INVOKE_VIRTUAL_RANGE_QUICK, true);
196 break;
197
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700198 case Instruction::NOP:
199 // We need to differentiate between check cast inserted NOP and normal NOP, put an invalid
200 // index in the map for normal nops. This should be rare in real code.
201 quickened_info_.push_back(QuickenedInfo(dex_pc, DexFile::kDexNoIndex16));
202 break;
203
Brian Carlstrom7940e442013-07-12 13:46:57 -0700204 default:
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700205 DCHECK(!inst->IsQuickened());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700206 // Nothing to do.
207 break;
208 }
209 }
210}
211
212void DexCompiler::CompileReturnVoid(Instruction* inst, uint32_t dex_pc) {
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700213 DCHECK_EQ(inst->Opcode(), Instruction::RETURN_VOID);
214 if (unit_.IsConstructor()) {
215 // Are we compiling a non clinit constructor which needs a barrier ?
216 if (!unit_.IsStatic() &&
217 driver_.RequiresConstructorBarrier(Thread::Current(), unit_.GetDexFile(),
218 unit_.GetClassDefIndex())) {
219 return;
220 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700221 }
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700222 // Replace RETURN_VOID by RETURN_VOID_NO_BARRIER.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200223 VLOG(compiler) << "Replacing " << Instruction::Name(inst->Opcode())
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700224 << " by " << Instruction::Name(Instruction::RETURN_VOID_NO_BARRIER)
Sebastien Hertz543959c2013-07-03 12:00:19 +0200225 << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700226 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700227 inst->SetOpcode(Instruction::RETURN_VOID_NO_BARRIER);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700228}
229
Sebastien Hertz543959c2013-07-03 12:00:19 +0200230Instruction* DexCompiler::CompileCheckCast(Instruction* inst, uint32_t dex_pc) {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700231 if (!kEnableCheckCastEllision) {
Sebastien Hertz543959c2013-07-03 12:00:19 +0200232 return inst;
233 }
Vladimir Marko2730db02014-01-27 11:15:17 +0000234 if (!driver_.IsSafeCast(&unit_, dex_pc)) {
Sebastien Hertz543959c2013-07-03 12:00:19 +0200235 return inst;
236 }
237 // Ok, this is a safe cast. Since the "check-cast" instruction size is 2 code
238 // units and a "nop" instruction size is 1 code unit, we need to replace it by
239 // 2 consecutive NOP instructions.
240 // Because the caller loops over instructions by calling Instruction::Next onto
241 // the current instruction, we need to return the 2nd NOP instruction. Indeed,
242 // its next instruction is the former check-cast's next instruction.
243 VLOG(compiler) << "Removing " << Instruction::Name(inst->Opcode())
244 << " by replacing it with 2 NOPs at dex pc "
245 << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700246 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Nicolas Geoffray01b70e82016-11-17 10:58:36 +0000247 quickened_info_.push_back(QuickenedInfo(dex_pc, inst->VRegA_21c()));
248 quickened_info_.push_back(QuickenedInfo(dex_pc, inst->VRegB_21c()));
Sebastien Hertz543959c2013-07-03 12:00:19 +0200249 // We are modifying 4 consecutive bytes.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200250 inst->SetOpcode(Instruction::NOP);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700251 inst->SetVRegA_10x(0u); // keep compliant with verifier.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200252 // Get to next instruction which is the second half of check-cast and replace
253 // it by a NOP.
254 inst = const_cast<Instruction*>(inst->Next());
255 inst->SetOpcode(Instruction::NOP);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700256 inst->SetVRegA_10x(0u); // keep compliant with verifier.
Sebastien Hertz543959c2013-07-03 12:00:19 +0200257 return inst;
258}
259
Brian Carlstrom7940e442013-07-12 13:46:57 -0700260void DexCompiler::CompileInstanceFieldAccess(Instruction* inst,
261 uint32_t dex_pc,
262 Instruction::Code new_opcode,
263 bool is_put) {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700264 if (!kEnableQuickening) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700265 return;
266 }
267 uint32_t field_idx = inst->VRegC_22c();
Vladimir Markobe0e5462014-02-26 11:24:15 +0000268 MemberOffset field_offset(0u);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700269 bool is_volatile;
Ian Rogers9b297bf2013-09-06 11:11:25 -0700270 bool fast_path = driver_.ComputeInstanceFieldInfo(field_idx, &unit_, is_put,
271 &field_offset, &is_volatile);
Andreas Gampeab1eb0d2015-02-13 19:23:55 -0800272 if (fast_path && !is_volatile && IsUint<16>(field_offset.Int32Value())) {
Sebastien Hertz543959c2013-07-03 12:00:19 +0200273 VLOG(compiler) << "Quickening " << Instruction::Name(inst->Opcode())
274 << " to " << Instruction::Name(new_opcode)
275 << " by replacing field index " << field_idx
Vladimir Markobe0e5462014-02-26 11:24:15 +0000276 << " by field offset " << field_offset.Int32Value()
Sebastien Hertz543959c2013-07-03 12:00:19 +0200277 << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700278 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700279 // We are modifying 4 consecutive bytes.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700280 inst->SetOpcode(new_opcode);
281 // Replace field index by field offset.
Vladimir Markobe0e5462014-02-26 11:24:15 +0000282 inst->SetVRegC_22c(static_cast<uint16_t>(field_offset.Int32Value()));
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100283 quickened_info_.push_back(QuickenedInfo(dex_pc, field_idx));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700284 }
285}
286
Mathieu Chartier091d2382015-03-06 10:59:06 -0800287void DexCompiler::CompileInvokeVirtual(Instruction* inst, uint32_t dex_pc,
288 Instruction::Code new_opcode, bool is_range) {
Andreas Gampe1a4bc7f2017-03-27 14:57:30 -0700289 if (!kEnableQuickening) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700290 return;
291 }
292 uint32_t method_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100293 ScopedObjectAccess soa(Thread::Current());
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100294
295 ClassLinker* class_linker = unit_.GetClassLinker();
Vladimir Markoba118822017-06-12 15:41:56 +0100296 ArtMethod* resolved_method =
297 class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>(
298 GetDexFile(),
299 method_idx,
300 unit_.GetDexCache(),
301 unit_.GetClassLoader(),
302 /* referrer */ nullptr,
303 kVirtual);
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100304
305 if (UNLIKELY(resolved_method == nullptr)) {
306 // Clean up any exception left by type resolution.
307 soa.Self()->ClearException();
308 return;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700309 }
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100310
311 uint32_t vtable_idx = resolved_method->GetMethodIndex();
312 DCHECK(IsUint<16>(vtable_idx));
313 VLOG(compiler) << "Quickening " << Instruction::Name(inst->Opcode())
David Sehr709b0702016-10-13 09:12:37 -0700314 << "(" << GetDexFile().PrettyMethod(method_idx, true) << ")"
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100315 << " to " << Instruction::Name(new_opcode)
316 << " by replacing method index " << method_idx
317 << " by vtable index " << vtable_idx
318 << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method "
David Sehr709b0702016-10-13 09:12:37 -0700319 << GetDexFile().PrettyMethod(unit_.GetDexMethodIndex(), true);
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100320 // We are modifying 4 consecutive bytes.
321 inst->SetOpcode(new_opcode);
322 // Replace method index by vtable index.
323 if (is_range) {
324 inst->SetVRegB_3rc(static_cast<uint16_t>(vtable_idx));
325 } else {
326 inst->SetVRegB_35c(static_cast<uint16_t>(vtable_idx));
327 }
328 quickened_info_.push_back(QuickenedInfo(dex_pc, method_idx));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700329}
330
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700331CompiledMethod* ArtCompileDEX(
332 CompilerDriver* driver,
333 const DexFile::CodeItem* code_item,
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100334 uint32_t access_flags,
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700335 InvokeType invoke_type ATTRIBUTE_UNUSED,
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100336 uint16_t class_def_idx,
337 uint32_t method_idx,
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000338 Handle<mirror::ClassLoader> class_loader,
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700339 const DexFile& dex_file,
340 DexToDexCompilationLevel dex_to_dex_compilation_level) {
341 DCHECK(driver != nullptr);
342 if (dex_to_dex_compilation_level != DexToDexCompilationLevel::kDontDexToDexCompile) {
Mathieu Chartier736b5602015-09-02 14:54:11 -0700343 ScopedObjectAccess soa(Thread::Current());
344 StackHandleScope<1> hs(soa.Self());
345 ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
Vladimir Markodf739842016-03-23 16:59:07 +0000346 art::DexCompilationUnit unit(
347 class_loader,
348 class_linker,
349 dex_file,
350 code_item,
351 class_def_idx,
352 method_idx,
353 access_flags,
354 driver->GetVerifiedMethod(&dex_file, method_idx),
355 hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file)));
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700356 art::optimizer::DexCompiler dex_compiler(*driver, unit, dex_to_dex_compilation_level);
Sebastien Hertz75021222013-07-16 18:34:50 +0200357 dex_compiler.Compile();
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100358 if (dex_compiler.GetQuickenedInfo().empty()) {
359 // No need to create a CompiledMethod if there are no quickened opcodes.
360 return nullptr;
361 }
362
363 // Create a `CompiledMethod`, with the quickened information in the vmap table.
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700364 if (kIsDebugBuild) {
365 // Double check that the counts line up with the size of the quicken info.
366 size_t quicken_count = 0;
Mathieu Chartier0021feb2017-11-07 00:08:52 -0800367 for (const DexInstructionPcPair& pair : code_item->Instructions()) {
368 if (QuickenInfoTable::NeedsIndexForInstruction(&pair.Inst())) {
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700369 ++quicken_count;
370 }
371 }
372 CHECK_EQ(quicken_count, dex_compiler.GetQuickenedInfo().size());
373 }
374 std::vector<uint8_t> quicken_data;
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100375 for (QuickenedInfo info : dex_compiler.GetQuickenedInfo()) {
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700376 // Dex pc is not serialized, only used for checking the instructions. Since we access the
377 // array based on the index of the quickened instruction, the indexes must line up perfectly.
378 // The reader side uses the NeedsIndexForInstruction function too.
Mathieu Chartier1d2d4ff2017-09-23 16:11:06 -0700379 const Instruction& inst = code_item->InstructionAt(info.dex_pc);
380 CHECK(QuickenInfoTable::NeedsIndexForInstruction(&inst)) << inst.Opcode();
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700381 // Add the index.
382 quicken_data.push_back(static_cast<uint8_t>(info.dex_member_index >> 0));
383 quicken_data.push_back(static_cast<uint8_t>(info.dex_member_index >> 8));
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100384 }
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700385 InstructionSet instruction_set = driver->GetInstructionSet();
Vladimir Marko33bff252017-11-01 14:35:42 +0000386 if (instruction_set == InstructionSet::kThumb2) {
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100387 // Don't use the thumb2 instruction set to avoid the one off code delta.
Vladimir Marko33bff252017-11-01 14:35:42 +0000388 instruction_set = InstructionSet::kArm;
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100389 }
390 return CompiledMethod::SwapAllocCompiledMethod(
Andreas Gampe5eb0d382015-07-23 01:19:26 -0700391 driver,
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100392 instruction_set,
393 ArrayRef<const uint8_t>(), // no code
394 0,
395 0,
396 0,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700397 ArrayRef<const uint8_t>(), // method_info
Mathieu Chartierde4b08f2017-07-10 14:13:41 -0700398 ArrayRef<const uint8_t>(quicken_data), // vmap_table
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100399 ArrayRef<const uint8_t>(), // cfi data
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100400 ArrayRef<const linker::LinkerPatch>());
Sebastien Hertz75021222013-07-16 18:34:50 +0200401 }
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100402 return nullptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700403}
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100404
405} // namespace optimizer
406
407} // namespace art