blob: da4597e38536df9bcd30667f88b438cdf39dbb1c [file] [log] [blame]
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +01001/*
2 * Copyright (C) 2014 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 */
16
17#include "stack_map.h"
Mathieu Chartiere5d80f82015-10-15 17:47:48 -070018
Nicolas Geoffray5d37c152017-01-12 13:25:19 +000019#include "art_method.h"
Mathieu Chartiere5d80f82015-10-15 17:47:48 -070020#include "base/arena_bit_vector.h"
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010021#include "stack_map_stream.h"
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010022
23#include "gtest/gtest.h"
24
25namespace art {
26
David Srbecky09ed0982016-02-12 21:58:43 +000027// Check that the stack mask of given stack map is identical
28// to the given bit vector. Returns true if they are same.
29static bool CheckStackMask(
Mathieu Chartier12f1b992017-01-19 18:00:45 -080030 int number_of_bits,
David Srbecky09ed0982016-02-12 21:58:43 +000031 const StackMap& stack_map,
32 StackMapEncoding& encoding,
33 const BitVector& bit_vector) {
David Srbecky09ed0982016-02-12 21:58:43 +000034 if (bit_vector.GetHighestBitSet() >= number_of_bits) {
35 return false;
36 }
37 for (int i = 0; i < number_of_bits; ++i) {
38 if (stack_map.GetStackMaskBit(encoding, i) != bit_vector.IsBitSet(i)) {
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010039 return false;
40 }
41 }
42 return true;
43}
44
Roland Levillaina552e1c2015-03-26 15:01:03 +000045using Kind = DexRegisterLocation::Kind;
46
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010047TEST(StackMapTest, Test1) {
48 ArenaPool pool;
49 ArenaAllocator arena(&pool);
Mathieu Chartiera2f526f2017-01-19 14:48:48 -080050 StackMapStream stream(&arena, kRuntimeISA);
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010051
52 ArenaBitVector sp_mask(&arena, 0, false);
Roland Levillain12baf472015-03-05 12:41:42 +000053 size_t number_of_dex_registers = 2;
Calin Juravle4f46ac52015-04-23 18:47:21 +010054 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010055 stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location.
56 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Short location.
Calin Juravle4f46ac52015-04-23 18:47:21 +010057 stream.EndStackMapEntry();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010058
Calin Juravle4f46ac52015-04-23 18:47:21 +010059 size_t size = stream.PrepareForFillIn();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010060 void* memory = arena.Alloc(size, kArenaAllocMisc);
61 MemoryRegion region(memory, size);
62 stream.FillIn(region);
63
Nicolas Geoffray39468442014-09-02 15:17:15 +010064 CodeInfo code_info(region);
David Srbecky09ed0982016-02-12 21:58:43 +000065 CodeInfoEncoding encoding = code_info.ExtractEncoding();
66 ASSERT_EQ(1u, code_info.GetNumberOfStackMaps(encoding));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010067
David Srbecky09ed0982016-02-12 21:58:43 +000068 uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(encoding);
69 ASSERT_EQ(2u, number_of_catalog_entries);
David Brazdilf677ebf2015-05-29 16:29:43 +010070 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding);
Roland Levillaina552e1c2015-03-26 15:01:03 +000071 // The Dex register location catalog contains:
72 // - one 1-byte short Dex register location, and
73 // - one 5-byte large Dex register location.
74 size_t expected_location_catalog_size = 1u + 5u;
75 ASSERT_EQ(expected_location_catalog_size, location_catalog.Size());
76
David Brazdilf677ebf2015-05-29 16:29:43 +010077 StackMap stack_map = code_info.GetStackMapAt(0, encoding);
78 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding)));
79 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding)));
David Srbecky09ed0982016-02-12 21:58:43 +000080 ASSERT_EQ(0u, stack_map.GetDexPc(encoding.stack_map_encoding));
Mathieu Chartiera2f526f2017-01-19 14:48:48 -080081 ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding.stack_map_encoding, kRuntimeISA));
David Srbecky09ed0982016-02-12 21:58:43 +000082 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding.stack_map_encoding));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010083
Mathieu Chartier12f1b992017-01-19 18:00:45 -080084 ASSERT_TRUE(CheckStackMask(code_info.GetNumberOfStackMaskBits(encoding),
85 stack_map,
86 encoding.stack_map_encoding,
87 sp_mask));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010088
David Srbecky09ed0982016-02-12 21:58:43 +000089 ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding.stack_map_encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +000090 DexRegisterMap dex_register_map =
David Brazdilf677ebf2015-05-29 16:29:43 +010091 code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +000092 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0));
93 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
94 ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
95 // The Dex register map contains:
96 // - one 1-byte live bit mask, and
97 // - one 1-byte set of location catalog entry indices composed of two 2-bit values.
98 size_t expected_dex_register_map_size = 1u + 1u;
99 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
100
David Brazdilf677ebf2015-05-29 16:29:43 +0100101 ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationKind(
102 0, number_of_dex_registers, code_info, encoding));
103 ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind(
104 1, number_of_dex_registers, code_info, encoding));
105 ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationInternalKind(
106 0, number_of_dex_registers, code_info, encoding));
107 ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind(
108 1, number_of_dex_registers, code_info, encoding));
109 ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes(
110 0, number_of_dex_registers, code_info, encoding));
111 ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info, encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000112
113 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000114 0, number_of_dex_registers, number_of_catalog_entries);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000115 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000116 1, number_of_dex_registers, number_of_catalog_entries);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000117 ASSERT_EQ(0u, index0);
118 ASSERT_EQ(1u, index1);
119 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
120 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
121 ASSERT_EQ(Kind::kInStack, location0.GetKind());
122 ASSERT_EQ(Kind::kConstant, location1.GetKind());
123 ASSERT_EQ(Kind::kInStack, location0.GetInternalKind());
124 ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind());
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000125 ASSERT_EQ(0, location0.GetValue());
126 ASSERT_EQ(-2, location1.GetValue());
Roland Levillain12baf472015-03-05 12:41:42 +0000127
David Srbecky09ed0982016-02-12 21:58:43 +0000128 ASSERT_FALSE(stack_map.HasInlineInfo(encoding.stack_map_encoding));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100129}
130
131TEST(StackMapTest, Test2) {
132 ArenaPool pool;
133 ArenaAllocator arena(&pool);
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800134 StackMapStream stream(&arena, kRuntimeISA);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000135 ArtMethod art_method;
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100136
137 ArenaBitVector sp_mask1(&arena, 0, true);
138 sp_mask1.SetBit(2);
139 sp_mask1.SetBit(4);
Roland Levillain12baf472015-03-05 12:41:42 +0000140 size_t number_of_dex_registers = 2;
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100141 size_t number_of_dex_registers_in_inline_info = 0;
Calin Juravle4f46ac52015-04-23 18:47:21 +0100142 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, number_of_dex_registers, 2);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100143 stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location.
144 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000145 stream.BeginInlineInfoEntry(&art_method, 3, number_of_dex_registers_in_inline_info);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100146 stream.EndInlineInfoEntry();
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000147 stream.BeginInlineInfoEntry(&art_method, 2, number_of_dex_registers_in_inline_info);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100148 stream.EndInlineInfoEntry();
Calin Juravle4f46ac52015-04-23 18:47:21 +0100149 stream.EndStackMapEntry();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100150
151 ArenaBitVector sp_mask2(&arena, 0, true);
152 sp_mask2.SetBit(3);
David Brazdilf10a25f2015-06-02 14:29:52 +0100153 sp_mask2.SetBit(8);
Calin Juravle4f46ac52015-04-23 18:47:21 +0100154 stream.BeginStackMapEntry(1, 128, 0xFF, &sp_mask2, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100155 stream.AddDexRegisterEntry(Kind::kInRegister, 18); // Short location.
156 stream.AddDexRegisterEntry(Kind::kInFpuRegister, 3); // Short location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100157 stream.EndStackMapEntry();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100158
David Brazdild9cb68e2015-08-25 13:52:43 +0100159 ArenaBitVector sp_mask3(&arena, 0, true);
160 sp_mask3.SetBit(1);
161 sp_mask3.SetBit(5);
162 stream.BeginStackMapEntry(2, 192, 0xAB, &sp_mask3, number_of_dex_registers, 0);
163 stream.AddDexRegisterEntry(Kind::kInRegister, 6); // Short location.
164 stream.AddDexRegisterEntry(Kind::kInRegisterHigh, 8); // Short location.
165 stream.EndStackMapEntry();
166
167 ArenaBitVector sp_mask4(&arena, 0, true);
168 sp_mask4.SetBit(6);
169 sp_mask4.SetBit(7);
170 stream.BeginStackMapEntry(3, 256, 0xCD, &sp_mask4, number_of_dex_registers, 0);
171 stream.AddDexRegisterEntry(Kind::kInFpuRegister, 3); // Short location, same in stack map 2.
172 stream.AddDexRegisterEntry(Kind::kInFpuRegisterHigh, 1); // Short location.
173 stream.EndStackMapEntry();
174
Calin Juravle4f46ac52015-04-23 18:47:21 +0100175 size_t size = stream.PrepareForFillIn();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100176 void* memory = arena.Alloc(size, kArenaAllocMisc);
177 MemoryRegion region(memory, size);
178 stream.FillIn(region);
179
Nicolas Geoffray39468442014-09-02 15:17:15 +0100180 CodeInfo code_info(region);
David Srbecky09ed0982016-02-12 21:58:43 +0000181 CodeInfoEncoding encoding = code_info.ExtractEncoding();
182 ASSERT_EQ(4u, code_info.GetNumberOfStackMaps(encoding));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100183
David Srbecky09ed0982016-02-12 21:58:43 +0000184 uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(encoding);
185 ASSERT_EQ(7u, number_of_catalog_entries);
David Brazdilf677ebf2015-05-29 16:29:43 +0100186 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000187 // The Dex register location catalog contains:
David Brazdild9cb68e2015-08-25 13:52:43 +0100188 // - six 1-byte short Dex register locations, and
Roland Levillaina552e1c2015-03-26 15:01:03 +0000189 // - one 5-byte large Dex register location.
David Brazdild9cb68e2015-08-25 13:52:43 +0100190 size_t expected_location_catalog_size = 6u * 1u + 5u;
Roland Levillaina552e1c2015-03-26 15:01:03 +0000191 ASSERT_EQ(expected_location_catalog_size, location_catalog.Size());
192
Roland Levillain12baf472015-03-05 12:41:42 +0000193 // First stack map.
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000194 {
David Brazdilf677ebf2015-05-29 16:29:43 +0100195 StackMap stack_map = code_info.GetStackMapAt(0, encoding);
196 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding)));
197 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding)));
David Srbecky09ed0982016-02-12 21:58:43 +0000198 ASSERT_EQ(0u, stack_map.GetDexPc(encoding.stack_map_encoding));
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800199 ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding.stack_map_encoding, kRuntimeISA));
David Srbecky09ed0982016-02-12 21:58:43 +0000200 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding.stack_map_encoding));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100201
Mathieu Chartier12f1b992017-01-19 18:00:45 -0800202 ASSERT_TRUE(CheckStackMask(code_info.GetNumberOfStackMaskBits(encoding),
203 stack_map,
204 encoding.stack_map_encoding,
205 sp_mask1));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100206
David Srbecky09ed0982016-02-12 21:58:43 +0000207 ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding.stack_map_encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000208 DexRegisterMap dex_register_map =
David Brazdilf677ebf2015-05-29 16:29:43 +0100209 code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000210 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0));
211 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
212 ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
213 // The Dex register map contains:
214 // - one 1-byte live bit mask, and
215 // - one 1-byte set of location catalog entry indices composed of two 2-bit values.
216 size_t expected_dex_register_map_size = 1u + 1u;
217 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
218
David Brazdilf677ebf2015-05-29 16:29:43 +0100219 ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationKind(
220 0, number_of_dex_registers, code_info, encoding));
221 ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind(
222 1, number_of_dex_registers, code_info, encoding));
223 ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationInternalKind(
224 0, number_of_dex_registers, code_info, encoding));
225 ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind(
226 1, number_of_dex_registers, code_info, encoding));
227 ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes(
228 0, number_of_dex_registers, code_info, encoding));
229 ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info, encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000230
231 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000232 0, number_of_dex_registers, number_of_catalog_entries);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000233 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000234 1, number_of_dex_registers, number_of_catalog_entries);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000235 ASSERT_EQ(0u, index0);
236 ASSERT_EQ(1u, index1);
237 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
238 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
239 ASSERT_EQ(Kind::kInStack, location0.GetKind());
240 ASSERT_EQ(Kind::kConstant, location1.GetKind());
241 ASSERT_EQ(Kind::kInStack, location0.GetInternalKind());
242 ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind());
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000243 ASSERT_EQ(0, location0.GetValue());
244 ASSERT_EQ(-2, location1.GetValue());
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100245
David Srbecky09ed0982016-02-12 21:58:43 +0000246 ASSERT_TRUE(stack_map.HasInlineInfo(encoding.stack_map_encoding));
David Brazdilf677ebf2015-05-29 16:29:43 +0100247 InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map, encoding);
David Srbecky61b28a12016-02-25 21:55:03 +0000248 ASSERT_EQ(2u, inline_info.GetDepth(encoding.inline_info_encoding));
David Srbecky61b28a12016-02-25 21:55:03 +0000249 ASSERT_EQ(3u, inline_info.GetDexPcAtDepth(encoding.inline_info_encoding, 0));
250 ASSERT_EQ(2u, inline_info.GetDexPcAtDepth(encoding.inline_info_encoding, 1));
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000251 ASSERT_TRUE(inline_info.EncodesArtMethodAtDepth(encoding.inline_info_encoding, 0));
252 ASSERT_TRUE(inline_info.EncodesArtMethodAtDepth(encoding.inline_info_encoding, 1));
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000253 }
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100254
Roland Levillain12baf472015-03-05 12:41:42 +0000255 // Second stack map.
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000256 {
David Brazdilf677ebf2015-05-29 16:29:43 +0100257 StackMap stack_map = code_info.GetStackMapAt(1, encoding);
258 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(1u, encoding)));
259 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(128u, encoding)));
David Srbecky09ed0982016-02-12 21:58:43 +0000260 ASSERT_EQ(1u, stack_map.GetDexPc(encoding.stack_map_encoding));
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800261 ASSERT_EQ(128u, stack_map.GetNativePcOffset(encoding.stack_map_encoding, kRuntimeISA));
David Srbecky09ed0982016-02-12 21:58:43 +0000262 ASSERT_EQ(0xFFu, stack_map.GetRegisterMask(encoding.stack_map_encoding));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100263
Mathieu Chartier12f1b992017-01-19 18:00:45 -0800264 ASSERT_TRUE(CheckStackMask(code_info.GetNumberOfStackMaskBits(encoding),
265 stack_map,
266 encoding.stack_map_encoding,
267 sp_mask2));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100268
David Srbecky09ed0982016-02-12 21:58:43 +0000269 ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding.stack_map_encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000270 DexRegisterMap dex_register_map =
David Brazdilf677ebf2015-05-29 16:29:43 +0100271 code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000272 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0));
273 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
274 ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
275 // The Dex register map contains:
276 // - one 1-byte live bit mask, and
277 // - one 1-byte set of location catalog entry indices composed of two 2-bit values.
278 size_t expected_dex_register_map_size = 1u + 1u;
279 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
280
David Brazdilf677ebf2015-05-29 16:29:43 +0100281 ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationKind(
282 0, number_of_dex_registers, code_info, encoding));
283 ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationKind(
284 1, number_of_dex_registers, code_info, encoding));
285 ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationInternalKind(
286 0, number_of_dex_registers, code_info, encoding));
287 ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationInternalKind(
288 1, number_of_dex_registers, code_info, encoding));
289 ASSERT_EQ(18, dex_register_map.GetMachineRegister(
290 0, number_of_dex_registers, code_info, encoding));
291 ASSERT_EQ(3, dex_register_map.GetMachineRegister(
292 1, number_of_dex_registers, code_info, encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000293
294 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000295 0, number_of_dex_registers, number_of_catalog_entries);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000296 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000297 1, number_of_dex_registers, number_of_catalog_entries);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000298 ASSERT_EQ(2u, index0);
299 ASSERT_EQ(3u, index1);
300 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
301 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
302 ASSERT_EQ(Kind::kInRegister, location0.GetKind());
303 ASSERT_EQ(Kind::kInFpuRegister, location1.GetKind());
304 ASSERT_EQ(Kind::kInRegister, location0.GetInternalKind());
305 ASSERT_EQ(Kind::kInFpuRegister, location1.GetInternalKind());
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000306 ASSERT_EQ(18, location0.GetValue());
307 ASSERT_EQ(3, location1.GetValue());
Roland Levillain12baf472015-03-05 12:41:42 +0000308
David Srbecky09ed0982016-02-12 21:58:43 +0000309 ASSERT_FALSE(stack_map.HasInlineInfo(encoding.stack_map_encoding));
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000310 }
David Brazdild9cb68e2015-08-25 13:52:43 +0100311
312 // Third stack map.
313 {
314 StackMap stack_map = code_info.GetStackMapAt(2, encoding);
315 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(2u, encoding)));
316 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(192u, encoding)));
David Srbecky09ed0982016-02-12 21:58:43 +0000317 ASSERT_EQ(2u, stack_map.GetDexPc(encoding.stack_map_encoding));
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800318 ASSERT_EQ(192u, stack_map.GetNativePcOffset(encoding.stack_map_encoding, kRuntimeISA));
David Srbecky09ed0982016-02-12 21:58:43 +0000319 ASSERT_EQ(0xABu, stack_map.GetRegisterMask(encoding.stack_map_encoding));
David Brazdild9cb68e2015-08-25 13:52:43 +0100320
Mathieu Chartier12f1b992017-01-19 18:00:45 -0800321 ASSERT_TRUE(CheckStackMask(code_info.GetNumberOfStackMaskBits(encoding),
322 stack_map,
323 encoding.stack_map_encoding,
324 sp_mask3));
David Brazdild9cb68e2015-08-25 13:52:43 +0100325
David Srbecky09ed0982016-02-12 21:58:43 +0000326 ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding.stack_map_encoding));
David Brazdild9cb68e2015-08-25 13:52:43 +0100327 DexRegisterMap dex_register_map =
328 code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers);
329 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0));
330 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
331 ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
332 // The Dex register map contains:
333 // - one 1-byte live bit mask, and
334 // - one 1-byte set of location catalog entry indices composed of two 2-bit values.
335 size_t expected_dex_register_map_size = 1u + 1u;
336 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
337
338 ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationKind(
339 0, number_of_dex_registers, code_info, encoding));
340 ASSERT_EQ(Kind::kInRegisterHigh, dex_register_map.GetLocationKind(
341 1, number_of_dex_registers, code_info, encoding));
342 ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationInternalKind(
343 0, number_of_dex_registers, code_info, encoding));
344 ASSERT_EQ(Kind::kInRegisterHigh, dex_register_map.GetLocationInternalKind(
345 1, number_of_dex_registers, code_info, encoding));
346 ASSERT_EQ(6, dex_register_map.GetMachineRegister(
347 0, number_of_dex_registers, code_info, encoding));
348 ASSERT_EQ(8, dex_register_map.GetMachineRegister(
349 1, number_of_dex_registers, code_info, encoding));
350
351 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000352 0, number_of_dex_registers, number_of_catalog_entries);
David Brazdild9cb68e2015-08-25 13:52:43 +0100353 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000354 1, number_of_dex_registers, number_of_catalog_entries);
David Brazdild9cb68e2015-08-25 13:52:43 +0100355 ASSERT_EQ(4u, index0);
356 ASSERT_EQ(5u, index1);
357 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
358 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
359 ASSERT_EQ(Kind::kInRegister, location0.GetKind());
360 ASSERT_EQ(Kind::kInRegisterHigh, location1.GetKind());
361 ASSERT_EQ(Kind::kInRegister, location0.GetInternalKind());
362 ASSERT_EQ(Kind::kInRegisterHigh, location1.GetInternalKind());
363 ASSERT_EQ(6, location0.GetValue());
364 ASSERT_EQ(8, location1.GetValue());
365
David Srbecky09ed0982016-02-12 21:58:43 +0000366 ASSERT_FALSE(stack_map.HasInlineInfo(encoding.stack_map_encoding));
David Brazdild9cb68e2015-08-25 13:52:43 +0100367 }
368
369 // Fourth stack map.
370 {
371 StackMap stack_map = code_info.GetStackMapAt(3, encoding);
372 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(3u, encoding)));
373 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(256u, encoding)));
David Srbecky09ed0982016-02-12 21:58:43 +0000374 ASSERT_EQ(3u, stack_map.GetDexPc(encoding.stack_map_encoding));
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800375 ASSERT_EQ(256u, stack_map.GetNativePcOffset(encoding.stack_map_encoding, kRuntimeISA));
David Srbecky09ed0982016-02-12 21:58:43 +0000376 ASSERT_EQ(0xCDu, stack_map.GetRegisterMask(encoding.stack_map_encoding));
David Brazdild9cb68e2015-08-25 13:52:43 +0100377
Mathieu Chartier12f1b992017-01-19 18:00:45 -0800378 ASSERT_TRUE(CheckStackMask(code_info.GetNumberOfStackMaskBits(encoding),
379 stack_map,
380 encoding.stack_map_encoding,
381 sp_mask4));
David Brazdild9cb68e2015-08-25 13:52:43 +0100382
David Srbecky09ed0982016-02-12 21:58:43 +0000383 ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding.stack_map_encoding));
David Brazdild9cb68e2015-08-25 13:52:43 +0100384 DexRegisterMap dex_register_map =
385 code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers);
386 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0));
387 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
388 ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
389 // The Dex register map contains:
390 // - one 1-byte live bit mask, and
391 // - one 1-byte set of location catalog entry indices composed of two 2-bit values.
392 size_t expected_dex_register_map_size = 1u + 1u;
393 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
394
395 ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationKind(
396 0, number_of_dex_registers, code_info, encoding));
397 ASSERT_EQ(Kind::kInFpuRegisterHigh, dex_register_map.GetLocationKind(
398 1, number_of_dex_registers, code_info, encoding));
399 ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationInternalKind(
400 0, number_of_dex_registers, code_info, encoding));
401 ASSERT_EQ(Kind::kInFpuRegisterHigh, dex_register_map.GetLocationInternalKind(
402 1, number_of_dex_registers, code_info, encoding));
403 ASSERT_EQ(3, dex_register_map.GetMachineRegister(
404 0, number_of_dex_registers, code_info, encoding));
405 ASSERT_EQ(1, dex_register_map.GetMachineRegister(
406 1, number_of_dex_registers, code_info, encoding));
407
408 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000409 0, number_of_dex_registers, number_of_catalog_entries);
David Brazdild9cb68e2015-08-25 13:52:43 +0100410 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000411 1, number_of_dex_registers, number_of_catalog_entries);
David Brazdild9cb68e2015-08-25 13:52:43 +0100412 ASSERT_EQ(3u, index0); // Shared with second stack map.
413 ASSERT_EQ(6u, index1);
414 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
415 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
416 ASSERT_EQ(Kind::kInFpuRegister, location0.GetKind());
417 ASSERT_EQ(Kind::kInFpuRegisterHigh, location1.GetKind());
418 ASSERT_EQ(Kind::kInFpuRegister, location0.GetInternalKind());
419 ASSERT_EQ(Kind::kInFpuRegisterHigh, location1.GetInternalKind());
420 ASSERT_EQ(3, location0.GetValue());
421 ASSERT_EQ(1, location1.GetValue());
422
David Srbecky09ed0982016-02-12 21:58:43 +0000423 ASSERT_FALSE(stack_map.HasInlineInfo(encoding.stack_map_encoding));
David Brazdild9cb68e2015-08-25 13:52:43 +0100424 }
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100425}
426
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000427TEST(StackMapTest, TestNonLiveDexRegisters) {
428 ArenaPool pool;
429 ArenaAllocator arena(&pool);
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800430 StackMapStream stream(&arena, kRuntimeISA);
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000431
432 ArenaBitVector sp_mask(&arena, 0, false);
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000433 uint32_t number_of_dex_registers = 2;
Calin Juravle4f46ac52015-04-23 18:47:21 +0100434 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100435 stream.AddDexRegisterEntry(Kind::kNone, 0); // No location.
436 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100437 stream.EndStackMapEntry();
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000438
Calin Juravle4f46ac52015-04-23 18:47:21 +0100439 size_t size = stream.PrepareForFillIn();
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000440 void* memory = arena.Alloc(size, kArenaAllocMisc);
441 MemoryRegion region(memory, size);
442 stream.FillIn(region);
443
444 CodeInfo code_info(region);
David Srbecky09ed0982016-02-12 21:58:43 +0000445 CodeInfoEncoding encoding = code_info.ExtractEncoding();
446 ASSERT_EQ(1u, code_info.GetNumberOfStackMaps(encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000447
David Srbecky09ed0982016-02-12 21:58:43 +0000448 uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(encoding);
449 ASSERT_EQ(1u, number_of_catalog_entries);
David Brazdilf677ebf2015-05-29 16:29:43 +0100450 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000451 // The Dex register location catalog contains:
452 // - one 5-byte large Dex register location.
453 size_t expected_location_catalog_size = 5u;
454 ASSERT_EQ(expected_location_catalog_size, location_catalog.Size());
455
David Brazdilf677ebf2015-05-29 16:29:43 +0100456 StackMap stack_map = code_info.GetStackMapAt(0, encoding);
457 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding)));
458 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding)));
David Srbecky09ed0982016-02-12 21:58:43 +0000459 ASSERT_EQ(0u, stack_map.GetDexPc(encoding.stack_map_encoding));
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800460 ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding.stack_map_encoding, kRuntimeISA));
David Srbecky09ed0982016-02-12 21:58:43 +0000461 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding.stack_map_encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000462
David Srbecky09ed0982016-02-12 21:58:43 +0000463 ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding.stack_map_encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000464 DexRegisterMap dex_register_map =
David Brazdilf677ebf2015-05-29 16:29:43 +0100465 code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000466 ASSERT_FALSE(dex_register_map.IsDexRegisterLive(0));
467 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
468 ASSERT_EQ(1u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
469 // The Dex register map contains:
470 // - one 1-byte live bit mask.
471 // No space is allocated for the sole location catalog entry index, as it is useless.
472 size_t expected_dex_register_map_size = 1u + 0u;
473 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
474
David Brazdilf677ebf2015-05-29 16:29:43 +0100475 ASSERT_EQ(Kind::kNone, dex_register_map.GetLocationKind(
476 0, number_of_dex_registers, code_info, encoding));
477 ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind(
478 1, number_of_dex_registers, code_info, encoding));
479 ASSERT_EQ(Kind::kNone, dex_register_map.GetLocationInternalKind(
480 0, number_of_dex_registers, code_info, encoding));
481 ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind(
482 1, number_of_dex_registers, code_info, encoding));
483 ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info, encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000484
485 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000486 0, number_of_dex_registers, number_of_catalog_entries);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000487 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
David Srbecky09ed0982016-02-12 21:58:43 +0000488 1, number_of_dex_registers, number_of_catalog_entries);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000489 ASSERT_EQ(DexRegisterLocationCatalog::kNoLocationEntryIndex, index0);
490 ASSERT_EQ(0u, index1);
491 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
492 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
493 ASSERT_EQ(Kind::kNone, location0.GetKind());
494 ASSERT_EQ(Kind::kConstant, location1.GetKind());
495 ASSERT_EQ(Kind::kNone, location0.GetInternalKind());
496 ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind());
497 ASSERT_EQ(0, location0.GetValue());
498 ASSERT_EQ(-2, location1.GetValue());
499
David Srbecky09ed0982016-02-12 21:58:43 +0000500 ASSERT_FALSE(stack_map.HasInlineInfo(encoding.stack_map_encoding));
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000501}
502
503// Generate a stack map whose dex register offset is
504// StackMap::kNoDexRegisterMapSmallEncoding, and ensure we do
505// not treat it as kNoDexRegisterMap.
506TEST(StackMapTest, DexRegisterMapOffsetOverflow) {
507 ArenaPool pool;
508 ArenaAllocator arena(&pool);
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800509 StackMapStream stream(&arena, kRuntimeISA);
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000510
511 ArenaBitVector sp_mask(&arena, 0, false);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000512 uint32_t number_of_dex_registers = 1024;
513 // Create the first stack map (and its Dex register map).
Calin Juravle4f46ac52015-04-23 18:47:21 +0100514 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000515 uint32_t number_of_dex_live_registers_in_dex_register_map_0 = number_of_dex_registers - 8;
516 for (uint32_t i = 0; i < number_of_dex_live_registers_in_dex_register_map_0; ++i) {
517 // Use two different Dex register locations to populate this map,
518 // as using a single value (in the whole CodeInfo object) would
519 // make this Dex register mapping data empty (see
520 // art::DexRegisterMap::SingleEntrySizeInBits).
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100521 stream.AddDexRegisterEntry(Kind::kConstant, i % 2); // Short location.
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000522 }
Calin Juravle4f46ac52015-04-23 18:47:21 +0100523 stream.EndStackMapEntry();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000524 // Create the second stack map (and its Dex register map).
Calin Juravle4f46ac52015-04-23 18:47:21 +0100525 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000526 for (uint32_t i = 0; i < number_of_dex_registers; ++i) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100527 stream.AddDexRegisterEntry(Kind::kConstant, 0); // Short location.
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000528 }
Calin Juravle4f46ac52015-04-23 18:47:21 +0100529 stream.EndStackMapEntry();
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000530
Calin Juravle4f46ac52015-04-23 18:47:21 +0100531 size_t size = stream.PrepareForFillIn();
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000532 void* memory = arena.Alloc(size, kArenaAllocMisc);
533 MemoryRegion region(memory, size);
534 stream.FillIn(region);
535
536 CodeInfo code_info(region);
David Srbecky09ed0982016-02-12 21:58:43 +0000537 CodeInfoEncoding encoding = code_info.ExtractEncoding();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000538 // The location catalog contains two entries (DexRegisterLocation(kConstant, 0)
539 // and DexRegisterLocation(kConstant, 1)), therefore the location catalog index
540 // has a size of 1 bit.
David Srbecky09ed0982016-02-12 21:58:43 +0000541 uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(encoding);
542 ASSERT_EQ(2u, number_of_catalog_entries);
543 ASSERT_EQ(1u, DexRegisterMap::SingleEntrySizeInBits(number_of_catalog_entries));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000544
545 // The first Dex register map contains:
546 // - a live register bit mask for 1024 registers (that is, 128 bytes of
547 // data); and
548 // - Dex register mapping information for 1016 1-bit Dex (live) register
549 // locations (that is, 127 bytes of data).
550 // Hence it has a size of 255 bytes, and therefore...
551 ASSERT_EQ(128u, DexRegisterMap::GetLiveBitMaskSize(number_of_dex_registers));
David Brazdilf677ebf2015-05-29 16:29:43 +0100552 StackMap stack_map0 = code_info.GetStackMapAt(0, encoding);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000553 DexRegisterMap dex_register_map0 =
David Brazdilf677ebf2015-05-29 16:29:43 +0100554 code_info.GetDexRegisterMapOf(stack_map0, encoding, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000555 ASSERT_EQ(127u, dex_register_map0.GetLocationMappingDataSize(number_of_dex_registers,
David Srbecky09ed0982016-02-12 21:58:43 +0000556 number_of_catalog_entries));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000557 ASSERT_EQ(255u, dex_register_map0.Size());
558
David Brazdilf677ebf2015-05-29 16:29:43 +0100559 StackMap stack_map1 = code_info.GetStackMapAt(1, encoding);
David Srbecky09ed0982016-02-12 21:58:43 +0000560 ASSERT_TRUE(stack_map1.HasDexRegisterMap(encoding.stack_map_encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000561 // ...the offset of the second Dex register map (relative to the
562 // beginning of the Dex register maps region) is 255 (i.e.,
563 // kNoDexRegisterMapSmallEncoding).
David Srbecky09ed0982016-02-12 21:58:43 +0000564 ASSERT_NE(stack_map1.GetDexRegisterMapOffset(encoding.stack_map_encoding),
565 StackMap::kNoDexRegisterMap);
566 ASSERT_EQ(stack_map1.GetDexRegisterMapOffset(encoding.stack_map_encoding), 0xFFu);
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000567}
568
Calin Juravle6ae70962015-03-18 16:31:28 +0000569TEST(StackMapTest, TestShareDexRegisterMap) {
570 ArenaPool pool;
571 ArenaAllocator arena(&pool);
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800572 StackMapStream stream(&arena, kRuntimeISA);
Calin Juravle6ae70962015-03-18 16:31:28 +0000573
574 ArenaBitVector sp_mask(&arena, 0, false);
575 uint32_t number_of_dex_registers = 2;
576 // First stack map.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100577 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100578 stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location.
579 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100580 stream.EndStackMapEntry();
Calin Juravle6ae70962015-03-18 16:31:28 +0000581 // Second stack map, which should share the same dex register map.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100582 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100583 stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location.
584 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100585 stream.EndStackMapEntry();
Calin Juravle6ae70962015-03-18 16:31:28 +0000586 // Third stack map (doesn't share the dex register map).
Calin Juravle4f46ac52015-04-23 18:47:21 +0100587 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100588 stream.AddDexRegisterEntry(Kind::kInRegister, 2); // Short location.
589 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100590 stream.EndStackMapEntry();
Calin Juravle6ae70962015-03-18 16:31:28 +0000591
Calin Juravle4f46ac52015-04-23 18:47:21 +0100592 size_t size = stream.PrepareForFillIn();
Calin Juravle6ae70962015-03-18 16:31:28 +0000593 void* memory = arena.Alloc(size, kArenaAllocMisc);
594 MemoryRegion region(memory, size);
595 stream.FillIn(region);
596
597 CodeInfo ci(region);
David Srbecky09ed0982016-02-12 21:58:43 +0000598 CodeInfoEncoding encoding = ci.ExtractEncoding();
David Brazdilf677ebf2015-05-29 16:29:43 +0100599
Calin Juravle6ae70962015-03-18 16:31:28 +0000600 // Verify first stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100601 StackMap sm0 = ci.GetStackMapAt(0, encoding);
602 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm0, encoding, number_of_dex_registers);
603 ASSERT_EQ(0, dex_registers0.GetMachineRegister(0, number_of_dex_registers, ci, encoding));
604 ASSERT_EQ(-2, dex_registers0.GetConstant(1, number_of_dex_registers, ci, encoding));
Calin Juravle6ae70962015-03-18 16:31:28 +0000605
606 // Verify second stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100607 StackMap sm1 = ci.GetStackMapAt(1, encoding);
608 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapOf(sm1, encoding, number_of_dex_registers);
609 ASSERT_EQ(0, dex_registers1.GetMachineRegister(0, number_of_dex_registers, ci, encoding));
610 ASSERT_EQ(-2, dex_registers1.GetConstant(1, number_of_dex_registers, ci, encoding));
Calin Juravle6ae70962015-03-18 16:31:28 +0000611
612 // Verify third stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100613 StackMap sm2 = ci.GetStackMapAt(2, encoding);
614 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapOf(sm2, encoding, number_of_dex_registers);
615 ASSERT_EQ(2, dex_registers2.GetMachineRegister(0, number_of_dex_registers, ci, encoding));
616 ASSERT_EQ(-2, dex_registers2.GetConstant(1, number_of_dex_registers, ci, encoding));
Calin Juravle6ae70962015-03-18 16:31:28 +0000617
618 // Verify dex register map offsets.
David Srbecky09ed0982016-02-12 21:58:43 +0000619 ASSERT_EQ(sm0.GetDexRegisterMapOffset(encoding.stack_map_encoding),
620 sm1.GetDexRegisterMapOffset(encoding.stack_map_encoding));
621 ASSERT_NE(sm0.GetDexRegisterMapOffset(encoding.stack_map_encoding),
622 sm2.GetDexRegisterMapOffset(encoding.stack_map_encoding));
623 ASSERT_NE(sm1.GetDexRegisterMapOffset(encoding.stack_map_encoding),
624 sm2.GetDexRegisterMapOffset(encoding.stack_map_encoding));
Calin Juravle6ae70962015-03-18 16:31:28 +0000625}
626
Roland Levillaina552e1c2015-03-26 15:01:03 +0000627TEST(StackMapTest, TestNoDexRegisterMap) {
628 ArenaPool pool;
629 ArenaAllocator arena(&pool);
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800630 StackMapStream stream(&arena, kRuntimeISA);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000631
632 ArenaBitVector sp_mask(&arena, 0, false);
633 uint32_t number_of_dex_registers = 0;
Calin Juravle4f46ac52015-04-23 18:47:21 +0100634 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
635 stream.EndStackMapEntry();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000636
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000637 number_of_dex_registers = 1;
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800638 stream.BeginStackMapEntry(1, 68, 0x4, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000639 stream.EndStackMapEntry();
640
Calin Juravle4f46ac52015-04-23 18:47:21 +0100641 size_t size = stream.PrepareForFillIn();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000642 void* memory = arena.Alloc(size, kArenaAllocMisc);
643 MemoryRegion region(memory, size);
644 stream.FillIn(region);
645
646 CodeInfo code_info(region);
David Srbecky09ed0982016-02-12 21:58:43 +0000647 CodeInfoEncoding encoding = code_info.ExtractEncoding();
648 ASSERT_EQ(2u, code_info.GetNumberOfStackMaps(encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000649
David Srbecky09ed0982016-02-12 21:58:43 +0000650 uint32_t number_of_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(encoding);
651 ASSERT_EQ(0u, number_of_catalog_entries);
David Brazdilf677ebf2015-05-29 16:29:43 +0100652 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000653 ASSERT_EQ(0u, location_catalog.Size());
654
David Brazdilf677ebf2015-05-29 16:29:43 +0100655 StackMap stack_map = code_info.GetStackMapAt(0, encoding);
656 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding)));
657 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding)));
David Srbecky09ed0982016-02-12 21:58:43 +0000658 ASSERT_EQ(0u, stack_map.GetDexPc(encoding.stack_map_encoding));
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800659 ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding.stack_map_encoding, kRuntimeISA));
David Srbecky09ed0982016-02-12 21:58:43 +0000660 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding.stack_map_encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000661
David Srbecky09ed0982016-02-12 21:58:43 +0000662 ASSERT_FALSE(stack_map.HasDexRegisterMap(encoding.stack_map_encoding));
663 ASSERT_FALSE(stack_map.HasInlineInfo(encoding.stack_map_encoding));
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000664
665 stack_map = code_info.GetStackMapAt(1, encoding);
666 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(1, encoding)));
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800667 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(68, encoding)));
David Srbecky09ed0982016-02-12 21:58:43 +0000668 ASSERT_EQ(1u, stack_map.GetDexPc(encoding.stack_map_encoding));
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800669 ASSERT_EQ(68u, stack_map.GetNativePcOffset(encoding.stack_map_encoding, kRuntimeISA));
David Srbecky09ed0982016-02-12 21:58:43 +0000670 ASSERT_EQ(0x4u, stack_map.GetRegisterMask(encoding.stack_map_encoding));
Nicolas Geoffray012fc4e2016-01-08 15:58:19 +0000671
David Srbecky09ed0982016-02-12 21:58:43 +0000672 ASSERT_FALSE(stack_map.HasDexRegisterMap(encoding.stack_map_encoding));
673 ASSERT_FALSE(stack_map.HasInlineInfo(encoding.stack_map_encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000674}
675
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100676TEST(StackMapTest, InlineTest) {
677 ArenaPool pool;
678 ArenaAllocator arena(&pool);
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800679 StackMapStream stream(&arena, kRuntimeISA);
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000680 ArtMethod art_method;
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100681
682 ArenaBitVector sp_mask1(&arena, 0, true);
683 sp_mask1.SetBit(2);
684 sp_mask1.SetBit(4);
685
686 // First stack map.
687 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, 2, 2);
688 stream.AddDexRegisterEntry(Kind::kInStack, 0);
689 stream.AddDexRegisterEntry(Kind::kConstant, 4);
690
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000691 stream.BeginInlineInfoEntry(&art_method, 2, 1);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100692 stream.AddDexRegisterEntry(Kind::kInStack, 8);
693 stream.EndInlineInfoEntry();
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000694 stream.BeginInlineInfoEntry(&art_method, 3, 3);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100695 stream.AddDexRegisterEntry(Kind::kInStack, 16);
696 stream.AddDexRegisterEntry(Kind::kConstant, 20);
697 stream.AddDexRegisterEntry(Kind::kInRegister, 15);
698 stream.EndInlineInfoEntry();
699
700 stream.EndStackMapEntry();
701
702 // Second stack map.
703 stream.BeginStackMapEntry(2, 22, 0x3, &sp_mask1, 2, 3);
704 stream.AddDexRegisterEntry(Kind::kInStack, 56);
705 stream.AddDexRegisterEntry(Kind::kConstant, 0);
706
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000707 stream.BeginInlineInfoEntry(&art_method, 2, 1);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100708 stream.AddDexRegisterEntry(Kind::kInStack, 12);
709 stream.EndInlineInfoEntry();
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000710 stream.BeginInlineInfoEntry(&art_method, 3, 3);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100711 stream.AddDexRegisterEntry(Kind::kInStack, 80);
712 stream.AddDexRegisterEntry(Kind::kConstant, 10);
713 stream.AddDexRegisterEntry(Kind::kInRegister, 5);
714 stream.EndInlineInfoEntry();
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000715 stream.BeginInlineInfoEntry(&art_method, 5, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100716 stream.EndInlineInfoEntry();
717
718 stream.EndStackMapEntry();
719
720 // Third stack map.
721 stream.BeginStackMapEntry(4, 56, 0x3, &sp_mask1, 2, 0);
722 stream.AddDexRegisterEntry(Kind::kNone, 0);
723 stream.AddDexRegisterEntry(Kind::kConstant, 4);
724 stream.EndStackMapEntry();
725
726 // Fourth stack map.
727 stream.BeginStackMapEntry(6, 78, 0x3, &sp_mask1, 2, 3);
728 stream.AddDexRegisterEntry(Kind::kInStack, 56);
729 stream.AddDexRegisterEntry(Kind::kConstant, 0);
730
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000731 stream.BeginInlineInfoEntry(&art_method, 2, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100732 stream.EndInlineInfoEntry();
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000733 stream.BeginInlineInfoEntry(&art_method, 5, 1);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100734 stream.AddDexRegisterEntry(Kind::kInRegister, 2);
735 stream.EndInlineInfoEntry();
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000736 stream.BeginInlineInfoEntry(&art_method, 10, 2);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100737 stream.AddDexRegisterEntry(Kind::kNone, 0);
738 stream.AddDexRegisterEntry(Kind::kInRegister, 3);
739 stream.EndInlineInfoEntry();
740
741 stream.EndStackMapEntry();
742
743 size_t size = stream.PrepareForFillIn();
744 void* memory = arena.Alloc(size, kArenaAllocMisc);
745 MemoryRegion region(memory, size);
746 stream.FillIn(region);
747
748 CodeInfo ci(region);
David Srbecky09ed0982016-02-12 21:58:43 +0000749 CodeInfoEncoding encoding = ci.ExtractEncoding();
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100750
751 {
752 // Verify first stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100753 StackMap sm0 = ci.GetStackMapAt(0, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100754
David Brazdilf677ebf2015-05-29 16:29:43 +0100755 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm0, encoding, 2);
756 ASSERT_EQ(0, dex_registers0.GetStackOffsetInBytes(0, 2, ci, encoding));
757 ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100758
David Brazdilf677ebf2015-05-29 16:29:43 +0100759 InlineInfo if0 = ci.GetInlineInfoOf(sm0, encoding);
David Srbecky61b28a12016-02-25 21:55:03 +0000760 ASSERT_EQ(2u, if0.GetDepth(encoding.inline_info_encoding));
761 ASSERT_EQ(2u, if0.GetDexPcAtDepth(encoding.inline_info_encoding, 0));
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000762 ASSERT_TRUE(if0.EncodesArtMethodAtDepth(encoding.inline_info_encoding, 0));
David Srbecky61b28a12016-02-25 21:55:03 +0000763 ASSERT_EQ(3u, if0.GetDexPcAtDepth(encoding.inline_info_encoding, 1));
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000764 ASSERT_TRUE(if0.EncodesArtMethodAtDepth(encoding.inline_info_encoding, 1));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100765
David Brazdilf677ebf2015-05-29 16:29:43 +0100766 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if0, encoding, 1);
767 ASSERT_EQ(8, dex_registers1.GetStackOffsetInBytes(0, 1, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100768
David Brazdilf677ebf2015-05-29 16:29:43 +0100769 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(1, if0, encoding, 3);
770 ASSERT_EQ(16, dex_registers2.GetStackOffsetInBytes(0, 3, ci, encoding));
771 ASSERT_EQ(20, dex_registers2.GetConstant(1, 3, ci, encoding));
772 ASSERT_EQ(15, dex_registers2.GetMachineRegister(2, 3, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100773 }
774
775 {
776 // Verify second stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100777 StackMap sm1 = ci.GetStackMapAt(1, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100778
David Brazdilf677ebf2015-05-29 16:29:43 +0100779 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm1, encoding, 2);
780 ASSERT_EQ(56, dex_registers0.GetStackOffsetInBytes(0, 2, ci, encoding));
781 ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100782
David Brazdilf677ebf2015-05-29 16:29:43 +0100783 InlineInfo if1 = ci.GetInlineInfoOf(sm1, encoding);
David Srbecky61b28a12016-02-25 21:55:03 +0000784 ASSERT_EQ(3u, if1.GetDepth(encoding.inline_info_encoding));
785 ASSERT_EQ(2u, if1.GetDexPcAtDepth(encoding.inline_info_encoding, 0));
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000786 ASSERT_TRUE(if1.EncodesArtMethodAtDepth(encoding.inline_info_encoding, 0));
David Srbecky61b28a12016-02-25 21:55:03 +0000787 ASSERT_EQ(3u, if1.GetDexPcAtDepth(encoding.inline_info_encoding, 1));
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000788 ASSERT_TRUE(if1.EncodesArtMethodAtDepth(encoding.inline_info_encoding, 1));
David Srbecky61b28a12016-02-25 21:55:03 +0000789 ASSERT_EQ(5u, if1.GetDexPcAtDepth(encoding.inline_info_encoding, 2));
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000790 ASSERT_TRUE(if1.EncodesArtMethodAtDepth(encoding.inline_info_encoding, 2));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100791
David Brazdilf677ebf2015-05-29 16:29:43 +0100792 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if1, encoding, 1);
793 ASSERT_EQ(12, dex_registers1.GetStackOffsetInBytes(0, 1, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100794
David Brazdilf677ebf2015-05-29 16:29:43 +0100795 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(1, if1, encoding, 3);
796 ASSERT_EQ(80, dex_registers2.GetStackOffsetInBytes(0, 3, ci, encoding));
797 ASSERT_EQ(10, dex_registers2.GetConstant(1, 3, ci, encoding));
798 ASSERT_EQ(5, dex_registers2.GetMachineRegister(2, 3, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100799
David Srbecky61b28a12016-02-25 21:55:03 +0000800 ASSERT_FALSE(if1.HasDexRegisterMapAtDepth(encoding.inline_info_encoding, 2));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100801 }
802
803 {
804 // Verify third stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100805 StackMap sm2 = ci.GetStackMapAt(2, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100806
David Brazdilf677ebf2015-05-29 16:29:43 +0100807 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm2, encoding, 2);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100808 ASSERT_FALSE(dex_registers0.IsDexRegisterLive(0));
David Brazdilf677ebf2015-05-29 16:29:43 +0100809 ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci, encoding));
David Srbecky09ed0982016-02-12 21:58:43 +0000810 ASSERT_FALSE(sm2.HasInlineInfo(encoding.stack_map_encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100811 }
812
813 {
814 // Verify fourth stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100815 StackMap sm3 = ci.GetStackMapAt(3, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100816
David Brazdilf677ebf2015-05-29 16:29:43 +0100817 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm3, encoding, 2);
818 ASSERT_EQ(56, dex_registers0.GetStackOffsetInBytes(0, 2, ci, encoding));
819 ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100820
David Brazdilf677ebf2015-05-29 16:29:43 +0100821 InlineInfo if2 = ci.GetInlineInfoOf(sm3, encoding);
David Srbecky61b28a12016-02-25 21:55:03 +0000822 ASSERT_EQ(3u, if2.GetDepth(encoding.inline_info_encoding));
823 ASSERT_EQ(2u, if2.GetDexPcAtDepth(encoding.inline_info_encoding, 0));
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000824 ASSERT_TRUE(if2.EncodesArtMethodAtDepth(encoding.inline_info_encoding, 0));
David Srbecky61b28a12016-02-25 21:55:03 +0000825 ASSERT_EQ(5u, if2.GetDexPcAtDepth(encoding.inline_info_encoding, 1));
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000826 ASSERT_TRUE(if2.EncodesArtMethodAtDepth(encoding.inline_info_encoding, 1));
David Srbecky61b28a12016-02-25 21:55:03 +0000827 ASSERT_EQ(10u, if2.GetDexPcAtDepth(encoding.inline_info_encoding, 2));
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000828 ASSERT_TRUE(if2.EncodesArtMethodAtDepth(encoding.inline_info_encoding, 2));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100829
David Srbecky61b28a12016-02-25 21:55:03 +0000830 ASSERT_FALSE(if2.HasDexRegisterMapAtDepth(encoding.inline_info_encoding, 0));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100831
David Brazdilf677ebf2015-05-29 16:29:43 +0100832 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(1, if2, encoding, 1);
833 ASSERT_EQ(2, dex_registers1.GetMachineRegister(0, 1, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100834
David Brazdilf677ebf2015-05-29 16:29:43 +0100835 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(2, if2, encoding, 2);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100836 ASSERT_FALSE(dex_registers2.IsDexRegisterLive(0));
David Brazdilf677ebf2015-05-29 16:29:43 +0100837 ASSERT_EQ(3, dex_registers2.GetMachineRegister(1, 2, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100838 }
839}
840
Mathieu Chartiera2f526f2017-01-19 14:48:48 -0800841TEST(StackMapTest, CodeOffsetTest) {
842 // Test minimum alignments, encoding, and decoding.
843 CodeOffset offset_thumb2 = CodeOffset::FromOffset(kThumb2InstructionAlignment, kThumb2);
844 CodeOffset offset_arm64 = CodeOffset::FromOffset(kArm64InstructionAlignment, kArm64);
845 CodeOffset offset_x86 = CodeOffset::FromOffset(kX86InstructionAlignment, kX86);
846 CodeOffset offset_x86_64 = CodeOffset::FromOffset(kX86_64InstructionAlignment, kX86_64);
847 CodeOffset offset_mips = CodeOffset::FromOffset(kMipsInstructionAlignment, kMips);
848 CodeOffset offset_mips64 = CodeOffset::FromOffset(kMips64InstructionAlignment, kMips64);
849 EXPECT_EQ(offset_thumb2.Uint32Value(kThumb2), kThumb2InstructionAlignment);
850 EXPECT_EQ(offset_arm64.Uint32Value(kArm64), kArm64InstructionAlignment);
851 EXPECT_EQ(offset_x86.Uint32Value(kX86), kX86InstructionAlignment);
852 EXPECT_EQ(offset_x86_64.Uint32Value(kX86_64), kX86_64InstructionAlignment);
853 EXPECT_EQ(offset_mips.Uint32Value(kMips), kMipsInstructionAlignment);
854 EXPECT_EQ(offset_mips64.Uint32Value(kMips64), kMips64InstructionAlignment);
855}
856
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100857} // namespace art