Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Mathieu Chartier | c56057e | 2014-05-04 13:18:58 -0700 | [diff] [blame] | 17 | #include "indirect_reference_table-inl.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 18 | |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 19 | #include "class_linker-inl.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 20 | #include "common_runtime_test.h" |
Hiroshi Yamauchi | 967a0ad | 2013-09-10 16:24:21 -0700 | [diff] [blame] | 21 | #include "mirror/object-inl.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 22 | #include "scoped_thread_state_change.h" |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 23 | |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 24 | namespace art { |
| 25 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 26 | class IndirectReferenceTableTest : public CommonRuntimeTest {}; |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 27 | |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 28 | static void CheckDump(IndirectReferenceTable* irt, size_t num_objects, size_t num_unique) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 29 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 30 | std::ostringstream oss; |
| 31 | irt->Dump(oss); |
| 32 | if (num_objects == 0) { |
| 33 | EXPECT_EQ(oss.str().find("java.lang.Object"), std::string::npos) << oss.str(); |
| 34 | } else if (num_objects == 1) { |
| 35 | EXPECT_NE(oss.str().find("1 of java.lang.Object"), std::string::npos) << oss.str(); |
| 36 | } else { |
| 37 | EXPECT_NE(oss.str().find(StringPrintf("%zd of java.lang.Object (%zd unique instances)", |
| 38 | num_objects, num_unique)), |
| 39 | std::string::npos) |
| 40 | << "\n Expected number of objects: " << num_objects |
| 41 | << "\n Expected unique objects: " << num_unique << "\n" |
| 42 | << oss.str(); |
| 43 | } |
| 44 | } |
| 45 | |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 46 | TEST_F(IndirectReferenceTableTest, BasicTest) { |
Andreas Gampe | 369810a | 2015-01-14 19:53:31 -0800 | [diff] [blame] | 47 | // This will lead to error messages in the log. |
| 48 | ScopedLogSeverity sls(LogSeverity::FATAL); |
| 49 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 50 | ScopedObjectAccess soa(Thread::Current()); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 51 | static const size_t kTableInitial = 10; |
| 52 | static const size_t kTableMax = 20; |
| 53 | IndirectReferenceTable irt(kTableInitial, kTableMax, kGlobal); |
| 54 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 55 | mirror::Class* c = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 56 | ASSERT_TRUE(c != nullptr); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 57 | mirror::Object* obj0 = c->AllocObject(soa.Self()); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 58 | ASSERT_TRUE(obj0 != nullptr); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 59 | mirror::Object* obj1 = c->AllocObject(soa.Self()); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 60 | ASSERT_TRUE(obj1 != nullptr); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 61 | mirror::Object* obj2 = c->AllocObject(soa.Self()); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 62 | ASSERT_TRUE(obj2 != nullptr); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 63 | mirror::Object* obj3 = c->AllocObject(soa.Self()); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 64 | ASSERT_TRUE(obj3 != nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 65 | |
| 66 | const uint32_t cookie = IRT_FIRST_SEGMENT; |
| 67 | |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 68 | CheckDump(&irt, 0, 0); |
| 69 | |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 70 | IndirectRef iref0 = (IndirectRef) 0x11110; |
| 71 | EXPECT_FALSE(irt.Remove(cookie, iref0)) << "unexpectedly successful removal"; |
| 72 | |
| 73 | // Add three, check, remove in the order in which they were added. |
| 74 | iref0 = irt.Add(cookie, obj0); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 75 | EXPECT_TRUE(iref0 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 76 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 77 | IndirectRef iref1 = irt.Add(cookie, obj1); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 78 | EXPECT_TRUE(iref1 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 79 | CheckDump(&irt, 2, 2); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 80 | IndirectRef iref2 = irt.Add(cookie, obj2); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 81 | EXPECT_TRUE(iref2 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 82 | CheckDump(&irt, 3, 3); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 83 | |
| 84 | EXPECT_EQ(obj0, irt.Get(iref0)); |
| 85 | EXPECT_EQ(obj1, irt.Get(iref1)); |
| 86 | EXPECT_EQ(obj2, irt.Get(iref2)); |
| 87 | |
| 88 | EXPECT_TRUE(irt.Remove(cookie, iref0)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 89 | CheckDump(&irt, 2, 2); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 90 | EXPECT_TRUE(irt.Remove(cookie, iref1)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 91 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 92 | EXPECT_TRUE(irt.Remove(cookie, iref2)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 93 | CheckDump(&irt, 0, 0); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 94 | |
| 95 | // Table should be empty now. |
| 96 | EXPECT_EQ(0U, irt.Capacity()); |
| 97 | |
| 98 | // Get invalid entry (off the end of the list). |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 99 | EXPECT_TRUE(irt.Get(iref0) == nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 100 | |
| 101 | // Add three, remove in the opposite order. |
| 102 | iref0 = irt.Add(cookie, obj0); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 103 | EXPECT_TRUE(iref0 != nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 104 | iref1 = irt.Add(cookie, obj1); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 105 | EXPECT_TRUE(iref1 != nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 106 | iref2 = irt.Add(cookie, obj2); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 107 | EXPECT_TRUE(iref2 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 108 | CheckDump(&irt, 3, 3); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 109 | |
| 110 | ASSERT_TRUE(irt.Remove(cookie, iref2)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 111 | CheckDump(&irt, 2, 2); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 112 | ASSERT_TRUE(irt.Remove(cookie, iref1)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 113 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 114 | ASSERT_TRUE(irt.Remove(cookie, iref0)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 115 | CheckDump(&irt, 0, 0); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 116 | |
| 117 | // Table should be empty now. |
| 118 | ASSERT_EQ(0U, irt.Capacity()); |
| 119 | |
| 120 | // Add three, remove middle / middle / bottom / top. (Second attempt |
| 121 | // to remove middle should fail.) |
| 122 | iref0 = irt.Add(cookie, obj0); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 123 | EXPECT_TRUE(iref0 != nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 124 | iref1 = irt.Add(cookie, obj1); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 125 | EXPECT_TRUE(iref1 != nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 126 | iref2 = irt.Add(cookie, obj2); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 127 | EXPECT_TRUE(iref2 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 128 | CheckDump(&irt, 3, 3); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 129 | |
| 130 | ASSERT_EQ(3U, irt.Capacity()); |
| 131 | |
| 132 | ASSERT_TRUE(irt.Remove(cookie, iref1)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 133 | CheckDump(&irt, 2, 2); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 134 | ASSERT_FALSE(irt.Remove(cookie, iref1)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 135 | CheckDump(&irt, 2, 2); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 136 | |
| 137 | // Get invalid entry (from hole). |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 138 | EXPECT_TRUE(irt.Get(iref1) == nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 139 | |
| 140 | ASSERT_TRUE(irt.Remove(cookie, iref2)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 141 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 142 | ASSERT_TRUE(irt.Remove(cookie, iref0)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 143 | CheckDump(&irt, 0, 0); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 144 | |
| 145 | // Table should be empty now. |
| 146 | ASSERT_EQ(0U, irt.Capacity()); |
| 147 | |
| 148 | // Add four entries. Remove #1, add new entry, verify that table size |
| 149 | // is still 4 (i.e. holes are getting filled). Remove #1 and #3, verify |
| 150 | // that we delete one and don't hole-compact the other. |
| 151 | iref0 = irt.Add(cookie, obj0); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 152 | EXPECT_TRUE(iref0 != nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 153 | iref1 = irt.Add(cookie, obj1); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 154 | EXPECT_TRUE(iref1 != nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 155 | iref2 = irt.Add(cookie, obj2); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 156 | EXPECT_TRUE(iref2 != nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 157 | IndirectRef iref3 = irt.Add(cookie, obj3); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 158 | EXPECT_TRUE(iref3 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 159 | CheckDump(&irt, 4, 4); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 160 | |
| 161 | ASSERT_TRUE(irt.Remove(cookie, iref1)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 162 | CheckDump(&irt, 3, 3); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 163 | |
| 164 | iref1 = irt.Add(cookie, obj1); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 165 | EXPECT_TRUE(iref1 != nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 166 | |
| 167 | ASSERT_EQ(4U, irt.Capacity()) << "hole not filled"; |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 168 | CheckDump(&irt, 4, 4); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 169 | |
| 170 | ASSERT_TRUE(irt.Remove(cookie, iref1)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 171 | CheckDump(&irt, 3, 3); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 172 | ASSERT_TRUE(irt.Remove(cookie, iref3)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 173 | CheckDump(&irt, 2, 2); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 174 | |
| 175 | ASSERT_EQ(3U, irt.Capacity()) << "should be 3 after two deletions"; |
| 176 | |
| 177 | ASSERT_TRUE(irt.Remove(cookie, iref2)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 178 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 179 | ASSERT_TRUE(irt.Remove(cookie, iref0)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 180 | CheckDump(&irt, 0, 0); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 181 | |
| 182 | ASSERT_EQ(0U, irt.Capacity()) << "not empty after split remove"; |
| 183 | |
| 184 | // Add an entry, remove it, add a new entry, and try to use the original |
| 185 | // iref. They have the same slot number but are for different objects. |
| 186 | // With the extended checks in place, this should fail. |
| 187 | iref0 = irt.Add(cookie, obj0); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 188 | EXPECT_TRUE(iref0 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 189 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 190 | ASSERT_TRUE(irt.Remove(cookie, iref0)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 191 | CheckDump(&irt, 0, 0); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 192 | iref1 = irt.Add(cookie, obj1); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 193 | EXPECT_TRUE(iref1 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 194 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 195 | ASSERT_FALSE(irt.Remove(cookie, iref0)) << "mismatched del succeeded"; |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 196 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 197 | ASSERT_TRUE(irt.Remove(cookie, iref1)) << "switched del failed"; |
| 198 | ASSERT_EQ(0U, irt.Capacity()) << "switching del not empty"; |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 199 | CheckDump(&irt, 0, 0); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 200 | |
| 201 | // Same as above, but with the same object. A more rigorous checker |
| 202 | // (e.g. with slot serialization) will catch this. |
| 203 | iref0 = irt.Add(cookie, obj0); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 204 | EXPECT_TRUE(iref0 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 205 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 206 | ASSERT_TRUE(irt.Remove(cookie, iref0)); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 207 | CheckDump(&irt, 0, 0); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 208 | iref1 = irt.Add(cookie, obj0); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 209 | EXPECT_TRUE(iref1 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 210 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 211 | if (iref0 != iref1) { |
| 212 | // Try 0, should not work. |
| 213 | ASSERT_FALSE(irt.Remove(cookie, iref0)) << "temporal del succeeded"; |
| 214 | } |
| 215 | ASSERT_TRUE(irt.Remove(cookie, iref1)) << "temporal cleanup failed"; |
| 216 | ASSERT_EQ(0U, irt.Capacity()) << "temporal del not empty"; |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 217 | CheckDump(&irt, 0, 0); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 218 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 219 | // null isn't a valid iref. |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 220 | ASSERT_TRUE(irt.Get(nullptr) == nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 221 | |
| 222 | // Stale lookup. |
| 223 | iref0 = irt.Add(cookie, obj0); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 224 | EXPECT_TRUE(iref0 != nullptr); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 225 | CheckDump(&irt, 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 226 | ASSERT_TRUE(irt.Remove(cookie, iref0)); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 227 | EXPECT_TRUE(irt.Get(iref0) == nullptr) << "stale lookup succeeded"; |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 228 | CheckDump(&irt, 0, 0); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 229 | |
| 230 | // Test table resizing. |
| 231 | // These ones fit... |
| 232 | IndirectRef manyRefs[kTableInitial]; |
| 233 | for (size_t i = 0; i < kTableInitial; i++) { |
| 234 | manyRefs[i] = irt.Add(cookie, obj0); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 235 | ASSERT_TRUE(manyRefs[i] != nullptr) << "Failed adding " << i; |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 236 | CheckDump(&irt, i + 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 237 | } |
| 238 | // ...this one causes overflow. |
| 239 | iref0 = irt.Add(cookie, obj0); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 240 | ASSERT_TRUE(iref0 != nullptr); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 241 | ASSERT_EQ(kTableInitial + 1, irt.Capacity()); |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 242 | CheckDump(&irt, kTableInitial + 1, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 243 | |
| 244 | for (size_t i = 0; i < kTableInitial; i++) { |
| 245 | ASSERT_TRUE(irt.Remove(cookie, manyRefs[i])) << "failed removing " << i; |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 246 | CheckDump(&irt, kTableInitial - i, 1); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 247 | } |
| 248 | // Because of removal order, should have 11 entries, 10 of them holes. |
| 249 | ASSERT_EQ(kTableInitial + 1, irt.Capacity()); |
| 250 | |
| 251 | ASSERT_TRUE(irt.Remove(cookie, iref0)) << "multi-remove final failed"; |
| 252 | |
| 253 | ASSERT_EQ(0U, irt.Capacity()) << "multi-del not empty"; |
Ian Rogers | 63818dc | 2012-09-26 12:23:04 -0700 | [diff] [blame] | 254 | CheckDump(&irt, 0, 0); |
Elliott Hughes | 6c1a394 | 2011-08-17 15:00:06 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | } // namespace art |