Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(581)

Side by Side Diff: Source/platform/heap/Heap.cpp

Issue 720163002: Oilpan: Vector::reserveCapacity shouldn't reallocate backing storage always (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/heap/Heap.h ('k') | Source/wtf/DefaultAllocator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 #endif 856 #endif
857 int index = bucketIndexForSize(size); 857 int index = bucketIndexForSize(size);
858 entry->link(&m_freeLists[index]); 858 entry->link(&m_freeLists[index]);
859 if (!m_lastFreeListEntries[index]) 859 if (!m_lastFreeListEntries[index])
860 m_lastFreeListEntries[index] = entry; 860 m_lastFreeListEntries[index] = entry;
861 if (index > m_biggestFreeListIndex) 861 if (index > m_biggestFreeListIndex)
862 m_biggestFreeListIndex = index; 862 m_biggestFreeListIndex = index;
863 } 863 }
864 864
865 template<typename Header> 865 template<typename Header>
866 bool ThreadHeap<Header>::expandObject(Header* header, size_t newSize)
867 {
868 ASSERT(header->payloadSize() < newSize);
869 size_t allocationSize = allocationSizeFromSize(newSize);
870 ASSERT(allocationSize > header->size());
871 size_t expandSize = allocationSize - header->size();
872 if (header->payloadEnd() == m_currentAllocationPoint && expandSize <= m_rema iningAllocationSize) {
873 m_currentAllocationPoint += expandSize;
874 m_remainingAllocationSize -= expandSize;
875
876 // Unpoison the memory used for the object (payload).
877 ASAN_UNPOISON_MEMORY_REGION(header->payloadEnd(), expandSize);
878 #if ENABLE(ASSERT) || defined(LEAK_SANITIZER) || defined(ADDRESS_SANITIZER)
879 memset(header->payloadEnd(), 0, expandSize);
880 #endif
881 header->setSize(allocationSize);
882 ASSERT(heapPageFromAddress(header->payloadEnd() - 1));
883 return true;
884 }
885 return false;
886 }
887
888 template<typename Header>
866 void ThreadHeap<Header>::promptlyFreeObject(Header* header) 889 void ThreadHeap<Header>::promptlyFreeObject(Header* header)
867 { 890 {
868 ASSERT(!m_threadState->isSweepInProgress()); 891 ASSERT(!m_threadState->isSweepInProgress());
869 header->checkHeader(); 892 header->checkHeader();
870 Address address = reinterpret_cast<Address>(header); 893 Address address = reinterpret_cast<Address>(header);
871 Address payload = header->payload(); 894 Address payload = header->payload();
872 size_t size = header->size(); 895 size_t size = header->size();
873 size_t payloadSize = header->payloadSize(); 896 size_t payloadSize = header->payloadSize();
874 BaseHeapPage* page = pageHeaderFromObject(address); 897 BaseHeapPage* page = pageHeaderFromObject(address);
875 ASSERT(size > 0); 898 ASSERT(size > 0);
(...skipping 1983 matching lines...) Expand 10 before | Expand all | Expand 10 after
2859 2882
2860 HeaderType* header = HeaderType::fromPayload(address); 2883 HeaderType* header = HeaderType::fromPayload(address);
2861 header->checkHeader(); 2884 header->checkHeader();
2862 2885
2863 const GCInfo* gcInfo = header->gcInfo(); 2886 const GCInfo* gcInfo = header->gcInfo();
2864 int heapIndex = HeapTraits::index(gcInfo->hasFinalizer(), header->payloadSiz e()); 2887 int heapIndex = HeapTraits::index(gcInfo->hasFinalizer(), header->payloadSiz e());
2865 HeapType* heap = static_cast<HeapType*>(state->heap(heapIndex)); 2888 HeapType* heap = static_cast<HeapType*>(state->heap(heapIndex));
2866 heap->promptlyFreeObject(header); 2889 heap->promptlyFreeObject(header);
2867 } 2890 }
2868 2891
2892 bool HeapAllocator::backingExpand(void* address, size_t newSize)
2893 {
2894 if (!address || ThreadState::isAnyThreadInGC())
2895 return false;
2896
2897 ThreadState* state = ThreadState::current();
2898 if (state->isSweepInProgress())
2899 return false;
2900 ASSERT(state->isAllocationAllowed());
2901
2902 BaseHeapPage* page = pageHeaderFromObject(address);
2903 if (page->isLargeObject() || page->threadState() != state)
2904 return false;
2905
2906 typedef HeapIndexTrait<CollectionBackingHeap> HeapTraits;
2907 typedef HeapTraits::HeapType HeapType;
2908 typedef HeapTraits::HeaderType HeaderType;
2909
2910 HeaderType* header = HeaderType::fromPayload(address);
2911 header->checkHeader();
2912
2913 const GCInfo* gcInfo = header->gcInfo();
2914 int heapIndex = HeapTraits::index(gcInfo->hasFinalizer(), header->payloadSiz e());
2915 HeapType* heap = static_cast<HeapType*>(state->heap(heapIndex));
2916 return heap->expandObject(header, newSize);
2917 }
2918
2869 BaseHeapPage* Heap::lookup(Address address) 2919 BaseHeapPage* Heap::lookup(Address address)
2870 { 2920 {
2871 ASSERT(ThreadState::isAnyThreadInGC()); 2921 ASSERT(ThreadState::isAnyThreadInGC());
2872 if (!s_regionTree) 2922 if (!s_regionTree)
2873 return 0; 2923 return 0;
2874 if (PageMemoryRegion* region = s_regionTree->lookup(address)) 2924 if (PageMemoryRegion* region = s_regionTree->lookup(address))
2875 return region->pageFromAddress(address); 2925 return region->pageFromAddress(address);
2876 return 0; 2926 return 0;
2877 } 2927 }
2878 2928
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2968 CallbackStack* Heap::s_weakCallbackStack; 3018 CallbackStack* Heap::s_weakCallbackStack;
2969 CallbackStack* Heap::s_ephemeronStack; 3019 CallbackStack* Heap::s_ephemeronStack;
2970 HeapDoesNotContainCache* Heap::s_heapDoesNotContainCache; 3020 HeapDoesNotContainCache* Heap::s_heapDoesNotContainCache;
2971 bool Heap::s_shutdownCalled = false; 3021 bool Heap::s_shutdownCalled = false;
2972 bool Heap::s_lastGCWasConservative = false; 3022 bool Heap::s_lastGCWasConservative = false;
2973 FreePagePool* Heap::s_freePagePool; 3023 FreePagePool* Heap::s_freePagePool;
2974 OrphanedPagePool* Heap::s_orphanedPagePool; 3024 OrphanedPagePool* Heap::s_orphanedPagePool;
2975 Heap::RegionTree* Heap::s_regionTree = 0; 3025 Heap::RegionTree* Heap::s_regionTree = 0;
2976 3026
2977 } // namespace blink 3027 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/heap/Heap.h ('k') | Source/wtf/DefaultAllocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698