| 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 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 | 560 |
| 561 int gcCount = 0; | 561 int gcCount = 0; |
| 562 while (!done()) { | 562 while (!done()) { |
| 563 ThreadState::current()->safePoint(BlinkGC::NoHeapPointersOnStack); | 563 ThreadState::current()->safePoint(BlinkGC::NoHeapPointersOnStack); |
| 564 { | 564 { |
| 565 Persistent<HeapHashMap<ThreadMarker, WeakMember<IntWrapper>>> weakMap = | 565 Persistent<HeapHashMap<ThreadMarker, WeakMember<IntWrapper>>> weakMap = |
| 566 new HeapHashMap<ThreadMarker, WeakMember<IntWrapper>>; | 566 new HeapHashMap<ThreadMarker, WeakMember<IntWrapper>>; |
| 567 PersistentHeapHashMap<ThreadMarker, WeakMember<IntWrapper>> weakMap2; | 567 PersistentHeapHashMap<ThreadMarker, WeakMember<IntWrapper>> weakMap2; |
| 568 | 568 |
| 569 for (int i = 0; i < numberOfAllocations; i++) { | 569 for (int i = 0; i < numberOfAllocations; i++) { |
| 570 weakMap->add(static_cast<unsigned>(i), IntWrapper::create(0)); | 570 weakMap->insert(static_cast<unsigned>(i), IntWrapper::create(0)); |
| 571 weakMap2.add(static_cast<unsigned>(i), IntWrapper::create(0)); | 571 weakMap2.insert(static_cast<unsigned>(i), IntWrapper::create(0)); |
| 572 SafePointScope scope(BlinkGC::NoHeapPointersOnStack); | 572 SafePointScope scope(BlinkGC::NoHeapPointersOnStack); |
| 573 testing::yieldCurrentThread(); | 573 testing::yieldCurrentThread(); |
| 574 } | 574 } |
| 575 | 575 |
| 576 if (gcCount < gcPerThread) { | 576 if (gcCount < gcPerThread) { |
| 577 preciselyCollectGarbage(); | 577 preciselyCollectGarbage(); |
| 578 gcCount++; | 578 gcCount++; |
| 579 atomicIncrement(&m_gcCount); | 579 atomicIncrement(&m_gcCount); |
| 580 } | 580 } |
| 581 | 581 |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 | 1172 |
| 1173 explicit FinalizationObserverWithHashMap(Observable& target) | 1173 explicit FinalizationObserverWithHashMap(Observable& target) |
| 1174 : m_target(target) {} | 1174 : m_target(target) {} |
| 1175 ~FinalizationObserverWithHashMap() { | 1175 ~FinalizationObserverWithHashMap() { |
| 1176 m_target.willFinalize(); | 1176 m_target.willFinalize(); |
| 1177 s_didCallWillFinalize = true; | 1177 s_didCallWillFinalize = true; |
| 1178 } | 1178 } |
| 1179 | 1179 |
| 1180 static ObserverMap& observe(Observable& target) { | 1180 static ObserverMap& observe(Observable& target) { |
| 1181 ObserverMap& map = observers(); | 1181 ObserverMap& map = observers(); |
| 1182 ObserverMap::AddResult result = map.add(&target, nullptr); | 1182 ObserverMap::AddResult result = map.insert(&target, nullptr); |
| 1183 if (result.isNewEntry) { | 1183 if (result.isNewEntry) { |
| 1184 result.storedValue->value = | 1184 result.storedValue->value = |
| 1185 WTF::makeUnique<FinalizationObserverWithHashMap>(target); | 1185 WTF::makeUnique<FinalizationObserverWithHashMap>(target); |
| 1186 } else { | 1186 } else { |
| 1187 ASSERT(result.storedValue->value); | 1187 ASSERT(result.storedValue->value); |
| 1188 } | 1188 } |
| 1189 return map; | 1189 return map; |
| 1190 } | 1190 } |
| 1191 | 1191 |
| 1192 static void clearObservers() { | 1192 static void clearObservers() { |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 | 2025 |
| 2026 preciselyCollectGarbage(); | 2026 preciselyCollectGarbage(); |
| 2027 size_t afterGC = heap.objectPayloadSizeForTesting(); | 2027 size_t afterGC = heap.objectPayloadSizeForTesting(); |
| 2028 EXPECT_EQ(afterGC, afterSetWasCreated); | 2028 EXPECT_EQ(afterGC, afterSetWasCreated); |
| 2029 | 2029 |
| 2030 // If the additions below cause garbage collections, these | 2030 // If the additions below cause garbage collections, these |
| 2031 // pointers should be found by conservative stack scanning. | 2031 // pointers should be found by conservative stack scanning. |
| 2032 IntWrapper* one(IntWrapper::create(1)); | 2032 IntWrapper* one(IntWrapper::create(1)); |
| 2033 IntWrapper* anotherOne(IntWrapper::create(1)); | 2033 IntWrapper* anotherOne(IntWrapper::create(1)); |
| 2034 | 2034 |
| 2035 map->add(one, one); | 2035 map->insert(one, one); |
| 2036 | 2036 |
| 2037 size_t afterOneAdd = heap.objectPayloadSizeForTesting(); | 2037 size_t afterOneAdd = heap.objectPayloadSizeForTesting(); |
| 2038 EXPECT_TRUE(afterOneAdd > afterGC); | 2038 EXPECT_TRUE(afterOneAdd > afterGC); |
| 2039 | 2039 |
| 2040 HeapObjectIdentityMap::iterator it(map->begin()); | 2040 HeapObjectIdentityMap::iterator it(map->begin()); |
| 2041 HeapObjectIdentityMap::iterator it2(map->begin()); | 2041 HeapObjectIdentityMap::iterator it2(map->begin()); |
| 2042 ++it; | 2042 ++it; |
| 2043 ++it2; | 2043 ++it2; |
| 2044 | 2044 |
| 2045 map->add(anotherOne, one); | 2045 map->insert(anotherOne, one); |
| 2046 | 2046 |
| 2047 // The addition above can cause an allocation of a new | 2047 // The addition above can cause an allocation of a new |
| 2048 // backing store. We therefore garbage collect before | 2048 // backing store. We therefore garbage collect before |
| 2049 // taking the heap stats in order to get rid of the old | 2049 // taking the heap stats in order to get rid of the old |
| 2050 // backing store. We make sure to not use conservative | 2050 // backing store. We make sure to not use conservative |
| 2051 // stack scanning as that could find a pointer to the | 2051 // stack scanning as that could find a pointer to the |
| 2052 // old backing. | 2052 // old backing. |
| 2053 preciselyCollectGarbage(); | 2053 preciselyCollectGarbage(); |
| 2054 size_t afterAddAndGC = heap.objectPayloadSizeForTesting(); | 2054 size_t afterAddAndGC = heap.objectPayloadSizeForTesting(); |
| 2055 EXPECT_TRUE(afterAddAndGC >= afterOneAdd); | 2055 EXPECT_TRUE(afterAddAndGC >= afterOneAdd); |
| 2056 | 2056 |
| 2057 EXPECT_EQ(map->size(), 2u); // Two different wrappings of '1' are distinct. | 2057 EXPECT_EQ(map->size(), 2u); // Two different wrappings of '1' are distinct. |
| 2058 | 2058 |
| 2059 preciselyCollectGarbage(); | 2059 preciselyCollectGarbage(); |
| 2060 EXPECT_TRUE(map->contains(one)); | 2060 EXPECT_TRUE(map->contains(one)); |
| 2061 EXPECT_TRUE(map->contains(anotherOne)); | 2061 EXPECT_TRUE(map->contains(anotherOne)); |
| 2062 | 2062 |
| 2063 IntWrapper* gotten(map->get(one)); | 2063 IntWrapper* gotten(map->get(one)); |
| 2064 EXPECT_EQ(gotten->value(), one->value()); | 2064 EXPECT_EQ(gotten->value(), one->value()); |
| 2065 EXPECT_EQ(gotten, one); | 2065 EXPECT_EQ(gotten, one); |
| 2066 | 2066 |
| 2067 size_t afterGC2 = heap.objectPayloadSizeForTesting(); | 2067 size_t afterGC2 = heap.objectPayloadSizeForTesting(); |
| 2068 EXPECT_EQ(afterGC2, afterAddAndGC); | 2068 EXPECT_EQ(afterGC2, afterAddAndGC); |
| 2069 | 2069 |
| 2070 IntWrapper* dozen = 0; | 2070 IntWrapper* dozen = 0; |
| 2071 | 2071 |
| 2072 for (int i = 1; i < 1000; i++) { // 999 iterations. | 2072 for (int i = 1; i < 1000; i++) { // 999 iterations. |
| 2073 IntWrapper* iWrapper(IntWrapper::create(i)); | 2073 IntWrapper* iWrapper(IntWrapper::create(i)); |
| 2074 IntWrapper* iSquared(IntWrapper::create(i * i)); | 2074 IntWrapper* iSquared(IntWrapper::create(i * i)); |
| 2075 map->add(iWrapper, iSquared); | 2075 map->insert(iWrapper, iSquared); |
| 2076 if (i == 12) | 2076 if (i == 12) |
| 2077 dozen = iWrapper; | 2077 dozen = iWrapper; |
| 2078 } | 2078 } |
| 2079 size_t afterAdding1000 = heap.objectPayloadSizeForTesting(); | 2079 size_t afterAdding1000 = heap.objectPayloadSizeForTesting(); |
| 2080 EXPECT_TRUE(afterAdding1000 > afterGC2); | 2080 EXPECT_TRUE(afterAdding1000 > afterGC2); |
| 2081 | 2081 |
| 2082 IntWrapper* gross(map->get(dozen)); | 2082 IntWrapper* gross(map->get(dozen)); |
| 2083 EXPECT_EQ(gross->value(), 144); | 2083 EXPECT_EQ(gross->value(), 144); |
| 2084 | 2084 |
| 2085 // This should clear out any junk backings created by all the adds. | 2085 // This should clear out any junk backings created by all the adds. |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2418 IntWrapper* fourD(IntWrapper::create(4)); | 2418 IntWrapper* fourD(IntWrapper::create(4)); |
| 2419 IntWrapper* fourE(IntWrapper::create(4)); | 2419 IntWrapper* fourE(IntWrapper::create(4)); |
| 2420 IntWrapper* fourF(IntWrapper::create(4)); | 2420 IntWrapper* fourF(IntWrapper::create(4)); |
| 2421 IntWrapper* four(IntWrapper::create(4)); | 2421 IntWrapper* four(IntWrapper::create(4)); |
| 2422 IntWrapper* fiveC(IntWrapper::create(5)); | 2422 IntWrapper* fiveC(IntWrapper::create(5)); |
| 2423 IntWrapper* fiveD(IntWrapper::create(5)); | 2423 IntWrapper* fiveD(IntWrapper::create(5)); |
| 2424 IntWrapper* fiveE(IntWrapper::create(5)); | 2424 IntWrapper* fiveE(IntWrapper::create(5)); |
| 2425 IntWrapper* fiveF(IntWrapper::create(5)); | 2425 IntWrapper* fiveF(IntWrapper::create(5)); |
| 2426 | 2426 |
| 2427 // Member Collections. | 2427 // Member Collections. |
| 2428 memberMember2->add(one, two); | 2428 memberMember2->insert(one, two); |
| 2429 memberMember2->add(two, three); | 2429 memberMember2->insert(two, three); |
| 2430 memberMember2->add(three, four); | 2430 memberMember2->insert(three, four); |
| 2431 memberMember2->add(four, one); | 2431 memberMember2->insert(four, one); |
| 2432 primitiveMember->add(1, two); | 2432 primitiveMember->insert(1, two); |
| 2433 primitiveMember->add(2, three); | 2433 primitiveMember->insert(2, three); |
| 2434 primitiveMember->add(3, four); | 2434 primitiveMember->insert(3, four); |
| 2435 primitiveMember->add(4, one); | 2435 primitiveMember->insert(4, one); |
| 2436 memberPrimitive->add(one, 2); | 2436 memberPrimitive->insert(one, 2); |
| 2437 memberPrimitive->add(two, 3); | 2437 memberPrimitive->insert(two, 3); |
| 2438 memberPrimitive->add(three, 4); | 2438 memberPrimitive->insert(three, 4); |
| 2439 memberPrimitive->add(four, 1); | 2439 memberPrimitive->insert(four, 1); |
| 2440 set2->add(one); | 2440 set2->add(one); |
| 2441 set2->add(two); | 2441 set2->add(two); |
| 2442 set2->add(three); | 2442 set2->add(three); |
| 2443 set2->add(four); | 2443 set2->add(four); |
| 2444 set->add(oneB); | 2444 set->add(oneB); |
| 2445 set3->add(oneB); | 2445 set3->add(oneB); |
| 2446 set3->add(oneB); | 2446 set3->add(oneB); |
| 2447 vector->push_back(oneB); | 2447 vector->push_back(oneB); |
| 2448 deque->append(oneB); | 2448 deque->append(oneB); |
| 2449 vector2->push_back(threeB); | 2449 vector2->push_back(threeB); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2901 | 2901 |
| 2902 private: | 2902 private: |
| 2903 HeapDeque<Member<IntWrapper>> m_deque; | 2903 HeapDeque<Member<IntWrapper>> m_deque; |
| 2904 HeapVector<Member<IntWrapper>> m_vector; | 2904 HeapVector<Member<IntWrapper>> m_vector; |
| 2905 }; | 2905 }; |
| 2906 | 2906 |
| 2907 TEST(HeapTest, HeapHashMapWithInlinedObject) { | 2907 TEST(HeapTest, HeapHashMapWithInlinedObject) { |
| 2908 HeapHashMap<int, NonTrivialObject> map; | 2908 HeapHashMap<int, NonTrivialObject> map; |
| 2909 for (int num = 1; num < 1000; num++) { | 2909 for (int num = 1; num < 1000; num++) { |
| 2910 NonTrivialObject object(num); | 2910 NonTrivialObject object(num); |
| 2911 map.add(num, object); | 2911 map.insert(num, object); |
| 2912 } | 2912 } |
| 2913 } | 2913 } |
| 2914 | 2914 |
| 2915 template <typename T> | 2915 template <typename T> |
| 2916 void MapIteratorCheck(T& it, const T& end, int expected) { | 2916 void MapIteratorCheck(T& it, const T& end, int expected) { |
| 2917 int found = 0; | 2917 int found = 0; |
| 2918 while (it != end) { | 2918 while (it != end) { |
| 2919 found++; | 2919 found++; |
| 2920 int key = it->key->value(); | 2920 int key = it->key->value(); |
| 2921 int value = it->value->value(); | 2921 int value = it->value->value(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2955 Persistent<WeakWeak> weakWeak = new WeakWeak(); | 2955 Persistent<WeakWeak> weakWeak = new WeakWeak(); |
| 2956 Persistent<WeakSet> weakSet = new WeakSet(); | 2956 Persistent<WeakSet> weakSet = new WeakSet(); |
| 2957 Persistent<WeakCountedSet> weakCountedSet = new WeakCountedSet(); | 2957 Persistent<WeakCountedSet> weakCountedSet = new WeakCountedSet(); |
| 2958 | 2958 |
| 2959 Persistent<IntWrapper> two = IntWrapper::create(2); | 2959 Persistent<IntWrapper> two = IntWrapper::create(2); |
| 2960 | 2960 |
| 2961 keepNumbersAlive.push_back(IntWrapper::create(103)); | 2961 keepNumbersAlive.push_back(IntWrapper::create(103)); |
| 2962 keepNumbersAlive.push_back(IntWrapper::create(10)); | 2962 keepNumbersAlive.push_back(IntWrapper::create(10)); |
| 2963 | 2963 |
| 2964 { | 2964 { |
| 2965 weakStrong->add(IntWrapper::create(1), two); | 2965 weakStrong->insert(IntWrapper::create(1), two); |
| 2966 strongWeak->add(two, IntWrapper::create(1)); | 2966 strongWeak->insert(two, IntWrapper::create(1)); |
| 2967 weakWeak->add(two, IntWrapper::create(42)); | 2967 weakWeak->insert(two, IntWrapper::create(42)); |
| 2968 weakWeak->add(IntWrapper::create(42), two); | 2968 weakWeak->insert(IntWrapper::create(42), two); |
| 2969 weakSet->add(IntWrapper::create(0)); | 2969 weakSet->add(IntWrapper::create(0)); |
| 2970 weakSet->add(two); | 2970 weakSet->add(two); |
| 2971 weakSet->add(keepNumbersAlive[0]); | 2971 weakSet->add(keepNumbersAlive[0]); |
| 2972 weakSet->add(keepNumbersAlive[1]); | 2972 weakSet->add(keepNumbersAlive[1]); |
| 2973 weakCountedSet->add(IntWrapper::create(0)); | 2973 weakCountedSet->add(IntWrapper::create(0)); |
| 2974 weakCountedSet->add(two); | 2974 weakCountedSet->add(two); |
| 2975 weakCountedSet->add(two); | 2975 weakCountedSet->add(two); |
| 2976 weakCountedSet->add(two); | 2976 weakCountedSet->add(two); |
| 2977 weakCountedSet->add(keepNumbersAlive[0]); | 2977 weakCountedSet->add(keepNumbersAlive[0]); |
| 2978 weakCountedSet->add(keepNumbersAlive[1]); | 2978 weakCountedSet->add(keepNumbersAlive[1]); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3159 | 3159 |
| 3160 int baseLine, refBaseLine; | 3160 int baseLine, refBaseLine; |
| 3161 | 3161 |
| 3162 { | 3162 { |
| 3163 Map stackMap; | 3163 Map stackMap; |
| 3164 RefMap stackRefMap; | 3164 RefMap stackRefMap; |
| 3165 | 3165 |
| 3166 preciselyCollectGarbage(); | 3166 preciselyCollectGarbage(); |
| 3167 preciselyCollectGarbage(); | 3167 preciselyCollectGarbage(); |
| 3168 | 3168 |
| 3169 stackMap.add(IntWrapper::create(42), ThingWithDestructor(1729)); | 3169 stackMap.insert(IntWrapper::create(42), ThingWithDestructor(1729)); |
| 3170 stackMap.add(luck, ThingWithDestructor(8128)); | 3170 stackMap.insert(luck, ThingWithDestructor(8128)); |
| 3171 stackRefMap.add(IntWrapper::create(42), | 3171 stackRefMap.insert(IntWrapper::create(42), |
| 3172 RefCountedAndGarbageCollected::create()); | 3172 RefCountedAndGarbageCollected::create()); |
| 3173 stackRefMap.add(luck, RefCountedAndGarbageCollected::create()); | 3173 stackRefMap.insert(luck, RefCountedAndGarbageCollected::create()); |
| 3174 | 3174 |
| 3175 baseLine = ThingWithDestructor::s_liveThingsWithDestructor; | 3175 baseLine = ThingWithDestructor::s_liveThingsWithDestructor; |
| 3176 refBaseLine = RefCountedAndGarbageCollected::s_destructorCalls; | 3176 refBaseLine = RefCountedAndGarbageCollected::s_destructorCalls; |
| 3177 | 3177 |
| 3178 // Although the heap maps are on-stack, we can't expect prompt | 3178 // Although the heap maps are on-stack, we can't expect prompt |
| 3179 // finalization of the elements, so when they go out of scope here we | 3179 // finalization of the elements, so when they go out of scope here we |
| 3180 // will not necessarily have called the relevant destructors. | 3180 // will not necessarily have called the relevant destructors. |
| 3181 } | 3181 } |
| 3182 | 3182 |
| 3183 // The RefCountedAndGarbageCollected things need an extra GC to discover | 3183 // The RefCountedAndGarbageCollected things need an extra GC to discover |
| 3184 // that they are no longer ref counted. | 3184 // that they are no longer ref counted. |
| 3185 preciselyCollectGarbage(); | 3185 preciselyCollectGarbage(); |
| 3186 preciselyCollectGarbage(); | 3186 preciselyCollectGarbage(); |
| 3187 EXPECT_EQ(baseLine - 2, ThingWithDestructor::s_liveThingsWithDestructor); | 3187 EXPECT_EQ(baseLine - 2, ThingWithDestructor::s_liveThingsWithDestructor); |
| 3188 EXPECT_EQ(refBaseLine + 2, RefCountedAndGarbageCollected::s_destructorCalls); | 3188 EXPECT_EQ(refBaseLine + 2, RefCountedAndGarbageCollected::s_destructorCalls); |
| 3189 | 3189 |
| 3190 // Now use maps kept alive with persistents. Here we don't expect any | 3190 // Now use maps kept alive with persistents. Here we don't expect any |
| 3191 // destructors to be called before there have been GCs. | 3191 // destructors to be called before there have been GCs. |
| 3192 | 3192 |
| 3193 map->add(IntWrapper::create(42), ThingWithDestructor(1729)); | 3193 map->insert(IntWrapper::create(42), ThingWithDestructor(1729)); |
| 3194 map->add(luck, ThingWithDestructor(8128)); | 3194 map->insert(luck, ThingWithDestructor(8128)); |
| 3195 refMap->add(IntWrapper::create(42), RefCountedAndGarbageCollected::create()); | 3195 refMap->insert(IntWrapper::create(42), |
| 3196 refMap->add(luck, RefCountedAndGarbageCollected::create()); | 3196 RefCountedAndGarbageCollected::create()); |
| 3197 refMap->insert(luck, RefCountedAndGarbageCollected::create()); |
| 3197 | 3198 |
| 3198 baseLine = ThingWithDestructor::s_liveThingsWithDestructor; | 3199 baseLine = ThingWithDestructor::s_liveThingsWithDestructor; |
| 3199 refBaseLine = RefCountedAndGarbageCollected::s_destructorCalls; | 3200 refBaseLine = RefCountedAndGarbageCollected::s_destructorCalls; |
| 3200 | 3201 |
| 3201 luck.clear(); | 3202 luck.clear(); |
| 3202 if (clearMaps) { | 3203 if (clearMaps) { |
| 3203 map->clear(); // Clear map. | 3204 map->clear(); // Clear map. |
| 3204 refMap->clear(); // Clear map. | 3205 refMap->clear(); // Clear map. |
| 3205 } else { | 3206 } else { |
| 3206 map.clear(); // Clear Persistent handle, not map. | 3207 map.clear(); // Clear Persistent handle, not map. |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3400 | 3401 |
| 3401 Persistent<WeakSet> weakSet = new WeakSet(); | 3402 Persistent<WeakSet> weakSet = new WeakSet(); |
| 3402 Persistent<WeakOrderedSet> weakOrderedSet = new WeakOrderedSet(); | 3403 Persistent<WeakOrderedSet> weakOrderedSet = new WeakOrderedSet(); |
| 3403 | 3404 |
| 3404 PersistentHeapVector<Member<IntWrapper>> keepNumbersAlive; | 3405 PersistentHeapVector<Member<IntWrapper>> keepNumbersAlive; |
| 3405 for (int i = 0; i < 128; i += 2) { | 3406 for (int i = 0; i < 128; i += 2) { |
| 3406 IntWrapper* wrapped = IntWrapper::create(i); | 3407 IntWrapper* wrapped = IntWrapper::create(i); |
| 3407 IntWrapper* wrapped2 = IntWrapper::create(i + 1); | 3408 IntWrapper* wrapped2 = IntWrapper::create(i + 1); |
| 3408 keepNumbersAlive.push_back(wrapped); | 3409 keepNumbersAlive.push_back(wrapped); |
| 3409 keepNumbersAlive.push_back(wrapped2); | 3410 keepNumbersAlive.push_back(wrapped2); |
| 3410 weakStrong->add(wrapped, wrapped2); | 3411 weakStrong->insert(wrapped, wrapped2); |
| 3411 strongWeak->add(wrapped2, wrapped); | 3412 strongWeak->insert(wrapped2, wrapped); |
| 3412 weakWeak->add(wrapped, wrapped2); | 3413 weakWeak->insert(wrapped, wrapped2); |
| 3413 weakSet->add(wrapped); | 3414 weakSet->add(wrapped); |
| 3414 weakOrderedSet->add(wrapped); | 3415 weakOrderedSet->add(wrapped); |
| 3415 } | 3416 } |
| 3416 | 3417 |
| 3417 EXPECT_EQ(64u, weakStrong->size()); | 3418 EXPECT_EQ(64u, weakStrong->size()); |
| 3418 EXPECT_EQ(64u, strongWeak->size()); | 3419 EXPECT_EQ(64u, strongWeak->size()); |
| 3419 EXPECT_EQ(64u, weakWeak->size()); | 3420 EXPECT_EQ(64u, weakWeak->size()); |
| 3420 EXPECT_EQ(64u, weakSet->size()); | 3421 EXPECT_EQ(64u, weakSet->size()); |
| 3421 EXPECT_EQ(64u, weakOrderedSet->size()); | 3422 EXPECT_EQ(64u, weakOrderedSet->size()); |
| 3422 | 3423 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3517 if (deleteAfterwards) | 3518 if (deleteAfterwards) |
| 3518 weakOrderedSet->remove(keepNumbersAlive[i]); | 3519 weakOrderedSet->remove(keepNumbersAlive[i]); |
| 3519 else | 3520 else |
| 3520 count++; | 3521 count++; |
| 3521 } | 3522 } |
| 3522 } | 3523 } |
| 3523 if (addAfterwards) { | 3524 if (addAfterwards) { |
| 3524 for (int i = 1000; i < 1100; i++) { | 3525 for (int i = 1000; i < 1100; i++) { |
| 3525 IntWrapper* wrapped = IntWrapper::create(i); | 3526 IntWrapper* wrapped = IntWrapper::create(i); |
| 3526 keepNumbersAlive.push_back(wrapped); | 3527 keepNumbersAlive.push_back(wrapped); |
| 3527 weakStrong->add(wrapped, wrapped); | 3528 weakStrong->insert(wrapped, wrapped); |
| 3528 strongWeak->add(wrapped, wrapped); | 3529 strongWeak->insert(wrapped, wrapped); |
| 3529 weakWeak->add(wrapped, wrapped); | 3530 weakWeak->insert(wrapped, wrapped); |
| 3530 weakSet->add(wrapped); | 3531 weakSet->add(wrapped); |
| 3531 weakOrderedSet->add(wrapped); | 3532 weakOrderedSet->add(wrapped); |
| 3532 } | 3533 } |
| 3533 } | 3534 } |
| 3534 if (collectionNumber == weakStrongIndex) | 3535 if (collectionNumber == weakStrongIndex) |
| 3535 EXPECT_EQ(count + added, weakStrong->size()); | 3536 EXPECT_EQ(count + added, weakStrong->size()); |
| 3536 else if (collectionNumber == strongWeakIndex) | 3537 else if (collectionNumber == strongWeakIndex) |
| 3537 EXPECT_EQ(count + added, strongWeak->size()); | 3538 EXPECT_EQ(count + added, strongWeak->size()); |
| 3538 else if (collectionNumber == weakWeakIndex) | 3539 else if (collectionNumber == weakWeakIndex) |
| 3539 EXPECT_EQ(count + added, weakWeak->size()); | 3540 EXPECT_EQ(count + added, weakWeak->size()); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3882 | 3883 |
| 3883 Vec* vec = new Vec(); | 3884 Vec* vec = new Vec(); |
| 3884 vec->swap(pVec); | 3885 vec->swap(pVec); |
| 3885 | 3886 |
| 3886 pVec.push_back(two); | 3887 pVec.push_back(two); |
| 3887 pVec.push_back(three); | 3888 pVec.push_back(three); |
| 3888 | 3889 |
| 3889 pSet.add(four); | 3890 pSet.add(four); |
| 3890 pListSet.add(eight); | 3891 pListSet.add(eight); |
| 3891 pLinkedSet.add(nine); | 3892 pLinkedSet.add(nine); |
| 3892 pMap.add(five, six); | 3893 pMap.insert(five, six); |
| 3893 wpMap.add(ten, eleven); | 3894 wpMap.insert(ten, eleven); |
| 3894 | 3895 |
| 3895 // Collect |vec| and |one|. | 3896 // Collect |vec| and |one|. |
| 3896 vec = 0; | 3897 vec = 0; |
| 3897 preciselyCollectGarbage(); | 3898 preciselyCollectGarbage(); |
| 3898 EXPECT_EQ(1, IntWrapper::s_destructorCalls); | 3899 EXPECT_EQ(1, IntWrapper::s_destructorCalls); |
| 3899 | 3900 |
| 3900 EXPECT_EQ(2u, pVec.size()); | 3901 EXPECT_EQ(2u, pVec.size()); |
| 3901 EXPECT_EQ(two, pVec.at(0)); | 3902 EXPECT_EQ(two, pVec.at(0)); |
| 3902 EXPECT_EQ(three, pVec.at(1)); | 3903 EXPECT_EQ(three, pVec.at(1)); |
| 3903 | 3904 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3938 IntWrapper::s_destructorCalls = 0; | 3939 IntWrapper::s_destructorCalls = 0; |
| 3939 typedef HeapVector<Member<IntWrapper>> IntVector; | 3940 typedef HeapVector<Member<IntWrapper>> IntVector; |
| 3940 typedef HeapDeque<Member<IntWrapper>> IntDeque; | 3941 typedef HeapDeque<Member<IntWrapper>> IntDeque; |
| 3941 HeapHashMap<void*, IntVector>* map = new HeapHashMap<void*, IntVector>(); | 3942 HeapHashMap<void*, IntVector>* map = new HeapHashMap<void*, IntVector>(); |
| 3942 HeapHashMap<void*, IntDeque>* map2 = new HeapHashMap<void*, IntDeque>(); | 3943 HeapHashMap<void*, IntDeque>* map2 = new HeapHashMap<void*, IntDeque>(); |
| 3943 static_assert(WTF::IsTraceable<IntVector>::value, | 3944 static_assert(WTF::IsTraceable<IntVector>::value, |
| 3944 "Failed to recognize HeapVector as traceable"); | 3945 "Failed to recognize HeapVector as traceable"); |
| 3945 static_assert(WTF::IsTraceable<IntDeque>::value, | 3946 static_assert(WTF::IsTraceable<IntDeque>::value, |
| 3946 "Failed to recognize HeapDeque as traceable"); | 3947 "Failed to recognize HeapDeque as traceable"); |
| 3947 | 3948 |
| 3948 map->add(key, IntVector()); | 3949 map->insert(key, IntVector()); |
| 3949 map2->add(key, IntDeque()); | 3950 map2->insert(key, IntDeque()); |
| 3950 | 3951 |
| 3951 HeapHashMap<void*, IntVector>::iterator it = map->find(key); | 3952 HeapHashMap<void*, IntVector>::iterator it = map->find(key); |
| 3952 EXPECT_EQ(0u, map->get(key).size()); | 3953 EXPECT_EQ(0u, map->get(key).size()); |
| 3953 | 3954 |
| 3954 HeapHashMap<void*, IntDeque>::iterator it2 = map2->find(key); | 3955 HeapHashMap<void*, IntDeque>::iterator it2 = map2->find(key); |
| 3955 EXPECT_EQ(0u, map2->get(key).size()); | 3956 EXPECT_EQ(0u, map2->get(key).size()); |
| 3956 | 3957 |
| 3957 it->value.push_back(IntWrapper::create(42)); | 3958 it->value.push_back(IntWrapper::create(42)); |
| 3958 EXPECT_EQ(1u, map->get(key).size()); | 3959 EXPECT_EQ(1u, map->get(key).size()); |
| 3959 | 3960 |
| 3960 it2->value.append(IntWrapper::create(42)); | 3961 it2->value.append(IntWrapper::create(42)); |
| 3961 EXPECT_EQ(1u, map2->get(key).size()); | 3962 EXPECT_EQ(1u, map2->get(key).size()); |
| 3962 | 3963 |
| 3963 Persistent<HeapHashMap<void*, IntVector>> keepAlive(map); | 3964 Persistent<HeapHashMap<void*, IntVector>> keepAlive(map); |
| 3964 Persistent<HeapHashMap<void*, IntDeque>> keepAlive2(map2); | 3965 Persistent<HeapHashMap<void*, IntDeque>> keepAlive2(map2); |
| 3965 | 3966 |
| 3966 for (int i = 0; i < 100; i++) { | 3967 for (int i = 0; i < 100; i++) { |
| 3967 map->add(key + 1 + i, IntVector()); | 3968 map->insert(key + 1 + i, IntVector()); |
| 3968 map2->add(key + 1 + i, IntDeque()); | 3969 map2->insert(key + 1 + i, IntDeque()); |
| 3969 } | 3970 } |
| 3970 | 3971 |
| 3971 preciselyCollectGarbage(); | 3972 preciselyCollectGarbage(); |
| 3972 | 3973 |
| 3973 EXPECT_EQ(1u, map->get(key).size()); | 3974 EXPECT_EQ(1u, map->get(key).size()); |
| 3974 EXPECT_EQ(1u, map2->get(key).size()); | 3975 EXPECT_EQ(1u, map2->get(key).size()); |
| 3975 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 3976 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
| 3976 | 3977 |
| 3977 keepAlive = nullptr; | 3978 keepAlive = nullptr; |
| 3978 preciselyCollectGarbage(); | 3979 preciselyCollectGarbage(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3998 EXPECT_EQ(0u, weakMap.size()); | 3999 EXPECT_EQ(0u, weakMap.size()); |
| 3999 } | 4000 } |
| 4000 | 4001 |
| 4001 TEST(HeapTest, CollectionNesting2) { | 4002 TEST(HeapTest, CollectionNesting2) { |
| 4002 clearOutOldGarbage(); | 4003 clearOutOldGarbage(); |
| 4003 void* key = &IntWrapper::s_destructorCalls; | 4004 void* key = &IntWrapper::s_destructorCalls; |
| 4004 IntWrapper::s_destructorCalls = 0; | 4005 IntWrapper::s_destructorCalls = 0; |
| 4005 typedef HeapHashSet<Member<IntWrapper>> IntSet; | 4006 typedef HeapHashSet<Member<IntWrapper>> IntSet; |
| 4006 HeapHashMap<void*, IntSet>* map = new HeapHashMap<void*, IntSet>(); | 4007 HeapHashMap<void*, IntSet>* map = new HeapHashMap<void*, IntSet>(); |
| 4007 | 4008 |
| 4008 map->add(key, IntSet()); | 4009 map->insert(key, IntSet()); |
| 4009 | 4010 |
| 4010 HeapHashMap<void*, IntSet>::iterator it = map->find(key); | 4011 HeapHashMap<void*, IntSet>::iterator it = map->find(key); |
| 4011 EXPECT_EQ(0u, map->get(key).size()); | 4012 EXPECT_EQ(0u, map->get(key).size()); |
| 4012 | 4013 |
| 4013 it->value.add(IntWrapper::create(42)); | 4014 it->value.add(IntWrapper::create(42)); |
| 4014 EXPECT_EQ(1u, map->get(key).size()); | 4015 EXPECT_EQ(1u, map->get(key).size()); |
| 4015 | 4016 |
| 4016 Persistent<HeapHashMap<void*, IntSet>> keepAlive(map); | 4017 Persistent<HeapHashMap<void*, IntSet>> keepAlive(map); |
| 4017 preciselyCollectGarbage(); | 4018 preciselyCollectGarbage(); |
| 4018 EXPECT_EQ(1u, map->get(key).size()); | 4019 EXPECT_EQ(1u, map->get(key).size()); |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4484 | 4485 |
| 4485 EXPECT_FALSE(RefCountedWithDestructor::s_wasDestructed); | 4486 EXPECT_FALSE(RefCountedWithDestructor::s_wasDestructed); |
| 4486 set.clear(); | 4487 set.clear(); |
| 4487 EXPECT_TRUE(RefCountedWithDestructor::s_wasDestructed); | 4488 EXPECT_TRUE(RefCountedWithDestructor::s_wasDestructed); |
| 4488 } | 4489 } |
| 4489 | 4490 |
| 4490 TEST(HeapTest, DestructorsCalled) { | 4491 TEST(HeapTest, DestructorsCalled) { |
| 4491 HeapHashMap<Member<IntWrapper>, std::unique_ptr<SimpleClassWithDestructor>> | 4492 HeapHashMap<Member<IntWrapper>, std::unique_ptr<SimpleClassWithDestructor>> |
| 4492 map; | 4493 map; |
| 4493 SimpleClassWithDestructor* hasDestructor = new SimpleClassWithDestructor(); | 4494 SimpleClassWithDestructor* hasDestructor = new SimpleClassWithDestructor(); |
| 4494 map.add(IntWrapper::create(1), WTF::wrapUnique(hasDestructor)); | 4495 map.insert(IntWrapper::create(1), WTF::wrapUnique(hasDestructor)); |
| 4495 SimpleClassWithDestructor::s_wasDestructed = false; | 4496 SimpleClassWithDestructor::s_wasDestructed = false; |
| 4496 map.clear(); | 4497 map.clear(); |
| 4497 EXPECT_TRUE(SimpleClassWithDestructor::s_wasDestructed); | 4498 EXPECT_TRUE(SimpleClassWithDestructor::s_wasDestructed); |
| 4498 } | 4499 } |
| 4499 | 4500 |
| 4500 class MixinA : public GarbageCollectedMixin { | 4501 class MixinA : public GarbageCollectedMixin { |
| 4501 public: | 4502 public: |
| 4502 MixinA() : m_obj(IntWrapper::create(100)) {} | 4503 MixinA() : m_obj(IntWrapper::create(100)) {} |
| 4503 DEFINE_INLINE_VIRTUAL_TRACE() { | 4504 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 4504 s_traceCount++; | 4505 s_traceCount++; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4714 typedef HeapHashMap<PairWithWeakHandling, RefPtr<OffHeapInt>> Map; | 4715 typedef HeapHashMap<PairWithWeakHandling, RefPtr<OffHeapInt>> Map; |
| 4715 typedef Map::iterator Iterator; | 4716 typedef Map::iterator Iterator; |
| 4716 clearOutOldGarbage(); | 4717 clearOutOldGarbage(); |
| 4717 OffHeapInt::s_destructorCalls = 0; | 4718 OffHeapInt::s_destructorCalls = 0; |
| 4718 | 4719 |
| 4719 Persistent<Map> map1(new Map()); | 4720 Persistent<Map> map1(new Map()); |
| 4720 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); | 4721 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); |
| 4721 { | 4722 { |
| 4722 Map map2; | 4723 Map map2; |
| 4723 Map* map3 = new Map(); | 4724 Map* map3 = new Map(); |
| 4724 map2.add(PairWithWeakHandling(IntWrapper::create(0), IntWrapper::create(1)), | 4725 map2.insert( |
| 4725 OffHeapInt::create(1001)); | 4726 PairWithWeakHandling(IntWrapper::create(0), IntWrapper::create(1)), |
| 4726 map3->add( | 4727 OffHeapInt::create(1001)); |
| 4728 map3->insert( |
| 4727 PairWithWeakHandling(IntWrapper::create(2), IntWrapper::create(3)), | 4729 PairWithWeakHandling(IntWrapper::create(2), IntWrapper::create(3)), |
| 4728 OffHeapInt::create(1002)); | 4730 OffHeapInt::create(1002)); |
| 4729 map1->add( | 4731 map1->insert( |
| 4730 PairWithWeakHandling(IntWrapper::create(4), IntWrapper::create(5)), | 4732 PairWithWeakHandling(IntWrapper::create(4), IntWrapper::create(5)), |
| 4731 OffHeapInt::create(1003)); | 4733 OffHeapInt::create(1003)); |
| 4732 EXPECT_EQ(0, OffHeapInt::s_destructorCalls); | 4734 EXPECT_EQ(0, OffHeapInt::s_destructorCalls); |
| 4733 | 4735 |
| 4734 conservativelyCollectGarbage(); | 4736 conservativelyCollectGarbage(); |
| 4735 // The first map2 is pointed to from a persistent, so it's referenced, but | 4737 // The first map2 is pointed to from a persistent, so it's referenced, but |
| 4736 // the weak processing may have taken place. | 4738 // the weak processing may have taken place. |
| 4737 if (map1->size()) { | 4739 if (map1->size()) { |
| 4738 Iterator i1 = map1->begin(); | 4740 Iterator i1 = map1->begin(); |
| 4739 EXPECT_EQ(4, i1->key.first->value()); | 4741 EXPECT_EQ(4, i1->key.first->value()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4755 EXPECT_EQ(1002, i3->value->value()); | 4757 EXPECT_EQ(1002, i3->value->value()); |
| 4756 } | 4758 } |
| 4757 } | 4759 } |
| 4758 preciselyCollectGarbage(); | 4760 preciselyCollectGarbage(); |
| 4759 | 4761 |
| 4760 EXPECT_EQ(0u, map1->size()); | 4762 EXPECT_EQ(0u, map1->size()); |
| 4761 EXPECT_EQ(3, OffHeapInt::s_destructorCalls); | 4763 EXPECT_EQ(3, OffHeapInt::s_destructorCalls); |
| 4762 | 4764 |
| 4763 OffHeapInt::s_destructorCalls = 0; | 4765 OffHeapInt::s_destructorCalls = 0; |
| 4764 | 4766 |
| 4765 map1->add(PairWithWeakHandling(IntWrapper::create(103), livingInt), | 4767 map1->insert(PairWithWeakHandling(IntWrapper::create(103), livingInt), |
| 4766 OffHeapInt::create(2000)); | 4768 OffHeapInt::create(2000)); |
| 4767 map1->add(PairWithWeakHandling(livingInt, IntWrapper::create(103)), | 4769 map1->insert(PairWithWeakHandling(livingInt, IntWrapper::create(103)), |
| 4768 OffHeapInt::create(2001)); // This one gets zapped at GC time | 4770 OffHeapInt::create(2001)); // This one gets zapped at GC time |
| 4769 // because nothing holds the 103 alive. | 4771 // because nothing holds the 103 alive. |
| 4770 map1->add( | 4772 map1->insert( |
| 4771 PairWithWeakHandling(IntWrapper::create(103), IntWrapper::create(103)), | 4773 PairWithWeakHandling(IntWrapper::create(103), IntWrapper::create(103)), |
| 4772 OffHeapInt::create(2002)); // This one gets zapped too. | 4774 OffHeapInt::create(2002)); // This one gets zapped too. |
| 4773 RefPtr<OffHeapInt> dupeInt(OffHeapInt::create(2003)); | 4775 RefPtr<OffHeapInt> dupeInt(OffHeapInt::create(2003)); |
| 4774 map1->add(PairWithWeakHandling(livingInt, livingInt), dupeInt); | 4776 map1->insert(PairWithWeakHandling(livingInt, livingInt), dupeInt); |
| 4775 map1->add(PairWithWeakHandling(livingInt, livingInt), | 4777 map1->insert( |
| 4776 dupeInt); // This one is identical to the previous and doesn't add | 4778 PairWithWeakHandling(livingInt, livingInt), |
| 4777 // anything. | 4779 dupeInt); // This one is identical to the previous and doesn't add |
| 4780 // anything. |
| 4778 dupeInt.clear(); | 4781 dupeInt.clear(); |
| 4779 | 4782 |
| 4780 EXPECT_EQ(0, OffHeapInt::s_destructorCalls); | 4783 EXPECT_EQ(0, OffHeapInt::s_destructorCalls); |
| 4781 EXPECT_EQ(4u, map1->size()); | 4784 EXPECT_EQ(4u, map1->size()); |
| 4782 preciselyCollectGarbage(); | 4785 preciselyCollectGarbage(); |
| 4783 EXPECT_EQ(2, OffHeapInt::s_destructorCalls); | 4786 EXPECT_EQ(2, OffHeapInt::s_destructorCalls); |
| 4784 EXPECT_EQ(2u, map1->size()); | 4787 EXPECT_EQ(2u, map1->size()); |
| 4785 Iterator i1 = map1->begin(); | 4788 Iterator i1 = map1->begin(); |
| 4786 EXPECT_TRUE(i1->key.first->value() == 103 || i1->key.first == livingInt); | 4789 EXPECT_TRUE(i1->key.first->value() == 103 || i1->key.first == livingInt); |
| 4787 EXPECT_EQ(livingInt, i1->key.second); | 4790 EXPECT_EQ(livingInt, i1->key.second); |
| 4788 ++i1; | 4791 ++i1; |
| 4789 EXPECT_TRUE(i1->key.first->value() == 103 || i1->key.first == livingInt); | 4792 EXPECT_TRUE(i1->key.first->value() == 103 || i1->key.first == livingInt); |
| 4790 EXPECT_EQ(livingInt, i1->key.second); | 4793 EXPECT_EQ(livingInt, i1->key.second); |
| 4791 } | 4794 } |
| 4792 | 4795 |
| 4793 TEST(HeapTest, MapWithCustomWeaknessHandling2) { | 4796 TEST(HeapTest, MapWithCustomWeaknessHandling2) { |
| 4794 typedef HeapHashMap<RefPtr<OffHeapInt>, PairWithWeakHandling> Map; | 4797 typedef HeapHashMap<RefPtr<OffHeapInt>, PairWithWeakHandling> Map; |
| 4795 typedef Map::iterator Iterator; | 4798 typedef Map::iterator Iterator; |
| 4796 clearOutOldGarbage(); | 4799 clearOutOldGarbage(); |
| 4797 OffHeapInt::s_destructorCalls = 0; | 4800 OffHeapInt::s_destructorCalls = 0; |
| 4798 | 4801 |
| 4799 Persistent<Map> map1(new Map()); | 4802 Persistent<Map> map1(new Map()); |
| 4800 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); | 4803 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); |
| 4801 | 4804 |
| 4802 { | 4805 { |
| 4803 Map map2; | 4806 Map map2; |
| 4804 Map* map3 = new Map(); | 4807 Map* map3 = new Map(); |
| 4805 map2.add( | 4808 map2.insert( |
| 4806 OffHeapInt::create(1001), | 4809 OffHeapInt::create(1001), |
| 4807 PairWithWeakHandling(IntWrapper::create(0), IntWrapper::create(1))); | 4810 PairWithWeakHandling(IntWrapper::create(0), IntWrapper::create(1))); |
| 4808 map3->add( | 4811 map3->insert( |
| 4809 OffHeapInt::create(1002), | 4812 OffHeapInt::create(1002), |
| 4810 PairWithWeakHandling(IntWrapper::create(2), IntWrapper::create(3))); | 4813 PairWithWeakHandling(IntWrapper::create(2), IntWrapper::create(3))); |
| 4811 map1->add( | 4814 map1->insert( |
| 4812 OffHeapInt::create(1003), | 4815 OffHeapInt::create(1003), |
| 4813 PairWithWeakHandling(IntWrapper::create(4), IntWrapper::create(5))); | 4816 PairWithWeakHandling(IntWrapper::create(4), IntWrapper::create(5))); |
| 4814 EXPECT_EQ(0, OffHeapInt::s_destructorCalls); | 4817 EXPECT_EQ(0, OffHeapInt::s_destructorCalls); |
| 4815 | 4818 |
| 4816 conservativelyCollectGarbage(); | 4819 conservativelyCollectGarbage(); |
| 4817 // The first map2 is pointed to from a persistent, so it's referenced, but | 4820 // The first map2 is pointed to from a persistent, so it's referenced, but |
| 4818 // the weak processing may have taken place. | 4821 // the weak processing may have taken place. |
| 4819 if (map1->size()) { | 4822 if (map1->size()) { |
| 4820 Iterator i1 = map1->begin(); | 4823 Iterator i1 = map1->begin(); |
| 4821 EXPECT_EQ(4, i1->value.first->value()); | 4824 EXPECT_EQ(4, i1->value.first->value()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4837 EXPECT_EQ(1002, i3->key->value()); | 4840 EXPECT_EQ(1002, i3->key->value()); |
| 4838 } | 4841 } |
| 4839 } | 4842 } |
| 4840 preciselyCollectGarbage(); | 4843 preciselyCollectGarbage(); |
| 4841 | 4844 |
| 4842 EXPECT_EQ(0u, map1->size()); | 4845 EXPECT_EQ(0u, map1->size()); |
| 4843 EXPECT_EQ(3, OffHeapInt::s_destructorCalls); | 4846 EXPECT_EQ(3, OffHeapInt::s_destructorCalls); |
| 4844 | 4847 |
| 4845 OffHeapInt::s_destructorCalls = 0; | 4848 OffHeapInt::s_destructorCalls = 0; |
| 4846 | 4849 |
| 4847 map1->add(OffHeapInt::create(2000), | 4850 map1->insert(OffHeapInt::create(2000), |
| 4848 PairWithWeakHandling(IntWrapper::create(103), livingInt)); | 4851 PairWithWeakHandling(IntWrapper::create(103), livingInt)); |
| 4849 // This one gets zapped at GC time because nothing holds the 103 alive. | 4852 // This one gets zapped at GC time because nothing holds the 103 alive. |
| 4850 map1->add(OffHeapInt::create(2001), | 4853 map1->insert(OffHeapInt::create(2001), |
| 4851 PairWithWeakHandling(livingInt, IntWrapper::create(103))); | 4854 PairWithWeakHandling(livingInt, IntWrapper::create(103))); |
| 4852 map1->add(OffHeapInt::create(2002), | 4855 map1->insert(OffHeapInt::create(2002), |
| 4853 PairWithWeakHandling( | 4856 PairWithWeakHandling( |
| 4854 IntWrapper::create(103), | 4857 IntWrapper::create(103), |
| 4855 IntWrapper::create(103))); // This one gets zapped too. | 4858 IntWrapper::create(103))); // This one gets zapped too. |
| 4856 RefPtr<OffHeapInt> dupeInt(OffHeapInt::create(2003)); | 4859 RefPtr<OffHeapInt> dupeInt(OffHeapInt::create(2003)); |
| 4857 map1->add(dupeInt, PairWithWeakHandling(livingInt, livingInt)); | 4860 map1->insert(dupeInt, PairWithWeakHandling(livingInt, livingInt)); |
| 4858 // This one is identical to the previous and doesn't add anything. | 4861 // This one is identical to the previous and doesn't add anything. |
| 4859 map1->add(dupeInt, PairWithWeakHandling(livingInt, livingInt)); | 4862 map1->insert(dupeInt, PairWithWeakHandling(livingInt, livingInt)); |
| 4860 dupeInt.clear(); | 4863 dupeInt.clear(); |
| 4861 | 4864 |
| 4862 EXPECT_EQ(0, OffHeapInt::s_destructorCalls); | 4865 EXPECT_EQ(0, OffHeapInt::s_destructorCalls); |
| 4863 EXPECT_EQ(4u, map1->size()); | 4866 EXPECT_EQ(4u, map1->size()); |
| 4864 preciselyCollectGarbage(); | 4867 preciselyCollectGarbage(); |
| 4865 EXPECT_EQ(2, OffHeapInt::s_destructorCalls); | 4868 EXPECT_EQ(2, OffHeapInt::s_destructorCalls); |
| 4866 EXPECT_EQ(2u, map1->size()); | 4869 EXPECT_EQ(2u, map1->size()); |
| 4867 Iterator i1 = map1->begin(); | 4870 Iterator i1 = map1->begin(); |
| 4868 EXPECT_TRUE(i1->value.first->value() == 103 || i1->value.first == livingInt); | 4871 EXPECT_TRUE(i1->value.first->value() == 103 || i1->value.first == livingInt); |
| 4869 EXPECT_EQ(livingInt, i1->value.second); | 4872 EXPECT_EQ(livingInt, i1->value.second); |
| 4870 ++i1; | 4873 ++i1; |
| 4871 EXPECT_TRUE(i1->value.first->value() == 103 || i1->value.first == livingInt); | 4874 EXPECT_TRUE(i1->value.first->value() == 103 || i1->value.first == livingInt); |
| 4872 EXPECT_EQ(livingInt, i1->value.second); | 4875 EXPECT_EQ(livingInt, i1->value.second); |
| 4873 } | 4876 } |
| 4874 | 4877 |
| 4875 static void addElementsToWeakMap( | 4878 static void addElementsToWeakMap( |
| 4876 HeapHashMap<int, WeakMember<IntWrapper>>* map) { | 4879 HeapHashMap<int, WeakMember<IntWrapper>>* map) { |
| 4877 // Key cannot be zero in hashmap. | 4880 // Key cannot be zero in hashmap. |
| 4878 for (int i = 1; i < 11; i++) | 4881 for (int i = 1; i < 11; i++) |
| 4879 map->add(i, IntWrapper::create(i)); | 4882 map->insert(i, IntWrapper::create(i)); |
| 4880 } | 4883 } |
| 4881 | 4884 |
| 4882 // crbug.com/402426 | 4885 // crbug.com/402426 |
| 4883 // If it doesn't assert a concurrent modification to the map, then it's passing. | 4886 // If it doesn't assert a concurrent modification to the map, then it's passing. |
| 4884 TEST(HeapTest, RegressNullIsStrongified) { | 4887 TEST(HeapTest, RegressNullIsStrongified) { |
| 4885 Persistent<HeapHashMap<int, WeakMember<IntWrapper>>> map = | 4888 Persistent<HeapHashMap<int, WeakMember<IntWrapper>>> map = |
| 4886 new HeapHashMap<int, WeakMember<IntWrapper>>(); | 4889 new HeapHashMap<int, WeakMember<IntWrapper>>(); |
| 4887 addElementsToWeakMap(map); | 4890 addElementsToWeakMap(map); |
| 4888 HeapHashMap<int, WeakMember<IntWrapper>>::AddResult result = | 4891 HeapHashMap<int, WeakMember<IntWrapper>>::AddResult result = |
| 4889 map->add(800, nullptr); | 4892 map->insert(800, nullptr); |
| 4890 conservativelyCollectGarbage(); | 4893 conservativelyCollectGarbage(); |
| 4891 result.storedValue->value = IntWrapper::create(42); | 4894 result.storedValue->value = IntWrapper::create(42); |
| 4892 } | 4895 } |
| 4893 | 4896 |
| 4894 TEST(HeapTest, Bind) { | 4897 TEST(HeapTest, Bind) { |
| 4895 std::unique_ptr<WTF::Closure> closure = | 4898 std::unique_ptr<WTF::Closure> closure = |
| 4896 WTF::bind(static_cast<void (Bar::*)(Visitor*)>(&Bar::trace), | 4899 WTF::bind(static_cast<void (Bar::*)(Visitor*)>(&Bar::trace), |
| 4897 wrapPersistent(Bar::create()), nullptr); | 4900 wrapPersistent(Bar::create()), nullptr); |
| 4898 // OffHeapInt* should not make Persistent. | 4901 // OffHeapInt* should not make Persistent. |
| 4899 std::unique_ptr<WTF::Closure> closure2 = | 4902 std::unique_ptr<WTF::Closure> closure2 = |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4956 clearOutOldGarbage(); | 4959 clearOutOldGarbage(); |
| 4957 OffHeapInt::s_destructorCalls = 0; | 4960 OffHeapInt::s_destructorCalls = 0; |
| 4958 | 4961 |
| 4959 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); | 4962 Persistent<IntWrapper> livingInt(IntWrapper::create(42)); |
| 4960 | 4963 |
| 4961 typedef RefPtr<OffHeapInt> Key; | 4964 typedef RefPtr<OffHeapInt> Key; |
| 4962 typedef HeapHashMap<Key, WeakSet, WTF::DefaultHash<Key>::Hash, | 4965 typedef HeapHashMap<Key, WeakSet, WTF::DefaultHash<Key>::Hash, |
| 4963 HashTraits<Key>, EmptyClearingHashSetTraits> | 4966 HashTraits<Key>, EmptyClearingHashSetTraits> |
| 4964 Map; | 4967 Map; |
| 4965 Persistent<Map> map(new Map()); | 4968 Persistent<Map> map(new Map()); |
| 4966 map->add(OffHeapInt::create(1), WeakSet()); | 4969 map->insert(OffHeapInt::create(1), WeakSet()); |
| 4967 { | 4970 { |
| 4968 WeakSet& set = map->begin()->value; | 4971 WeakSet& set = map->begin()->value; |
| 4969 set.add(IntWrapper::create(103)); // Weak set can't hold this long. | 4972 set.add(IntWrapper::create(103)); // Weak set can't hold this long. |
| 4970 set.add(livingInt); // This prevents the set from being emptied. | 4973 set.add(livingInt); // This prevents the set from being emptied. |
| 4971 EXPECT_EQ(2u, set.size()); | 4974 EXPECT_EQ(2u, set.size()); |
| 4972 } | 4975 } |
| 4973 | 4976 |
| 4974 // The set we add here is empty, so the entry will be removed from the map | 4977 // The set we add here is empty, so the entry will be removed from the map |
| 4975 // at the next GC. | 4978 // at the next GC. |
| 4976 map->add(OffHeapInt::create(2), WeakSet()); | 4979 map->insert(OffHeapInt::create(2), WeakSet()); |
| 4977 EXPECT_EQ(2u, map->size()); | 4980 EXPECT_EQ(2u, map->size()); |
| 4978 | 4981 |
| 4979 preciselyCollectGarbage(); | 4982 preciselyCollectGarbage(); |
| 4980 EXPECT_EQ(1u, map->size()); // The one with key 2 was removed. | 4983 EXPECT_EQ(1u, map->size()); // The one with key 2 was removed. |
| 4981 EXPECT_EQ(1, OffHeapInt::s_destructorCalls); | 4984 EXPECT_EQ(1, OffHeapInt::s_destructorCalls); |
| 4982 { | 4985 { |
| 4983 WeakSet& set = map->begin()->value; | 4986 WeakSet& set = map->begin()->value; |
| 4984 EXPECT_EQ(1u, set.size()); | 4987 EXPECT_EQ(1u, set.size()); |
| 4985 } | 4988 } |
| 4986 | 4989 |
| 4987 livingInt.clear(); // The weak set can no longer keep the '42' alive now. | 4990 livingInt.clear(); // The weak set can no longer keep the '42' alive now. |
| 4988 preciselyCollectGarbage(); | 4991 preciselyCollectGarbage(); |
| 4989 EXPECT_EQ(0u, map->size()); | 4992 EXPECT_EQ(0u, map->size()); |
| 4990 } | 4993 } |
| 4991 | 4994 |
| 4992 TEST(HeapTest, EphemeronsInEphemerons) { | 4995 TEST(HeapTest, EphemeronsInEphemerons) { |
| 4993 typedef HeapHashMap<WeakMember<IntWrapper>, Member<IntWrapper>> InnerMap; | 4996 typedef HeapHashMap<WeakMember<IntWrapper>, Member<IntWrapper>> InnerMap; |
| 4994 typedef HeapHashMap<WeakMember<IntWrapper>, InnerMap> OuterMap; | 4997 typedef HeapHashMap<WeakMember<IntWrapper>, InnerMap> OuterMap; |
| 4995 | 4998 |
| 4996 for (int keepOuterAlive = 0; keepOuterAlive <= 1; keepOuterAlive++) { | 4999 for (int keepOuterAlive = 0; keepOuterAlive <= 1; keepOuterAlive++) { |
| 4997 for (int keepInnerAlive = 0; keepInnerAlive <= 1; keepInnerAlive++) { | 5000 for (int keepInnerAlive = 0; keepInnerAlive <= 1; keepInnerAlive++) { |
| 4998 Persistent<OuterMap> outer = new OuterMap(); | 5001 Persistent<OuterMap> outer = new OuterMap(); |
| 4999 Persistent<IntWrapper> one = IntWrapper::create(1); | 5002 Persistent<IntWrapper> one = IntWrapper::create(1); |
| 5000 Persistent<IntWrapper> two = IntWrapper::create(2); | 5003 Persistent<IntWrapper> two = IntWrapper::create(2); |
| 5001 outer->add(one, InnerMap()); | 5004 outer->insert(one, InnerMap()); |
| 5002 outer->begin()->value.add(two, IntWrapper::create(3)); | 5005 outer->begin()->value.insert(two, IntWrapper::create(3)); |
| 5003 EXPECT_EQ(1u, outer->get(one).size()); | 5006 EXPECT_EQ(1u, outer->get(one).size()); |
| 5004 if (!keepOuterAlive) | 5007 if (!keepOuterAlive) |
| 5005 one.clear(); | 5008 one.clear(); |
| 5006 if (!keepInnerAlive) | 5009 if (!keepInnerAlive) |
| 5007 two.clear(); | 5010 two.clear(); |
| 5008 preciselyCollectGarbage(); | 5011 preciselyCollectGarbage(); |
| 5009 if (keepOuterAlive) { | 5012 if (keepOuterAlive) { |
| 5010 const InnerMap& inner = outer->get(one); | 5013 const InnerMap& inner = outer->get(one); |
| 5011 if (keepInnerAlive) { | 5014 if (keepInnerAlive) { |
| 5012 EXPECT_EQ(1u, inner.size()); | 5015 EXPECT_EQ(1u, inner.size()); |
| 5013 IntWrapper* three = inner.get(two); | 5016 IntWrapper* three = inner.get(two); |
| 5014 EXPECT_EQ(3, three->value()); | 5017 EXPECT_EQ(3, three->value()); |
| 5015 } else { | 5018 } else { |
| 5016 EXPECT_EQ(0u, inner.size()); | 5019 EXPECT_EQ(0u, inner.size()); |
| 5017 } | 5020 } |
| 5018 } else { | 5021 } else { |
| 5019 EXPECT_EQ(0u, outer->size()); | 5022 EXPECT_EQ(0u, outer->size()); |
| 5020 } | 5023 } |
| 5021 outer->clear(); | 5024 outer->clear(); |
| 5022 Persistent<IntWrapper> deep = IntWrapper::create(42); | 5025 Persistent<IntWrapper> deep = IntWrapper::create(42); |
| 5023 Persistent<IntWrapper> home = IntWrapper::create(103); | 5026 Persistent<IntWrapper> home = IntWrapper::create(103); |
| 5024 Persistent<IntWrapper> composite = IntWrapper::create(91); | 5027 Persistent<IntWrapper> composite = IntWrapper::create(91); |
| 5025 Persistent<HeapVector<Member<IntWrapper>>> keepAlive = | 5028 Persistent<HeapVector<Member<IntWrapper>>> keepAlive = |
| 5026 new HeapVector<Member<IntWrapper>>(); | 5029 new HeapVector<Member<IntWrapper>>(); |
| 5027 for (int i = 0; i < 10000; i++) { | 5030 for (int i = 0; i < 10000; i++) { |
| 5028 IntWrapper* value = IntWrapper::create(i); | 5031 IntWrapper* value = IntWrapper::create(i); |
| 5029 keepAlive->push_back(value); | 5032 keepAlive->push_back(value); |
| 5030 OuterMap::AddResult newEntry = outer->add(value, InnerMap()); | 5033 OuterMap::AddResult newEntry = outer->insert(value, InnerMap()); |
| 5031 newEntry.storedValue->value.add(deep, home); | 5034 newEntry.storedValue->value.insert(deep, home); |
| 5032 newEntry.storedValue->value.add(composite, home); | 5035 newEntry.storedValue->value.insert(composite, home); |
| 5033 } | 5036 } |
| 5034 composite.clear(); | 5037 composite.clear(); |
| 5035 preciselyCollectGarbage(); | 5038 preciselyCollectGarbage(); |
| 5036 EXPECT_EQ(10000u, outer->size()); | 5039 EXPECT_EQ(10000u, outer->size()); |
| 5037 for (int i = 0; i < 10000; i++) { | 5040 for (int i = 0; i < 10000; i++) { |
| 5038 IntWrapper* value = keepAlive->at(i); | 5041 IntWrapper* value = keepAlive->at(i); |
| 5039 EXPECT_EQ(1u, outer->get(value) | 5042 EXPECT_EQ(1u, outer->get(value) |
| 5040 .size()); // Other one was deleted by weak handling. | 5043 .size()); // Other one was deleted by weak handling. |
| 5041 if (i & 1) | 5044 if (i & 1) |
| 5042 keepAlive->at(i) = nullptr; | 5045 keepAlive->at(i) = nullptr; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5060 | 5063 |
| 5061 TEST(HeapTest, EphemeronsPointToEphemerons) { | 5064 TEST(HeapTest, EphemeronsPointToEphemerons) { |
| 5062 Persistent<IntWrapper> key = IntWrapper::create(42); | 5065 Persistent<IntWrapper> key = IntWrapper::create(42); |
| 5063 Persistent<IntWrapper> key2 = IntWrapper::create(103); | 5066 Persistent<IntWrapper> key2 = IntWrapper::create(103); |
| 5064 | 5067 |
| 5065 Persistent<EphemeronWrapper> chain; | 5068 Persistent<EphemeronWrapper> chain; |
| 5066 for (int i = 0; i < 100; i++) { | 5069 for (int i = 0; i < 100; i++) { |
| 5067 EphemeronWrapper* oldHead = chain; | 5070 EphemeronWrapper* oldHead = chain; |
| 5068 chain = new EphemeronWrapper(); | 5071 chain = new EphemeronWrapper(); |
| 5069 if (i == 50) | 5072 if (i == 50) |
| 5070 chain->getMap().add(key2, oldHead); | 5073 chain->getMap().insert(key2, oldHead); |
| 5071 else | 5074 else |
| 5072 chain->getMap().add(key, oldHead); | 5075 chain->getMap().insert(key, oldHead); |
| 5073 chain->getMap().add(IntWrapper::create(103), new EphemeronWrapper()); | 5076 chain->getMap().insert(IntWrapper::create(103), new EphemeronWrapper()); |
| 5074 } | 5077 } |
| 5075 | 5078 |
| 5076 preciselyCollectGarbage(); | 5079 preciselyCollectGarbage(); |
| 5077 | 5080 |
| 5078 EphemeronWrapper* wrapper = chain; | 5081 EphemeronWrapper* wrapper = chain; |
| 5079 for (int i = 0; i < 100; i++) { | 5082 for (int i = 0; i < 100; i++) { |
| 5080 EXPECT_EQ(1u, wrapper->getMap().size()); | 5083 EXPECT_EQ(1u, wrapper->getMap().size()); |
| 5081 if (i == 49) | 5084 if (i == 49) |
| 5082 wrapper = wrapper->getMap().get(key2); | 5085 wrapper = wrapper->getMap().get(key2); |
| 5083 else | 5086 else |
| (...skipping 29 matching lines...) Expand all Loading... |
| 5113 Persistent<PairWeakMap> pairWeakMap = new PairWeakMap(); | 5116 Persistent<PairWeakMap> pairWeakMap = new PairWeakMap(); |
| 5114 Persistent<PairWeakMap> pairWeakMap2 = new PairWeakMap(); | 5117 Persistent<PairWeakMap> pairWeakMap2 = new PairWeakMap(); |
| 5115 | 5118 |
| 5116 Persistent<Set> set = new Set(); | 5119 Persistent<Set> set = new Set(); |
| 5117 | 5120 |
| 5118 Persistent<IntWrapper> wp1 = IntWrapper::create(1); | 5121 Persistent<IntWrapper> wp1 = IntWrapper::create(1); |
| 5119 Persistent<IntWrapper> wp2 = IntWrapper::create(2); | 5122 Persistent<IntWrapper> wp2 = IntWrapper::create(2); |
| 5120 Persistent<IntWrapper> pw1 = IntWrapper::create(3); | 5123 Persistent<IntWrapper> pw1 = IntWrapper::create(3); |
| 5121 Persistent<IntWrapper> pw2 = IntWrapper::create(4); | 5124 Persistent<IntWrapper> pw2 = IntWrapper::create(4); |
| 5122 | 5125 |
| 5123 weakPairMap->add(wp1, PairWithWeakHandling(wp1, wp1)); | 5126 weakPairMap->insert(wp1, PairWithWeakHandling(wp1, wp1)); |
| 5124 weakPairMap->add(wp2, PairWithWeakHandling(wp1, wp1)); | 5127 weakPairMap->insert(wp2, PairWithWeakHandling(wp1, wp1)); |
| 5125 weakPairMap2->add(wp1, PairWithWeakHandling(wp1, wp2)); | 5128 weakPairMap2->insert(wp1, PairWithWeakHandling(wp1, wp2)); |
| 5126 weakPairMap2->add(wp2, PairWithWeakHandling(wp1, wp2)); | 5129 weakPairMap2->insert(wp2, PairWithWeakHandling(wp1, wp2)); |
| 5127 // The map from wp1 to (wp2, wp1) would mark wp2 live, so we skip that. | 5130 // The map from wp1 to (wp2, wp1) would mark wp2 live, so we skip that. |
| 5128 weakPairMap3->add(wp2, PairWithWeakHandling(wp2, wp1)); | 5131 weakPairMap3->insert(wp2, PairWithWeakHandling(wp2, wp1)); |
| 5129 weakPairMap4->add(wp1, PairWithWeakHandling(wp2, wp2)); | 5132 weakPairMap4->insert(wp1, PairWithWeakHandling(wp2, wp2)); |
| 5130 weakPairMap4->add(wp2, PairWithWeakHandling(wp2, wp2)); | 5133 weakPairMap4->insert(wp2, PairWithWeakHandling(wp2, wp2)); |
| 5131 | 5134 |
| 5132 pairWeakMap->add(PairWithWeakHandling(pw1, pw1), pw1); | 5135 pairWeakMap->insert(PairWithWeakHandling(pw1, pw1), pw1); |
| 5133 pairWeakMap->add(PairWithWeakHandling(pw1, pw2), pw1); | 5136 pairWeakMap->insert(PairWithWeakHandling(pw1, pw2), pw1); |
| 5134 // The map from (pw2, pw1) to pw1 would make pw2 live, so we skip that. | 5137 // The map from (pw2, pw1) to pw1 would make pw2 live, so we skip that. |
| 5135 pairWeakMap->add(PairWithWeakHandling(pw2, pw2), pw1); | 5138 pairWeakMap->insert(PairWithWeakHandling(pw2, pw2), pw1); |
| 5136 pairWeakMap2->add(PairWithWeakHandling(pw1, pw1), pw2); | 5139 pairWeakMap2->insert(PairWithWeakHandling(pw1, pw1), pw2); |
| 5137 pairWeakMap2->add(PairWithWeakHandling(pw1, pw2), pw2); | 5140 pairWeakMap2->insert(PairWithWeakHandling(pw1, pw2), pw2); |
| 5138 pairWeakMap2->add(PairWithWeakHandling(pw2, pw1), pw2); | 5141 pairWeakMap2->insert(PairWithWeakHandling(pw2, pw1), pw2); |
| 5139 pairWeakMap2->add(PairWithWeakHandling(pw2, pw2), pw2); | 5142 pairWeakMap2->insert(PairWithWeakHandling(pw2, pw2), pw2); |
| 5140 | 5143 |
| 5141 set->add(wp1); | 5144 set->add(wp1); |
| 5142 set->add(wp2); | 5145 set->add(wp2); |
| 5143 set->add(pw1); | 5146 set->add(pw1); |
| 5144 set->add(pw2); | 5147 set->add(pw2); |
| 5145 | 5148 |
| 5146 preciselyCollectGarbage(); | 5149 preciselyCollectGarbage(); |
| 5147 | 5150 |
| 5148 EXPECT_EQ(2u, weakPairMap->size()); | 5151 EXPECT_EQ(2u, weakPairMap->size()); |
| 5149 EXPECT_EQ(2u, weakPairMap2->size()); | 5152 EXPECT_EQ(2u, weakPairMap2->size()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5193 private: | 5196 private: |
| 5194 Member<IntWrapper> m_link; | 5197 Member<IntWrapper> m_link; |
| 5195 }; | 5198 }; |
| 5196 | 5199 |
| 5197 TEST(HeapTest, IndirectStrongToWeak) { | 5200 TEST(HeapTest, IndirectStrongToWeak) { |
| 5198 typedef HeapHashMap<WeakMember<IntWrapper>, Member<Link1>> Map; | 5201 typedef HeapHashMap<WeakMember<IntWrapper>, Member<Link1>> Map; |
| 5199 Persistent<Map> map = new Map(); | 5202 Persistent<Map> map = new Map(); |
| 5200 Persistent<IntWrapper> deadObject = | 5203 Persistent<IntWrapper> deadObject = |
| 5201 IntWrapper::create(100); // Named for "Drowning by Numbers" (1988). | 5204 IntWrapper::create(100); // Named for "Drowning by Numbers" (1988). |
| 5202 Persistent<IntWrapper> lifeObject = IntWrapper::create(42); | 5205 Persistent<IntWrapper> lifeObject = IntWrapper::create(42); |
| 5203 map->add(deadObject, new Link1(deadObject)); | 5206 map->insert(deadObject, new Link1(deadObject)); |
| 5204 map->add(lifeObject, new Link1(lifeObject)); | 5207 map->insert(lifeObject, new Link1(lifeObject)); |
| 5205 EXPECT_EQ(2u, map->size()); | 5208 EXPECT_EQ(2u, map->size()); |
| 5206 preciselyCollectGarbage(); | 5209 preciselyCollectGarbage(); |
| 5207 EXPECT_EQ(2u, map->size()); | 5210 EXPECT_EQ(2u, map->size()); |
| 5208 EXPECT_EQ(deadObject, map->get(deadObject)->link()); | 5211 EXPECT_EQ(deadObject, map->get(deadObject)->link()); |
| 5209 EXPECT_EQ(lifeObject, map->get(lifeObject)->link()); | 5212 EXPECT_EQ(lifeObject, map->get(lifeObject)->link()); |
| 5210 deadObject.clear(); // Now it can live up to its name. | 5213 deadObject.clear(); // Now it can live up to its name. |
| 5211 preciselyCollectGarbage(); | 5214 preciselyCollectGarbage(); |
| 5212 EXPECT_EQ(1u, map->size()); | 5215 EXPECT_EQ(1u, map->size()); |
| 5213 EXPECT_EQ(lifeObject, map->get(lifeObject)->link()); | 5216 EXPECT_EQ(lifeObject, map->get(lifeObject)->link()); |
| 5214 lifeObject.clear(); // Despite its name. | 5217 lifeObject.clear(); // Despite its name. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5300 // Create a weak collection that is kept alive by a persistent | 5303 // Create a weak collection that is kept alive by a persistent |
| 5301 // and keep the contents alive with a persistents as | 5304 // and keep the contents alive with a persistents as |
| 5302 // well. | 5305 // well. |
| 5303 Persistent<IntWrapper> wrapper1 = IntWrapper::create(32); | 5306 Persistent<IntWrapper> wrapper1 = IntWrapper::create(32); |
| 5304 Persistent<IntWrapper> wrapper2 = IntWrapper::create(32); | 5307 Persistent<IntWrapper> wrapper2 = IntWrapper::create(32); |
| 5305 Persistent<IntWrapper> wrapper3 = IntWrapper::create(32); | 5308 Persistent<IntWrapper> wrapper3 = IntWrapper::create(32); |
| 5306 Persistent<IntWrapper> wrapper4 = IntWrapper::create(32); | 5309 Persistent<IntWrapper> wrapper4 = IntWrapper::create(32); |
| 5307 Persistent<IntWrapper> wrapper5 = IntWrapper::create(32); | 5310 Persistent<IntWrapper> wrapper5 = IntWrapper::create(32); |
| 5308 Persistent<IntWrapper> wrapper6 = IntWrapper::create(32); | 5311 Persistent<IntWrapper> wrapper6 = IntWrapper::create(32); |
| 5309 Persistent<WeakCollectionType> weakCollection = new WeakCollectionType; | 5312 Persistent<WeakCollectionType> weakCollection = new WeakCollectionType; |
| 5310 weakCollection->add(wrapper1, wrapper1); | 5313 weakCollection->insert(wrapper1, wrapper1); |
| 5311 weakCollection->add(wrapper2, wrapper2); | 5314 weakCollection->insert(wrapper2, wrapper2); |
| 5312 weakCollection->add(wrapper3, wrapper3); | 5315 weakCollection->insert(wrapper3, wrapper3); |
| 5313 weakCollection->add(wrapper4, wrapper4); | 5316 weakCollection->insert(wrapper4, wrapper4); |
| 5314 weakCollection->add(wrapper5, wrapper5); | 5317 weakCollection->insert(wrapper5, wrapper5); |
| 5315 weakCollection->add(wrapper6, wrapper6); | 5318 weakCollection->insert(wrapper6, wrapper6); |
| 5316 | 5319 |
| 5317 // Signal the main thread that the worker is done with its allocation. | 5320 // Signal the main thread that the worker is done with its allocation. |
| 5318 wakeMainThread(); | 5321 wakeMainThread(); |
| 5319 | 5322 |
| 5320 { | 5323 { |
| 5321 // Wait for the main thread to do two GCs without sweeping | 5324 // Wait for the main thread to do two GCs without sweeping |
| 5322 // this thread heap. The worker waits within a safepoint, | 5325 // this thread heap. The worker waits within a safepoint, |
| 5323 // but there is no sweeping until leaving the safepoint | 5326 // but there is no sweeping until leaving the safepoint |
| 5324 // scope. If the weak collection backing is marked dead | 5327 // scope. If the weak collection backing is marked dead |
| 5325 // because of this we will not get strongification in the | 5328 // because of this we will not get strongification in the |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5565 : blink::AllocatesOnAssignmentHashTraits {}; | 5568 : blink::AllocatesOnAssignmentHashTraits {}; |
| 5566 | 5569 |
| 5567 } // namespace WTF | 5570 } // namespace WTF |
| 5568 | 5571 |
| 5569 namespace blink { | 5572 namespace blink { |
| 5570 | 5573 |
| 5571 TEST(HeapTest, GCInHashMapOperations) { | 5574 TEST(HeapTest, GCInHashMapOperations) { |
| 5572 typedef HeapHashMap<AllocatesOnAssignment, AllocatesOnAssignment> Map; | 5575 typedef HeapHashMap<AllocatesOnAssignment, AllocatesOnAssignment> Map; |
| 5573 Map* map = new Map(); | 5576 Map* map = new Map(); |
| 5574 IntWrapper* key = new IntWrapper(42); | 5577 IntWrapper* key = new IntWrapper(42); |
| 5575 map->add(key, AllocatesOnAssignment(103)); | 5578 map->insert(key, AllocatesOnAssignment(103)); |
| 5576 map->erase(key); | 5579 map->erase(key); |
| 5577 for (int i = 0; i < 10; i++) | 5580 for (int i = 0; i < 10; i++) |
| 5578 map->add(AllocatesOnAssignment(i), AllocatesOnAssignment(i)); | 5581 map->insert(AllocatesOnAssignment(i), AllocatesOnAssignment(i)); |
| 5579 for (Map::iterator it = map->begin(); it != map->end(); ++it) | 5582 for (Map::iterator it = map->begin(); it != map->end(); ++it) |
| 5580 EXPECT_EQ(it->key.value(), it->value.value()); | 5583 EXPECT_EQ(it->key.value(), it->value.value()); |
| 5581 } | 5584 } |
| 5582 | 5585 |
| 5583 class PartObjectWithVirtualMethod { | 5586 class PartObjectWithVirtualMethod { |
| 5584 public: | 5587 public: |
| 5585 DEFINE_INLINE_VIRTUAL_TRACE() {} | 5588 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 5586 }; | 5589 }; |
| 5587 | 5590 |
| 5588 class ObjectWithVirtualPartObject | 5591 class ObjectWithVirtualPartObject |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6376 "HeapVector"); | 6379 "HeapVector"); |
| 6377 static_assert( | 6380 static_assert( |
| 6378 WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::value, | 6381 WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::value, |
| 6379 "HeapDeque"); | 6382 "HeapDeque"); |
| 6380 static_assert(WTF::IsGarbageCollectedType< | 6383 static_assert(WTF::IsGarbageCollectedType< |
| 6381 HeapTerminatedArray<Member<IntWrapper>>>::value, | 6384 HeapTerminatedArray<Member<IntWrapper>>>::value, |
| 6382 "HeapTerminatedArray"); | 6385 "HeapTerminatedArray"); |
| 6383 } | 6386 } |
| 6384 | 6387 |
| 6385 } // namespace blink | 6388 } // namespace blink |
| OLD | NEW |