| 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 5127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5138 | 5138 |
| 5139 // Wait for the worker thread to sweep its heaps before checking. | 5139 // Wait for the worker thread to sweep its heaps before checking. |
| 5140 { | 5140 { |
| 5141 SafePointScope scope(ThreadState::NoHeapPointersOnStack); | 5141 SafePointScope scope(ThreadState::NoHeapPointersOnStack); |
| 5142 parkMainThread(); | 5142 parkMainThread(); |
| 5143 } | 5143 } |
| 5144 } | 5144 } |
| 5145 | 5145 |
| 5146 private: | 5146 private: |
| 5147 | 5147 |
| 5148 static HeapHashSet<WeakMember<IntWrapper>>* allocateCollection() | 5148 using WeakCollectionType = HeapHashMap<WeakMember<IntWrapper>, Member<IntWra
pper>>; |
| 5149 |
| 5150 static WeakCollectionType* allocateCollection() |
| 5149 { | 5151 { |
| 5150 // Create a weak collection that is kept alive by a persistent | 5152 // Create a weak collection that is kept alive by a persistent |
| 5151 // and keep the contents alive with a persistents as | 5153 // and keep the contents alive with a persistents as |
| 5152 // well. | 5154 // well. |
| 5153 Persistent<IntWrapper> wrapper1 = IntWrapper::create(32); | 5155 Persistent<IntWrapper> wrapper1 = IntWrapper::create(32); |
| 5154 Persistent<IntWrapper> wrapper2 = IntWrapper::create(32); | 5156 Persistent<IntWrapper> wrapper2 = IntWrapper::create(32); |
| 5155 Persistent<IntWrapper> wrapper3 = IntWrapper::create(32); | 5157 Persistent<IntWrapper> wrapper3 = IntWrapper::create(32); |
| 5156 Persistent<IntWrapper> wrapper4 = IntWrapper::create(32); | 5158 Persistent<IntWrapper> wrapper4 = IntWrapper::create(32); |
| 5157 Persistent<IntWrapper> wrapper5 = IntWrapper::create(32); | 5159 Persistent<IntWrapper> wrapper5 = IntWrapper::create(32); |
| 5158 Persistent<IntWrapper> wrapper6 = IntWrapper::create(32); | 5160 Persistent<IntWrapper> wrapper6 = IntWrapper::create(32); |
| 5159 Persistent<HeapHashSet<WeakMember<IntWrapper>>> weakCollection = new Hea
pHashSet<WeakMember<IntWrapper>>; | 5161 Persistent<WeakCollectionType> weakCollection = new WeakCollectionType; |
| 5160 weakCollection->add(wrapper1); | 5162 weakCollection->add(wrapper1, wrapper1); |
| 5161 weakCollection->add(wrapper2); | 5163 weakCollection->add(wrapper2, wrapper2); |
| 5162 weakCollection->add(wrapper3); | 5164 weakCollection->add(wrapper3, wrapper3); |
| 5163 weakCollection->add(wrapper4); | 5165 weakCollection->add(wrapper4, wrapper4); |
| 5164 weakCollection->add(wrapper5); | 5166 weakCollection->add(wrapper5, wrapper5); |
| 5165 weakCollection->add(wrapper6); | 5167 weakCollection->add(wrapper6, wrapper6); |
| 5166 | 5168 |
| 5167 // Signal the main thread that the worker is done with its allocation. | 5169 // Signal the main thread that the worker is done with its allocation. |
| 5168 wakeMainThread(); | 5170 wakeMainThread(); |
| 5169 | 5171 |
| 5170 { | 5172 { |
| 5171 // Wait for the main thread to do two GCs without sweeping | 5173 // Wait for the main thread to do two GCs without sweeping |
| 5172 // this thread heap. The worker waits within a safepoint, | 5174 // this thread heap. The worker waits within a safepoint, |
| 5173 // but there is no sweeping until leaving the safepoint | 5175 // but there is no sweeping until leaving the safepoint |
| 5174 // scope. If the weak collection backing is marked dead | 5176 // scope. If the weak collection backing is marked dead |
| 5175 // because of this we will not get strongification in the | 5177 // because of this we will not get strongification in the |
| 5176 // GC we force when we continue. | 5178 // GC we force when we continue. |
| 5177 SafePointScope scope(ThreadState::NoHeapPointersOnStack); | 5179 SafePointScope scope(ThreadState::NoHeapPointersOnStack); |
| 5178 parkWorkerThread(); | 5180 parkWorkerThread(); |
| 5179 } | 5181 } |
| 5180 | 5182 |
| 5181 return weakCollection; | 5183 return weakCollection; |
| 5182 } | 5184 } |
| 5183 | 5185 |
| 5184 static void workerThreadMain() | 5186 static void workerThreadMain() |
| 5185 { | 5187 { |
| 5186 MutexLocker locker(workerThreadMutex()); | 5188 MutexLocker locker(workerThreadMutex()); |
| 5187 | 5189 |
| 5188 ThreadState::attach(); | 5190 ThreadState::attach(); |
| 5189 | 5191 |
| 5190 { | 5192 { |
| 5191 Persistent<HeapHashSet<WeakMember<IntWrapper>>> collection = allocat
eCollection(); | 5193 Persistent<WeakCollectionType> collection = allocateCollection(); |
| 5192 { | 5194 { |
| 5193 // Prevent weak processing with an iterator and GC. | 5195 // Prevent weak processing with an iterator and GC. |
| 5194 HeapHashSet<WeakMember<IntWrapper>>::iterator it = collection->b
egin(); | 5196 WeakCollectionType::iterator it = collection->begin(); |
| 5195 Heap::collectGarbage(ThreadState::HeapPointersOnStack, ThreadSta
te::GCWithSweep, Heap::ForcedGC); | 5197 Heap::collectGarbage(ThreadState::HeapPointersOnStack, ThreadSta
te::GCWithSweep, Heap::ForcedGC); |
| 5196 | 5198 |
| 5197 // The backing should be strongified because of the iterator. | 5199 // The backing should be strongified because of the iterator. |
| 5198 EXPECT_EQ(6u, collection->size()); | 5200 EXPECT_EQ(6u, collection->size()); |
| 5199 EXPECT_EQ(32, (*it)->value()); | 5201 EXPECT_EQ(32, it->value->value()); |
| 5200 } | 5202 } |
| 5201 | 5203 |
| 5202 // Disregarding the iterator but keeping the collection alive | 5204 // Disregarding the iterator but keeping the collection alive |
| 5203 // with a persistent should lead to weak processing. | 5205 // with a persistent should lead to weak processing. |
| 5204 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState
::GCWithSweep, Heap::ForcedGC); | 5206 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState
::GCWithSweep, Heap::ForcedGC); |
| 5205 EXPECT_EQ(0u, collection->size()); | 5207 EXPECT_EQ(0u, collection->size()); |
| 5206 } | 5208 } |
| 5207 | 5209 |
| 5208 wakeMainThread(); | 5210 wakeMainThread(); |
| 5209 ThreadState::detach(); | 5211 ThreadState::detach(); |
| (...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6003 { | 6005 { |
| 6004 Persistent<ClassWithMember> object = ClassWithMember::create(); | 6006 Persistent<ClassWithMember> object = ClassWithMember::create(); |
| 6005 EXPECT_EQ(0, object->traceCount()); | 6007 EXPECT_EQ(0, object->traceCount()); |
| 6006 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); | 6008 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); |
| 6007 EXPECT_TRUE(mixin); | 6009 EXPECT_TRUE(mixin); |
| 6008 EXPECT_GT(object->traceCount(), 0); | 6010 EXPECT_GT(object->traceCount(), 0); |
| 6009 EXPECT_GT(mixin->traceCount(), 0); | 6011 EXPECT_GT(mixin->traceCount(), 0); |
| 6010 } | 6012 } |
| 6011 | 6013 |
| 6012 } // namespace blink | 6014 } // namespace blink |
| OLD | NEW |