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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 if (threadState()->isMainThread()) | 602 if (threadState()->isMainThread()) |
603 ScriptForbiddenScope::enter(); | 603 ScriptForbiddenScope::enter(); |
604 | 604 |
605 Address result = lazySweepPages(allocationSize, gcInfoIndex); | 605 Address result = lazySweepPages(allocationSize, gcInfoIndex); |
606 | 606 |
607 if (threadState()->isMainThread()) | 607 if (threadState()->isMainThread()) |
608 ScriptForbiddenScope::exit(); | 608 ScriptForbiddenScope::exit(); |
609 return result; | 609 return result; |
610 } | 610 } |
611 | 611 |
| 612 void BaseHeap::sweepUnsweptPage() |
| 613 { |
| 614 BasePage* page = m_firstUnsweptPage; |
| 615 if (page->isEmpty()) { |
| 616 page->unlink(&m_firstUnsweptPage); |
| 617 page->removeFromHeap(); |
| 618 } else { |
| 619 // Sweep a page and move the page from m_firstUnsweptPages to |
| 620 // m_firstPages. |
| 621 page->sweep(); |
| 622 page->unlink(&m_firstUnsweptPage); |
| 623 page->link(&m_firstPage); |
| 624 page->markAsSwept(); |
| 625 } |
| 626 } |
| 627 |
| 628 bool BaseHeap::lazySweepWithDeadline(double deadlineSeconds) |
| 629 { |
| 630 // It might be heavy to call Platform::current()->monotonicallyIncreasingTim
e() |
| 631 // per page (i.e., 128 KB sweep or one LargeObject sweep), so we check |
| 632 // the deadline per 10 pages. |
| 633 static const int deadlineCheckInterval = 10; |
| 634 |
| 635 RELEASE_ASSERT(threadState()->isSweepingInProgress()); |
| 636 ASSERT(threadState()->sweepForbidden()); |
| 637 ASSERT(!threadState()->isMainThread() || ScriptForbiddenScope::isScriptForbi
dden()); |
| 638 |
| 639 int pageCount = 1; |
| 640 while (m_firstUnsweptPage) { |
| 641 sweepUnsweptPage(); |
| 642 if (pageCount % deadlineCheckInterval == 0) { |
| 643 if (deadlineSeconds <= Platform::current()->monotonicallyIncreasingT
ime()) { |
| 644 // Deadline has come. |
| 645 return !m_firstUnsweptPage; |
| 646 } |
| 647 } |
| 648 pageCount++; |
| 649 } |
| 650 return true; |
| 651 } |
| 652 |
612 void BaseHeap::completeSweep() | 653 void BaseHeap::completeSweep() |
613 { | 654 { |
614 RELEASE_ASSERT(threadState()->isSweepingInProgress()); | 655 RELEASE_ASSERT(threadState()->isSweepingInProgress()); |
615 ASSERT(threadState()->sweepForbidden()); | 656 ASSERT(threadState()->sweepForbidden()); |
616 | 657 ASSERT(!threadState()->isMainThread() || ScriptForbiddenScope::isScriptForbi
dden()); |
617 if (threadState()->isMainThread()) | |
618 ScriptForbiddenScope::enter(); | |
619 | 658 |
620 while (m_firstUnsweptPage) { | 659 while (m_firstUnsweptPage) { |
621 BasePage* page = m_firstUnsweptPage; | 660 sweepUnsweptPage(); |
622 if (page->isEmpty()) { | |
623 page->unlink(&m_firstUnsweptPage); | |
624 page->removeFromHeap(); | |
625 } else { | |
626 // Sweep a page and move the page from m_firstUnsweptPages to | |
627 // m_firstPages. | |
628 page->sweep(); | |
629 page->unlink(&m_firstUnsweptPage); | |
630 page->link(&m_firstPage); | |
631 page->markAsSwept(); | |
632 } | |
633 } | 661 } |
634 | |
635 if (threadState()->isMainThread()) | |
636 ScriptForbiddenScope::exit(); | |
637 } | 662 } |
638 | 663 |
639 NormalPageHeap::NormalPageHeap(ThreadState* state, int index) | 664 NormalPageHeap::NormalPageHeap(ThreadState* state, int index) |
640 : BaseHeap(state, index) | 665 : BaseHeap(state, index) |
641 , m_currentAllocationPoint(nullptr) | 666 , m_currentAllocationPoint(nullptr) |
642 , m_remainingAllocationSize(0) | 667 , m_remainingAllocationSize(0) |
643 , m_lastRemainingAllocationSize(0) | 668 , m_lastRemainingAllocationSize(0) |
644 , m_promptlyFreedSize(0) | 669 , m_promptlyFreedSize(0) |
645 #if ENABLE(GC_PROFILING) | 670 #if ENABLE(GC_PROFILING) |
646 , m_cumulativeAllocationSize(0) | 671 , m_cumulativeAllocationSize(0) |
(...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2848 size_t Heap::s_allocatedObjectSize = 0; | 2873 size_t Heap::s_allocatedObjectSize = 0; |
2849 size_t Heap::s_allocatedSpace = 0; | 2874 size_t Heap::s_allocatedSpace = 0; |
2850 size_t Heap::s_markedObjectSize = 0; | 2875 size_t Heap::s_markedObjectSize = 0; |
2851 | 2876 |
2852 size_t Heap::s_externallyAllocatedBytes = 0; | 2877 size_t Heap::s_externallyAllocatedBytes = 0; |
2853 size_t Heap::s_externallyAllocatedBytesAlive = 0; | 2878 size_t Heap::s_externallyAllocatedBytesAlive = 0; |
2854 unsigned Heap::s_requestedUrgentGC = false; | 2879 unsigned Heap::s_requestedUrgentGC = false; |
2855 double Heap::s_markingTimeInLastGC = 0.0; | 2880 double Heap::s_markingTimeInLastGC = 0.0; |
2856 | 2881 |
2857 } // namespace blink | 2882 } // namespace blink |
OLD | NEW |