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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 // Heap::markedObjectSize() may be underestimated if any thread has not | 643 // Heap::markedObjectSize() may be underestimated if any thread has not |
644 // finished completeSweep(). | 644 // finished completeSweep(). |
645 size_t currentObjectSizeKb = currentObjectSize() >> 10; | 645 size_t currentObjectSizeKb = currentObjectSize() >> 10; |
646 // Schedule a precise GC if Oilpan has allocated more than 1 MB since | 646 // Schedule a precise GC if Oilpan has allocated more than 1 MB since |
647 // the last GC and the current memory usage is >50% larger than | 647 // the last GC and the current memory usage is >50% larger than |
648 // the estimated live memory usage. | 648 // the estimated live memory usage. |
649 return allocatedObjectSizeKb >= 1024 && currentObjectSizeKb > (estimatedLive ObjectSizeKb * 3) / 2; | 649 return allocatedObjectSizeKb >= 1024 && currentObjectSizeKb > (estimatedLive ObjectSizeKb * 3) / 2; |
650 #endif | 650 #endif |
651 } | 651 } |
652 | 652 |
653 bool ThreadState::shouldSchedulePageNavigationGC(float estimatedRemovalRatio) | |
654 { | |
655 if (UNLIKELY(isGCForbidden())) | |
656 return false; | |
657 | |
658 if (shouldForceMemoryPressureGC()) | |
659 return true; | |
660 | |
661 // Avoid potential overflow by truncating to Kb. | |
662 size_t allocatedObjectSizeKb = Heap::allocatedObjectSize() >> 10; | |
663 // The estimated size is updated when the main thread finishes lazy | |
664 // sweeping. If this thread reaches here before the main thread finishes | |
665 // lazy sweeping, the thread will use the estimated size of the last GC. | |
666 size_t estimatedLiveObjectSizeKb = (estimatedLiveObjectSize() >> 10) * (1 - estimatedRemovalRatio); | |
667 // Heap::markedObjectSize() may be underestimated if any thread has not | |
668 // finished completeSweep(). | |
669 size_t currentObjectSizeKb = currentObjectSize() >> 10; | |
670 // Schedule a precise GC if Oilpan has allocated more than 1 MB since | |
671 // the last GC and the current memory usage is >50% larger than | |
672 // the estimated live memory usage. | |
673 return allocatedObjectSizeKb >= 1024 && currentObjectSizeKb > (estimatedLive ObjectSizeKb * 3) / 2; | |
674 } | |
675 | |
676 void ThreadState::schedulePageNavigationGCIfNeeded(float estimatedRemovalRatio) | |
677 { | |
678 ASSERT(checkThread()); | |
679 // Finish on-going lazy sweeping. | |
680 // TODO(haraken): It might not make sense to force completeSweep() for all | |
681 // page navigations. | |
682 completeSweep(); | |
683 ASSERT(!isSweepingInProgress()); | |
684 ASSERT(!sweepForbidden()); | |
685 | |
686 Heap::reportMemoryUsageForTracing(); | |
687 if (shouldSchedulePageNavigationGC(estimatedRemovalRatio)) | |
688 schedulePageNavigationGC(); | |
689 } | |
690 | |
691 void ThreadState::schedulePageNavigationGC() | |
692 { | |
693 ASSERT(checkThread()); | |
694 ASSERT(!isSweepingInProgress()); | |
695 setGCState(PageNavigationGCScheduled); | |
696 } | |
697 | |
653 // TODO(haraken): We should improve the GC heuristics. | 698 // TODO(haraken): We should improve the GC heuristics. |
654 // These heuristics affect performance significantly. | 699 // These heuristics affect performance significantly. |
655 bool ThreadState::shouldForceConservativeGC() | 700 bool ThreadState::shouldForceConservativeGC() |
656 { | 701 { |
657 if (UNLIKELY(isGCForbidden())) | 702 if (UNLIKELY(isGCForbidden())) |
658 return false; | 703 return false; |
659 | 704 |
660 if (shouldForceMemoryPressureGC()) | 705 if (shouldForceMemoryPressureGC()) |
661 return true; | 706 return true; |
662 | 707 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
832 { | 877 { |
833 switch (gcState) { | 878 switch (gcState) { |
834 case NoGCScheduled: | 879 case NoGCScheduled: |
835 ASSERT(checkThread()); | 880 ASSERT(checkThread()); |
836 VERIFY_STATE_TRANSITION(m_gcState == Sweeping || m_gcState == SweepingAn dIdleGCScheduled); | 881 VERIFY_STATE_TRANSITION(m_gcState == Sweeping || m_gcState == SweepingAn dIdleGCScheduled); |
837 break; | 882 break; |
838 case IdleGCScheduled: | 883 case IdleGCScheduled: |
839 case PreciseGCScheduled: | 884 case PreciseGCScheduled: |
840 case FullGCScheduled: | 885 case FullGCScheduled: |
841 ASSERT(checkThread()); | 886 ASSERT(checkThread()); |
842 VERIFY_STATE_TRANSITION(m_gcState == NoGCScheduled || m_gcState == IdleG CScheduled || m_gcState == PreciseGCScheduled || m_gcState == FullGCScheduled || m_gcState == SweepingAndIdleGCScheduled || m_gcState == SweepingAndPreciseGCSch eduled); | 887 VERIFY_STATE_TRANSITION(m_gcState == NoGCScheduled || m_gcState == IdleG CScheduled || m_gcState == PreciseGCScheduled || m_gcState == FullGCScheduled || m_gcState == PageNavigationGCScheduled || m_gcState == SweepingAndIdleGCSchedul ed || m_gcState == SweepingAndPreciseGCScheduled); |
843 completeSweep(); | 888 completeSweep(); |
844 break; | 889 break; |
890 case PageNavigationGCScheduled: | |
haraken
2015/08/11 08:30:20
I'd slightly prefer including this into the above
keishi
2015/08/11 08:32:29
Thanks! Done.
Proceeding to commit.
| |
891 ASSERT(checkThread()); | |
892 VERIFY_STATE_TRANSITION(m_gcState == NoGCScheduled || m_gcState == IdleG CScheduled || m_gcState == PreciseGCScheduled || m_gcState == FullGCScheduled || m_gcState == PageNavigationGCScheduled || m_gcState == SweepingAndIdleGCSchedul ed || m_gcState == SweepingAndPreciseGCScheduled); | |
893 break; | |
845 case GCRunning: | 894 case GCRunning: |
846 ASSERT(!isInGC()); | 895 ASSERT(!isInGC()); |
847 VERIFY_STATE_TRANSITION(m_gcState != GCRunning); | 896 VERIFY_STATE_TRANSITION(m_gcState != GCRunning); |
848 break; | 897 break; |
849 case EagerSweepScheduled: | 898 case EagerSweepScheduled: |
850 case LazySweepScheduled: | 899 case LazySweepScheduled: |
851 ASSERT(isInGC()); | 900 ASSERT(isInGC()); |
852 VERIFY_STATE_TRANSITION(m_gcState == GCRunning); | 901 VERIFY_STATE_TRANSITION(m_gcState == GCRunning); |
853 break; | 902 break; |
854 case Sweeping: | 903 case Sweeping: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 if (isGCForbidden()) | 952 if (isGCForbidden()) |
904 return; | 953 return; |
905 | 954 |
906 switch (gcState()) { | 955 switch (gcState()) { |
907 case FullGCScheduled: | 956 case FullGCScheduled: |
908 Heap::collectAllGarbage(); | 957 Heap::collectAllGarbage(); |
909 break; | 958 break; |
910 case PreciseGCScheduled: | 959 case PreciseGCScheduled: |
911 Heap::collectGarbage(NoHeapPointersOnStack, GCWithoutSweep, Heap::Precis eGC); | 960 Heap::collectGarbage(NoHeapPointersOnStack, GCWithoutSweep, Heap::Precis eGC); |
912 break; | 961 break; |
962 case PageNavigationGCScheduled: | |
963 Heap::collectGarbage(NoHeapPointersOnStack, GCWithSweep, Heap::PreciseGC ); | |
964 break; | |
913 case IdleGCScheduled: | 965 case IdleGCScheduled: |
914 // Idle time GC will be scheduled by Blink Scheduler. | 966 // Idle time GC will be scheduled by Blink Scheduler. |
915 break; | 967 break; |
916 default: | 968 default: |
917 break; | 969 break; |
918 } | 970 } |
919 } | 971 } |
920 | 972 |
921 void ThreadState::flushHeapDoesNotContainCacheIfNeeded() | 973 void ThreadState::flushHeapDoesNotContainCacheIfNeeded() |
922 { | 974 { |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1531 json->beginArray(it->key.ascii().data()); | 1583 json->beginArray(it->key.ascii().data()); |
1532 for (size_t age = 0; age <= maxHeapObjectAge; ++age) | 1584 for (size_t age = 0; age <= maxHeapObjectAge; ++age) |
1533 json->pushInteger(it->value.ages[age]); | 1585 json->pushInteger(it->value.ages[age]); |
1534 json->endArray(); | 1586 json->endArray(); |
1535 } | 1587 } |
1536 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s tatsName, this, json.release()); | 1588 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s tatsName, this, json.release()); |
1537 } | 1589 } |
1538 #endif | 1590 #endif |
1539 | 1591 |
1540 } // namespace blink | 1592 } // namespace blink |
OLD | NEW |