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: third_party/WebKit/Source/platform/heap/HeapTest.cpp

Issue 2687283002: Remove ParkThreadsScope (Closed)
Patch Set: temp Created 3 years, 10 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
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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 static const bool value = IsTraceable<blink::StrongWeakPair>::value; 271 static const bool value = IsTraceable<blink::StrongWeakPair>::value;
272 }; 272 };
273 273
274 } // namespace WTF 274 } // namespace WTF
275 275
276 namespace blink { 276 namespace blink {
277 277
278 class TestGCScope { 278 class TestGCScope {
279 public: 279 public:
280 explicit TestGCScope(BlinkGC::StackState state) 280 explicit TestGCScope(BlinkGC::StackState state)
281 : m_state(ThreadState::current()), 281 : m_state(ThreadState::current()), m_safePointScope(state) {
282 m_safePointScope(state),
283 m_parkedAllThreads(false) {
284 ASSERT(m_state->checkThread()); 282 ASSERT(m_state->checkThread());
285 if (LIKELY(m_state->heap().park())) { 283 m_state->heap().preGC();
286 m_state->heap().preGC();
287 m_parkedAllThreads = true;
288 }
289 } 284 }
290 285
291 bool allThreadsParked() { return m_parkedAllThreads; } 286 ~TestGCScope() { m_state->heap().postGC(BlinkGC::GCWithSweep); }
292
293 ~TestGCScope() {
294 // Only cleanup if we parked all threads in which case the GC happened
295 // and we need to resume the other threads.
296 if (LIKELY(m_parkedAllThreads)) {
297 m_state->heap().postGC(BlinkGC::GCWithSweep);
298 m_state->heap().resume();
299 }
300 }
301 287
302 private: 288 private:
303 ThreadState* m_state; 289 ThreadState* m_state;
304 SafePointScope m_safePointScope; 290 SafePointScope m_safePointScope;
305 bool m_parkedAllThreads; // False if we fail to park all threads
306 }; 291 };
307 292
308 class SimpleObject : public GarbageCollected<SimpleObject> { 293 class SimpleObject : public GarbageCollected<SimpleObject> {
309 public: 294 public:
310 static SimpleObject* create() { return new SimpleObject(); } 295 static SimpleObject* create() { return new SimpleObject(); }
311 DEFINE_INLINE_TRACE() {} 296 DEFINE_INLINE_TRACE() {}
312 char getPayload(int i) { return payload[i]; } 297 char getPayload(int i) { return payload[i]; }
313 // This virtual method is unused but it is here to make sure 298 // This virtual method is unused but it is here to make sure
314 // that this object has a vtable. This object is used 299 // that this object has a vtable. This object is used
315 // as the super class for objects that also have garbage 300 // as the super class for objects that also have garbage
(...skipping 3463 matching lines...) Expand 10 before | Expand all | Expand 10 after
3779 // causes the object start bitmap to be computed which requires the heap 3764 // causes the object start bitmap to be computed which requires the heap
3780 // to be in a consistent state (e.g. the free allocation area must be put 3765 // to be in a consistent state (e.g. the free allocation area must be put
3781 // into a free list header). However when we call makeConsistentForGC it 3766 // into a free list header). However when we call makeConsistentForGC it
3782 // also clears out the freelists so we have to rebuild those before trying 3767 // also clears out the freelists so we have to rebuild those before trying
3783 // to allocate anything again. We do this by forcing a GC after doing the 3768 // to allocate anything again. We do this by forcing a GC after doing the
3784 // checkAndMarkPointer tests. 3769 // checkAndMarkPointer tests.
3785 { 3770 {
3786 TestGCScope scope(BlinkGC::HeapPointersOnStack); 3771 TestGCScope scope(BlinkGC::HeapPointersOnStack);
3787 ThreadState::GCForbiddenScope gcScope(ThreadState::current()); 3772 ThreadState::GCForbiddenScope gcScope(ThreadState::current());
3788 Visitor visitor(ThreadState::current(), Visitor::GlobalMarking); 3773 Visitor visitor(ThreadState::current(), Visitor::GlobalMarking);
3789 EXPECT_TRUE(scope.allThreadsParked()); // Fail the test if we could not
3790 // park all threads.
3791 heap.flushHeapDoesNotContainCache(); 3774 heap.flushHeapDoesNotContainCache();
3792 for (size_t i = 0; i < objectAddresses.size(); i++) { 3775 for (size_t i = 0; i < objectAddresses.size(); i++) {
3793 EXPECT_TRUE(heap.checkAndMarkPointer(&visitor, objectAddresses[i], 3776 EXPECT_TRUE(heap.checkAndMarkPointer(&visitor, objectAddresses[i],
3794 reportMarkedPointer)); 3777 reportMarkedPointer));
3795 EXPECT_TRUE(heap.checkAndMarkPointer(&visitor, endAddresses[i], 3778 EXPECT_TRUE(heap.checkAndMarkPointer(&visitor, endAddresses[i],
3796 reportMarkedPointer)); 3779 reportMarkedPointer));
3797 } 3780 }
3798 EXPECT_EQ(objectAddresses.size() * 2, s_checkMarkCount); 3781 EXPECT_EQ(objectAddresses.size() * 2, s_checkMarkCount);
3799 s_checkMarkCount = 0; 3782 s_checkMarkCount = 0;
3800 EXPECT_TRUE(heap.checkAndMarkPointer(&visitor, largeObjectAddress, 3783 EXPECT_TRUE(heap.checkAndMarkPointer(&visitor, largeObjectAddress,
3801 reportMarkedPointer)); 3784 reportMarkedPointer));
3802 EXPECT_TRUE(heap.checkAndMarkPointer(&visitor, largeObjectEndAddress, 3785 EXPECT_TRUE(heap.checkAndMarkPointer(&visitor, largeObjectEndAddress,
3803 reportMarkedPointer)); 3786 reportMarkedPointer));
3804 EXPECT_EQ(2ul, s_checkMarkCount); 3787 EXPECT_EQ(2ul, s_checkMarkCount);
3805 s_checkMarkCount = 0ul; 3788 s_checkMarkCount = 0ul;
3806 } 3789 }
3807 // This forces a GC without stack scanning which results in the objects 3790 // This forces a GC without stack scanning which results in the objects
3808 // being collected. This will also rebuild the above mentioned freelists, 3791 // being collected. This will also rebuild the above mentioned freelists,
3809 // however we don't rely on that below since we don't have any allocations. 3792 // however we don't rely on that below since we don't have any allocations.
3810 clearOutOldGarbage(); 3793 clearOutOldGarbage();
3811 { 3794 {
3812 TestGCScope scope(BlinkGC::HeapPointersOnStack); 3795 TestGCScope scope(BlinkGC::HeapPointersOnStack);
3813 ThreadState::GCForbiddenScope gcScope(ThreadState::current()); 3796 ThreadState::GCForbiddenScope gcScope(ThreadState::current());
3814 Visitor visitor(ThreadState::current(), Visitor::GlobalMarking); 3797 Visitor visitor(ThreadState::current(), Visitor::GlobalMarking);
3815 EXPECT_TRUE(scope.allThreadsParked());
3816 heap.flushHeapDoesNotContainCache(); 3798 heap.flushHeapDoesNotContainCache();
3817 for (size_t i = 0; i < objectAddresses.size(); i++) { 3799 for (size_t i = 0; i < objectAddresses.size(); i++) {
3818 // We would like to assert that checkAndMarkPointer returned false 3800 // We would like to assert that checkAndMarkPointer returned false
3819 // here because the pointers no longer point into a valid object 3801 // here because the pointers no longer point into a valid object
3820 // (it's been freed by the GCs. But checkAndMarkPointer will return 3802 // (it's been freed by the GCs. But checkAndMarkPointer will return
3821 // true for any pointer that points into a heap page, regardless of 3803 // true for any pointer that points into a heap page, regardless of
3822 // whether it points at a valid object (this ensures the 3804 // whether it points at a valid object (this ensures the
3823 // correctness of the page-based on-heap address caches), so we 3805 // correctness of the page-based on-heap address caches), so we
3824 // can't make that assert. 3806 // can't make that assert.
3825 heap.checkAndMarkPointer(&visitor, objectAddresses[i], 3807 heap.checkAndMarkPointer(&visitor, objectAddresses[i],
(...skipping 2551 matching lines...) Expand 10 before | Expand all | Expand 10 after
6377 "HeapVector"); 6359 "HeapVector");
6378 static_assert( 6360 static_assert(
6379 WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::value, 6361 WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::value,
6380 "HeapDeque"); 6362 "HeapDeque");
6381 static_assert(WTF::IsGarbageCollectedType< 6363 static_assert(WTF::IsGarbageCollectedType<
6382 HeapTerminatedArray<Member<IntWrapper>>>::value, 6364 HeapTerminatedArray<Member<IntWrapper>>>::value,
6383 "HeapTerminatedArray"); 6365 "HeapTerminatedArray");
6384 } 6366 }
6385 6367
6386 } // namespace blink 6368 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/Heap.cpp ('k') | third_party/WebKit/Source/platform/heap/ThreadState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698