| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 // SimpleClassHashTraits allow empty slots in the table to be initialzed with | 225 // SimpleClassHashTraits allow empty slots in the table to be initialzed with |
| 226 // memset to zero, and we use -1 in the first part of the pair to represent | 226 // memset to zero, and we use -1 in the first part of the pair to represent |
| 227 // deleted slots. | 227 // deleted slots. |
| 228 template<> struct HashTraits<blink::PairWithWeakHandling> : blink::WeakHandlingH
ashTraits<blink::PairWithWeakHandling> { | 228 template<> struct HashTraits<blink::PairWithWeakHandling> : blink::WeakHandlingH
ashTraits<blink::PairWithWeakHandling> { |
| 229 static const bool hasIsEmptyValueFunction = true; | 229 static const bool hasIsEmptyValueFunction = true; |
| 230 static bool isEmptyValue(const blink::PairWithWeakHandling& value) { return
!value.first; } | 230 static bool isEmptyValue(const blink::PairWithWeakHandling& value) { return
!value.first; } |
| 231 static void constructDeletedValue(blink::PairWithWeakHandling& slot, bool) {
new (NotNull, &slot) blink::PairWithWeakHandling(HashTableDeletedValue); } | 231 static void constructDeletedValue(blink::PairWithWeakHandling& slot, bool) {
new (NotNull, &slot) blink::PairWithWeakHandling(HashTableDeletedValue); } |
| 232 static bool isDeletedValue(const blink::PairWithWeakHandling& value) { retur
n value.isHashTableDeletedValue(); } | 232 static bool isDeletedValue(const blink::PairWithWeakHandling& value) { retur
n value.isHashTableDeletedValue(); } |
| 233 }; | 233 }; |
| 234 | 234 |
| 235 template<> |
| 236 struct NeedsTracing<blink::PairWithWeakHandling> { |
| 237 static const bool value = NeedsTracing<blink::StrongWeakPair>::value; |
| 238 }; |
| 239 |
| 235 } // namespace WTF | 240 } // namespace WTF |
| 236 | 241 |
| 237 namespace blink { | 242 namespace blink { |
| 238 | 243 |
| 239 class TestGCScope { | 244 class TestGCScope { |
| 240 public: | 245 public: |
| 241 explicit TestGCScope(BlinkGC::StackState state) | 246 explicit TestGCScope(BlinkGC::StackState state) |
| 242 : m_state(ThreadState::current()) | 247 : m_state(ThreadState::current()) |
| 243 , m_safePointScope(state) | 248 , m_safePointScope(state) |
| 244 , m_parkedAllThreads(false) | 249 , m_parkedAllThreads(false) |
| (...skipping 3807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4052 outlineVector.append(o2); | 4057 outlineVector.append(o2); |
| 4053 | 4058 |
| 4054 PersistentHeapVector<VectorObjectInheritedTrace> vectorInheritedTrace; | 4059 PersistentHeapVector<VectorObjectInheritedTrace> vectorInheritedTrace; |
| 4055 VectorObjectInheritedTrace it1, it2; | 4060 VectorObjectInheritedTrace it1, it2; |
| 4056 vectorInheritedTrace.append(it1); | 4061 vectorInheritedTrace.append(it1); |
| 4057 vectorInheritedTrace.append(it2); | 4062 vectorInheritedTrace.append(it2); |
| 4058 | 4063 |
| 4059 preciselyCollectGarbage(); | 4064 preciselyCollectGarbage(); |
| 4060 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 4065 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
| 4061 | 4066 |
| 4062 // Since VectorObjectNoTrace has no trace method it will | |
| 4063 // not be traced and hence be collected when doing GC. | |
| 4064 // We trace items in a collection braced on the item's | |
| 4065 // having a trace method. This is determined via the | |
| 4066 // NeedsTracing trait in wtf/TypeTraits.h. | |
| 4067 PersistentHeapVector<VectorObjectNoTrace> vectorNoTrace; | |
| 4068 VectorObjectNoTrace n1, n2; | |
| 4069 vectorNoTrace.append(n1); | |
| 4070 vectorNoTrace.append(n2); | |
| 4071 preciselyCollectGarbage(); | |
| 4072 EXPECT_EQ(2, SimpleFinalizedObject::s_destructorCalls); | |
| 4073 } | 4067 } |
| 4074 preciselyCollectGarbage(); | 4068 preciselyCollectGarbage(); |
| 4075 EXPECT_EQ(8, SimpleFinalizedObject::s_destructorCalls); | 4069 EXPECT_EQ(6, SimpleFinalizedObject::s_destructorCalls); |
| 4076 } | 4070 } |
| 4077 | 4071 |
| 4078 TEST(HeapTest, EmbeddedInDeque) | 4072 TEST(HeapTest, EmbeddedInDeque) |
| 4079 { | 4073 { |
| 4080 clearOutOldGarbage(); | 4074 clearOutOldGarbage(); |
| 4081 SimpleFinalizedObject::s_destructorCalls = 0; | 4075 SimpleFinalizedObject::s_destructorCalls = 0; |
| 4082 { | 4076 { |
| 4083 PersistentHeapDeque<VectorObject, 2> inlineDeque; | 4077 PersistentHeapDeque<VectorObject, 2> inlineDeque; |
| 4084 PersistentHeapDeque<VectorObject> outlineDeque; | 4078 PersistentHeapDeque<VectorObject> outlineDeque; |
| 4085 VectorObject i1, i2; | 4079 VectorObject i1, i2; |
| 4086 inlineDeque.append(i1); | 4080 inlineDeque.append(i1); |
| 4087 inlineDeque.append(i2); | 4081 inlineDeque.append(i2); |
| 4088 | 4082 |
| 4089 VectorObject o1, o2; | 4083 VectorObject o1, o2; |
| 4090 outlineDeque.append(o1); | 4084 outlineDeque.append(o1); |
| 4091 outlineDeque.append(o2); | 4085 outlineDeque.append(o2); |
| 4092 | 4086 |
| 4093 PersistentHeapDeque<VectorObjectInheritedTrace> dequeInheritedTrace; | 4087 PersistentHeapDeque<VectorObjectInheritedTrace> dequeInheritedTrace; |
| 4094 VectorObjectInheritedTrace it1, it2; | 4088 VectorObjectInheritedTrace it1, it2; |
| 4095 dequeInheritedTrace.append(it1); | 4089 dequeInheritedTrace.append(it1); |
| 4096 dequeInheritedTrace.append(it2); | 4090 dequeInheritedTrace.append(it2); |
| 4097 | 4091 |
| 4098 preciselyCollectGarbage(); | 4092 preciselyCollectGarbage(); |
| 4099 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 4093 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
| 4100 | |
| 4101 // Since VectorObjectNoTrace has no trace method it will | |
| 4102 // not be traced and hence be collected when doing GC. | |
| 4103 // We trace items in a collection braced on the item's | |
| 4104 // having a trace method. This is determined via the | |
| 4105 // NeedsTracing trait in wtf/TypeTraits.h. | |
| 4106 PersistentHeapDeque<VectorObjectNoTrace> dequeNoTrace; | |
| 4107 VectorObjectNoTrace n1, n2; | |
| 4108 dequeNoTrace.append(n1); | |
| 4109 dequeNoTrace.append(n2); | |
| 4110 preciselyCollectGarbage(); | |
| 4111 EXPECT_EQ(2, SimpleFinalizedObject::s_destructorCalls); | |
| 4112 } | 4094 } |
| 4113 preciselyCollectGarbage(); | 4095 preciselyCollectGarbage(); |
| 4114 EXPECT_EQ(8, SimpleFinalizedObject::s_destructorCalls); | 4096 EXPECT_EQ(6, SimpleFinalizedObject::s_destructorCalls); |
| 4115 } | 4097 } |
| 4116 | 4098 |
| 4117 class InlinedVectorObject { | 4099 class InlinedVectorObject { |
| 4118 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 4100 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 4119 public: | 4101 public: |
| 4120 InlinedVectorObject() | 4102 InlinedVectorObject() |
| 4121 { | 4103 { |
| 4122 } | 4104 } |
| 4123 ~InlinedVectorObject() | 4105 ~InlinedVectorObject() |
| 4124 { | 4106 { |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4521 } | 4503 } |
| 4522 } | 4504 } |
| 4523 | 4505 |
| 4524 EXPECT_FALSE(RefCountedWithDestructor::s_wasDestructed); | 4506 EXPECT_FALSE(RefCountedWithDestructor::s_wasDestructed); |
| 4525 set.clear(); | 4507 set.clear(); |
| 4526 EXPECT_TRUE(RefCountedWithDestructor::s_wasDestructed); | 4508 EXPECT_TRUE(RefCountedWithDestructor::s_wasDestructed); |
| 4527 } | 4509 } |
| 4528 | 4510 |
| 4529 TEST(HeapTest, DestructorsCalled) | 4511 TEST(HeapTest, DestructorsCalled) |
| 4530 { | 4512 { |
| 4531 HeapHashMap<SimpleClassWithDestructor*, OwnPtr<SimpleClassWithDestructor>> m
ap; | 4513 HeapHashMap<Member<IntWrapper>, OwnPtr<SimpleClassWithDestructor>> map; |
| 4532 SimpleClassWithDestructor* hasDestructor = new SimpleClassWithDestructor(); | 4514 SimpleClassWithDestructor* hasDestructor = new SimpleClassWithDestructor(); |
| 4533 map.add(hasDestructor, adoptPtr(hasDestructor)); | 4515 map.add(IntWrapper::create(1), adoptPtr(hasDestructor)); |
| 4534 SimpleClassWithDestructor::s_wasDestructed = false; | 4516 SimpleClassWithDestructor::s_wasDestructed = false; |
| 4535 map.clear(); | 4517 map.clear(); |
| 4536 EXPECT_TRUE(SimpleClassWithDestructor::s_wasDestructed); | 4518 EXPECT_TRUE(SimpleClassWithDestructor::s_wasDestructed); |
| 4537 | |
| 4538 destructorsCalledOnClear<HeapHashSet<RefPtr<RefCountedWithDestructor>>>(fals
e); | |
| 4539 destructorsCalledOnClear<HeapListHashSet<RefPtr<RefCountedWithDestructor>>>(
false); | |
| 4540 destructorsCalledOnClear<HeapLinkedHashSet<RefPtr<RefCountedWithDestructor>>
>(false); | |
| 4541 destructorsCalledOnClear<HeapHashSet<RefPtr<RefCountedWithDestructor>>>(true
); | |
| 4542 destructorsCalledOnClear<HeapListHashSet<RefPtr<RefCountedWithDestructor>>>(
true); | |
| 4543 destructorsCalledOnClear<HeapLinkedHashSet<RefPtr<RefCountedWithDestructor>>
>(true); | |
| 4544 | |
| 4545 destructorsCalledOnGC<HeapHashSet<RefPtr<RefCountedWithDestructor>>>(false); | |
| 4546 destructorsCalledOnGC<HeapListHashSet<RefPtr<RefCountedWithDestructor>>>(fal
se); | |
| 4547 destructorsCalledOnGC<HeapLinkedHashSet<RefPtr<RefCountedWithDestructor>>>(f
alse); | |
| 4548 destructorsCalledOnGC<HeapHashSet<RefPtr<RefCountedWithDestructor>>>(true); | |
| 4549 destructorsCalledOnGC<HeapListHashSet<RefPtr<RefCountedWithDestructor>>>(tru
e); | |
| 4550 destructorsCalledOnGC<HeapLinkedHashSet<RefPtr<RefCountedWithDestructor>>>(t
rue); | |
| 4551 } | 4519 } |
| 4552 | 4520 |
| 4553 class MixinA : public GarbageCollectedMixin { | 4521 class MixinA : public GarbageCollectedMixin { |
| 4554 public: | 4522 public: |
| 4555 MixinA() : m_obj(IntWrapper::create(100)) { } | 4523 MixinA() : m_obj(IntWrapper::create(100)) { } |
| 4556 DEFINE_INLINE_VIRTUAL_TRACE() | 4524 DEFINE_INLINE_VIRTUAL_TRACE() |
| 4557 { | 4525 { |
| 4558 s_traceCount++; | 4526 s_traceCount++; |
| 4559 visitor->trace(m_obj); | 4527 visitor->trace(m_obj); |
| 4560 } | 4528 } |
| (...skipping 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6095 }; | 6063 }; |
| 6096 | 6064 |
| 6097 class PartObjectWithRef { | 6065 class PartObjectWithRef { |
| 6098 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 6066 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 6099 public: | 6067 public: |
| 6100 PartObjectWithRef(int i) | 6068 PartObjectWithRef(int i) |
| 6101 : m_value(SimpleRefValue::create(i)) | 6069 : m_value(SimpleRefValue::create(i)) |
| 6102 { | 6070 { |
| 6103 } | 6071 } |
| 6104 | 6072 |
| 6073 DEFINE_INLINE_TRACE() { } |
| 6074 |
| 6105 int value() const { return m_value->value(); } | 6075 int value() const { return m_value->value(); } |
| 6106 | 6076 |
| 6107 private: | 6077 private: |
| 6108 RefPtr<SimpleRefValue> m_value; | 6078 RefPtr<SimpleRefValue> m_value; |
| 6109 }; | 6079 }; |
| 6110 | 6080 |
| 6111 } // namespace blink | 6081 } // namespace blink |
| 6112 | 6082 |
| 6113 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::PartObjectWithRef); | 6083 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::PartObjectWithRef); |
| 6114 | 6084 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6522 }; | 6492 }; |
| 6523 | 6493 |
| 6524 } // namespace | 6494 } // namespace |
| 6525 | 6495 |
| 6526 TEST(HeapTest, TestClearOnShutdown) | 6496 TEST(HeapTest, TestClearOnShutdown) |
| 6527 { | 6497 { |
| 6528 ThreadedClearOnShutdownTester::test(); | 6498 ThreadedClearOnShutdownTester::test(); |
| 6529 } | 6499 } |
| 6530 | 6500 |
| 6531 } // namespace blink | 6501 } // namespace blink |
| OLD | NEW |