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

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

Issue 1265103003: Invalidate cross-thread persistents on heap termination. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: simplify the invalidation as ref-clearing Created 5 years, 4 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 | « no previous file | Source/platform/heap/PersistentNode.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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 }; 492 };
493 493
494 class ThreadedHeapTester : public ThreadedTesterBase { 494 class ThreadedHeapTester : public ThreadedTesterBase {
495 public: 495 public:
496 static void test() 496 static void test()
497 { 497 {
498 ThreadedTesterBase::test(new ThreadedHeapTester); 498 ThreadedTesterBase::test(new ThreadedHeapTester);
499 } 499 }
500 500
501 protected: 501 protected:
502 using GlobalIntWrapperPersistent = CrossThreadPersistent<IntWrapper>;
503
504 PassOwnPtr<GlobalIntWrapperPersistent> createGlobalPersistent(int value)
505 {
506 return adoptPtr(new GlobalIntWrapperPersistent(IntWrapper::create(value) ));
507 }
508
502 void runThread() override 509 void runThread() override
503 { 510 {
511 OwnPtr<GlobalIntWrapperPersistent> longLivingPersistent;
504 ThreadState::attach(); 512 ThreadState::attach();
505 513
514 longLivingPersistent = createGlobalPersistent(0x2a2a2a2a);
506 int gcCount = 0; 515 int gcCount = 0;
507 while (!done()) { 516 while (!done()) {
508 ThreadState::current()->safePoint(ThreadState::NoHeapPointersOnStack ); 517 ThreadState::current()->safePoint(ThreadState::NoHeapPointersOnStack );
509 { 518 {
510 Persistent<IntWrapper> wrapper; 519 Persistent<IntWrapper> wrapper;
511 520
512 typedef CrossThreadPersistent<IntWrapper> GlobalIntWrapperPersis tent; 521 OwnPtr<GlobalIntWrapperPersistent> globalPersistent = createGlob alPersistent(0x0ed0cabb);
513 OwnPtr<GlobalIntWrapperPersistent> globalPersistent = adoptPtr(n ew GlobalIntWrapperPersistent(IntWrapper::create(0x0ed0cabb)));
514 522
515 for (int i = 0; i < numberOfAllocations; i++) { 523 for (int i = 0; i < numberOfAllocations; i++) {
516 wrapper = IntWrapper::create(0x0bbac0de); 524 wrapper = IntWrapper::create(0x0bbac0de);
517 if (!(i % 10)) { 525 if (!(i % 10)) {
518 globalPersistent = adoptPtr(new GlobalIntWrapperPersiste nt(IntWrapper::create(0x0ed0cabb))); 526 globalPersistent = createGlobalPersistent(0x0ed0cabb);
519 } 527 }
520 SafePointScope scope(ThreadState::NoHeapPointersOnStack); 528 SafePointScope scope(ThreadState::NoHeapPointersOnStack);
521 Platform::current()->yieldCurrentThread(); 529 Platform::current()->yieldCurrentThread();
522 } 530 }
523 531
524 if (gcCount < gcPerThread) { 532 if (gcCount < gcPerThread) {
525 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, Thr eadState::GCWithSweep, Heap::ForcedGC); 533 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, Thr eadState::GCWithSweep, Heap::ForcedGC);
526 gcCount++; 534 gcCount++;
527 atomicIncrement(&m_gcCount); 535 atomicIncrement(&m_gcCount);
528 } 536 }
529 537
530 // Taking snapshot shouldn't have any bad side effect. 538 // Taking snapshot shouldn't have any bad side effect.
531 // TODO(haraken): This snapshot GC causes crashes, so disable 539 // TODO(haraken): This snapshot GC causes crashes, so disable
532 // it at the moment. Fix the crash and enable it. 540 // it at the moment. Fix the crash and enable it.
533 // Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, Thre adState::TakeSnapshot, Heap::ForcedGC); 541 // Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, Thre adState::TakeSnapshot, Heap::ForcedGC);
534 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadS tate::GCWithSweep, Heap::ForcedGC); 542 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadS tate::GCWithSweep, Heap::ForcedGC);
535 EXPECT_EQ(wrapper->value(), 0x0bbac0de); 543 EXPECT_EQ(wrapper->value(), 0x0bbac0de);
536 EXPECT_EQ((*globalPersistent)->value(), 0x0ed0cabb); 544 EXPECT_EQ((*globalPersistent)->value(), 0x0ed0cabb);
537 } 545 }
538 SafePointScope scope(ThreadState::NoHeapPointersOnStack); 546 SafePointScope scope(ThreadState::NoHeapPointersOnStack);
539 Platform::current()->yieldCurrentThread(); 547 Platform::current()->yieldCurrentThread();
540 } 548 }
549
550 // Intentionally leak the cross-thread persistent so as to verify
551 // that later GCs correctly handle cross-thread persistents that
552 // refer to finalized objects after their heaps have been detached
553 // and freed.
554 EXPECT_TRUE(longLivingPersistent.leakPtr());
555
541 ThreadState::detach(); 556 ThreadState::detach();
542 atomicDecrement(&m_threadsToFinish); 557 atomicDecrement(&m_threadsToFinish);
543 } 558 }
544 }; 559 };
545 560
546 class ThreadedWeaknessTester : public ThreadedTesterBase { 561 class ThreadedWeaknessTester : public ThreadedTesterBase {
547 public: 562 public:
548 static void test() 563 static void test()
549 { 564 {
550 ThreadedTesterBase::test(new ThreadedWeaknessTester); 565 ThreadedTesterBase::test(new ThreadedWeaknessTester);
(...skipping 5722 matching lines...) Expand 10 before | Expand all | Expand 10 after
6273 { 6288 {
6274 Persistent<ClassWithMember> object = ClassWithMember::create(); 6289 Persistent<ClassWithMember> object = ClassWithMember::create();
6275 EXPECT_EQ(0, object->traceCount()); 6290 EXPECT_EQ(0, object->traceCount());
6276 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object. get()); 6291 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object. get());
6277 EXPECT_TRUE(mixin); 6292 EXPECT_TRUE(mixin);
6278 EXPECT_GT(object->traceCount(), 0); 6293 EXPECT_GT(object->traceCount(), 0);
6279 EXPECT_GT(mixin->traceCount(), 0); 6294 EXPECT_GT(mixin->traceCount(), 0);
6280 } 6295 }
6281 6296
6282 } // namespace blink 6297 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/heap/PersistentNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698