OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
919 HeapStats backToInitial; | 919 HeapStats backToInitial; |
920 clearOutOldGarbage(&backToInitial); | 920 clearOutOldGarbage(&backToInitial); |
921 EXPECT_TRUE(initialHeapSize == backToInitial); | 921 EXPECT_TRUE(initialHeapSize == backToInitial); |
922 EXPECT_EQ(11, IntWrapper::s_destructorCalls); | 922 EXPECT_EQ(11, IntWrapper::s_destructorCalls); |
923 EXPECT_EQ(11, LargeObject::s_destructorCalls); | 923 EXPECT_EQ(11, LargeObject::s_destructorCalls); |
924 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 924 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
925 | 925 |
926 Heap::shutdown(); | 926 Heap::shutdown(); |
927 } | 927 } |
928 | 928 |
929 class Container : public GarbageCollected<Container> { | |
930 DECLARE_GC_INFO | |
931 public: | |
932 static Container* create() { return new Container(); } | |
933 HeapHashMap<Member<IntWrapper>, Member<IntWrapper> > map; | |
934 HeapHashSet<Member<IntWrapper> > set; | |
935 HeapHashSet<Member<IntWrapper> > set2; | |
936 HeapVector<Member<IntWrapper>, 2> vector; | |
937 void trace(Visitor* visitor) | |
938 { | |
939 visitor->trace(map); | |
940 visitor->trace(set); | |
941 visitor->trace(set2); | |
942 visitor->trace(vector); | |
943 } | |
944 }; | |
945 | |
946 TEST(HeapTest, HeapVectorWithInlineCapacity) | |
947 { | |
948 // FIXME: init and shutdown should be called via Blink | |
949 // initialization in the test runner. | |
950 Heap::init(); | |
haraken
2014/01/15 04:48:35
This was removed by wibling's CL.
| |
951 | |
952 { | |
953 IntWrapper* one = IntWrapper::create(1); | |
954 IntWrapper* two = IntWrapper::create(2); | |
955 IntWrapper* three = IntWrapper::create(3); | |
956 IntWrapper* four = IntWrapper::create(4); | |
957 IntWrapper* five = IntWrapper::create(5); | |
958 IntWrapper* six = IntWrapper::create(6); | |
959 { | |
960 HeapVector<Member<IntWrapper>, 2> vector; | |
961 vector.append(one); | |
962 vector.append(two); | |
963 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | |
964 EXPECT_TRUE(vector.contains(one)); | |
965 EXPECT_TRUE(vector.contains(two)); | |
966 | |
967 vector.append(three); | |
968 vector.append(four); | |
969 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | |
970 EXPECT_TRUE(vector.contains(one)); | |
971 EXPECT_TRUE(vector.contains(two)); | |
972 EXPECT_TRUE(vector.contains(three)); | |
973 EXPECT_TRUE(vector.contains(four)); | |
974 | |
975 vector.shrink(1); | |
976 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | |
977 EXPECT_TRUE(vector.contains(one)); | |
978 EXPECT_FALSE(vector.contains(two)); | |
979 EXPECT_FALSE(vector.contains(three)); | |
980 EXPECT_FALSE(vector.contains(four)); | |
981 } | |
982 { | |
983 HeapVector<Member<IntWrapper>, 2> vector1; | |
984 HeapVector<Member<IntWrapper>, 2> vector2; | |
985 | |
986 vector1.append(one); | |
987 vector2.append(two); | |
988 vector1.swap(vector2); | |
989 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | |
990 EXPECT_TRUE(vector1.contains(two)); | |
991 EXPECT_TRUE(vector2.contains(one)); | |
992 } | |
993 { | |
994 HeapVector<Member<IntWrapper>, 2> vector1; | |
995 HeapVector<Member<IntWrapper>, 2> vector2; | |
996 | |
997 vector1.append(one); | |
998 vector1.append(two); | |
999 vector2.append(three); | |
1000 vector2.append(four); | |
1001 vector2.append(five); | |
1002 vector2.append(six); | |
1003 vector1.swap(vector2); | |
1004 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | |
1005 EXPECT_TRUE(vector1.contains(three)); | |
1006 EXPECT_TRUE(vector1.contains(four)); | |
1007 EXPECT_TRUE(vector1.contains(five)); | |
1008 EXPECT_TRUE(vector1.contains(six)); | |
1009 EXPECT_TRUE(vector2.contains(one)); | |
1010 EXPECT_TRUE(vector2.contains(two)); | |
1011 } | |
1012 } | |
1013 | |
1014 Heap::shutdown(); | |
1015 } | |
1016 | |
1017 TEST(HeapTest, HeapCollectionTypes) | |
1018 { | |
1019 // FIXME: init and shutdown should be called via Blink | |
1020 // initialization in the test runner. | |
1021 Heap::init(); | |
haraken
2014/01/15 04:48:35
Ditto.
| |
1022 | |
1023 { | |
1024 HeapStats initialHeapSize; | |
1025 IntWrapper::s_destructorCalls = 0; | |
1026 | |
1027 typedef HeapHashMap<Member<IntWrapper>, Member<IntWrapper> > MemberMembe r; | |
1028 typedef HeapHashMap<Member<IntWrapper>, int> MemberPrimitive; | |
1029 typedef HeapHashMap<int, Member<IntWrapper> > PrimitiveMember; | |
1030 | |
1031 typedef HeapHashSet<Member<IntWrapper> > MemberSet; | |
1032 typedef HeapHashSet<WeakMember<IntWrapper> > WeakMemberSet; | |
1033 | |
1034 typedef HeapVector<Member<IntWrapper>, 2> MemberVector; | |
1035 | |
1036 Persistent<MemberMember> memberMember = new MemberMember(); | |
1037 Persistent<MemberMember> memberMember2 = new MemberMember(); | |
1038 Persistent<MemberMember> memberMember3 = new MemberMember(); | |
1039 Persistent<MemberPrimitive> memberPrimitive = new MemberPrimitive(); | |
1040 Persistent<PrimitiveMember> primitiveMember = new PrimitiveMember(); | |
1041 Persistent<MemberSet> set = new MemberSet(); | |
1042 Persistent<MemberSet> set2 = new MemberSet(); | |
1043 Persistent<MemberVector> vector = new MemberVector(); | |
1044 Persistent<MemberVector> vector2 = new MemberVector(); | |
1045 Persistent<Container> container = Container::create(); | |
1046 | |
1047 clearOutOldGarbage(&initialHeapSize); | |
1048 { | |
1049 Persistent<IntWrapper> one(IntWrapper::create(1)); | |
1050 Persistent<IntWrapper> two(IntWrapper::create(2)); | |
1051 Persistent<IntWrapper> oneB(IntWrapper::create(1)); | |
1052 Persistent<IntWrapper> twoB(IntWrapper::create(2)); | |
1053 Persistent<IntWrapper> oneC(IntWrapper::create(1)); | |
1054 Persistent<IntWrapper> twoC(IntWrapper::create(2)); | |
1055 { | |
1056 IntWrapper* three(IntWrapper::create(3)); | |
1057 IntWrapper* four(IntWrapper::create(4)); | |
1058 IntWrapper* threeB(IntWrapper::create(3)); | |
1059 IntWrapper* fourB(IntWrapper::create(4)); | |
1060 | |
1061 // Member Collections. | |
1062 memberMember2->add(one, two); | |
1063 memberMember2->add(two, three); | |
1064 memberMember2->add(three, four); | |
1065 memberMember2->add(four, one); | |
1066 primitiveMember->add(1, two); | |
1067 primitiveMember->add(2, three); | |
1068 primitiveMember->add(3, four); | |
1069 primitiveMember->add(4, one); | |
1070 memberPrimitive->add(one, 2); | |
1071 memberPrimitive->add(two, 3); | |
1072 memberPrimitive->add(three, 4); | |
1073 memberPrimitive->add(four, 1); | |
1074 set2->add(one); | |
1075 set2->add(two); | |
1076 set2->add(three); | |
1077 set2->add(four); | |
1078 set->add(oneB); | |
1079 vector->append(oneB); | |
1080 vector2->append(threeB); | |
1081 vector2->append(fourB); | |
1082 | |
1083 // Collect garbage. This should change nothing since we are keep ing | |
1084 // alive the IntWrapper objects with on-stack pointers. | |
1085 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | |
1086 EXPECT_EQ(0u, memberMember->size()); | |
1087 EXPECT_EQ(4u, memberMember2->size()); | |
1088 EXPECT_EQ(4u, primitiveMember->size()); | |
1089 EXPECT_EQ(4u, memberPrimitive->size()); | |
1090 EXPECT_EQ(1u, set->size()); | |
1091 EXPECT_EQ(4u, set2->size()); | |
1092 EXPECT_EQ(1u, vector->size()); | |
1093 EXPECT_EQ(2u, vector2->size()); | |
1094 | |
1095 MemberVector& cvec = container->vector; | |
1096 cvec.swap(*vector.raw()); | |
1097 vector2->swap(cvec); | |
1098 vector->swap(cvec); | |
1099 | |
1100 // Swap set and set2 in a roundabout way. | |
1101 MemberSet& cset1 = container->set; | |
1102 MemberSet& cset2 = container->set2; | |
1103 set->swap(cset1); | |
1104 set2->swap(cset2); | |
1105 set->swap(cset2); | |
1106 cset1.swap(cset2); | |
1107 cset2.swap(set2); | |
1108 | |
1109 // Triple swap. | |
1110 container->map.swap(memberMember2); | |
1111 MemberMember& containedMap = container->map; | |
1112 memberMember3->swap(containedMap); | |
1113 memberMember3->swap(memberMember); | |
1114 | |
1115 EXPECT_TRUE(memberMember->get(one) == two); | |
1116 EXPECT_TRUE(memberMember->get(two) == three); | |
1117 EXPECT_TRUE(memberMember->get(three) == four); | |
1118 EXPECT_TRUE(memberMember->get(four) == one); | |
1119 EXPECT_TRUE(primitiveMember->get(1) == two); | |
1120 EXPECT_TRUE(primitiveMember->get(2) == three); | |
1121 EXPECT_TRUE(primitiveMember->get(3) == four); | |
1122 EXPECT_TRUE(primitiveMember->get(4) == one); | |
1123 EXPECT_EQ(1, memberPrimitive->get(four)); | |
1124 EXPECT_EQ(2, memberPrimitive->get(one)); | |
1125 EXPECT_EQ(3, memberPrimitive->get(two)); | |
1126 EXPECT_EQ(4, memberPrimitive->get(three)); | |
1127 EXPECT_TRUE(set->contains(one)); | |
1128 EXPECT_TRUE(set->contains(two)); | |
1129 EXPECT_TRUE(set->contains(three)); | |
1130 EXPECT_TRUE(set->contains(four)); | |
1131 EXPECT_TRUE(set2->contains(oneB)); | |
1132 EXPECT_TRUE(vector->contains(threeB)); | |
1133 EXPECT_TRUE(vector->contains(fourB)); | |
1134 EXPECT_TRUE(vector2->contains(oneB)); | |
1135 EXPECT_FALSE(vector2->contains(threeB)); | |
1136 } | |
1137 | |
1138 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
1139 | |
1140 EXPECT_EQ(4u, memberMember->size()); | |
1141 EXPECT_EQ(0u, memberMember2->size()); | |
1142 EXPECT_EQ(4u, primitiveMember->size()); | |
1143 EXPECT_EQ(4u, memberPrimitive->size()); | |
1144 EXPECT_EQ(4u, set->size()); | |
1145 EXPECT_EQ(1u, set2->size()); | |
1146 EXPECT_EQ(2u, vector->size()); | |
1147 EXPECT_EQ(1u, vector2->size()); | |
1148 | |
1149 EXPECT_TRUE(memberMember->get(one) == two); | |
1150 EXPECT_TRUE(primitiveMember->get(1) == two); | |
1151 EXPECT_TRUE(primitiveMember->get(4) == one); | |
1152 EXPECT_EQ(2, memberPrimitive->get(one)); | |
1153 EXPECT_EQ(3, memberPrimitive->get(two)); | |
1154 EXPECT_TRUE(set->contains(one)); | |
1155 EXPECT_TRUE(set->contains(two)); | |
1156 EXPECT_FALSE(set->contains(oneB)); | |
1157 EXPECT_TRUE(set2->contains(oneB)); | |
1158 EXPECT_EQ(3, vector->at(0)->value()); | |
1159 EXPECT_EQ(4, vector->at(1)->value()); | |
1160 } | |
1161 | |
1162 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
1163 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
1164 | |
1165 EXPECT_EQ(4u, memberMember->size()); | |
1166 EXPECT_EQ(4u, primitiveMember->size()); | |
1167 EXPECT_EQ(4u, memberPrimitive->size()); | |
1168 EXPECT_EQ(4u, set->size()); | |
1169 EXPECT_EQ(1u, set2->size()); | |
1170 EXPECT_EQ(2u, vector->size()); | |
1171 EXPECT_EQ(1u, vector2->size()); | |
1172 EXPECT_EQ(2u, vector->size()); | |
1173 EXPECT_EQ(1u, vector2->size()); | |
1174 } | |
1175 | |
1176 Heap::shutdown(); | |
1177 } | |
1178 | |
1179 template<typename T> | |
1180 void MapIteratorCheck(T& it, const T& end, int expected) | |
1181 { | |
1182 int found = 0; | |
1183 while (it != end) { | |
1184 found++; | |
1185 int key = it->key->value(); | |
1186 int value = it->value->value(); | |
1187 EXPECT_TRUE(key >= 0 && key < 1100); | |
1188 EXPECT_TRUE(value >= 0 && value < 1100); | |
1189 ++it; | |
1190 } | |
1191 EXPECT_EQ(expected, found); | |
1192 } | |
1193 | |
1194 template<typename T> | |
1195 void SetIteratorCheck(T& it, const T& end, int expected) | |
1196 { | |
1197 int found = 0; | |
1198 while (it != end) { | |
1199 found++; | |
1200 int value = (*it)->value(); | |
1201 EXPECT_TRUE(value >= 0 && value < 1100); | |
1202 ++it; | |
1203 } | |
1204 EXPECT_EQ(expected, found); | |
1205 } | |
1206 | |
1207 TEST(HeapTest, HeapWeakCollectionSimple) | |
1208 { | |
1209 // FIXME: init and shutdown should be called via Blink | |
1210 // initialization in the test runner. | |
1211 Heap::init(); | |
haraken
2014/01/15 04:48:35
Ditto.
| |
1212 { | |
1213 | |
1214 IntWrapper::s_destructorCalls = 0; | |
1215 | |
1216 CollectionPersistent<Vector<Member<IntWrapper> > > keepNumbersAlive; | |
1217 | |
1218 typedef HeapHashMap<WeakMember<IntWrapper>, Member<IntWrapper> > WeakStr ong; | |
1219 typedef HeapHashMap<Member<IntWrapper>, WeakMember<IntWrapper> > StrongW eak; | |
1220 typedef HeapHashMap<WeakMember<IntWrapper>, WeakMember<IntWrapper> > Wea kWeak; | |
1221 typedef HeapHashSet<WeakMember<IntWrapper> > WeakSet; | |
1222 | |
1223 Persistent<WeakStrong> weakStrong = new WeakStrong(); | |
1224 Persistent<StrongWeak> strongWeak = new StrongWeak(); | |
1225 Persistent<WeakWeak> weakWeak = new WeakWeak(); | |
1226 Persistent<WeakSet> weakSet = new WeakSet(); | |
1227 | |
1228 Persistent<IntWrapper> two = IntWrapper::create(2); | |
1229 | |
1230 keepNumbersAlive->append(IntWrapper::create(103)); | |
1231 keepNumbersAlive->append(IntWrapper::create(10)); | |
1232 | |
1233 { | |
1234 weakStrong->add(IntWrapper::create(1), two); | |
1235 strongWeak->add(two, IntWrapper::create(1)); | |
1236 weakWeak->add(two, IntWrapper::create(42)); | |
1237 weakWeak->add(IntWrapper::create(42), two); | |
1238 weakSet->add(IntWrapper::create(0)); | |
1239 weakSet->add(two); | |
1240 weakSet->add(keepNumbersAlive[0]); | |
1241 weakSet->add(keepNumbersAlive[1]); | |
1242 EXPECT_EQ(1u, weakStrong->size()); | |
1243 EXPECT_EQ(1u, strongWeak->size()); | |
1244 EXPECT_EQ(2u, weakWeak->size()); | |
1245 EXPECT_EQ(4u, weakSet->size()); | |
1246 } | |
1247 | |
1248 keepNumbersAlive[0] = nullptr; | |
1249 | |
1250 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
1251 | |
1252 EXPECT_EQ(0u, weakStrong->size()); | |
1253 EXPECT_EQ(0u, strongWeak->size()); | |
1254 EXPECT_EQ(0u, weakWeak->size()); | |
1255 EXPECT_EQ(2u, weakSet->size()); | |
1256 } | |
1257 | |
1258 Heap::shutdown(); | |
1259 } | |
1260 | |
1261 TEST(HeapTest, HeapWeakCollectionTypes) | |
1262 { | |
1263 // FIXME: init and shutdown should be called via Blink | |
1264 // initialization in the test runner. | |
1265 Heap::init(); | |
haraken
2014/01/15 04:48:35
Ditto.
| |
1266 | |
1267 HeapStats initialHeapSize; | |
1268 IntWrapper::s_destructorCalls = 0; | |
1269 | |
1270 typedef HeapHashMap<WeakMember<IntWrapper>, Member<IntWrapper> > WeakStrong; | |
1271 typedef HeapHashMap<Member<IntWrapper>, WeakMember<IntWrapper> > StrongWeak; | |
1272 typedef HeapHashMap<WeakMember<IntWrapper>, WeakMember<IntWrapper> > WeakWea k; | |
1273 typedef HeapHashSet<WeakMember<IntWrapper> > WeakSet; | |
1274 | |
1275 clearOutOldGarbage(&initialHeapSize); | |
1276 | |
1277 const int weakStrongIndex = 0; | |
1278 const int strongWeakIndex = 1; | |
1279 const int weakWeakIndex = 2; | |
1280 const int numberOfMapIndices = 3; | |
1281 const int weakSetIndex = 3; | |
1282 const int numberOfCollections = 4; | |
1283 | |
1284 for (int testRun = 0; testRun < 4; testRun++) { | |
1285 for (int collectionNumber = 0; collectionNumber < numberOfCollections; c ollectionNumber++) { | |
1286 bool testThatIteratorsMakeStrong = (testRun == weakSetIndex); | |
1287 bool deleteAfterwards = (testRun == 1); | |
1288 bool addAfterwards = (testRun == weakWeakIndex); | |
1289 | |
1290 // The test doesn't work for strongWeak with deleting because we los t | |
1291 // the key from the keepNumbersAlive array, so we can't do the looku p. | |
1292 if (deleteAfterwards && collectionNumber == strongWeakIndex) | |
1293 continue; | |
1294 | |
1295 unsigned added = addAfterwards ? 100 : 0; | |
1296 | |
1297 Persistent<WeakStrong> weakStrong = new WeakStrong(); | |
1298 Persistent<StrongWeak> strongWeak = new StrongWeak(); | |
1299 Persistent<WeakWeak> weakWeak = new WeakWeak(); | |
1300 | |
1301 Persistent<WeakSet> weakSet = new WeakSet(); | |
1302 | |
1303 CollectionPersistent<Vector<Member<IntWrapper> > > keepNumbersAlive; | |
1304 for (int i = 0; i < 128; i += 2) { | |
1305 IntWrapper* wrapped = IntWrapper::create(i); | |
1306 IntWrapper* wrapped2 = IntWrapper::create(i + 1); | |
1307 keepNumbersAlive->append(wrapped); | |
1308 keepNumbersAlive->append(wrapped2); | |
1309 weakStrong->add(wrapped, wrapped2); | |
1310 strongWeak->add(wrapped2, wrapped); | |
1311 weakWeak->add(wrapped, wrapped2); | |
1312 weakSet->add(wrapped); | |
1313 } | |
1314 | |
1315 EXPECT_EQ(64u, weakStrong->size()); | |
1316 EXPECT_EQ(64u, strongWeak->size()); | |
1317 EXPECT_EQ(64u, weakWeak->size()); | |
1318 EXPECT_EQ(64u, weakSet->size()); | |
1319 | |
1320 // Collect garbage. This should change nothing since we are keeping | |
1321 // alive the IntWrapper objects. | |
1322 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
1323 | |
1324 EXPECT_EQ(64u, weakStrong->size()); | |
1325 EXPECT_EQ(64u, strongWeak->size()); | |
1326 EXPECT_EQ(64u, weakWeak->size()); | |
1327 EXPECT_EQ(64u, weakSet->size()); | |
1328 | |
1329 for (int i = 0; i < 128; i += 2) { | |
1330 IntWrapper* wrapped = keepNumbersAlive[i]; | |
1331 IntWrapper* wrapped2 = keepNumbersAlive[i + 1]; | |
1332 EXPECT_EQ(wrapped2, weakStrong->get(wrapped)); | |
1333 EXPECT_EQ(wrapped, strongWeak->get(wrapped2)); | |
1334 EXPECT_EQ(wrapped2, weakWeak->get(wrapped)); | |
1335 EXPECT_TRUE(weakSet->contains(wrapped)); | |
1336 } | |
1337 | |
1338 for (int i = 0; i < 128; i += 3) | |
1339 keepNumbersAlive[i] = nullptr; | |
1340 | |
1341 if (collectionNumber != weakStrongIndex) | |
1342 weakStrong->clear(); | |
1343 if (collectionNumber != strongWeakIndex) | |
1344 strongWeak->clear(); | |
1345 if (collectionNumber != weakWeakIndex) | |
1346 weakWeak->clear(); | |
1347 if (collectionNumber != weakSetIndex) | |
1348 weakSet->clear(); | |
1349 | |
1350 if (testThatIteratorsMakeStrong) { | |
1351 WeakStrong::iterator it1 = weakStrong->begin(); | |
1352 StrongWeak::iterator it2 = strongWeak->begin(); | |
1353 WeakWeak::iterator it3 = weakWeak->begin(); | |
1354 WeakSet::iterator it4 = weakSet->begin(); | |
1355 // Collect garbage. This should change nothing since the | |
1356 // iterators make the collections strong. | |
1357 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | |
1358 if (collectionNumber == weakStrongIndex) { | |
1359 EXPECT_EQ(64u, weakStrong->size()); | |
1360 MapIteratorCheck(it1, weakStrong->end(), 64); | |
1361 } else if (collectionNumber == strongWeakIndex) { | |
1362 EXPECT_EQ(64u, strongWeak->size()); | |
1363 MapIteratorCheck(it2, strongWeak->end(), 64); | |
1364 } else if (collectionNumber == weakWeakIndex) { | |
1365 EXPECT_EQ(64u, weakWeak->size()); | |
1366 MapIteratorCheck(it3, weakWeak->end(), 64); | |
1367 } else if (collectionNumber == weakSetIndex) { | |
1368 EXPECT_EQ(64u, weakSet->size()); | |
1369 SetIteratorCheck(it4, weakSet->end(), 64); | |
1370 } | |
1371 } else { | |
1372 // Collect garbage. This causes weak processing to remove | |
1373 // things from the collections. | |
1374 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
1375 unsigned count = 0; | |
1376 for (int i = 0; i < 128; i += 2) { | |
1377 bool firstAlive = keepNumbersAlive[i]; | |
1378 bool secondAlive = keepNumbersAlive[i + 1]; | |
1379 if (firstAlive && (collectionNumber == weakStrongIndex || co llectionNumber == strongWeakIndex)) | |
1380 secondAlive = true; | |
1381 if (firstAlive && secondAlive && collectionNumber < numberOf MapIndices) { | |
1382 if (collectionNumber == weakStrongIndex) { | |
1383 if (deleteAfterwards) | |
1384 EXPECT_EQ(i + 1, weakStrong->take(keepNumbersAli ve[i])->value()); | |
1385 } else if (collectionNumber == strongWeakIndex) { | |
1386 if (deleteAfterwards) | |
1387 EXPECT_EQ(i, strongWeak->take(keepNumbersAlive[i + 1])->value()); | |
1388 } else if (collectionNumber == weakWeakIndex) { | |
1389 if (deleteAfterwards) | |
1390 EXPECT_EQ(i + 1, weakWeak->take(keepNumbersAlive [i])->value()); | |
1391 } | |
1392 if (!deleteAfterwards) | |
1393 count++; | |
1394 } else if (collectionNumber == weakSetIndex && firstAlive) { | |
1395 ASSERT_TRUE(weakSet->contains(keepNumbersAlive[i])); | |
1396 if (deleteAfterwards) | |
1397 weakSet->remove(keepNumbersAlive[i]); | |
1398 else | |
1399 count++; | |
1400 } | |
1401 } | |
1402 if (addAfterwards) { | |
1403 for (int i = 1000; i < 1100; i++) { | |
1404 IntWrapper* wrapped = IntWrapper::create(i); | |
1405 keepNumbersAlive->append(wrapped); | |
1406 weakStrong->add(wrapped, wrapped); | |
1407 strongWeak->add(wrapped, wrapped); | |
1408 weakWeak->add(wrapped, wrapped); | |
1409 weakSet->add(wrapped); | |
1410 } | |
1411 } | |
1412 if (collectionNumber == weakStrongIndex) | |
1413 EXPECT_EQ(count + added, weakStrong->size()); | |
1414 else if (collectionNumber == strongWeakIndex) | |
1415 EXPECT_EQ(count + added, strongWeak->size()); | |
1416 else if (collectionNumber == weakWeakIndex) | |
1417 EXPECT_EQ(count + added, weakWeak->size()); | |
1418 else if (collectionNumber == weakSetIndex) | |
1419 EXPECT_EQ(count + added, weakSet->size()); | |
1420 WeakStrong::iterator it1 = weakStrong->begin(); | |
1421 StrongWeak::iterator it2 = strongWeak->begin(); | |
1422 WeakWeak::iterator it3 = weakWeak->begin(); | |
1423 WeakSet::iterator it4 = weakSet->begin(); | |
1424 MapIteratorCheck(it1, weakStrong->end(), (collectionNumber == we akStrongIndex ? count : 0) + added); | |
1425 MapIteratorCheck(it2, strongWeak->end(), (collectionNumber == st rongWeakIndex ? count : 0) + added); | |
1426 MapIteratorCheck(it3, weakWeak->end(), (collectionNumber == weak WeakIndex ? count : 0) + added); | |
1427 SetIteratorCheck(it4, weakSet->end(), (collectionNumber == weakS etIndex ? count : 0) + added); | |
1428 } | |
1429 for (unsigned i = 0; i < 128 + added; i++) | |
1430 keepNumbersAlive[i] = nullptr; | |
1431 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
1432 EXPECT_EQ(added, weakStrong->size()); | |
1433 EXPECT_EQ(added, strongWeak->size()); | |
1434 EXPECT_EQ(added, weakWeak->size()); | |
1435 EXPECT_EQ(added, weakSet->size()); | |
1436 } | |
1437 } | |
1438 | |
1439 Heap::shutdown(); | |
1440 } | |
1441 | |
929 TEST(HeapTest, RefCountedGarbageCollected) | 1442 TEST(HeapTest, RefCountedGarbageCollected) |
930 { | 1443 { |
931 // FIXME: init and shutdown should be called via Blink | 1444 // FIXME: init and shutdown should be called via Blink |
932 // initialization in the test runner. | 1445 // initialization in the test runner. |
933 Heap::init(); | 1446 Heap::init(); |
934 | 1447 |
935 RefCountedAndGarbageCollected::s_destructorCalls = 0; | 1448 RefCountedAndGarbageCollected::s_destructorCalls = 0; |
936 { | 1449 { |
937 RefPtr<RefCountedAndGarbageCollected> refPtr3; | 1450 RefPtr<RefCountedAndGarbageCollected> refPtr3; |
938 { | 1451 { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1005 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 1518 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
1006 EXPECT_EQ(0u, Bar::s_live); // All gone. | 1519 EXPECT_EQ(0u, Bar::s_live); // All gone. |
1007 | 1520 |
1008 Heap::shutdown(); | 1521 Heap::shutdown(); |
1009 } | 1522 } |
1010 | 1523 |
1011 DEFINE_GC_INFO(Bar); | 1524 DEFINE_GC_INFO(Bar); |
1012 DEFINE_GC_INFO(Baz); | 1525 DEFINE_GC_INFO(Baz); |
1013 DEFINE_GC_INFO(ClassWithMember); | 1526 DEFINE_GC_INFO(ClassWithMember); |
1014 DEFINE_GC_INFO(ConstructorAllocation); | 1527 DEFINE_GC_INFO(ConstructorAllocation); |
1528 DEFINE_GC_INFO(Container); | |
1015 DEFINE_GC_INFO(HeapAllocatedArray); | 1529 DEFINE_GC_INFO(HeapAllocatedArray); |
1016 DEFINE_GC_INFO(IntWrapper); | 1530 DEFINE_GC_INFO(IntWrapper); |
1017 DEFINE_GC_INFO(LargeObject); | 1531 DEFINE_GC_INFO(LargeObject); |
1018 DEFINE_GC_INFO(RefCountedAndGarbageCollected); | 1532 DEFINE_GC_INFO(RefCountedAndGarbageCollected); |
1019 DEFINE_GC_INFO(SimpleFinalizedObject); | 1533 DEFINE_GC_INFO(SimpleFinalizedObject); |
1020 DEFINE_GC_INFO(TestTypedHeapClass); | 1534 DEFINE_GC_INFO(TestTypedHeapClass); |
1021 DEFINE_GC_INFO(TraceCounter); | 1535 DEFINE_GC_INFO(TraceCounter); |
1022 | 1536 |
1023 } // namespace | 1537 } // namespace |
OLD | NEW |