blob: 7010e3f380aacfa0eb04674ebe13813f441f5e7e [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"
David Sehr9e734c72018-01-04 17:56:19 -080021#include "dex/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";
35 current_entry_.dex_pc = dex_pc;
Mathieu Chartiera2f526f2017-01-19 14:48:48 -080036 current_entry_.native_pc_code_offset = CodeOffset::FromOffset(native_pc_offset, instruction_set_);
Calin Juravle4f46ac52015-04-23 18:47:21 +010037 current_entry_.register_mask = register_mask;
38 current_entry_.sp_mask = sp_mask;
Calin Juravle4f46ac52015-04-23 18:47:21 +010039 current_entry_.inlining_depth = inlining_depth;
Vladimir Marko225b6462015-09-28 12:17:40 +010040 current_entry_.inline_infos_start_index = inline_infos_.size();
David Srbecky45aa5982016-03-18 02:15:09 +000041 current_entry_.stack_mask_index = 0;
Andreas Gampee2abbc62017-09-15 11:59:26 -070042 current_entry_.dex_method_index = dex::kDexNoIndex;
Mathieu Chartier32289082017-02-09 15:57:37 -080043 current_entry_.dex_register_entry.num_dex_registers = num_dex_registers;
44 current_entry_.dex_register_entry.locations_start_index = dex_register_locations_.size();
Vladimir Marko174b2e22017-10-12 13:34:49 +010045 current_entry_.dex_register_entry.live_dex_registers_mask = nullptr;
46 if (num_dex_registers != 0u) {
47 current_entry_.dex_register_entry.live_dex_registers_mask =
48 ArenaBitVector::Create(allocator_, num_dex_registers, true, kArenaAllocStackMapStream);
49 current_entry_.dex_register_entry.live_dex_registers_mask->ClearAllBits();
50 }
Calin Juravlec416d332015-04-23 16:01:43 +010051 if (sp_mask != nullptr) {
52 stack_mask_max_ = std::max(stack_mask_max_, sp_mask->GetHighestBitSet());
53 }
54 if (inlining_depth > 0) {
55 number_of_stack_maps_with_inline_info_++;
56 }
57
Vladimir Marko92f7f3c2017-10-31 11:38:30 +000058 // Note: dex_pc can be kNoDexPc for native method intrinsics.
59 if (dex_pc != dex::kDexNoIndex && (dex_pc_max_ == dex::kDexNoIndex || dex_pc_max_ < dex_pc)) {
60 dex_pc_max_ = dex_pc;
61 }
Calin Juravlec416d332015-04-23 16:01:43 +010062 register_mask_max_ = std::max(register_mask_max_, register_mask);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010063 current_dex_register_ = 0;
Calin Juravlec416d332015-04-23 16:01:43 +010064}
65
Calin Juravle4f46ac52015-04-23 18:47:21 +010066void StackMapStream::EndStackMapEntry() {
Mathieu Chartier32289082017-02-09 15:57:37 -080067 current_entry_.dex_register_map_index = AddDexRegisterMapEntry(current_entry_.dex_register_entry);
Vladimir Marko225b6462015-09-28 12:17:40 +010068 stack_maps_.push_back(current_entry_);
Calin Juravle4f46ac52015-04-23 18:47:21 +010069 current_entry_ = StackMapEntry();
70}
71
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010072void StackMapStream::AddDexRegisterEntry(DexRegisterLocation::Kind kind, int32_t value) {
Calin Juravlec416d332015-04-23 16:01:43 +010073 if (kind != DexRegisterLocation::Kind::kNone) {
74 // Ensure we only use non-compressed location kind at this stage.
David Srbecky7dc11782016-02-25 13:23:56 +000075 DCHECK(DexRegisterLocation::IsShortLocationKind(kind)) << kind;
Calin Juravlec416d332015-04-23 16:01:43 +010076 DexRegisterLocation location(kind, value);
77
78 // Look for Dex register `location` in the location catalog (using the
79 // companion hash map of locations to indices). Use its index if it
80 // is already in the location catalog. If not, insert it (in the
81 // location catalog and the hash map) and use the newly created index.
82 auto it = location_catalog_entries_indices_.Find(location);
83 if (it != location_catalog_entries_indices_.end()) {
84 // Retrieve the index from the hash map.
Vladimir Marko225b6462015-09-28 12:17:40 +010085 dex_register_locations_.push_back(it->second);
Calin Juravlec416d332015-04-23 16:01:43 +010086 } else {
87 // Create a new entry in the location catalog and the hash map.
Vladimir Marko225b6462015-09-28 12:17:40 +010088 size_t index = location_catalog_entries_.size();
89 location_catalog_entries_.push_back(location);
90 dex_register_locations_.push_back(index);
Calin Juravlec416d332015-04-23 16:01:43 +010091 location_catalog_entries_indices_.Insert(std::make_pair(location, index));
92 }
Mathieu Chartier32289082017-02-09 15:57:37 -080093 DexRegisterMapEntry* const entry = in_inline_frame_
94 ? &current_inline_info_.dex_register_entry
95 : &current_entry_.dex_register_entry;
96 DCHECK_LT(current_dex_register_, entry->num_dex_registers);
97 entry->live_dex_registers_mask->SetBit(current_dex_register_);
98 entry->hash += (1 <<
99 (current_dex_register_ % (sizeof(DexRegisterMapEntry::hash) * kBitsPerByte)));
100 entry->hash += static_cast<uint32_t>(value);
101 entry->hash += static_cast<uint32_t>(kind);
Calin Juravlec416d332015-04-23 16:01:43 +0100102 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100103 current_dex_register_++;
Calin Juravlec416d332015-04-23 16:01:43 +0100104}
105
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800106void StackMapStream::AddInvoke(InvokeType invoke_type, uint32_t dex_method_index) {
107 current_entry_.invoke_type = invoke_type;
108 current_entry_.dex_method_index = dex_method_index;
109}
110
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000111void StackMapStream::BeginInlineInfoEntry(ArtMethod* method,
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100112 uint32_t dex_pc,
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000113 uint32_t num_dex_registers,
114 const DexFile* outer_dex_file) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100115 DCHECK(!in_inline_frame_);
116 in_inline_frame_ = true;
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000117 if (EncodeArtMethodInInlineInfo(method)) {
118 current_inline_info_.method = method;
119 } else {
120 if (dex_pc != static_cast<uint32_t>(-1) && kIsDebugBuild) {
121 ScopedObjectAccess soa(Thread::Current());
122 DCHECK(IsSameDexFile(*outer_dex_file, *method->GetDexFile()));
123 }
124 current_inline_info_.method_index = method->GetDexMethodIndexUnchecked();
125 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100126 current_inline_info_.dex_pc = dex_pc;
Mathieu Chartier32289082017-02-09 15:57:37 -0800127 current_inline_info_.dex_register_entry.num_dex_registers = num_dex_registers;
128 current_inline_info_.dex_register_entry.locations_start_index = dex_register_locations_.size();
Vladimir Marko174b2e22017-10-12 13:34:49 +0100129 current_inline_info_.dex_register_entry.live_dex_registers_mask = nullptr;
130 if (num_dex_registers != 0) {
131 current_inline_info_.dex_register_entry.live_dex_registers_mask =
132 ArenaBitVector::Create(allocator_, num_dex_registers, true, kArenaAllocStackMapStream);
133 current_inline_info_.dex_register_entry.live_dex_registers_mask->ClearAllBits();
134 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100135 current_dex_register_ = 0;
136}
137
138void StackMapStream::EndInlineInfoEntry() {
Mathieu Chartier32289082017-02-09 15:57:37 -0800139 current_inline_info_.dex_register_map_index =
140 AddDexRegisterMapEntry(current_inline_info_.dex_register_entry);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100141 DCHECK(in_inline_frame_);
Mathieu Chartier32289082017-02-09 15:57:37 -0800142 DCHECK_EQ(current_dex_register_, current_inline_info_.dex_register_entry.num_dex_registers)
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100143 << "Inline information contains less registers than expected";
144 in_inline_frame_ = false;
Vladimir Marko225b6462015-09-28 12:17:40 +0100145 inline_infos_.push_back(current_inline_info_);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100146 current_inline_info_ = InlineInfoEntry();
Calin Juravlec416d332015-04-23 16:01:43 +0100147}
148
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800149CodeOffset StackMapStream::ComputeMaxNativePcCodeOffset() const {
150 CodeOffset max_native_pc_offset;
Vladimir Marko225b6462015-09-28 12:17:40 +0100151 for (const StackMapEntry& entry : stack_maps_) {
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800152 max_native_pc_offset = std::max(max_native_pc_offset, entry.native_pc_code_offset);
Vladimir Markobd8c7252015-06-12 10:06:32 +0100153 }
154 return max_native_pc_offset;
155}
156
Calin Juravle4f46ac52015-04-23 18:47:21 +0100157size_t StackMapStream::PrepareForFillIn() {
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800158 CodeInfoEncoding encoding;
159 encoding.dex_register_map.num_entries = 0; // TODO: Remove this field.
160 encoding.dex_register_map.num_bytes = ComputeDexRegisterMapsSize();
161 encoding.location_catalog.num_entries = location_catalog_entries_.size();
162 encoding.location_catalog.num_bytes = ComputeDexRegisterLocationCatalogSize();
163 encoding.inline_info.num_entries = inline_infos_.size();
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700164 // Must be done before calling ComputeInlineInfoEncoding since ComputeInlineInfoEncoding requires
165 // dex_method_index_idx to be filled in.
166 PrepareMethodIndices();
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800167 ComputeInlineInfoEncoding(&encoding.inline_info.encoding,
168 encoding.dex_register_map.num_bytes);
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800169 CodeOffset max_native_pc_offset = ComputeMaxNativePcCodeOffset();
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800170 // Prepare the CodeInfo variable-sized encoding.
171 encoding.stack_mask.encoding.num_bits = stack_mask_max_ + 1; // Need room for max element too.
172 encoding.stack_mask.num_entries = PrepareStackMasks(encoding.stack_mask.encoding.num_bits);
173 encoding.register_mask.encoding.num_bits = MinimumBitsToStore(register_mask_max_);
174 encoding.register_mask.num_entries = PrepareRegisterMasks();
175 encoding.stack_map.num_entries = stack_maps_.size();
176 encoding.stack_map.encoding.SetFromSizes(
177 // The stack map contains compressed native PC offsets.
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800178 max_native_pc_offset.CompressedValue(),
179 dex_pc_max_,
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800180 encoding.dex_register_map.num_bytes,
181 encoding.inline_info.num_entries,
182 encoding.register_mask.num_entries,
183 encoding.stack_mask.num_entries);
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800184 ComputeInvokeInfoEncoding(&encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800185 DCHECK_EQ(code_info_encoding_.size(), 0u);
186 encoding.Compress(&code_info_encoding_);
187 encoding.ComputeTableOffsets();
188 // Compute table offsets so we can get the non header size.
189 DCHECK_EQ(encoding.HeaderSize(), code_info_encoding_.size());
190 needed_size_ = code_info_encoding_.size() + encoding.NonHeaderSize();
Calin Juravle4f46ac52015-04-23 18:47:21 +0100191 return needed_size_;
Calin Juravlec416d332015-04-23 16:01:43 +0100192}
193
194size_t StackMapStream::ComputeDexRegisterLocationCatalogSize() const {
195 size_t size = DexRegisterLocationCatalog::kFixedSize;
Vladimir Marko225b6462015-09-28 12:17:40 +0100196 for (const DexRegisterLocation& dex_register_location : location_catalog_entries_) {
Calin Juravlec416d332015-04-23 16:01:43 +0100197 size += DexRegisterLocationCatalog::EntrySize(dex_register_location);
198 }
199 return size;
200}
201
Mathieu Chartier32289082017-02-09 15:57:37 -0800202size_t StackMapStream::DexRegisterMapEntry::ComputeSize(size_t catalog_size) const {
Vladimir Marko225b6462015-09-28 12:17:40 +0100203 // For num_dex_registers == 0u live_dex_registers_mask may be null.
204 if (num_dex_registers == 0u) {
205 return 0u; // No register map will be emitted.
206 }
207 DCHECK(live_dex_registers_mask != nullptr);
208
Calin Juravlec416d332015-04-23 16:01:43 +0100209 // Size of the map in bytes.
210 size_t size = DexRegisterMap::kFixedSize;
211 // Add the live bit mask for the Dex register liveness.
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100212 size += DexRegisterMap::GetLiveBitMaskSize(num_dex_registers);
Calin Juravlec416d332015-04-23 16:01:43 +0100213 // Compute the size of the set of live Dex register entries.
Vladimir Marko225b6462015-09-28 12:17:40 +0100214 size_t number_of_live_dex_registers = live_dex_registers_mask->NumSetBits();
Calin Juravlec416d332015-04-23 16:01:43 +0100215 size_t map_entries_size_in_bits =
Mathieu Chartier32289082017-02-09 15:57:37 -0800216 DexRegisterMap::SingleEntrySizeInBits(catalog_size) * number_of_live_dex_registers;
Calin Juravlec416d332015-04-23 16:01:43 +0100217 size_t map_entries_size_in_bytes =
218 RoundUp(map_entries_size_in_bits, kBitsPerByte) / kBitsPerByte;
219 size += map_entries_size_in_bytes;
220 return size;
221}
222
Calin Juravle4f46ac52015-04-23 18:47:21 +0100223size_t StackMapStream::ComputeDexRegisterMapsSize() const {
Calin Juravlec416d332015-04-23 16:01:43 +0100224 size_t size = 0;
Mathieu Chartier32289082017-02-09 15:57:37 -0800225 for (const DexRegisterMapEntry& entry : dex_register_entries_) {
226 size += entry.ComputeSize(location_catalog_entries_.size());
Calin Juravlec416d332015-04-23 16:01:43 +0100227 }
228 return size;
229}
230
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800231void StackMapStream::ComputeInvokeInfoEncoding(CodeInfoEncoding* encoding) {
232 DCHECK(encoding != nullptr);
233 uint32_t native_pc_max = 0;
234 uint16_t method_index_max = 0;
235 size_t invoke_infos_count = 0;
236 size_t invoke_type_max = 0;
237 for (const StackMapEntry& entry : stack_maps_) {
Andreas Gampee2abbc62017-09-15 11:59:26 -0700238 if (entry.dex_method_index != dex::kDexNoIndex) {
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800239 native_pc_max = std::max(native_pc_max, entry.native_pc_code_offset.CompressedValue());
240 method_index_max = std::max(method_index_max, static_cast<uint16_t>(entry.dex_method_index));
241 invoke_type_max = std::max(invoke_type_max, static_cast<size_t>(entry.invoke_type));
242 ++invoke_infos_count;
243 }
244 }
245 encoding->invoke_info.num_entries = invoke_infos_count;
246 encoding->invoke_info.encoding.SetFromSizes(native_pc_max, invoke_type_max, method_index_max);
247}
248
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800249void StackMapStream::ComputeInlineInfoEncoding(InlineInfoEncoding* encoding,
250 size_t dex_register_maps_bytes) {
David Srbecky61b28a12016-02-25 21:55:03 +0000251 uint32_t method_index_max = 0;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700252 uint32_t dex_pc_max = dex::kDexNoIndex;
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000253 uint32_t extra_data_max = 0;
David Srbecky61b28a12016-02-25 21:55:03 +0000254
255 uint32_t inline_info_index = 0;
256 for (const StackMapEntry& entry : stack_maps_) {
257 for (size_t j = 0; j < entry.inlining_depth; ++j) {
258 InlineInfoEntry inline_entry = inline_infos_[inline_info_index++];
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000259 if (inline_entry.method == nullptr) {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700260 method_index_max = std::max(method_index_max, inline_entry.dex_method_index_idx);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000261 extra_data_max = std::max(extra_data_max, 1u);
262 } else {
263 method_index_max = std::max(
264 method_index_max, High32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
265 extra_data_max = std::max(
266 extra_data_max, Low32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
267 }
Andreas Gampee2abbc62017-09-15 11:59:26 -0700268 if (inline_entry.dex_pc != dex::kDexNoIndex &&
269 (dex_pc_max == dex::kDexNoIndex || dex_pc_max < inline_entry.dex_pc)) {
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100270 dex_pc_max = inline_entry.dex_pc;
271 }
David Srbecky61b28a12016-02-25 21:55:03 +0000272 }
273 }
274 DCHECK_EQ(inline_info_index, inline_infos_.size());
275
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800276 encoding->SetFromSizes(method_index_max, dex_pc_max, extra_data_max, dex_register_maps_bytes);
Calin Juravlec416d332015-04-23 16:01:43 +0100277}
278
Mathieu Chartier32289082017-02-09 15:57:37 -0800279size_t StackMapStream::MaybeCopyDexRegisterMap(DexRegisterMapEntry& entry,
280 size_t* current_offset,
281 MemoryRegion dex_register_locations_region) {
282 DCHECK(current_offset != nullptr);
283 if ((entry.num_dex_registers == 0) || (entry.live_dex_registers_mask->NumSetBits() == 0)) {
284 // No dex register map needed.
285 return StackMap::kNoDexRegisterMap;
286 }
287 if (entry.offset == DexRegisterMapEntry::kOffsetUnassigned) {
288 // Not already copied, need to copy and and assign an offset.
289 entry.offset = *current_offset;
290 const size_t entry_size = entry.ComputeSize(location_catalog_entries_.size());
291 DexRegisterMap dex_register_map(
292 dex_register_locations_region.Subregion(entry.offset, entry_size));
293 *current_offset += entry_size;
294 // Fill in the map since it was just added.
295 FillInDexRegisterMap(dex_register_map,
296 entry.num_dex_registers,
297 *entry.live_dex_registers_mask,
298 entry.locations_start_index);
299 }
300 return entry.offset;
301}
302
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700303void StackMapStream::FillInMethodInfo(MemoryRegion region) {
304 {
305 MethodInfo info(region.begin(), method_indices_.size());
306 for (size_t i = 0; i < method_indices_.size(); ++i) {
307 info.SetMethodIndex(i, method_indices_[i]);
308 }
309 }
310 if (kIsDebugBuild) {
311 // Check the data matches.
312 MethodInfo info(region.begin());
313 const size_t count = info.NumMethodIndices();
314 DCHECK_EQ(count, method_indices_.size());
315 for (size_t i = 0; i < count; ++i) {
316 DCHECK_EQ(info.GetMethodIndex(i), method_indices_[i]);
317 }
318 }
319}
320
321void StackMapStream::FillInCodeInfo(MemoryRegion region) {
Calin Juravle4f46ac52015-04-23 18:47:21 +0100322 DCHECK_EQ(0u, current_entry_.dex_pc) << "EndStackMapEntry not called after BeginStackMapEntry";
323 DCHECK_NE(0u, needed_size_) << "PrepareForFillIn not called before FillIn";
324
Calin Juravle4f46ac52015-04-23 18:47:21 +0100325 DCHECK_EQ(region.size(), needed_size_);
David Srbecky09ed0982016-02-12 21:58:43 +0000326
327 // Note that the memory region does not have to be zeroed when we JIT code
328 // because we do not use the arena allocator there.
329
330 // Write the CodeInfo header.
331 region.CopyFrom(0, MemoryRegion(code_info_encoding_.data(), code_info_encoding_.size()));
Calin Juravlec416d332015-04-23 16:01:43 +0100332
David Srbecky09ed0982016-02-12 21:58:43 +0000333 CodeInfo code_info(region);
334 CodeInfoEncoding encoding = code_info.ExtractEncoding();
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800335 DCHECK_EQ(encoding.stack_map.num_entries, stack_maps_.size());
336
337 MemoryRegion dex_register_locations_region = region.Subregion(
338 encoding.dex_register_map.byte_offset,
339 encoding.dex_register_map.num_bytes);
Calin Juravlec416d332015-04-23 16:01:43 +0100340
341 // Set the Dex register location catalog.
Calin Juravlec416d332015-04-23 16:01:43 +0100342 MemoryRegion dex_register_location_catalog_region = region.Subregion(
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800343 encoding.location_catalog.byte_offset,
344 encoding.location_catalog.num_bytes);
Calin Juravlec416d332015-04-23 16:01:43 +0100345 DexRegisterLocationCatalog dex_register_location_catalog(dex_register_location_catalog_region);
346 // Offset in `dex_register_location_catalog` where to store the next
347 // register location.
348 size_t location_catalog_offset = DexRegisterLocationCatalog::kFixedSize;
Vladimir Marko225b6462015-09-28 12:17:40 +0100349 for (DexRegisterLocation dex_register_location : location_catalog_entries_) {
Calin Juravlec416d332015-04-23 16:01:43 +0100350 dex_register_location_catalog.SetRegisterInfo(location_catalog_offset, dex_register_location);
351 location_catalog_offset += DexRegisterLocationCatalog::EntrySize(dex_register_location);
352 }
353 // Ensure we reached the end of the Dex registers location_catalog.
354 DCHECK_EQ(location_catalog_offset, dex_register_location_catalog_region.size());
355
Vladimir Markof6a35de2016-03-21 12:01:50 +0000356 ArenaBitVector empty_bitmask(allocator_, 0, /* expandable */ false, kArenaAllocStackMapStream);
Calin Juravlec416d332015-04-23 16:01:43 +0100357 uintptr_t next_dex_register_map_offset = 0;
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800358 uintptr_t next_inline_info_index = 0;
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800359 size_t invoke_info_idx = 0;
Vladimir Marko225b6462015-09-28 12:17:40 +0100360 for (size_t i = 0, e = stack_maps_.size(); i < e; ++i) {
David Srbecky09ed0982016-02-12 21:58:43 +0000361 StackMap stack_map = code_info.GetStackMapAt(i, encoding);
Vladimir Marko225b6462015-09-28 12:17:40 +0100362 StackMapEntry entry = stack_maps_[i];
Calin Juravlec416d332015-04-23 16:01:43 +0100363
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800364 stack_map.SetDexPc(encoding.stack_map.encoding, entry.dex_pc);
365 stack_map.SetNativePcCodeOffset(encoding.stack_map.encoding, entry.native_pc_code_offset);
366 stack_map.SetRegisterMaskIndex(encoding.stack_map.encoding, entry.register_mask_index);
367 stack_map.SetStackMaskIndex(encoding.stack_map.encoding, entry.stack_mask_index);
Calin Juravlec416d332015-04-23 16:01:43 +0100368
Mathieu Chartier32289082017-02-09 15:57:37 -0800369 size_t offset = MaybeCopyDexRegisterMap(dex_register_entries_[entry.dex_register_map_index],
370 &next_dex_register_map_offset,
371 dex_register_locations_region);
372 stack_map.SetDexRegisterMapOffset(encoding.stack_map.encoding, offset);
Calin Juravlec416d332015-04-23 16:01:43 +0100373
Andreas Gampee2abbc62017-09-15 11:59:26 -0700374 if (entry.dex_method_index != dex::kDexNoIndex) {
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800375 InvokeInfo invoke_info(code_info.GetInvokeInfo(encoding, invoke_info_idx));
376 invoke_info.SetNativePcCodeOffset(encoding.invoke_info.encoding, entry.native_pc_code_offset);
377 invoke_info.SetInvokeType(encoding.invoke_info.encoding, entry.invoke_type);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700378 invoke_info.SetMethodIndexIdx(encoding.invoke_info.encoding, entry.dex_method_index_idx);
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800379 ++invoke_info_idx;
380 }
381
Calin Juravlec416d332015-04-23 16:01:43 +0100382 // Set the inlining info.
383 if (entry.inlining_depth != 0) {
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800384 InlineInfo inline_info = code_info.GetInlineInfo(next_inline_info_index, encoding);
Calin Juravlec416d332015-04-23 16:01:43 +0100385
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800386 // Fill in the index.
387 stack_map.SetInlineInfoIndex(encoding.stack_map.encoding, next_inline_info_index);
388 DCHECK_EQ(next_inline_info_index, entry.inline_infos_start_index);
389 next_inline_info_index += entry.inlining_depth;
Calin Juravlec416d332015-04-23 16:01:43 +0100390
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800391 inline_info.SetDepth(encoding.inline_info.encoding, entry.inlining_depth);
Vladimir Marko225b6462015-09-28 12:17:40 +0100392 DCHECK_LE(entry.inline_infos_start_index + entry.inlining_depth, inline_infos_.size());
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800393
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100394 for (size_t depth = 0; depth < entry.inlining_depth; ++depth) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100395 InlineInfoEntry inline_entry = inline_infos_[depth + entry.inline_infos_start_index];
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000396 if (inline_entry.method != nullptr) {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700397 inline_info.SetMethodIndexIdxAtDepth(
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800398 encoding.inline_info.encoding,
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000399 depth,
400 High32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
401 inline_info.SetExtraDataAtDepth(
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800402 encoding.inline_info.encoding,
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000403 depth,
404 Low32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
405 } else {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700406 inline_info.SetMethodIndexIdxAtDepth(encoding.inline_info.encoding,
407 depth,
408 inline_entry.dex_method_index_idx);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800409 inline_info.SetExtraDataAtDepth(encoding.inline_info.encoding, depth, 1);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000410 }
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800411 inline_info.SetDexPcAtDepth(encoding.inline_info.encoding, depth, inline_entry.dex_pc);
Mathieu Chartier32289082017-02-09 15:57:37 -0800412 size_t dex_register_map_offset = MaybeCopyDexRegisterMap(
413 dex_register_entries_[inline_entry.dex_register_map_index],
414 &next_dex_register_map_offset,
415 dex_register_locations_region);
416 inline_info.SetDexRegisterMapOffsetAtDepth(encoding.inline_info.encoding,
417 depth,
418 dex_register_map_offset);
Calin Juravlec416d332015-04-23 16:01:43 +0100419 }
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800420 } else if (encoding.stack_map.encoding.GetInlineInfoEncoding().BitSize() > 0) {
421 stack_map.SetInlineInfoIndex(encoding.stack_map.encoding, StackMap::kNoInlineInfo);
Calin Juravlec416d332015-04-23 16:01:43 +0100422 }
423 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000424
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800425 // Write stack masks table.
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800426 const size_t stack_mask_bits = encoding.stack_mask.encoding.BitSize();
David Srbecky45aa5982016-03-18 02:15:09 +0000427 if (stack_mask_bits > 0) {
428 size_t stack_mask_bytes = RoundUp(stack_mask_bits, kBitsPerByte) / kBitsPerByte;
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800429 for (size_t i = 0; i < encoding.stack_mask.num_entries; ++i) {
David Srbecky45aa5982016-03-18 02:15:09 +0000430 MemoryRegion source(&stack_masks_[i * stack_mask_bytes], stack_mask_bytes);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800431 BitMemoryRegion stack_mask = code_info.GetStackMask(i, encoding);
432 for (size_t bit_index = 0; bit_index < stack_mask_bits; ++bit_index) {
David Srbecky45aa5982016-03-18 02:15:09 +0000433 stack_mask.StoreBit(bit_index, source.LoadBit(bit_index));
434 }
435 }
436 }
437
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800438 // Write register masks table.
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800439 for (size_t i = 0; i < encoding.register_mask.num_entries; ++i) {
440 BitMemoryRegion register_mask = code_info.GetRegisterMask(i, encoding);
441 register_mask.StoreBits(0, register_masks_[i], encoding.register_mask.encoding.BitSize());
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800442 }
443
David Srbecky1bbdfd72016-02-24 16:39:26 +0000444 // Verify all written data in debug build.
445 if (kIsDebugBuild) {
446 CheckCodeInfo(region);
447 }
Calin Juravlec416d332015-04-23 16:01:43 +0100448}
449
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100450void StackMapStream::FillInDexRegisterMap(DexRegisterMap dex_register_map,
451 uint32_t num_dex_registers,
452 const BitVector& live_dex_registers_mask,
453 uint32_t start_index_in_dex_register_locations) const {
454 dex_register_map.SetLiveBitMask(num_dex_registers, live_dex_registers_mask);
455 // Set the dex register location mapping data.
Vladimir Marko225b6462015-09-28 12:17:40 +0100456 size_t number_of_live_dex_registers = live_dex_registers_mask.NumSetBits();
457 DCHECK_LE(number_of_live_dex_registers, dex_register_locations_.size());
458 DCHECK_LE(start_index_in_dex_register_locations,
459 dex_register_locations_.size() - number_of_live_dex_registers);
460 for (size_t index_in_dex_register_locations = 0;
461 index_in_dex_register_locations != number_of_live_dex_registers;
462 ++index_in_dex_register_locations) {
463 size_t location_catalog_entry_index = dex_register_locations_[
464 start_index_in_dex_register_locations + index_in_dex_register_locations];
465 dex_register_map.SetLocationCatalogEntryIndex(
466 index_in_dex_register_locations,
467 location_catalog_entry_index,
468 num_dex_registers,
469 location_catalog_entries_.size());
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100470 }
471}
472
Mathieu Chartier32289082017-02-09 15:57:37 -0800473size_t StackMapStream::AddDexRegisterMapEntry(const DexRegisterMapEntry& entry) {
474 const size_t current_entry_index = dex_register_entries_.size();
475 auto entries_it = dex_map_hash_to_stack_map_indices_.find(entry.hash);
Calin Juravlec416d332015-04-23 16:01:43 +0100476 if (entries_it == dex_map_hash_to_stack_map_indices_.end()) {
477 // We don't have a perfect hash functions so we need a list to collect all stack maps
478 // which might have the same dex register map.
Vladimir Marko174b2e22017-10-12 13:34:49 +0100479 ScopedArenaVector<uint32_t> stack_map_indices(allocator_->Adapter(kArenaAllocStackMapStream));
Vladimir Marko225b6462015-09-28 12:17:40 +0100480 stack_map_indices.push_back(current_entry_index);
Mathieu Chartier32289082017-02-09 15:57:37 -0800481 dex_map_hash_to_stack_map_indices_.Put(entry.hash, std::move(stack_map_indices));
482 } else {
483 // We might have collisions, so we need to check whether or not we really have a match.
484 for (uint32_t test_entry_index : entries_it->second) {
485 if (DexRegisterMapEntryEquals(dex_register_entries_[test_entry_index], entry)) {
486 return test_entry_index;
487 }
Calin Juravlec416d332015-04-23 16:01:43 +0100488 }
Mathieu Chartier32289082017-02-09 15:57:37 -0800489 entries_it->second.push_back(current_entry_index);
Calin Juravlec416d332015-04-23 16:01:43 +0100490 }
Mathieu Chartier32289082017-02-09 15:57:37 -0800491 dex_register_entries_.push_back(entry);
492 return current_entry_index;
Calin Juravlec416d332015-04-23 16:01:43 +0100493}
494
Mathieu Chartier32289082017-02-09 15:57:37 -0800495bool StackMapStream::DexRegisterMapEntryEquals(const DexRegisterMapEntry& a,
496 const DexRegisterMapEntry& b) const {
497 if ((a.live_dex_registers_mask == nullptr) != (b.live_dex_registers_mask == nullptr)) {
Calin Juravlec416d332015-04-23 16:01:43 +0100498 return false;
499 }
500 if (a.num_dex_registers != b.num_dex_registers) {
501 return false;
502 }
Vladimir Marko225b6462015-09-28 12:17:40 +0100503 if (a.num_dex_registers != 0u) {
504 DCHECK(a.live_dex_registers_mask != nullptr);
505 DCHECK(b.live_dex_registers_mask != nullptr);
506 if (!a.live_dex_registers_mask->Equal(b.live_dex_registers_mask)) {
Calin Juravlec416d332015-04-23 16:01:43 +0100507 return false;
508 }
Vladimir Marko225b6462015-09-28 12:17:40 +0100509 size_t number_of_live_dex_registers = a.live_dex_registers_mask->NumSetBits();
510 DCHECK_LE(number_of_live_dex_registers, dex_register_locations_.size());
Mathieu Chartier32289082017-02-09 15:57:37 -0800511 DCHECK_LE(a.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 DCHECK_LE(b.locations_start_index,
Vladimir Marko225b6462015-09-28 12:17:40 +0100514 dex_register_locations_.size() - number_of_live_dex_registers);
Mathieu Chartier32289082017-02-09 15:57:37 -0800515 auto a_begin = dex_register_locations_.begin() + a.locations_start_index;
516 auto b_begin = dex_register_locations_.begin() + b.locations_start_index;
Vladimir Marko225b6462015-09-28 12:17:40 +0100517 if (!std::equal(a_begin, a_begin + number_of_live_dex_registers, b_begin)) {
518 return false;
Calin Juravlec416d332015-04-23 16:01:43 +0100519 }
520 }
521 return true;
522}
523
David Srbecky1bbdfd72016-02-24 16:39:26 +0000524// Helper for CheckCodeInfo - check that register map has the expected content.
525void StackMapStream::CheckDexRegisterMap(const CodeInfo& code_info,
526 const DexRegisterMap& dex_register_map,
527 size_t num_dex_registers,
528 BitVector* live_dex_registers_mask,
529 size_t dex_register_locations_index) const {
David Srbecky09ed0982016-02-12 21:58:43 +0000530 CodeInfoEncoding encoding = code_info.ExtractEncoding();
David Srbecky1bbdfd72016-02-24 16:39:26 +0000531 for (size_t reg = 0; reg < num_dex_registers; reg++) {
532 // Find the location we tried to encode.
533 DexRegisterLocation expected = DexRegisterLocation::None();
534 if (live_dex_registers_mask->IsBitSet(reg)) {
535 size_t catalog_index = dex_register_locations_[dex_register_locations_index++];
536 expected = location_catalog_entries_[catalog_index];
537 }
538 // Compare to the seen location.
539 if (expected.GetKind() == DexRegisterLocation::Kind::kNone) {
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800540 DCHECK(!dex_register_map.IsValid() || !dex_register_map.IsDexRegisterLive(reg))
541 << dex_register_map.IsValid() << " " << dex_register_map.IsDexRegisterLive(reg);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000542 } else {
543 DCHECK(dex_register_map.IsDexRegisterLive(reg));
544 DexRegisterLocation seen = dex_register_map.GetDexRegisterLocation(
545 reg, num_dex_registers, code_info, encoding);
546 DCHECK_EQ(expected.GetKind(), seen.GetKind());
547 DCHECK_EQ(expected.GetValue(), seen.GetValue());
548 }
549 }
550 if (num_dex_registers == 0) {
551 DCHECK(!dex_register_map.IsValid());
552 }
553}
554
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800555size_t StackMapStream::PrepareRegisterMasks() {
556 register_masks_.resize(stack_maps_.size(), 0u);
Vladimir Marko174b2e22017-10-12 13:34:49 +0100557 ScopedArenaUnorderedMap<uint32_t, size_t> dedupe(allocator_->Adapter(kArenaAllocStackMapStream));
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800558 for (StackMapEntry& stack_map : stack_maps_) {
559 const size_t index = dedupe.size();
560 stack_map.register_mask_index = dedupe.emplace(stack_map.register_mask, index).first->second;
561 register_masks_[index] = stack_map.register_mask;
562 }
563 return dedupe.size();
564}
565
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700566void StackMapStream::PrepareMethodIndices() {
567 CHECK(method_indices_.empty());
568 method_indices_.resize(stack_maps_.size() + inline_infos_.size());
Vladimir Marko174b2e22017-10-12 13:34:49 +0100569 ScopedArenaUnorderedMap<uint32_t, size_t> dedupe(allocator_->Adapter(kArenaAllocStackMapStream));
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700570 for (StackMapEntry& stack_map : stack_maps_) {
571 const size_t index = dedupe.size();
572 const uint32_t method_index = stack_map.dex_method_index;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700573 if (method_index != dex::kDexNoIndex) {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700574 stack_map.dex_method_index_idx = dedupe.emplace(method_index, index).first->second;
575 method_indices_[index] = method_index;
576 }
577 }
578 for (InlineInfoEntry& inline_info : inline_infos_) {
579 const size_t index = dedupe.size();
580 const uint32_t method_index = inline_info.method_index;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700581 CHECK_NE(method_index, dex::kDexNoIndex);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700582 inline_info.dex_method_index_idx = dedupe.emplace(method_index, index).first->second;
583 method_indices_[index] = method_index;
584 }
585 method_indices_.resize(dedupe.size());
586}
587
588
David Srbecky45aa5982016-03-18 02:15:09 +0000589size_t StackMapStream::PrepareStackMasks(size_t entry_size_in_bits) {
590 // Preallocate memory since we do not want it to move (the dedup map will point into it).
591 const size_t byte_entry_size = RoundUp(entry_size_in_bits, kBitsPerByte) / kBitsPerByte;
592 stack_masks_.resize(byte_entry_size * stack_maps_.size(), 0u);
593 // For deduplicating we store the stack masks as byte packed for simplicity. We can bit pack later
594 // when copying out from stack_masks_.
Vladimir Marko174b2e22017-10-12 13:34:49 +0100595 ScopedArenaUnorderedMap<MemoryRegion,
596 size_t,
597 FNVHash<MemoryRegion>,
598 MemoryRegion::ContentEquals> dedup(
599 stack_maps_.size(), allocator_->Adapter(kArenaAllocStackMapStream));
David Srbecky45aa5982016-03-18 02:15:09 +0000600 for (StackMapEntry& stack_map : stack_maps_) {
601 size_t index = dedup.size();
602 MemoryRegion stack_mask(stack_masks_.data() + index * byte_entry_size, byte_entry_size);
603 for (size_t i = 0; i < entry_size_in_bits; i++) {
604 stack_mask.StoreBit(i, stack_map.sp_mask != nullptr && stack_map.sp_mask->IsBitSet(i));
605 }
606 stack_map.stack_mask_index = dedup.emplace(stack_mask, index).first->second;
607 }
608 return dedup.size();
609}
610
David Srbecky1bbdfd72016-02-24 16:39:26 +0000611// Check that all StackMapStream inputs are correctly encoded by trying to read them back.
612void StackMapStream::CheckCodeInfo(MemoryRegion region) const {
613 CodeInfo code_info(region);
David Srbecky09ed0982016-02-12 21:58:43 +0000614 CodeInfoEncoding encoding = code_info.ExtractEncoding();
615 DCHECK_EQ(code_info.GetNumberOfStackMaps(encoding), stack_maps_.size());
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800616 size_t invoke_info_index = 0;
David Srbecky1bbdfd72016-02-24 16:39:26 +0000617 for (size_t s = 0; s < stack_maps_.size(); ++s) {
618 const StackMap stack_map = code_info.GetStackMapAt(s, encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800619 const StackMapEncoding& stack_map_encoding = encoding.stack_map.encoding;
David Srbecky1bbdfd72016-02-24 16:39:26 +0000620 StackMapEntry entry = stack_maps_[s];
621
622 // Check main stack map fields.
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800623 DCHECK_EQ(stack_map.GetNativePcOffset(stack_map_encoding, instruction_set_),
624 entry.native_pc_code_offset.Uint32Value(instruction_set_));
David Srbecky09ed0982016-02-12 21:58:43 +0000625 DCHECK_EQ(stack_map.GetDexPc(stack_map_encoding), entry.dex_pc);
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800626 DCHECK_EQ(stack_map.GetRegisterMaskIndex(stack_map_encoding), entry.register_mask_index);
627 DCHECK_EQ(code_info.GetRegisterMaskOf(encoding, stack_map), entry.register_mask);
David Srbecky45aa5982016-03-18 02:15:09 +0000628 const size_t num_stack_mask_bits = code_info.GetNumberOfStackMaskBits(encoding);
629 DCHECK_EQ(stack_map.GetStackMaskIndex(stack_map_encoding), entry.stack_mask_index);
630 BitMemoryRegion stack_mask = code_info.GetStackMaskOf(encoding, stack_map);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000631 if (entry.sp_mask != nullptr) {
David Srbecky45aa5982016-03-18 02:15:09 +0000632 DCHECK_GE(stack_mask.size_in_bits(), entry.sp_mask->GetNumberOfBits());
David Srbecky09ed0982016-02-12 21:58:43 +0000633 for (size_t b = 0; b < num_stack_mask_bits; b++) {
David Srbecky45aa5982016-03-18 02:15:09 +0000634 DCHECK_EQ(stack_mask.LoadBit(b), entry.sp_mask->IsBitSet(b));
David Srbecky1bbdfd72016-02-24 16:39:26 +0000635 }
636 } else {
David Srbecky09ed0982016-02-12 21:58:43 +0000637 for (size_t b = 0; b < num_stack_mask_bits; b++) {
David Srbecky45aa5982016-03-18 02:15:09 +0000638 DCHECK_EQ(stack_mask.LoadBit(b), 0u);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000639 }
640 }
Andreas Gampee2abbc62017-09-15 11:59:26 -0700641 if (entry.dex_method_index != dex::kDexNoIndex) {
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800642 InvokeInfo invoke_info = code_info.GetInvokeInfo(encoding, invoke_info_index);
643 DCHECK_EQ(invoke_info.GetNativePcOffset(encoding.invoke_info.encoding, instruction_set_),
644 entry.native_pc_code_offset.Uint32Value(instruction_set_));
645 DCHECK_EQ(invoke_info.GetInvokeType(encoding.invoke_info.encoding), entry.invoke_type);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700646 DCHECK_EQ(invoke_info.GetMethodIndexIdx(encoding.invoke_info.encoding),
647 entry.dex_method_index_idx);
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800648 invoke_info_index++;
649 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000650 CheckDexRegisterMap(code_info,
651 code_info.GetDexRegisterMapOf(
Mathieu Chartier32289082017-02-09 15:57:37 -0800652 stack_map, encoding, entry.dex_register_entry.num_dex_registers),
653 entry.dex_register_entry.num_dex_registers,
654 entry.dex_register_entry.live_dex_registers_mask,
655 entry.dex_register_entry.locations_start_index);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000656
657 // Check inline info.
David Srbecky09ed0982016-02-12 21:58:43 +0000658 DCHECK_EQ(stack_map.HasInlineInfo(stack_map_encoding), (entry.inlining_depth != 0));
David Srbecky1bbdfd72016-02-24 16:39:26 +0000659 if (entry.inlining_depth != 0) {
660 InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map, encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800661 DCHECK_EQ(inline_info.GetDepth(encoding.inline_info.encoding), entry.inlining_depth);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000662 for (size_t d = 0; d < entry.inlining_depth; ++d) {
663 size_t inline_info_index = entry.inline_infos_start_index + d;
664 DCHECK_LT(inline_info_index, inline_infos_.size());
665 InlineInfoEntry inline_entry = inline_infos_[inline_info_index];
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800666 DCHECK_EQ(inline_info.GetDexPcAtDepth(encoding.inline_info.encoding, d),
David Srbecky61b28a12016-02-25 21:55:03 +0000667 inline_entry.dex_pc);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800668 if (inline_info.EncodesArtMethodAtDepth(encoding.inline_info.encoding, d)) {
669 DCHECK_EQ(inline_info.GetArtMethodAtDepth(encoding.inline_info.encoding, d),
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000670 inline_entry.method);
671 } else {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700672 const size_t method_index_idx =
673 inline_info.GetMethodIndexIdxAtDepth(encoding.inline_info.encoding, d);
674 DCHECK_EQ(method_index_idx, inline_entry.dex_method_index_idx);
675 DCHECK_EQ(method_indices_[method_index_idx], inline_entry.method_index);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000676 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000677
678 CheckDexRegisterMap(code_info,
679 code_info.GetDexRegisterMapAtDepth(
Mathieu Chartier32289082017-02-09 15:57:37 -0800680 d,
681 inline_info,
682 encoding,
683 inline_entry.dex_register_entry.num_dex_registers),
684 inline_entry.dex_register_entry.num_dex_registers,
685 inline_entry.dex_register_entry.live_dex_registers_mask,
686 inline_entry.dex_register_entry.locations_start_index);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000687 }
688 }
689 }
690}
691
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700692size_t StackMapStream::ComputeMethodInfoSize() const {
693 DCHECK_NE(0u, needed_size_) << "PrepareForFillIn not called before " << __FUNCTION__;
694 return MethodInfo::ComputeSize(method_indices_.size());
695}
696
Calin Juravlec416d332015-04-23 16:01:43 +0100697} // namespace art