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 4642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4653 | 4653 |
4654 // Nothing should have been collected/destructed. | 4654 // Nothing should have been collected/destructed. |
4655 EXPECT_EQ(0, CrossThreadObject::s_destructorCalls); | 4655 EXPECT_EQ(0, CrossThreadObject::s_destructorCalls); |
4656 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 4656 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
4657 | 4657 |
4658 // Put cto into a stack value. This is used to check that a conserva
tive | 4658 // Put cto into a stack value. This is used to check that a conserva
tive |
4659 // GC succeeds even though we are tracing the other thread heap afte
r | 4659 // GC succeeds even though we are tracing the other thread heap afte
r |
4660 // shutting it down. | 4660 // shutting it down. |
4661 stackPtrValue = reinterpret_cast<uintptr_t>(cto.get()); | 4661 stackPtrValue = reinterpret_cast<uintptr_t>(cto.get()); |
4662 } | 4662 } |
4663 RELEASE_ASSERT(stackPtrValue); | |
4664 | |
4665 // At this point it is "programatically" okay to shut down the worker th
read | 4663 // At this point it is "programatically" okay to shut down the worker th
read |
4666 // since the cto object should be dead. However out stackPtrValue will c
ause a | 4664 // since the cto object should be dead. However out stackPtrValue will c
ause a |
4667 // trace of the object when doing a conservative GC. | 4665 // trace of the object when doing a conservative GC. |
4668 // The worker thread's thread local GC's should just add the worker thre
ad's | 4666 // The worker thread's thread local GC's should just add the worker thre
ad's |
4669 // pages to the heap after finalizing IntWrapper. | 4667 // pages to the heap after finalizing IntWrapper. |
4670 wakeWorkerThread(); | 4668 wakeWorkerThread(); |
4671 | 4669 |
4672 // Wait for the worker to shutdown. | 4670 // Wait for the worker to shutdown. |
4673 parkMainThread(); | 4671 parkMainThread(); |
4674 | 4672 |
4675 // After the worker thread has detached it should have finalized the | 4673 // After the worker thread has detached it should have finalized the |
4676 // IntWrapper object on its heaps. Since there has been no global GC | 4674 // IntWrapper object on its heaps. Since there has been no global GC |
4677 // the cto object should not have been finalized. | 4675 // the cto object should not have been finalized. |
4678 EXPECT_EQ(0, CrossThreadObject::s_destructorCalls); | 4676 EXPECT_EQ(0, CrossThreadObject::s_destructorCalls); |
4679 EXPECT_EQ(1, IntWrapper::s_destructorCalls); | 4677 EXPECT_EQ(1, IntWrapper::s_destructorCalls); |
4680 | 4678 |
4681 // Now do a conservative GC. The stackPtrValue should keep cto alive | 4679 // Now do a conservative GC. The stackPtrValue should keep cto alive |
4682 // and will also cause the orphaned page of the other thread to be | 4680 // and will also cause the orphaned page of the other thread to be |
4683 // traced. At this point cto should still not be finalized. | 4681 // traced. At this point cto should still not be finalized. |
4684 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | 4682 Heap::collectGarbage(ThreadState::HeapPointersOnStack); |
4685 EXPECT_EQ(0, CrossThreadObject::s_destructorCalls); | 4683 EXPECT_EQ(0, CrossThreadObject::s_destructorCalls); |
4686 EXPECT_EQ(1, IntWrapper::s_destructorCalls); | 4684 EXPECT_EQ(1, IntWrapper::s_destructorCalls); |
4687 | 4685 |
| 4686 // This release assert is here to ensure the stackValuePtr is not |
| 4687 // optimized away before doing the above conservative GC. If the |
| 4688 // EXPECT_EQ(0, CrossThreadObject::s_destructorCalls) call above |
| 4689 // starts failing it means we have to find a better way to ensure |
| 4690 // the stackPtrValue is not optimized away. |
| 4691 RELEASE_ASSERT(stackPtrValue); |
| 4692 |
4688 // Do a GC with no pointers on the stack to see the cto being collected. | 4693 // Do a GC with no pointers on the stack to see the cto being collected. |
4689 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 4694 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
4690 EXPECT_EQ(1, CrossThreadObject::s_destructorCalls); | 4695 EXPECT_EQ(1, CrossThreadObject::s_destructorCalls); |
4691 EXPECT_EQ(1, IntWrapper::s_destructorCalls); | 4696 EXPECT_EQ(1, IntWrapper::s_destructorCalls); |
4692 } | 4697 } |
4693 | 4698 |
4694 private: | 4699 private: |
4695 static void workerThreadMain(void* data) | 4700 static void workerThreadMain(void* data) |
4696 { | 4701 { |
4697 MutexLocker locker(workerThreadMutex()); | 4702 MutexLocker locker(workerThreadMutex()); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4866 // Regression test for out of bounds call through vtable. | 4871 // Regression test for out of bounds call through vtable. |
4867 // Passes if it doesn't crash. | 4872 // Passes if it doesn't crash. |
4868 TEST(HeapTest, GarbageCollectionDuringMixinConstruction) | 4873 TEST(HeapTest, GarbageCollectionDuringMixinConstruction) |
4869 { | 4874 { |
4870 ClassWithGarbageCollectingMixinConstructor* a = | 4875 ClassWithGarbageCollectingMixinConstructor* a = |
4871 new ClassWithGarbageCollectingMixinConstructor(); | 4876 new ClassWithGarbageCollectingMixinConstructor(); |
4872 a->verify(); | 4877 a->verify(); |
4873 } | 4878 } |
4874 | 4879 |
4875 } // WebCore namespace | 4880 } // WebCore namespace |
OLD | NEW |