blob: 9bc80457a3c9858f099ce9f0fa5edf82d1a903d7 [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 */
Nicolas Geoffray5d37c152017-01-12 13:25:19 +000016
Calin Juravlec416d332015-04-23 16:01:43 +010017#include "stack_map_stream.h"
18
Andreas Gampe90b936d2017-01-31 08:58:55 -080019#include "art_method-inl.h"
David Srbecky45aa5982016-03-18 02:15:09 +000020#include "base/stl_util.h"
Andreas Gampee2abbc62017-09-15 11:59:26 -070021#include "dex_file_types.h"
Nicolas Geoffrayfbdfa6d2017-02-03 10:43:13 +000022#include "optimizing/optimizing_compiler.h"
Nicolas Geoffray5d37c152017-01-12 13:25:19 +000023#include "runtime.h"
24#include "scoped_thread_state_change-inl.h"
25
Calin Juravlec416d332015-04-23 16:01:43 +010026namespace art {
27
Calin Juravle4f46ac52015-04-23 18:47:21 +010028void StackMapStream::BeginStackMapEntry(uint32_t dex_pc,
29 uint32_t native_pc_offset,
30 uint32_t register_mask,
31 BitVector* sp_mask,
32 uint32_t num_dex_registers,
33 uint8_t inlining_depth) {
34 DCHECK_EQ(0u, current_entry_.dex_pc) << "EndStackMapEntry not called after BeginStackMapEntry";
Calin Juravleb5c46932015-10-06 17:09:49 +010035 DCHECK_NE(dex_pc, static_cast<uint32_t>(-1)) << "invalid dex_pc";
Calin Juravle4f46ac52015-04-23 18:47:21 +010036 current_entry_.dex_pc = dex_pc;
Mathieu Chartiera2f526f2017-01-19 14:48:48 -080037 current_entry_.native_pc_code_offset = CodeOffset::FromOffset(native_pc_offset, instruction_set_);
Calin Juravle4f46ac52015-04-23 18:47:21 +010038 current_entry_.register_mask = register_mask;
39 current_entry_.sp_mask = sp_mask;
Calin Juravle4f46ac52015-04-23 18:47:21 +010040 current_entry_.inlining_depth = inlining_depth;
Vladimir Marko225b6462015-09-28 12:17:40 +010041 current_entry_.inline_infos_start_index = inline_infos_.size();
David Srbecky45aa5982016-03-18 02:15:09 +000042 current_entry_.stack_mask_index = 0;
Andreas Gampee2abbc62017-09-15 11:59:26 -070043 current_entry_.dex_method_index = dex::kDexNoIndex;
Mathieu Chartier32289082017-02-09 15:57:37 -080044 current_entry_.dex_register_entry.num_dex_registers = num_dex_registers;
45 current_entry_.dex_register_entry.locations_start_index = dex_register_locations_.size();
Vladimir Marko174b2e22017-10-12 13:34:49 +010046 current_entry_.dex_register_entry.live_dex_registers_mask = nullptr;
47 if (num_dex_registers != 0u) {
48 current_entry_.dex_register_entry.live_dex_registers_mask =
49 ArenaBitVector::Create(allocator_, num_dex_registers, true, kArenaAllocStackMapStream);
50 current_entry_.dex_register_entry.live_dex_registers_mask->ClearAllBits();
51 }
Calin Juravlec416d332015-04-23 16:01:43 +010052 if (sp_mask != nullptr) {
53 stack_mask_max_ = std::max(stack_mask_max_, sp_mask->GetHighestBitSet());
54 }
55 if (inlining_depth > 0) {
56 number_of_stack_maps_with_inline_info_++;
57 }
58
59 dex_pc_max_ = std::max(dex_pc_max_, dex_pc);
Calin Juravlec416d332015-04-23 16:01:43 +010060 register_mask_max_ = std::max(register_mask_max_, register_mask);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010061 current_dex_register_ = 0;
Calin Juravlec416d332015-04-23 16:01:43 +010062}
63
Calin Juravle4f46ac52015-04-23 18:47:21 +010064void StackMapStream::EndStackMapEntry() {
Mathieu Chartier32289082017-02-09 15:57:37 -080065 current_entry_.dex_register_map_index = AddDexRegisterMapEntry(current_entry_.dex_register_entry);
Vladimir Marko225b6462015-09-28 12:17:40 +010066 stack_maps_.push_back(current_entry_);
Calin Juravle4f46ac52015-04-23 18:47:21 +010067 current_entry_ = StackMapEntry();
68}
69
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010070void StackMapStream::AddDexRegisterEntry(DexRegisterLocation::Kind kind, int32_t value) {
Calin Juravlec416d332015-04-23 16:01:43 +010071 if (kind != DexRegisterLocation::Kind::kNone) {
72 // Ensure we only use non-compressed location kind at this stage.
David Srbecky7dc11782016-02-25 13:23:56 +000073 DCHECK(DexRegisterLocation::IsShortLocationKind(kind)) << kind;
Calin Juravlec416d332015-04-23 16:01:43 +010074 DexRegisterLocation location(kind, value);
75
76 // Look for Dex register `location` in the location catalog (using the
77 // companion hash map of locations to indices). Use its index if it
78 // is already in the location catalog. If not, insert it (in the
79 // location catalog and the hash map) and use the newly created index.
80 auto it = location_catalog_entries_indices_.Find(location);
81 if (it != location_catalog_entries_indices_.end()) {
82 // Retrieve the index from the hash map.
Vladimir Marko225b6462015-09-28 12:17:40 +010083 dex_register_locations_.push_back(it->second);
Calin Juravlec416d332015-04-23 16:01:43 +010084 } else {
85 // Create a new entry in the location catalog and the hash map.
Vladimir Marko225b6462015-09-28 12:17:40 +010086 size_t index = location_catalog_entries_.size();
87 location_catalog_entries_.push_back(location);
88 dex_register_locations_.push_back(index);
Calin Juravlec416d332015-04-23 16:01:43 +010089 location_catalog_entries_indices_.Insert(std::make_pair(location, index));
90 }
Mathieu Chartier32289082017-02-09 15:57:37 -080091 DexRegisterMapEntry* const entry = in_inline_frame_
92 ? &current_inline_info_.dex_register_entry
93 : &current_entry_.dex_register_entry;
94 DCHECK_LT(current_dex_register_, entry->num_dex_registers);
95 entry->live_dex_registers_mask->SetBit(current_dex_register_);
96 entry->hash += (1 <<
97 (current_dex_register_ % (sizeof(DexRegisterMapEntry::hash) * kBitsPerByte)));
98 entry->hash += static_cast<uint32_t>(value);
99 entry->hash += static_cast<uint32_t>(kind);
Calin Juravlec416d332015-04-23 16:01:43 +0100100 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100101 current_dex_register_++;
Calin Juravlec416d332015-04-23 16:01:43 +0100102}
103
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800104void StackMapStream::AddInvoke(InvokeType invoke_type, uint32_t dex_method_index) {
105 current_entry_.invoke_type = invoke_type;
106 current_entry_.dex_method_index = dex_method_index;
107}
108
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000109void StackMapStream::BeginInlineInfoEntry(ArtMethod* method,
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100110 uint32_t dex_pc,
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000111 uint32_t num_dex_registers,
112 const DexFile* outer_dex_file) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100113 DCHECK(!in_inline_frame_);
114 in_inline_frame_ = true;
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000115 if (EncodeArtMethodInInlineInfo(method)) {
116 current_inline_info_.method = method;
117 } else {
118 if (dex_pc != static_cast<uint32_t>(-1) && kIsDebugBuild) {
119 ScopedObjectAccess soa(Thread::Current());
120 DCHECK(IsSameDexFile(*outer_dex_file, *method->GetDexFile()));
121 }
122 current_inline_info_.method_index = method->GetDexMethodIndexUnchecked();
123 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100124 current_inline_info_.dex_pc = dex_pc;
Mathieu Chartier32289082017-02-09 15:57:37 -0800125 current_inline_info_.dex_register_entry.num_dex_registers = num_dex_registers;
126 current_inline_info_.dex_register_entry.locations_start_index = dex_register_locations_.size();
Vladimir Marko174b2e22017-10-12 13:34:49 +0100127 current_inline_info_.dex_register_entry.live_dex_registers_mask = nullptr;
128 if (num_dex_registers != 0) {
129 current_inline_info_.dex_register_entry.live_dex_registers_mask =
130 ArenaBitVector::Create(allocator_, num_dex_registers, true, kArenaAllocStackMapStream);
131 current_inline_info_.dex_register_entry.live_dex_registers_mask->ClearAllBits();
132 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100133 current_dex_register_ = 0;
134}
135
136void StackMapStream::EndInlineInfoEntry() {
Mathieu Chartier32289082017-02-09 15:57:37 -0800137 current_inline_info_.dex_register_map_index =
138 AddDexRegisterMapEntry(current_inline_info_.dex_register_entry);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100139 DCHECK(in_inline_frame_);
Mathieu Chartier32289082017-02-09 15:57:37 -0800140 DCHECK_EQ(current_dex_register_, current_inline_info_.dex_register_entry.num_dex_registers)
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100141 << "Inline information contains less registers than expected";
142 in_inline_frame_ = false;
Vladimir Marko225b6462015-09-28 12:17:40 +0100143 inline_infos_.push_back(current_inline_info_);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100144 current_inline_info_ = InlineInfoEntry();
Calin Juravlec416d332015-04-23 16:01:43 +0100145}
146
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800147CodeOffset StackMapStream::ComputeMaxNativePcCodeOffset() const {
148 CodeOffset max_native_pc_offset;
Vladimir Marko225b6462015-09-28 12:17:40 +0100149 for (const StackMapEntry& entry : stack_maps_) {
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800150 max_native_pc_offset = std::max(max_native_pc_offset, entry.native_pc_code_offset);
Vladimir Markobd8c7252015-06-12 10:06:32 +0100151 }
152 return max_native_pc_offset;
153}
154
Calin Juravle4f46ac52015-04-23 18:47:21 +0100155size_t StackMapStream::PrepareForFillIn() {
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800156 CodeInfoEncoding encoding;
157 encoding.dex_register_map.num_entries = 0; // TODO: Remove this field.
158 encoding.dex_register_map.num_bytes = ComputeDexRegisterMapsSize();
159 encoding.location_catalog.num_entries = location_catalog_entries_.size();
160 encoding.location_catalog.num_bytes = ComputeDexRegisterLocationCatalogSize();
161 encoding.inline_info.num_entries = inline_infos_.size();
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700162 // Must be done before calling ComputeInlineInfoEncoding since ComputeInlineInfoEncoding requires
163 // dex_method_index_idx to be filled in.
164 PrepareMethodIndices();
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800165 ComputeInlineInfoEncoding(&encoding.inline_info.encoding,
166 encoding.dex_register_map.num_bytes);
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800167 CodeOffset max_native_pc_offset = ComputeMaxNativePcCodeOffset();
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800168 // Prepare the CodeInfo variable-sized encoding.
169 encoding.stack_mask.encoding.num_bits = stack_mask_max_ + 1; // Need room for max element too.
170 encoding.stack_mask.num_entries = PrepareStackMasks(encoding.stack_mask.encoding.num_bits);
171 encoding.register_mask.encoding.num_bits = MinimumBitsToStore(register_mask_max_);
172 encoding.register_mask.num_entries = PrepareRegisterMasks();
173 encoding.stack_map.num_entries = stack_maps_.size();
174 encoding.stack_map.encoding.SetFromSizes(
175 // The stack map contains compressed native PC offsets.
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800176 max_native_pc_offset.CompressedValue(),
177 dex_pc_max_,
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800178 encoding.dex_register_map.num_bytes,
179 encoding.inline_info.num_entries,
180 encoding.register_mask.num_entries,
181 encoding.stack_mask.num_entries);
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800182 ComputeInvokeInfoEncoding(&encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800183 DCHECK_EQ(code_info_encoding_.size(), 0u);
184 encoding.Compress(&code_info_encoding_);
185 encoding.ComputeTableOffsets();
186 // Compute table offsets so we can get the non header size.
187 DCHECK_EQ(encoding.HeaderSize(), code_info_encoding_.size());
188 needed_size_ = code_info_encoding_.size() + encoding.NonHeaderSize();
Calin Juravle4f46ac52015-04-23 18:47:21 +0100189 return needed_size_;
Calin Juravlec416d332015-04-23 16:01:43 +0100190}
191
192size_t StackMapStream::ComputeDexRegisterLocationCatalogSize() const {
193 size_t size = DexRegisterLocationCatalog::kFixedSize;
Vladimir Marko225b6462015-09-28 12:17:40 +0100194 for (const DexRegisterLocation& dex_register_location : location_catalog_entries_) {
Calin Juravlec416d332015-04-23 16:01:43 +0100195 size += DexRegisterLocationCatalog::EntrySize(dex_register_location);
196 }
197 return size;
198}
199
Mathieu Chartier32289082017-02-09 15:57:37 -0800200size_t StackMapStream::DexRegisterMapEntry::ComputeSize(size_t catalog_size) const {
Vladimir Marko225b6462015-09-28 12:17:40 +0100201 // For num_dex_registers == 0u live_dex_registers_mask may be null.
202 if (num_dex_registers == 0u) {
203 return 0u; // No register map will be emitted.
204 }
205 DCHECK(live_dex_registers_mask != nullptr);
206
Calin Juravlec416d332015-04-23 16:01:43 +0100207 // Size of the map in bytes.
208 size_t size = DexRegisterMap::kFixedSize;
209 // Add the live bit mask for the Dex register liveness.
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100210 size += DexRegisterMap::GetLiveBitMaskSize(num_dex_registers);
Calin Juravlec416d332015-04-23 16:01:43 +0100211 // Compute the size of the set of live Dex register entries.
Vladimir Marko225b6462015-09-28 12:17:40 +0100212 size_t number_of_live_dex_registers = live_dex_registers_mask->NumSetBits();
Calin Juravlec416d332015-04-23 16:01:43 +0100213 size_t map_entries_size_in_bits =
Mathieu Chartier32289082017-02-09 15:57:37 -0800214 DexRegisterMap::SingleEntrySizeInBits(catalog_size) * number_of_live_dex_registers;
Calin Juravlec416d332015-04-23 16:01:43 +0100215 size_t map_entries_size_in_bytes =
216 RoundUp(map_entries_size_in_bits, kBitsPerByte) / kBitsPerByte;
217 size += map_entries_size_in_bytes;
218 return size;
219}
220
Calin Juravle4f46ac52015-04-23 18:47:21 +0100221size_t StackMapStream::ComputeDexRegisterMapsSize() const {
Calin Juravlec416d332015-04-23 16:01:43 +0100222 size_t size = 0;
Mathieu Chartier32289082017-02-09 15:57:37 -0800223 for (const DexRegisterMapEntry& entry : dex_register_entries_) {
224 size += entry.ComputeSize(location_catalog_entries_.size());
Calin Juravlec416d332015-04-23 16:01:43 +0100225 }
226 return size;
227}
228
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800229void StackMapStream::ComputeInvokeInfoEncoding(CodeInfoEncoding* encoding) {
230 DCHECK(encoding != nullptr);
231 uint32_t native_pc_max = 0;
232 uint16_t method_index_max = 0;
233 size_t invoke_infos_count = 0;
234 size_t invoke_type_max = 0;
235 for (const StackMapEntry& entry : stack_maps_) {
Andreas Gampee2abbc62017-09-15 11:59:26 -0700236 if (entry.dex_method_index != dex::kDexNoIndex) {
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800237 native_pc_max = std::max(native_pc_max, entry.native_pc_code_offset.CompressedValue());
238 method_index_max = std::max(method_index_max, static_cast<uint16_t>(entry.dex_method_index));
239 invoke_type_max = std::max(invoke_type_max, static_cast<size_t>(entry.invoke_type));
240 ++invoke_infos_count;
241 }
242 }
243 encoding->invoke_info.num_entries = invoke_infos_count;
244 encoding->invoke_info.encoding.SetFromSizes(native_pc_max, invoke_type_max, method_index_max);
245}
246
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800247void StackMapStream::ComputeInlineInfoEncoding(InlineInfoEncoding* encoding,
248 size_t dex_register_maps_bytes) {
David Srbecky61b28a12016-02-25 21:55:03 +0000249 uint32_t method_index_max = 0;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700250 uint32_t dex_pc_max = dex::kDexNoIndex;
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000251 uint32_t extra_data_max = 0;
David Srbecky61b28a12016-02-25 21:55:03 +0000252
253 uint32_t inline_info_index = 0;
254 for (const StackMapEntry& entry : stack_maps_) {
255 for (size_t j = 0; j < entry.inlining_depth; ++j) {
256 InlineInfoEntry inline_entry = inline_infos_[inline_info_index++];
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000257 if (inline_entry.method == nullptr) {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700258 method_index_max = std::max(method_index_max, inline_entry.dex_method_index_idx);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000259 extra_data_max = std::max(extra_data_max, 1u);
260 } else {
261 method_index_max = std::max(
262 method_index_max, High32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
263 extra_data_max = std::max(
264 extra_data_max, Low32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
265 }
Andreas Gampee2abbc62017-09-15 11:59:26 -0700266 if (inline_entry.dex_pc != dex::kDexNoIndex &&
267 (dex_pc_max == dex::kDexNoIndex || dex_pc_max < inline_entry.dex_pc)) {
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100268 dex_pc_max = inline_entry.dex_pc;
269 }
David Srbecky61b28a12016-02-25 21:55:03 +0000270 }
271 }
272 DCHECK_EQ(inline_info_index, inline_infos_.size());
273
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800274 encoding->SetFromSizes(method_index_max, dex_pc_max, extra_data_max, dex_register_maps_bytes);
Calin Juravlec416d332015-04-23 16:01:43 +0100275}
276
Mathieu Chartier32289082017-02-09 15:57:37 -0800277size_t StackMapStream::MaybeCopyDexRegisterMap(DexRegisterMapEntry& entry,
278 size_t* current_offset,
279 MemoryRegion dex_register_locations_region) {
280 DCHECK(current_offset != nullptr);
281 if ((entry.num_dex_registers == 0) || (entry.live_dex_registers_mask->NumSetBits() == 0)) {
282 // No dex register map needed.
283 return StackMap::kNoDexRegisterMap;
284 }
285 if (entry.offset == DexRegisterMapEntry::kOffsetUnassigned) {
286 // Not already copied, need to copy and and assign an offset.
287 entry.offset = *current_offset;
288 const size_t entry_size = entry.ComputeSize(location_catalog_entries_.size());
289 DexRegisterMap dex_register_map(
290 dex_register_locations_region.Subregion(entry.offset, entry_size));
291 *current_offset += entry_size;
292 // Fill in the map since it was just added.
293 FillInDexRegisterMap(dex_register_map,
294 entry.num_dex_registers,
295 *entry.live_dex_registers_mask,
296 entry.locations_start_index);
297 }
298 return entry.offset;
299}
300
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700301void StackMapStream::FillInMethodInfo(MemoryRegion region) {
302 {
303 MethodInfo info(region.begin(), method_indices_.size());
304 for (size_t i = 0; i < method_indices_.size(); ++i) {
305 info.SetMethodIndex(i, method_indices_[i]);
306 }
307 }
308 if (kIsDebugBuild) {
309 // Check the data matches.
310 MethodInfo info(region.begin());
311 const size_t count = info.NumMethodIndices();
312 DCHECK_EQ(count, method_indices_.size());
313 for (size_t i = 0; i < count; ++i) {
314 DCHECK_EQ(info.GetMethodIndex(i), method_indices_[i]);
315 }
316 }
317}
318
319void StackMapStream::FillInCodeInfo(MemoryRegion region) {
Calin Juravle4f46ac52015-04-23 18:47:21 +0100320 DCHECK_EQ(0u, current_entry_.dex_pc) << "EndStackMapEntry not called after BeginStackMapEntry";
321 DCHECK_NE(0u, needed_size_) << "PrepareForFillIn not called before FillIn";
322
Calin Juravle4f46ac52015-04-23 18:47:21 +0100323 DCHECK_EQ(region.size(), needed_size_);
David Srbecky09ed0982016-02-12 21:58:43 +0000324
325 // Note that the memory region does not have to be zeroed when we JIT code
326 // because we do not use the arena allocator there.
327
328 // Write the CodeInfo header.
329 region.CopyFrom(0, MemoryRegion(code_info_encoding_.data(), code_info_encoding_.size()));
Calin Juravlec416d332015-04-23 16:01:43 +0100330
David Srbecky09ed0982016-02-12 21:58:43 +0000331 CodeInfo code_info(region);
332 CodeInfoEncoding encoding = code_info.ExtractEncoding();
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800333 DCHECK_EQ(encoding.stack_map.num_entries, stack_maps_.size());
334
335 MemoryRegion dex_register_locations_region = region.Subregion(
336 encoding.dex_register_map.byte_offset,
337 encoding.dex_register_map.num_bytes);
Calin Juravlec416d332015-04-23 16:01:43 +0100338
339 // Set the Dex register location catalog.
Calin Juravlec416d332015-04-23 16:01:43 +0100340 MemoryRegion dex_register_location_catalog_region = region.Subregion(
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800341 encoding.location_catalog.byte_offset,
342 encoding.location_catalog.num_bytes);
Calin Juravlec416d332015-04-23 16:01:43 +0100343 DexRegisterLocationCatalog dex_register_location_catalog(dex_register_location_catalog_region);
344 // Offset in `dex_register_location_catalog` where to store the next
345 // register location.
346 size_t location_catalog_offset = DexRegisterLocationCatalog::kFixedSize;
Vladimir Marko225b6462015-09-28 12:17:40 +0100347 for (DexRegisterLocation dex_register_location : location_catalog_entries_) {
Calin Juravlec416d332015-04-23 16:01:43 +0100348 dex_register_location_catalog.SetRegisterInfo(location_catalog_offset, dex_register_location);
349 location_catalog_offset += DexRegisterLocationCatalog::EntrySize(dex_register_location);
350 }
351 // Ensure we reached the end of the Dex registers location_catalog.
352 DCHECK_EQ(location_catalog_offset, dex_register_location_catalog_region.size());
353
Vladimir Markof6a35de2016-03-21 12:01:50 +0000354 ArenaBitVector empty_bitmask(allocator_, 0, /* expandable */ false, kArenaAllocStackMapStream);
Calin Juravlec416d332015-04-23 16:01:43 +0100355 uintptr_t next_dex_register_map_offset = 0;
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800356 uintptr_t next_inline_info_index = 0;
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800357 size_t invoke_info_idx = 0;
Vladimir Marko225b6462015-09-28 12:17:40 +0100358 for (size_t i = 0, e = stack_maps_.size(); i < e; ++i) {
David Srbecky09ed0982016-02-12 21:58:43 +0000359 StackMap stack_map = code_info.GetStackMapAt(i, encoding);
Vladimir Marko225b6462015-09-28 12:17:40 +0100360 StackMapEntry entry = stack_maps_[i];
Calin Juravlec416d332015-04-23 16:01:43 +0100361
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800362 stack_map.SetDexPc(encoding.stack_map.encoding, entry.dex_pc);
363 stack_map.SetNativePcCodeOffset(encoding.stack_map.encoding, entry.native_pc_code_offset);
364 stack_map.SetRegisterMaskIndex(encoding.stack_map.encoding, entry.register_mask_index);
365 stack_map.SetStackMaskIndex(encoding.stack_map.encoding, entry.stack_mask_index);
Calin Juravlec416d332015-04-23 16:01:43 +0100366
Mathieu Chartier32289082017-02-09 15:57:37 -0800367 size_t offset = MaybeCopyDexRegisterMap(dex_register_entries_[entry.dex_register_map_index],
368 &next_dex_register_map_offset,
369 dex_register_locations_region);
370 stack_map.SetDexRegisterMapOffset(encoding.stack_map.encoding, offset);
Calin Juravlec416d332015-04-23 16:01:43 +0100371
Andreas Gampee2abbc62017-09-15 11:59:26 -0700372 if (entry.dex_method_index != dex::kDexNoIndex) {
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800373 InvokeInfo invoke_info(code_info.GetInvokeInfo(encoding, invoke_info_idx));
374 invoke_info.SetNativePcCodeOffset(encoding.invoke_info.encoding, entry.native_pc_code_offset);
375 invoke_info.SetInvokeType(encoding.invoke_info.encoding, entry.invoke_type);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700376 invoke_info.SetMethodIndexIdx(encoding.invoke_info.encoding, entry.dex_method_index_idx);
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800377 ++invoke_info_idx;
378 }
379
Calin Juravlec416d332015-04-23 16:01:43 +0100380 // Set the inlining info.
381 if (entry.inlining_depth != 0) {
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800382 InlineInfo inline_info = code_info.GetInlineInfo(next_inline_info_index, encoding);
Calin Juravlec416d332015-04-23 16:01:43 +0100383
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800384 // Fill in the index.
385 stack_map.SetInlineInfoIndex(encoding.stack_map.encoding, next_inline_info_index);
386 DCHECK_EQ(next_inline_info_index, entry.inline_infos_start_index);
387 next_inline_info_index += entry.inlining_depth;
Calin Juravlec416d332015-04-23 16:01:43 +0100388
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800389 inline_info.SetDepth(encoding.inline_info.encoding, entry.inlining_depth);
Vladimir Marko225b6462015-09-28 12:17:40 +0100390 DCHECK_LE(entry.inline_infos_start_index + entry.inlining_depth, inline_infos_.size());
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800391
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100392 for (size_t depth = 0; depth < entry.inlining_depth; ++depth) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100393 InlineInfoEntry inline_entry = inline_infos_[depth + entry.inline_infos_start_index];
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000394 if (inline_entry.method != nullptr) {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700395 inline_info.SetMethodIndexIdxAtDepth(
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800396 encoding.inline_info.encoding,
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000397 depth,
398 High32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
399 inline_info.SetExtraDataAtDepth(
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800400 encoding.inline_info.encoding,
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000401 depth,
402 Low32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
403 } else {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700404 inline_info.SetMethodIndexIdxAtDepth(encoding.inline_info.encoding,
405 depth,
406 inline_entry.dex_method_index_idx);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800407 inline_info.SetExtraDataAtDepth(encoding.inline_info.encoding, depth, 1);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000408 }
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800409 inline_info.SetDexPcAtDepth(encoding.inline_info.encoding, depth, inline_entry.dex_pc);
Mathieu Chartier32289082017-02-09 15:57:37 -0800410 size_t dex_register_map_offset = MaybeCopyDexRegisterMap(
411 dex_register_entries_[inline_entry.dex_register_map_index],
412 &next_dex_register_map_offset,
413 dex_register_locations_region);
414 inline_info.SetDexRegisterMapOffsetAtDepth(encoding.inline_info.encoding,
415 depth,
416 dex_register_map_offset);
Calin Juravlec416d332015-04-23 16:01:43 +0100417 }
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800418 } else if (encoding.stack_map.encoding.GetInlineInfoEncoding().BitSize() > 0) {
419 stack_map.SetInlineInfoIndex(encoding.stack_map.encoding, StackMap::kNoInlineInfo);
Calin Juravlec416d332015-04-23 16:01:43 +0100420 }
421 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000422
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800423 // Write stack masks table.
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800424 const size_t stack_mask_bits = encoding.stack_mask.encoding.BitSize();
David Srbecky45aa5982016-03-18 02:15:09 +0000425 if (stack_mask_bits > 0) {
426 size_t stack_mask_bytes = RoundUp(stack_mask_bits, kBitsPerByte) / kBitsPerByte;
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800427 for (size_t i = 0; i < encoding.stack_mask.num_entries; ++i) {
David Srbecky45aa5982016-03-18 02:15:09 +0000428 MemoryRegion source(&stack_masks_[i * stack_mask_bytes], stack_mask_bytes);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800429 BitMemoryRegion stack_mask = code_info.GetStackMask(i, encoding);
430 for (size_t bit_index = 0; bit_index < stack_mask_bits; ++bit_index) {
David Srbecky45aa5982016-03-18 02:15:09 +0000431 stack_mask.StoreBit(bit_index, source.LoadBit(bit_index));
432 }
433 }
434 }
435
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800436 // Write register masks table.
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800437 for (size_t i = 0; i < encoding.register_mask.num_entries; ++i) {
438 BitMemoryRegion register_mask = code_info.GetRegisterMask(i, encoding);
439 register_mask.StoreBits(0, register_masks_[i], encoding.register_mask.encoding.BitSize());
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800440 }
441
David Srbecky1bbdfd72016-02-24 16:39:26 +0000442 // Verify all written data in debug build.
443 if (kIsDebugBuild) {
444 CheckCodeInfo(region);
445 }
Calin Juravlec416d332015-04-23 16:01:43 +0100446}
447
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100448void StackMapStream::FillInDexRegisterMap(DexRegisterMap dex_register_map,
449 uint32_t num_dex_registers,
450 const BitVector& live_dex_registers_mask,
451 uint32_t start_index_in_dex_register_locations) const {
452 dex_register_map.SetLiveBitMask(num_dex_registers, live_dex_registers_mask);
453 // Set the dex register location mapping data.
Vladimir Marko225b6462015-09-28 12:17:40 +0100454 size_t number_of_live_dex_registers = live_dex_registers_mask.NumSetBits();
455 DCHECK_LE(number_of_live_dex_registers, dex_register_locations_.size());
456 DCHECK_LE(start_index_in_dex_register_locations,
457 dex_register_locations_.size() - number_of_live_dex_registers);
458 for (size_t index_in_dex_register_locations = 0;
459 index_in_dex_register_locations != number_of_live_dex_registers;
460 ++index_in_dex_register_locations) {
461 size_t location_catalog_entry_index = dex_register_locations_[
462 start_index_in_dex_register_locations + index_in_dex_register_locations];
463 dex_register_map.SetLocationCatalogEntryIndex(
464 index_in_dex_register_locations,
465 location_catalog_entry_index,
466 num_dex_registers,
467 location_catalog_entries_.size());
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100468 }
469}
470
Mathieu Chartier32289082017-02-09 15:57:37 -0800471size_t StackMapStream::AddDexRegisterMapEntry(const DexRegisterMapEntry& entry) {
472 const size_t current_entry_index = dex_register_entries_.size();
473 auto entries_it = dex_map_hash_to_stack_map_indices_.find(entry.hash);
Calin Juravlec416d332015-04-23 16:01:43 +0100474 if (entries_it == dex_map_hash_to_stack_map_indices_.end()) {
475 // We don't have a perfect hash functions so we need a list to collect all stack maps
476 // which might have the same dex register map.
Vladimir Marko174b2e22017-10-12 13:34:49 +0100477 ScopedArenaVector<uint32_t> stack_map_indices(allocator_->Adapter(kArenaAllocStackMapStream));
Vladimir Marko225b6462015-09-28 12:17:40 +0100478 stack_map_indices.push_back(current_entry_index);
Mathieu Chartier32289082017-02-09 15:57:37 -0800479 dex_map_hash_to_stack_map_indices_.Put(entry.hash, std::move(stack_map_indices));
480 } else {
481 // We might have collisions, so we need to check whether or not we really have a match.
482 for (uint32_t test_entry_index : entries_it->second) {
483 if (DexRegisterMapEntryEquals(dex_register_entries_[test_entry_index], entry)) {
484 return test_entry_index;
485 }
Calin Juravlec416d332015-04-23 16:01:43 +0100486 }
Mathieu Chartier32289082017-02-09 15:57:37 -0800487 entries_it->second.push_back(current_entry_index);
Calin Juravlec416d332015-04-23 16:01:43 +0100488 }
Mathieu Chartier32289082017-02-09 15:57:37 -0800489 dex_register_entries_.push_back(entry);
490 return current_entry_index;
Calin Juravlec416d332015-04-23 16:01:43 +0100491}
492
Mathieu Chartier32289082017-02-09 15:57:37 -0800493bool StackMapStream::DexRegisterMapEntryEquals(const DexRegisterMapEntry& a,
494 const DexRegisterMapEntry& b) const {
495 if ((a.live_dex_registers_mask == nullptr) != (b.live_dex_registers_mask == nullptr)) {
Calin Juravlec416d332015-04-23 16:01:43 +0100496 return false;
497 }
498 if (a.num_dex_registers != b.num_dex_registers) {
499 return false;
500 }
Vladimir Marko225b6462015-09-28 12:17:40 +0100501 if (a.num_dex_registers != 0u) {
502 DCHECK(a.live_dex_registers_mask != nullptr);
503 DCHECK(b.live_dex_registers_mask != nullptr);
504 if (!a.live_dex_registers_mask->Equal(b.live_dex_registers_mask)) {
Calin Juravlec416d332015-04-23 16:01:43 +0100505 return false;
506 }
Vladimir Marko225b6462015-09-28 12:17:40 +0100507 size_t number_of_live_dex_registers = a.live_dex_registers_mask->NumSetBits();
508 DCHECK_LE(number_of_live_dex_registers, dex_register_locations_.size());
Mathieu Chartier32289082017-02-09 15:57:37 -0800509 DCHECK_LE(a.locations_start_index,
Vladimir Marko225b6462015-09-28 12:17:40 +0100510 dex_register_locations_.size() - number_of_live_dex_registers);
Mathieu Chartier32289082017-02-09 15:57:37 -0800511 DCHECK_LE(b.locations_start_index,
Vladimir Marko225b6462015-09-28 12:17:40 +0100512 dex_register_locations_.size() - number_of_live_dex_registers);
Mathieu Chartier32289082017-02-09 15:57:37 -0800513 auto a_begin = dex_register_locations_.begin() + a.locations_start_index;
514 auto b_begin = dex_register_locations_.begin() + b.locations_start_index;
Vladimir Marko225b6462015-09-28 12:17:40 +0100515 if (!std::equal(a_begin, a_begin + number_of_live_dex_registers, b_begin)) {
516 return false;
Calin Juravlec416d332015-04-23 16:01:43 +0100517 }
518 }
519 return true;
520}
521
David Srbecky1bbdfd72016-02-24 16:39:26 +0000522// Helper for CheckCodeInfo - check that register map has the expected content.
523void StackMapStream::CheckDexRegisterMap(const CodeInfo& code_info,
524 const DexRegisterMap& dex_register_map,
525 size_t num_dex_registers,
526 BitVector* live_dex_registers_mask,
527 size_t dex_register_locations_index) const {
David Srbecky09ed0982016-02-12 21:58:43 +0000528 CodeInfoEncoding encoding = code_info.ExtractEncoding();
David Srbecky1bbdfd72016-02-24 16:39:26 +0000529 for (size_t reg = 0; reg < num_dex_registers; reg++) {
530 // Find the location we tried to encode.
531 DexRegisterLocation expected = DexRegisterLocation::None();
532 if (live_dex_registers_mask->IsBitSet(reg)) {
533 size_t catalog_index = dex_register_locations_[dex_register_locations_index++];
534 expected = location_catalog_entries_[catalog_index];
535 }
536 // Compare to the seen location.
537 if (expected.GetKind() == DexRegisterLocation::Kind::kNone) {
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800538 DCHECK(!dex_register_map.IsValid() || !dex_register_map.IsDexRegisterLive(reg))
539 << dex_register_map.IsValid() << " " << dex_register_map.IsDexRegisterLive(reg);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000540 } else {
541 DCHECK(dex_register_map.IsDexRegisterLive(reg));
542 DexRegisterLocation seen = dex_register_map.GetDexRegisterLocation(
543 reg, num_dex_registers, code_info, encoding);
544 DCHECK_EQ(expected.GetKind(), seen.GetKind());
545 DCHECK_EQ(expected.GetValue(), seen.GetValue());
546 }
547 }
548 if (num_dex_registers == 0) {
549 DCHECK(!dex_register_map.IsValid());
550 }
551}
552
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800553size_t StackMapStream::PrepareRegisterMasks() {
554 register_masks_.resize(stack_maps_.size(), 0u);
Vladimir Marko174b2e22017-10-12 13:34:49 +0100555 ScopedArenaUnorderedMap<uint32_t, size_t> dedupe(allocator_->Adapter(kArenaAllocStackMapStream));
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800556 for (StackMapEntry& stack_map : stack_maps_) {
557 const size_t index = dedupe.size();
558 stack_map.register_mask_index = dedupe.emplace(stack_map.register_mask, index).first->second;
559 register_masks_[index] = stack_map.register_mask;
560 }
561 return dedupe.size();
562}
563
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700564void StackMapStream::PrepareMethodIndices() {
565 CHECK(method_indices_.empty());
566 method_indices_.resize(stack_maps_.size() + inline_infos_.size());
Vladimir Marko174b2e22017-10-12 13:34:49 +0100567 ScopedArenaUnorderedMap<uint32_t, size_t> dedupe(allocator_->Adapter(kArenaAllocStackMapStream));
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700568 for (StackMapEntry& stack_map : stack_maps_) {
569 const size_t index = dedupe.size();
570 const uint32_t method_index = stack_map.dex_method_index;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700571 if (method_index != dex::kDexNoIndex) {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700572 stack_map.dex_method_index_idx = dedupe.emplace(method_index, index).first->second;
573 method_indices_[index] = method_index;
574 }
575 }
576 for (InlineInfoEntry& inline_info : inline_infos_) {
577 const size_t index = dedupe.size();
578 const uint32_t method_index = inline_info.method_index;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700579 CHECK_NE(method_index, dex::kDexNoIndex);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700580 inline_info.dex_method_index_idx = dedupe.emplace(method_index, index).first->second;
581 method_indices_[index] = method_index;
582 }
583 method_indices_.resize(dedupe.size());
584}
585
586
David Srbecky45aa5982016-03-18 02:15:09 +0000587size_t StackMapStream::PrepareStackMasks(size_t entry_size_in_bits) {
588 // Preallocate memory since we do not want it to move (the dedup map will point into it).
589 const size_t byte_entry_size = RoundUp(entry_size_in_bits, kBitsPerByte) / kBitsPerByte;
590 stack_masks_.resize(byte_entry_size * stack_maps_.size(), 0u);
591 // For deduplicating we store the stack masks as byte packed for simplicity. We can bit pack later
592 // when copying out from stack_masks_.
Vladimir Marko174b2e22017-10-12 13:34:49 +0100593 ScopedArenaUnorderedMap<MemoryRegion,
594 size_t,
595 FNVHash<MemoryRegion>,
596 MemoryRegion::ContentEquals> dedup(
597 stack_maps_.size(), allocator_->Adapter(kArenaAllocStackMapStream));
David Srbecky45aa5982016-03-18 02:15:09 +0000598 for (StackMapEntry& stack_map : stack_maps_) {
599 size_t index = dedup.size();
600 MemoryRegion stack_mask(stack_masks_.data() + index * byte_entry_size, byte_entry_size);
601 for (size_t i = 0; i < entry_size_in_bits; i++) {
602 stack_mask.StoreBit(i, stack_map.sp_mask != nullptr && stack_map.sp_mask->IsBitSet(i));
603 }
604 stack_map.stack_mask_index = dedup.emplace(stack_mask, index).first->second;
605 }
606 return dedup.size();
607}
608
David Srbecky1bbdfd72016-02-24 16:39:26 +0000609// Check that all StackMapStream inputs are correctly encoded by trying to read them back.
610void StackMapStream::CheckCodeInfo(MemoryRegion region) const {
611 CodeInfo code_info(region);
David Srbecky09ed0982016-02-12 21:58:43 +0000612 CodeInfoEncoding encoding = code_info.ExtractEncoding();
613 DCHECK_EQ(code_info.GetNumberOfStackMaps(encoding), stack_maps_.size());
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800614 size_t invoke_info_index = 0;
David Srbecky1bbdfd72016-02-24 16:39:26 +0000615 for (size_t s = 0; s < stack_maps_.size(); ++s) {
616 const StackMap stack_map = code_info.GetStackMapAt(s, encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800617 const StackMapEncoding& stack_map_encoding = encoding.stack_map.encoding;
David Srbecky1bbdfd72016-02-24 16:39:26 +0000618 StackMapEntry entry = stack_maps_[s];
619
620 // Check main stack map fields.
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800621 DCHECK_EQ(stack_map.GetNativePcOffset(stack_map_encoding, instruction_set_),
622 entry.native_pc_code_offset.Uint32Value(instruction_set_));
David Srbecky09ed0982016-02-12 21:58:43 +0000623 DCHECK_EQ(stack_map.GetDexPc(stack_map_encoding), entry.dex_pc);
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800624 DCHECK_EQ(stack_map.GetRegisterMaskIndex(stack_map_encoding), entry.register_mask_index);
625 DCHECK_EQ(code_info.GetRegisterMaskOf(encoding, stack_map), entry.register_mask);
David Srbecky45aa5982016-03-18 02:15:09 +0000626 const size_t num_stack_mask_bits = code_info.GetNumberOfStackMaskBits(encoding);
627 DCHECK_EQ(stack_map.GetStackMaskIndex(stack_map_encoding), entry.stack_mask_index);
628 BitMemoryRegion stack_mask = code_info.GetStackMaskOf(encoding, stack_map);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000629 if (entry.sp_mask != nullptr) {
David Srbecky45aa5982016-03-18 02:15:09 +0000630 DCHECK_GE(stack_mask.size_in_bits(), entry.sp_mask->GetNumberOfBits());
David Srbecky09ed0982016-02-12 21:58:43 +0000631 for (size_t b = 0; b < num_stack_mask_bits; b++) {
David Srbecky45aa5982016-03-18 02:15:09 +0000632 DCHECK_EQ(stack_mask.LoadBit(b), entry.sp_mask->IsBitSet(b));
David Srbecky1bbdfd72016-02-24 16:39:26 +0000633 }
634 } else {
David Srbecky09ed0982016-02-12 21:58:43 +0000635 for (size_t b = 0; b < num_stack_mask_bits; b++) {
David Srbecky45aa5982016-03-18 02:15:09 +0000636 DCHECK_EQ(stack_mask.LoadBit(b), 0u);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000637 }
638 }
Andreas Gampee2abbc62017-09-15 11:59:26 -0700639 if (entry.dex_method_index != dex::kDexNoIndex) {
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800640 InvokeInfo invoke_info = code_info.GetInvokeInfo(encoding, invoke_info_index);
641 DCHECK_EQ(invoke_info.GetNativePcOffset(encoding.invoke_info.encoding, instruction_set_),
642 entry.native_pc_code_offset.Uint32Value(instruction_set_));
643 DCHECK_EQ(invoke_info.GetInvokeType(encoding.invoke_info.encoding), entry.invoke_type);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700644 DCHECK_EQ(invoke_info.GetMethodIndexIdx(encoding.invoke_info.encoding),
645 entry.dex_method_index_idx);
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800646 invoke_info_index++;
647 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000648 CheckDexRegisterMap(code_info,
649 code_info.GetDexRegisterMapOf(
Mathieu Chartier32289082017-02-09 15:57:37 -0800650 stack_map, encoding, entry.dex_register_entry.num_dex_registers),
651 entry.dex_register_entry.num_dex_registers,
652 entry.dex_register_entry.live_dex_registers_mask,
653 entry.dex_register_entry.locations_start_index);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000654
655 // Check inline info.
David Srbecky09ed0982016-02-12 21:58:43 +0000656 DCHECK_EQ(stack_map.HasInlineInfo(stack_map_encoding), (entry.inlining_depth != 0));
David Srbecky1bbdfd72016-02-24 16:39:26 +0000657 if (entry.inlining_depth != 0) {
658 InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map, encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800659 DCHECK_EQ(inline_info.GetDepth(encoding.inline_info.encoding), entry.inlining_depth);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000660 for (size_t d = 0; d < entry.inlining_depth; ++d) {
661 size_t inline_info_index = entry.inline_infos_start_index + d;
662 DCHECK_LT(inline_info_index, inline_infos_.size());
663 InlineInfoEntry inline_entry = inline_infos_[inline_info_index];
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800664 DCHECK_EQ(inline_info.GetDexPcAtDepth(encoding.inline_info.encoding, d),
David Srbecky61b28a12016-02-25 21:55:03 +0000665 inline_entry.dex_pc);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800666 if (inline_info.EncodesArtMethodAtDepth(encoding.inline_info.encoding, d)) {
667 DCHECK_EQ(inline_info.GetArtMethodAtDepth(encoding.inline_info.encoding, d),
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000668 inline_entry.method);
669 } else {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700670 const size_t method_index_idx =
671 inline_info.GetMethodIndexIdxAtDepth(encoding.inline_info.encoding, d);
672 DCHECK_EQ(method_index_idx, inline_entry.dex_method_index_idx);
673 DCHECK_EQ(method_indices_[method_index_idx], inline_entry.method_index);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000674 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000675
676 CheckDexRegisterMap(code_info,
677 code_info.GetDexRegisterMapAtDepth(
Mathieu Chartier32289082017-02-09 15:57:37 -0800678 d,
679 inline_info,
680 encoding,
681 inline_entry.dex_register_entry.num_dex_registers),
682 inline_entry.dex_register_entry.num_dex_registers,
683 inline_entry.dex_register_entry.live_dex_registers_mask,
684 inline_entry.dex_register_entry.locations_start_index);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000685 }
686 }
687 }
688}
689
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700690size_t StackMapStream::ComputeMethodInfoSize() const {
691 DCHECK_NE(0u, needed_size_) << "PrepareForFillIn not called before " << __FUNCTION__;
692 return MethodInfo::ComputeSize(method_indices_.size());
693}
694
Calin Juravlec416d332015-04-23 16:01:43 +0100695} // namespace art