indirect_reference_table_test.cc revision 2cebb24bfc3247d3e9be138a3350106737455918
16c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes/* 26c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * Copyright (C) 2009 The Android Open Source Project 36c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * 46c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 56c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * you may not use this file except in compliance with the License. 66c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * You may obtain a copy of the License at 76c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * 86c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 96c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * 106c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * Unless required by applicable law or agreed to in writing, software 116c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 126c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * See the License for the specific language governing permissions and 146c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes * limitations under the License. 156c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes */ 166c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 17c56057e40938c587a74984651a510e320a8cb4fdMathieu Chartier#include "indirect_reference_table-inl.h" 18a1ce1fef2d49d1d537776a5308ace7102a815fe5Brian Carlstrom 193481ba2c4e4f3aa80d8c6d50a9f85dacb56b508bVladimir Marko#include "class_linker-inl.h" 20a1ce1fef2d49d1d537776a5308ace7102a815fe5Brian Carlstrom#include "common_runtime_test.h" 21967a0adf8b93a23d2a8fef82e06bd913db94ac19Hiroshi Yamauchi#include "mirror/object-inl.h" 22e63db27db913f1a88e2095a1ee8239b2bb9124e8Ian Rogers#include "scoped_thread_state_change.h" 236c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 246c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughesnamespace art { 256c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 26a1ce1fef2d49d1d537776a5308ace7102a815fe5Brian Carlstromclass IndirectReferenceTableTest : public CommonRuntimeTest {}; 276c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 2863818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogersstatic void CheckDump(IndirectReferenceTable* irt, size_t num_objects, size_t num_unique) 2963818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 3063818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers std::ostringstream oss; 3163818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers irt->Dump(oss); 3263818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers if (num_objects == 0) { 3363818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers EXPECT_EQ(oss.str().find("java.lang.Object"), std::string::npos) << oss.str(); 3463818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers } else if (num_objects == 1) { 3563818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers EXPECT_NE(oss.str().find("1 of java.lang.Object"), std::string::npos) << oss.str(); 3663818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers } else { 3763818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers EXPECT_NE(oss.str().find(StringPrintf("%zd of java.lang.Object (%zd unique instances)", 3863818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers num_objects, num_unique)), 3963818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers std::string::npos) 4063818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers << "\n Expected number of objects: " << num_objects 4163818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers << "\n Expected unique objects: " << num_unique << "\n" 4263818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers << oss.str(); 4363818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers } 4463818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers} 4563818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers 466c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott HughesTEST_F(IndirectReferenceTableTest, BasicTest) { 47369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe // This will lead to error messages in the log. 48369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe ScopedLogSeverity sls(LogSeverity::FATAL); 49369810a98e6394b6dd162f5349e38a1f597b3bc7Andreas Gampe 5000f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers ScopedObjectAccess soa(Thread::Current()); 516c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes static const size_t kTableInitial = 10; 526c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes static const size_t kTableMax = 20; 536c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes IndirectReferenceTable irt(kTableInitial, kTableMax, kGlobal); 546c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 559837939678bb5dcba178e5fb00ed59b5d14c8d9bIan Rogers mirror::Class* c = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"); 56c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers ASSERT_TRUE(c != nullptr); 572dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Object* obj0 = c->AllocObject(soa.Self()); 58c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers ASSERT_TRUE(obj0 != nullptr); 592dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Object* obj1 = c->AllocObject(soa.Self()); 60c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers ASSERT_TRUE(obj1 != nullptr); 612dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Object* obj2 = c->AllocObject(soa.Self()); 62c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers ASSERT_TRUE(obj2 != nullptr); 632dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Object* obj3 = c->AllocObject(soa.Self()); 64c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers ASSERT_TRUE(obj3 != nullptr); 656c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 666c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes const uint32_t cookie = IRT_FIRST_SEGMENT; 676c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 6863818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 6963818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers 706c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes IndirectRef iref0 = (IndirectRef) 0x11110; 716c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes EXPECT_FALSE(irt.Remove(cookie, iref0)) << "unexpectedly successful removal"; 726c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 736c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Add three, check, remove in the order in which they were added. 746c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref0 = irt.Add(cookie, obj0); 75c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref0 != nullptr); 7663818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 776c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes IndirectRef iref1 = irt.Add(cookie, obj1); 78c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref1 != nullptr); 7963818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 2, 2); 806c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes IndirectRef iref2 = irt.Add(cookie, obj2); 81c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref2 != nullptr); 8263818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 3, 3); 836c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 846c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes EXPECT_EQ(obj0, irt.Get(iref0)); 856c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes EXPECT_EQ(obj1, irt.Get(iref1)); 866c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes EXPECT_EQ(obj2, irt.Get(iref2)); 876c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 886c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes EXPECT_TRUE(irt.Remove(cookie, iref0)); 8963818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 2, 2); 906c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes EXPECT_TRUE(irt.Remove(cookie, iref1)); 9163818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 926c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes EXPECT_TRUE(irt.Remove(cookie, iref2)); 9363818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 946c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 956c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Table should be empty now. 966c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes EXPECT_EQ(0U, irt.Capacity()); 976c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 986c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Get invalid entry (off the end of the list). 99c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(irt.Get(iref0) == nullptr); 1006c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1016c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Add three, remove in the opposite order. 1026c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref0 = irt.Add(cookie, obj0); 103c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref0 != nullptr); 1046c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref1 = irt.Add(cookie, obj1); 105c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref1 != nullptr); 1066c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref2 = irt.Add(cookie, obj2); 107c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref2 != nullptr); 10863818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 3, 3); 1096c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1106c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref2)); 11163818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 2, 2); 1126c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref1)); 11363818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 1146c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref0)); 11563818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 1166c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1176c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Table should be empty now. 1186c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(0U, irt.Capacity()); 1196c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1206c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Add three, remove middle / middle / bottom / top. (Second attempt 1216c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // to remove middle should fail.) 1226c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref0 = irt.Add(cookie, obj0); 123c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref0 != nullptr); 1246c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref1 = irt.Add(cookie, obj1); 125c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref1 != nullptr); 1266c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref2 = irt.Add(cookie, obj2); 127c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref2 != nullptr); 12863818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 3, 3); 1296c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1306c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(3U, irt.Capacity()); 1316c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1326c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref1)); 13363818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 2, 2); 1346c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_FALSE(irt.Remove(cookie, iref1)); 13563818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 2, 2); 1366c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1376c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Get invalid entry (from hole). 138c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(irt.Get(iref1) == nullptr); 1396c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1406c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref2)); 14163818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 1426c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref0)); 14363818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 1446c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1456c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Table should be empty now. 1466c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(0U, irt.Capacity()); 1476c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1486c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Add four entries. Remove #1, add new entry, verify that table size 1496c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // is still 4 (i.e. holes are getting filled). Remove #1 and #3, verify 1506c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // that we delete one and don't hole-compact the other. 1516c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref0 = irt.Add(cookie, obj0); 152c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref0 != nullptr); 1536c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref1 = irt.Add(cookie, obj1); 154c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref1 != nullptr); 1556c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref2 = irt.Add(cookie, obj2); 156c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref2 != nullptr); 1576c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes IndirectRef iref3 = irt.Add(cookie, obj3); 158c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref3 != nullptr); 15963818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 4, 4); 1606c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1616c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref1)); 16263818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 3, 3); 1636c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1646c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref1 = irt.Add(cookie, obj1); 165c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref1 != nullptr); 1666c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1676c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(4U, irt.Capacity()) << "hole not filled"; 16863818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 4, 4); 1696c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1706c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref1)); 17163818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 3, 3); 1726c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref3)); 17363818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 2, 2); 1746c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1756c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(3U, irt.Capacity()) << "should be 3 after two deletions"; 1766c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1776c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref2)); 17863818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 1796c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref0)); 18063818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 1816c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1826c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(0U, irt.Capacity()) << "not empty after split remove"; 1836c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 1846c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Add an entry, remove it, add a new entry, and try to use the original 1856c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // iref. They have the same slot number but are for different objects. 1866c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // With the extended checks in place, this should fail. 1876c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref0 = irt.Add(cookie, obj0); 188c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref0 != nullptr); 18963818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 1906c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref0)); 19163818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 1926c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref1 = irt.Add(cookie, obj1); 193c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref1 != nullptr); 19463818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 1956c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_FALSE(irt.Remove(cookie, iref0)) << "mismatched del succeeded"; 19663818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 1976c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref1)) << "switched del failed"; 1986c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(0U, irt.Capacity()) << "switching del not empty"; 19963818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 2006c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 2016c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Same as above, but with the same object. A more rigorous checker 2026c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // (e.g. with slot serialization) will catch this. 2036c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref0 = irt.Add(cookie, obj0); 204c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref0 != nullptr); 20563818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 2066c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref0)); 20763818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 2086c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref1 = irt.Add(cookie, obj0); 209c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref1 != nullptr); 21063818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 2116c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes if (iref0 != iref1) { 2126c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Try 0, should not work. 2136c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_FALSE(irt.Remove(cookie, iref0)) << "temporal del succeeded"; 2146c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes } 2156c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref1)) << "temporal cleanup failed"; 2166c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(0U, irt.Capacity()) << "temporal del not empty"; 21763818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 2186c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 2192cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier // null isn't a valid iref. 220c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers ASSERT_TRUE(irt.Get(nullptr) == nullptr); 2216c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 2226c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Stale lookup. 2236c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref0 = irt.Add(cookie, obj0); 224c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(iref0 != nullptr); 22563818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 1, 1); 2266c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref0)); 227c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers EXPECT_TRUE(irt.Get(iref0) == nullptr) << "stale lookup succeeded"; 22863818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 2296c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 2306c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Test table resizing. 2316c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // These ones fit... 2326c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes IndirectRef manyRefs[kTableInitial]; 2336c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes for (size_t i = 0; i < kTableInitial; i++) { 2346c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes manyRefs[i] = irt.Add(cookie, obj0); 235c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers ASSERT_TRUE(manyRefs[i] != nullptr) << "Failed adding " << i; 23663818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, i + 1, 1); 2376c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes } 2386c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // ...this one causes overflow. 2396c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes iref0 = irt.Add(cookie, obj0); 240c0542af3e2170143ba40d89136e284997e16bf64Ian Rogers ASSERT_TRUE(iref0 != nullptr); 2416c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(kTableInitial + 1, irt.Capacity()); 24263818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, kTableInitial + 1, 1); 2436c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 2446c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes for (size_t i = 0; i < kTableInitial; i++) { 2456c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, manyRefs[i])) << "failed removing " << i; 24663818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, kTableInitial - i, 1); 2476c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes } 2486c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes // Because of removal order, should have 11 entries, 10 of them holes. 2496c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(kTableInitial + 1, irt.Capacity()); 2506c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 2516c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_TRUE(irt.Remove(cookie, iref0)) << "multi-remove final failed"; 2526c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 2536c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes ASSERT_EQ(0U, irt.Capacity()) << "multi-del not empty"; 25463818dc8b06af4a1e65c41b453f1a42166c22728Ian Rogers CheckDump(&irt, 0, 0); 2556c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes} 2566c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes 2576c1a394b47c85c8d1723fc3b156a3b1b0b29a757Elliott Hughes} // namespace art 258