| 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 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include <algorithm> |
| 32 #include <memory> |
| 31 #include "platform/CrossThreadFunctional.h" | 33 #include "platform/CrossThreadFunctional.h" |
| 32 #include "platform/WebTaskRunner.h" | 34 #include "platform/WebTaskRunner.h" |
| 33 #include "platform/heap/Handle.h" | 35 #include "platform/heap/Handle.h" |
| 34 #include "platform/heap/Heap.h" | 36 #include "platform/heap/Heap.h" |
| 35 #include "platform/heap/HeapLinkedStack.h" | 37 #include "platform/heap/HeapLinkedStack.h" |
| 36 #include "platform/heap/HeapTerminatedArrayBuilder.h" | 38 #include "platform/heap/HeapTerminatedArrayBuilder.h" |
| 37 #include "platform/heap/SafePoint.h" | 39 #include "platform/heap/SafePoint.h" |
| 38 #include "platform/heap/SelfKeepAlive.h" | 40 #include "platform/heap/SelfKeepAlive.h" |
| 39 #include "platform/heap/ThreadState.h" | 41 #include "platform/heap/ThreadState.h" |
| 40 #include "platform/heap/Visitor.h" | 42 #include "platform/heap/Visitor.h" |
| 41 #include "platform/testing/UnitTestHelpers.h" | 43 #include "platform/testing/UnitTestHelpers.h" |
| 42 #include "public/platform/Platform.h" | 44 #include "public/platform/Platform.h" |
| 43 #include "public/platform/WebTraceLocation.h" | 45 #include "public/platform/WebTraceLocation.h" |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "wtf/HashTraits.h" | 47 #include "wtf/HashTraits.h" |
| 46 #include "wtf/LinkedHashSet.h" | 48 #include "wtf/LinkedHashSet.h" |
| 47 #include "wtf/PtrUtil.h" | 49 #include "wtf/PtrUtil.h" |
| 48 #include <algorithm> | |
| 49 #include <memory> | |
| 50 | 50 |
| 51 namespace blink { | 51 namespace blink { |
| 52 | 52 |
| 53 static void preciselyCollectGarbage() { | 53 static void preciselyCollectGarbage() { |
| 54 ThreadState::current()->collectGarbage( | 54 ThreadState::current()->collectGarbage( |
| 55 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); | 55 BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, BlinkGC::ForcedGC); |
| 56 } | 56 } |
| 57 | 57 |
| 58 static void conservativelyCollectGarbage() { | 58 static void conservativelyCollectGarbage() { |
| 59 ThreadState::current()->collectGarbage( | 59 ThreadState::current()->collectGarbage( |
| (...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 } | 1041 } |
| 1042 ~ObservableWithPreFinalizer() { m_wasDestructed = true; } | 1042 ~ObservableWithPreFinalizer() { m_wasDestructed = true; } |
| 1043 DEFINE_INLINE_TRACE() {} | 1043 DEFINE_INLINE_TRACE() {} |
| 1044 void dispose() { | 1044 void dispose() { |
| 1045 EXPECT_FALSE(m_wasDestructed); | 1045 EXPECT_FALSE(m_wasDestructed); |
| 1046 s_disposeWasCalled = true; | 1046 s_disposeWasCalled = true; |
| 1047 } | 1047 } |
| 1048 static bool s_disposeWasCalled; | 1048 static bool s_disposeWasCalled; |
| 1049 | 1049 |
| 1050 protected: | 1050 protected: |
| 1051 ObservableWithPreFinalizer() : m_wasDestructed(false) { | 1051 ObservableWithPreFinalizer() : m_wasDestructed(false) {} |
| 1052 } | |
| 1053 | 1052 |
| 1054 bool m_wasDestructed; | 1053 bool m_wasDestructed; |
| 1055 }; | 1054 }; |
| 1056 | 1055 |
| 1057 bool ObservableWithPreFinalizer::s_disposeWasCalled = false; | 1056 bool ObservableWithPreFinalizer::s_disposeWasCalled = false; |
| 1058 | 1057 |
| 1059 bool s_disposeWasCalledForPreFinalizerBase = false; | 1058 bool s_disposeWasCalledForPreFinalizerBase = false; |
| 1060 bool s_disposeWasCalledForPreFinalizerMixin = false; | 1059 bool s_disposeWasCalledForPreFinalizerMixin = false; |
| 1061 bool s_disposeWasCalledForPreFinalizerSubClass = false; | 1060 bool s_disposeWasCalledForPreFinalizerSubClass = false; |
| 1062 | 1061 |
| 1063 class PreFinalizerBase : public GarbageCollectedFinalized<PreFinalizerBase> { | 1062 class PreFinalizerBase : public GarbageCollectedFinalized<PreFinalizerBase> { |
| 1064 USING_PRE_FINALIZER(PreFinalizerBase, dispose); | 1063 USING_PRE_FINALIZER(PreFinalizerBase, dispose); |
| 1065 | 1064 |
| 1066 public: | 1065 public: |
| 1067 static PreFinalizerBase* create() { return new PreFinalizerBase(); } | 1066 static PreFinalizerBase* create() { return new PreFinalizerBase(); } |
| 1068 virtual ~PreFinalizerBase() { m_wasDestructed = true; } | 1067 virtual ~PreFinalizerBase() { m_wasDestructed = true; } |
| 1069 DEFINE_INLINE_VIRTUAL_TRACE() {} | 1068 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 1070 void dispose() { | 1069 void dispose() { |
| 1071 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerBase); | 1070 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerBase); |
| 1072 EXPECT_TRUE(s_disposeWasCalledForPreFinalizerSubClass); | 1071 EXPECT_TRUE(s_disposeWasCalledForPreFinalizerSubClass); |
| 1073 EXPECT_TRUE(s_disposeWasCalledForPreFinalizerMixin); | 1072 EXPECT_TRUE(s_disposeWasCalledForPreFinalizerMixin); |
| 1074 EXPECT_FALSE(m_wasDestructed); | 1073 EXPECT_FALSE(m_wasDestructed); |
| 1075 s_disposeWasCalledForPreFinalizerBase = true; | 1074 s_disposeWasCalledForPreFinalizerBase = true; |
| 1076 } | 1075 } |
| 1077 | 1076 |
| 1078 protected: | 1077 protected: |
| 1079 PreFinalizerBase() : m_wasDestructed(false) { | 1078 PreFinalizerBase() : m_wasDestructed(false) {} |
| 1080 } | |
| 1081 bool m_wasDestructed; | 1079 bool m_wasDestructed; |
| 1082 }; | 1080 }; |
| 1083 | 1081 |
| 1084 class PreFinalizerMixin : public GarbageCollectedMixin { | 1082 class PreFinalizerMixin : public GarbageCollectedMixin { |
| 1085 USING_PRE_FINALIZER(PreFinalizerMixin, dispose); | 1083 USING_PRE_FINALIZER(PreFinalizerMixin, dispose); |
| 1086 | 1084 |
| 1087 public: | 1085 public: |
| 1088 ~PreFinalizerMixin() { m_wasDestructed = true; } | 1086 ~PreFinalizerMixin() { m_wasDestructed = true; } |
| 1089 DEFINE_INLINE_VIRTUAL_TRACE() {} | 1087 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 1090 void dispose() { | 1088 void dispose() { |
| 1091 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerBase); | 1089 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerBase); |
| 1092 EXPECT_TRUE(s_disposeWasCalledForPreFinalizerSubClass); | 1090 EXPECT_TRUE(s_disposeWasCalledForPreFinalizerSubClass); |
| 1093 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerMixin); | 1091 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerMixin); |
| 1094 EXPECT_FALSE(m_wasDestructed); | 1092 EXPECT_FALSE(m_wasDestructed); |
| 1095 s_disposeWasCalledForPreFinalizerMixin = true; | 1093 s_disposeWasCalledForPreFinalizerMixin = true; |
| 1096 } | 1094 } |
| 1097 | 1095 |
| 1098 protected: | 1096 protected: |
| 1099 PreFinalizerMixin() : m_wasDestructed(false) { | 1097 PreFinalizerMixin() : m_wasDestructed(false) {} |
| 1100 } | |
| 1101 bool m_wasDestructed; | 1098 bool m_wasDestructed; |
| 1102 }; | 1099 }; |
| 1103 | 1100 |
| 1104 class PreFinalizerSubClass : public PreFinalizerBase, public PreFinalizerMixin { | 1101 class PreFinalizerSubClass : public PreFinalizerBase, public PreFinalizerMixin { |
| 1105 USING_GARBAGE_COLLECTED_MIXIN(PreFinalizerSubClass); | 1102 USING_GARBAGE_COLLECTED_MIXIN(PreFinalizerSubClass); |
| 1106 USING_PRE_FINALIZER(PreFinalizerSubClass, dispose); | 1103 USING_PRE_FINALIZER(PreFinalizerSubClass, dispose); |
| 1107 | 1104 |
| 1108 public: | 1105 public: |
| 1109 static PreFinalizerSubClass* create() { return new PreFinalizerSubClass(); } | 1106 static PreFinalizerSubClass* create() { return new PreFinalizerSubClass(); } |
| 1110 ~PreFinalizerSubClass() { m_wasDestructed = true; } | 1107 ~PreFinalizerSubClass() { m_wasDestructed = true; } |
| 1111 DEFINE_INLINE_VIRTUAL_TRACE() {} | 1108 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 1112 void dispose() { | 1109 void dispose() { |
| 1113 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerBase); | 1110 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerBase); |
| 1114 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerSubClass); | 1111 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerSubClass); |
| 1115 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerMixin); | 1112 EXPECT_FALSE(s_disposeWasCalledForPreFinalizerMixin); |
| 1116 EXPECT_FALSE(m_wasDestructed); | 1113 EXPECT_FALSE(m_wasDestructed); |
| 1117 s_disposeWasCalledForPreFinalizerSubClass = true; | 1114 s_disposeWasCalledForPreFinalizerSubClass = true; |
| 1118 } | 1115 } |
| 1119 | 1116 |
| 1120 protected: | 1117 protected: |
| 1121 PreFinalizerSubClass() : m_wasDestructed(false) { | 1118 PreFinalizerSubClass() : m_wasDestructed(false) {} |
| 1122 } | |
| 1123 bool m_wasDestructed; | 1119 bool m_wasDestructed; |
| 1124 }; | 1120 }; |
| 1125 | 1121 |
| 1126 template <typename T> | 1122 template <typename T> |
| 1127 class FinalizationObserver : public GarbageCollected<FinalizationObserver<T>> { | 1123 class FinalizationObserver : public GarbageCollected<FinalizationObserver<T>> { |
| 1128 public: | 1124 public: |
| 1129 static FinalizationObserver* create(T* data) { | 1125 static FinalizationObserver* create(T* data) { |
| 1130 return new FinalizationObserver(data); | 1126 return new FinalizationObserver(data); |
| 1131 } | 1127 } |
| 1132 bool didCallWillFinalize() const { return m_didCallWillFinalize; } | 1128 bool didCallWillFinalize() const { return m_didCallWillFinalize; } |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 private: | 1426 private: |
| 1431 Persistent<IntWrapper>* m_wrapper; | 1427 Persistent<IntWrapper>* m_wrapper; |
| 1432 }; | 1428 }; |
| 1433 | 1429 |
| 1434 class PreFinalizationAllocator | 1430 class PreFinalizationAllocator |
| 1435 : public GarbageCollectedFinalized<PreFinalizationAllocator> { | 1431 : public GarbageCollectedFinalized<PreFinalizationAllocator> { |
| 1436 USING_PRE_FINALIZER(PreFinalizationAllocator, dispose); | 1432 USING_PRE_FINALIZER(PreFinalizationAllocator, dispose); |
| 1437 | 1433 |
| 1438 public: | 1434 public: |
| 1439 PreFinalizationAllocator(Persistent<IntWrapper>* wrapper) | 1435 PreFinalizationAllocator(Persistent<IntWrapper>* wrapper) |
| 1440 : m_wrapper(wrapper) { | 1436 : m_wrapper(wrapper) {} |
| 1441 } | |
| 1442 | 1437 |
| 1443 void dispose() { | 1438 void dispose() { |
| 1444 for (int i = 0; i < 10; ++i) | 1439 for (int i = 0; i < 10; ++i) |
| 1445 *m_wrapper = IntWrapper::create(42); | 1440 *m_wrapper = IntWrapper::create(42); |
| 1446 for (int i = 0; i < 512; ++i) | 1441 for (int i = 0; i < 512; ++i) |
| 1447 new OneKiloByteObject(); | 1442 new OneKiloByteObject(); |
| 1448 for (int i = 0; i < 32; ++i) | 1443 for (int i = 0; i < 32; ++i) |
| 1449 LargeHeapObject::create(); | 1444 LargeHeapObject::create(); |
| 1450 } | 1445 } |
| 1451 | 1446 |
| (...skipping 4910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6362 "HeapVector"); | 6357 "HeapVector"); |
| 6363 static_assert( | 6358 static_assert( |
| 6364 WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::value, | 6359 WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::value, |
| 6365 "HeapDeque"); | 6360 "HeapDeque"); |
| 6366 static_assert(WTF::IsGarbageCollectedType< | 6361 static_assert(WTF::IsGarbageCollectedType< |
| 6367 HeapTerminatedArray<Member<IntWrapper>>>::value, | 6362 HeapTerminatedArray<Member<IntWrapper>>>::value, |
| 6368 "HeapTerminatedArray"); | 6363 "HeapTerminatedArray"); |
| 6369 } | 6364 } |
| 6370 | 6365 |
| 6371 } // namespace blink | 6366 } // namespace blink |
| OLD | NEW |