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