| 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 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 // so as to avoid possible warnings about linker duplicates. | 768 // so as to avoid possible warnings about linker duplicates. |
| 769 // Override operator new to allocate IntNode subtype objects onto | 769 // Override operator new to allocate IntNode subtype objects onto |
| 770 // the dedicated heap for blink::Node. | 770 // the dedicated heap for blink::Node. |
| 771 // | 771 // |
| 772 // TODO(haraken): untangling the heap unit tests from Blink would | 772 // TODO(haraken): untangling the heap unit tests from Blink would |
| 773 // simplify and avoid running into this problem - http://crbug.com/425381 | 773 // simplify and avoid running into this problem - http://crbug.com/425381 |
| 774 GC_PLUGIN_IGNORE("crbug.com/443854") | 774 GC_PLUGIN_IGNORE("crbug.com/443854") |
| 775 void* operator new(size_t size) | 775 void* operator new(size_t size) |
| 776 { | 776 { |
| 777 ThreadState* state = ThreadState::current(); | 777 ThreadState* state = ThreadState::current(); |
| 778 return Heap::allocateOnHeapIndex(state, size, BlinkGC::NodeHeapIndex, GC
InfoTrait<IntNode>::index()); | 778 return Heap::allocateOnArenaIndex(state, size, BlinkGC::NodeArenaIndex,
GCInfoTrait<IntNode>::index()); |
| 779 } | 779 } |
| 780 | 780 |
| 781 static IntNode* create(int i) | 781 static IntNode* create(int i) |
| 782 { | 782 { |
| 783 return new IntNode(i); | 783 return new IntNode(i); |
| 784 } | 784 } |
| 785 | 785 |
| 786 DEFINE_INLINE_TRACE() { } | 786 DEFINE_INLINE_TRACE() { } |
| 787 | 787 |
| 788 int value() { return m_value; } | 788 int value() { return m_value; } |
| (...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2099 // the finalizer on all three objects. | 2099 // the finalizer on all three objects. |
| 2100 preciselyCollectGarbage(); | 2100 preciselyCollectGarbage(); |
| 2101 EXPECT_EQ(2, HeapTestSubClass::s_destructorCalls); | 2101 EXPECT_EQ(2, HeapTestSubClass::s_destructorCalls); |
| 2102 EXPECT_EQ(3, HeapTestSuperClass::s_destructorCalls); | 2102 EXPECT_EQ(3, HeapTestSuperClass::s_destructorCalls); |
| 2103 // Destructors not called again when GCing again. | 2103 // Destructors not called again when GCing again. |
| 2104 preciselyCollectGarbage(); | 2104 preciselyCollectGarbage(); |
| 2105 EXPECT_EQ(2, HeapTestSubClass::s_destructorCalls); | 2105 EXPECT_EQ(2, HeapTestSubClass::s_destructorCalls); |
| 2106 EXPECT_EQ(3, HeapTestSuperClass::s_destructorCalls); | 2106 EXPECT_EQ(3, HeapTestSuperClass::s_destructorCalls); |
| 2107 } | 2107 } |
| 2108 | 2108 |
| 2109 TEST(HeapTest, TypedHeapSanity) | 2109 TEST(HeapTest, TypedArenaSanity) |
| 2110 { | 2110 { |
| 2111 // We use TraceCounter for allocating an object on the general heap. | 2111 // We use TraceCounter for allocating an object on the general heap. |
| 2112 Persistent<TraceCounter> generalHeapObject = TraceCounter::create(); | 2112 Persistent<TraceCounter> generalHeapObject = TraceCounter::create(); |
| 2113 Persistent<IntNode> typedHeapObject = IntNode::create(0); | 2113 Persistent<IntNode> typedHeapObject = IntNode::create(0); |
| 2114 EXPECT_NE(pageFromObject(generalHeapObject.get()), | 2114 EXPECT_NE(pageFromObject(generalHeapObject.get()), |
| 2115 pageFromObject(typedHeapObject.get())); | 2115 pageFromObject(typedHeapObject.get())); |
| 2116 } | 2116 } |
| 2117 | 2117 |
| 2118 TEST(HeapTest, NoAllocation) | 2118 TEST(HeapTest, NoAllocation) |
| 2119 { | 2119 { |
| (...skipping 3571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5691 // until the main thread has done its GC. | 5691 // until the main thread has done its GC. |
| 5692 wakeWorkerThread(); | 5692 wakeWorkerThread(); |
| 5693 | 5693 |
| 5694 preciselyCollectGarbage(); | 5694 preciselyCollectGarbage(); |
| 5695 | 5695 |
| 5696 // The worker thread should not have swept yet since it is waiting | 5696 // The worker thread should not have swept yet since it is waiting |
| 5697 // to get the global mutex. | 5697 // to get the global mutex. |
| 5698 EXPECT_EQ(0, DestructorLockingObject::s_destructorCalls); | 5698 EXPECT_EQ(0, DestructorLockingObject::s_destructorCalls); |
| 5699 } | 5699 } |
| 5700 // At this point the main thread releases the global lock and the worker | 5700 // At this point the main thread releases the global lock and the worker |
| 5701 // can acquire it and do its sweep of its heaps. Just wait for the worke
r | 5701 // can acquire it and do its sweep of its arenas. Just wait for the work
er |
| 5702 // to complete its sweep and check the result. | 5702 // to complete its sweep and check the result. |
| 5703 parkMainThread(); | 5703 parkMainThread(); |
| 5704 EXPECT_EQ(1, DestructorLockingObject::s_destructorCalls); | 5704 EXPECT_EQ(1, DestructorLockingObject::s_destructorCalls); |
| 5705 } | 5705 } |
| 5706 | 5706 |
| 5707 private: | 5707 private: |
| 5708 static void workerThreadMain() | 5708 static void workerThreadMain() |
| 5709 { | 5709 { |
| 5710 MutexLocker locker(workerThreadMutex()); | 5710 MutexLocker locker(workerThreadMutex()); |
| 5711 ThreadState::attach(); | 5711 ThreadState::attach(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5767 } | 5767 } |
| 5768 | 5768 |
| 5769 private: | 5769 private: |
| 5770 | 5770 |
| 5771 static void workerThreadMain() | 5771 static void workerThreadMain() |
| 5772 { | 5772 { |
| 5773 MutexLocker locker(workerThreadMutex()); | 5773 MutexLocker locker(workerThreadMutex()); |
| 5774 | 5774 |
| 5775 // Start up a worker thread and have it detach after the main thread has
. | 5775 // Start up a worker thread and have it detach after the main thread has
. |
| 5776 // Do this to verify that CrossThreadPersistent<>s referring to objects | 5776 // Do this to verify that CrossThreadPersistent<>s referring to objects |
| 5777 // on one of the main thread's heaps does not upset the CTP invalidation | 5777 // on one of the main thread's arenas does not upset the CTP invalidatio
n |
| 5778 // pass that ThreadState::detach() performs. | 5778 // pass that ThreadState::detach() performs. |
| 5779 ThreadState::attach(); | 5779 ThreadState::attach(); |
| 5780 | 5780 |
| 5781 CrossThreadPersistent<IntWrapper> persistent(IntWrapper::create(43)); | 5781 CrossThreadPersistent<IntWrapper> persistent(IntWrapper::create(43)); |
| 5782 | 5782 |
| 5783 // Wait for the main thread to detach. | 5783 // Wait for the main thread to detach. |
| 5784 wakeMainThread(); | 5784 wakeMainThread(); |
| 5785 parkWorkerThread(); | 5785 parkWorkerThread(); |
| 5786 | 5786 |
| 5787 ThreadState::detach(); | 5787 ThreadState::detach(); |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6526 EXPECT_EQ(1u, vector2.size()); | 6526 EXPECT_EQ(1u, vector2.size()); |
| 6527 // TODO(Oilpan): when Vector.h's contiguous container support no longer disables | 6527 // TODO(Oilpan): when Vector.h's contiguous container support no longer disables |
| 6528 // Vector<>s with inline capacity, remove. | 6528 // Vector<>s with inline capacity, remove. |
| 6529 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER) | 6529 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER) |
| 6530 EXPECT_EQ(16u, vector1.capacity()); | 6530 EXPECT_EQ(16u, vector1.capacity()); |
| 6531 EXPECT_EQ(16u, vector2.capacity()); | 6531 EXPECT_EQ(16u, vector2.capacity()); |
| 6532 #endif | 6532 #endif |
| 6533 } | 6533 } |
| 6534 | 6534 |
| 6535 } // namespace blink | 6535 } // namespace blink |
| OLD | NEW |