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