Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: Source/platform/heap/HeapTest.cpp

Issue 1125613002: Oilpan: handle thread-local weak tracing slightly better. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rename some methods Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/heap/Heap.cpp ('k') | Source/platform/heap/StackFrameDepth.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 { \ 237 { \
238 return ensureMarked(objectPointer); \ 238 return ensureMarked(objectPointer); \
239 } 239 }
240 240
241 class CountingVisitor : public Visitor { 241 class CountingVisitor : public Visitor {
242 public: 242 public:
243 CountingVisitor() 243 CountingVisitor()
244 : Visitor(Visitor::ThreadLocalMarking) 244 : Visitor(Visitor::ThreadLocalMarking)
245 , m_count(0) 245 , m_count(0)
246 { 246 {
247 StackFrameDepth::configureStackLimit();
248 } 247 }
249 248
250 virtual void mark(const void* object, TraceCallback) override 249 virtual void mark(const void* object, TraceCallback) override
251 { 250 {
252 if (object) 251 if (object)
253 m_count++; 252 m_count++;
254 } 253 }
255 254
256 virtual void markHeader(HeapObjectHeader* header, TraceCallback callback) ov erride 255 virtual void markHeader(HeapObjectHeader* header, TraceCallback callback) ov erride
257 { 256 {
(...skipping 17 matching lines...) Expand all
275 if (!objectPointer || isMarked(objectPointer)) 274 if (!objectPointer || isMarked(objectPointer))
276 return false; 275 return false;
277 markNoTracing(objectPointer); 276 markNoTracing(objectPointer);
278 return true; 277 return true;
279 } 278 }
280 279
281 size_t count() { return m_count; } 280 size_t count() { return m_count; }
282 void reset() { m_count = 0; } 281 void reset() { m_count = 0; }
283 282
284 private: 283 private:
284 StackFrameDepthScope m_scope;
285 size_t m_count; 285 size_t m_count;
286 }; 286 };
287 287
288 #undef DEFINE_VISITOR_METHODS 288 #undef DEFINE_VISITOR_METHODS
289 289
290 class SimpleObject : public GarbageCollected<SimpleObject> { 290 class SimpleObject : public GarbageCollected<SimpleObject> {
291 public: 291 public:
292 static SimpleObject* create() { return new SimpleObject(); } 292 static SimpleObject* create() { return new SimpleObject(); }
293 DEFINE_INLINE_TRACE() { } 293 DEFINE_INLINE_TRACE() { }
294 char getPayload(int i) { return payload[i]; } 294 char getPayload(int i) { return payload[i]; }
(...skipping 4843 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW
« no previous file with comments | « Source/platform/heap/Heap.cpp ('k') | Source/platform/heap/StackFrameDepth.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698