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

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

Issue 2846843002: [blink] Unique pointers in Platform.h (Closed)
Patch Set: fix compilation (and again) Created 3 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
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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 }; 463 };
464 464
465 int IntWrapper::destructor_calls_ = 0; 465 int IntWrapper::destructor_calls_ = 0;
466 int OffHeapInt::destructor_calls_ = 0; 466 int OffHeapInt::destructor_calls_ = 0;
467 467
468 class ThreadedTesterBase { 468 class ThreadedTesterBase {
469 protected: 469 protected:
470 static void Test(ThreadedTesterBase* tester) { 470 static void Test(ThreadedTesterBase* tester) {
471 Vector<std::unique_ptr<WebThread>, kNumberOfThreads> threads; 471 Vector<std::unique_ptr<WebThread>, kNumberOfThreads> threads;
472 for (int i = 0; i < kNumberOfThreads; i++) { 472 for (int i = 0; i < kNumberOfThreads; i++) {
473 threads.push_back(WTF::WrapUnique( 473 threads.push_back(
474 Platform::Current()->CreateThread("blink gc testing thread"))); 474 Platform::Current()->CreateThread("blink gc testing thread"));
475 threads.back()->GetWebTaskRunner()->PostTask( 475 threads.back()->GetWebTaskRunner()->PostTask(
476 BLINK_FROM_HERE, 476 BLINK_FROM_HERE,
477 CrossThreadBind(ThreadFunc, CrossThreadUnretained(tester))); 477 CrossThreadBind(ThreadFunc, CrossThreadUnretained(tester)));
478 } 478 }
479 while (tester->threads_to_finish_) { 479 while (tester->threads_to_finish_) {
480 testing::YieldCurrentThread(); 480 testing::YieldCurrentThread();
481 } 481 }
482 delete tester; 482 delete tester;
483 } 483 }
484 484
(...skipping 4940 matching lines...) Expand 10 before | Expand all | Expand 10 after
5425 MutexLocker locker(WorkerThreadMutex()); 5425 MutexLocker locker(WorkerThreadMutex());
5426 WorkerThreadCondition().Signal(); 5426 WorkerThreadCondition().Signal();
5427 } 5427 }
5428 5428
5429 class ThreadedStrongificationTester { 5429 class ThreadedStrongificationTester {
5430 public: 5430 public:
5431 static void Test() { 5431 static void Test() {
5432 IntWrapper::destructor_calls_ = 0; 5432 IntWrapper::destructor_calls_ = 0;
5433 5433
5434 MutexLocker locker(MainThreadMutex()); 5434 MutexLocker locker(MainThreadMutex());
5435 std::unique_ptr<WebThread> worker_thread = WTF::WrapUnique( 5435 std::unique_ptr<WebThread> worker_thread =
5436 Platform::Current()->CreateThread("Test Worker Thread")); 5436 Platform::Current()->CreateThread("Test Worker Thread");
5437 worker_thread->GetWebTaskRunner()->PostTask( 5437 worker_thread->GetWebTaskRunner()->PostTask(
5438 BLINK_FROM_HERE, CrossThreadBind(WorkerThreadMain)); 5438 BLINK_FROM_HERE, CrossThreadBind(WorkerThreadMain));
5439 5439
5440 // Wait for the worker thread initialization. The worker 5440 // Wait for the worker thread initialization. The worker
5441 // allocates a weak collection where both collection and 5441 // allocates a weak collection where both collection and
5442 // contents are kept alive via persistent pointers. 5442 // contents are kept alive via persistent pointers.
5443 ParkMainThread(); 5443 ParkMainThread();
5444 5444
5445 // Perform two garbage collections where the worker thread does 5445 // Perform two garbage collections where the worker thread does
5446 // not wake up in between. This will cause us to remove marks 5446 // not wake up in between. This will cause us to remove marks
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
5524 TEST(HeapTest, ThreadedStrongification) { 5524 TEST(HeapTest, ThreadedStrongification) {
5525 ThreadedStrongificationTester::Test(); 5525 ThreadedStrongificationTester::Test();
5526 } 5526 }
5527 5527
5528 class MemberSameThreadCheckTester { 5528 class MemberSameThreadCheckTester {
5529 public: 5529 public:
5530 void Test() { 5530 void Test() {
5531 IntWrapper::destructor_calls_ = 0; 5531 IntWrapper::destructor_calls_ = 0;
5532 5532
5533 MutexLocker locker(MainThreadMutex()); 5533 MutexLocker locker(MainThreadMutex());
5534 std::unique_ptr<WebThread> worker_thread = WTF::WrapUnique( 5534 std::unique_ptr<WebThread> worker_thread =
5535 Platform::Current()->CreateThread("Test Worker Thread")); 5535 Platform::Current()->CreateThread("Test Worker Thread");
5536 worker_thread->GetWebTaskRunner()->PostTask( 5536 worker_thread->GetWebTaskRunner()->PostTask(
5537 BLINK_FROM_HERE, 5537 BLINK_FROM_HERE,
5538 CrossThreadBind(&MemberSameThreadCheckTester::WorkerThreadMain, 5538 CrossThreadBind(&MemberSameThreadCheckTester::WorkerThreadMain,
5539 CrossThreadUnretained(this))); 5539 CrossThreadUnretained(this)));
5540 5540
5541 ParkMainThread(); 5541 ParkMainThread();
5542 } 5542 }
5543 5543
5544 private: 5544 private:
5545 Member<IntWrapper> wrapper_; 5545 Member<IntWrapper> wrapper_;
(...skipping 21 matching lines...) Expand all
5567 } 5567 }
5568 #endif 5568 #endif
5569 #endif 5569 #endif
5570 5570
5571 class PersistentSameThreadCheckTester { 5571 class PersistentSameThreadCheckTester {
5572 public: 5572 public:
5573 void Test() { 5573 void Test() {
5574 IntWrapper::destructor_calls_ = 0; 5574 IntWrapper::destructor_calls_ = 0;
5575 5575
5576 MutexLocker locker(MainThreadMutex()); 5576 MutexLocker locker(MainThreadMutex());
5577 std::unique_ptr<WebThread> worker_thread = WTF::WrapUnique( 5577 std::unique_ptr<WebThread> worker_thread =
5578 Platform::Current()->CreateThread("Test Worker Thread")); 5578 Platform::Current()->CreateThread("Test Worker Thread");
5579 worker_thread->GetWebTaskRunner()->PostTask( 5579 worker_thread->GetWebTaskRunner()->PostTask(
5580 BLINK_FROM_HERE, 5580 BLINK_FROM_HERE,
5581 CrossThreadBind(&PersistentSameThreadCheckTester::WorkerThreadMain, 5581 CrossThreadBind(&PersistentSameThreadCheckTester::WorkerThreadMain,
5582 CrossThreadUnretained(this))); 5582 CrossThreadUnretained(this)));
5583 5583
5584 ParkMainThread(); 5584 ParkMainThread();
5585 } 5585 }
5586 5586
5587 private: 5587 private:
5588 Persistent<IntWrapper> wrapper_; 5588 Persistent<IntWrapper> wrapper_;
(...skipping 21 matching lines...) Expand all
5610 } 5610 }
5611 #endif 5611 #endif
5612 #endif 5612 #endif
5613 5613
5614 class MarkingSameThreadCheckTester { 5614 class MarkingSameThreadCheckTester {
5615 public: 5615 public:
5616 void Test() { 5616 void Test() {
5617 IntWrapper::destructor_calls_ = 0; 5617 IntWrapper::destructor_calls_ = 0;
5618 5618
5619 MutexLocker locker(MainThreadMutex()); 5619 MutexLocker locker(MainThreadMutex());
5620 std::unique_ptr<WebThread> worker_thread = WTF::WrapUnique( 5620 std::unique_ptr<WebThread> worker_thread =
5621 Platform::Current()->CreateThread("Test Worker Thread")); 5621 Platform::Current()->CreateThread("Test Worker Thread");
5622 Persistent<MainThreadObject> main_thread_object = new MainThreadObject(); 5622 Persistent<MainThreadObject> main_thread_object = new MainThreadObject();
5623 worker_thread->GetWebTaskRunner()->PostTask( 5623 worker_thread->GetWebTaskRunner()->PostTask(
5624 BLINK_FROM_HERE, 5624 BLINK_FROM_HERE,
5625 CrossThreadBind(&MarkingSameThreadCheckTester::WorkerThreadMain, 5625 CrossThreadBind(&MarkingSameThreadCheckTester::WorkerThreadMain,
5626 CrossThreadUnretained(this), 5626 CrossThreadUnretained(this),
5627 WrapCrossThreadPersistent(main_thread_object.Get()))); 5627 WrapCrossThreadPersistent(main_thread_object.Get())));
5628 ParkMainThread(); 5628 ParkMainThread();
5629 // This will try to mark MainThreadObject when it tries to mark IntWrapper 5629 // This will try to mark MainThreadObject when it tries to mark IntWrapper
5630 // it should crash. 5630 // it should crash.
5631 PreciselyCollectGarbage(); 5631 PreciselyCollectGarbage();
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
6398 // pointing to it on the main thread, clear the reference in the worker 6398 // pointing to it on the main thread, clear the reference in the worker
6399 // thread, run a GC in the worker thread, and see if the 6399 // thread, run a GC in the worker thread, and see if the
6400 // CrossThreadWeakPersistent is cleared. 6400 // CrossThreadWeakPersistent is cleared.
6401 6401
6402 DestructorLockingObject::destructor_calls_ = 0; 6402 DestructorLockingObject::destructor_calls_ = 0;
6403 6403
6404 // Step 1: Initiate a worker thread, and wait for |object| to get allocated on 6404 // Step 1: Initiate a worker thread, and wait for |object| to get allocated on
6405 // the worker thread. 6405 // the worker thread.
6406 MutexLocker main_thread_mutex_locker(MainThreadMutex()); 6406 MutexLocker main_thread_mutex_locker(MainThreadMutex());
6407 std::unique_ptr<WebThread> worker_thread = 6407 std::unique_ptr<WebThread> worker_thread =
6408 WTF::WrapUnique(Platform::Current()->CreateThread("Test Worker Thread")); 6408 Platform::Current()->CreateThread("Test Worker Thread");
6409 DestructorLockingObject* object = nullptr; 6409 DestructorLockingObject* object = nullptr;
6410 worker_thread->GetWebTaskRunner()->PostTask( 6410 worker_thread->GetWebTaskRunner()->PostTask(
6411 BLINK_FROM_HERE, 6411 BLINK_FROM_HERE,
6412 CrossThreadBind(WorkerThreadMainForCrossThreadWeakPersistentTest, 6412 CrossThreadBind(WorkerThreadMainForCrossThreadWeakPersistentTest,
6413 CrossThreadUnretained(&object))); 6413 CrossThreadUnretained(&object)));
6414 ParkMainThread(); 6414 ParkMainThread();
6415 6415
6416 // Step 3: Set up a CrossThreadWeakPersistent. 6416 // Step 3: Set up a CrossThreadWeakPersistent.
6417 ASSERT_TRUE(object); 6417 ASSERT_TRUE(object);
6418 CrossThreadWeakPersistent<DestructorLockingObject> 6418 CrossThreadWeakPersistent<DestructorLockingObject>
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
6698 map.insert(key, IntWrapper::Create(i)); 6698 map.insert(key, IntWrapper::Create(i));
6699 } 6699 }
6700 6700
6701 EXPECT_FALSE(string.Impl()->HasOneRef()); 6701 EXPECT_FALSE(string.Impl()->HasOneRef());
6702 map.clear(); 6702 map.clear();
6703 6703
6704 EXPECT_TRUE(string.Impl()->HasOneRef()); 6704 EXPECT_TRUE(string.Impl()->HasOneRef());
6705 } 6705 }
6706 6706
6707 } // namespace blink 6707 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698