| 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 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 #endif | 795 #endif |
| 796 | 796 |
| 797 // 1. If this allocation is big enough, allocate a large object. | 797 // 1. If this allocation is big enough, allocate a large object. |
| 798 if (allocationSize >= largeObjectSizeThreshold) { | 798 if (allocationSize >= largeObjectSizeThreshold) { |
| 799 LargeObjectHeap* largeObjectHeap = static_cast<LargeObjectHeap*>(threadS
tate()->heap(LargeObjectHeapIndex)); | 799 LargeObjectHeap* largeObjectHeap = static_cast<LargeObjectHeap*>(threadS
tate()->heap(LargeObjectHeapIndex)); |
| 800 Address largeObject = largeObjectHeap->allocateLargeObjectPage(allocatio
nSize, gcInfoIndex); | 800 Address largeObject = largeObjectHeap->allocateLargeObjectPage(allocatio
nSize, gcInfoIndex); |
| 801 ASAN_MARK_LARGE_VECTOR_CONTAINER(this, largeObject); | 801 ASAN_MARK_LARGE_VECTOR_CONTAINER(this, largeObject); |
| 802 return largeObject; | 802 return largeObject; |
| 803 } | 803 } |
| 804 | 804 |
| 805 // 2. Check if we should trigger a GC. | 805 // 2. Try to allocate from a free list. |
| 806 updateRemainingAllocationSize(); | 806 updateRemainingAllocationSize(); |
| 807 threadState()->scheduleGCIfNeeded(); | |
| 808 | |
| 809 // 3. Try to allocate from a free list. | |
| 810 Address result = allocateFromFreeList(allocationSize, gcInfoIndex); | 807 Address result = allocateFromFreeList(allocationSize, gcInfoIndex); |
| 811 if (result) | 808 if (result) |
| 812 return result; | 809 return result; |
| 813 | 810 |
| 814 // 4. Reset the allocation point. | 811 // 3. Reset the allocation point. |
| 815 setAllocationPoint(nullptr, 0); | 812 setAllocationPoint(nullptr, 0); |
| 816 | 813 |
| 817 // 5. Lazily sweep pages of this heap until we find a freed area for | 814 // 4. Lazily sweep pages of this heap until we find a freed area for |
| 818 // this allocation or we finish sweeping all pages of this heap. | 815 // this allocation or we finish sweeping all pages of this heap. |
| 819 result = lazySweep(allocationSize, gcInfoIndex); | 816 result = lazySweep(allocationSize, gcInfoIndex); |
| 820 if (result) | 817 if (result) |
| 821 return result; | 818 return result; |
| 822 | 819 |
| 823 // 6. Coalesce promptly freed areas and then try to allocate from a free | 820 // 5. Coalesce promptly freed areas and then try to allocate from a free |
| 824 // list. | 821 // list. |
| 825 if (coalesce()) { | 822 if (coalesce()) { |
| 826 result = allocateFromFreeList(allocationSize, gcInfoIndex); | 823 result = allocateFromFreeList(allocationSize, gcInfoIndex); |
| 827 if (result) | 824 if (result) |
| 828 return result; | 825 return result; |
| 829 } | 826 } |
| 830 | 827 |
| 831 // 7. Complete sweeping. | 828 // 6. Complete sweeping. |
| 832 threadState()->completeSweep(); | 829 threadState()->completeSweep(); |
| 833 | 830 |
| 831 // 7. Check if we should trigger a GC. |
| 832 threadState()->scheduleGCIfNeeded(); |
| 833 |
| 834 // 8. Add a new page to this heap. | 834 // 8. Add a new page to this heap. |
| 835 allocatePage(); | 835 allocatePage(); |
| 836 | 836 |
| 837 // 9. Try to allocate from a free list. This allocation must succeed. | 837 // 9. Try to allocate from a free list. This allocation must succeed. |
| 838 result = allocateFromFreeList(allocationSize, gcInfoIndex); | 838 result = allocateFromFreeList(allocationSize, gcInfoIndex); |
| 839 RELEASE_ASSERT(result); | 839 RELEASE_ASSERT(result); |
| 840 return result; | 840 return result; |
| 841 } | 841 } |
| 842 | 842 |
| 843 Address NormalPageHeap::allocateFromFreeList(size_t allocationSize, size_t gcInf
oIndex) | 843 Address NormalPageHeap::allocateFromFreeList(size_t allocationSize, size_t gcInf
oIndex) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 : BaseHeap(state, index) | 875 : BaseHeap(state, index) |
| 876 { | 876 { |
| 877 } | 877 } |
| 878 | 878 |
| 879 Address LargeObjectHeap::allocateLargeObjectPage(size_t allocationSize, size_t g
cInfoIndex) | 879 Address LargeObjectHeap::allocateLargeObjectPage(size_t allocationSize, size_t g
cInfoIndex) |
| 880 { | 880 { |
| 881 // Caller already added space for object header and rounded up to allocation | 881 // Caller already added space for object header and rounded up to allocation |
| 882 // alignment | 882 // alignment |
| 883 ASSERT(!(allocationSize & allocationMask)); | 883 ASSERT(!(allocationSize & allocationMask)); |
| 884 | 884 |
| 885 // 1. Check if we should trigger a GC. | 885 // 1. Try to sweep large objects more than allocationSize bytes |
| 886 threadState()->scheduleGCIfNeeded(); | |
| 887 | |
| 888 // 2. Try to sweep large objects more than allocationSize bytes | |
| 889 // before allocating a new large object. | 886 // before allocating a new large object. |
| 890 Address result = lazySweep(allocationSize, gcInfoIndex); | 887 Address result = lazySweep(allocationSize, gcInfoIndex); |
| 891 if (result) | 888 if (result) |
| 892 return result; | 889 return result; |
| 893 | 890 |
| 894 // 3. If we have failed in sweeping allocationSize bytes, | 891 // 2. If we have failed in sweeping allocationSize bytes, |
| 895 // we complete sweeping before allocating this large object. | 892 // we complete sweeping before allocating this large object. |
| 896 threadState()->completeSweep(); | 893 threadState()->completeSweep(); |
| 894 |
| 895 // 3. Check if we should trigger a GC. |
| 896 threadState()->scheduleGCIfNeeded(); |
| 897 |
| 897 return doAllocateLargeObjectPage(allocationSize, gcInfoIndex); | 898 return doAllocateLargeObjectPage(allocationSize, gcInfoIndex); |
| 898 } | 899 } |
| 899 | 900 |
| 900 Address LargeObjectHeap::doAllocateLargeObjectPage(size_t allocationSize, size_t
gcInfoIndex) | 901 Address LargeObjectHeap::doAllocateLargeObjectPage(size_t allocationSize, size_t
gcInfoIndex) |
| 901 { | 902 { |
| 902 size_t largeObjectSize = LargeObjectPage::pageHeaderSize() + allocationSize; | 903 size_t largeObjectSize = LargeObjectPage::pageHeaderSize() + allocationSize; |
| 903 // If ASan is supported we add allocationGranularity bytes to the allocated | 904 // If ASan is supported we add allocationGranularity bytes to the allocated |
| 904 // space and poison that to detect overflows | 905 // space and poison that to detect overflows |
| 905 #if defined(ADDRESS_SANITIZER) | 906 #if defined(ADDRESS_SANITIZER) |
| 906 largeObjectSize += allocationGranularity; | 907 largeObjectSize += allocationGranularity; |
| (...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2259 size_t Heap::s_allocatedObjectSize = 0; | 2260 size_t Heap::s_allocatedObjectSize = 0; |
| 2260 size_t Heap::s_allocatedSpace = 0; | 2261 size_t Heap::s_allocatedSpace = 0; |
| 2261 size_t Heap::s_markedObjectSize = 0; | 2262 size_t Heap::s_markedObjectSize = 0; |
| 2262 // We don't want to use 0 KB for the initial value because it may end up | 2263 // We don't want to use 0 KB for the initial value because it may end up |
| 2263 // triggering the first GC of some thread too prematurely. | 2264 // triggering the first GC of some thread too prematurely. |
| 2264 size_t Heap::s_estimatedLiveObjectSize = 512 * 1024; | 2265 size_t Heap::s_estimatedLiveObjectSize = 512 * 1024; |
| 2265 size_t Heap::s_externalObjectSizeAtLastGC = 0; | 2266 size_t Heap::s_externalObjectSizeAtLastGC = 0; |
| 2266 double Heap::s_estimatedMarkingTimePerByte = 0.0; | 2267 double Heap::s_estimatedMarkingTimePerByte = 0.0; |
| 2267 | 2268 |
| 2268 } // namespace blink | 2269 } // namespace blink |
| OLD | NEW |