blob: 7eb2188a28b57824ca4414af359db1c2fe3c9a46 [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();
46 current_entry_.dex_register_entry.live_dex_registers_mask = (num_dex_registers != 0)
47 ? ArenaBitVector::Create(allocator_, num_dex_registers, true, kArenaAllocStackMapStream)
48 : nullptr;
Calin Juravlec416d332015-04-23 16:01:43 +010049 if (sp_mask != nullptr) {
50 stack_mask_max_ = std::max(stack_mask_max_, sp_mask->GetHighestBitSet());
51 }
52 if (inlining_depth > 0) {
53 number_of_stack_maps_with_inline_info_++;
54 }
55
56 dex_pc_max_ = std::max(dex_pc_max_, dex_pc);
Calin Juravlec416d332015-04-23 16:01:43 +010057 register_mask_max_ = std::max(register_mask_max_, register_mask);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010058 current_dex_register_ = 0;
Calin Juravlec416d332015-04-23 16:01:43 +010059}
60
Calin Juravle4f46ac52015-04-23 18:47:21 +010061void StackMapStream::EndStackMapEntry() {
Mathieu Chartier32289082017-02-09 15:57:37 -080062 current_entry_.dex_register_map_index = AddDexRegisterMapEntry(current_entry_.dex_register_entry);
Vladimir Marko225b6462015-09-28 12:17:40 +010063 stack_maps_.push_back(current_entry_);
Calin Juravle4f46ac52015-04-23 18:47:21 +010064 current_entry_ = StackMapEntry();
65}
66
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010067void StackMapStream::AddDexRegisterEntry(DexRegisterLocation::Kind kind, int32_t value) {
Calin Juravlec416d332015-04-23 16:01:43 +010068 if (kind != DexRegisterLocation::Kind::kNone) {
69 // Ensure we only use non-compressed location kind at this stage.
David Srbecky7dc11782016-02-25 13:23:56 +000070 DCHECK(DexRegisterLocation::IsShortLocationKind(kind)) << kind;
Calin Juravlec416d332015-04-23 16:01:43 +010071 DexRegisterLocation location(kind, value);
72
73 // Look for Dex register `location` in the location catalog (using the
74 // companion hash map of locations to indices). Use its index if it
75 // is already in the location catalog. If not, insert it (in the
76 // location catalog and the hash map) and use the newly created index.
77 auto it = location_catalog_entries_indices_.Find(location);
78 if (it != location_catalog_entries_indices_.end()) {
79 // Retrieve the index from the hash map.
Vladimir Marko225b6462015-09-28 12:17:40 +010080 dex_register_locations_.push_back(it->second);
Calin Juravlec416d332015-04-23 16:01:43 +010081 } else {
82 // Create a new entry in the location catalog and the hash map.
Vladimir Marko225b6462015-09-28 12:17:40 +010083 size_t index = location_catalog_entries_.size();
84 location_catalog_entries_.push_back(location);
85 dex_register_locations_.push_back(index);
Calin Juravlec416d332015-04-23 16:01:43 +010086 location_catalog_entries_indices_.Insert(std::make_pair(location, index));
87 }
Mathieu Chartier32289082017-02-09 15:57:37 -080088 DexRegisterMapEntry* const entry = in_inline_frame_
89 ? &current_inline_info_.dex_register_entry
90 : &current_entry_.dex_register_entry;
91 DCHECK_LT(current_dex_register_, entry->num_dex_registers);
92 entry->live_dex_registers_mask->SetBit(current_dex_register_);
93 entry->hash += (1 <<
94 (current_dex_register_ % (sizeof(DexRegisterMapEntry::hash) * kBitsPerByte)));
95 entry->hash += static_cast<uint32_t>(value);
96 entry->hash += static_cast<uint32_t>(kind);
Calin Juravlec416d332015-04-23 16:01:43 +010097 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010098 current_dex_register_++;
Calin Juravlec416d332015-04-23 16:01:43 +010099}
100
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800101void StackMapStream::AddInvoke(InvokeType invoke_type, uint32_t dex_method_index) {
102 current_entry_.invoke_type = invoke_type;
103 current_entry_.dex_method_index = dex_method_index;
104}
105
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000106void StackMapStream::BeginInlineInfoEntry(ArtMethod* method,
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100107 uint32_t dex_pc,
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000108 uint32_t num_dex_registers,
109 const DexFile* outer_dex_file) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100110 DCHECK(!in_inline_frame_);
111 in_inline_frame_ = true;
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000112 if (EncodeArtMethodInInlineInfo(method)) {
113 current_inline_info_.method = method;
114 } else {
115 if (dex_pc != static_cast<uint32_t>(-1) && kIsDebugBuild) {
116 ScopedObjectAccess soa(Thread::Current());
117 DCHECK(IsSameDexFile(*outer_dex_file, *method->GetDexFile()));
118 }
119 current_inline_info_.method_index = method->GetDexMethodIndexUnchecked();
120 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100121 current_inline_info_.dex_pc = dex_pc;
Mathieu Chartier32289082017-02-09 15:57:37 -0800122 current_inline_info_.dex_register_entry.num_dex_registers = num_dex_registers;
123 current_inline_info_.dex_register_entry.locations_start_index = dex_register_locations_.size();
124 current_inline_info_.dex_register_entry.live_dex_registers_mask = (num_dex_registers != 0)
125 ? ArenaBitVector::Create(allocator_, num_dex_registers, true, kArenaAllocStackMapStream)
126 : nullptr;
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100127 current_dex_register_ = 0;
128}
129
130void StackMapStream::EndInlineInfoEntry() {
Mathieu Chartier32289082017-02-09 15:57:37 -0800131 current_inline_info_.dex_register_map_index =
132 AddDexRegisterMapEntry(current_inline_info_.dex_register_entry);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100133 DCHECK(in_inline_frame_);
Mathieu Chartier32289082017-02-09 15:57:37 -0800134 DCHECK_EQ(current_dex_register_, current_inline_info_.dex_register_entry.num_dex_registers)
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100135 << "Inline information contains less registers than expected";
136 in_inline_frame_ = false;
Vladimir Marko225b6462015-09-28 12:17:40 +0100137 inline_infos_.push_back(current_inline_info_);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100138 current_inline_info_ = InlineInfoEntry();
Calin Juravlec416d332015-04-23 16:01:43 +0100139}
140
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800141CodeOffset StackMapStream::ComputeMaxNativePcCodeOffset() const {
142 CodeOffset max_native_pc_offset;
Vladimir Marko225b6462015-09-28 12:17:40 +0100143 for (const StackMapEntry& entry : stack_maps_) {
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800144 max_native_pc_offset = std::max(max_native_pc_offset, entry.native_pc_code_offset);
Vladimir Markobd8c7252015-06-12 10:06:32 +0100145 }
146 return max_native_pc_offset;
147}
148
Calin Juravle4f46ac52015-04-23 18:47:21 +0100149size_t StackMapStream::PrepareForFillIn() {
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800150 CodeInfoEncoding encoding;
151 encoding.dex_register_map.num_entries = 0; // TODO: Remove this field.
152 encoding.dex_register_map.num_bytes = ComputeDexRegisterMapsSize();
153 encoding.location_catalog.num_entries = location_catalog_entries_.size();
154 encoding.location_catalog.num_bytes = ComputeDexRegisterLocationCatalogSize();
155 encoding.inline_info.num_entries = inline_infos_.size();
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700156 // Must be done before calling ComputeInlineInfoEncoding since ComputeInlineInfoEncoding requires
157 // dex_method_index_idx to be filled in.
158 PrepareMethodIndices();
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800159 ComputeInlineInfoEncoding(&encoding.inline_info.encoding,
160 encoding.dex_register_map.num_bytes);
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800161 CodeOffset max_native_pc_offset = ComputeMaxNativePcCodeOffset();
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800162 // Prepare the CodeInfo variable-sized encoding.
163 encoding.stack_mask.encoding.num_bits = stack_mask_max_ + 1; // Need room for max element too.
164 encoding.stack_mask.num_entries = PrepareStackMasks(encoding.stack_mask.encoding.num_bits);
165 encoding.register_mask.encoding.num_bits = MinimumBitsToStore(register_mask_max_);
166 encoding.register_mask.num_entries = PrepareRegisterMasks();
167 encoding.stack_map.num_entries = stack_maps_.size();
168 encoding.stack_map.encoding.SetFromSizes(
169 // The stack map contains compressed native PC offsets.
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800170 max_native_pc_offset.CompressedValue(),
171 dex_pc_max_,
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800172 encoding.dex_register_map.num_bytes,
173 encoding.inline_info.num_entries,
174 encoding.register_mask.num_entries,
175 encoding.stack_mask.num_entries);
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800176 ComputeInvokeInfoEncoding(&encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800177 DCHECK_EQ(code_info_encoding_.size(), 0u);
178 encoding.Compress(&code_info_encoding_);
179 encoding.ComputeTableOffsets();
180 // Compute table offsets so we can get the non header size.
181 DCHECK_EQ(encoding.HeaderSize(), code_info_encoding_.size());
182 needed_size_ = code_info_encoding_.size() + encoding.NonHeaderSize();
Calin Juravle4f46ac52015-04-23 18:47:21 +0100183 return needed_size_;
Calin Juravlec416d332015-04-23 16:01:43 +0100184}
185
186size_t StackMapStream::ComputeDexRegisterLocationCatalogSize() const {
187 size_t size = DexRegisterLocationCatalog::kFixedSize;
Vladimir Marko225b6462015-09-28 12:17:40 +0100188 for (const DexRegisterLocation& dex_register_location : location_catalog_entries_) {
Calin Juravlec416d332015-04-23 16:01:43 +0100189 size += DexRegisterLocationCatalog::EntrySize(dex_register_location);
190 }
191 return size;
192}
193
Mathieu Chartier32289082017-02-09 15:57:37 -0800194size_t StackMapStream::DexRegisterMapEntry::ComputeSize(size_t catalog_size) const {
Vladimir Marko225b6462015-09-28 12:17:40 +0100195 // For num_dex_registers == 0u live_dex_registers_mask may be null.
196 if (num_dex_registers == 0u) {
197 return 0u; // No register map will be emitted.
198 }
199 DCHECK(live_dex_registers_mask != nullptr);
200
Calin Juravlec416d332015-04-23 16:01:43 +0100201 // Size of the map in bytes.
202 size_t size = DexRegisterMap::kFixedSize;
203 // Add the live bit mask for the Dex register liveness.
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100204 size += DexRegisterMap::GetLiveBitMaskSize(num_dex_registers);
Calin Juravlec416d332015-04-23 16:01:43 +0100205 // Compute the size of the set of live Dex register entries.
Vladimir Marko225b6462015-09-28 12:17:40 +0100206 size_t number_of_live_dex_registers = live_dex_registers_mask->NumSetBits();
Calin Juravlec416d332015-04-23 16:01:43 +0100207 size_t map_entries_size_in_bits =
Mathieu Chartier32289082017-02-09 15:57:37 -0800208 DexRegisterMap::SingleEntrySizeInBits(catalog_size) * number_of_live_dex_registers;
Calin Juravlec416d332015-04-23 16:01:43 +0100209 size_t map_entries_size_in_bytes =
210 RoundUp(map_entries_size_in_bits, kBitsPerByte) / kBitsPerByte;
211 size += map_entries_size_in_bytes;
212 return size;
213}
214
Calin Juravle4f46ac52015-04-23 18:47:21 +0100215size_t StackMapStream::ComputeDexRegisterMapsSize() const {
Calin Juravlec416d332015-04-23 16:01:43 +0100216 size_t size = 0;
Mathieu Chartier32289082017-02-09 15:57:37 -0800217 for (const DexRegisterMapEntry& entry : dex_register_entries_) {
218 size += entry.ComputeSize(location_catalog_entries_.size());
Calin Juravlec416d332015-04-23 16:01:43 +0100219 }
220 return size;
221}
222
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800223void StackMapStream::ComputeInvokeInfoEncoding(CodeInfoEncoding* encoding) {
224 DCHECK(encoding != nullptr);
225 uint32_t native_pc_max = 0;
226 uint16_t method_index_max = 0;
227 size_t invoke_infos_count = 0;
228 size_t invoke_type_max = 0;
229 for (const StackMapEntry& entry : stack_maps_) {
Andreas Gampee2abbc62017-09-15 11:59:26 -0700230 if (entry.dex_method_index != dex::kDexNoIndex) {
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800231 native_pc_max = std::max(native_pc_max, entry.native_pc_code_offset.CompressedValue());
232 method_index_max = std::max(method_index_max, static_cast<uint16_t>(entry.dex_method_index));
233 invoke_type_max = std::max(invoke_type_max, static_cast<size_t>(entry.invoke_type));
234 ++invoke_infos_count;
235 }
236 }
237 encoding->invoke_info.num_entries = invoke_infos_count;
238 encoding->invoke_info.encoding.SetFromSizes(native_pc_max, invoke_type_max, method_index_max);
239}
240
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800241void StackMapStream::ComputeInlineInfoEncoding(InlineInfoEncoding* encoding,
242 size_t dex_register_maps_bytes) {
David Srbecky61b28a12016-02-25 21:55:03 +0000243 uint32_t method_index_max = 0;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700244 uint32_t dex_pc_max = dex::kDexNoIndex;
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000245 uint32_t extra_data_max = 0;
David Srbecky61b28a12016-02-25 21:55:03 +0000246
247 uint32_t inline_info_index = 0;
248 for (const StackMapEntry& entry : stack_maps_) {
249 for (size_t j = 0; j < entry.inlining_depth; ++j) {
250 InlineInfoEntry inline_entry = inline_infos_[inline_info_index++];
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000251 if (inline_entry.method == nullptr) {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700252 method_index_max = std::max(method_index_max, inline_entry.dex_method_index_idx);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000253 extra_data_max = std::max(extra_data_max, 1u);
254 } else {
255 method_index_max = std::max(
256 method_index_max, High32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
257 extra_data_max = std::max(
258 extra_data_max, Low32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
259 }
Andreas Gampee2abbc62017-09-15 11:59:26 -0700260 if (inline_entry.dex_pc != dex::kDexNoIndex &&
261 (dex_pc_max == dex::kDexNoIndex || dex_pc_max < inline_entry.dex_pc)) {
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100262 dex_pc_max = inline_entry.dex_pc;
263 }
David Srbecky61b28a12016-02-25 21:55:03 +0000264 }
265 }
266 DCHECK_EQ(inline_info_index, inline_infos_.size());
267
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800268 encoding->SetFromSizes(method_index_max, dex_pc_max, extra_data_max, dex_register_maps_bytes);
Calin Juravlec416d332015-04-23 16:01:43 +0100269}
270
Mathieu Chartier32289082017-02-09 15:57:37 -0800271size_t StackMapStream::MaybeCopyDexRegisterMap(DexRegisterMapEntry& entry,
272 size_t* current_offset,
273 MemoryRegion dex_register_locations_region) {
274 DCHECK(current_offset != nullptr);
275 if ((entry.num_dex_registers == 0) || (entry.live_dex_registers_mask->NumSetBits() == 0)) {
276 // No dex register map needed.
277 return StackMap::kNoDexRegisterMap;
278 }
279 if (entry.offset == DexRegisterMapEntry::kOffsetUnassigned) {
280 // Not already copied, need to copy and and assign an offset.
281 entry.offset = *current_offset;
282 const size_t entry_size = entry.ComputeSize(location_catalog_entries_.size());
283 DexRegisterMap dex_register_map(
284 dex_register_locations_region.Subregion(entry.offset, entry_size));
285 *current_offset += entry_size;
286 // Fill in the map since it was just added.
287 FillInDexRegisterMap(dex_register_map,
288 entry.num_dex_registers,
289 *entry.live_dex_registers_mask,
290 entry.locations_start_index);
291 }
292 return entry.offset;
293}
294
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700295void StackMapStream::FillInMethodInfo(MemoryRegion region) {
296 {
297 MethodInfo info(region.begin(), method_indices_.size());
298 for (size_t i = 0; i < method_indices_.size(); ++i) {
299 info.SetMethodIndex(i, method_indices_[i]);
300 }
301 }
302 if (kIsDebugBuild) {
303 // Check the data matches.
304 MethodInfo info(region.begin());
305 const size_t count = info.NumMethodIndices();
306 DCHECK_EQ(count, method_indices_.size());
307 for (size_t i = 0; i < count; ++i) {
308 DCHECK_EQ(info.GetMethodIndex(i), method_indices_[i]);
309 }
310 }
311}
312
313void StackMapStream::FillInCodeInfo(MemoryRegion region) {
Calin Juravle4f46ac52015-04-23 18:47:21 +0100314 DCHECK_EQ(0u, current_entry_.dex_pc) << "EndStackMapEntry not called after BeginStackMapEntry";
315 DCHECK_NE(0u, needed_size_) << "PrepareForFillIn not called before FillIn";
316
Calin Juravle4f46ac52015-04-23 18:47:21 +0100317 DCHECK_EQ(region.size(), needed_size_);
David Srbecky09ed0982016-02-12 21:58:43 +0000318
319 // Note that the memory region does not have to be zeroed when we JIT code
320 // because we do not use the arena allocator there.
321
322 // Write the CodeInfo header.
323 region.CopyFrom(0, MemoryRegion(code_info_encoding_.data(), code_info_encoding_.size()));
Calin Juravlec416d332015-04-23 16:01:43 +0100324
David Srbecky09ed0982016-02-12 21:58:43 +0000325 CodeInfo code_info(region);
326 CodeInfoEncoding encoding = code_info.ExtractEncoding();
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800327 DCHECK_EQ(encoding.stack_map.num_entries, stack_maps_.size());
328
329 MemoryRegion dex_register_locations_region = region.Subregion(
330 encoding.dex_register_map.byte_offset,
331 encoding.dex_register_map.num_bytes);
Calin Juravlec416d332015-04-23 16:01:43 +0100332
333 // Set the Dex register location catalog.
Calin Juravlec416d332015-04-23 16:01:43 +0100334 MemoryRegion dex_register_location_catalog_region = region.Subregion(
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800335 encoding.location_catalog.byte_offset,
336 encoding.location_catalog.num_bytes);
Calin Juravlec416d332015-04-23 16:01:43 +0100337 DexRegisterLocationCatalog dex_register_location_catalog(dex_register_location_catalog_region);
338 // Offset in `dex_register_location_catalog` where to store the next
339 // register location.
340 size_t location_catalog_offset = DexRegisterLocationCatalog::kFixedSize;
Vladimir Marko225b6462015-09-28 12:17:40 +0100341 for (DexRegisterLocation dex_register_location : location_catalog_entries_) {
Calin Juravlec416d332015-04-23 16:01:43 +0100342 dex_register_location_catalog.SetRegisterInfo(location_catalog_offset, dex_register_location);
343 location_catalog_offset += DexRegisterLocationCatalog::EntrySize(dex_register_location);
344 }
345 // Ensure we reached the end of the Dex registers location_catalog.
346 DCHECK_EQ(location_catalog_offset, dex_register_location_catalog_region.size());
347
Vladimir Markof6a35de2016-03-21 12:01:50 +0000348 ArenaBitVector empty_bitmask(allocator_, 0, /* expandable */ false, kArenaAllocStackMapStream);
Calin Juravlec416d332015-04-23 16:01:43 +0100349 uintptr_t next_dex_register_map_offset = 0;
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800350 uintptr_t next_inline_info_index = 0;
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800351 size_t invoke_info_idx = 0;
Vladimir Marko225b6462015-09-28 12:17:40 +0100352 for (size_t i = 0, e = stack_maps_.size(); i < e; ++i) {
David Srbecky09ed0982016-02-12 21:58:43 +0000353 StackMap stack_map = code_info.GetStackMapAt(i, encoding);
Vladimir Marko225b6462015-09-28 12:17:40 +0100354 StackMapEntry entry = stack_maps_[i];
Calin Juravlec416d332015-04-23 16:01:43 +0100355
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800356 stack_map.SetDexPc(encoding.stack_map.encoding, entry.dex_pc);
357 stack_map.SetNativePcCodeOffset(encoding.stack_map.encoding, entry.native_pc_code_offset);
358 stack_map.SetRegisterMaskIndex(encoding.stack_map.encoding, entry.register_mask_index);
359 stack_map.SetStackMaskIndex(encoding.stack_map.encoding, entry.stack_mask_index);
Calin Juravlec416d332015-04-23 16:01:43 +0100360
Mathieu Chartier32289082017-02-09 15:57:37 -0800361 size_t offset = MaybeCopyDexRegisterMap(dex_register_entries_[entry.dex_register_map_index],
362 &next_dex_register_map_offset,
363 dex_register_locations_region);
364 stack_map.SetDexRegisterMapOffset(encoding.stack_map.encoding, offset);
Calin Juravlec416d332015-04-23 16:01:43 +0100365
Andreas Gampee2abbc62017-09-15 11:59:26 -0700366 if (entry.dex_method_index != dex::kDexNoIndex) {
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800367 InvokeInfo invoke_info(code_info.GetInvokeInfo(encoding, invoke_info_idx));
368 invoke_info.SetNativePcCodeOffset(encoding.invoke_info.encoding, entry.native_pc_code_offset);
369 invoke_info.SetInvokeType(encoding.invoke_info.encoding, entry.invoke_type);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700370 invoke_info.SetMethodIndexIdx(encoding.invoke_info.encoding, entry.dex_method_index_idx);
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800371 ++invoke_info_idx;
372 }
373
Calin Juravlec416d332015-04-23 16:01:43 +0100374 // Set the inlining info.
375 if (entry.inlining_depth != 0) {
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800376 InlineInfo inline_info = code_info.GetInlineInfo(next_inline_info_index, encoding);
Calin Juravlec416d332015-04-23 16:01:43 +0100377
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800378 // Fill in the index.
379 stack_map.SetInlineInfoIndex(encoding.stack_map.encoding, next_inline_info_index);
380 DCHECK_EQ(next_inline_info_index, entry.inline_infos_start_index);
381 next_inline_info_index += entry.inlining_depth;
Calin Juravlec416d332015-04-23 16:01:43 +0100382
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800383 inline_info.SetDepth(encoding.inline_info.encoding, entry.inlining_depth);
Vladimir Marko225b6462015-09-28 12:17:40 +0100384 DCHECK_LE(entry.inline_infos_start_index + entry.inlining_depth, inline_infos_.size());
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800385
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100386 for (size_t depth = 0; depth < entry.inlining_depth; ++depth) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100387 InlineInfoEntry inline_entry = inline_infos_[depth + entry.inline_infos_start_index];
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000388 if (inline_entry.method != nullptr) {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700389 inline_info.SetMethodIndexIdxAtDepth(
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800390 encoding.inline_info.encoding,
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000391 depth,
392 High32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
393 inline_info.SetExtraDataAtDepth(
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800394 encoding.inline_info.encoding,
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000395 depth,
396 Low32Bits(reinterpret_cast<uintptr_t>(inline_entry.method)));
397 } else {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700398 inline_info.SetMethodIndexIdxAtDepth(encoding.inline_info.encoding,
399 depth,
400 inline_entry.dex_method_index_idx);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800401 inline_info.SetExtraDataAtDepth(encoding.inline_info.encoding, depth, 1);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000402 }
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800403 inline_info.SetDexPcAtDepth(encoding.inline_info.encoding, depth, inline_entry.dex_pc);
Mathieu Chartier32289082017-02-09 15:57:37 -0800404 size_t dex_register_map_offset = MaybeCopyDexRegisterMap(
405 dex_register_entries_[inline_entry.dex_register_map_index],
406 &next_dex_register_map_offset,
407 dex_register_locations_region);
408 inline_info.SetDexRegisterMapOffsetAtDepth(encoding.inline_info.encoding,
409 depth,
410 dex_register_map_offset);
Calin Juravlec416d332015-04-23 16:01:43 +0100411 }
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800412 } else if (encoding.stack_map.encoding.GetInlineInfoEncoding().BitSize() > 0) {
413 stack_map.SetInlineInfoIndex(encoding.stack_map.encoding, StackMap::kNoInlineInfo);
Calin Juravlec416d332015-04-23 16:01:43 +0100414 }
415 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000416
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800417 // Write stack masks table.
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800418 const size_t stack_mask_bits = encoding.stack_mask.encoding.BitSize();
David Srbecky45aa5982016-03-18 02:15:09 +0000419 if (stack_mask_bits > 0) {
420 size_t stack_mask_bytes = RoundUp(stack_mask_bits, kBitsPerByte) / kBitsPerByte;
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800421 for (size_t i = 0; i < encoding.stack_mask.num_entries; ++i) {
David Srbecky45aa5982016-03-18 02:15:09 +0000422 MemoryRegion source(&stack_masks_[i * stack_mask_bytes], stack_mask_bytes);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800423 BitMemoryRegion stack_mask = code_info.GetStackMask(i, encoding);
424 for (size_t bit_index = 0; bit_index < stack_mask_bits; ++bit_index) {
David Srbecky45aa5982016-03-18 02:15:09 +0000425 stack_mask.StoreBit(bit_index, source.LoadBit(bit_index));
426 }
427 }
428 }
429
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800430 // Write register masks table.
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800431 for (size_t i = 0; i < encoding.register_mask.num_entries; ++i) {
432 BitMemoryRegion register_mask = code_info.GetRegisterMask(i, encoding);
433 register_mask.StoreBits(0, register_masks_[i], encoding.register_mask.encoding.BitSize());
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800434 }
435
David Srbecky1bbdfd72016-02-24 16:39:26 +0000436 // Verify all written data in debug build.
437 if (kIsDebugBuild) {
438 CheckCodeInfo(region);
439 }
Calin Juravlec416d332015-04-23 16:01:43 +0100440}
441
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100442void StackMapStream::FillInDexRegisterMap(DexRegisterMap dex_register_map,
443 uint32_t num_dex_registers,
444 const BitVector& live_dex_registers_mask,
445 uint32_t start_index_in_dex_register_locations) const {
446 dex_register_map.SetLiveBitMask(num_dex_registers, live_dex_registers_mask);
447 // Set the dex register location mapping data.
Vladimir Marko225b6462015-09-28 12:17:40 +0100448 size_t number_of_live_dex_registers = live_dex_registers_mask.NumSetBits();
449 DCHECK_LE(number_of_live_dex_registers, dex_register_locations_.size());
450 DCHECK_LE(start_index_in_dex_register_locations,
451 dex_register_locations_.size() - number_of_live_dex_registers);
452 for (size_t index_in_dex_register_locations = 0;
453 index_in_dex_register_locations != number_of_live_dex_registers;
454 ++index_in_dex_register_locations) {
455 size_t location_catalog_entry_index = dex_register_locations_[
456 start_index_in_dex_register_locations + index_in_dex_register_locations];
457 dex_register_map.SetLocationCatalogEntryIndex(
458 index_in_dex_register_locations,
459 location_catalog_entry_index,
460 num_dex_registers,
461 location_catalog_entries_.size());
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100462 }
463}
464
Mathieu Chartier32289082017-02-09 15:57:37 -0800465size_t StackMapStream::AddDexRegisterMapEntry(const DexRegisterMapEntry& entry) {
466 const size_t current_entry_index = dex_register_entries_.size();
467 auto entries_it = dex_map_hash_to_stack_map_indices_.find(entry.hash);
Calin Juravlec416d332015-04-23 16:01:43 +0100468 if (entries_it == dex_map_hash_to_stack_map_indices_.end()) {
469 // We don't have a perfect hash functions so we need a list to collect all stack maps
470 // which might have the same dex register map.
Vladimir Marko225b6462015-09-28 12:17:40 +0100471 ArenaVector<uint32_t> stack_map_indices(allocator_->Adapter(kArenaAllocStackMapStream));
472 stack_map_indices.push_back(current_entry_index);
Mathieu Chartier32289082017-02-09 15:57:37 -0800473 dex_map_hash_to_stack_map_indices_.Put(entry.hash, std::move(stack_map_indices));
474 } else {
475 // We might have collisions, so we need to check whether or not we really have a match.
476 for (uint32_t test_entry_index : entries_it->second) {
477 if (DexRegisterMapEntryEquals(dex_register_entries_[test_entry_index], entry)) {
478 return test_entry_index;
479 }
Calin Juravlec416d332015-04-23 16:01:43 +0100480 }
Mathieu Chartier32289082017-02-09 15:57:37 -0800481 entries_it->second.push_back(current_entry_index);
Calin Juravlec416d332015-04-23 16:01:43 +0100482 }
Mathieu Chartier32289082017-02-09 15:57:37 -0800483 dex_register_entries_.push_back(entry);
484 return current_entry_index;
Calin Juravlec416d332015-04-23 16:01:43 +0100485}
486
Mathieu Chartier32289082017-02-09 15:57:37 -0800487bool StackMapStream::DexRegisterMapEntryEquals(const DexRegisterMapEntry& a,
488 const DexRegisterMapEntry& b) const {
489 if ((a.live_dex_registers_mask == nullptr) != (b.live_dex_registers_mask == nullptr)) {
Calin Juravlec416d332015-04-23 16:01:43 +0100490 return false;
491 }
492 if (a.num_dex_registers != b.num_dex_registers) {
493 return false;
494 }
Vladimir Marko225b6462015-09-28 12:17:40 +0100495 if (a.num_dex_registers != 0u) {
496 DCHECK(a.live_dex_registers_mask != nullptr);
497 DCHECK(b.live_dex_registers_mask != nullptr);
498 if (!a.live_dex_registers_mask->Equal(b.live_dex_registers_mask)) {
Calin Juravlec416d332015-04-23 16:01:43 +0100499 return false;
500 }
Vladimir Marko225b6462015-09-28 12:17:40 +0100501 size_t number_of_live_dex_registers = a.live_dex_registers_mask->NumSetBits();
502 DCHECK_LE(number_of_live_dex_registers, dex_register_locations_.size());
Mathieu Chartier32289082017-02-09 15:57:37 -0800503 DCHECK_LE(a.locations_start_index,
Vladimir Marko225b6462015-09-28 12:17:40 +0100504 dex_register_locations_.size() - number_of_live_dex_registers);
Mathieu Chartier32289082017-02-09 15:57:37 -0800505 DCHECK_LE(b.locations_start_index,
Vladimir Marko225b6462015-09-28 12:17:40 +0100506 dex_register_locations_.size() - number_of_live_dex_registers);
Mathieu Chartier32289082017-02-09 15:57:37 -0800507 auto a_begin = dex_register_locations_.begin() + a.locations_start_index;
508 auto b_begin = dex_register_locations_.begin() + b.locations_start_index;
Vladimir Marko225b6462015-09-28 12:17:40 +0100509 if (!std::equal(a_begin, a_begin + number_of_live_dex_registers, b_begin)) {
510 return false;
Calin Juravlec416d332015-04-23 16:01:43 +0100511 }
512 }
513 return true;
514}
515
David Srbecky1bbdfd72016-02-24 16:39:26 +0000516// Helper for CheckCodeInfo - check that register map has the expected content.
517void StackMapStream::CheckDexRegisterMap(const CodeInfo& code_info,
518 const DexRegisterMap& dex_register_map,
519 size_t num_dex_registers,
520 BitVector* live_dex_registers_mask,
521 size_t dex_register_locations_index) const {
David Srbecky09ed0982016-02-12 21:58:43 +0000522 CodeInfoEncoding encoding = code_info.ExtractEncoding();
David Srbecky1bbdfd72016-02-24 16:39:26 +0000523 for (size_t reg = 0; reg < num_dex_registers; reg++) {
524 // Find the location we tried to encode.
525 DexRegisterLocation expected = DexRegisterLocation::None();
526 if (live_dex_registers_mask->IsBitSet(reg)) {
527 size_t catalog_index = dex_register_locations_[dex_register_locations_index++];
528 expected = location_catalog_entries_[catalog_index];
529 }
530 // Compare to the seen location.
531 if (expected.GetKind() == DexRegisterLocation::Kind::kNone) {
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800532 DCHECK(!dex_register_map.IsValid() || !dex_register_map.IsDexRegisterLive(reg))
533 << dex_register_map.IsValid() << " " << dex_register_map.IsDexRegisterLive(reg);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000534 } else {
535 DCHECK(dex_register_map.IsDexRegisterLive(reg));
536 DexRegisterLocation seen = dex_register_map.GetDexRegisterLocation(
537 reg, num_dex_registers, code_info, encoding);
538 DCHECK_EQ(expected.GetKind(), seen.GetKind());
539 DCHECK_EQ(expected.GetValue(), seen.GetValue());
540 }
541 }
542 if (num_dex_registers == 0) {
543 DCHECK(!dex_register_map.IsValid());
544 }
545}
546
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800547size_t StackMapStream::PrepareRegisterMasks() {
548 register_masks_.resize(stack_maps_.size(), 0u);
Vladimir Marko9c571132017-02-22 11:59:57 +0000549 ArenaUnorderedMap<uint32_t, size_t> dedupe(allocator_->Adapter(kArenaAllocStackMapStream));
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800550 for (StackMapEntry& stack_map : stack_maps_) {
551 const size_t index = dedupe.size();
552 stack_map.register_mask_index = dedupe.emplace(stack_map.register_mask, index).first->second;
553 register_masks_[index] = stack_map.register_mask;
554 }
555 return dedupe.size();
556}
557
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700558void StackMapStream::PrepareMethodIndices() {
559 CHECK(method_indices_.empty());
560 method_indices_.resize(stack_maps_.size() + inline_infos_.size());
561 ArenaUnorderedMap<uint32_t, size_t> dedupe(allocator_->Adapter(kArenaAllocStackMapStream));
562 for (StackMapEntry& stack_map : stack_maps_) {
563 const size_t index = dedupe.size();
564 const uint32_t method_index = stack_map.dex_method_index;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700565 if (method_index != dex::kDexNoIndex) {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700566 stack_map.dex_method_index_idx = dedupe.emplace(method_index, index).first->second;
567 method_indices_[index] = method_index;
568 }
569 }
570 for (InlineInfoEntry& inline_info : inline_infos_) {
571 const size_t index = dedupe.size();
572 const uint32_t method_index = inline_info.method_index;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700573 CHECK_NE(method_index, dex::kDexNoIndex);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700574 inline_info.dex_method_index_idx = dedupe.emplace(method_index, index).first->second;
575 method_indices_[index] = method_index;
576 }
577 method_indices_.resize(dedupe.size());
578}
579
580
David Srbecky45aa5982016-03-18 02:15:09 +0000581size_t StackMapStream::PrepareStackMasks(size_t entry_size_in_bits) {
582 // Preallocate memory since we do not want it to move (the dedup map will point into it).
583 const size_t byte_entry_size = RoundUp(entry_size_in_bits, kBitsPerByte) / kBitsPerByte;
584 stack_masks_.resize(byte_entry_size * stack_maps_.size(), 0u);
585 // For deduplicating we store the stack masks as byte packed for simplicity. We can bit pack later
586 // when copying out from stack_masks_.
Vladimir Marko9c571132017-02-22 11:59:57 +0000587 ArenaUnorderedMap<MemoryRegion,
588 size_t,
589 FNVHash<MemoryRegion>,
590 MemoryRegion::ContentEquals> dedup(
591 stack_maps_.size(), allocator_->Adapter(kArenaAllocStackMapStream));
David Srbecky45aa5982016-03-18 02:15:09 +0000592 for (StackMapEntry& stack_map : stack_maps_) {
593 size_t index = dedup.size();
594 MemoryRegion stack_mask(stack_masks_.data() + index * byte_entry_size, byte_entry_size);
595 for (size_t i = 0; i < entry_size_in_bits; i++) {
596 stack_mask.StoreBit(i, stack_map.sp_mask != nullptr && stack_map.sp_mask->IsBitSet(i));
597 }
598 stack_map.stack_mask_index = dedup.emplace(stack_mask, index).first->second;
599 }
600 return dedup.size();
601}
602
David Srbecky1bbdfd72016-02-24 16:39:26 +0000603// Check that all StackMapStream inputs are correctly encoded by trying to read them back.
604void StackMapStream::CheckCodeInfo(MemoryRegion region) const {
605 CodeInfo code_info(region);
David Srbecky09ed0982016-02-12 21:58:43 +0000606 CodeInfoEncoding encoding = code_info.ExtractEncoding();
607 DCHECK_EQ(code_info.GetNumberOfStackMaps(encoding), stack_maps_.size());
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800608 size_t invoke_info_index = 0;
David Srbecky1bbdfd72016-02-24 16:39:26 +0000609 for (size_t s = 0; s < stack_maps_.size(); ++s) {
610 const StackMap stack_map = code_info.GetStackMapAt(s, encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800611 const StackMapEncoding& stack_map_encoding = encoding.stack_map.encoding;
David Srbecky1bbdfd72016-02-24 16:39:26 +0000612 StackMapEntry entry = stack_maps_[s];
613
614 // Check main stack map fields.
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800615 DCHECK_EQ(stack_map.GetNativePcOffset(stack_map_encoding, instruction_set_),
616 entry.native_pc_code_offset.Uint32Value(instruction_set_));
David Srbecky09ed0982016-02-12 21:58:43 +0000617 DCHECK_EQ(stack_map.GetDexPc(stack_map_encoding), entry.dex_pc);
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800618 DCHECK_EQ(stack_map.GetRegisterMaskIndex(stack_map_encoding), entry.register_mask_index);
619 DCHECK_EQ(code_info.GetRegisterMaskOf(encoding, stack_map), entry.register_mask);
David Srbecky45aa5982016-03-18 02:15:09 +0000620 const size_t num_stack_mask_bits = code_info.GetNumberOfStackMaskBits(encoding);
621 DCHECK_EQ(stack_map.GetStackMaskIndex(stack_map_encoding), entry.stack_mask_index);
622 BitMemoryRegion stack_mask = code_info.GetStackMaskOf(encoding, stack_map);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000623 if (entry.sp_mask != nullptr) {
David Srbecky45aa5982016-03-18 02:15:09 +0000624 DCHECK_GE(stack_mask.size_in_bits(), entry.sp_mask->GetNumberOfBits());
David Srbecky09ed0982016-02-12 21:58:43 +0000625 for (size_t b = 0; b < num_stack_mask_bits; b++) {
David Srbecky45aa5982016-03-18 02:15:09 +0000626 DCHECK_EQ(stack_mask.LoadBit(b), entry.sp_mask->IsBitSet(b));
David Srbecky1bbdfd72016-02-24 16:39:26 +0000627 }
628 } else {
David Srbecky09ed0982016-02-12 21:58:43 +0000629 for (size_t b = 0; b < num_stack_mask_bits; b++) {
David Srbecky45aa5982016-03-18 02:15:09 +0000630 DCHECK_EQ(stack_mask.LoadBit(b), 0u);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000631 }
632 }
Andreas Gampee2abbc62017-09-15 11:59:26 -0700633 if (entry.dex_method_index != dex::kDexNoIndex) {
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800634 InvokeInfo invoke_info = code_info.GetInvokeInfo(encoding, invoke_info_index);
635 DCHECK_EQ(invoke_info.GetNativePcOffset(encoding.invoke_info.encoding, instruction_set_),
636 entry.native_pc_code_offset.Uint32Value(instruction_set_));
637 DCHECK_EQ(invoke_info.GetInvokeType(encoding.invoke_info.encoding), entry.invoke_type);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700638 DCHECK_EQ(invoke_info.GetMethodIndexIdx(encoding.invoke_info.encoding),
639 entry.dex_method_index_idx);
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800640 invoke_info_index++;
641 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000642 CheckDexRegisterMap(code_info,
643 code_info.GetDexRegisterMapOf(
Mathieu Chartier32289082017-02-09 15:57:37 -0800644 stack_map, encoding, entry.dex_register_entry.num_dex_registers),
645 entry.dex_register_entry.num_dex_registers,
646 entry.dex_register_entry.live_dex_registers_mask,
647 entry.dex_register_entry.locations_start_index);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000648
649 // Check inline info.
David Srbecky09ed0982016-02-12 21:58:43 +0000650 DCHECK_EQ(stack_map.HasInlineInfo(stack_map_encoding), (entry.inlining_depth != 0));
David Srbecky1bbdfd72016-02-24 16:39:26 +0000651 if (entry.inlining_depth != 0) {
652 InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map, encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800653 DCHECK_EQ(inline_info.GetDepth(encoding.inline_info.encoding), entry.inlining_depth);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000654 for (size_t d = 0; d < entry.inlining_depth; ++d) {
655 size_t inline_info_index = entry.inline_infos_start_index + d;
656 DCHECK_LT(inline_info_index, inline_infos_.size());
657 InlineInfoEntry inline_entry = inline_infos_[inline_info_index];
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800658 DCHECK_EQ(inline_info.GetDexPcAtDepth(encoding.inline_info.encoding, d),
David Srbecky61b28a12016-02-25 21:55:03 +0000659 inline_entry.dex_pc);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800660 if (inline_info.EncodesArtMethodAtDepth(encoding.inline_info.encoding, d)) {
661 DCHECK_EQ(inline_info.GetArtMethodAtDepth(encoding.inline_info.encoding, d),
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000662 inline_entry.method);
663 } else {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700664 const size_t method_index_idx =
665 inline_info.GetMethodIndexIdxAtDepth(encoding.inline_info.encoding, d);
666 DCHECK_EQ(method_index_idx, inline_entry.dex_method_index_idx);
667 DCHECK_EQ(method_indices_[method_index_idx], inline_entry.method_index);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000668 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000669
670 CheckDexRegisterMap(code_info,
671 code_info.GetDexRegisterMapAtDepth(
Mathieu Chartier32289082017-02-09 15:57:37 -0800672 d,
673 inline_info,
674 encoding,
675 inline_entry.dex_register_entry.num_dex_registers),
676 inline_entry.dex_register_entry.num_dex_registers,
677 inline_entry.dex_register_entry.live_dex_registers_mask,
678 inline_entry.dex_register_entry.locations_start_index);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000679 }
680 }
681 }
682}
683
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700684size_t StackMapStream::ComputeMethodInfoSize() const {
685 DCHECK_NE(0u, needed_size_) << "PrepareForFillIn not called before " << __FUNCTION__;
686 return MethodInfo::ComputeSize(method_indices_.size());
687}
688
Calin Juravlec416d332015-04-23 16:01:43 +0100689} // namespace art