| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "wtf/HashTraits.h" | 45 #include "wtf/HashTraits.h" |
| 46 #include "wtf/LinkedHashSet.h" | 46 #include "wtf/LinkedHashSet.h" |
| 47 #include "wtf/PtrUtil.h" | 47 #include "wtf/PtrUtil.h" |
| 48 #include <algorithm> | 48 #include <algorithm> |
| 49 #include <memory> | 49 #include <memory> |
| 50 | 50 |
| 51 namespace blink { | 51 namespace blink { |
| 52 | 52 |
| 53 static void preciselyCollectGarbage() | 53 static void preciselyCollectGarbage() |
| 54 { | 54 { |
| 55 ThreadState::current()->collectGarbage(BlinkGC::NoHeapPointersOnStack, Blink
GC::GCWithSweep, BlinkGC::ForcedGC); | 55 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw
eep, BlinkGC::ForcedGC); |
| 56 } | 56 } |
| 57 | 57 |
| 58 static void conservativelyCollectGarbage() | 58 static void conservativelyCollectGarbage() |
| 59 { | 59 { |
| 60 ThreadState::current()->collectGarbage(BlinkGC::HeapPointersOnStack, BlinkGC
::GCWithSweep, BlinkGC::ForcedGC); | 60 ThreadHeap::collectGarbage(BlinkGC::HeapPointersOnStack, BlinkGC::GCWithSwee
p, BlinkGC::ForcedGC); |
| 61 } | 61 } |
| 62 | 62 |
| 63 class IntWrapper : public GarbageCollectedFinalized<IntWrapper> { | 63 class IntWrapper : public GarbageCollectedFinalized<IntWrapper> { |
| 64 public: | 64 public: |
| 65 static IntWrapper* create(int x) | 65 static IntWrapper* create(int x) |
| 66 { | 66 { |
| 67 return new IntWrapper(x); | 67 return new IntWrapper(x); |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual ~IntWrapper() | 70 virtual ~IntWrapper() |
| (...skipping 1944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2015 #endif | 2015 #endif |
| 2016 | 2016 |
| 2017 TEST(HeapTest, LazySweepingPages) | 2017 TEST(HeapTest, LazySweepingPages) |
| 2018 { | 2018 { |
| 2019 clearOutOldGarbage(); | 2019 clearOutOldGarbage(); |
| 2020 | 2020 |
| 2021 SimpleFinalizedObject::s_destructorCalls = 0; | 2021 SimpleFinalizedObject::s_destructorCalls = 0; |
| 2022 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 2022 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
| 2023 for (int i = 0; i < 1000; i++) | 2023 for (int i = 0; i < 1000; i++) |
| 2024 SimpleFinalizedObject::create(); | 2024 SimpleFinalizedObject::create(); |
| 2025 ThreadState::current()->collectGarbage(BlinkGC::NoHeapPointersOnStack, Blink
GC::GCWithoutSweep, BlinkGC::ForcedGC); | 2025 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithou
tSweep, BlinkGC::ForcedGC); |
| 2026 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 2026 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
| 2027 for (int i = 0; i < 10000; i++) | 2027 for (int i = 0; i < 10000; i++) |
| 2028 SimpleFinalizedObject::create(); | 2028 SimpleFinalizedObject::create(); |
| 2029 EXPECT_EQ(1000, SimpleFinalizedObject::s_destructorCalls); | 2029 EXPECT_EQ(1000, SimpleFinalizedObject::s_destructorCalls); |
| 2030 preciselyCollectGarbage(); | 2030 preciselyCollectGarbage(); |
| 2031 EXPECT_EQ(11000, SimpleFinalizedObject::s_destructorCalls); | 2031 EXPECT_EQ(11000, SimpleFinalizedObject::s_destructorCalls); |
| 2032 } | 2032 } |
| 2033 | 2033 |
| 2034 TEST(HeapTest, LazySweepingLargeObjectPages) | 2034 TEST(HeapTest, LazySweepingLargeObjectPages) |
| 2035 { | 2035 { |
| 2036 clearOutOldGarbage(); | 2036 clearOutOldGarbage(); |
| 2037 | 2037 |
| 2038 // Create free lists that can be reused for IntWrappers created in | 2038 // Create free lists that can be reused for IntWrappers created in |
| 2039 // LargeHeapObject::create(). | 2039 // LargeHeapObject::create(). |
| 2040 Persistent<IntWrapper> p1 = new IntWrapper(1); | 2040 Persistent<IntWrapper> p1 = new IntWrapper(1); |
| 2041 for (int i = 0; i < 100; i++) { | 2041 for (int i = 0; i < 100; i++) { |
| 2042 new IntWrapper(i); | 2042 new IntWrapper(i); |
| 2043 } | 2043 } |
| 2044 Persistent<IntWrapper> p2 = new IntWrapper(2); | 2044 Persistent<IntWrapper> p2 = new IntWrapper(2); |
| 2045 preciselyCollectGarbage(); | 2045 preciselyCollectGarbage(); |
| 2046 preciselyCollectGarbage(); | 2046 preciselyCollectGarbage(); |
| 2047 | 2047 |
| 2048 LargeHeapObject::s_destructorCalls = 0; | 2048 LargeHeapObject::s_destructorCalls = 0; |
| 2049 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); | 2049 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); |
| 2050 for (int i = 0; i < 10; i++) | 2050 for (int i = 0; i < 10; i++) |
| 2051 LargeHeapObject::create(); | 2051 LargeHeapObject::create(); |
| 2052 ThreadState::current()->collectGarbage(BlinkGC::NoHeapPointersOnStack, Blink
GC::GCWithoutSweep, BlinkGC::ForcedGC); | 2052 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithou
tSweep, BlinkGC::ForcedGC); |
| 2053 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); | 2053 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); |
| 2054 for (int i = 0; i < 10; i++) { | 2054 for (int i = 0; i < 10; i++) { |
| 2055 LargeHeapObject::create(); | 2055 LargeHeapObject::create(); |
| 2056 EXPECT_EQ(i + 1, LargeHeapObject::s_destructorCalls); | 2056 EXPECT_EQ(i + 1, LargeHeapObject::s_destructorCalls); |
| 2057 } | 2057 } |
| 2058 LargeHeapObject::create(); | 2058 LargeHeapObject::create(); |
| 2059 LargeHeapObject::create(); | 2059 LargeHeapObject::create(); |
| 2060 EXPECT_EQ(10, LargeHeapObject::s_destructorCalls); | 2060 EXPECT_EQ(10, LargeHeapObject::s_destructorCalls); |
| 2061 ThreadState::current()->collectGarbage(BlinkGC::NoHeapPointersOnStack, Blink
GC::GCWithoutSweep, BlinkGC::ForcedGC); | 2061 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithou
tSweep, BlinkGC::ForcedGC); |
| 2062 EXPECT_EQ(10, LargeHeapObject::s_destructorCalls); | 2062 EXPECT_EQ(10, LargeHeapObject::s_destructorCalls); |
| 2063 preciselyCollectGarbage(); | 2063 preciselyCollectGarbage(); |
| 2064 EXPECT_EQ(22, LargeHeapObject::s_destructorCalls); | 2064 EXPECT_EQ(22, LargeHeapObject::s_destructorCalls); |
| 2065 } | 2065 } |
| 2066 | 2066 |
| 2067 class SimpleFinalizedEagerObjectBase : public GarbageCollectedFinalized<SimpleFi
nalizedEagerObjectBase> { | 2067 class SimpleFinalizedEagerObjectBase : public GarbageCollectedFinalized<SimpleFi
nalizedEagerObjectBase> { |
| 2068 public: | 2068 public: |
| 2069 virtual ~SimpleFinalizedEagerObjectBase() { } | 2069 virtual ~SimpleFinalizedEagerObjectBase() { } |
| 2070 DEFINE_INLINE_TRACE() { } | 2070 DEFINE_INLINE_TRACE() { } |
| 2071 | 2071 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2126 SimpleFinalizedEagerObject::s_destructorCalls = 0; | 2126 SimpleFinalizedEagerObject::s_destructorCalls = 0; |
| 2127 SimpleFinalizedObjectInstanceOfTemplate::s_destructorCalls = 0; | 2127 SimpleFinalizedObjectInstanceOfTemplate::s_destructorCalls = 0; |
| 2128 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 2128 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
| 2129 EXPECT_EQ(0, SimpleFinalizedEagerObject::s_destructorCalls); | 2129 EXPECT_EQ(0, SimpleFinalizedEagerObject::s_destructorCalls); |
| 2130 for (int i = 0; i < 1000; i++) | 2130 for (int i = 0; i < 1000; i++) |
| 2131 SimpleFinalizedObject::create(); | 2131 SimpleFinalizedObject::create(); |
| 2132 for (int i = 0; i < 100; i++) | 2132 for (int i = 0; i < 100; i++) |
| 2133 SimpleFinalizedEagerObject::create(); | 2133 SimpleFinalizedEagerObject::create(); |
| 2134 for (int i = 0; i < 100; i++) | 2134 for (int i = 0; i < 100; i++) |
| 2135 SimpleFinalizedObjectInstanceOfTemplate::create(); | 2135 SimpleFinalizedObjectInstanceOfTemplate::create(); |
| 2136 ThreadState::current()->collectGarbage(BlinkGC::NoHeapPointersOnStack, Blink
GC::GCWithoutSweep, BlinkGC::ForcedGC); | 2136 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithou
tSweep, BlinkGC::ForcedGC); |
| 2137 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 2137 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
| 2138 EXPECT_EQ(100, SimpleFinalizedEagerObject::s_destructorCalls); | 2138 EXPECT_EQ(100, SimpleFinalizedEagerObject::s_destructorCalls); |
| 2139 EXPECT_EQ(100, SimpleFinalizedObjectInstanceOfTemplate::s_destructorCalls); | 2139 EXPECT_EQ(100, SimpleFinalizedObjectInstanceOfTemplate::s_destructorCalls); |
| 2140 } | 2140 } |
| 2141 | 2141 |
| 2142 TEST(HeapTest, Finalization) | 2142 TEST(HeapTest, Finalization) |
| 2143 { | 2143 { |
| 2144 { | 2144 { |
| 2145 HeapTestSubClass* t1 = HeapTestSubClass::create(); | 2145 HeapTestSubClass* t1 = HeapTestSubClass::create(); |
| 2146 HeapTestSubClass* t2 = HeapTestSubClass::create(); | 2146 HeapTestSubClass* t2 = HeapTestSubClass::create(); |
| (...skipping 4087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6234 { | 6234 { |
| 6235 } | 6235 } |
| 6236 }; | 6236 }; |
| 6237 | 6237 |
| 6238 // Regression test for crbug.com/404511. Tests conservative marking of | 6238 // Regression test for crbug.com/404511. Tests conservative marking of |
| 6239 // an object with an uninitialized vtable. | 6239 // an object with an uninitialized vtable. |
| 6240 TEST(HeapTest, AllocationInSuperConstructorArgument) | 6240 TEST(HeapTest, AllocationInSuperConstructorArgument) |
| 6241 { | 6241 { |
| 6242 AllocInSuperConstructorArgument* object = new AllocInSuperConstructorArgumen
t(); | 6242 AllocInSuperConstructorArgument* object = new AllocInSuperConstructorArgumen
t(); |
| 6243 EXPECT_TRUE(object); | 6243 EXPECT_TRUE(object); |
| 6244 ThreadState::current()->collectAllGarbage(); | 6244 ThreadHeap::collectAllGarbage(); |
| 6245 } | 6245 } |
| 6246 | 6246 |
| 6247 class NonNodeAllocatingNodeInDestructor : public GarbageCollectedFinalized<NonNo
deAllocatingNodeInDestructor> { | 6247 class NonNodeAllocatingNodeInDestructor : public GarbageCollectedFinalized<NonNo
deAllocatingNodeInDestructor> { |
| 6248 public: | 6248 public: |
| 6249 ~NonNodeAllocatingNodeInDestructor() | 6249 ~NonNodeAllocatingNodeInDestructor() |
| 6250 { | 6250 { |
| 6251 s_node = new Persistent<IntNode>(IntNode::create(10)); | 6251 s_node = new Persistent<IntNode>(IntNode::create(10)); |
| 6252 } | 6252 } |
| 6253 | 6253 |
| 6254 DEFINE_INLINE_TRACE() { } | 6254 DEFINE_INLINE_TRACE() { } |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6690 void workerThreadMainForCrossThreadWeakPersistentTest(DestructorLockingObject**
object) | 6690 void workerThreadMainForCrossThreadWeakPersistentTest(DestructorLockingObject**
object) |
| 6691 { | 6691 { |
| 6692 // Step 2: Create an object and store the pointer. | 6692 // Step 2: Create an object and store the pointer. |
| 6693 MutexLocker locker(workerThreadMutex()); | 6693 MutexLocker locker(workerThreadMutex()); |
| 6694 ThreadState::attachCurrentThread(false); | 6694 ThreadState::attachCurrentThread(false); |
| 6695 *object = DestructorLockingObject::create(); | 6695 *object = DestructorLockingObject::create(); |
| 6696 wakeMainThread(); | 6696 wakeMainThread(); |
| 6697 parkWorkerThread(); | 6697 parkWorkerThread(); |
| 6698 | 6698 |
| 6699 // Step 4: Run a GC. | 6699 // Step 4: Run a GC. |
| 6700 ThreadState::current()->collectGarbage(BlinkGC::NoHeapPointersOnStack, Blink
GC::GCWithSweep, BlinkGC::ForcedGC); | 6700 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw
eep, BlinkGC::ForcedGC); |
| 6701 wakeMainThread(); | 6701 wakeMainThread(); |
| 6702 parkWorkerThread(); | 6702 parkWorkerThread(); |
| 6703 | 6703 |
| 6704 // Step 6: Finish. | 6704 // Step 6: Finish. |
| 6705 ThreadState::detachCurrentThread(); | 6705 ThreadState::detachCurrentThread(); |
| 6706 wakeMainThread(); | 6706 wakeMainThread(); |
| 6707 } | 6707 } |
| 6708 | 6708 |
| 6709 } // anonymous namespace | 6709 } // anonymous namespace |
| 6710 | 6710 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6982 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe
r>>>::value, "HeapLinkedHashSet"); | 6982 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe
r>>>::value, "HeapLinkedHashSet"); |
| 6983 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper>
>>::value, "HeapListHashSet"); | 6983 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper>
>>::value, "HeapListHashSet"); |
| 6984 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp
er>>>::value, "HeapHashCountedSet"); | 6984 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp
er>>>::value, "HeapHashCountedSet"); |
| 6985 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper
>>>::value, "HeapHashMap"); | 6985 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper
>>>::value, "HeapHashMap"); |
| 6986 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v
alue, "HeapVector"); | 6986 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v
alue, "HeapVector"); |
| 6987 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va
lue, "HeapDeque"); | 6987 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va
lue, "HeapDeque"); |
| 6988 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap
per>>>::value, "HeapTerminatedArray"); | 6988 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap
per>>>::value, "HeapTerminatedArray"); |
| 6989 } | 6989 } |
| 6990 | 6990 |
| 6991 } // namespace blink | 6991 } // namespace blink |
| OLD | NEW |