blob: 98e14ea9a6a92792d73824b6904700b60de3d62d [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"
18#include "stack_map_stream.h"
19#include "utils/arena_bit_vector.h"
20
21#include "gtest/gtest.h"
22
23namespace art {
24
Roland Levillaina2d8ec62015-03-12 15:25:29 +000025static bool SameBits(MemoryRegion region, const BitVector& bit_vector) {
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010026 for (size_t i = 0; i < region.size_in_bits(); ++i) {
27 if (region.LoadBit(i) != bit_vector.IsBitSet(i)) {
28 return false;
29 }
30 }
31 return true;
32}
33
Roland Levillaina552e1c2015-03-26 15:01:03 +000034using Kind = DexRegisterLocation::Kind;
35
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010036TEST(StackMapTest, Test1) {
37 ArenaPool pool;
38 ArenaAllocator arena(&pool);
Nicolas Geoffray39468442014-09-02 15:17:15 +010039 StackMapStream stream(&arena);
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010040
41 ArenaBitVector sp_mask(&arena, 0, false);
Roland Levillain12baf472015-03-05 12:41:42 +000042 size_t number_of_dex_registers = 2;
Calin Juravle4f46ac52015-04-23 18:47:21 +010043 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +010044 stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location.
45 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Short location.
Calin Juravle4f46ac52015-04-23 18:47:21 +010046 stream.EndStackMapEntry();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010047
Calin Juravle4f46ac52015-04-23 18:47:21 +010048 size_t size = stream.PrepareForFillIn();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010049 void* memory = arena.Alloc(size, kArenaAllocMisc);
50 MemoryRegion region(memory, size);
51 stream.FillIn(region);
52
Nicolas Geoffray39468442014-09-02 15:17:15 +010053 CodeInfo code_info(region);
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010054 ASSERT_EQ(0u, code_info.GetStackMaskSize());
55 ASSERT_EQ(1u, code_info.GetNumberOfStackMaps());
56
Roland Levillaina552e1c2015-03-26 15:01:03 +000057 uint32_t number_of_location_catalog_entries =
58 code_info.GetNumberOfDexRegisterLocationCatalogEntries();
59 ASSERT_EQ(2u, number_of_location_catalog_entries);
60 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog();
61 // The Dex register location catalog contains:
62 // - one 1-byte short Dex register location, and
63 // - one 5-byte large Dex register location.
64 size_t expected_location_catalog_size = 1u + 5u;
65 ASSERT_EQ(expected_location_catalog_size, location_catalog.Size());
66
Nicolas Geoffray39468442014-09-02 15:17:15 +010067 StackMap stack_map = code_info.GetStackMapAt(0);
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010068 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0)));
Nicolas Geoffray39468442014-09-02 15:17:15 +010069 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64)));
Nicolas Geoffray004c2302015-03-20 10:06:38 +000070 ASSERT_EQ(0u, stack_map.GetDexPc(code_info));
71 ASSERT_EQ(64u, stack_map.GetNativePcOffset(code_info));
72 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(code_info));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010073
Nicolas Geoffray004c2302015-03-20 10:06:38 +000074 MemoryRegion stack_mask = stack_map.GetStackMask(code_info);
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010075 ASSERT_TRUE(SameBits(stack_mask, sp_mask));
76
Nicolas Geoffray004c2302015-03-20 10:06:38 +000077 ASSERT_TRUE(stack_map.HasDexRegisterMap(code_info));
Roland Levillaina552e1c2015-03-26 15:01:03 +000078 DexRegisterMap dex_register_map =
79 code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers);
80 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0));
81 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
82 ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
83 // The Dex register map contains:
84 // - one 1-byte live bit mask, and
85 // - one 1-byte set of location catalog entry indices composed of two 2-bit values.
86 size_t expected_dex_register_map_size = 1u + 1u;
87 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
88
89 ASSERT_EQ(Kind::kInStack,
90 dex_register_map.GetLocationKind(0, number_of_dex_registers, code_info));
91 ASSERT_EQ(Kind::kConstant,
92 dex_register_map.GetLocationKind(1, number_of_dex_registers, code_info));
93 ASSERT_EQ(Kind::kInStack,
94 dex_register_map.GetLocationInternalKind(0, number_of_dex_registers, code_info));
95 ASSERT_EQ(Kind::kConstantLargeValue,
96 dex_register_map.GetLocationInternalKind(1, number_of_dex_registers, code_info));
97 ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes(0, number_of_dex_registers, code_info));
98 ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info));
99
100 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
101 0, number_of_dex_registers, number_of_location_catalog_entries);
102 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
103 1, number_of_dex_registers, number_of_location_catalog_entries);
104 ASSERT_EQ(0u, index0);
105 ASSERT_EQ(1u, index1);
106 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
107 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
108 ASSERT_EQ(Kind::kInStack, location0.GetKind());
109 ASSERT_EQ(Kind::kConstant, location1.GetKind());
110 ASSERT_EQ(Kind::kInStack, location0.GetInternalKind());
111 ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind());
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000112 ASSERT_EQ(0, location0.GetValue());
113 ASSERT_EQ(-2, location1.GetValue());
Roland Levillain12baf472015-03-05 12:41:42 +0000114
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000115 ASSERT_FALSE(stack_map.HasInlineInfo(code_info));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100116}
117
118TEST(StackMapTest, Test2) {
119 ArenaPool pool;
120 ArenaAllocator arena(&pool);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100121 StackMapStream stream(&arena);
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100122
123 ArenaBitVector sp_mask1(&arena, 0, true);
124 sp_mask1.SetBit(2);
125 sp_mask1.SetBit(4);
Roland Levillain12baf472015-03-05 12:41:42 +0000126 size_t number_of_dex_registers = 2;
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100127 size_t number_of_dex_registers_in_inline_info = 0;
Calin Juravle4f46ac52015-04-23 18:47:21 +0100128 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, number_of_dex_registers, 2);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100129 stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location.
130 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100131 stream.BeginInlineInfoEntry(82, 3, kDirect, number_of_dex_registers_in_inline_info);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100132 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100133 stream.BeginInlineInfoEntry(42, 2, kStatic, number_of_dex_registers_in_inline_info);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100134 stream.EndInlineInfoEntry();
Calin Juravle4f46ac52015-04-23 18:47:21 +0100135 stream.EndStackMapEntry();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100136
137 ArenaBitVector sp_mask2(&arena, 0, true);
138 sp_mask2.SetBit(3);
139 sp_mask1.SetBit(8);
Calin Juravle4f46ac52015-04-23 18:47:21 +0100140 stream.BeginStackMapEntry(1, 128, 0xFF, &sp_mask2, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100141 stream.AddDexRegisterEntry(Kind::kInRegister, 18); // Short location.
142 stream.AddDexRegisterEntry(Kind::kInFpuRegister, 3); // Short location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100143 stream.EndStackMapEntry();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100144
Calin Juravle4f46ac52015-04-23 18:47:21 +0100145 size_t size = stream.PrepareForFillIn();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100146 void* memory = arena.Alloc(size, kArenaAllocMisc);
147 MemoryRegion region(memory, size);
148 stream.FillIn(region);
149
Nicolas Geoffray39468442014-09-02 15:17:15 +0100150 CodeInfo code_info(region);
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100151 ASSERT_EQ(1u, code_info.GetStackMaskSize());
152 ASSERT_EQ(2u, code_info.GetNumberOfStackMaps());
153
Roland Levillaina552e1c2015-03-26 15:01:03 +0000154 uint32_t number_of_location_catalog_entries =
155 code_info.GetNumberOfDexRegisterLocationCatalogEntries();
156 ASSERT_EQ(4u, number_of_location_catalog_entries);
157 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog();
158 // The Dex register location catalog contains:
159 // - three 1-byte short Dex register locations, and
160 // - one 5-byte large Dex register location.
161 size_t expected_location_catalog_size = 3u * 1u + 5u;
162 ASSERT_EQ(expected_location_catalog_size, location_catalog.Size());
163
Roland Levillain12baf472015-03-05 12:41:42 +0000164 // First stack map.
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000165 {
166 StackMap stack_map = code_info.GetStackMapAt(0);
167 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0)));
168 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64)));
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000169 ASSERT_EQ(0u, stack_map.GetDexPc(code_info));
170 ASSERT_EQ(64u, stack_map.GetNativePcOffset(code_info));
171 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(code_info));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100172
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000173 MemoryRegion stack_mask = stack_map.GetStackMask(code_info);
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000174 ASSERT_TRUE(SameBits(stack_mask, sp_mask1));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100175
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000176 ASSERT_TRUE(stack_map.HasDexRegisterMap(code_info));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000177 DexRegisterMap dex_register_map =
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000178 code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000179 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0));
180 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
181 ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
182 // The Dex register map contains:
183 // - one 1-byte live bit mask, and
184 // - one 1-byte set of location catalog entry indices composed of two 2-bit values.
185 size_t expected_dex_register_map_size = 1u + 1u;
186 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
187
188 ASSERT_EQ(Kind::kInStack,
189 dex_register_map.GetLocationKind(0, number_of_dex_registers, code_info));
190 ASSERT_EQ(Kind::kConstant,
191 dex_register_map.GetLocationKind(1, number_of_dex_registers, code_info));
192 ASSERT_EQ(Kind::kInStack,
193 dex_register_map.GetLocationInternalKind(0, number_of_dex_registers, code_info));
194 ASSERT_EQ(Kind::kConstantLargeValue,
195 dex_register_map.GetLocationInternalKind(1, number_of_dex_registers, code_info));
196 ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes(0, number_of_dex_registers, code_info));
197 ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info));
198
199 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
200 0, number_of_dex_registers, number_of_location_catalog_entries);
201 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
202 1, number_of_dex_registers, number_of_location_catalog_entries);
203 ASSERT_EQ(0u, index0);
204 ASSERT_EQ(1u, index1);
205 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
206 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
207 ASSERT_EQ(Kind::kInStack, location0.GetKind());
208 ASSERT_EQ(Kind::kConstant, location1.GetKind());
209 ASSERT_EQ(Kind::kInStack, location0.GetInternalKind());
210 ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind());
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000211 ASSERT_EQ(0, location0.GetValue());
212 ASSERT_EQ(-2, location1.GetValue());
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100213
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000214 ASSERT_TRUE(stack_map.HasInlineInfo(code_info));
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000215 InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map);
216 ASSERT_EQ(2u, inline_info.GetDepth());
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100217 ASSERT_EQ(82u, inline_info.GetMethodIndexAtDepth(0));
218 ASSERT_EQ(42u, inline_info.GetMethodIndexAtDepth(1));
219 ASSERT_EQ(3u, inline_info.GetDexPcAtDepth(0));
220 ASSERT_EQ(2u, inline_info.GetDexPcAtDepth(1));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100221 ASSERT_EQ(kDirect, inline_info.GetInvokeTypeAtDepth(0));
222 ASSERT_EQ(kStatic, inline_info.GetInvokeTypeAtDepth(1));
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000223 }
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100224
Roland Levillain12baf472015-03-05 12:41:42 +0000225 // Second stack map.
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000226 {
227 StackMap stack_map = code_info.GetStackMapAt(1);
228 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(1u)));
229 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(128u)));
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000230 ASSERT_EQ(1u, stack_map.GetDexPc(code_info));
231 ASSERT_EQ(128u, stack_map.GetNativePcOffset(code_info));
232 ASSERT_EQ(0xFFu, stack_map.GetRegisterMask(code_info));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100233
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000234 MemoryRegion stack_mask = stack_map.GetStackMask(code_info);
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000235 ASSERT_TRUE(SameBits(stack_mask, sp_mask2));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100236
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000237 ASSERT_TRUE(stack_map.HasDexRegisterMap(code_info));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000238 DexRegisterMap dex_register_map =
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000239 code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000240 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0));
241 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
242 ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
243 // The Dex register map contains:
244 // - one 1-byte live bit mask, and
245 // - one 1-byte set of location catalog entry indices composed of two 2-bit values.
246 size_t expected_dex_register_map_size = 1u + 1u;
247 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
248
249 ASSERT_EQ(Kind::kInRegister,
250 dex_register_map.GetLocationKind(0, number_of_dex_registers, code_info));
251 ASSERT_EQ(Kind::kInFpuRegister,
252 dex_register_map.GetLocationKind(1, number_of_dex_registers, code_info));
253 ASSERT_EQ(Kind::kInRegister,
254 dex_register_map.GetLocationInternalKind(0, number_of_dex_registers, code_info));
255 ASSERT_EQ(Kind::kInFpuRegister,
256 dex_register_map.GetLocationInternalKind(1, number_of_dex_registers, code_info));
257 ASSERT_EQ(18, dex_register_map.GetMachineRegister(0, number_of_dex_registers, code_info));
258 ASSERT_EQ(3, dex_register_map.GetMachineRegister(1, number_of_dex_registers, code_info));
259
260 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
261 0, number_of_dex_registers, number_of_location_catalog_entries);
262 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
263 1, number_of_dex_registers, number_of_location_catalog_entries);
264 ASSERT_EQ(2u, index0);
265 ASSERT_EQ(3u, index1);
266 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
267 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
268 ASSERT_EQ(Kind::kInRegister, location0.GetKind());
269 ASSERT_EQ(Kind::kInFpuRegister, location1.GetKind());
270 ASSERT_EQ(Kind::kInRegister, location0.GetInternalKind());
271 ASSERT_EQ(Kind::kInFpuRegister, location1.GetInternalKind());
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000272 ASSERT_EQ(18, location0.GetValue());
273 ASSERT_EQ(3, location1.GetValue());
Roland Levillain12baf472015-03-05 12:41:42 +0000274
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000275 ASSERT_FALSE(stack_map.HasInlineInfo(code_info));
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000276 }
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100277}
278
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000279TEST(StackMapTest, TestNonLiveDexRegisters) {
280 ArenaPool pool;
281 ArenaAllocator arena(&pool);
282 StackMapStream stream(&arena);
283
284 ArenaBitVector sp_mask(&arena, 0, false);
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000285 uint32_t number_of_dex_registers = 2;
Calin Juravle4f46ac52015-04-23 18:47:21 +0100286 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100287 stream.AddDexRegisterEntry(Kind::kNone, 0); // No location.
288 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100289 stream.EndStackMapEntry();
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000290
Calin Juravle4f46ac52015-04-23 18:47:21 +0100291 size_t size = stream.PrepareForFillIn();
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000292 void* memory = arena.Alloc(size, kArenaAllocMisc);
293 MemoryRegion region(memory, size);
294 stream.FillIn(region);
295
296 CodeInfo code_info(region);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000297 ASSERT_EQ(0u, code_info.GetStackMaskSize());
298 ASSERT_EQ(1u, code_info.GetNumberOfStackMaps());
299
300 uint32_t number_of_location_catalog_entries =
301 code_info.GetNumberOfDexRegisterLocationCatalogEntries();
302 ASSERT_EQ(1u, number_of_location_catalog_entries);
303 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog();
304 // The Dex register location catalog contains:
305 // - one 5-byte large Dex register location.
306 size_t expected_location_catalog_size = 5u;
307 ASSERT_EQ(expected_location_catalog_size, location_catalog.Size());
308
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000309 StackMap stack_map = code_info.GetStackMapAt(0);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000310 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0)));
311 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64)));
312 ASSERT_EQ(0u, stack_map.GetDexPc(code_info));
313 ASSERT_EQ(64u, stack_map.GetNativePcOffset(code_info));
314 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(code_info));
315
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000316 ASSERT_TRUE(stack_map.HasDexRegisterMap(code_info));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000317 DexRegisterMap dex_register_map =
318 code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers);
319 ASSERT_FALSE(dex_register_map.IsDexRegisterLive(0));
320 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
321 ASSERT_EQ(1u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
322 // The Dex register map contains:
323 // - one 1-byte live bit mask.
324 // No space is allocated for the sole location catalog entry index, as it is useless.
325 size_t expected_dex_register_map_size = 1u + 0u;
326 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
327
328 ASSERT_EQ(Kind::kNone,
329 dex_register_map.GetLocationKind(0, number_of_dex_registers, code_info));
330 ASSERT_EQ(Kind::kConstant,
331 dex_register_map.GetLocationKind(1, number_of_dex_registers, code_info));
332 ASSERT_EQ(Kind::kNone,
333 dex_register_map.GetLocationInternalKind(0, number_of_dex_registers, code_info));
334 ASSERT_EQ(Kind::kConstantLargeValue,
335 dex_register_map.GetLocationInternalKind(1, number_of_dex_registers, code_info));
336 ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info));
337
338 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
339 0, number_of_dex_registers, number_of_location_catalog_entries);
340 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
341 1, number_of_dex_registers, number_of_location_catalog_entries);
342 ASSERT_EQ(DexRegisterLocationCatalog::kNoLocationEntryIndex, index0);
343 ASSERT_EQ(0u, index1);
344 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
345 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
346 ASSERT_EQ(Kind::kNone, location0.GetKind());
347 ASSERT_EQ(Kind::kConstant, location1.GetKind());
348 ASSERT_EQ(Kind::kNone, location0.GetInternalKind());
349 ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind());
350 ASSERT_EQ(0, location0.GetValue());
351 ASSERT_EQ(-2, location1.GetValue());
352
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000353 ASSERT_FALSE(stack_map.HasInlineInfo(code_info));
354}
355
356// Generate a stack map whose dex register offset is
357// StackMap::kNoDexRegisterMapSmallEncoding, and ensure we do
358// not treat it as kNoDexRegisterMap.
359TEST(StackMapTest, DexRegisterMapOffsetOverflow) {
360 ArenaPool pool;
361 ArenaAllocator arena(&pool);
362 StackMapStream stream(&arena);
363
364 ArenaBitVector sp_mask(&arena, 0, false);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000365 uint32_t number_of_dex_registers = 1024;
366 // Create the first stack map (and its Dex register map).
Calin Juravle4f46ac52015-04-23 18:47:21 +0100367 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000368 uint32_t number_of_dex_live_registers_in_dex_register_map_0 = number_of_dex_registers - 8;
369 for (uint32_t i = 0; i < number_of_dex_live_registers_in_dex_register_map_0; ++i) {
370 // Use two different Dex register locations to populate this map,
371 // as using a single value (in the whole CodeInfo object) would
372 // make this Dex register mapping data empty (see
373 // art::DexRegisterMap::SingleEntrySizeInBits).
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100374 stream.AddDexRegisterEntry(Kind::kConstant, i % 2); // Short location.
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000375 }
Calin Juravle4f46ac52015-04-23 18:47:21 +0100376 stream.EndStackMapEntry();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000377 // Create the second stack map (and its Dex register map).
Calin Juravle4f46ac52015-04-23 18:47:21 +0100378 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000379 for (uint32_t i = 0; i < number_of_dex_registers; ++i) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100380 stream.AddDexRegisterEntry(Kind::kConstant, 0); // Short location.
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000381 }
Calin Juravle4f46ac52015-04-23 18:47:21 +0100382 stream.EndStackMapEntry();
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000383
Calin Juravle4f46ac52015-04-23 18:47:21 +0100384 size_t size = stream.PrepareForFillIn();
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000385 void* memory = arena.Alloc(size, kArenaAllocMisc);
386 MemoryRegion region(memory, size);
387 stream.FillIn(region);
388
389 CodeInfo code_info(region);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000390 // The location catalog contains two entries (DexRegisterLocation(kConstant, 0)
391 // and DexRegisterLocation(kConstant, 1)), therefore the location catalog index
392 // has a size of 1 bit.
393 uint32_t number_of_location_catalog_entries =
394 code_info.GetNumberOfDexRegisterLocationCatalogEntries();
395 ASSERT_EQ(2u, number_of_location_catalog_entries);
396 ASSERT_EQ(1u, DexRegisterMap::SingleEntrySizeInBits(number_of_location_catalog_entries));
397
398 // The first Dex register map contains:
399 // - a live register bit mask for 1024 registers (that is, 128 bytes of
400 // data); and
401 // - Dex register mapping information for 1016 1-bit Dex (live) register
402 // locations (that is, 127 bytes of data).
403 // Hence it has a size of 255 bytes, and therefore...
404 ASSERT_EQ(128u, DexRegisterMap::GetLiveBitMaskSize(number_of_dex_registers));
405 StackMap stack_map0 = code_info.GetStackMapAt(0);
406 DexRegisterMap dex_register_map0 =
407 code_info.GetDexRegisterMapOf(stack_map0, number_of_dex_registers);
408 ASSERT_EQ(127u, dex_register_map0.GetLocationMappingDataSize(number_of_dex_registers,
409 number_of_location_catalog_entries));
410 ASSERT_EQ(255u, dex_register_map0.Size());
411
412 StackMap stack_map1 = code_info.GetStackMapAt(1);
413 ASSERT_TRUE(stack_map1.HasDexRegisterMap(code_info));
414 // ...the offset of the second Dex register map (relative to the
415 // beginning of the Dex register maps region) is 255 (i.e.,
416 // kNoDexRegisterMapSmallEncoding).
Nicolas Geoffray896f8f72015-03-30 15:44:25 +0100417 ASSERT_NE(stack_map1.GetDexRegisterMapOffset(code_info), StackMap::kNoDexRegisterMap);
418 ASSERT_EQ(stack_map1.GetDexRegisterMapOffset(code_info), 0xFFu);
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000419}
420
Calin Juravle6ae70962015-03-18 16:31:28 +0000421TEST(StackMapTest, TestShareDexRegisterMap) {
422 ArenaPool pool;
423 ArenaAllocator arena(&pool);
424 StackMapStream stream(&arena);
425
426 ArenaBitVector sp_mask(&arena, 0, false);
427 uint32_t number_of_dex_registers = 2;
428 // First stack map.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100429 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100430 stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location.
431 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100432 stream.EndStackMapEntry();
Calin Juravle6ae70962015-03-18 16:31:28 +0000433 // Second stack map, which should share the same dex register map.
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::kInRegister, 0); // Short location.
436 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100437 stream.EndStackMapEntry();
Calin Juravle6ae70962015-03-18 16:31:28 +0000438 // Third stack map (doesn't share the dex register map).
Calin Juravle4f46ac52015-04-23 18:47:21 +0100439 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100440 stream.AddDexRegisterEntry(Kind::kInRegister, 2); // Short location.
441 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100442 stream.EndStackMapEntry();
Calin Juravle6ae70962015-03-18 16:31:28 +0000443
Calin Juravle4f46ac52015-04-23 18:47:21 +0100444 size_t size = stream.PrepareForFillIn();
Calin Juravle6ae70962015-03-18 16:31:28 +0000445 void* memory = arena.Alloc(size, kArenaAllocMisc);
446 MemoryRegion region(memory, size);
447 stream.FillIn(region);
448
449 CodeInfo ci(region);
450 // Verify first stack map.
451 StackMap sm0 = ci.GetStackMapAt(0);
452 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm0, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000453 ASSERT_EQ(0, dex_registers0.GetMachineRegister(0, number_of_dex_registers, ci));
454 ASSERT_EQ(-2, dex_registers0.GetConstant(1, number_of_dex_registers, ci));
Calin Juravle6ae70962015-03-18 16:31:28 +0000455
456 // Verify second stack map.
457 StackMap sm1 = ci.GetStackMapAt(1);
458 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapOf(sm1, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000459 ASSERT_EQ(0, dex_registers1.GetMachineRegister(0, number_of_dex_registers, ci));
460 ASSERT_EQ(-2, dex_registers1.GetConstant(1, number_of_dex_registers, ci));
Calin Juravle6ae70962015-03-18 16:31:28 +0000461
462 // Verify third stack map.
463 StackMap sm2 = ci.GetStackMapAt(2);
464 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapOf(sm2, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000465 ASSERT_EQ(2, dex_registers2.GetMachineRegister(0, number_of_dex_registers, ci));
466 ASSERT_EQ(-2, dex_registers2.GetConstant(1, number_of_dex_registers, ci));
Calin Juravle6ae70962015-03-18 16:31:28 +0000467
468 // Verify dex register map offsets.
469 ASSERT_EQ(sm0.GetDexRegisterMapOffset(ci), sm1.GetDexRegisterMapOffset(ci));
470 ASSERT_NE(sm0.GetDexRegisterMapOffset(ci), sm2.GetDexRegisterMapOffset(ci));
471 ASSERT_NE(sm1.GetDexRegisterMapOffset(ci), sm2.GetDexRegisterMapOffset(ci));
472}
473
Roland Levillaina552e1c2015-03-26 15:01:03 +0000474TEST(StackMapTest, TestNoDexRegisterMap) {
475 ArenaPool pool;
476 ArenaAllocator arena(&pool);
477 StackMapStream stream(&arena);
478
479 ArenaBitVector sp_mask(&arena, 0, false);
480 uint32_t number_of_dex_registers = 0;
Calin Juravle4f46ac52015-04-23 18:47:21 +0100481 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
482 stream.EndStackMapEntry();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000483
Calin Juravle4f46ac52015-04-23 18:47:21 +0100484 size_t size = stream.PrepareForFillIn();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000485 void* memory = arena.Alloc(size, kArenaAllocMisc);
486 MemoryRegion region(memory, size);
487 stream.FillIn(region);
488
489 CodeInfo code_info(region);
490 ASSERT_EQ(0u, code_info.GetStackMaskSize());
491 ASSERT_EQ(1u, code_info.GetNumberOfStackMaps());
492
493 uint32_t number_of_location_catalog_entries =
494 code_info.GetNumberOfDexRegisterLocationCatalogEntries();
495 ASSERT_EQ(0u, number_of_location_catalog_entries);
496 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog();
497 ASSERT_EQ(0u, location_catalog.Size());
498
499 StackMap stack_map = code_info.GetStackMapAt(0);
500 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0)));
501 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64)));
502 ASSERT_EQ(0u, stack_map.GetDexPc(code_info));
503 ASSERT_EQ(64u, stack_map.GetNativePcOffset(code_info));
504 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(code_info));
505
506 ASSERT_FALSE(stack_map.HasDexRegisterMap(code_info));
507 ASSERT_FALSE(stack_map.HasInlineInfo(code_info));
508}
509
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100510TEST(StackMapTest, InlineTest) {
511 ArenaPool pool;
512 ArenaAllocator arena(&pool);
513 StackMapStream stream(&arena);
514
515 ArenaBitVector sp_mask1(&arena, 0, true);
516 sp_mask1.SetBit(2);
517 sp_mask1.SetBit(4);
518
519 // First stack map.
520 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, 2, 2);
521 stream.AddDexRegisterEntry(Kind::kInStack, 0);
522 stream.AddDexRegisterEntry(Kind::kConstant, 4);
523
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100524 stream.BeginInlineInfoEntry(42, 2, kStatic, 1);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100525 stream.AddDexRegisterEntry(Kind::kInStack, 8);
526 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100527 stream.BeginInlineInfoEntry(82, 3, kStatic, 3);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100528 stream.AddDexRegisterEntry(Kind::kInStack, 16);
529 stream.AddDexRegisterEntry(Kind::kConstant, 20);
530 stream.AddDexRegisterEntry(Kind::kInRegister, 15);
531 stream.EndInlineInfoEntry();
532
533 stream.EndStackMapEntry();
534
535 // Second stack map.
536 stream.BeginStackMapEntry(2, 22, 0x3, &sp_mask1, 2, 3);
537 stream.AddDexRegisterEntry(Kind::kInStack, 56);
538 stream.AddDexRegisterEntry(Kind::kConstant, 0);
539
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100540 stream.BeginInlineInfoEntry(42, 2, kDirect, 1);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100541 stream.AddDexRegisterEntry(Kind::kInStack, 12);
542 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100543 stream.BeginInlineInfoEntry(82, 3, kStatic, 3);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100544 stream.AddDexRegisterEntry(Kind::kInStack, 80);
545 stream.AddDexRegisterEntry(Kind::kConstant, 10);
546 stream.AddDexRegisterEntry(Kind::kInRegister, 5);
547 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100548 stream.BeginInlineInfoEntry(52, 5, kVirtual, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100549 stream.EndInlineInfoEntry();
550
551 stream.EndStackMapEntry();
552
553 // Third stack map.
554 stream.BeginStackMapEntry(4, 56, 0x3, &sp_mask1, 2, 0);
555 stream.AddDexRegisterEntry(Kind::kNone, 0);
556 stream.AddDexRegisterEntry(Kind::kConstant, 4);
557 stream.EndStackMapEntry();
558
559 // Fourth stack map.
560 stream.BeginStackMapEntry(6, 78, 0x3, &sp_mask1, 2, 3);
561 stream.AddDexRegisterEntry(Kind::kInStack, 56);
562 stream.AddDexRegisterEntry(Kind::kConstant, 0);
563
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100564 stream.BeginInlineInfoEntry(42, 2, kVirtual, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100565 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100566 stream.BeginInlineInfoEntry(52, 5, kInterface, 1);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100567 stream.AddDexRegisterEntry(Kind::kInRegister, 2);
568 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100569 stream.BeginInlineInfoEntry(52, 10, kStatic, 2);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100570 stream.AddDexRegisterEntry(Kind::kNone, 0);
571 stream.AddDexRegisterEntry(Kind::kInRegister, 3);
572 stream.EndInlineInfoEntry();
573
574 stream.EndStackMapEntry();
575
576 size_t size = stream.PrepareForFillIn();
577 void* memory = arena.Alloc(size, kArenaAllocMisc);
578 MemoryRegion region(memory, size);
579 stream.FillIn(region);
580
581 CodeInfo ci(region);
582
583 {
584 // Verify first stack map.
585 StackMap sm0 = ci.GetStackMapAt(0);
586
587 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm0, 2);
588 ASSERT_EQ(0, dex_registers0.GetStackOffsetInBytes(0, 2, ci));
589 ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci));
590
591 InlineInfo if0 = ci.GetInlineInfoOf(sm0);
592 ASSERT_EQ(2u, if0.GetDepth());
593 ASSERT_EQ(2u, if0.GetDexPcAtDepth(0));
594 ASSERT_EQ(42u, if0.GetMethodIndexAtDepth(0));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100595 ASSERT_EQ(kStatic, if0.GetInvokeTypeAtDepth(0));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100596 ASSERT_EQ(3u, if0.GetDexPcAtDepth(1));
597 ASSERT_EQ(82u, if0.GetMethodIndexAtDepth(1));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100598 ASSERT_EQ(kStatic, if0.GetInvokeTypeAtDepth(1));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100599
600 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if0, 1);
601 ASSERT_EQ(8, dex_registers1.GetStackOffsetInBytes(0, 1, ci));
602
603 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(1, if0, 3);
604 ASSERT_EQ(16, dex_registers2.GetStackOffsetInBytes(0, 3, ci));
605 ASSERT_EQ(20, dex_registers2.GetConstant(1, 3, ci));
606 ASSERT_EQ(15, dex_registers2.GetMachineRegister(2, 3, ci));
607 }
608
609 {
610 // Verify second stack map.
611 StackMap sm1 = ci.GetStackMapAt(1);
612
613 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm1, 2);
614 ASSERT_EQ(56, dex_registers0.GetStackOffsetInBytes(0, 2, ci));
615 ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci));
616
617 InlineInfo if1 = ci.GetInlineInfoOf(sm1);
618 ASSERT_EQ(3u, if1.GetDepth());
619 ASSERT_EQ(2u, if1.GetDexPcAtDepth(0));
620 ASSERT_EQ(42u, if1.GetMethodIndexAtDepth(0));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100621 ASSERT_EQ(kDirect, if1.GetInvokeTypeAtDepth(0));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100622 ASSERT_EQ(3u, if1.GetDexPcAtDepth(1));
623 ASSERT_EQ(82u, if1.GetMethodIndexAtDepth(1));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100624 ASSERT_EQ(kStatic, if1.GetInvokeTypeAtDepth(1));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100625 ASSERT_EQ(5u, if1.GetDexPcAtDepth(2));
626 ASSERT_EQ(52u, if1.GetMethodIndexAtDepth(2));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100627 ASSERT_EQ(kVirtual, if1.GetInvokeTypeAtDepth(2));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100628
629 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if1, 1);
630 ASSERT_EQ(12, dex_registers1.GetStackOffsetInBytes(0, 1, ci));
631
632 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(1, if1, 3);
633 ASSERT_EQ(80, dex_registers2.GetStackOffsetInBytes(0, 3, ci));
634 ASSERT_EQ(10, dex_registers2.GetConstant(1, 3, ci));
635 ASSERT_EQ(5, dex_registers2.GetMachineRegister(2, 3, ci));
636
637 ASSERT_FALSE(if1.HasDexRegisterMapAtDepth(2));
638 }
639
640 {
641 // Verify third stack map.
642 StackMap sm2 = ci.GetStackMapAt(2);
643
644 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm2, 2);
645 ASSERT_FALSE(dex_registers0.IsDexRegisterLive(0));
646 ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci));
647 ASSERT_FALSE(sm2.HasInlineInfo(ci));
648 }
649
650 {
651 // Verify fourth stack map.
652 StackMap sm3 = ci.GetStackMapAt(3);
653
654 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm3, 2);
655 ASSERT_EQ(56, dex_registers0.GetStackOffsetInBytes(0, 2, ci));
656 ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci));
657
658 InlineInfo if2 = ci.GetInlineInfoOf(sm3);
659 ASSERT_EQ(3u, if2.GetDepth());
660 ASSERT_EQ(2u, if2.GetDexPcAtDepth(0));
661 ASSERT_EQ(42u, if2.GetMethodIndexAtDepth(0));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100662 ASSERT_EQ(kVirtual, if2.GetInvokeTypeAtDepth(0));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100663 ASSERT_EQ(5u, if2.GetDexPcAtDepth(1));
664 ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(1));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100665 ASSERT_EQ(kInterface, if2.GetInvokeTypeAtDepth(1));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100666 ASSERT_EQ(10u, if2.GetDexPcAtDepth(2));
667 ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(2));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100668 ASSERT_EQ(kStatic, if2.GetInvokeTypeAtDepth(2));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100669
670 ASSERT_FALSE(if2.HasDexRegisterMapAtDepth(0));
671
672 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(1, if2, 1);
673 ASSERT_EQ(2, dex_registers1.GetMachineRegister(0, 1, ci));
674
675 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(2, if2, 2);
676 ASSERT_FALSE(dex_registers2.IsDexRegisterLive(0));
677 ASSERT_EQ(3, dex_registers2.GetMachineRegister(1, 2, ci));
678 }
679}
680
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100681} // namespace art