blob: b4468157706edfca4b0efbcdd5fb90d444020cd6 [file] [log] [blame]
Calin Juravlec416d332015-04-23 16:01:43 +01001/*
2 * Copyright (C) 2015 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 */
Calin Juravlec416d332015-04-23 16:01:43 +010016#include "stack_map_stream.h"
17
18namespace art {
19
Calin Juravle4f46ac52015-04-23 18:47:21 +010020void StackMapStream::BeginStackMapEntry(uint32_t dex_pc,
21 uint32_t native_pc_offset,
22 uint32_t register_mask,
23 BitVector* sp_mask,
24 uint32_t num_dex_registers,
25 uint8_t inlining_depth) {
26 DCHECK_EQ(0u, current_entry_.dex_pc) << "EndStackMapEntry not called after BeginStackMapEntry";
27 current_entry_.dex_pc = dex_pc;
28 current_entry_.native_pc_offset = native_pc_offset;
29 current_entry_.register_mask = register_mask;
30 current_entry_.sp_mask = sp_mask;
31 current_entry_.num_dex_registers = num_dex_registers;
32 current_entry_.inlining_depth = inlining_depth;
33 current_entry_.dex_register_locations_start_index = dex_register_locations_.Size();
34 current_entry_.inline_infos_start_index = inline_infos_.Size();
35 current_entry_.dex_register_map_hash = 0;
36 current_entry_.same_dex_register_map_as_ = kNoSameDexMapFound;
Calin Juravlec416d332015-04-23 16:01:43 +010037 if (num_dex_registers != 0) {
Calin Juravle4f46ac52015-04-23 18:47:21 +010038 current_entry_.live_dex_registers_mask =
Calin Juravlec416d332015-04-23 16:01:43 +010039 new (allocator_) ArenaBitVector(allocator_, num_dex_registers, true);
40 } else {
Calin Juravle4f46ac52015-04-23 18:47:21 +010041 current_entry_.live_dex_registers_mask = nullptr;
Calin Juravlec416d332015-04-23 16:01:43 +010042 }
Calin Juravlec416d332015-04-23 16:01:43 +010043
44 if (sp_mask != nullptr) {
45 stack_mask_max_ = std::max(stack_mask_max_, sp_mask->GetHighestBitSet());
46 }
47 if (inlining_depth > 0) {
48 number_of_stack_maps_with_inline_info_++;
49 }
50
51 dex_pc_max_ = std::max(dex_pc_max_, dex_pc);
52 native_pc_offset_max_ = std::max(native_pc_offset_max_, native_pc_offset);
53 register_mask_max_ = std::max(register_mask_max_, register_mask);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010054 current_dex_register_ = 0;
Calin Juravlec416d332015-04-23 16:01:43 +010055}
56
Calin Juravle4f46ac52015-04-23 18:47:21 +010057void StackMapStream::EndStackMapEntry() {
58 current_entry_.same_dex_register_map_as_ = FindEntryWithTheSameDexMap();
59 stack_maps_.Add(current_entry_);
60 current_entry_ = StackMapEntry();
61}
62
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010063void StackMapStream::AddDexRegisterEntry(DexRegisterLocation::Kind kind, int32_t value) {
Calin Juravlec416d332015-04-23 16:01:43 +010064 if (kind != DexRegisterLocation::Kind::kNone) {
65 // Ensure we only use non-compressed location kind at this stage.
66 DCHECK(DexRegisterLocation::IsShortLocationKind(kind))
67 << DexRegisterLocation::PrettyDescriptor(kind);
68 DexRegisterLocation location(kind, value);
69
70 // Look for Dex register `location` in the location catalog (using the
71 // companion hash map of locations to indices). Use its index if it
72 // is already in the location catalog. If not, insert it (in the
73 // location catalog and the hash map) and use the newly created index.
74 auto it = location_catalog_entries_indices_.Find(location);
75 if (it != location_catalog_entries_indices_.end()) {
76 // Retrieve the index from the hash map.
77 dex_register_locations_.Add(it->second);
78 } else {
79 // Create a new entry in the location catalog and the hash map.
80 size_t index = location_catalog_entries_.Size();
81 location_catalog_entries_.Add(location);
82 dex_register_locations_.Add(index);
83 location_catalog_entries_indices_.Insert(std::make_pair(location, index));
84 }
85
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010086 if (in_inline_frame_) {
87 // TODO: Support sharing DexRegisterMap across InlineInfo.
88 DCHECK_LT(current_dex_register_, current_inline_info_.num_dex_registers);
89 current_inline_info_.live_dex_registers_mask->SetBit(current_dex_register_);
90 } else {
91 DCHECK_LT(current_dex_register_, current_entry_.num_dex_registers);
92 current_entry_.live_dex_registers_mask->SetBit(current_dex_register_);
93 current_entry_.dex_register_map_hash += (1 <<
94 (current_dex_register_ % (sizeof(current_entry_.dex_register_map_hash) * kBitsPerByte)));
95 current_entry_.dex_register_map_hash += static_cast<uint32_t>(value);
96 current_entry_.dex_register_map_hash += static_cast<uint32_t>(kind);
97 }
Calin Juravlec416d332015-04-23 16:01:43 +010098 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010099 current_dex_register_++;
Calin Juravlec416d332015-04-23 16:01:43 +0100100}
101
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100102void StackMapStream::BeginInlineInfoEntry(uint32_t method_index,
103 uint32_t dex_pc,
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100104 InvokeType invoke_type,
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100105 uint32_t num_dex_registers) {
106 DCHECK(!in_inline_frame_);
107 in_inline_frame_ = true;
108 current_inline_info_.method_index = method_index;
109 current_inline_info_.dex_pc = dex_pc;
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100110 current_inline_info_.invoke_type = invoke_type;
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100111 current_inline_info_.num_dex_registers = num_dex_registers;
112 current_inline_info_.dex_register_locations_start_index = dex_register_locations_.Size();
113 if (num_dex_registers != 0) {
114 current_inline_info_.live_dex_registers_mask =
115 new (allocator_) ArenaBitVector(allocator_, num_dex_registers, true);
116 } else {
117 current_inline_info_.live_dex_registers_mask = nullptr;
118 }
119 current_dex_register_ = 0;
120}
121
122void StackMapStream::EndInlineInfoEntry() {
123 DCHECK(in_inline_frame_);
124 DCHECK_EQ(current_dex_register_, current_inline_info_.num_dex_registers)
125 << "Inline information contains less registers than expected";
126 in_inline_frame_ = false;
127 inline_infos_.Add(current_inline_info_);
128 current_inline_info_ = InlineInfoEntry();
Calin Juravlec416d332015-04-23 16:01:43 +0100129}
130
Calin Juravle4f46ac52015-04-23 18:47:21 +0100131size_t StackMapStream::PrepareForFillIn() {
132 int stack_mask_number_of_bits = stack_mask_max_ + 1; // Need room for max element too.
133 stack_mask_size_ = RoundUp(stack_mask_number_of_bits, kBitsPerByte) / kBitsPerByte;
134 inline_info_size_ = ComputeInlineInfoSize();
135 dex_register_maps_size_ = ComputeDexRegisterMapsSize();
136 stack_maps_size_ = stack_maps_.Size()
137 * StackMap::ComputeStackMapSize(stack_mask_size_,
138 inline_info_size_,
139 dex_register_maps_size_,
140 dex_pc_max_,
141 native_pc_offset_max_,
142 register_mask_max_);
143 dex_register_location_catalog_size_ = ComputeDexRegisterLocationCatalogSize();
144
Calin Juravlec416d332015-04-23 16:01:43 +0100145 // Note: use RoundUp to word-size here if you want CodeInfo objects to be word aligned.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100146 needed_size_ = CodeInfo::kFixedSize
147 + dex_register_location_catalog_size_
148 + stack_maps_size_
149 + dex_register_maps_size_
150 + inline_info_size_;
Calin Juravlec416d332015-04-23 16:01:43 +0100151
Calin Juravle4f46ac52015-04-23 18:47:21 +0100152 dex_register_location_catalog_start_ = CodeInfo::kFixedSize;
153 stack_maps_start_ = dex_register_location_catalog_start_ + dex_register_location_catalog_size_;
154 dex_register_maps_start_ = stack_maps_start_ + stack_maps_size_;
155 inline_infos_start_ = dex_register_maps_start_ + dex_register_maps_size_;
Calin Juravlec416d332015-04-23 16:01:43 +0100156
Calin Juravle4f46ac52015-04-23 18:47:21 +0100157 return needed_size_;
Calin Juravlec416d332015-04-23 16:01:43 +0100158}
159
160size_t StackMapStream::ComputeDexRegisterLocationCatalogSize() const {
161 size_t size = DexRegisterLocationCatalog::kFixedSize;
162 for (size_t location_catalog_entry_index = 0;
163 location_catalog_entry_index < location_catalog_entries_.Size();
164 ++location_catalog_entry_index) {
165 DexRegisterLocation dex_register_location =
166 location_catalog_entries_.Get(location_catalog_entry_index);
167 size += DexRegisterLocationCatalog::EntrySize(dex_register_location);
168 }
169 return size;
170}
171
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100172size_t StackMapStream::ComputeDexRegisterMapSize(uint32_t num_dex_registers,
173 const BitVector& live_dex_registers_mask) const {
Calin Juravlec416d332015-04-23 16:01:43 +0100174 // Size of the map in bytes.
175 size_t size = DexRegisterMap::kFixedSize;
176 // Add the live bit mask for the Dex register liveness.
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100177 size += DexRegisterMap::GetLiveBitMaskSize(num_dex_registers);
Calin Juravlec416d332015-04-23 16:01:43 +0100178 // Compute the size of the set of live Dex register entries.
179 size_t number_of_live_dex_registers = 0;
180 for (size_t dex_register_number = 0;
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100181 dex_register_number < num_dex_registers;
Calin Juravlec416d332015-04-23 16:01:43 +0100182 ++dex_register_number) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100183 if (live_dex_registers_mask.IsBitSet(dex_register_number)) {
Calin Juravlec416d332015-04-23 16:01:43 +0100184 ++number_of_live_dex_registers;
185 }
186 }
187 size_t map_entries_size_in_bits =
188 DexRegisterMap::SingleEntrySizeInBits(location_catalog_entries_.Size())
189 * number_of_live_dex_registers;
190 size_t map_entries_size_in_bytes =
191 RoundUp(map_entries_size_in_bits, kBitsPerByte) / kBitsPerByte;
192 size += map_entries_size_in_bytes;
193 return size;
194}
195
Calin Juravle4f46ac52015-04-23 18:47:21 +0100196size_t StackMapStream::ComputeDexRegisterMapsSize() const {
Calin Juravlec416d332015-04-23 16:01:43 +0100197 size_t size = 0;
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100198 size_t inline_info_index = 0;
Calin Juravlec416d332015-04-23 16:01:43 +0100199 for (size_t i = 0; i < stack_maps_.Size(); ++i) {
Calin Juravle4f46ac52015-04-23 18:47:21 +0100200 StackMapEntry entry = stack_maps_.Get(i);
201 if (entry.same_dex_register_map_as_ == kNoSameDexMapFound) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100202 size += ComputeDexRegisterMapSize(entry.num_dex_registers, *entry.live_dex_registers_mask);
203 } else {
Calin Juravlec416d332015-04-23 16:01:43 +0100204 // Entries with the same dex map will have the same offset.
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100205 }
206 for (size_t j = 0; j < entry.inlining_depth; ++j) {
207 InlineInfoEntry inline_entry = inline_infos_.Get(inline_info_index++);
208 size += ComputeDexRegisterMapSize(inline_entry.num_dex_registers,
209 *inline_entry.live_dex_registers_mask);
Calin Juravlec416d332015-04-23 16:01:43 +0100210 }
211 }
212 return size;
213}
214
215size_t StackMapStream::ComputeInlineInfoSize() const {
216 return inline_infos_.Size() * InlineInfo::SingleEntrySize()
217 // For encoding the depth.
218 + (number_of_stack_maps_with_inline_info_ * InlineInfo::kFixedSize);
219}
220
Calin Juravlec416d332015-04-23 16:01:43 +0100221void StackMapStream::FillIn(MemoryRegion region) {
Calin Juravle4f46ac52015-04-23 18:47:21 +0100222 DCHECK_EQ(0u, current_entry_.dex_pc) << "EndStackMapEntry not called after BeginStackMapEntry";
223 DCHECK_NE(0u, needed_size_) << "PrepareForFillIn not called before FillIn";
224
Calin Juravlec416d332015-04-23 16:01:43 +0100225 CodeInfo code_info(region);
Calin Juravle4f46ac52015-04-23 18:47:21 +0100226 DCHECK_EQ(region.size(), needed_size_);
Calin Juravlec416d332015-04-23 16:01:43 +0100227 code_info.SetOverallSize(region.size());
228
Calin Juravlec416d332015-04-23 16:01:43 +0100229 MemoryRegion dex_register_locations_region = region.Subregion(
Calin Juravle4f46ac52015-04-23 18:47:21 +0100230 dex_register_maps_start_, dex_register_maps_size_);
Calin Juravlec416d332015-04-23 16:01:43 +0100231
232 MemoryRegion inline_infos_region = region.Subregion(
Calin Juravle4f46ac52015-04-23 18:47:21 +0100233 inline_infos_start_, inline_info_size_);
Calin Juravlec416d332015-04-23 16:01:43 +0100234
Calin Juravle4f46ac52015-04-23 18:47:21 +0100235 code_info.SetEncoding(inline_info_size_,
236 dex_register_maps_size_,
Calin Juravlec416d332015-04-23 16:01:43 +0100237 dex_pc_max_,
238 native_pc_offset_max_,
239 register_mask_max_);
240 code_info.SetNumberOfStackMaps(stack_maps_.Size());
Calin Juravle4f46ac52015-04-23 18:47:21 +0100241 code_info.SetStackMaskSize(stack_mask_size_);
242 DCHECK_EQ(code_info.GetStackMapsSize(), stack_maps_size_);
Calin Juravlec416d332015-04-23 16:01:43 +0100243
244 // Set the Dex register location catalog.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100245 code_info.SetNumberOfDexRegisterLocationCatalogEntries(location_catalog_entries_.Size());
Calin Juravlec416d332015-04-23 16:01:43 +0100246 MemoryRegion dex_register_location_catalog_region = region.Subregion(
Calin Juravle4f46ac52015-04-23 18:47:21 +0100247 dex_register_location_catalog_start_, dex_register_location_catalog_size_);
Calin Juravlec416d332015-04-23 16:01:43 +0100248 DexRegisterLocationCatalog dex_register_location_catalog(dex_register_location_catalog_region);
249 // Offset in `dex_register_location_catalog` where to store the next
250 // register location.
251 size_t location_catalog_offset = DexRegisterLocationCatalog::kFixedSize;
252 for (size_t i = 0, e = location_catalog_entries_.Size(); i < e; ++i) {
253 DexRegisterLocation dex_register_location = location_catalog_entries_.Get(i);
254 dex_register_location_catalog.SetRegisterInfo(location_catalog_offset, dex_register_location);
255 location_catalog_offset += DexRegisterLocationCatalog::EntrySize(dex_register_location);
256 }
257 // Ensure we reached the end of the Dex registers location_catalog.
258 DCHECK_EQ(location_catalog_offset, dex_register_location_catalog_region.size());
259
260 uintptr_t next_dex_register_map_offset = 0;
261 uintptr_t next_inline_info_offset = 0;
262 for (size_t i = 0, e = stack_maps_.Size(); i < e; ++i) {
263 StackMap stack_map = code_info.GetStackMapAt(i);
264 StackMapEntry entry = stack_maps_.Get(i);
265
266 stack_map.SetDexPc(code_info, entry.dex_pc);
267 stack_map.SetNativePcOffset(code_info, entry.native_pc_offset);
268 stack_map.SetRegisterMask(code_info, entry.register_mask);
269 if (entry.sp_mask != nullptr) {
270 stack_map.SetStackMask(code_info, *entry.sp_mask);
271 }
272
273 if (entry.num_dex_registers == 0) {
274 // No dex map available.
275 stack_map.SetDexRegisterMapOffset(code_info, StackMap::kNoDexRegisterMap);
276 } else {
277 // Search for an entry with the same dex map.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100278 if (entry.same_dex_register_map_as_ != kNoSameDexMapFound) {
Calin Juravlec416d332015-04-23 16:01:43 +0100279 // If we have a hit reuse the offset.
280 stack_map.SetDexRegisterMapOffset(code_info,
Calin Juravle4f46ac52015-04-23 18:47:21 +0100281 code_info.GetStackMapAt(entry.same_dex_register_map_as_)
282 .GetDexRegisterMapOffset(code_info));
Calin Juravlec416d332015-04-23 16:01:43 +0100283 } else {
284 // New dex registers maps should be added to the stack map.
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100285 MemoryRegion register_region = dex_register_locations_region.Subregion(
286 next_dex_register_map_offset,
287 ComputeDexRegisterMapSize(entry.num_dex_registers, *entry.live_dex_registers_mask));
Calin Juravlec416d332015-04-23 16:01:43 +0100288 next_dex_register_map_offset += register_region.size();
289 DexRegisterMap dex_register_map(register_region);
290 stack_map.SetDexRegisterMapOffset(
291 code_info, register_region.start() - dex_register_locations_region.start());
292
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100293 // Set the dex register location.
294 FillInDexRegisterMap(dex_register_map,
295 entry.num_dex_registers,
296 *entry.live_dex_registers_mask,
297 entry.dex_register_locations_start_index);
Calin Juravlec416d332015-04-23 16:01:43 +0100298 }
299 }
300
301 // Set the inlining info.
302 if (entry.inlining_depth != 0) {
303 MemoryRegion inline_region = inline_infos_region.Subregion(
304 next_inline_info_offset,
305 InlineInfo::kFixedSize + entry.inlining_depth * InlineInfo::SingleEntrySize());
306 next_inline_info_offset += inline_region.size();
307 InlineInfo inline_info(inline_region);
308
309 // Currently relative to the dex register map.
310 stack_map.SetInlineDescriptorOffset(
311 code_info, inline_region.start() - dex_register_locations_region.start());
312
313 inline_info.SetDepth(entry.inlining_depth);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100314 for (size_t depth = 0; depth < entry.inlining_depth; ++depth) {
315 InlineInfoEntry inline_entry = inline_infos_.Get(depth + entry.inline_infos_start_index);
316 inline_info.SetMethodIndexAtDepth(depth, inline_entry.method_index);
317 inline_info.SetDexPcAtDepth(depth, inline_entry.dex_pc);
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100318 inline_info.SetInvokeTypeAtDepth(depth, inline_entry.invoke_type);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100319 if (inline_entry.num_dex_registers == 0) {
320 // No dex map available.
321 inline_info.SetDexRegisterMapOffsetAtDepth(depth, StackMap::kNoDexRegisterMap);
322 DCHECK(inline_entry.live_dex_registers_mask == nullptr);
323 } else {
324 MemoryRegion register_region = dex_register_locations_region.Subregion(
325 next_dex_register_map_offset,
326 ComputeDexRegisterMapSize(inline_entry.num_dex_registers,
327 *inline_entry.live_dex_registers_mask));
328 next_dex_register_map_offset += register_region.size();
329 DexRegisterMap dex_register_map(register_region);
330 inline_info.SetDexRegisterMapOffsetAtDepth(
331 depth, register_region.start() - dex_register_locations_region.start());
332
333 FillInDexRegisterMap(dex_register_map,
334 inline_entry.num_dex_registers,
335 *inline_entry.live_dex_registers_mask,
336 inline_entry.dex_register_locations_start_index);
337 }
Calin Juravlec416d332015-04-23 16:01:43 +0100338 }
339 } else {
Calin Juravle4f46ac52015-04-23 18:47:21 +0100340 if (inline_info_size_ != 0) {
Calin Juravlec416d332015-04-23 16:01:43 +0100341 stack_map.SetInlineDescriptorOffset(code_info, StackMap::kNoInlineInfo);
342 }
343 }
344 }
345}
346
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100347void StackMapStream::FillInDexRegisterMap(DexRegisterMap dex_register_map,
348 uint32_t num_dex_registers,
349 const BitVector& live_dex_registers_mask,
350 uint32_t start_index_in_dex_register_locations) const {
351 dex_register_map.SetLiveBitMask(num_dex_registers, live_dex_registers_mask);
352 // Set the dex register location mapping data.
353 for (size_t dex_register_number = 0, index_in_dex_register_locations = 0;
354 dex_register_number < num_dex_registers;
355 ++dex_register_number) {
356 if (live_dex_registers_mask.IsBitSet(dex_register_number)) {
357 size_t location_catalog_entry_index = dex_register_locations_.Get(
358 start_index_in_dex_register_locations + index_in_dex_register_locations);
359 dex_register_map.SetLocationCatalogEntryIndex(
360 index_in_dex_register_locations,
361 location_catalog_entry_index,
362 num_dex_registers,
363 location_catalog_entries_.Size());
364 ++index_in_dex_register_locations;
365 }
366 }
367}
368
Calin Juravle4f46ac52015-04-23 18:47:21 +0100369size_t StackMapStream::FindEntryWithTheSameDexMap() {
370 size_t current_entry_index = stack_maps_.Size();
371 auto entries_it = dex_map_hash_to_stack_map_indices_.find(current_entry_.dex_register_map_hash);
Calin Juravlec416d332015-04-23 16:01:43 +0100372 if (entries_it == dex_map_hash_to_stack_map_indices_.end()) {
373 // We don't have a perfect hash functions so we need a list to collect all stack maps
374 // which might have the same dex register map.
375 GrowableArray<uint32_t> stack_map_indices(allocator_, 1);
Calin Juravle4f46ac52015-04-23 18:47:21 +0100376 stack_map_indices.Add(current_entry_index);
377 dex_map_hash_to_stack_map_indices_.Put(current_entry_.dex_register_map_hash, stack_map_indices);
Calin Juravlec416d332015-04-23 16:01:43 +0100378 return kNoSameDexMapFound;
379 }
380
Calin Juravle4f46ac52015-04-23 18:47:21 +0100381 // We might have collisions, so we need to check whether or not we really have a match.
Calin Juravlec416d332015-04-23 16:01:43 +0100382 for (size_t i = 0; i < entries_it->second.Size(); i++) {
383 size_t test_entry_index = entries_it->second.Get(i);
Calin Juravle4f46ac52015-04-23 18:47:21 +0100384 if (HaveTheSameDexMaps(stack_maps_.Get(test_entry_index), current_entry_)) {
385 return test_entry_index;
Calin Juravlec416d332015-04-23 16:01:43 +0100386 }
387 }
Calin Juravle4f46ac52015-04-23 18:47:21 +0100388 entries_it->second.Add(current_entry_index);
389 return kNoSameDexMapFound;
Calin Juravlec416d332015-04-23 16:01:43 +0100390}
391
392bool StackMapStream::HaveTheSameDexMaps(const StackMapEntry& a, const StackMapEntry& b) const {
393 if (a.live_dex_registers_mask == nullptr && b.live_dex_registers_mask == nullptr) {
394 return true;
395 }
396 if (a.live_dex_registers_mask == nullptr || b.live_dex_registers_mask == nullptr) {
397 return false;
398 }
399 if (a.num_dex_registers != b.num_dex_registers) {
400 return false;
401 }
402
403 int index_in_dex_register_locations = 0;
404 for (uint32_t i = 0; i < a.num_dex_registers; i++) {
405 if (a.live_dex_registers_mask->IsBitSet(i) != b.live_dex_registers_mask->IsBitSet(i)) {
406 return false;
407 }
408 if (a.live_dex_registers_mask->IsBitSet(i)) {
409 size_t a_loc = dex_register_locations_.Get(
410 a.dex_register_locations_start_index + index_in_dex_register_locations);
411 size_t b_loc = dex_register_locations_.Get(
412 b.dex_register_locations_start_index + index_in_dex_register_locations);
413 if (a_loc != b_loc) {
414 return false;
415 }
416 ++index_in_dex_register_locations;
417 }
418 }
419 return true;
420}
421
422} // namespace art