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); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 54 | ASSERT_EQ(0u, code_info.GetStackMaskSize()); |
| 55 | ASSERT_EQ(1u, code_info.GetNumberOfStackMaps()); |
| 56 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 57 | uint32_t number_of_location_catalog_entries = |
| 58 | code_info.GetNumberOfDexRegisterLocationCatalogEntries(); |
| 59 | ASSERT_EQ(2u, number_of_location_catalog_entries); |
| 60 | DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(); |
| 61 | // The Dex register location catalog contains: |
| 62 | // - one 1-byte short Dex register location, and |
| 63 | // - one 5-byte large Dex register location. |
| 64 | size_t expected_location_catalog_size = 1u + 5u; |
| 65 | ASSERT_EQ(expected_location_catalog_size, location_catalog.Size()); |
| 66 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 67 | StackMap stack_map = code_info.GetStackMapAt(0); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 68 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 69 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64))); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 70 | ASSERT_EQ(0u, stack_map.GetDexPc(code_info)); |
| 71 | ASSERT_EQ(64u, stack_map.GetNativePcOffset(code_info)); |
| 72 | ASSERT_EQ(0x3u, stack_map.GetRegisterMask(code_info)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 73 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 74 | MemoryRegion stack_mask = stack_map.GetStackMask(code_info); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 75 | ASSERT_TRUE(SameBits(stack_mask, sp_mask)); |
| 76 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 77 | ASSERT_TRUE(stack_map.HasDexRegisterMap(code_info)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 78 | DexRegisterMap dex_register_map = |
| 79 | code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); |
| 80 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); |
| 81 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); |
| 82 | ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 83 | // The Dex register map contains: |
| 84 | // - one 1-byte live bit mask, and |
| 85 | // - one 1-byte set of location catalog entry indices composed of two 2-bit values. |
| 86 | size_t expected_dex_register_map_size = 1u + 1u; |
| 87 | ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); |
| 88 | |
| 89 | ASSERT_EQ(Kind::kInStack, |
| 90 | dex_register_map.GetLocationKind(0, number_of_dex_registers, code_info)); |
| 91 | ASSERT_EQ(Kind::kConstant, |
| 92 | dex_register_map.GetLocationKind(1, number_of_dex_registers, code_info)); |
| 93 | ASSERT_EQ(Kind::kInStack, |
| 94 | dex_register_map.GetLocationInternalKind(0, number_of_dex_registers, code_info)); |
| 95 | ASSERT_EQ(Kind::kConstantLargeValue, |
| 96 | dex_register_map.GetLocationInternalKind(1, number_of_dex_registers, code_info)); |
| 97 | ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes(0, number_of_dex_registers, code_info)); |
| 98 | ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info)); |
| 99 | |
| 100 | size_t index0 = dex_register_map.GetLocationCatalogEntryIndex( |
| 101 | 0, number_of_dex_registers, number_of_location_catalog_entries); |
| 102 | size_t index1 = dex_register_map.GetLocationCatalogEntryIndex( |
| 103 | 1, number_of_dex_registers, number_of_location_catalog_entries); |
| 104 | ASSERT_EQ(0u, index0); |
| 105 | ASSERT_EQ(1u, index1); |
| 106 | DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); |
| 107 | DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); |
| 108 | ASSERT_EQ(Kind::kInStack, location0.GetKind()); |
| 109 | ASSERT_EQ(Kind::kConstant, location1.GetKind()); |
| 110 | ASSERT_EQ(Kind::kInStack, location0.GetInternalKind()); |
| 111 | ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind()); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 112 | ASSERT_EQ(0, location0.GetValue()); |
| 113 | ASSERT_EQ(-2, location1.GetValue()); |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 114 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 115 | ASSERT_FALSE(stack_map.HasInlineInfo(code_info)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | TEST(StackMapTest, Test2) { |
| 119 | ArenaPool pool; |
| 120 | ArenaAllocator arena(&pool); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 121 | StackMapStream stream(&arena); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 122 | |
| 123 | ArenaBitVector sp_mask1(&arena, 0, true); |
| 124 | sp_mask1.SetBit(2); |
| 125 | sp_mask1.SetBit(4); |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 126 | size_t number_of_dex_registers = 2; |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 127 | size_t number_of_dex_registers_in_inline_info = 0; |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 128 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, number_of_dex_registers, 2); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 129 | stream.AddDexRegisterEntry(Kind::kInStack, 0); // Short location. |
| 130 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. |
| 131 | stream.BeginInlineInfoEntry(82, 3, number_of_dex_registers_in_inline_info); |
| 132 | stream.EndInlineInfoEntry(); |
| 133 | stream.BeginInlineInfoEntry(42, 2, number_of_dex_registers_in_inline_info); |
| 134 | stream.EndInlineInfoEntry(); |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 135 | stream.EndStackMapEntry(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 136 | |
| 137 | ArenaBitVector sp_mask2(&arena, 0, true); |
| 138 | sp_mask2.SetBit(3); |
| 139 | sp_mask1.SetBit(8); |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 140 | stream.BeginStackMapEntry(1, 128, 0xFF, &sp_mask2, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 141 | stream.AddDexRegisterEntry(Kind::kInRegister, 18); // Short location. |
| 142 | stream.AddDexRegisterEntry(Kind::kInFpuRegister, 3); // Short location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 143 | stream.EndStackMapEntry(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 144 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 145 | size_t size = stream.PrepareForFillIn(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 146 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 147 | MemoryRegion region(memory, size); |
| 148 | stream.FillIn(region); |
| 149 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 150 | CodeInfo code_info(region); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 151 | ASSERT_EQ(1u, code_info.GetStackMaskSize()); |
| 152 | ASSERT_EQ(2u, code_info.GetNumberOfStackMaps()); |
| 153 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 154 | uint32_t number_of_location_catalog_entries = |
| 155 | code_info.GetNumberOfDexRegisterLocationCatalogEntries(); |
| 156 | ASSERT_EQ(4u, number_of_location_catalog_entries); |
| 157 | DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(); |
| 158 | // The Dex register location catalog contains: |
| 159 | // - three 1-byte short Dex register locations, and |
| 160 | // - one 5-byte large Dex register location. |
| 161 | size_t expected_location_catalog_size = 3u * 1u + 5u; |
| 162 | ASSERT_EQ(expected_location_catalog_size, location_catalog.Size()); |
| 163 | |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 164 | // First stack map. |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 165 | { |
| 166 | StackMap stack_map = code_info.GetStackMapAt(0); |
| 167 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0))); |
| 168 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64))); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 169 | ASSERT_EQ(0u, stack_map.GetDexPc(code_info)); |
| 170 | ASSERT_EQ(64u, stack_map.GetNativePcOffset(code_info)); |
| 171 | ASSERT_EQ(0x3u, stack_map.GetRegisterMask(code_info)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 172 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 173 | MemoryRegion stack_mask = stack_map.GetStackMask(code_info); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 174 | ASSERT_TRUE(SameBits(stack_mask, sp_mask1)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 175 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 176 | ASSERT_TRUE(stack_map.HasDexRegisterMap(code_info)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 177 | DexRegisterMap dex_register_map = |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 178 | code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 179 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); |
| 180 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); |
| 181 | ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 182 | // The Dex register map contains: |
| 183 | // - one 1-byte live bit mask, and |
| 184 | // - one 1-byte set of location catalog entry indices composed of two 2-bit values. |
| 185 | size_t expected_dex_register_map_size = 1u + 1u; |
| 186 | ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); |
| 187 | |
| 188 | ASSERT_EQ(Kind::kInStack, |
| 189 | dex_register_map.GetLocationKind(0, number_of_dex_registers, code_info)); |
| 190 | ASSERT_EQ(Kind::kConstant, |
| 191 | dex_register_map.GetLocationKind(1, number_of_dex_registers, code_info)); |
| 192 | ASSERT_EQ(Kind::kInStack, |
| 193 | dex_register_map.GetLocationInternalKind(0, number_of_dex_registers, code_info)); |
| 194 | ASSERT_EQ(Kind::kConstantLargeValue, |
| 195 | dex_register_map.GetLocationInternalKind(1, number_of_dex_registers, code_info)); |
| 196 | ASSERT_EQ(0, dex_register_map.GetStackOffsetInBytes(0, number_of_dex_registers, code_info)); |
| 197 | ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info)); |
| 198 | |
| 199 | size_t index0 = dex_register_map.GetLocationCatalogEntryIndex( |
| 200 | 0, number_of_dex_registers, number_of_location_catalog_entries); |
| 201 | size_t index1 = dex_register_map.GetLocationCatalogEntryIndex( |
| 202 | 1, number_of_dex_registers, number_of_location_catalog_entries); |
| 203 | ASSERT_EQ(0u, index0); |
| 204 | ASSERT_EQ(1u, index1); |
| 205 | DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); |
| 206 | DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); |
| 207 | ASSERT_EQ(Kind::kInStack, location0.GetKind()); |
| 208 | ASSERT_EQ(Kind::kConstant, location1.GetKind()); |
| 209 | ASSERT_EQ(Kind::kInStack, location0.GetInternalKind()); |
| 210 | ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind()); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 211 | ASSERT_EQ(0, location0.GetValue()); |
| 212 | ASSERT_EQ(-2, location1.GetValue()); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 213 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 214 | ASSERT_TRUE(stack_map.HasInlineInfo(code_info)); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 215 | InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map); |
| 216 | ASSERT_EQ(2u, inline_info.GetDepth()); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 217 | ASSERT_EQ(82u, inline_info.GetMethodIndexAtDepth(0)); |
| 218 | ASSERT_EQ(42u, inline_info.GetMethodIndexAtDepth(1)); |
| 219 | ASSERT_EQ(3u, inline_info.GetDexPcAtDepth(0)); |
| 220 | ASSERT_EQ(2u, inline_info.GetDexPcAtDepth(1)); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 221 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 222 | |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 223 | // Second stack map. |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 224 | { |
| 225 | StackMap stack_map = code_info.GetStackMapAt(1); |
| 226 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(1u))); |
| 227 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(128u))); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 228 | ASSERT_EQ(1u, stack_map.GetDexPc(code_info)); |
| 229 | ASSERT_EQ(128u, stack_map.GetNativePcOffset(code_info)); |
| 230 | ASSERT_EQ(0xFFu, stack_map.GetRegisterMask(code_info)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 231 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 232 | MemoryRegion stack_mask = stack_map.GetStackMask(code_info); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 233 | ASSERT_TRUE(SameBits(stack_mask, sp_mask2)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 234 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 235 | ASSERT_TRUE(stack_map.HasDexRegisterMap(code_info)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 236 | DexRegisterMap dex_register_map = |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 237 | code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 238 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(0)); |
| 239 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); |
| 240 | ASSERT_EQ(2u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 241 | // The Dex register map contains: |
| 242 | // - one 1-byte live bit mask, and |
| 243 | // - one 1-byte set of location catalog entry indices composed of two 2-bit values. |
| 244 | size_t expected_dex_register_map_size = 1u + 1u; |
| 245 | ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); |
| 246 | |
| 247 | ASSERT_EQ(Kind::kInRegister, |
| 248 | dex_register_map.GetLocationKind(0, number_of_dex_registers, code_info)); |
| 249 | ASSERT_EQ(Kind::kInFpuRegister, |
| 250 | dex_register_map.GetLocationKind(1, number_of_dex_registers, code_info)); |
| 251 | ASSERT_EQ(Kind::kInRegister, |
| 252 | dex_register_map.GetLocationInternalKind(0, number_of_dex_registers, code_info)); |
| 253 | ASSERT_EQ(Kind::kInFpuRegister, |
| 254 | dex_register_map.GetLocationInternalKind(1, number_of_dex_registers, code_info)); |
| 255 | ASSERT_EQ(18, dex_register_map.GetMachineRegister(0, number_of_dex_registers, code_info)); |
| 256 | ASSERT_EQ(3, dex_register_map.GetMachineRegister(1, number_of_dex_registers, code_info)); |
| 257 | |
| 258 | size_t index0 = dex_register_map.GetLocationCatalogEntryIndex( |
| 259 | 0, number_of_dex_registers, number_of_location_catalog_entries); |
| 260 | size_t index1 = dex_register_map.GetLocationCatalogEntryIndex( |
| 261 | 1, number_of_dex_registers, number_of_location_catalog_entries); |
| 262 | ASSERT_EQ(2u, index0); |
| 263 | ASSERT_EQ(3u, index1); |
| 264 | DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); |
| 265 | DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); |
| 266 | ASSERT_EQ(Kind::kInRegister, location0.GetKind()); |
| 267 | ASSERT_EQ(Kind::kInFpuRegister, location1.GetKind()); |
| 268 | ASSERT_EQ(Kind::kInRegister, location0.GetInternalKind()); |
| 269 | ASSERT_EQ(Kind::kInFpuRegister, location1.GetInternalKind()); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 270 | ASSERT_EQ(18, location0.GetValue()); |
| 271 | ASSERT_EQ(3, location1.GetValue()); |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 272 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 273 | ASSERT_FALSE(stack_map.HasInlineInfo(code_info)); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 274 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 277 | TEST(StackMapTest, TestNonLiveDexRegisters) { |
| 278 | ArenaPool pool; |
| 279 | ArenaAllocator arena(&pool); |
| 280 | StackMapStream stream(&arena); |
| 281 | |
| 282 | ArenaBitVector sp_mask(&arena, 0, false); |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 283 | uint32_t number_of_dex_registers = 2; |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 284 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 285 | stream.AddDexRegisterEntry(Kind::kNone, 0); // No location. |
| 286 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 287 | stream.EndStackMapEntry(); |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 288 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 289 | size_t size = stream.PrepareForFillIn(); |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 290 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 291 | MemoryRegion region(memory, size); |
| 292 | stream.FillIn(region); |
| 293 | |
| 294 | CodeInfo code_info(region); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 295 | ASSERT_EQ(0u, code_info.GetStackMaskSize()); |
| 296 | ASSERT_EQ(1u, code_info.GetNumberOfStackMaps()); |
| 297 | |
| 298 | uint32_t number_of_location_catalog_entries = |
| 299 | code_info.GetNumberOfDexRegisterLocationCatalogEntries(); |
| 300 | ASSERT_EQ(1u, number_of_location_catalog_entries); |
| 301 | DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(); |
| 302 | // The Dex register location catalog contains: |
| 303 | // - one 5-byte large Dex register location. |
| 304 | size_t expected_location_catalog_size = 5u; |
| 305 | ASSERT_EQ(expected_location_catalog_size, location_catalog.Size()); |
| 306 | |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 307 | StackMap stack_map = code_info.GetStackMapAt(0); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 308 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0))); |
| 309 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64))); |
| 310 | ASSERT_EQ(0u, stack_map.GetDexPc(code_info)); |
| 311 | ASSERT_EQ(64u, stack_map.GetNativePcOffset(code_info)); |
| 312 | ASSERT_EQ(0x3u, stack_map.GetRegisterMask(code_info)); |
| 313 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 314 | ASSERT_TRUE(stack_map.HasDexRegisterMap(code_info)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 315 | DexRegisterMap dex_register_map = |
| 316 | code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers); |
| 317 | ASSERT_FALSE(dex_register_map.IsDexRegisterLive(0)); |
| 318 | ASSERT_TRUE(dex_register_map.IsDexRegisterLive(1)); |
| 319 | ASSERT_EQ(1u, dex_register_map.GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 320 | // The Dex register map contains: |
| 321 | // - one 1-byte live bit mask. |
| 322 | // No space is allocated for the sole location catalog entry index, as it is useless. |
| 323 | size_t expected_dex_register_map_size = 1u + 0u; |
| 324 | ASSERT_EQ(expected_dex_register_map_size, dex_register_map.Size()); |
| 325 | |
| 326 | ASSERT_EQ(Kind::kNone, |
| 327 | dex_register_map.GetLocationKind(0, number_of_dex_registers, code_info)); |
| 328 | ASSERT_EQ(Kind::kConstant, |
| 329 | dex_register_map.GetLocationKind(1, number_of_dex_registers, code_info)); |
| 330 | ASSERT_EQ(Kind::kNone, |
| 331 | dex_register_map.GetLocationInternalKind(0, number_of_dex_registers, code_info)); |
| 332 | ASSERT_EQ(Kind::kConstantLargeValue, |
| 333 | dex_register_map.GetLocationInternalKind(1, number_of_dex_registers, code_info)); |
| 334 | ASSERT_EQ(-2, dex_register_map.GetConstant(1, number_of_dex_registers, code_info)); |
| 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(DexRegisterLocationCatalog::kNoLocationEntryIndex, index0); |
| 341 | ASSERT_EQ(0u, index1); |
| 342 | DexRegisterLocation location0 = location_catalog.GetDexRegisterLocation(index0); |
| 343 | DexRegisterLocation location1 = location_catalog.GetDexRegisterLocation(index1); |
| 344 | ASSERT_EQ(Kind::kNone, location0.GetKind()); |
| 345 | ASSERT_EQ(Kind::kConstant, location1.GetKind()); |
| 346 | ASSERT_EQ(Kind::kNone, location0.GetInternalKind()); |
| 347 | ASSERT_EQ(Kind::kConstantLargeValue, location1.GetInternalKind()); |
| 348 | ASSERT_EQ(0, location0.GetValue()); |
| 349 | ASSERT_EQ(-2, location1.GetValue()); |
| 350 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 351 | ASSERT_FALSE(stack_map.HasInlineInfo(code_info)); |
| 352 | } |
| 353 | |
| 354 | // Generate a stack map whose dex register offset is |
| 355 | // StackMap::kNoDexRegisterMapSmallEncoding, and ensure we do |
| 356 | // not treat it as kNoDexRegisterMap. |
| 357 | TEST(StackMapTest, DexRegisterMapOffsetOverflow) { |
| 358 | ArenaPool pool; |
| 359 | ArenaAllocator arena(&pool); |
| 360 | StackMapStream stream(&arena); |
| 361 | |
| 362 | ArenaBitVector sp_mask(&arena, 0, false); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 363 | uint32_t number_of_dex_registers = 1024; |
| 364 | // Create the first stack map (and its Dex register map). |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 365 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 366 | uint32_t number_of_dex_live_registers_in_dex_register_map_0 = number_of_dex_registers - 8; |
| 367 | for (uint32_t i = 0; i < number_of_dex_live_registers_in_dex_register_map_0; ++i) { |
| 368 | // Use two different Dex register locations to populate this map, |
| 369 | // as using a single value (in the whole CodeInfo object) would |
| 370 | // make this Dex register mapping data empty (see |
| 371 | // art::DexRegisterMap::SingleEntrySizeInBits). |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 372 | stream.AddDexRegisterEntry(Kind::kConstant, i % 2); // Short location. |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 373 | } |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 374 | stream.EndStackMapEntry(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 375 | // Create the second stack map (and its Dex register map). |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 376 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 377 | for (uint32_t i = 0; i < number_of_dex_registers; ++i) { |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 378 | stream.AddDexRegisterEntry(Kind::kConstant, 0); // Short location. |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 379 | } |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 380 | stream.EndStackMapEntry(); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 381 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 382 | size_t size = stream.PrepareForFillIn(); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 383 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 384 | MemoryRegion region(memory, size); |
| 385 | stream.FillIn(region); |
| 386 | |
| 387 | CodeInfo code_info(region); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 388 | // The location catalog contains two entries (DexRegisterLocation(kConstant, 0) |
| 389 | // and DexRegisterLocation(kConstant, 1)), therefore the location catalog index |
| 390 | // has a size of 1 bit. |
| 391 | uint32_t number_of_location_catalog_entries = |
| 392 | code_info.GetNumberOfDexRegisterLocationCatalogEntries(); |
| 393 | ASSERT_EQ(2u, number_of_location_catalog_entries); |
| 394 | ASSERT_EQ(1u, DexRegisterMap::SingleEntrySizeInBits(number_of_location_catalog_entries)); |
| 395 | |
| 396 | // The first Dex register map contains: |
| 397 | // - a live register bit mask for 1024 registers (that is, 128 bytes of |
| 398 | // data); and |
| 399 | // - Dex register mapping information for 1016 1-bit Dex (live) register |
| 400 | // locations (that is, 127 bytes of data). |
| 401 | // Hence it has a size of 255 bytes, and therefore... |
| 402 | ASSERT_EQ(128u, DexRegisterMap::GetLiveBitMaskSize(number_of_dex_registers)); |
| 403 | StackMap stack_map0 = code_info.GetStackMapAt(0); |
| 404 | DexRegisterMap dex_register_map0 = |
| 405 | code_info.GetDexRegisterMapOf(stack_map0, number_of_dex_registers); |
| 406 | ASSERT_EQ(127u, dex_register_map0.GetLocationMappingDataSize(number_of_dex_registers, |
| 407 | number_of_location_catalog_entries)); |
| 408 | ASSERT_EQ(255u, dex_register_map0.Size()); |
| 409 | |
| 410 | StackMap stack_map1 = code_info.GetStackMapAt(1); |
| 411 | ASSERT_TRUE(stack_map1.HasDexRegisterMap(code_info)); |
| 412 | // ...the offset of the second Dex register map (relative to the |
| 413 | // beginning of the Dex register maps region) is 255 (i.e., |
| 414 | // kNoDexRegisterMapSmallEncoding). |
Nicolas Geoffray | 896f8f7 | 2015-03-30 15:44:25 +0100 | [diff] [blame] | 415 | ASSERT_NE(stack_map1.GetDexRegisterMapOffset(code_info), StackMap::kNoDexRegisterMap); |
| 416 | ASSERT_EQ(stack_map1.GetDexRegisterMapOffset(code_info), 0xFFu); |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 419 | TEST(StackMapTest, TestShareDexRegisterMap) { |
| 420 | ArenaPool pool; |
| 421 | ArenaAllocator arena(&pool); |
| 422 | StackMapStream stream(&arena); |
| 423 | |
| 424 | ArenaBitVector sp_mask(&arena, 0, false); |
| 425 | uint32_t number_of_dex_registers = 2; |
| 426 | // First stack map. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 427 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 428 | stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location. |
| 429 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 430 | stream.EndStackMapEntry(); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 431 | // Second stack map, which should share the same dex register map. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 432 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 433 | stream.AddDexRegisterEntry(Kind::kInRegister, 0); // Short location. |
| 434 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 435 | stream.EndStackMapEntry(); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 436 | // Third stack map (doesn't share the dex register map). |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 437 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 438 | stream.AddDexRegisterEntry(Kind::kInRegister, 2); // Short location. |
| 439 | stream.AddDexRegisterEntry(Kind::kConstant, -2); // Large location. |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 440 | stream.EndStackMapEntry(); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 441 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 442 | size_t size = stream.PrepareForFillIn(); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 443 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 444 | MemoryRegion region(memory, size); |
| 445 | stream.FillIn(region); |
| 446 | |
| 447 | CodeInfo ci(region); |
| 448 | // Verify first stack map. |
| 449 | StackMap sm0 = ci.GetStackMapAt(0); |
| 450 | DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm0, number_of_dex_registers); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 451 | ASSERT_EQ(0, dex_registers0.GetMachineRegister(0, number_of_dex_registers, ci)); |
| 452 | ASSERT_EQ(-2, dex_registers0.GetConstant(1, number_of_dex_registers, ci)); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 453 | |
| 454 | // Verify second stack map. |
| 455 | StackMap sm1 = ci.GetStackMapAt(1); |
| 456 | DexRegisterMap dex_registers1 = ci.GetDexRegisterMapOf(sm1, number_of_dex_registers); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 457 | ASSERT_EQ(0, dex_registers1.GetMachineRegister(0, number_of_dex_registers, ci)); |
| 458 | ASSERT_EQ(-2, dex_registers1.GetConstant(1, number_of_dex_registers, ci)); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 459 | |
| 460 | // Verify third stack map. |
| 461 | StackMap sm2 = ci.GetStackMapAt(2); |
| 462 | DexRegisterMap dex_registers2 = ci.GetDexRegisterMapOf(sm2, number_of_dex_registers); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 463 | ASSERT_EQ(2, dex_registers2.GetMachineRegister(0, number_of_dex_registers, ci)); |
| 464 | ASSERT_EQ(-2, dex_registers2.GetConstant(1, number_of_dex_registers, ci)); |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 465 | |
| 466 | // Verify dex register map offsets. |
| 467 | ASSERT_EQ(sm0.GetDexRegisterMapOffset(ci), sm1.GetDexRegisterMapOffset(ci)); |
| 468 | ASSERT_NE(sm0.GetDexRegisterMapOffset(ci), sm2.GetDexRegisterMapOffset(ci)); |
| 469 | ASSERT_NE(sm1.GetDexRegisterMapOffset(ci), sm2.GetDexRegisterMapOffset(ci)); |
| 470 | } |
| 471 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 472 | TEST(StackMapTest, TestNoDexRegisterMap) { |
| 473 | ArenaPool pool; |
| 474 | ArenaAllocator arena(&pool); |
| 475 | StackMapStream stream(&arena); |
| 476 | |
| 477 | ArenaBitVector sp_mask(&arena, 0, false); |
| 478 | uint32_t number_of_dex_registers = 0; |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 479 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask, number_of_dex_registers, 0); |
| 480 | stream.EndStackMapEntry(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 481 | |
Calin Juravle | 4f46ac5 | 2015-04-23 18:47:21 +0100 | [diff] [blame] | 482 | size_t size = stream.PrepareForFillIn(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 483 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 484 | MemoryRegion region(memory, size); |
| 485 | stream.FillIn(region); |
| 486 | |
| 487 | CodeInfo code_info(region); |
| 488 | ASSERT_EQ(0u, code_info.GetStackMaskSize()); |
| 489 | ASSERT_EQ(1u, code_info.GetNumberOfStackMaps()); |
| 490 | |
| 491 | uint32_t number_of_location_catalog_entries = |
| 492 | code_info.GetNumberOfDexRegisterLocationCatalogEntries(); |
| 493 | ASSERT_EQ(0u, number_of_location_catalog_entries); |
| 494 | DexRegisterLocationCatalog location_catalog = code_info.GetDexRegisterLocationCatalog(); |
| 495 | ASSERT_EQ(0u, location_catalog.Size()); |
| 496 | |
| 497 | StackMap stack_map = code_info.GetStackMapAt(0); |
| 498 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForDexPc(0))); |
| 499 | ASSERT_TRUE(stack_map.Equals(code_info.GetStackMapForNativePcOffset(64))); |
| 500 | ASSERT_EQ(0u, stack_map.GetDexPc(code_info)); |
| 501 | ASSERT_EQ(64u, stack_map.GetNativePcOffset(code_info)); |
| 502 | ASSERT_EQ(0x3u, stack_map.GetRegisterMask(code_info)); |
| 503 | |
| 504 | ASSERT_FALSE(stack_map.HasDexRegisterMap(code_info)); |
| 505 | ASSERT_FALSE(stack_map.HasInlineInfo(code_info)); |
| 506 | } |
| 507 | |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame^] | 508 | TEST(StackMapTest, InlineTest) { |
| 509 | ArenaPool pool; |
| 510 | ArenaAllocator arena(&pool); |
| 511 | StackMapStream stream(&arena); |
| 512 | |
| 513 | ArenaBitVector sp_mask1(&arena, 0, true); |
| 514 | sp_mask1.SetBit(2); |
| 515 | sp_mask1.SetBit(4); |
| 516 | |
| 517 | // First stack map. |
| 518 | stream.BeginStackMapEntry(0, 64, 0x3, &sp_mask1, 2, 2); |
| 519 | stream.AddDexRegisterEntry(Kind::kInStack, 0); |
| 520 | stream.AddDexRegisterEntry(Kind::kConstant, 4); |
| 521 | |
| 522 | stream.BeginInlineInfoEntry(42, 2, 1); |
| 523 | stream.AddDexRegisterEntry(Kind::kInStack, 8); |
| 524 | stream.EndInlineInfoEntry(); |
| 525 | stream.BeginInlineInfoEntry(82, 3, 3); |
| 526 | stream.AddDexRegisterEntry(Kind::kInStack, 16); |
| 527 | stream.AddDexRegisterEntry(Kind::kConstant, 20); |
| 528 | stream.AddDexRegisterEntry(Kind::kInRegister, 15); |
| 529 | stream.EndInlineInfoEntry(); |
| 530 | |
| 531 | stream.EndStackMapEntry(); |
| 532 | |
| 533 | // Second stack map. |
| 534 | stream.BeginStackMapEntry(2, 22, 0x3, &sp_mask1, 2, 3); |
| 535 | stream.AddDexRegisterEntry(Kind::kInStack, 56); |
| 536 | stream.AddDexRegisterEntry(Kind::kConstant, 0); |
| 537 | |
| 538 | stream.BeginInlineInfoEntry(42, 2, 1); |
| 539 | stream.AddDexRegisterEntry(Kind::kInStack, 12); |
| 540 | stream.EndInlineInfoEntry(); |
| 541 | stream.BeginInlineInfoEntry(82, 3, 3); |
| 542 | stream.AddDexRegisterEntry(Kind::kInStack, 80); |
| 543 | stream.AddDexRegisterEntry(Kind::kConstant, 10); |
| 544 | stream.AddDexRegisterEntry(Kind::kInRegister, 5); |
| 545 | stream.EndInlineInfoEntry(); |
| 546 | stream.BeginInlineInfoEntry(52, 5, 0); |
| 547 | stream.EndInlineInfoEntry(); |
| 548 | |
| 549 | stream.EndStackMapEntry(); |
| 550 | |
| 551 | // Third stack map. |
| 552 | stream.BeginStackMapEntry(4, 56, 0x3, &sp_mask1, 2, 0); |
| 553 | stream.AddDexRegisterEntry(Kind::kNone, 0); |
| 554 | stream.AddDexRegisterEntry(Kind::kConstant, 4); |
| 555 | stream.EndStackMapEntry(); |
| 556 | |
| 557 | // Fourth stack map. |
| 558 | stream.BeginStackMapEntry(6, 78, 0x3, &sp_mask1, 2, 3); |
| 559 | stream.AddDexRegisterEntry(Kind::kInStack, 56); |
| 560 | stream.AddDexRegisterEntry(Kind::kConstant, 0); |
| 561 | |
| 562 | stream.BeginInlineInfoEntry(42, 2, 0); |
| 563 | stream.EndInlineInfoEntry(); |
| 564 | stream.BeginInlineInfoEntry(52, 5, 1); |
| 565 | stream.AddDexRegisterEntry(Kind::kInRegister, 2); |
| 566 | stream.EndInlineInfoEntry(); |
| 567 | stream.BeginInlineInfoEntry(52, 10, 2); |
| 568 | stream.AddDexRegisterEntry(Kind::kNone, 0); |
| 569 | stream.AddDexRegisterEntry(Kind::kInRegister, 3); |
| 570 | stream.EndInlineInfoEntry(); |
| 571 | |
| 572 | stream.EndStackMapEntry(); |
| 573 | |
| 574 | size_t size = stream.PrepareForFillIn(); |
| 575 | void* memory = arena.Alloc(size, kArenaAllocMisc); |
| 576 | MemoryRegion region(memory, size); |
| 577 | stream.FillIn(region); |
| 578 | |
| 579 | CodeInfo ci(region); |
| 580 | |
| 581 | { |
| 582 | // Verify first stack map. |
| 583 | StackMap sm0 = ci.GetStackMapAt(0); |
| 584 | |
| 585 | DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm0, 2); |
| 586 | ASSERT_EQ(0, dex_registers0.GetStackOffsetInBytes(0, 2, ci)); |
| 587 | ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci)); |
| 588 | |
| 589 | InlineInfo if0 = ci.GetInlineInfoOf(sm0); |
| 590 | ASSERT_EQ(2u, if0.GetDepth()); |
| 591 | ASSERT_EQ(2u, if0.GetDexPcAtDepth(0)); |
| 592 | ASSERT_EQ(42u, if0.GetMethodIndexAtDepth(0)); |
| 593 | ASSERT_EQ(3u, if0.GetDexPcAtDepth(1)); |
| 594 | ASSERT_EQ(82u, if0.GetMethodIndexAtDepth(1)); |
| 595 | |
| 596 | DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if0, 1); |
| 597 | ASSERT_EQ(8, dex_registers1.GetStackOffsetInBytes(0, 1, ci)); |
| 598 | |
| 599 | DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(1, if0, 3); |
| 600 | ASSERT_EQ(16, dex_registers2.GetStackOffsetInBytes(0, 3, ci)); |
| 601 | ASSERT_EQ(20, dex_registers2.GetConstant(1, 3, ci)); |
| 602 | ASSERT_EQ(15, dex_registers2.GetMachineRegister(2, 3, ci)); |
| 603 | } |
| 604 | |
| 605 | { |
| 606 | // Verify second stack map. |
| 607 | StackMap sm1 = ci.GetStackMapAt(1); |
| 608 | |
| 609 | DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm1, 2); |
| 610 | ASSERT_EQ(56, dex_registers0.GetStackOffsetInBytes(0, 2, ci)); |
| 611 | ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci)); |
| 612 | |
| 613 | InlineInfo if1 = ci.GetInlineInfoOf(sm1); |
| 614 | ASSERT_EQ(3u, if1.GetDepth()); |
| 615 | ASSERT_EQ(2u, if1.GetDexPcAtDepth(0)); |
| 616 | ASSERT_EQ(42u, if1.GetMethodIndexAtDepth(0)); |
| 617 | ASSERT_EQ(3u, if1.GetDexPcAtDepth(1)); |
| 618 | ASSERT_EQ(82u, if1.GetMethodIndexAtDepth(1)); |
| 619 | ASSERT_EQ(5u, if1.GetDexPcAtDepth(2)); |
| 620 | ASSERT_EQ(52u, if1.GetMethodIndexAtDepth(2)); |
| 621 | |
| 622 | DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if1, 1); |
| 623 | ASSERT_EQ(12, dex_registers1.GetStackOffsetInBytes(0, 1, ci)); |
| 624 | |
| 625 | DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(1, if1, 3); |
| 626 | ASSERT_EQ(80, dex_registers2.GetStackOffsetInBytes(0, 3, ci)); |
| 627 | ASSERT_EQ(10, dex_registers2.GetConstant(1, 3, ci)); |
| 628 | ASSERT_EQ(5, dex_registers2.GetMachineRegister(2, 3, ci)); |
| 629 | |
| 630 | ASSERT_FALSE(if1.HasDexRegisterMapAtDepth(2)); |
| 631 | } |
| 632 | |
| 633 | { |
| 634 | // Verify third stack map. |
| 635 | StackMap sm2 = ci.GetStackMapAt(2); |
| 636 | |
| 637 | DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm2, 2); |
| 638 | ASSERT_FALSE(dex_registers0.IsDexRegisterLive(0)); |
| 639 | ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci)); |
| 640 | ASSERT_FALSE(sm2.HasInlineInfo(ci)); |
| 641 | } |
| 642 | |
| 643 | { |
| 644 | // Verify fourth stack map. |
| 645 | StackMap sm3 = ci.GetStackMapAt(3); |
| 646 | |
| 647 | DexRegisterMap dex_registers0 = ci.GetDexRegisterMapOf(sm3, 2); |
| 648 | ASSERT_EQ(56, dex_registers0.GetStackOffsetInBytes(0, 2, ci)); |
| 649 | ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci)); |
| 650 | |
| 651 | InlineInfo if2 = ci.GetInlineInfoOf(sm3); |
| 652 | ASSERT_EQ(3u, if2.GetDepth()); |
| 653 | ASSERT_EQ(2u, if2.GetDexPcAtDepth(0)); |
| 654 | ASSERT_EQ(42u, if2.GetMethodIndexAtDepth(0)); |
| 655 | ASSERT_EQ(5u, if2.GetDexPcAtDepth(1)); |
| 656 | ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(1)); |
| 657 | ASSERT_EQ(10u, if2.GetDexPcAtDepth(2)); |
| 658 | ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(2)); |
| 659 | |
| 660 | ASSERT_FALSE(if2.HasDexRegisterMapAtDepth(0)); |
| 661 | |
| 662 | DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(1, if2, 1); |
| 663 | ASSERT_EQ(2, dex_registers1.GetMachineRegister(0, 1, ci)); |
| 664 | |
| 665 | DexRegisterMap dex_registers2 = ci.GetDexRegisterMapAtDepth(2, if2, 2); |
| 666 | ASSERT_FALSE(dex_registers2.IsDexRegisterLive(0)); |
| 667 | ASSERT_EQ(3, dex_registers2.GetMachineRegister(1, 2, ci)); |
| 668 | } |
| 669 | } |
| 670 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 671 | } // namespace art |