| 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 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 for (int i = 0; i < 32; ++i) | 1590 for (int i = 0; i < 32; ++i) |
| 1591 LargeHeapObject::create(); | 1591 LargeHeapObject::create(); |
| 1592 } | 1592 } |
| 1593 | 1593 |
| 1594 DEFINE_INLINE_TRACE() { } | 1594 DEFINE_INLINE_TRACE() { } |
| 1595 | 1595 |
| 1596 private: | 1596 private: |
| 1597 Persistent<IntWrapper>* m_wrapper; | 1597 Persistent<IntWrapper>* m_wrapper; |
| 1598 }; | 1598 }; |
| 1599 | 1599 |
| 1600 class PreFinalizationAllocator : public GarbageCollectedFinalized<PreFinalizatio
nAllocator> { |
| 1601 USING_PRE_FINALIZER(PreFinalizationAllocator, dispose); |
| 1602 public: |
| 1603 PreFinalizationAllocator(Persistent<IntWrapper>* wrapper) |
| 1604 : m_wrapper(wrapper) |
| 1605 { |
| 1606 ThreadState::current()->registerPreFinalizer(*this); |
| 1607 } |
| 1608 |
| 1609 void dispose() |
| 1610 { |
| 1611 for (int i = 0; i < 10; ++i) |
| 1612 *m_wrapper = IntWrapper::create(42); |
| 1613 for (int i = 0; i < 512; ++i) |
| 1614 new OneKiloByteObject(); |
| 1615 for (int i = 0; i < 32; ++i) |
| 1616 LargeHeapObject::create(); |
| 1617 } |
| 1618 |
| 1619 DEFINE_INLINE_TRACE() { } |
| 1620 |
| 1621 private: |
| 1622 Persistent<IntWrapper>* m_wrapper; |
| 1623 }; |
| 1624 |
| 1600 TEST(HeapTest, Transition) | 1625 TEST(HeapTest, Transition) |
| 1601 { | 1626 { |
| 1602 { | 1627 { |
| 1603 RefPtrWillBePersistent<TransitionRefCounted> refCounted = TransitionRefC
ounted::create(); | 1628 RefPtrWillBePersistent<TransitionRefCounted> refCounted = TransitionRefC
ounted::create(); |
| 1604 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); | 1629 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); |
| 1605 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GC
WithSweep, Heap::ForcedGC); | 1630 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GC
WithSweep, Heap::ForcedGC); |
| 1606 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); | 1631 EXPECT_EQ(1, TransitionRefCounted::s_aliveCount); |
| 1607 } | 1632 } |
| 1608 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | 1633 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); |
| 1609 EXPECT_EQ(0, TransitionRefCounted::s_aliveCount); | 1634 EXPECT_EQ(0, TransitionRefCounted::s_aliveCount); |
| (...skipping 2681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4291 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | 4316 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); |
| 4292 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 4317 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
| 4293 EXPECT_EQ(0, OneKiloByteObject::s_destructorCalls); | 4318 EXPECT_EQ(0, OneKiloByteObject::s_destructorCalls); |
| 4294 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); | 4319 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); |
| 4295 // Check that the wrapper allocated during finalization is not | 4320 // Check that the wrapper allocated during finalization is not |
| 4296 // swept away and zapped later in the same sweeping phase. | 4321 // swept away and zapped later in the same sweeping phase. |
| 4297 EXPECT_EQ(42, wrapper->value()); | 4322 EXPECT_EQ(42, wrapper->value()); |
| 4298 | 4323 |
| 4299 wrapper.clear(); | 4324 wrapper.clear(); |
| 4300 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | 4325 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); |
| 4326 // The 42 IntWrappers were the ones allocated in ~FinalizationAllocator |
| 4327 // and the ones allocated in LargeHeapObject. |
| 4301 EXPECT_EQ(42, IntWrapper::s_destructorCalls); | 4328 EXPECT_EQ(42, IntWrapper::s_destructorCalls); |
| 4302 EXPECT_EQ(512, OneKiloByteObject::s_destructorCalls); | 4329 EXPECT_EQ(512, OneKiloByteObject::s_destructorCalls); |
| 4303 EXPECT_EQ(32, LargeHeapObject::s_destructorCalls); | 4330 EXPECT_EQ(32, LargeHeapObject::s_destructorCalls); |
| 4331 } |
| 4332 |
| 4333 TEST(HeapTest, AllocationDuringPrefinalizer) |
| 4334 { |
| 4335 clearOutOldGarbage(); |
| 4336 IntWrapper::s_destructorCalls = 0; |
| 4337 OneKiloByteObject::s_destructorCalls = 0; |
| 4338 LargeHeapObject::s_destructorCalls = 0; |
| 4339 |
| 4340 Persistent<IntWrapper> wrapper; |
| 4341 new PreFinalizationAllocator(&wrapper); |
| 4342 |
| 4343 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); |
| 4344 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
| 4345 EXPECT_EQ(0, OneKiloByteObject::s_destructorCalls); |
| 4346 EXPECT_EQ(0, LargeHeapObject::s_destructorCalls); |
| 4347 // Check that the wrapper allocated during finalization is not |
| 4348 // swept away and zapped later in the same sweeping phase. |
| 4349 EXPECT_EQ(42, wrapper->value()); |
| 4350 |
| 4351 wrapper.clear(); |
| 4352 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); |
| 4353 // The 42 IntWrappers were the ones allocated in the pre-finalizer |
| 4354 // of PreFinalizationAllocator and the ones allocated in LargeHeapObject. |
| 4355 EXPECT_EQ(42, IntWrapper::s_destructorCalls); |
| 4356 EXPECT_EQ(512, OneKiloByteObject::s_destructorCalls); |
| 4357 EXPECT_EQ(32, LargeHeapObject::s_destructorCalls); |
| 4304 } | 4358 } |
| 4305 | 4359 |
| 4306 class SimpleClassWithDestructor { | 4360 class SimpleClassWithDestructor { |
| 4307 public: | 4361 public: |
| 4308 SimpleClassWithDestructor() { } | 4362 SimpleClassWithDestructor() { } |
| 4309 ~SimpleClassWithDestructor() | 4363 ~SimpleClassWithDestructor() |
| 4310 { | 4364 { |
| 4311 s_wasDestructed = true; | 4365 s_wasDestructed = true; |
| 4312 } | 4366 } |
| 4313 static bool s_wasDestructed; | 4367 static bool s_wasDestructed; |
| (...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6124 { | 6178 { |
| 6125 Persistent<ClassWithMember> object = ClassWithMember::create(); | 6179 Persistent<ClassWithMember> object = ClassWithMember::create(); |
| 6126 EXPECT_EQ(0, object->traceCount()); | 6180 EXPECT_EQ(0, object->traceCount()); |
| 6127 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); | 6181 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); |
| 6128 EXPECT_TRUE(mixin); | 6182 EXPECT_TRUE(mixin); |
| 6129 EXPECT_GT(object->traceCount(), 0); | 6183 EXPECT_GT(object->traceCount(), 0); |
| 6130 EXPECT_GT(mixin->traceCount(), 0); | 6184 EXPECT_GT(mixin->traceCount(), 0); |
| 6131 } | 6185 } |
| 6132 | 6186 |
| 6133 } // namespace blink | 6187 } // namespace blink |
| OLD | NEW |