blob: bf7c5542ef99719643ebb505aefc8ed5bf2f9cb8 [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 Srbecky68fefac2018-05-10 17:49:33 +0100430 BitMemoryRegion src(MemoryRegion(&stack_masks_[i * stack_mask_bytes], stack_mask_bytes));
431 BitMemoryRegion dst = code_info.GetStackMask(i, encoding);
432 for (size_t bit_index = 0; bit_index < stack_mask_bits; bit_index += BitSizeOf<uint32_t>()) {
433 size_t num_bits = std::min<size_t>(stack_mask_bits - bit_index, BitSizeOf<uint32_t>());
434 dst.StoreBits(bit_index, src.LoadBits(bit_index, num_bits), num_bits);
David Srbecky45aa5982016-03-18 02:15:09 +0000435 }
436 }
437 }
438
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800439 // Write register masks table.
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800440 for (size_t i = 0; i < encoding.register_mask.num_entries; ++i) {
441 BitMemoryRegion register_mask = code_info.GetRegisterMask(i, encoding);
442 register_mask.StoreBits(0, register_masks_[i], encoding.register_mask.encoding.BitSize());
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800443 }
444
David Srbecky1bbdfd72016-02-24 16:39:26 +0000445 // Verify all written data in debug build.
446 if (kIsDebugBuild) {
447 CheckCodeInfo(region);
448 }
Calin Juravlec416d332015-04-23 16:01:43 +0100449}
450
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100451void StackMapStream::FillInDexRegisterMap(DexRegisterMap dex_register_map,
452 uint32_t num_dex_registers,
453 const BitVector& live_dex_registers_mask,
454 uint32_t start_index_in_dex_register_locations) const {
455 dex_register_map.SetLiveBitMask(num_dex_registers, live_dex_registers_mask);
456 // Set the dex register location mapping data.
Vladimir Marko225b6462015-09-28 12:17:40 +0100457 size_t number_of_live_dex_registers = live_dex_registers_mask.NumSetBits();
458 DCHECK_LE(number_of_live_dex_registers, dex_register_locations_.size());
459 DCHECK_LE(start_index_in_dex_register_locations,
460 dex_register_locations_.size() - number_of_live_dex_registers);
461 for (size_t index_in_dex_register_locations = 0;
462 index_in_dex_register_locations != number_of_live_dex_registers;
463 ++index_in_dex_register_locations) {
464 size_t location_catalog_entry_index = dex_register_locations_[
465 start_index_in_dex_register_locations + index_in_dex_register_locations];
466 dex_register_map.SetLocationCatalogEntryIndex(
467 index_in_dex_register_locations,
468 location_catalog_entry_index,
469 num_dex_registers,
470 location_catalog_entries_.size());
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100471 }
472}
473
Mathieu Chartier32289082017-02-09 15:57:37 -0800474size_t StackMapStream::AddDexRegisterMapEntry(const DexRegisterMapEntry& entry) {
475 const size_t current_entry_index = dex_register_entries_.size();
476 auto entries_it = dex_map_hash_to_stack_map_indices_.find(entry.hash);
Calin Juravlec416d332015-04-23 16:01:43 +0100477 if (entries_it == dex_map_hash_to_stack_map_indices_.end()) {
478 // We don't have a perfect hash functions so we need a list to collect all stack maps
479 // which might have the same dex register map.
Vladimir Marko174b2e22017-10-12 13:34:49 +0100480 ScopedArenaVector<uint32_t> stack_map_indices(allocator_->Adapter(kArenaAllocStackMapStream));
Vladimir Marko225b6462015-09-28 12:17:40 +0100481 stack_map_indices.push_back(current_entry_index);
Mathieu Chartier32289082017-02-09 15:57:37 -0800482 dex_map_hash_to_stack_map_indices_.Put(entry.hash, std::move(stack_map_indices));
483 } else {
484 // We might have collisions, so we need to check whether or not we really have a match.
485 for (uint32_t test_entry_index : entries_it->second) {
486 if (DexRegisterMapEntryEquals(dex_register_entries_[test_entry_index], entry)) {
487 return test_entry_index;
488 }
Calin Juravlec416d332015-04-23 16:01:43 +0100489 }
Mathieu Chartier32289082017-02-09 15:57:37 -0800490 entries_it->second.push_back(current_entry_index);
Calin Juravlec416d332015-04-23 16:01:43 +0100491 }
Mathieu Chartier32289082017-02-09 15:57:37 -0800492 dex_register_entries_.push_back(entry);
493 return current_entry_index;
Calin Juravlec416d332015-04-23 16:01:43 +0100494}
495
Mathieu Chartier32289082017-02-09 15:57:37 -0800496bool StackMapStream::DexRegisterMapEntryEquals(const DexRegisterMapEntry& a,
497 const DexRegisterMapEntry& b) const {
498 if ((a.live_dex_registers_mask == nullptr) != (b.live_dex_registers_mask == nullptr)) {
Calin Juravlec416d332015-04-23 16:01:43 +0100499 return false;
500 }
501 if (a.num_dex_registers != b.num_dex_registers) {
502 return false;
503 }
Vladimir Marko225b6462015-09-28 12:17:40 +0100504 if (a.num_dex_registers != 0u) {
505 DCHECK(a.live_dex_registers_mask != nullptr);
506 DCHECK(b.live_dex_registers_mask != nullptr);
507 if (!a.live_dex_registers_mask->Equal(b.live_dex_registers_mask)) {
Calin Juravlec416d332015-04-23 16:01:43 +0100508 return false;
509 }
Vladimir Marko225b6462015-09-28 12:17:40 +0100510 size_t number_of_live_dex_registers = a.live_dex_registers_mask->NumSetBits();
511 DCHECK_LE(number_of_live_dex_registers, dex_register_locations_.size());
Mathieu Chartier32289082017-02-09 15:57:37 -0800512 DCHECK_LE(a.locations_start_index,
Vladimir Marko225b6462015-09-28 12:17:40 +0100513 dex_register_locations_.size() - number_of_live_dex_registers);
Mathieu Chartier32289082017-02-09 15:57:37 -0800514 DCHECK_LE(b.locations_start_index,
Vladimir Marko225b6462015-09-28 12:17:40 +0100515 dex_register_locations_.size() - number_of_live_dex_registers);
Mathieu Chartier32289082017-02-09 15:57:37 -0800516 auto a_begin = dex_register_locations_.begin() + a.locations_start_index;
517 auto b_begin = dex_register_locations_.begin() + b.locations_start_index;
Vladimir Marko225b6462015-09-28 12:17:40 +0100518 if (!std::equal(a_begin, a_begin + number_of_live_dex_registers, b_begin)) {
519 return false;
Calin Juravlec416d332015-04-23 16:01:43 +0100520 }
521 }
522 return true;
523}
524
David Srbecky1bbdfd72016-02-24 16:39:26 +0000525// Helper for CheckCodeInfo - check that register map has the expected content.
526void StackMapStream::CheckDexRegisterMap(const CodeInfo& code_info,
527 const DexRegisterMap& dex_register_map,
528 size_t num_dex_registers,
529 BitVector* live_dex_registers_mask,
530 size_t dex_register_locations_index) const {
David Srbecky09ed0982016-02-12 21:58:43 +0000531 CodeInfoEncoding encoding = code_info.ExtractEncoding();
David Srbecky1bbdfd72016-02-24 16:39:26 +0000532 for (size_t reg = 0; reg < num_dex_registers; reg++) {
533 // Find the location we tried to encode.
534 DexRegisterLocation expected = DexRegisterLocation::None();
535 if (live_dex_registers_mask->IsBitSet(reg)) {
536 size_t catalog_index = dex_register_locations_[dex_register_locations_index++];
537 expected = location_catalog_entries_[catalog_index];
538 }
539 // Compare to the seen location.
540 if (expected.GetKind() == DexRegisterLocation::Kind::kNone) {
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800541 DCHECK(!dex_register_map.IsValid() || !dex_register_map.IsDexRegisterLive(reg))
542 << dex_register_map.IsValid() << " " << dex_register_map.IsDexRegisterLive(reg);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000543 } else {
544 DCHECK(dex_register_map.IsDexRegisterLive(reg));
545 DexRegisterLocation seen = dex_register_map.GetDexRegisterLocation(
546 reg, num_dex_registers, code_info, encoding);
547 DCHECK_EQ(expected.GetKind(), seen.GetKind());
548 DCHECK_EQ(expected.GetValue(), seen.GetValue());
549 }
550 }
551 if (num_dex_registers == 0) {
552 DCHECK(!dex_register_map.IsValid());
553 }
554}
555
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800556size_t StackMapStream::PrepareRegisterMasks() {
557 register_masks_.resize(stack_maps_.size(), 0u);
Vladimir Marko174b2e22017-10-12 13:34:49 +0100558 ScopedArenaUnorderedMap<uint32_t, size_t> dedupe(allocator_->Adapter(kArenaAllocStackMapStream));
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800559 for (StackMapEntry& stack_map : stack_maps_) {
560 const size_t index = dedupe.size();
561 stack_map.register_mask_index = dedupe.emplace(stack_map.register_mask, index).first->second;
562 register_masks_[index] = stack_map.register_mask;
563 }
564 return dedupe.size();
565}
566
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700567void StackMapStream::PrepareMethodIndices() {
568 CHECK(method_indices_.empty());
569 method_indices_.resize(stack_maps_.size() + inline_infos_.size());
Vladimir Marko174b2e22017-10-12 13:34:49 +0100570 ScopedArenaUnorderedMap<uint32_t, size_t> dedupe(allocator_->Adapter(kArenaAllocStackMapStream));
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700571 for (StackMapEntry& stack_map : stack_maps_) {
572 const size_t index = dedupe.size();
573 const uint32_t method_index = stack_map.dex_method_index;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700574 if (method_index != dex::kDexNoIndex) {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700575 stack_map.dex_method_index_idx = dedupe.emplace(method_index, index).first->second;
576 method_indices_[index] = method_index;
577 }
578 }
579 for (InlineInfoEntry& inline_info : inline_infos_) {
580 const size_t index = dedupe.size();
581 const uint32_t method_index = inline_info.method_index;
Andreas Gampee2abbc62017-09-15 11:59:26 -0700582 CHECK_NE(method_index, dex::kDexNoIndex);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700583 inline_info.dex_method_index_idx = dedupe.emplace(method_index, index).first->second;
584 method_indices_[index] = method_index;
585 }
586 method_indices_.resize(dedupe.size());
587}
588
589
David Srbecky45aa5982016-03-18 02:15:09 +0000590size_t StackMapStream::PrepareStackMasks(size_t entry_size_in_bits) {
591 // Preallocate memory since we do not want it to move (the dedup map will point into it).
592 const size_t byte_entry_size = RoundUp(entry_size_in_bits, kBitsPerByte) / kBitsPerByte;
593 stack_masks_.resize(byte_entry_size * stack_maps_.size(), 0u);
594 // For deduplicating we store the stack masks as byte packed for simplicity. We can bit pack later
595 // when copying out from stack_masks_.
Vladimir Marko174b2e22017-10-12 13:34:49 +0100596 ScopedArenaUnorderedMap<MemoryRegion,
597 size_t,
598 FNVHash<MemoryRegion>,
599 MemoryRegion::ContentEquals> dedup(
600 stack_maps_.size(), allocator_->Adapter(kArenaAllocStackMapStream));
David Srbecky45aa5982016-03-18 02:15:09 +0000601 for (StackMapEntry& stack_map : stack_maps_) {
602 size_t index = dedup.size();
603 MemoryRegion stack_mask(stack_masks_.data() + index * byte_entry_size, byte_entry_size);
David Srbecky68fefac2018-05-10 17:49:33 +0100604 BitMemoryRegion stack_mask_bits(stack_mask);
David Srbecky45aa5982016-03-18 02:15:09 +0000605 for (size_t i = 0; i < entry_size_in_bits; i++) {
David Srbecky68fefac2018-05-10 17:49:33 +0100606 stack_mask_bits.StoreBit(i, stack_map.sp_mask != nullptr && stack_map.sp_mask->IsBitSet(i));
David Srbecky45aa5982016-03-18 02:15:09 +0000607 }
608 stack_map.stack_mask_index = dedup.emplace(stack_mask, index).first->second;
609 }
610 return dedup.size();
611}
612
David Srbecky1bbdfd72016-02-24 16:39:26 +0000613// Check that all StackMapStream inputs are correctly encoded by trying to read them back.
614void StackMapStream::CheckCodeInfo(MemoryRegion region) const {
615 CodeInfo code_info(region);
David Srbecky09ed0982016-02-12 21:58:43 +0000616 CodeInfoEncoding encoding = code_info.ExtractEncoding();
617 DCHECK_EQ(code_info.GetNumberOfStackMaps(encoding), stack_maps_.size());
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800618 size_t invoke_info_index = 0;
David Srbecky1bbdfd72016-02-24 16:39:26 +0000619 for (size_t s = 0; s < stack_maps_.size(); ++s) {
620 const StackMap stack_map = code_info.GetStackMapAt(s, encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800621 const StackMapEncoding& stack_map_encoding = encoding.stack_map.encoding;
David Srbecky1bbdfd72016-02-24 16:39:26 +0000622 StackMapEntry entry = stack_maps_[s];
623
624 // Check main stack map fields.
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800625 DCHECK_EQ(stack_map.GetNativePcOffset(stack_map_encoding, instruction_set_),
626 entry.native_pc_code_offset.Uint32Value(instruction_set_));
David Srbecky09ed0982016-02-12 21:58:43 +0000627 DCHECK_EQ(stack_map.GetDexPc(stack_map_encoding), entry.dex_pc);
Mathieu Chartier1a20b682017-01-31 14:25:16 -0800628 DCHECK_EQ(stack_map.GetRegisterMaskIndex(stack_map_encoding), entry.register_mask_index);
629 DCHECK_EQ(code_info.GetRegisterMaskOf(encoding, stack_map), entry.register_mask);
David Srbecky45aa5982016-03-18 02:15:09 +0000630 const size_t num_stack_mask_bits = code_info.GetNumberOfStackMaskBits(encoding);
631 DCHECK_EQ(stack_map.GetStackMaskIndex(stack_map_encoding), entry.stack_mask_index);
632 BitMemoryRegion stack_mask = code_info.GetStackMaskOf(encoding, stack_map);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000633 if (entry.sp_mask != nullptr) {
David Srbecky45aa5982016-03-18 02:15:09 +0000634 DCHECK_GE(stack_mask.size_in_bits(), entry.sp_mask->GetNumberOfBits());
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), entry.sp_mask->IsBitSet(b));
David Srbecky1bbdfd72016-02-24 16:39:26 +0000637 }
638 } else {
David Srbecky09ed0982016-02-12 21:58:43 +0000639 for (size_t b = 0; b < num_stack_mask_bits; b++) {
David Srbecky45aa5982016-03-18 02:15:09 +0000640 DCHECK_EQ(stack_mask.LoadBit(b), 0u);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000641 }
642 }
Andreas Gampee2abbc62017-09-15 11:59:26 -0700643 if (entry.dex_method_index != dex::kDexNoIndex) {
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800644 InvokeInfo invoke_info = code_info.GetInvokeInfo(encoding, invoke_info_index);
645 DCHECK_EQ(invoke_info.GetNativePcOffset(encoding.invoke_info.encoding, instruction_set_),
646 entry.native_pc_code_offset.Uint32Value(instruction_set_));
647 DCHECK_EQ(invoke_info.GetInvokeType(encoding.invoke_info.encoding), entry.invoke_type);
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700648 DCHECK_EQ(invoke_info.GetMethodIndexIdx(encoding.invoke_info.encoding),
649 entry.dex_method_index_idx);
Mathieu Chartierd776ff02017-01-17 09:32:18 -0800650 invoke_info_index++;
651 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000652 CheckDexRegisterMap(code_info,
653 code_info.GetDexRegisterMapOf(
Mathieu Chartier32289082017-02-09 15:57:37 -0800654 stack_map, encoding, entry.dex_register_entry.num_dex_registers),
655 entry.dex_register_entry.num_dex_registers,
656 entry.dex_register_entry.live_dex_registers_mask,
657 entry.dex_register_entry.locations_start_index);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000658
659 // Check inline info.
David Srbecky09ed0982016-02-12 21:58:43 +0000660 DCHECK_EQ(stack_map.HasInlineInfo(stack_map_encoding), (entry.inlining_depth != 0));
David Srbecky1bbdfd72016-02-24 16:39:26 +0000661 if (entry.inlining_depth != 0) {
662 InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map, encoding);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800663 DCHECK_EQ(inline_info.GetDepth(encoding.inline_info.encoding), entry.inlining_depth);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000664 for (size_t d = 0; d < entry.inlining_depth; ++d) {
665 size_t inline_info_index = entry.inline_infos_start_index + d;
666 DCHECK_LT(inline_info_index, inline_infos_.size());
667 InlineInfoEntry inline_entry = inline_infos_[inline_info_index];
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800668 DCHECK_EQ(inline_info.GetDexPcAtDepth(encoding.inline_info.encoding, d),
David Srbecky61b28a12016-02-25 21:55:03 +0000669 inline_entry.dex_pc);
Mathieu Chartier575d3e62017-02-06 11:00:40 -0800670 if (inline_info.EncodesArtMethodAtDepth(encoding.inline_info.encoding, d)) {
671 DCHECK_EQ(inline_info.GetArtMethodAtDepth(encoding.inline_info.encoding, d),
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000672 inline_entry.method);
673 } else {
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700674 const size_t method_index_idx =
675 inline_info.GetMethodIndexIdxAtDepth(encoding.inline_info.encoding, d);
676 DCHECK_EQ(method_index_idx, inline_entry.dex_method_index_idx);
677 DCHECK_EQ(method_indices_[method_index_idx], inline_entry.method_index);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000678 }
David Srbecky1bbdfd72016-02-24 16:39:26 +0000679
680 CheckDexRegisterMap(code_info,
681 code_info.GetDexRegisterMapAtDepth(
Mathieu Chartier32289082017-02-09 15:57:37 -0800682 d,
683 inline_info,
684 encoding,
685 inline_entry.dex_register_entry.num_dex_registers),
686 inline_entry.dex_register_entry.num_dex_registers,
687 inline_entry.dex_register_entry.live_dex_registers_mask,
688 inline_entry.dex_register_entry.locations_start_index);
David Srbecky1bbdfd72016-02-24 16:39:26 +0000689 }
690 }
691 }
692}
693
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700694size_t StackMapStream::ComputeMethodInfoSize() const {
695 DCHECK_NE(0u, needed_size_) << "PrepareForFillIn not called before " << __FUNCTION__;
696 return MethodInfo::ComputeSize(method_indices_.size());
697}
698
Calin Juravlec416d332015-04-23 16:01:43 +0100699} // namespace art