blob: 7731e6e982e462ee024ada1a0b9471966d749923 [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
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
17#include "code_generator.h"
18
19#include "code_generator_arm.h"
20#include "code_generator_x86.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010021#include "code_generator_x86_64.h"
Yevgeny Roubane3ea8382014-08-08 16:29:38 +070022#include "compiled_method.h"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000023#include "dex/verified_method.h"
24#include "driver/dex_compilation_unit.h"
25#include "gc_map_builder.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000026#include "leb128.h"
27#include "mapping_table.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000028#include "utils/assembler.h"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000029#include "verifier/dex_gc_map.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000030#include "vmap_table.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000031
32namespace art {
33
Nicolas Geoffray73e80c32014-07-22 17:47:56 +010034void CodeGenerator::CompileBaseline(CodeAllocator* allocator, bool is_leaf) {
Nicolas Geoffray804d0932014-05-02 08:46:00 +010035 const GrowableArray<HBasicBlock*>& blocks = GetGraph()->GetBlocks();
36 DCHECK(blocks.Get(0) == GetGraph()->GetEntryBlock());
37 DCHECK(GoesToNextBlock(GetGraph()->GetEntryBlock(), blocks.Get(1)));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010038 block_labels_.SetSize(blocks.Size());
39
40 DCHECK_EQ(frame_size_, kUninitializedFrameSize);
Nicolas Geoffray73e80c32014-07-22 17:47:56 +010041 if (!is_leaf) {
42 MarkNotLeaf();
43 }
Nicolas Geoffray39468442014-09-02 15:17:15 +010044 ComputeFrameSize(GetGraph()->GetNumberOfLocalVRegs()
45 + GetGraph()->GetNumberOfTemporaries()
46 + 1 /* filler */,
47 GetGraph()->GetMaximumNumberOfOutVRegs()
48 + 1 /* current method */);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +010049 GenerateFrameEntry();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010050
Nicolas Geoffray804d0932014-05-02 08:46:00 +010051 for (size_t i = 0, e = blocks.Size(); i < e; ++i) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010052 HBasicBlock* block = blocks.Get(i);
53 Bind(GetLabelOf(block));
54 HGraphVisitor* location_builder = GetLocationBuilder();
55 HGraphVisitor* instruction_visitor = GetInstructionVisitor();
56 for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
57 HInstruction* current = it.Current();
58 current->Accept(location_builder);
59 InitLocations(current);
60 current->Accept(instruction_visitor);
61 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000062 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +010063 GenerateSlowPaths();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010064
Nicolas Geoffray787c3072014-03-17 10:20:19 +000065 size_t code_size = GetAssembler()->CodeSize();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000066 uint8_t* buffer = allocator->Allocate(code_size);
67 MemoryRegion code(buffer, code_size);
Nicolas Geoffray787c3072014-03-17 10:20:19 +000068 GetAssembler()->FinalizeInstructions(code);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000069}
70
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010071void CodeGenerator::CompileOptimized(CodeAllocator* allocator) {
72 // The frame size has already been computed during register allocation.
73 DCHECK_NE(frame_size_, kUninitializedFrameSize);
74 const GrowableArray<HBasicBlock*>& blocks = GetGraph()->GetBlocks();
75 DCHECK(blocks.Get(0) == GetGraph()->GetEntryBlock());
76 DCHECK(GoesToNextBlock(GetGraph()->GetEntryBlock(), blocks.Get(1)));
77 block_labels_.SetSize(blocks.Size());
78
79 GenerateFrameEntry();
80 for (size_t i = 0, e = blocks.Size(); i < e; ++i) {
81 HBasicBlock* block = blocks.Get(i);
82 Bind(GetLabelOf(block));
83 HGraphVisitor* instruction_visitor = GetInstructionVisitor();
84 for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
85 HInstruction* current = it.Current();
86 current->Accept(instruction_visitor);
87 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000088 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +010089 GenerateSlowPaths();
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010090
91 size_t code_size = GetAssembler()->CodeSize();
92 uint8_t* buffer = allocator->Allocate(code_size);
93 MemoryRegion code(buffer, code_size);
94 GetAssembler()->FinalizeInstructions(code);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000095}
96
Nicolas Geoffraye5038322014-07-04 09:41:32 +010097void CodeGenerator::GenerateSlowPaths() {
98 for (size_t i = 0, e = slow_paths_.Size(); i < e; ++i) {
99 slow_paths_.Get(i)->EmitNativeCode(this);
100 }
101}
102
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100103size_t CodeGenerator::AllocateFreeRegisterInternal(
104 bool* blocked_registers, size_t number_of_registers) const {
105 for (size_t regno = 0; regno < number_of_registers; regno++) {
106 if (!blocked_registers[regno]) {
107 blocked_registers[regno] = true;
108 return regno;
109 }
110 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100111 return -1;
112}
113
Nicolas Geoffray39468442014-09-02 15:17:15 +0100114void CodeGenerator::ComputeFrameSize(size_t number_of_spill_slots, size_t number_of_out_slots) {
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100115 SetFrameSize(RoundUp(
116 number_of_spill_slots * kVRegSize
Nicolas Geoffray39468442014-09-02 15:17:15 +0100117 + number_of_out_slots * kVRegSize
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100118 + FrameEntrySpillSize(),
119 kStackAlignment));
120}
121
122Location CodeGenerator::GetTemporaryLocation(HTemporary* temp) const {
123 uint16_t number_of_locals = GetGraph()->GetNumberOfLocalVRegs();
124 // Use the temporary region (right below the dex registers).
125 int32_t slot = GetFrameSize() - FrameEntrySpillSize()
126 - kVRegSize // filler
127 - (number_of_locals * kVRegSize)
128 - ((1 + temp->GetIndex()) * kVRegSize);
129 return Location::StackSlot(slot);
130}
131
132int32_t CodeGenerator::GetStackSlot(HLocal* local) const {
133 uint16_t reg_number = local->GetRegNumber();
134 uint16_t number_of_locals = GetGraph()->GetNumberOfLocalVRegs();
135 if (reg_number >= number_of_locals) {
136 // Local is a parameter of the method. It is stored in the caller's frame.
137 return GetFrameSize() + kVRegSize // ART method
138 + (reg_number - number_of_locals) * kVRegSize;
139 } else {
140 // Local is a temporary in this method. It is stored in this method's frame.
141 return GetFrameSize() - FrameEntrySpillSize()
142 - kVRegSize // filler.
143 - (number_of_locals * kVRegSize)
144 + (reg_number * kVRegSize);
145 }
146}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100147
148void CodeGenerator::AllocateRegistersLocally(HInstruction* instruction) const {
149 LocationSummary* locations = instruction->GetLocations();
150 if (locations == nullptr) return;
151
152 for (size_t i = 0, e = GetNumberOfRegisters(); i < e; ++i) {
153 blocked_registers_[i] = false;
154 }
155
156 // Mark all fixed input, temp and output registers as used.
157 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
158 Location loc = locations->InAt(i);
159 if (loc.IsRegister()) {
160 // Check that a register is not specified twice in the summary.
161 DCHECK(!blocked_registers_[loc.GetEncoding()]);
162 blocked_registers_[loc.GetEncoding()] = true;
163 }
164 }
165
166 for (size_t i = 0, e = locations->GetTempCount(); i < e; ++i) {
167 Location loc = locations->GetTemp(i);
168 if (loc.IsRegister()) {
169 // Check that a register is not specified twice in the summary.
170 DCHECK(!blocked_registers_[loc.GetEncoding()]);
171 blocked_registers_[loc.GetEncoding()] = true;
172 }
173 }
174
175 SetupBlockedRegisters(blocked_registers_);
176
177 // Allocate all unallocated input locations.
178 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
179 Location loc = locations->InAt(i);
180 HInstruction* input = instruction->InputAt(i);
181 if (loc.IsUnallocated()) {
182 if (loc.GetPolicy() == Location::kRequiresRegister) {
183 loc = Location::RegisterLocation(
184 AllocateFreeRegister(input->GetType(), blocked_registers_));
185 } else {
186 DCHECK_EQ(loc.GetPolicy(), Location::kAny);
187 HLoadLocal* load = input->AsLoadLocal();
188 if (load != nullptr) {
189 loc = GetStackLocation(load);
190 } else {
191 loc = Location::RegisterLocation(
192 AllocateFreeRegister(input->GetType(), blocked_registers_));
193 }
194 }
195 locations->SetInAt(i, loc);
196 }
197 }
198
199 // Allocate all unallocated temp locations.
200 for (size_t i = 0, e = locations->GetTempCount(); i < e; ++i) {
201 Location loc = locations->GetTemp(i);
202 if (loc.IsUnallocated()) {
203 DCHECK_EQ(loc.GetPolicy(), Location::kRequiresRegister);
204 // TODO: Adjust handling of temps. We currently consider temps to use
205 // core registers. They may also use floating point registers at some point.
206 loc = Location::RegisterLocation(static_cast<ManagedRegister>(
207 AllocateFreeRegister(Primitive::kPrimInt, blocked_registers_)));
208 locations->SetTempAt(i, loc);
209 }
210 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100211 Location result_location = locations->Out();
212 if (result_location.IsUnallocated()) {
213 switch (result_location.GetPolicy()) {
214 case Location::kAny:
215 case Location::kRequiresRegister:
216 result_location = Location::RegisterLocation(
217 AllocateFreeRegister(instruction->GetType(), blocked_registers_));
218 break;
219 case Location::kSameAsFirstInput:
220 result_location = locations->InAt(0);
221 break;
222 }
223 locations->SetOut(result_location);
224 }
225}
226
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000227void CodeGenerator::InitLocations(HInstruction* instruction) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100228 if (instruction->GetLocations() == nullptr) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100229 if (instruction->IsTemporary()) {
230 HInstruction* previous = instruction->GetPrevious();
231 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
232 Move(previous, temp_location, instruction);
233 previous->GetLocations()->SetOut(temp_location);
234 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100235 return;
236 }
237 AllocateRegistersLocally(instruction);
238 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000239 Location location = instruction->GetLocations()->InAt(i);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000240 if (location.IsValid()) {
241 // Move the input to the desired location.
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100242 Move(instruction->InputAt(i), location, instruction);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000243 }
244 }
245}
246
247bool CodeGenerator::GoesToNextBlock(HBasicBlock* current, HBasicBlock* next) const {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000248 // We currently iterate over the block in insertion order.
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000249 return current->GetBlockId() + 1 == next->GetBlockId();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000250}
251
252Label* CodeGenerator::GetLabelOf(HBasicBlock* block) const {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000253 return block_labels_.GetRawStorage() + block->GetBlockId();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000254}
255
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000256CodeGenerator* CodeGenerator::Create(ArenaAllocator* allocator,
257 HGraph* graph,
258 InstructionSet instruction_set) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000259 switch (instruction_set) {
260 case kArm:
261 case kThumb2: {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000262 return new (allocator) arm::CodeGeneratorARM(graph);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000263 }
264 case kMips:
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000265 return nullptr;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000266 case kX86: {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000267 return new (allocator) x86::CodeGeneratorX86(graph);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000268 }
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700269 case kX86_64: {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100270 return new (allocator) x86_64::CodeGeneratorX86_64(graph);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700271 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000272 default:
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000273 return nullptr;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000274 }
275}
276
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000277void CodeGenerator::BuildNativeGCMap(
278 std::vector<uint8_t>* data, const DexCompilationUnit& dex_compilation_unit) const {
279 const std::vector<uint8_t>& gc_map_raw =
280 dex_compilation_unit.GetVerifiedMethod()->GetDexGcMap();
281 verifier::DexPcToReferenceMap dex_gc_map(&(gc_map_raw)[0]);
282
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000283 uint32_t max_native_offset = 0;
284 for (size_t i = 0; i < pc_infos_.Size(); i++) {
285 uint32_t native_offset = pc_infos_.Get(i).native_pc;
286 if (native_offset > max_native_offset) {
287 max_native_offset = native_offset;
288 }
289 }
290
291 GcMapBuilder builder(data, pc_infos_.Size(), max_native_offset, dex_gc_map.RegWidth());
292 for (size_t i = 0; i < pc_infos_.Size(); i++) {
293 struct PcInfo pc_info = pc_infos_.Get(i);
294 uint32_t native_offset = pc_info.native_pc;
295 uint32_t dex_pc = pc_info.dex_pc;
296 const uint8_t* references = dex_gc_map.FindBitMap(dex_pc, false);
297 CHECK(references != NULL) << "Missing ref for dex pc 0x" << std::hex << dex_pc;
298 builder.AddEntry(native_offset, references);
299 }
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000300}
301
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700302void CodeGenerator::BuildMappingTable(std::vector<uint8_t>* data, SrcMap* src_map) const {
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000303 uint32_t pc2dex_data_size = 0u;
304 uint32_t pc2dex_entries = pc_infos_.Size();
305 uint32_t pc2dex_offset = 0u;
306 int32_t pc2dex_dalvik_offset = 0;
307 uint32_t dex2pc_data_size = 0u;
308 uint32_t dex2pc_entries = 0u;
309
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700310 if (src_map != nullptr) {
311 src_map->reserve(pc2dex_entries);
312 }
313
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000314 // We currently only have pc2dex entries.
315 for (size_t i = 0; i < pc2dex_entries; i++) {
316 struct PcInfo pc_info = pc_infos_.Get(i);
317 pc2dex_data_size += UnsignedLeb128Size(pc_info.native_pc - pc2dex_offset);
318 pc2dex_data_size += SignedLeb128Size(pc_info.dex_pc - pc2dex_dalvik_offset);
319 pc2dex_offset = pc_info.native_pc;
320 pc2dex_dalvik_offset = pc_info.dex_pc;
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700321 if (src_map != nullptr) {
322 src_map->push_back(SrcMapElem({pc2dex_offset, pc2dex_dalvik_offset}));
323 }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000324 }
325
326 uint32_t total_entries = pc2dex_entries + dex2pc_entries;
327 uint32_t hdr_data_size = UnsignedLeb128Size(total_entries) + UnsignedLeb128Size(pc2dex_entries);
328 uint32_t data_size = hdr_data_size + pc2dex_data_size + dex2pc_data_size;
329 data->resize(data_size);
330
331 uint8_t* data_ptr = &(*data)[0];
332 uint8_t* write_pos = data_ptr;
333 write_pos = EncodeUnsignedLeb128(write_pos, total_entries);
334 write_pos = EncodeUnsignedLeb128(write_pos, pc2dex_entries);
335 DCHECK_EQ(static_cast<size_t>(write_pos - data_ptr), hdr_data_size);
336 uint8_t* write_pos2 = write_pos + pc2dex_data_size;
337
338 pc2dex_offset = 0u;
339 pc2dex_dalvik_offset = 0u;
340 for (size_t i = 0; i < pc2dex_entries; i++) {
341 struct PcInfo pc_info = pc_infos_.Get(i);
342 DCHECK(pc2dex_offset <= pc_info.native_pc);
343 write_pos = EncodeUnsignedLeb128(write_pos, pc_info.native_pc - pc2dex_offset);
344 write_pos = EncodeSignedLeb128(write_pos, pc_info.dex_pc - pc2dex_dalvik_offset);
345 pc2dex_offset = pc_info.native_pc;
346 pc2dex_dalvik_offset = pc_info.dex_pc;
347 }
348 DCHECK_EQ(static_cast<size_t>(write_pos - data_ptr), hdr_data_size + pc2dex_data_size);
349 DCHECK_EQ(static_cast<size_t>(write_pos2 - data_ptr), data_size);
350
351 if (kIsDebugBuild) {
352 // Verify the encoded table holds the expected data.
353 MappingTable table(data_ptr);
354 CHECK_EQ(table.TotalSize(), total_entries);
355 CHECK_EQ(table.PcToDexSize(), pc2dex_entries);
356 auto it = table.PcToDexBegin();
357 auto it2 = table.DexToPcBegin();
358 for (size_t i = 0; i < pc2dex_entries; i++) {
359 struct PcInfo pc_info = pc_infos_.Get(i);
360 CHECK_EQ(pc_info.native_pc, it.NativePcOffset());
361 CHECK_EQ(pc_info.dex_pc, it.DexPc());
362 ++it;
363 }
364 CHECK(it == table.PcToDexEnd());
365 CHECK(it2 == table.DexToPcEnd());
366 }
367}
368
369void CodeGenerator::BuildVMapTable(std::vector<uint8_t>* data) const {
370 Leb128EncodingVector vmap_encoder;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100371 // We currently don't use callee-saved registers.
372 size_t size = 0 + 1 /* marker */ + 0;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000373 vmap_encoder.Reserve(size + 1u); // All values are likely to be one byte in ULEB128 (<128).
374 vmap_encoder.PushBackUnsigned(size);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000375 vmap_encoder.PushBackUnsigned(VmapTable::kAdjustedFpMarker);
376
377 *data = vmap_encoder.GetData();
378}
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000379
Nicolas Geoffray39468442014-09-02 15:17:15 +0100380void CodeGenerator::BuildStackMaps(std::vector<uint8_t>* data) {
381 uint32_t size = stack_map_stream_.ComputeNeededSize();
382 data->resize(size);
383 MemoryRegion region(data->data(), size);
384 stack_map_stream_.FillIn(region);
385}
386
387void CodeGenerator::RecordPcInfo(HInstruction* instruction, uint32_t dex_pc) {
388 // Collect PC infos for the mapping table.
389 struct PcInfo pc_info;
390 pc_info.dex_pc = dex_pc;
391 pc_info.native_pc = GetAssembler()->CodeSize();
392 pc_infos_.Add(pc_info);
393
394 // Populate stack map information.
395
396 if (instruction == nullptr) {
397 // For stack overflow checks.
398 stack_map_stream_.AddStackMapEntry(dex_pc, pc_info.native_pc, 0, 0, 0, 0);
399 return;
400 }
401
402 LocationSummary* locations = instruction->GetLocations();
403 HEnvironment* environment = instruction->GetEnvironment();
404
405 size_t environment_size = instruction->EnvironmentSize();
406
407 size_t register_mask = 0;
408 size_t inlining_depth = 0;
409 stack_map_stream_.AddStackMapEntry(
410 dex_pc, pc_info.native_pc, register_mask,
411 locations->GetStackMask(), environment_size, inlining_depth);
412
413 // Walk over the environment, and record the location of dex registers.
414 for (size_t i = 0; i < environment_size; ++i) {
415 HInstruction* current = environment->GetInstructionAt(i);
416 if (current == nullptr) {
417 stack_map_stream_.AddDexRegisterEntry(DexRegisterMap::kNone, 0);
418 continue;
419 }
420
421 Location location = locations->GetEnvironmentAt(i);
422 switch (location.GetKind()) {
423 case Location::kConstant: {
424 DCHECK(current == location.GetConstant());
425 if (current->IsLongConstant()) {
426 int64_t value = current->AsLongConstant()->GetValue();
427 stack_map_stream_.AddDexRegisterEntry(DexRegisterMap::kConstant, Low32Bits(value));
428 stack_map_stream_.AddDexRegisterEntry(DexRegisterMap::kConstant, High32Bits(value));
429 ++i;
430 DCHECK_LT(i, environment_size);
431 } else {
432 DCHECK(current->IsIntConstant());
433 int32_t value = current->AsIntConstant()->GetValue();
434 stack_map_stream_.AddDexRegisterEntry(DexRegisterMap::kConstant, value);
435 }
436 break;
437 }
438
439 case Location::kStackSlot: {
440 stack_map_stream_.AddDexRegisterEntry(DexRegisterMap::kInStack, location.GetStackIndex());
441 break;
442 }
443
444 case Location::kDoubleStackSlot: {
445 stack_map_stream_.AddDexRegisterEntry(DexRegisterMap::kInStack, location.GetStackIndex());
446 stack_map_stream_.AddDexRegisterEntry(DexRegisterMap::kInStack,
447 location.GetHighStackIndex(kVRegSize));
448 ++i;
449 DCHECK_LT(i, environment_size);
450 break;
451 }
452
453 case Location::kRegister : {
454 int id = location.reg().RegId();
455 stack_map_stream_.AddDexRegisterEntry(DexRegisterMap::kInRegister, id);
456 if (current->GetType() == Primitive::kPrimDouble
457 || current->GetType() == Primitive::kPrimLong) {
458 stack_map_stream_.AddDexRegisterEntry(DexRegisterMap::kInRegister, id);
459 ++i;
460 DCHECK_LT(i, environment_size);
461 }
462 break;
463 }
464
465 default:
466 LOG(FATAL) << "Unexpected kind " << location.GetKind();
467 }
468 }
469}
470
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000471} // namespace art