blob: 33207d92d2239d919eeb0c60ad46e6cf09d726d5 [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);
David Brazdilf677ebf2015-05-29 16:29:43 +010054 StackMapEncoding encoding = code_info.ExtractEncoding();
55 ASSERT_EQ(0u, encoding.NumberOfBytesForStackMask());
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010056 ASSERT_EQ(1u, code_info.GetNumberOfStackMaps());
57
Roland Levillain1c1da432015-07-16 11:54:44 +010058 uint32_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries();
Roland Levillaina552e1c2015-03-26 15:01:03 +000059 ASSERT_EQ(2u, number_of_location_catalog_entries);
David Brazdilf677ebf2015-05-29 16:29:43 +010060 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding);
Roland Levillaina552e1c2015-03-26 15:01:03 +000061 // 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
David Brazdilf677ebf2015-05-29 16:29:43 +010067 StackMap stack_map = code_info.GetStackMapAt(0, encoding);
68 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding)));
69 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding)));
70 ASSERT_EQ(0u, stack_map.GetDexPc(encoding));
71 ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding));
72 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010073
David Brazdilf677ebf2015-05-29 16:29:43 +010074 MemoryRegion stack_mask = stack_map.GetStackMask(encoding);
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +010075 ASSERT_TRUE(SameBits(stack_mask, sp_mask));
76
David Brazdilf677ebf2015-05-29 16:29:43 +010077 ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +000078 DexRegisterMap dex_register_map =
David Brazdilf677ebf2015-05-29 16:29:43 +010079 code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +000080 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
David Brazdilf677ebf2015-05-29 16:29:43 +010089 ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationKind(
90 0, number_of_dex_registers, code_info, encoding));
91 ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind(
92 1, number_of_dex_registers, code_info, encoding));
93 ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationInternalKind(
94 0, number_of_dex_registers, code_info, encoding));
95 ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind(
96 1, number_of_dex_registers, code_info, encoding));
97 ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes(
98 0, number_of_dex_registers, code_info, encoding));
99 ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info, encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000100
101 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
102 0, number_of_dex_registers, number_of_location_catalog_entries);
103 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
104 1, number_of_dex_registers, number_of_location_catalog_entries);
105 ASSERT_EQ(0u, index0);
106 ASSERT_EQ(1u, index1);
107 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
108 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
109 ASSERT_EQ(Kind::kInStack, location0.GetKind());
110 ASSERT_EQ(Kind::kConstant, location1.GetKind());
111 ASSERT_EQ(Kind::kInStack, location0.GetInternalKind());
112 ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind());
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000113 ASSERT_EQ(0, location0.GetValue());
114 ASSERT_EQ(-2, location1.GetValue());
Roland Levillain12baf472015-03-05 12:41:42 +0000115
David Brazdilf677ebf2015-05-29 16:29:43 +0100116 ASSERT_FALSE(stack_map.HasInlineInfo(encoding));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100117}
118
119TEST(StackMapTest, Test2) {
120 ArenaPool pool;
121 ArenaAllocator arena(&pool);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100122 StackMapStream stream(&arena);
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100123
124 ArenaBitVector sp_mask1(&arena, 0, true);
125 sp_mask1.SetBit(2);
126 sp_mask1.SetBit(4);
Roland Levillain12baf472015-03-05 12:41:42 +0000127 size_t number_of_dex_registers = 2;
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100128 size_t number_of_dex_registers_in_inline_info = 0;
Calin Juravle4f46ac52015-04-23 18:47:21 +0100129 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, number_of_dex_registers, 2);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100130 stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location.
131 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100132 stream.BeginInlineInfoEntry(82, 3, kDirect, number_of_dex_registers_in_inline_info);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100133 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100134 stream.BeginInlineInfoEntry(42, 2, kStatic, number_of_dex_registers_in_inline_info);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100135 stream.EndInlineInfoEntry();
Calin Juravle4f46ac52015-04-23 18:47:21 +0100136 stream.EndStackMapEntry();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100137
138 ArenaBitVector sp_mask2(&arena, 0, true);
139 sp_mask2.SetBit(3);
David Brazdilf10a25f2015-06-02 14:29:52 +0100140 sp_mask2.SetBit(8);
Calin Juravle4f46ac52015-04-23 18:47:21 +0100141 stream.BeginStackMapEntry(1, 128, 0xFF, &sp_mask2, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100142 stream.AddDexRegisterEntry(Kind::kInRegister, 18); // Short location.
143 stream.AddDexRegisterEntry(Kind::kInFpuRegister, 3); // Short location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100144 stream.EndStackMapEntry();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100145
Calin Juravle4f46ac52015-04-23 18:47:21 +0100146 size_t size = stream.PrepareForFillIn();
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100147 void* memory = arena.Alloc(size, kArenaAllocMisc);
148 MemoryRegion region(memory, size);
149 stream.FillIn(region);
150
Nicolas Geoffray39468442014-09-02 15:17:15 +0100151 CodeInfo code_info(region);
David Brazdilf677ebf2015-05-29 16:29:43 +0100152 StackMapEncoding encoding = code_info.ExtractEncoding();
153 ASSERT_EQ(2u, encoding.NumberOfBytesForStackMask());
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100154 ASSERT_EQ(2u, code_info.GetNumberOfStackMaps());
155
Roland Levillain1c1da432015-07-16 11:54:44 +0100156 uint32_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000157 ASSERT_EQ(4u, number_of_location_catalog_entries);
David Brazdilf677ebf2015-05-29 16:29:43 +0100158 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000159 // The Dex register location catalog contains:
160 // - three 1-byte short Dex register locations, and
161 // - one 5-byte large Dex register location.
162 size_t expected_location_catalog_size = 3u * 1u + 5u;
163 ASSERT_EQ(expected_location_catalog_size, location_catalog.Size());
164
Roland Levillain12baf472015-03-05 12:41:42 +0000165 // First stack map.
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000166 {
David Brazdilf677ebf2015-05-29 16:29:43 +0100167 StackMap stack_map = code_info.GetStackMapAt(0, encoding);
168 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding)));
169 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding)));
170 ASSERT_EQ(0u, stack_map.GetDexPc(encoding));
171 ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding));
172 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100173
David Brazdilf677ebf2015-05-29 16:29:43 +0100174 MemoryRegion stack_mask = stack_map.GetStackMask(encoding);
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000175 ASSERT_TRUE(SameBits(stack_mask, sp_mask1));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100176
David Brazdilf677ebf2015-05-29 16:29:43 +0100177 ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000178 DexRegisterMap dex_register_map =
David Brazdilf677ebf2015-05-29 16:29:43 +0100179 code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000180 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0));
181 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
182 ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
183 // The Dex register map contains:
184 // - one 1-byte live bit mask, and
185 // - one 1-byte set of location catalog entry indices composed of two 2-bit values.
186 size_t expected_dex_register_map_size = 1u + 1u;
187 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
188
David Brazdilf677ebf2015-05-29 16:29:43 +0100189 ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationKind(
190 0, number_of_dex_registers, code_info, encoding));
191 ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind(
192 1, number_of_dex_registers, code_info, encoding));
193 ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationInternalKind(
194 0, number_of_dex_registers, code_info, encoding));
195 ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind(
196 1, number_of_dex_registers, code_info, encoding));
197 ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes(
198 0, number_of_dex_registers, code_info, encoding));
199 ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info, encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000200
201 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
202 0, number_of_dex_registers, number_of_location_catalog_entries);
203 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
204 1, number_of_dex_registers, number_of_location_catalog_entries);
205 ASSERT_EQ(0u, index0);
206 ASSERT_EQ(1u, index1);
207 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
208 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
209 ASSERT_EQ(Kind::kInStack, location0.GetKind());
210 ASSERT_EQ(Kind::kConstant, location1.GetKind());
211 ASSERT_EQ(Kind::kInStack, location0.GetInternalKind());
212 ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind());
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000213 ASSERT_EQ(0, location0.GetValue());
214 ASSERT_EQ(-2, location1.GetValue());
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100215
David Brazdilf677ebf2015-05-29 16:29:43 +0100216 ASSERT_TRUE(stack_map.HasInlineInfo(encoding));
217 InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map, encoding);
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000218 ASSERT_EQ(2u, inline_info.GetDepth());
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100219 ASSERT_EQ(82u, inline_info.GetMethodIndexAtDepth(0));
220 ASSERT_EQ(42u, inline_info.GetMethodIndexAtDepth(1));
221 ASSERT_EQ(3u, inline_info.GetDexPcAtDepth(0));
222 ASSERT_EQ(2u, inline_info.GetDexPcAtDepth(1));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100223 ASSERT_EQ(kDirect, inline_info.GetInvokeTypeAtDepth(0));
224 ASSERT_EQ(kStatic, inline_info.GetInvokeTypeAtDepth(1));
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000225 }
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100226
Roland Levillain12baf472015-03-05 12:41:42 +0000227 // Second stack map.
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000228 {
David Brazdilf677ebf2015-05-29 16:29:43 +0100229 StackMap stack_map = code_info.GetStackMapAt(1, encoding);
230 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(1u, encoding)));
231 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(128u, encoding)));
232 ASSERT_EQ(1u, stack_map.GetDexPc(encoding));
233 ASSERT_EQ(128u, stack_map.GetNativePcOffset(encoding));
234 ASSERT_EQ(0xFFu, stack_map.GetRegisterMask(encoding));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100235
David Brazdilf677ebf2015-05-29 16:29:43 +0100236 MemoryRegion stack_mask = stack_map.GetStackMask(encoding);
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000237 ASSERT_TRUE(SameBits(stack_mask, sp_mask2));
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100238
David Brazdilf677ebf2015-05-29 16:29:43 +0100239 ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000240 DexRegisterMap dex_register_map =
David Brazdilf677ebf2015-05-29 16:29:43 +0100241 code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000242 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0));
243 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
244 ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
245 // The Dex register map contains:
246 // - one 1-byte live bit mask, and
247 // - one 1-byte set of location catalog entry indices composed of two 2-bit values.
248 size_t expected_dex_register_map_size = 1u + 1u;
249 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
250
David Brazdilf677ebf2015-05-29 16:29:43 +0100251 ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationKind(
252 0, number_of_dex_registers, code_info, encoding));
253 ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationKind(
254 1, number_of_dex_registers, code_info, encoding));
255 ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationInternalKind(
256 0, number_of_dex_registers, code_info, encoding));
257 ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationInternalKind(
258 1, number_of_dex_registers, code_info, encoding));
259 ASSERT_EQ(18, dex_register_map.GetMachineRegister(
260 0, number_of_dex_registers, code_info, encoding));
261 ASSERT_EQ(3, dex_register_map.GetMachineRegister(
262 1, number_of_dex_registers, code_info, encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000263
264 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
265 0, number_of_dex_registers, number_of_location_catalog_entries);
266 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
267 1, number_of_dex_registers, number_of_location_catalog_entries);
268 ASSERT_EQ(2u, index0);
269 ASSERT_EQ(3u, index1);
270 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
271 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
272 ASSERT_EQ(Kind::kInRegister, location0.GetKind());
273 ASSERT_EQ(Kind::kInFpuRegister, location1.GetKind());
274 ASSERT_EQ(Kind::kInRegister, location0.GetInternalKind());
275 ASSERT_EQ(Kind::kInFpuRegister, location1.GetInternalKind());
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000276 ASSERT_EQ(18, location0.GetValue());
277 ASSERT_EQ(3, location1.GetValue());
Roland Levillain12baf472015-03-05 12:41:42 +0000278
David Brazdilf677ebf2015-05-29 16:29:43 +0100279 ASSERT_FALSE(stack_map.HasInlineInfo(encoding));
Roland Levillaina2d8ec62015-03-12 15:25:29 +0000280 }
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100281}
282
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000283TEST(StackMapTest, TestNonLiveDexRegisters) {
284 ArenaPool pool;
285 ArenaAllocator arena(&pool);
286 StackMapStream stream(&arena);
287
288 ArenaBitVector sp_mask(&arena, 0, false);
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000289 uint32_t number_of_dex_registers = 2;
Calin Juravle4f46ac52015-04-23 18:47:21 +0100290 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100291 stream.AddDexRegisterEntry(Kind::kNone, 0); // No location.
292 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100293 stream.EndStackMapEntry();
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000294
Calin Juravle4f46ac52015-04-23 18:47:21 +0100295 size_t size = stream.PrepareForFillIn();
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000296 void* memory = arena.Alloc(size, kArenaAllocMisc);
297 MemoryRegion region(memory, size);
298 stream.FillIn(region);
299
300 CodeInfo code_info(region);
David Brazdilf677ebf2015-05-29 16:29:43 +0100301 StackMapEncoding encoding = code_info.ExtractEncoding();
302 ASSERT_EQ(0u, encoding.NumberOfBytesForStackMask());
Roland Levillaina552e1c2015-03-26 15:01:03 +0000303 ASSERT_EQ(1u, code_info.GetNumberOfStackMaps());
304
Roland Levillain1c1da432015-07-16 11:54:44 +0100305 uint32_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000306 ASSERT_EQ(1u, number_of_location_catalog_entries);
David Brazdilf677ebf2015-05-29 16:29:43 +0100307 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000308 // The Dex register location catalog contains:
309 // - one 5-byte large Dex register location.
310 size_t expected_location_catalog_size = 5u;
311 ASSERT_EQ(expected_location_catalog_size, location_catalog.Size());
312
David Brazdilf677ebf2015-05-29 16:29:43 +0100313 StackMap stack_map = code_info.GetStackMapAt(0, encoding);
314 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding)));
315 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding)));
316 ASSERT_EQ(0u, stack_map.GetDexPc(encoding));
317 ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding));
318 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000319
David Brazdilf677ebf2015-05-29 16:29:43 +0100320 ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000321 DexRegisterMap dex_register_map =
David Brazdilf677ebf2015-05-29 16:29:43 +0100322 code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000323 ASSERT_FALSE(dex_register_map.IsDexRegisterLive(0));
324 ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1));
325 ASSERT_EQ(1u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers));
326 // The Dex register map contains:
327 // - one 1-byte live bit mask.
328 // No space is allocated for the sole location catalog entry index, as it is useless.
329 size_t expected_dex_register_map_size = 1u + 0u;
330 ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size());
331
David Brazdilf677ebf2015-05-29 16:29:43 +0100332 ASSERT_EQ(Kind::kNone, dex_register_map.GetLocationKind(
333 0, number_of_dex_registers, code_info, encoding));
334 ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind(
335 1, number_of_dex_registers, code_info, encoding));
336 ASSERT_EQ(Kind::kNone, dex_register_map.GetLocationInternalKind(
337 0, number_of_dex_registers, code_info, encoding));
338 ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind(
339 1, number_of_dex_registers, code_info, encoding));
340 ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info, encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000341
342 size_t index0 = dex_register_map.GetLocationCatalogEntryIndex(
343 0, number_of_dex_registers, number_of_location_catalog_entries);
344 size_t index1 = dex_register_map.GetLocationCatalogEntryIndex(
345 1, number_of_dex_registers, number_of_location_catalog_entries);
346 ASSERT_EQ(DexRegisterLocationCatalog::kNoLocationEntryIndex, index0);
347 ASSERT_EQ(0u, index1);
348 DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0);
349 DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1);
350 ASSERT_EQ(Kind::kNone, location0.GetKind());
351 ASSERT_EQ(Kind::kConstant, location1.GetKind());
352 ASSERT_EQ(Kind::kNone, location0.GetInternalKind());
353 ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind());
354 ASSERT_EQ(0, location0.GetValue());
355 ASSERT_EQ(-2, location1.GetValue());
356
David Brazdilf677ebf2015-05-29 16:29:43 +0100357 ASSERT_FALSE(stack_map.HasInlineInfo(encoding));
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000358}
359
360// Generate a stack map whose dex register offset is
361// StackMap::kNoDexRegisterMapSmallEncoding, and ensure we do
362// not treat it as kNoDexRegisterMap.
363TEST(StackMapTest, DexRegisterMapOffsetOverflow) {
364 ArenaPool pool;
365 ArenaAllocator arena(&pool);
366 StackMapStream stream(&arena);
367
368 ArenaBitVector sp_mask(&arena, 0, false);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000369 uint32_t number_of_dex_registers = 1024;
370 // Create the first stack map (and its Dex register map).
Calin Juravle4f46ac52015-04-23 18:47:21 +0100371 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000372 uint32_t number_of_dex_live_registers_in_dex_register_map_0 = number_of_dex_registers - 8;
373 for (uint32_t i = 0; i < number_of_dex_live_registers_in_dex_register_map_0; ++i) {
374 // Use two different Dex register locations to populate this map,
375 // as using a single value (in the whole CodeInfo object) would
376 // make this Dex register mapping data empty (see
377 // art::DexRegisterMap::SingleEntrySizeInBits).
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100378 stream.AddDexRegisterEntry(Kind::kConstant, i % 2); // Short location.
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000379 }
Calin Juravle4f46ac52015-04-23 18:47:21 +0100380 stream.EndStackMapEntry();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000381 // Create the second stack map (and its Dex register map).
Calin Juravle4f46ac52015-04-23 18:47:21 +0100382 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000383 for (uint32_t i = 0; i < number_of_dex_registers; ++i) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100384 stream.AddDexRegisterEntry(Kind::kConstant, 0); // Short location.
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000385 }
Calin Juravle4f46ac52015-04-23 18:47:21 +0100386 stream.EndStackMapEntry();
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000387
Calin Juravle4f46ac52015-04-23 18:47:21 +0100388 size_t size = stream.PrepareForFillIn();
Nicolas Geoffray004c2302015-03-20 10:06:38 +0000389 void* memory = arena.Alloc(size, kArenaAllocMisc);
390 MemoryRegion region(memory, size);
391 stream.FillIn(region);
392
393 CodeInfo code_info(region);
David Brazdilf677ebf2015-05-29 16:29:43 +0100394 StackMapEncoding encoding = code_info.ExtractEncoding();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000395 // The location catalog contains two entries (DexRegisterLocation(kConstant, 0)
396 // and DexRegisterLocation(kConstant, 1)), therefore the location catalog index
397 // has a size of 1 bit.
Roland Levillain1c1da432015-07-16 11:54:44 +0100398 uint32_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000399 ASSERT_EQ(2u, number_of_location_catalog_entries);
400 ASSERT_EQ(1u, DexRegisterMap::SingleEntrySizeInBits(number_of_location_catalog_entries));
401
402 // The first Dex register map contains:
403 // - a live register bit mask for 1024 registers (that is, 128 bytes of
404 // data); and
405 // - Dex register mapping information for 1016 1-bit Dex (live) register
406 // locations (that is, 127 bytes of data).
407 // Hence it has a size of 255 bytes, and therefore...
408 ASSERT_EQ(128u, DexRegisterMap::GetLiveBitMaskSize(number_of_dex_registers));
David Brazdilf677ebf2015-05-29 16:29:43 +0100409 StackMap stack_map0 = code_info.GetStackMapAt(0, encoding);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000410 DexRegisterMap dex_register_map0 =
David Brazdilf677ebf2015-05-29 16:29:43 +0100411 code_info.GetDexRegisterMapOf(stack_map0, encoding, number_of_dex_registers);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000412 ASSERT_EQ(127u, dex_register_map0.GetLocationMappingDataSize(number_of_dex_registers,
413 number_of_location_catalog_entries));
414 ASSERT_EQ(255u, dex_register_map0.Size());
415
David Brazdilf677ebf2015-05-29 16:29:43 +0100416 StackMap stack_map1 = code_info.GetStackMapAt(1, encoding);
417 ASSERT_TRUE(stack_map1.HasDexRegisterMap(encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000418 // ...the offset of the second Dex register map (relative to the
419 // beginning of the Dex register maps region) is 255 (i.e.,
420 // kNoDexRegisterMapSmallEncoding).
David Brazdilf677ebf2015-05-29 16:29:43 +0100421 ASSERT_NE(stack_map1.GetDexRegisterMapOffset(encoding), StackMap::kNoDexRegisterMap);
422 ASSERT_EQ(stack_map1.GetDexRegisterMapOffset(encoding), 0xFFu);
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000423}
424
Calin Juravle6ae70962015-03-18 16:31:28 +0000425TEST(StackMapTest, TestShareDexRegisterMap) {
426 ArenaPool pool;
427 ArenaAllocator arena(&pool);
428 StackMapStream stream(&arena);
429
430 ArenaBitVector sp_mask(&arena, 0, false);
431 uint32_t number_of_dex_registers = 2;
432 // First stack map.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100433 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100434 stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location.
435 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100436 stream.EndStackMapEntry();
Calin Juravle6ae70962015-03-18 16:31:28 +0000437 // Second stack map, which should share the same dex register map.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100438 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100439 stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location.
440 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100441 stream.EndStackMapEntry();
Calin Juravle6ae70962015-03-18 16:31:28 +0000442 // Third stack map (doesn't share the dex register map).
Calin Juravle4f46ac52015-04-23 18:47:21 +0100443 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100444 stream.AddDexRegisterEntry(Kind::kInRegister, 2); // Short location.
445 stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location.
Calin Juravle4f46ac52015-04-23 18:47:21 +0100446 stream.EndStackMapEntry();
Calin Juravle6ae70962015-03-18 16:31:28 +0000447
Calin Juravle4f46ac52015-04-23 18:47:21 +0100448 size_t size = stream.PrepareForFillIn();
Calin Juravle6ae70962015-03-18 16:31:28 +0000449 void* memory = arena.Alloc(size, kArenaAllocMisc);
450 MemoryRegion region(memory, size);
451 stream.FillIn(region);
452
453 CodeInfo ci(region);
David Brazdilf677ebf2015-05-29 16:29:43 +0100454 StackMapEncoding encoding = ci.ExtractEncoding();
455
Calin Juravle6ae70962015-03-18 16:31:28 +0000456 // Verify first stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100457 StackMap sm0 = ci.GetStackMapAt(0, encoding);
458 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm0, encoding, number_of_dex_registers);
459 ASSERT_EQ(0, dex_registers0.GetMachineRegister(0, number_of_dex_registers, ci, encoding));
460 ASSERT_EQ(-2, dex_registers0.GetConstant(1, number_of_dex_registers, ci, encoding));
Calin Juravle6ae70962015-03-18 16:31:28 +0000461
462 // Verify second stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100463 StackMap sm1 = ci.GetStackMapAt(1, encoding);
464 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapOf(sm1, encoding, number_of_dex_registers);
465 ASSERT_EQ(0, dex_registers1.GetMachineRegister(0, number_of_dex_registers, ci, encoding));
466 ASSERT_EQ(-2, dex_registers1.GetConstant(1, number_of_dex_registers, ci, encoding));
Calin Juravle6ae70962015-03-18 16:31:28 +0000467
468 // Verify third stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100469 StackMap sm2 = ci.GetStackMapAt(2, encoding);
470 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapOf(sm2, encoding, number_of_dex_registers);
471 ASSERT_EQ(2, dex_registers2.GetMachineRegister(0, number_of_dex_registers, ci, encoding));
472 ASSERT_EQ(-2, dex_registers2.GetConstant(1, number_of_dex_registers, ci, encoding));
Calin Juravle6ae70962015-03-18 16:31:28 +0000473
474 // Verify dex register map offsets.
David Brazdilf677ebf2015-05-29 16:29:43 +0100475 ASSERT_EQ(sm0.GetDexRegisterMapOffset(encoding), sm1.GetDexRegisterMapOffset(encoding));
476 ASSERT_NE(sm0.GetDexRegisterMapOffset(encoding), sm2.GetDexRegisterMapOffset(encoding));
477 ASSERT_NE(sm1.GetDexRegisterMapOffset(encoding), sm2.GetDexRegisterMapOffset(encoding));
Calin Juravle6ae70962015-03-18 16:31:28 +0000478}
479
Roland Levillaina552e1c2015-03-26 15:01:03 +0000480TEST(StackMapTest, TestNoDexRegisterMap) {
481 ArenaPool pool;
482 ArenaAllocator arena(&pool);
483 StackMapStream stream(&arena);
484
485 ArenaBitVector sp_mask(&arena, 0, false);
486 uint32_t number_of_dex_registers = 0;
Calin Juravle4f46ac52015-04-23 18:47:21 +0100487 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0);
488 stream.EndStackMapEntry();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000489
Calin Juravle4f46ac52015-04-23 18:47:21 +0100490 size_t size = stream.PrepareForFillIn();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000491 void* memory = arena.Alloc(size, kArenaAllocMisc);
492 MemoryRegion region(memory, size);
493 stream.FillIn(region);
494
495 CodeInfo code_info(region);
David Brazdilf677ebf2015-05-29 16:29:43 +0100496 StackMapEncoding encoding = code_info.ExtractEncoding();
497 ASSERT_EQ(0u, encoding.NumberOfBytesForStackMask());
Roland Levillaina552e1c2015-03-26 15:01:03 +0000498 ASSERT_EQ(1u, code_info.GetNumberOfStackMaps());
499
Roland Levillain1c1da432015-07-16 11:54:44 +0100500 uint32_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries();
Roland Levillaina552e1c2015-03-26 15:01:03 +0000501 ASSERT_EQ(0u, number_of_location_catalog_entries);
David Brazdilf677ebf2015-05-29 16:29:43 +0100502 DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding);
Roland Levillaina552e1c2015-03-26 15:01:03 +0000503 ASSERT_EQ(0u, location_catalog.Size());
504
David Brazdilf677ebf2015-05-29 16:29:43 +0100505 StackMap stack_map = code_info.GetStackMapAt(0, encoding);
506 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding)));
507 ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding)));
508 ASSERT_EQ(0u, stack_map.GetDexPc(encoding));
509 ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding));
510 ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000511
David Brazdilf677ebf2015-05-29 16:29:43 +0100512 ASSERT_FALSE(stack_map.HasDexRegisterMap(encoding));
513 ASSERT_FALSE(stack_map.HasInlineInfo(encoding));
Roland Levillaina552e1c2015-03-26 15:01:03 +0000514}
515
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100516TEST(StackMapTest, InlineTest) {
517 ArenaPool pool;
518 ArenaAllocator arena(&pool);
519 StackMapStream stream(&arena);
520
521 ArenaBitVector sp_mask1(&arena, 0, true);
522 sp_mask1.SetBit(2);
523 sp_mask1.SetBit(4);
524
525 // First stack map.
526 stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, 2, 2);
527 stream.AddDexRegisterEntry(Kind::kInStack, 0);
528 stream.AddDexRegisterEntry(Kind::kConstant, 4);
529
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100530 stream.BeginInlineInfoEntry(42, 2, kStatic, 1);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100531 stream.AddDexRegisterEntry(Kind::kInStack, 8);
532 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100533 stream.BeginInlineInfoEntry(82, 3, kStatic, 3);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100534 stream.AddDexRegisterEntry(Kind::kInStack, 16);
535 stream.AddDexRegisterEntry(Kind::kConstant, 20);
536 stream.AddDexRegisterEntry(Kind::kInRegister, 15);
537 stream.EndInlineInfoEntry();
538
539 stream.EndStackMapEntry();
540
541 // Second stack map.
542 stream.BeginStackMapEntry(2, 22, 0x3, &sp_mask1, 2, 3);
543 stream.AddDexRegisterEntry(Kind::kInStack, 56);
544 stream.AddDexRegisterEntry(Kind::kConstant, 0);
545
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100546 stream.BeginInlineInfoEntry(42, 2, kDirect, 1);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100547 stream.AddDexRegisterEntry(Kind::kInStack, 12);
548 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100549 stream.BeginInlineInfoEntry(82, 3, kStatic, 3);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100550 stream.AddDexRegisterEntry(Kind::kInStack, 80);
551 stream.AddDexRegisterEntry(Kind::kConstant, 10);
552 stream.AddDexRegisterEntry(Kind::kInRegister, 5);
553 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100554 stream.BeginInlineInfoEntry(52, 5, kVirtual, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100555 stream.EndInlineInfoEntry();
556
557 stream.EndStackMapEntry();
558
559 // Third stack map.
560 stream.BeginStackMapEntry(4, 56, 0x3, &sp_mask1, 2, 0);
561 stream.AddDexRegisterEntry(Kind::kNone, 0);
562 stream.AddDexRegisterEntry(Kind::kConstant, 4);
563 stream.EndStackMapEntry();
564
565 // Fourth stack map.
566 stream.BeginStackMapEntry(6, 78, 0x3, &sp_mask1, 2, 3);
567 stream.AddDexRegisterEntry(Kind::kInStack, 56);
568 stream.AddDexRegisterEntry(Kind::kConstant, 0);
569
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100570 stream.BeginInlineInfoEntry(42, 2, kVirtual, 0);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100571 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100572 stream.BeginInlineInfoEntry(52, 5, kInterface, 1);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100573 stream.AddDexRegisterEntry(Kind::kInRegister, 2);
574 stream.EndInlineInfoEntry();
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100575 stream.BeginInlineInfoEntry(52, 10, kStatic, 2);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100576 stream.AddDexRegisterEntry(Kind::kNone, 0);
577 stream.AddDexRegisterEntry(Kind::kInRegister, 3);
578 stream.EndInlineInfoEntry();
579
580 stream.EndStackMapEntry();
581
582 size_t size = stream.PrepareForFillIn();
583 void* memory = arena.Alloc(size, kArenaAllocMisc);
584 MemoryRegion region(memory, size);
585 stream.FillIn(region);
586
587 CodeInfo ci(region);
David Brazdilf677ebf2015-05-29 16:29:43 +0100588 StackMapEncoding encoding = ci.ExtractEncoding();
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100589
590 {
591 // Verify first stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100592 StackMap sm0 = ci.GetStackMapAt(0, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100593
David Brazdilf677ebf2015-05-29 16:29:43 +0100594 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm0, encoding, 2);
595 ASSERT_EQ(0, dex_registers0.GetStackOffsetInBytes(0, 2, ci, encoding));
596 ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100597
David Brazdilf677ebf2015-05-29 16:29:43 +0100598 InlineInfo if0 = ci.GetInlineInfoOf(sm0, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100599 ASSERT_EQ(2u, if0.GetDepth());
600 ASSERT_EQ(2u, if0.GetDexPcAtDepth(0));
601 ASSERT_EQ(42u, if0.GetMethodIndexAtDepth(0));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100602 ASSERT_EQ(kStatic, if0.GetInvokeTypeAtDepth(0));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100603 ASSERT_EQ(3u, if0.GetDexPcAtDepth(1));
604 ASSERT_EQ(82u, if0.GetMethodIndexAtDepth(1));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100605 ASSERT_EQ(kStatic, if0.GetInvokeTypeAtDepth(1));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100606
David Brazdilf677ebf2015-05-29 16:29:43 +0100607 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if0, encoding, 1);
608 ASSERT_EQ(8, dex_registers1.GetStackOffsetInBytes(0, 1, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100609
David Brazdilf677ebf2015-05-29 16:29:43 +0100610 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(1, if0, encoding, 3);
611 ASSERT_EQ(16, dex_registers2.GetStackOffsetInBytes(0, 3, ci, encoding));
612 ASSERT_EQ(20, dex_registers2.GetConstant(1, 3, ci, encoding));
613 ASSERT_EQ(15, dex_registers2.GetMachineRegister(2, 3, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100614 }
615
616 {
617 // Verify second stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100618 StackMap sm1 = ci.GetStackMapAt(1, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100619
David Brazdilf677ebf2015-05-29 16:29:43 +0100620 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm1, encoding, 2);
621 ASSERT_EQ(56, dex_registers0.GetStackOffsetInBytes(0, 2, ci, encoding));
622 ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100623
David Brazdilf677ebf2015-05-29 16:29:43 +0100624 InlineInfo if1 = ci.GetInlineInfoOf(sm1, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100625 ASSERT_EQ(3u, if1.GetDepth());
626 ASSERT_EQ(2u, if1.GetDexPcAtDepth(0));
627 ASSERT_EQ(42u, if1.GetMethodIndexAtDepth(0));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100628 ASSERT_EQ(kDirect, if1.GetInvokeTypeAtDepth(0));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100629 ASSERT_EQ(3u, if1.GetDexPcAtDepth(1));
630 ASSERT_EQ(82u, if1.GetMethodIndexAtDepth(1));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100631 ASSERT_EQ(kStatic, if1.GetInvokeTypeAtDepth(1));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100632 ASSERT_EQ(5u, if1.GetDexPcAtDepth(2));
633 ASSERT_EQ(52u, if1.GetMethodIndexAtDepth(2));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100634 ASSERT_EQ(kVirtual, if1.GetInvokeTypeAtDepth(2));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100635
David Brazdilf677ebf2015-05-29 16:29:43 +0100636 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if1, encoding, 1);
637 ASSERT_EQ(12, dex_registers1.GetStackOffsetInBytes(0, 1, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100638
David Brazdilf677ebf2015-05-29 16:29:43 +0100639 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(1, if1, encoding, 3);
640 ASSERT_EQ(80, dex_registers2.GetStackOffsetInBytes(0, 3, ci, encoding));
641 ASSERT_EQ(10, dex_registers2.GetConstant(1, 3, ci, encoding));
642 ASSERT_EQ(5, dex_registers2.GetMachineRegister(2, 3, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100643
644 ASSERT_FALSE(if1.HasDexRegisterMapAtDepth(2));
645 }
646
647 {
648 // Verify third stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100649 StackMap sm2 = ci.GetStackMapAt(2, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100650
David Brazdilf677ebf2015-05-29 16:29:43 +0100651 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm2, encoding, 2);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100652 ASSERT_FALSE(dex_registers0.IsDexRegisterLive(0));
David Brazdilf677ebf2015-05-29 16:29:43 +0100653 ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci, encoding));
654 ASSERT_FALSE(sm2.HasInlineInfo(encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100655 }
656
657 {
658 // Verify fourth stack map.
David Brazdilf677ebf2015-05-29 16:29:43 +0100659 StackMap sm3 = ci.GetStackMapAt(3, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100660
David Brazdilf677ebf2015-05-29 16:29:43 +0100661 DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm3, encoding, 2);
662 ASSERT_EQ(56, dex_registers0.GetStackOffsetInBytes(0, 2, ci, encoding));
663 ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100664
David Brazdilf677ebf2015-05-29 16:29:43 +0100665 InlineInfo if2 = ci.GetInlineInfoOf(sm3, encoding);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100666 ASSERT_EQ(3u, if2.GetDepth());
667 ASSERT_EQ(2u, if2.GetDexPcAtDepth(0));
668 ASSERT_EQ(42u, if2.GetMethodIndexAtDepth(0));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100669 ASSERT_EQ(kVirtual, if2.GetInvokeTypeAtDepth(0));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100670 ASSERT_EQ(5u, if2.GetDexPcAtDepth(1));
671 ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(1));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100672 ASSERT_EQ(kInterface, if2.GetInvokeTypeAtDepth(1));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100673 ASSERT_EQ(10u, if2.GetDexPcAtDepth(2));
674 ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(2));
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100675 ASSERT_EQ(kStatic, if2.GetInvokeTypeAtDepth(2));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100676
677 ASSERT_FALSE(if2.HasDexRegisterMapAtDepth(0));
678
David Brazdilf677ebf2015-05-29 16:29:43 +0100679 DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(1, if2, encoding, 1);
680 ASSERT_EQ(2, dex_registers1.GetMachineRegister(0, 1, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100681
David Brazdilf677ebf2015-05-29 16:29:43 +0100682 DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(2, if2, encoding, 2);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100683 ASSERT_FALSE(dex_registers2.IsDexRegisterLive(0));
David Brazdilf677ebf2015-05-29 16:29:43 +0100684 ASSERT_EQ(3, dex_registers2.GetMachineRegister(1, 2, ci, encoding));
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100685 }
686}
687
Nicolas Geoffray99ea58c2014-07-02 15:08:17 +0100688} // namespace art