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 2421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2432 #endif | 2432 #endif |
2433 | 2433 |
2434 // Disallow allocation during garbage collection (but not during the | 2434 // Disallow allocation during garbage collection (but not during the |
2435 // finalization that happens when the gcScope is torn down). | 2435 // finalization that happens when the gcScope is torn down). |
2436 ThreadState::NoAllocationScope noAllocationScope(state); | 2436 ThreadState::NoAllocationScope noAllocationScope(state); |
2437 | 2437 |
2438 preGC(); | 2438 preGC(); |
2439 s_markingVisitor->configureEagerTraceLimit(); | 2439 s_markingVisitor->configureEagerTraceLimit(); |
2440 ASSERT(s_markingVisitor->canTraceEagerly()); | 2440 ASSERT(s_markingVisitor->canTraceEagerly()); |
2441 | 2441 |
2442 Heap::resetMarkedObjectSize(); | 2442 Heap::resetHeapCounters(); |
2443 Heap::resetAllocatedObjectSize(); | |
2444 | 2443 |
2445 // 1. Trace persistent roots. | 2444 // 1. Trace persistent roots. |
2446 ThreadState::visitPersistentRoots(s_markingVisitor); | 2445 ThreadState::visitPersistentRoots(s_markingVisitor); |
2447 | 2446 |
2448 // 2. Trace objects reachable from the persistent roots including | 2447 // 2. Trace objects reachable from the persistent roots including |
2449 // ephemerons. | 2448 // ephemerons. |
2450 processMarkingStack(s_markingVisitor); | 2449 processMarkingStack(s_markingVisitor); |
2451 | 2450 |
2452 // 3. Trace objects reachable from the stack. We do this independent of the | 2451 // 3. Trace objects reachable from the stack. We do this independent of the |
2453 // given stackState since other threads might have a different stack state. | 2452 // given stackState since other threads might have a different stack state. |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2808 add(current->m_left, context); | 2807 add(current->m_left, context); |
2809 current->m_left = nullptr; | 2808 current->m_left = nullptr; |
2810 } | 2809 } |
2811 if (current->m_right) { | 2810 if (current->m_right) { |
2812 add(current->m_right, context); | 2811 add(current->m_right, context); |
2813 current->m_right = nullptr; | 2812 current->m_right = nullptr; |
2814 } | 2813 } |
2815 delete current; | 2814 delete current; |
2816 } | 2815 } |
2817 | 2816 |
2817 void Heap::resetHeapCounters() | |
2818 { | |
2819 ASSERT(ThreadState::current()->isInGC()); | |
2820 | |
2821 s_allocatedObjectSize = 0; | |
2822 s_markedObjectSize = 0; | |
2823 | |
2824 // Similarly, reset the amount of externally allocated memory. | |
2825 s_externallyAllocatedBytes = 0; | |
2826 s_externallyAllocatedBytesAlive = 0; | |
2827 | |
2828 s_requestedUrgentGC = false; | |
2829 } | |
2830 | |
2831 void Heap::increaseExternallyAllocatedBytes(size_t delta) | |
2832 { | |
2833 atomicAdd(&s_externallyAllocatedBytes, static_cast<long>(delta)); | |
haraken
2015/02/19 23:47:43
You can use the return value of atomicAdd, instead
sof
2015/02/20 09:33:49
Inlined and tidied.
| |
2834 | |
2835 if (isGCUrgentlyRequested()) | |
2836 return; | |
2837 | |
2838 // Flag GC urgency on a 50% increase in external allocation | |
2839 // since the last GC, but not for less than 100M. | |
2840 // | |
2841 // FIXME: consider other, 'better' policies (e.g., have the count of | |
2842 // heap objects with external allocations be taken into | |
2843 // account, ...) The overall goal here is to trigger a | |
2844 // GC such that it considerably lessens memory pressure | |
2845 // for a renderer process. | |
2846 size_t externalBytesSinceGC = externallyAllocatedBytes(); | |
haraken
2015/02/19 23:47:43
externalBytesSinceLastGC
| |
2847 if (externalBytesSinceGC < 100 * 1024 * 1024) | |
2848 return; | |
2849 | |
2850 size_t externalBytesAlive = externallyAllocatedBytesAlive(); | |
2851 | |
2852 // The urgent-gc flag will be considered the next time an out-of-line | |
2853 // allocation is made. Bump allocations from the current block will | |
2854 // go ahead until it can no longer service an allocation request. | |
2855 // | |
2856 // FIXME: if that delays urgently needed GCs for too long, consider | |
2857 // flushing out per-heap "allocation points" to trigger the GC | |
2858 // right away. | |
2859 if (externalBytesSinceGC > externalBytesAlive / 2) | |
2860 Heap::requestUrgentGC(); | |
2861 } | |
2862 | |
2818 Visitor* Heap::s_markingVisitor; | 2863 Visitor* Heap::s_markingVisitor; |
2819 CallbackStack* Heap::s_markingStack; | 2864 CallbackStack* Heap::s_markingStack; |
2820 CallbackStack* Heap::s_postMarkingCallbackStack; | 2865 CallbackStack* Heap::s_postMarkingCallbackStack; |
2821 CallbackStack* Heap::s_weakCallbackStack; | 2866 CallbackStack* Heap::s_weakCallbackStack; |
2822 CallbackStack* Heap::s_ephemeronStack; | 2867 CallbackStack* Heap::s_ephemeronStack; |
2823 HeapDoesNotContainCache* Heap::s_heapDoesNotContainCache; | 2868 HeapDoesNotContainCache* Heap::s_heapDoesNotContainCache; |
2824 bool Heap::s_shutdownCalled = false; | 2869 bool Heap::s_shutdownCalled = false; |
2825 bool Heap::s_lastGCWasConservative = false; | 2870 bool Heap::s_lastGCWasConservative = false; |
2826 FreePagePool* Heap::s_freePagePool; | 2871 FreePagePool* Heap::s_freePagePool; |
2827 OrphanedPagePool* Heap::s_orphanedPagePool; | 2872 OrphanedPagePool* Heap::s_orphanedPagePool; |
2828 Heap::RegionTree* Heap::s_regionTree = nullptr; | 2873 Heap::RegionTree* Heap::s_regionTree = nullptr; |
2829 size_t Heap::s_allocatedObjectSize = 0; | 2874 size_t Heap::s_allocatedObjectSize = 0; |
2830 size_t Heap::s_allocatedSpace = 0; | 2875 size_t Heap::s_allocatedSpace = 0; |
2831 size_t Heap::s_markedObjectSize = 0; | 2876 size_t Heap::s_markedObjectSize = 0; |
2832 | 2877 |
2878 size_t Heap::s_externallyAllocatedBytes = 0; | |
2879 size_t Heap::s_externallyAllocatedBytesAlive = 0; | |
2880 unsigned Heap::s_requestedUrgentGC = false; | |
2881 | |
2833 } // namespace blink | 2882 } // namespace blink |
OLD | NEW |