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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 static int s_destructorCalls; | 724 static int s_destructorCalls; |
725 | 725 |
726 DEFINE_INLINE_TRACE() { } | 726 DEFINE_INLINE_TRACE() { } |
727 | 727 |
728 private: | 728 private: |
729 SimpleFinalizedObject() { } | 729 SimpleFinalizedObject() { } |
730 }; | 730 }; |
731 | 731 |
732 int SimpleFinalizedObject::s_destructorCalls = 0; | 732 int SimpleFinalizedObject::s_destructorCalls = 0; |
733 | 733 |
734 class Node : public GarbageCollected<Node> { | 734 class IntNode : public GarbageCollected<IntNode> { |
735 public: | 735 public: |
736 static Node* create(int i) | 736 static IntNode* create(int i) |
737 { | 737 { |
738 return new Node(i); | 738 return new IntNode(i); |
739 } | 739 } |
740 | 740 |
741 DEFINE_INLINE_TRACE() { } | 741 DEFINE_INLINE_TRACE() { } |
742 | 742 |
743 int value() { return m_value; } | 743 int value() { return m_value; } |
744 | 744 |
745 private: | 745 private: |
746 Node(int i) : m_value(i) { } | 746 IntNode(int i) : m_value(i) { } |
747 int m_value; | 747 int m_value; |
748 }; | 748 }; |
749 | 749 |
| 750 // IntNode is used to test typed heap allocation. Instead of |
| 751 // redefining blink::Node to our test version, we keep it separate |
| 752 // so as to avoid possible warnings about linker duplicates. |
| 753 // Provide a HeapIndexTrait<> specialization to assign the test |
| 754 // object to Node's typed heap instead. |
| 755 // |
| 756 // FIXME: untangling the heap unit tests from Blink would simplify |
| 757 // and avoid running into this problem - http://crbug.com/425381 |
| 758 template<> |
| 759 struct HeapIndexTrait<IntNode> { |
| 760 static int index() { return NodeHeapIndex; } |
| 761 }; |
| 762 |
750 class Bar : public GarbageCollectedFinalized<Bar> { | 763 class Bar : public GarbageCollectedFinalized<Bar> { |
751 public: | 764 public: |
752 static Bar* create() | 765 static Bar* create() |
753 { | 766 { |
754 return new Bar(); | 767 return new Bar(); |
755 } | 768 } |
756 | 769 |
757 void finalizeGarbageCollectedObject() | 770 void finalizeGarbageCollectedObject() |
758 { | 771 { |
759 EXPECT_TRUE(m_magic == magic); | 772 EXPECT_TRUE(m_magic == magic); |
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1841 // Destructors not called again when GCing again. | 1854 // Destructors not called again when GCing again. |
1842 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGCForTesting); | 1855 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGCForTesting); |
1843 EXPECT_EQ(2, HeapTestSubClass::s_destructorCalls); | 1856 EXPECT_EQ(2, HeapTestSubClass::s_destructorCalls); |
1844 EXPECT_EQ(3, HeapTestSuperClass::s_destructorCalls); | 1857 EXPECT_EQ(3, HeapTestSuperClass::s_destructorCalls); |
1845 } | 1858 } |
1846 | 1859 |
1847 TEST(HeapTest, TypedHeapSanity) | 1860 TEST(HeapTest, TypedHeapSanity) |
1848 { | 1861 { |
1849 // We use TraceCounter for allocating an object on the general heap. | 1862 // We use TraceCounter for allocating an object on the general heap. |
1850 Persistent<TraceCounter> generalHeapObject = TraceCounter::create(); | 1863 Persistent<TraceCounter> generalHeapObject = TraceCounter::create(); |
1851 Persistent<Node> typedHeapObject = Node::create(0); | 1864 Persistent<IntNode> typedHeapObject = IntNode::create(0); |
1852 EXPECT_NE(pageFromObject(generalHeapObject.get()), | 1865 EXPECT_NE(pageFromObject(generalHeapObject.get()), |
1853 pageFromObject(typedHeapObject.get())); | 1866 pageFromObject(typedHeapObject.get())); |
1854 } | 1867 } |
1855 | 1868 |
1856 TEST(HeapTest, NoAllocation) | 1869 TEST(HeapTest, NoAllocation) |
1857 { | 1870 { |
1858 ThreadState* state = ThreadState::current(); | 1871 ThreadState* state = ThreadState::current(); |
1859 EXPECT_TRUE(state->isAllocationAllowed()); | 1872 EXPECT_TRUE(state->isAllocationAllowed()); |
1860 { | 1873 { |
1861 // Disallow allocation | 1874 // Disallow allocation |
(...skipping 3532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5394 { | 5407 { |
5395 AllocInSuperConstructorArgument* object = new AllocInSuperConstructorArgumen
t(); | 5408 AllocInSuperConstructorArgument* object = new AllocInSuperConstructorArgumen
t(); |
5396 EXPECT_TRUE(object); | 5409 EXPECT_TRUE(object); |
5397 Heap::collectAllGarbage(); | 5410 Heap::collectAllGarbage(); |
5398 } | 5411 } |
5399 | 5412 |
5400 class NonNodeAllocatingNodeInDestructor : public GarbageCollectedFinalized<NonNo
deAllocatingNodeInDestructor> { | 5413 class NonNodeAllocatingNodeInDestructor : public GarbageCollectedFinalized<NonNo
deAllocatingNodeInDestructor> { |
5401 public: | 5414 public: |
5402 ~NonNodeAllocatingNodeInDestructor() | 5415 ~NonNodeAllocatingNodeInDestructor() |
5403 { | 5416 { |
5404 s_node = new Persistent<Node>(Node::create(10)); | 5417 s_node = new Persistent<IntNode>(IntNode::create(10)); |
5405 } | 5418 } |
5406 | 5419 |
5407 DEFINE_INLINE_TRACE() { } | 5420 DEFINE_INLINE_TRACE() { } |
5408 | 5421 |
5409 static Persistent<Node>* s_node; | 5422 static Persistent<IntNode>* s_node; |
5410 }; | 5423 }; |
5411 | 5424 |
5412 Persistent<Node>* NonNodeAllocatingNodeInDestructor::s_node = 0; | 5425 Persistent<IntNode>* NonNodeAllocatingNodeInDestructor::s_node = 0; |
5413 | 5426 |
5414 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) | 5427 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) |
5415 { | 5428 { |
5416 new NonNodeAllocatingNodeInDestructor(); | 5429 new NonNodeAllocatingNodeInDestructor(); |
5417 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGCForTesting); | 5430 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGCForTesting); |
5418 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); | 5431 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); |
5419 delete NonNodeAllocatingNodeInDestructor::s_node; | 5432 delete NonNodeAllocatingNodeInDestructor::s_node; |
5420 NonNodeAllocatingNodeInDestructor::s_node = 0; | 5433 NonNodeAllocatingNodeInDestructor::s_node = 0; |
5421 } | 5434 } |
5422 | 5435 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5675 { | 5688 { |
5676 Persistent<ClassWithMember> object = ClassWithMember::create(); | 5689 Persistent<ClassWithMember> object = ClassWithMember::create(); |
5677 EXPECT_EQ(0, object->traceCount()); | 5690 EXPECT_EQ(0, object->traceCount()); |
5678 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); | 5691 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); |
5679 EXPECT_TRUE(mixin); | 5692 EXPECT_TRUE(mixin); |
5680 EXPECT_GT(object->traceCount(), 0); | 5693 EXPECT_GT(object->traceCount(), 0); |
5681 EXPECT_GT(mixin->traceCount(), 0); | 5694 EXPECT_GT(mixin->traceCount(), 0); |
5682 } | 5695 } |
5683 | 5696 |
5684 } // namespace blink | 5697 } // namespace blink |
OLD | NEW |