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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 ThreadState* ThreadState::fromObject(const void* object) { | 563 ThreadState* ThreadState::fromObject(const void* object) { |
564 ASSERT(object); | 564 ASSERT(object); |
565 BasePage* page = pageFromObject(object); | 565 BasePage* page = pageFromObject(object); |
566 ASSERT(page); | 566 ASSERT(page); |
567 ASSERT(page->arena()); | 567 ASSERT(page->arena()); |
568 return page->arena()->getThreadState(); | 568 return page->arena()->getThreadState(); |
569 } | 569 } |
570 | 570 |
571 void ThreadState::performIdleGC(double deadlineSeconds) { | 571 void ThreadState::performIdleGC(double deadlineSeconds) { |
572 ASSERT(checkThread()); | 572 ASSERT(checkThread()); |
573 ASSERT(isMainThread()); | |
574 ASSERT(Platform::current()->currentThread()->scheduler()); | 573 ASSERT(Platform::current()->currentThread()->scheduler()); |
575 | 574 |
576 if (gcState() != IdleGCScheduled) | 575 if (gcState() != IdleGCScheduled) |
577 return; | 576 return; |
578 | 577 |
579 if (isGCForbidden()) { | 578 if (isGCForbidden()) { |
580 // If GC is forbidden at this point, try again. | 579 // If GC is forbidden at this point, try again. |
581 scheduleIdleGC(); | 580 scheduleIdleGC(); |
582 return; | 581 return; |
583 } | 582 } |
(...skipping 12 matching lines...) Expand all Loading... |
596 | 595 |
597 TRACE_EVENT2("blink_gc", "ThreadState::performIdleGC", "idleDeltaInSeconds", | 596 TRACE_EVENT2("blink_gc", "ThreadState::performIdleGC", "idleDeltaInSeconds", |
598 idleDeltaInSeconds, "estimatedMarkingTime", | 597 idleDeltaInSeconds, "estimatedMarkingTime", |
599 m_heap->heapStats().estimatedMarkingTime()); | 598 m_heap->heapStats().estimatedMarkingTime()); |
600 collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithoutSweep, | 599 collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithoutSweep, |
601 BlinkGC::IdleGC); | 600 BlinkGC::IdleGC); |
602 } | 601 } |
603 | 602 |
604 void ThreadState::performIdleLazySweep(double deadlineSeconds) { | 603 void ThreadState::performIdleLazySweep(double deadlineSeconds) { |
605 ASSERT(checkThread()); | 604 ASSERT(checkThread()); |
606 ASSERT(isMainThread()); | |
607 | 605 |
608 // If we are not in a sweeping phase, there is nothing to do here. | 606 // If we are not in a sweeping phase, there is nothing to do here. |
609 if (!isSweepingInProgress()) | 607 if (!isSweepingInProgress()) |
610 return; | 608 return; |
611 | 609 |
612 // This check is here to prevent performIdleLazySweep() from being called | 610 // This check is here to prevent performIdleLazySweep() from being called |
613 // recursively. I'm not sure if it can happen but it would be safer to have | 611 // recursively. I'm not sure if it can happen but it would be safer to have |
614 // the check just in case. | 612 // the check just in case. |
615 if (sweepForbidden()) | 613 if (sweepForbidden()) |
616 return; | 614 return; |
(...skipping 22 matching lines...) Expand all Loading... |
639 break; | 637 break; |
640 } | 638 } |
641 } | 639 } |
642 accumulateSweepingTime(WTF::currentTimeMS() - startTime); | 640 accumulateSweepingTime(WTF::currentTimeMS() - startTime); |
643 | 641 |
644 if (sweepCompleted) | 642 if (sweepCompleted) |
645 postSweep(); | 643 postSweep(); |
646 } | 644 } |
647 | 645 |
648 void ThreadState::scheduleIdleGC() { | 646 void ThreadState::scheduleIdleGC() { |
649 // TODO(haraken): Idle GC should be supported in worker threads as well. | |
650 if (!isMainThread()) | |
651 return; | |
652 | |
653 if (isSweepingInProgress()) { | 647 if (isSweepingInProgress()) { |
654 setGCState(SweepingAndIdleGCScheduled); | 648 setGCState(SweepingAndIdleGCScheduled); |
655 return; | 649 return; |
656 } | 650 } |
657 | 651 |
658 // Some threads (e.g. PPAPI thread) don't have a scheduler. | 652 // Some threads (e.g. PPAPI thread) don't have a scheduler. |
659 if (!Platform::current()->currentThread()->scheduler()) | 653 if (!Platform::current()->currentThread()->scheduler()) |
660 return; | 654 return; |
661 | 655 |
662 Platform::current()->currentThread()->scheduler()->postNonNestableIdleTask( | 656 Platform::current()->currentThread()->scheduler()->postNonNestableIdleTask( |
663 BLINK_FROM_HERE, | 657 BLINK_FROM_HERE, |
664 WTF::bind(&ThreadState::performIdleGC, WTF::unretained(this))); | 658 WTF::bind(&ThreadState::performIdleGC, WTF::unretained(this))); |
665 setGCState(IdleGCScheduled); | 659 setGCState(IdleGCScheduled); |
666 } | 660 } |
667 | 661 |
668 void ThreadState::scheduleIdleLazySweep() { | 662 void ThreadState::scheduleIdleLazySweep() { |
669 // TODO(haraken): Idle complete sweep should be supported in worker threads. | |
670 if (!isMainThread()) | |
671 return; | |
672 | |
673 // Some threads (e.g. PPAPI thread) don't have a scheduler. | 663 // Some threads (e.g. PPAPI thread) don't have a scheduler. |
674 if (!Platform::current()->currentThread()->scheduler()) | 664 if (!Platform::current()->currentThread()->scheduler()) |
675 return; | 665 return; |
676 | 666 |
677 Platform::current()->currentThread()->scheduler()->postIdleTask( | 667 Platform::current()->currentThread()->scheduler()->postIdleTask( |
678 BLINK_FROM_HERE, | 668 BLINK_FROM_HERE, |
679 WTF::bind(&ThreadState::performIdleLazySweep, WTF::unretained(this))); | 669 WTF::bind(&ThreadState::performIdleLazySweep, WTF::unretained(this))); |
680 } | 670 } |
681 | 671 |
682 void ThreadState::schedulePreciseGC() { | 672 void ThreadState::schedulePreciseGC() { |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, | 1548 collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, |
1559 BlinkGC::ForcedGC); | 1549 BlinkGC::ForcedGC); |
1560 size_t liveObjects = heap().heapStats().markedObjectSize(); | 1550 size_t liveObjects = heap().heapStats().markedObjectSize(); |
1561 if (liveObjects == previousLiveObjects) | 1551 if (liveObjects == previousLiveObjects) |
1562 break; | 1552 break; |
1563 previousLiveObjects = liveObjects; | 1553 previousLiveObjects = liveObjects; |
1564 } | 1554 } |
1565 } | 1555 } |
1566 | 1556 |
1567 } // namespace blink | 1557 } // namespace blink |
OLD | NEW |