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 5654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5665 } | 5665 } |
5666 | 5666 |
5667 static volatile IntWrapper* s_workerObjectPointer; | 5667 static volatile IntWrapper* s_workerObjectPointer; |
5668 }; | 5668 }; |
5669 | 5669 |
5670 TEST(HeapTest, RecursiveMutex) | 5670 TEST(HeapTest, RecursiveMutex) |
5671 { | 5671 { |
5672 RecursiveLockingTester::test(); | 5672 RecursiveLockingTester::test(); |
5673 } | 5673 } |
5674 | 5674 |
| 5675 class CrossThreadPersistentOnMainThreadTester { |
| 5676 public: |
| 5677 static void test() |
| 5678 { |
| 5679 MutexLocker locker(mainThreadMutex()); |
| 5680 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); |
| 5681 workerThread->postTask(FROM_HERE, new Task(threadSafeBind(workerThreadMa
in))); |
| 5682 |
| 5683 parkMainThread(); |
| 5684 |
| 5685 // (Temporarily) detach main thread and wake the worker thread, so that
it |
| 5686 // can do its detach(). |
| 5687 ThreadState::detachMainThread(); |
| 5688 wakeWorkerThread(); |
| 5689 |
| 5690 parkMainThread(); |
| 5691 ThreadState::attachMainThread(); |
| 5692 } |
| 5693 |
| 5694 private: |
| 5695 |
| 5696 static void workerThreadMain() |
| 5697 { |
| 5698 MutexLocker locker(workerThreadMutex()); |
| 5699 |
| 5700 // Start up a worker thread and have it detach after the main thread has
. |
| 5701 // Do this to verify that CrossThreadPersistent<>s referring to objects |
| 5702 // on one of the main thread's heaps does not upset the CTP invalidation |
| 5703 // pass that ThreadState::detach() performs. |
| 5704 ThreadState::attach(); |
| 5705 |
| 5706 CrossThreadPersistent<IntWrapper> persistent(IntWrapper::create(43)); |
| 5707 |
| 5708 // Wait for the main thread to detach. |
| 5709 wakeMainThread(); |
| 5710 parkWorkerThread(); |
| 5711 |
| 5712 ThreadState::detach(); |
| 5713 wakeMainThread(); |
| 5714 } |
| 5715 }; |
| 5716 |
| 5717 TEST(HeapTest, CrossThreadPersistentOnMainThread) |
| 5718 { |
| 5719 CrossThreadPersistent<IntWrapper> persistent(IntWrapper::create(42)); |
| 5720 CrossThreadPersistentOnMainThreadTester::test(); |
| 5721 } |
| 5722 |
5675 template<typename T> | 5723 template<typename T> |
5676 class TraceIfNeededTester : public GarbageCollectedFinalized<TraceIfNeededTester
<T>> { | 5724 class TraceIfNeededTester : public GarbageCollectedFinalized<TraceIfNeededTester
<T>> { |
5677 public: | 5725 public: |
5678 static TraceIfNeededTester<T>* create() { return new TraceIfNeededTester<T>(
); } | 5726 static TraceIfNeededTester<T>* create() { return new TraceIfNeededTester<T>(
); } |
5679 static TraceIfNeededTester<T>* create(const T& obj) { return new TraceIfNeed
edTester<T>(obj); } | 5727 static TraceIfNeededTester<T>* create(const T& obj) { return new TraceIfNeed
edTester<T>(obj); } |
5680 DEFINE_INLINE_TRACE() { TraceIfNeeded<T>::trace(visitor, m_obj); } | 5728 DEFINE_INLINE_TRACE() { TraceIfNeeded<T>::trace(visitor, m_obj); } |
5681 T& obj() { return m_obj; } | 5729 T& obj() { return m_obj; } |
5682 ~TraceIfNeededTester() { } | 5730 ~TraceIfNeededTester() { } |
5683 private: | 5731 private: |
5684 TraceIfNeededTester() { } | 5732 TraceIfNeededTester() { } |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6307 Persistent<IntWrapper> object = new IntWrapper(20); | 6355 Persistent<IntWrapper> object = new IntWrapper(20); |
6308 OwnPtr<WeakPersistentHolder> holder = adoptPtr(new WeakPersistentHolder(obje
ct)); | 6356 OwnPtr<WeakPersistentHolder> holder = adoptPtr(new WeakPersistentHolder(obje
ct)); |
6309 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | 6357 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); |
6310 EXPECT_TRUE(holder->object()); | 6358 EXPECT_TRUE(holder->object()); |
6311 object = nullptr; | 6359 object = nullptr; |
6312 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | 6360 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); |
6313 EXPECT_FALSE(holder->object()); | 6361 EXPECT_FALSE(holder->object()); |
6314 } | 6362 } |
6315 | 6363 |
6316 } // namespace blink | 6364 } // namespace blink |
OLD | NEW |