Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1 | /* |
| 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 Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 18 | |
| 19 | #include "base/arena_bit_vector.h" |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 20 | #include "stack_map_stream.h" |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 21 | |
| 22 | #include "gtest/gtest.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 26 | static bool SameBits(MemoryRegion region, const BitVector& bit_vector) { |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 27 | for (size_t i = 0; i < region.size_in_bits(); ++i) { |
| 28 | if (region.LoadBit(i) != bit_vector.IsBitSet(i)) { |
| 29 | return false; |
| 30 | } |
| 31 | } |
| 32 | return true; |
| 33 | } |
| 34 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 35 | using Kind = DexRegisterLocation::Kind; |
| 36 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 37 | TEST(StackMapTest, Test1) { |
| 38 | ArenaPool pool; |
| 39 | ArenaAllocator arena(&pool); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 40 | StackMapStream stream(&arena); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 41 | |
| 42 | ArenaBitVector sp_mask(&arena, 0, false); |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 43 | size_t number_of_dex_registers = 2; |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 44 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 45 | stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location. |
| 46 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Short location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 47 | stream.EndStackMapEntry(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 48 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 49 | size_t size = stream.PrepareForFillIn(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 50 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 51 | MemoryRegion region(memory, size); |
| 52 | stream.FillIn(region); |
| 53 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 54 | CodeInfo code_info(region); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 55 | StackMapEncoding encoding = code_info.ExtractEncoding(); |
| 56 | ASSERT_EQ(0u, encoding.NumberOfBytesForStackMask()); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 57 | ASSERT_EQ(1u, code_info.GetNumberOfStackMaps()); |
| 58 | |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 59 | uint32_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 60 | ASSERT_EQ(2u, number_of_location_catalog_entries); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 61 | DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 62 | // The Dex register location catalog contains: |
| 63 | // - one 1-byte short Dex register location, and |
| 64 | // - one 5-byte large Dex register location. |
| 65 | size_t expected_location_catalog_size = 1u + 5u; |
| 66 | ASSERT_EQ(expected_location_catalog_size, location_catalog.Size()); |
| 67 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 68 | StackMap stack_map = code_info.GetStackMapAt(0, encoding); |
| 69 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding))); |
| 70 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding))); |
| 71 | ASSERT_EQ(0u, stack_map.GetDexPc(encoding)); |
| 72 | ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding)); |
| 73 | ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 74 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 75 | MemoryRegion stack_mask = stack_map.GetStackMask(encoding); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 76 | ASSERT_TRUE(SameBits(stack_mask, sp_mask)); |
| 77 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 78 | ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 79 | DexRegisterMap dex_register_map = |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 80 | code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 81 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); |
| 82 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); |
| 83 | ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 84 | // The Dex register map contains: |
| 85 | // - one 1-byte live bit mask, and |
| 86 | // - one 1-byte set of location catalog entry indices composed of two 2-bit values. |
| 87 | size_t expected_dex_register_map_size = 1u + 1u; |
| 88 | ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); |
| 89 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 90 | ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationKind( |
| 91 | 0, number_of_dex_registers, code_info, encoding)); |
| 92 | ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind( |
| 93 | 1, number_of_dex_registers, code_info, encoding)); |
| 94 | ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationInternalKind( |
| 95 | 0, number_of_dex_registers, code_info, encoding)); |
| 96 | ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind( |
| 97 | 1, number_of_dex_registers, code_info, encoding)); |
| 98 | ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes( |
| 99 | 0, number_of_dex_registers, code_info, encoding)); |
| 100 | ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info, encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 101 | |
| 102 | size_t index0 = dex_register_map.GetLocationCatalogEntryIndex( |
| 103 | 0, number_of_dex_registers, number_of_location_catalog_entries); |
| 104 | size_t index1 = dex_register_map.GetLocationCatalogEntryIndex( |
| 105 | 1, number_of_dex_registers, number_of_location_catalog_entries); |
| 106 | ASSERT_EQ(0u, index0); |
| 107 | ASSERT_EQ(1u, index1); |
| 108 | DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); |
| 109 | DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); |
| 110 | ASSERT_EQ(Kind::kInStack, location0.GetKind()); |
| 111 | ASSERT_EQ(Kind::kConstant, location1.GetKind()); |
| 112 | ASSERT_EQ(Kind::kInStack, location0.GetInternalKind()); |
| 113 | ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind()); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 114 | ASSERT_EQ(0, location0.GetValue()); |
| 115 | ASSERT_EQ(-2, location1.GetValue()); |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 116 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 117 | ASSERT_FALSE(stack_map.HasInlineInfo(encoding)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | TEST(StackMapTest, Test2) { |
| 121 | ArenaPool pool; |
| 122 | ArenaAllocator arena(&pool); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 123 | StackMapStream stream(&arena); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 124 | |
| 125 | ArenaBitVector sp_mask1(&arena, 0, true); |
| 126 | sp_mask1.SetBit(2); |
| 127 | sp_mask1.SetBit(4); |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 128 | size_t number_of_dex_registers = 2; |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 129 | size_t number_of_dex_registers_in_inline_info = 0; |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 130 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, number_of_dex_registers, 2); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 131 | stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location. |
| 132 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 133 | stream.BeginInlineInfoEntry(82, 3, kDirect, number_of_dex_registers_in_inline_info); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 134 | stream.EndInlineInfoEntry(); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 135 | stream.BeginInlineInfoEntry(42, 2, kStatic, number_of_dex_registers_in_inline_info); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 136 | stream.EndInlineInfoEntry(); |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 137 | stream.EndStackMapEntry(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 138 | |
| 139 | ArenaBitVector sp_mask2(&arena, 0, true); |
| 140 | sp_mask2.SetBit(3); |
David Brazdil | f10a25f | 2015-06-02 14:29:52 +0100 | [diff] [blame] | 141 | sp_mask2.SetBit(8); |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 142 | stream.BeginStackMapEntry(1, 128, 0xFF, &sp_mask2, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 143 | stream.AddDexRegisterEntry(Kind::kInRegister, 18); // Short location. |
| 144 | stream.AddDexRegisterEntry(Kind::kInFpuRegister, 3); // Short location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 145 | stream.EndStackMapEntry(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 146 | |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 147 | ArenaBitVector sp_mask3(&arena, 0, true); |
| 148 | sp_mask3.SetBit(1); |
| 149 | sp_mask3.SetBit(5); |
| 150 | stream.BeginStackMapEntry(2, 192, 0xAB, &sp_mask3, number_of_dex_registers, 0); |
| 151 | stream.AddDexRegisterEntry(Kind::kInRegister, 6); // Short location. |
| 152 | stream.AddDexRegisterEntry(Kind::kInRegisterHigh, 8); // Short location. |
| 153 | stream.EndStackMapEntry(); |
| 154 | |
| 155 | ArenaBitVector sp_mask4(&arena, 0, true); |
| 156 | sp_mask4.SetBit(6); |
| 157 | sp_mask4.SetBit(7); |
| 158 | stream.BeginStackMapEntry(3, 256, 0xCD, &sp_mask4, number_of_dex_registers, 0); |
| 159 | stream.AddDexRegisterEntry(Kind::kInFpuRegister, 3); // Short location, same in stack map 2. |
| 160 | stream.AddDexRegisterEntry(Kind::kInFpuRegisterHigh, 1); // Short location. |
| 161 | stream.EndStackMapEntry(); |
| 162 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 163 | size_t size = stream.PrepareForFillIn(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 164 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 165 | MemoryRegion region(memory, size); |
| 166 | stream.FillIn(region); |
| 167 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 168 | CodeInfo code_info(region); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 169 | StackMapEncoding encoding = code_info.ExtractEncoding(); |
| 170 | ASSERT_EQ(2u, encoding.NumberOfBytesForStackMask()); |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 171 | ASSERT_EQ(4u, code_info.GetNumberOfStackMaps()); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 172 | |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 173 | uint32_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 174 | ASSERT_EQ(7u, number_of_location_catalog_entries); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 175 | DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 176 | // The Dex register location catalog contains: |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 177 | // - six 1-byte short Dex register locations, and |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 178 | // - one 5-byte large Dex register location. |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 179 | size_t expected_location_catalog_size = 6u * 1u + 5u; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 180 | ASSERT_EQ(expected_location_catalog_size, location_catalog.Size()); |
| 181 | |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 182 | // First stack map. |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 183 | { |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 184 | StackMap stack_map = code_info.GetStackMapAt(0, encoding); |
| 185 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding))); |
| 186 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding))); |
| 187 | ASSERT_EQ(0u, stack_map.GetDexPc(encoding)); |
| 188 | ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding)); |
| 189 | ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 190 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 191 | MemoryRegion stack_mask = stack_map.GetStackMask(encoding); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 192 | ASSERT_TRUE(SameBits(stack_mask, sp_mask1)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 193 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 194 | ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 195 | DexRegisterMap dex_register_map = |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 196 | code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 197 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); |
| 198 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); |
| 199 | ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 200 | // The Dex register map contains: |
| 201 | // - one 1-byte live bit mask, and |
| 202 | // - one 1-byte set of location catalog entry indices composed of two 2-bit values. |
| 203 | size_t expected_dex_register_map_size = 1u + 1u; |
| 204 | ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); |
| 205 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 206 | ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationKind( |
| 207 | 0, number_of_dex_registers, code_info, encoding)); |
| 208 | ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind( |
| 209 | 1, number_of_dex_registers, code_info, encoding)); |
| 210 | ASSERT_EQ(Kind::kInStack, dex_register_map.GetLocationInternalKind( |
| 211 | 0, number_of_dex_registers, code_info, encoding)); |
| 212 | ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind( |
| 213 | 1, number_of_dex_registers, code_info, encoding)); |
| 214 | ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes( |
| 215 | 0, number_of_dex_registers, code_info, encoding)); |
| 216 | ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info, encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 217 | |
| 218 | size_t index0 = dex_register_map.GetLocationCatalogEntryIndex( |
| 219 | 0, number_of_dex_registers, number_of_location_catalog_entries); |
| 220 | size_t index1 = dex_register_map.GetLocationCatalogEntryIndex( |
| 221 | 1, number_of_dex_registers, number_of_location_catalog_entries); |
| 222 | ASSERT_EQ(0u, index0); |
| 223 | ASSERT_EQ(1u, index1); |
| 224 | DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); |
| 225 | DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); |
| 226 | ASSERT_EQ(Kind::kInStack, location0.GetKind()); |
| 227 | ASSERT_EQ(Kind::kConstant, location1.GetKind()); |
| 228 | ASSERT_EQ(Kind::kInStack, location0.GetInternalKind()); |
| 229 | ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind()); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 230 | ASSERT_EQ(0, location0.GetValue()); |
| 231 | ASSERT_EQ(-2, location1.GetValue()); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 232 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 233 | ASSERT_TRUE(stack_map.HasInlineInfo(encoding)); |
| 234 | InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map, encoding); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 235 | ASSERT_EQ(2u, inline_info.GetDepth()); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 236 | ASSERT_EQ(82u, inline_info.GetMethodIndexAtDepth(0)); |
| 237 | ASSERT_EQ(42u, inline_info.GetMethodIndexAtDepth(1)); |
| 238 | ASSERT_EQ(3u, inline_info.GetDexPcAtDepth(0)); |
| 239 | ASSERT_EQ(2u, inline_info.GetDexPcAtDepth(1)); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 240 | ASSERT_EQ(kDirect, inline_info.GetInvokeTypeAtDepth(0)); |
| 241 | ASSERT_EQ(kStatic, inline_info.GetInvokeTypeAtDepth(1)); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 242 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 243 | |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 244 | // Second stack map. |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 245 | { |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 246 | StackMap stack_map = code_info.GetStackMapAt(1, encoding); |
| 247 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(1u, encoding))); |
| 248 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(128u, encoding))); |
| 249 | ASSERT_EQ(1u, stack_map.GetDexPc(encoding)); |
| 250 | ASSERT_EQ(128u, stack_map.GetNativePcOffset(encoding)); |
| 251 | ASSERT_EQ(0xFFu, stack_map.GetRegisterMask(encoding)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 252 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 253 | MemoryRegion stack_mask = stack_map.GetStackMask(encoding); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 254 | ASSERT_TRUE(SameBits(stack_mask, sp_mask2)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 255 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 256 | ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 257 | DexRegisterMap dex_register_map = |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 258 | code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 259 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); |
| 260 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); |
| 261 | ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 262 | // The Dex register map contains: |
| 263 | // - one 1-byte live bit mask, and |
| 264 | // - one 1-byte set of location catalog entry indices composed of two 2-bit values. |
| 265 | size_t expected_dex_register_map_size = 1u + 1u; |
| 266 | ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); |
| 267 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 268 | ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationKind( |
| 269 | 0, number_of_dex_registers, code_info, encoding)); |
| 270 | ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationKind( |
| 271 | 1, number_of_dex_registers, code_info, encoding)); |
| 272 | ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationInternalKind( |
| 273 | 0, number_of_dex_registers, code_info, encoding)); |
| 274 | ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationInternalKind( |
| 275 | 1, number_of_dex_registers, code_info, encoding)); |
| 276 | ASSERT_EQ(18, dex_register_map.GetMachineRegister( |
| 277 | 0, number_of_dex_registers, code_info, encoding)); |
| 278 | ASSERT_EQ(3, dex_register_map.GetMachineRegister( |
| 279 | 1, number_of_dex_registers, code_info, encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 280 | |
| 281 | size_t index0 = dex_register_map.GetLocationCatalogEntryIndex( |
| 282 | 0, number_of_dex_registers, number_of_location_catalog_entries); |
| 283 | size_t index1 = dex_register_map.GetLocationCatalogEntryIndex( |
| 284 | 1, number_of_dex_registers, number_of_location_catalog_entries); |
| 285 | ASSERT_EQ(2u, index0); |
| 286 | ASSERT_EQ(3u, index1); |
| 287 | DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); |
| 288 | DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); |
| 289 | ASSERT_EQ(Kind::kInRegister, location0.GetKind()); |
| 290 | ASSERT_EQ(Kind::kInFpuRegister, location1.GetKind()); |
| 291 | ASSERT_EQ(Kind::kInRegister, location0.GetInternalKind()); |
| 292 | ASSERT_EQ(Kind::kInFpuRegister, location1.GetInternalKind()); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 293 | ASSERT_EQ(18, location0.GetValue()); |
| 294 | ASSERT_EQ(3, location1.GetValue()); |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 295 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 296 | ASSERT_FALSE(stack_map.HasInlineInfo(encoding)); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 297 | } |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 298 | |
| 299 | // Third stack map. |
| 300 | { |
| 301 | StackMap stack_map = code_info.GetStackMapAt(2, encoding); |
| 302 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(2u, encoding))); |
| 303 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(192u, encoding))); |
| 304 | ASSERT_EQ(2u, stack_map.GetDexPc(encoding)); |
| 305 | ASSERT_EQ(192u, stack_map.GetNativePcOffset(encoding)); |
| 306 | ASSERT_EQ(0xABu, stack_map.GetRegisterMask(encoding)); |
| 307 | |
| 308 | MemoryRegion stack_mask = stack_map.GetStackMask(encoding); |
| 309 | ASSERT_TRUE(SameBits(stack_mask, sp_mask3)); |
| 310 | |
| 311 | ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding)); |
| 312 | DexRegisterMap dex_register_map = |
| 313 | code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers); |
| 314 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); |
| 315 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); |
| 316 | ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 317 | // The Dex register map contains: |
| 318 | // - one 1-byte live bit mask, and |
| 319 | // - one 1-byte set of location catalog entry indices composed of two 2-bit values. |
| 320 | size_t expected_dex_register_map_size = 1u + 1u; |
| 321 | ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); |
| 322 | |
| 323 | ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationKind( |
| 324 | 0, number_of_dex_registers, code_info, encoding)); |
| 325 | ASSERT_EQ(Kind::kInRegisterHigh, dex_register_map.GetLocationKind( |
| 326 | 1, number_of_dex_registers, code_info, encoding)); |
| 327 | ASSERT_EQ(Kind::kInRegister, dex_register_map.GetLocationInternalKind( |
| 328 | 0, number_of_dex_registers, code_info, encoding)); |
| 329 | ASSERT_EQ(Kind::kInRegisterHigh, dex_register_map.GetLocationInternalKind( |
| 330 | 1, number_of_dex_registers, code_info, encoding)); |
| 331 | ASSERT_EQ(6, dex_register_map.GetMachineRegister( |
| 332 | 0, number_of_dex_registers, code_info, encoding)); |
| 333 | ASSERT_EQ(8, dex_register_map.GetMachineRegister( |
| 334 | 1, number_of_dex_registers, code_info, encoding)); |
| 335 | |
| 336 | size_t index0 = dex_register_map.GetLocationCatalogEntryIndex( |
| 337 | 0, number_of_dex_registers, number_of_location_catalog_entries); |
| 338 | size_t index1 = dex_register_map.GetLocationCatalogEntryIndex( |
| 339 | 1, number_of_dex_registers, number_of_location_catalog_entries); |
| 340 | ASSERT_EQ(4u, index0); |
| 341 | ASSERT_EQ(5u, index1); |
| 342 | DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); |
| 343 | DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); |
| 344 | ASSERT_EQ(Kind::kInRegister, location0.GetKind()); |
| 345 | ASSERT_EQ(Kind::kInRegisterHigh, location1.GetKind()); |
| 346 | ASSERT_EQ(Kind::kInRegister, location0.GetInternalKind()); |
| 347 | ASSERT_EQ(Kind::kInRegisterHigh, location1.GetInternalKind()); |
| 348 | ASSERT_EQ(6, location0.GetValue()); |
| 349 | ASSERT_EQ(8, location1.GetValue()); |
| 350 | |
| 351 | ASSERT_FALSE(stack_map.HasInlineInfo(encoding)); |
| 352 | } |
| 353 | |
| 354 | // Fourth stack map. |
| 355 | { |
| 356 | StackMap stack_map = code_info.GetStackMapAt(3, encoding); |
| 357 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(3u, encoding))); |
| 358 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(256u, encoding))); |
| 359 | ASSERT_EQ(3u, stack_map.GetDexPc(encoding)); |
| 360 | ASSERT_EQ(256u, stack_map.GetNativePcOffset(encoding)); |
| 361 | ASSERT_EQ(0xCDu, stack_map.GetRegisterMask(encoding)); |
| 362 | |
| 363 | MemoryRegion stack_mask = stack_map.GetStackMask(encoding); |
| 364 | ASSERT_TRUE(SameBits(stack_mask, sp_mask4)); |
| 365 | |
| 366 | ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding)); |
| 367 | DexRegisterMap dex_register_map = |
| 368 | code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers); |
| 369 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); |
| 370 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); |
| 371 | ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 372 | // The Dex register map contains: |
| 373 | // - one 1-byte live bit mask, and |
| 374 | // - one 1-byte set of location catalog entry indices composed of two 2-bit values. |
| 375 | size_t expected_dex_register_map_size = 1u + 1u; |
| 376 | ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); |
| 377 | |
| 378 | ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationKind( |
| 379 | 0, number_of_dex_registers, code_info, encoding)); |
| 380 | ASSERT_EQ(Kind::kInFpuRegisterHigh, dex_register_map.GetLocationKind( |
| 381 | 1, number_of_dex_registers, code_info, encoding)); |
| 382 | ASSERT_EQ(Kind::kInFpuRegister, dex_register_map.GetLocationInternalKind( |
| 383 | 0, number_of_dex_registers, code_info, encoding)); |
| 384 | ASSERT_EQ(Kind::kInFpuRegisterHigh, dex_register_map.GetLocationInternalKind( |
| 385 | 1, number_of_dex_registers, code_info, encoding)); |
| 386 | ASSERT_EQ(3, dex_register_map.GetMachineRegister( |
| 387 | 0, number_of_dex_registers, code_info, encoding)); |
| 388 | ASSERT_EQ(1, dex_register_map.GetMachineRegister( |
| 389 | 1, number_of_dex_registers, code_info, encoding)); |
| 390 | |
| 391 | size_t index0 = dex_register_map.GetLocationCatalogEntryIndex( |
| 392 | 0, number_of_dex_registers, number_of_location_catalog_entries); |
| 393 | size_t index1 = dex_register_map.GetLocationCatalogEntryIndex( |
| 394 | 1, number_of_dex_registers, number_of_location_catalog_entries); |
| 395 | ASSERT_EQ(3u, index0); // Shared with second stack map. |
| 396 | ASSERT_EQ(6u, index1); |
| 397 | DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); |
| 398 | DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); |
| 399 | ASSERT_EQ(Kind::kInFpuRegister, location0.GetKind()); |
| 400 | ASSERT_EQ(Kind::kInFpuRegisterHigh, location1.GetKind()); |
| 401 | ASSERT_EQ(Kind::kInFpuRegister, location0.GetInternalKind()); |
| 402 | ASSERT_EQ(Kind::kInFpuRegisterHigh, location1.GetInternalKind()); |
| 403 | ASSERT_EQ(3, location0.GetValue()); |
| 404 | ASSERT_EQ(1, location1.GetValue()); |
| 405 | |
| 406 | ASSERT_FALSE(stack_map.HasInlineInfo(encoding)); |
| 407 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 410 | TEST(StackMapTest, TestNonLiveDexRegisters) { |
| 411 | ArenaPool pool; |
| 412 | ArenaAllocator arena(&pool); |
| 413 | StackMapStream stream(&arena); |
| 414 | |
| 415 | ArenaBitVector sp_mask(&arena, 0, false); |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 416 | uint32_t number_of_dex_registers = 2; |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 417 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 418 | stream.AddDexRegisterEntry(Kind::kNone, 0); // No location. |
| 419 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 420 | stream.EndStackMapEntry(); |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 421 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 422 | size_t size = stream.PrepareForFillIn(); |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 423 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 424 | MemoryRegion region(memory, size); |
| 425 | stream.FillIn(region); |
| 426 | |
| 427 | CodeInfo code_info(region); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 428 | StackMapEncoding encoding = code_info.ExtractEncoding(); |
| 429 | ASSERT_EQ(0u, encoding.NumberOfBytesForStackMask()); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 430 | ASSERT_EQ(1u, code_info.GetNumberOfStackMaps()); |
| 431 | |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 432 | uint32_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 433 | ASSERT_EQ(1u, number_of_location_catalog_entries); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 434 | DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 435 | // The Dex register location catalog contains: |
| 436 | // - one 5-byte large Dex register location. |
| 437 | size_t expected_location_catalog_size = 5u; |
| 438 | ASSERT_EQ(expected_location_catalog_size, location_catalog.Size()); |
| 439 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 440 | StackMap stack_map = code_info.GetStackMapAt(0, encoding); |
| 441 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding))); |
| 442 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding))); |
| 443 | ASSERT_EQ(0u, stack_map.GetDexPc(encoding)); |
| 444 | ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding)); |
| 445 | ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 446 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 447 | ASSERT_TRUE(stack_map.HasDexRegisterMap(encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 448 | DexRegisterMap dex_register_map = |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 449 | code_info.GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 450 | ASSERT_FALSE(dex_register_map.IsDexRegisterLive(0)); |
| 451 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); |
| 452 | ASSERT_EQ(1u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 453 | // The Dex register map contains: |
| 454 | // - one 1-byte live bit mask. |
| 455 | // No space is allocated for the sole location catalog entry index, as it is useless. |
| 456 | size_t expected_dex_register_map_size = 1u + 0u; |
| 457 | ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); |
| 458 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 459 | ASSERT_EQ(Kind::kNone, dex_register_map.GetLocationKind( |
| 460 | 0, number_of_dex_registers, code_info, encoding)); |
| 461 | ASSERT_EQ(Kind::kConstant, dex_register_map.GetLocationKind( |
| 462 | 1, number_of_dex_registers, code_info, encoding)); |
| 463 | ASSERT_EQ(Kind::kNone, dex_register_map.GetLocationInternalKind( |
| 464 | 0, number_of_dex_registers, code_info, encoding)); |
| 465 | ASSERT_EQ(Kind::kConstantLargeValue, dex_register_map.GetLocationInternalKind( |
| 466 | 1, number_of_dex_registers, code_info, encoding)); |
| 467 | ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info, encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 468 | |
| 469 | size_t index0 = dex_register_map.GetLocationCatalogEntryIndex( |
| 470 | 0, number_of_dex_registers, number_of_location_catalog_entries); |
| 471 | size_t index1 = dex_register_map.GetLocationCatalogEntryIndex( |
| 472 | 1, number_of_dex_registers, number_of_location_catalog_entries); |
| 473 | ASSERT_EQ(DexRegisterLocationCatalog::kNoLocationEntryIndex, index0); |
| 474 | ASSERT_EQ(0u, index1); |
| 475 | DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); |
| 476 | DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); |
| 477 | ASSERT_EQ(Kind::kNone, location0.GetKind()); |
| 478 | ASSERT_EQ(Kind::kConstant, location1.GetKind()); |
| 479 | ASSERT_EQ(Kind::kNone, location0.GetInternalKind()); |
| 480 | ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind()); |
| 481 | ASSERT_EQ(0, location0.GetValue()); |
| 482 | ASSERT_EQ(-2, location1.GetValue()); |
| 483 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 484 | ASSERT_FALSE(stack_map.HasInlineInfo(encoding)); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | // Generate a stack map whose dex register offset is |
| 488 | // StackMap::kNoDexRegisterMapSmallEncoding, and ensure we do |
| 489 | // not treat it as kNoDexRegisterMap. |
| 490 | TEST(StackMapTest, DexRegisterMapOffsetOverflow) { |
| 491 | ArenaPool pool; |
| 492 | ArenaAllocator arena(&pool); |
| 493 | StackMapStream stream(&arena); |
| 494 | |
| 495 | ArenaBitVector sp_mask(&arena, 0, false); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 496 | uint32_t number_of_dex_registers = 1024; |
| 497 | // Create the first stack map (and its Dex register map). |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 498 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 499 | uint32_t number_of_dex_live_registers_in_dex_register_map_0 = number_of_dex_registers - 8; |
| 500 | for (uint32_t i = 0; i < number_of_dex_live_registers_in_dex_register_map_0; ++i) { |
| 501 | // Use two different Dex register locations to populate this map, |
| 502 | // as using a single value (in the whole CodeInfo object) would |
| 503 | // make this Dex register mapping data empty (see |
| 504 | // art::DexRegisterMap::SingleEntrySizeInBits). |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 505 | stream.AddDexRegisterEntry(Kind::kConstant, i % 2); // Short location. |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 506 | } |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 507 | stream.EndStackMapEntry(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 508 | // Create the second stack map (and its Dex register map). |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 509 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 510 | for (uint32_t i = 0; i < number_of_dex_registers; ++i) { |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 511 | stream.AddDexRegisterEntry(Kind::kConstant, 0); // Short location. |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 512 | } |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 513 | stream.EndStackMapEntry(); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 514 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 515 | size_t size = stream.PrepareForFillIn(); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 516 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 517 | MemoryRegion region(memory, size); |
| 518 | stream.FillIn(region); |
| 519 | |
| 520 | CodeInfo code_info(region); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 521 | StackMapEncoding encoding = code_info.ExtractEncoding(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 522 | // The location catalog contains two entries (DexRegisterLocation(kConstant, 0) |
| 523 | // and DexRegisterLocation(kConstant, 1)), therefore the location catalog index |
| 524 | // has a size of 1 bit. |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 525 | uint32_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 526 | ASSERT_EQ(2u, number_of_location_catalog_entries); |
| 527 | ASSERT_EQ(1u, DexRegisterMap::SingleEntrySizeInBits(number_of_location_catalog_entries)); |
| 528 | |
| 529 | // The first Dex register map contains: |
| 530 | // - a live register bit mask for 1024 registers (that is, 128 bytes of |
| 531 | // data); and |
| 532 | // - Dex register mapping information for 1016 1-bit Dex (live) register |
| 533 | // locations (that is, 127 bytes of data). |
| 534 | // Hence it has a size of 255 bytes, and therefore... |
| 535 | ASSERT_EQ(128u, DexRegisterMap::GetLiveBitMaskSize(number_of_dex_registers)); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 536 | StackMap stack_map0 = code_info.GetStackMapAt(0, encoding); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 537 | DexRegisterMap dex_register_map0 = |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 538 | code_info.GetDexRegisterMapOf(stack_map0, encoding, number_of_dex_registers); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 539 | ASSERT_EQ(127u, dex_register_map0.GetLocationMappingDataSize(number_of_dex_registers, |
| 540 | number_of_location_catalog_entries)); |
| 541 | ASSERT_EQ(255u, dex_register_map0.Size()); |
| 542 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 543 | StackMap stack_map1 = code_info.GetStackMapAt(1, encoding); |
| 544 | ASSERT_TRUE(stack_map1.HasDexRegisterMap(encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 545 | // ...the offset of the second Dex register map (relative to the |
| 546 | // beginning of the Dex register maps region) is 255 (i.e., |
| 547 | // kNoDexRegisterMapSmallEncoding). |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 548 | ASSERT_NE(stack_map1.GetDexRegisterMapOffset(encoding), StackMap::kNoDexRegisterMap); |
| 549 | ASSERT_EQ(stack_map1.GetDexRegisterMapOffset(encoding), 0xFFu); |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 552 | TEST(StackMapTest, TestShareDexRegisterMap) { |
| 553 | ArenaPool pool; |
| 554 | ArenaAllocator arena(&pool); |
| 555 | StackMapStream stream(&arena); |
| 556 | |
| 557 | ArenaBitVector sp_mask(&arena, 0, false); |
| 558 | uint32_t number_of_dex_registers = 2; |
| 559 | // First stack map. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 560 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 561 | stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location. |
| 562 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 563 | stream.EndStackMapEntry(); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 564 | // Second stack map, which should share the same dex register map. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 565 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 566 | stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location. |
| 567 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 568 | stream.EndStackMapEntry(); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 569 | // Third stack map (doesn't share the dex register map). |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 570 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 571 | stream.AddDexRegisterEntry(Kind::kInRegister, 2); // Short location. |
| 572 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 573 | stream.EndStackMapEntry(); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 574 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 575 | size_t size = stream.PrepareForFillIn(); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 576 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 577 | MemoryRegion region(memory, size); |
| 578 | stream.FillIn(region); |
| 579 | |
| 580 | CodeInfo ci(region); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 581 | StackMapEncoding encoding = ci.ExtractEncoding(); |
| 582 | |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 583 | // Verify first stack map. |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 584 | StackMap sm0 = ci.GetStackMapAt(0, encoding); |
| 585 | DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm0, encoding, number_of_dex_registers); |
| 586 | ASSERT_EQ(0, dex_registers0.GetMachineRegister(0, number_of_dex_registers, ci, encoding)); |
| 587 | ASSERT_EQ(-2, dex_registers0.GetConstant(1, number_of_dex_registers, ci, encoding)); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 588 | |
| 589 | // Verify second stack map. |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 590 | StackMap sm1 = ci.GetStackMapAt(1, encoding); |
| 591 | DexRegisterMap dex_registers1 = ci.GetDexRegisterMapOf(sm1, encoding, number_of_dex_registers); |
| 592 | ASSERT_EQ(0, dex_registers1.GetMachineRegister(0, number_of_dex_registers, ci, encoding)); |
| 593 | ASSERT_EQ(-2, dex_registers1.GetConstant(1, number_of_dex_registers, ci, encoding)); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 594 | |
| 595 | // Verify third stack map. |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 596 | StackMap sm2 = ci.GetStackMapAt(2, encoding); |
| 597 | DexRegisterMap dex_registers2 = ci.GetDexRegisterMapOf(sm2, encoding, number_of_dex_registers); |
| 598 | ASSERT_EQ(2, dex_registers2.GetMachineRegister(0, number_of_dex_registers, ci, encoding)); |
| 599 | ASSERT_EQ(-2, dex_registers2.GetConstant(1, number_of_dex_registers, ci, encoding)); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 600 | |
| 601 | // Verify dex register map offsets. |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 602 | ASSERT_EQ(sm0.GetDexRegisterMapOffset(encoding), sm1.GetDexRegisterMapOffset(encoding)); |
| 603 | ASSERT_NE(sm0.GetDexRegisterMapOffset(encoding), sm2.GetDexRegisterMapOffset(encoding)); |
| 604 | ASSERT_NE(sm1.GetDexRegisterMapOffset(encoding), sm2.GetDexRegisterMapOffset(encoding)); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 607 | TEST(StackMapTest, TestNoDexRegisterMap) { |
| 608 | ArenaPool pool; |
| 609 | ArenaAllocator arena(&pool); |
| 610 | StackMapStream stream(&arena); |
| 611 | |
| 612 | ArenaBitVector sp_mask(&arena, 0, false); |
| 613 | uint32_t number_of_dex_registers = 0; |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 614 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
| 615 | stream.EndStackMapEntry(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 616 | |
Nicolas Geoffray | 012fc4e | 2016-01-08 15:58:19 +0000 | [diff] [blame] | 617 | number_of_dex_registers = 1; |
| 618 | stream.BeginStackMapEntry(1, 67, 0x4, &sp_mask, number_of_dex_registers, 0); |
| 619 | stream.EndStackMapEntry(); |
| 620 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 621 | size_t size = stream.PrepareForFillIn(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 622 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 623 | MemoryRegion region(memory, size); |
| 624 | stream.FillIn(region); |
| 625 | |
| 626 | CodeInfo code_info(region); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 627 | StackMapEncoding encoding = code_info.ExtractEncoding(); |
| 628 | ASSERT_EQ(0u, encoding.NumberOfBytesForStackMask()); |
Nicolas Geoffray | 012fc4e | 2016-01-08 15:58:19 +0000 | [diff] [blame] | 629 | ASSERT_EQ(2u, code_info.GetNumberOfStackMaps()); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 630 | |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 631 | uint32_t number_of_location_catalog_entries = code_info.GetNumberOfLocationCatalogEntries(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 632 | ASSERT_EQ(0u, number_of_location_catalog_entries); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 633 | DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(encoding); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 634 | ASSERT_EQ(0u, location_catalog.Size()); |
| 635 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 636 | StackMap stack_map = code_info.GetStackMapAt(0, encoding); |
| 637 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0, encoding))); |
| 638 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64, encoding))); |
| 639 | ASSERT_EQ(0u, stack_map.GetDexPc(encoding)); |
| 640 | ASSERT_EQ(64u, stack_map.GetNativePcOffset(encoding)); |
| 641 | ASSERT_EQ(0x3u, stack_map.GetRegisterMask(encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 642 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 643 | ASSERT_FALSE(stack_map.HasDexRegisterMap(encoding)); |
| 644 | ASSERT_FALSE(stack_map.HasInlineInfo(encoding)); |
Nicolas Geoffray | 012fc4e | 2016-01-08 15:58:19 +0000 | [diff] [blame] | 645 | |
| 646 | stack_map = code_info.GetStackMapAt(1, encoding); |
| 647 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(1, encoding))); |
| 648 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(67, encoding))); |
| 649 | ASSERT_EQ(1u, stack_map.GetDexPc(encoding)); |
| 650 | ASSERT_EQ(67u, stack_map.GetNativePcOffset(encoding)); |
| 651 | ASSERT_EQ(0x4u, stack_map.GetRegisterMask(encoding)); |
| 652 | |
| 653 | ASSERT_FALSE(stack_map.HasDexRegisterMap(encoding)); |
| 654 | ASSERT_FALSE(stack_map.HasInlineInfo(encoding)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 657 | TEST(StackMapTest, InlineTest) { |
| 658 | ArenaPool pool; |
| 659 | ArenaAllocator arena(&pool); |
| 660 | StackMapStream stream(&arena); |
| 661 | |
| 662 | ArenaBitVector sp_mask1(&arena, 0, true); |
| 663 | sp_mask1.SetBit(2); |
| 664 | sp_mask1.SetBit(4); |
| 665 | |
| 666 | // First stack map. |
| 667 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, 2, 2); |
| 668 | stream.AddDexRegisterEntry(Kind::kInStack, 0); |
| 669 | stream.AddDexRegisterEntry(Kind::kConstant, 4); |
| 670 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 671 | stream.BeginInlineInfoEntry(42, 2, kStatic, 1); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 672 | stream.AddDexRegisterEntry(Kind::kInStack, 8); |
| 673 | stream.EndInlineInfoEntry(); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 674 | stream.BeginInlineInfoEntry(82, 3, kStatic, 3); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 675 | stream.AddDexRegisterEntry(Kind::kInStack, 16); |
| 676 | stream.AddDexRegisterEntry(Kind::kConstant, 20); |
| 677 | stream.AddDexRegisterEntry(Kind::kInRegister, 15); |
| 678 | stream.EndInlineInfoEntry(); |
| 679 | |
| 680 | stream.EndStackMapEntry(); |
| 681 | |
| 682 | // Second stack map. |
| 683 | stream.BeginStackMapEntry(2, 22, 0x3, &sp_mask1, 2, 3); |
| 684 | stream.AddDexRegisterEntry(Kind::kInStack, 56); |
| 685 | stream.AddDexRegisterEntry(Kind::kConstant, 0); |
| 686 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 687 | stream.BeginInlineInfoEntry(42, 2, kDirect, 1); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 688 | stream.AddDexRegisterEntry(Kind::kInStack, 12); |
| 689 | stream.EndInlineInfoEntry(); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 690 | stream.BeginInlineInfoEntry(82, 3, kStatic, 3); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 691 | stream.AddDexRegisterEntry(Kind::kInStack, 80); |
| 692 | stream.AddDexRegisterEntry(Kind::kConstant, 10); |
| 693 | stream.AddDexRegisterEntry(Kind::kInRegister, 5); |
| 694 | stream.EndInlineInfoEntry(); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 695 | stream.BeginInlineInfoEntry(52, 5, kVirtual, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 696 | stream.EndInlineInfoEntry(); |
| 697 | |
| 698 | stream.EndStackMapEntry(); |
| 699 | |
| 700 | // Third stack map. |
| 701 | stream.BeginStackMapEntry(4, 56, 0x3, &sp_mask1, 2, 0); |
| 702 | stream.AddDexRegisterEntry(Kind::kNone, 0); |
| 703 | stream.AddDexRegisterEntry(Kind::kConstant, 4); |
| 704 | stream.EndStackMapEntry(); |
| 705 | |
| 706 | // Fourth stack map. |
| 707 | stream.BeginStackMapEntry(6, 78, 0x3, &sp_mask1, 2, 3); |
| 708 | stream.AddDexRegisterEntry(Kind::kInStack, 56); |
| 709 | stream.AddDexRegisterEntry(Kind::kConstant, 0); |
| 710 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 711 | stream.BeginInlineInfoEntry(42, 2, kVirtual, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 712 | stream.EndInlineInfoEntry(); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 713 | stream.BeginInlineInfoEntry(52, 5, kInterface, 1); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 714 | stream.AddDexRegisterEntry(Kind::kInRegister, 2); |
| 715 | stream.EndInlineInfoEntry(); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 716 | stream.BeginInlineInfoEntry(52, 10, kStatic, 2); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 717 | stream.AddDexRegisterEntry(Kind::kNone, 0); |
| 718 | stream.AddDexRegisterEntry(Kind::kInRegister, 3); |
| 719 | stream.EndInlineInfoEntry(); |
| 720 | |
| 721 | stream.EndStackMapEntry(); |
| 722 | |
| 723 | size_t size = stream.PrepareForFillIn(); |
| 724 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 725 | MemoryRegion region(memory, size); |
| 726 | stream.FillIn(region); |
| 727 | |
| 728 | CodeInfo ci(region); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 729 | StackMapEncoding encoding = ci.ExtractEncoding(); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 730 | |
| 731 | { |
| 732 | // Verify first stack map. |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 733 | StackMap sm0 = ci.GetStackMapAt(0, encoding); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 734 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 735 | DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm0, encoding, 2); |
| 736 | ASSERT_EQ(0, dex_registers0.GetStackOffsetInBytes(0, 2, ci, encoding)); |
| 737 | ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci, encoding)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 738 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 739 | InlineInfo if0 = ci.GetInlineInfoOf(sm0, encoding); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 740 | ASSERT_EQ(2u, if0.GetDepth()); |
| 741 | ASSERT_EQ(2u, if0.GetDexPcAtDepth(0)); |
| 742 | ASSERT_EQ(42u, if0.GetMethodIndexAtDepth(0)); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 743 | ASSERT_EQ(kStatic, if0.GetInvokeTypeAtDepth(0)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 744 | ASSERT_EQ(3u, if0.GetDexPcAtDepth(1)); |
| 745 | ASSERT_EQ(82u, if0.GetMethodIndexAtDepth(1)); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 746 | ASSERT_EQ(kStatic, if0.GetInvokeTypeAtDepth(1)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 747 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 748 | DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if0, encoding, 1); |
| 749 | ASSERT_EQ(8, dex_registers1.GetStackOffsetInBytes(0, 1, ci, encoding)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 750 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 751 | DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(1, if0, encoding, 3); |
| 752 | ASSERT_EQ(16, dex_registers2.GetStackOffsetInBytes(0, 3, ci, encoding)); |
| 753 | ASSERT_EQ(20, dex_registers2.GetConstant(1, 3, ci, encoding)); |
| 754 | ASSERT_EQ(15, dex_registers2.GetMachineRegister(2, 3, ci, encoding)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | { |
| 758 | // Verify second stack map. |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 759 | StackMap sm1 = ci.GetStackMapAt(1, encoding); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 760 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 761 | DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm1, encoding, 2); |
| 762 | ASSERT_EQ(56, dex_registers0.GetStackOffsetInBytes(0, 2, ci, encoding)); |
| 763 | ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci, encoding)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 764 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 765 | InlineInfo if1 = ci.GetInlineInfoOf(sm1, encoding); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 766 | ASSERT_EQ(3u, if1.GetDepth()); |
| 767 | ASSERT_EQ(2u, if1.GetDexPcAtDepth(0)); |
| 768 | ASSERT_EQ(42u, if1.GetMethodIndexAtDepth(0)); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 769 | ASSERT_EQ(kDirect, if1.GetInvokeTypeAtDepth(0)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 770 | ASSERT_EQ(3u, if1.GetDexPcAtDepth(1)); |
| 771 | ASSERT_EQ(82u, if1.GetMethodIndexAtDepth(1)); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 772 | ASSERT_EQ(kStatic, if1.GetInvokeTypeAtDepth(1)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 773 | ASSERT_EQ(5u, if1.GetDexPcAtDepth(2)); |
| 774 | ASSERT_EQ(52u, if1.GetMethodIndexAtDepth(2)); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 775 | ASSERT_EQ(kVirtual, if1.GetInvokeTypeAtDepth(2)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 776 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 777 | DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if1, encoding, 1); |
| 778 | ASSERT_EQ(12, dex_registers1.GetStackOffsetInBytes(0, 1, ci, encoding)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 779 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 780 | DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(1, if1, encoding, 3); |
| 781 | ASSERT_EQ(80, dex_registers2.GetStackOffsetInBytes(0, 3, ci, encoding)); |
| 782 | ASSERT_EQ(10, dex_registers2.GetConstant(1, 3, ci, encoding)); |
| 783 | ASSERT_EQ(5, dex_registers2.GetMachineRegister(2, 3, ci, encoding)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 784 | |
| 785 | ASSERT_FALSE(if1.HasDexRegisterMapAtDepth(2)); |
| 786 | } |
| 787 | |
| 788 | { |
| 789 | // Verify third stack map. |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 790 | StackMap sm2 = ci.GetStackMapAt(2, encoding); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 791 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 792 | DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm2, encoding, 2); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 793 | ASSERT_FALSE(dex_registers0.IsDexRegisterLive(0)); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 794 | ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci, encoding)); |
| 795 | ASSERT_FALSE(sm2.HasInlineInfo(encoding)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | { |
| 799 | // Verify fourth stack map. |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 800 | StackMap sm3 = ci.GetStackMapAt(3, encoding); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 801 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 802 | DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm3, encoding, 2); |
| 803 | ASSERT_EQ(56, dex_registers0.GetStackOffsetInBytes(0, 2, ci, encoding)); |
| 804 | ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci, encoding)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 805 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 806 | InlineInfo if2 = ci.GetInlineInfoOf(sm3, encoding); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 807 | ASSERT_EQ(3u, if2.GetDepth()); |
| 808 | ASSERT_EQ(2u, if2.GetDexPcAtDepth(0)); |
| 809 | ASSERT_EQ(42u, if2.GetMethodIndexAtDepth(0)); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 810 | ASSERT_EQ(kVirtual, if2.GetInvokeTypeAtDepth(0)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 811 | ASSERT_EQ(5u, if2.GetDexPcAtDepth(1)); |
| 812 | ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(1)); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 813 | ASSERT_EQ(kInterface, if2.GetInvokeTypeAtDepth(1)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 814 | ASSERT_EQ(10u, if2.GetDexPcAtDepth(2)); |
| 815 | ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(2)); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 816 | ASSERT_EQ(kStatic, if2.GetInvokeTypeAtDepth(2)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 817 | |
| 818 | ASSERT_FALSE(if2.HasDexRegisterMapAtDepth(0)); |
| 819 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 820 | DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(1, if2, encoding, 1); |
| 821 | ASSERT_EQ(2, dex_registers1.GetMachineRegister(0, 1, ci, encoding)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 822 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 823 | DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(2, if2, encoding, 2); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 824 | ASSERT_FALSE(dex_registers2.IsDexRegisterLive(0)); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 825 | ASSERT_EQ(3, dex_registers2.GetMachineRegister(1, 2, ci, encoding)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 829 | } // namespace art |