haikuwebkit/Source/bmalloc/bmalloc/SmallPage.h

96 lines
3.2 KiB
C
Raw Permalink Normal View History

bmalloc https://bugs.webkit.org/show_bug.cgi?id=131170 Reviewed by Andreas Kling. Initial commit. * bmalloc: Added. * bmalloc.xcodeproj: Added. * bmalloc.xcodeproj/project.pbxproj: Added. * bmalloc/Algorithm.h: Added. (bmalloc::max): (bmalloc::min): (bmalloc::mask): (bmalloc::test): (bmalloc::roundUpToMultipleOf): (bmalloc::roundDownToMultipleOf): (bmalloc::sizeOf): (bmalloc::bitCount): (bmalloc::isPowerOfTwo): * bmalloc/Allocator.cpp: Added. (bmalloc::Allocator::Allocator): (bmalloc::Allocator::~Allocator): (bmalloc::Allocator::log): (bmalloc::Allocator::processSmallAllocatorLog): (bmalloc::Allocator::processMediumAllocatorLog): (bmalloc::Allocator::allocateLarge): (bmalloc::Allocator::allocateXLarge): (bmalloc::Allocator::allocateMedium): (bmalloc::Allocator::allocateSlowCase): * bmalloc/Allocator.h: Added. (bmalloc::Allocator::smallAllocatorFor): (bmalloc::Allocator::allocateFastCase): (bmalloc::Allocator::allocate): * bmalloc/AsyncTask.cpp: Added. (bmalloc::AsyncTask<Function>::runSlowCase): (bmalloc::AsyncTask<Function>::pthreadEntryPoint): (bmalloc::AsyncTask<Function>::entryPoint): * bmalloc/AsyncTask.h: Added. (bmalloc::Function>::AsyncTask): (bmalloc::Function>::join): (bmalloc::Function>::run): (bmalloc::Function>::runSlowCase): (bmalloc::Function>::pthreadEntryPoint): (bmalloc::Function>::entryPoint): * bmalloc/BAssert.h: Added. * bmalloc/BeginTag.h: Added. (bmalloc::BeginTag::isInFreeList): * bmalloc/BoundaryTag.h: Added. (bmalloc::BoundaryTag::isXLarge): (bmalloc::BoundaryTag::setXLarge): (bmalloc::BoundaryTag::isFree): (bmalloc::BoundaryTag::setFree): (bmalloc::BoundaryTag::isEnd): (bmalloc::BoundaryTag::setEnd): (bmalloc::BoundaryTag::hasPhysicalPages): (bmalloc::BoundaryTag::setHasPhysicalPages): (bmalloc::BoundaryTag::isNull): (bmalloc::BoundaryTag::clear): (bmalloc::BoundaryTag::size): (bmalloc::BoundaryTag::setSize): (bmalloc::BoundaryTag::prev): (bmalloc::BoundaryTag::next): * bmalloc/BoundaryTagInlines.h: Added. (bmalloc::validate): (bmalloc::validatePrev): (bmalloc::validateNext): (bmalloc::BoundaryTag::init): (bmalloc::BoundaryTag::mergeLargeLeft): (bmalloc::BoundaryTag::mergeLargeRight): (bmalloc::BoundaryTag::mergeLarge): (bmalloc::BoundaryTag::deallocate): (bmalloc::BoundaryTag::splitLarge): (bmalloc::BoundaryTag::allocate): * bmalloc/Cache.cpp: Added. (bmalloc::Cache::operator new): (bmalloc::Cache::operator delete): (bmalloc::Cache::Cache): (bmalloc::Cache::allocateSlowCase): (bmalloc::Cache::allocateSlowCaseNullCache): (bmalloc::Cache::deallocateSlowCase): (bmalloc::Cache::deallocateSlowCaseNullCache): * bmalloc/Cache.h: Added. (bmalloc::Cache::allocator): (bmalloc::Cache::deallocator): (bmalloc::Cache::allocateFastCase): (bmalloc::Cache::deallocateFastCase): (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): * bmalloc/Chunk.h: Added. (bmalloc::Chunk::begin): (bmalloc::Chunk::end): (bmalloc::Chunk::lines): (bmalloc::Chunk::pages): * bmalloc/Deallocator.cpp: Added. (bmalloc::Deallocator::Deallocator): (bmalloc::Deallocator::~Deallocator): (bmalloc::Deallocator::deallocateLarge): (bmalloc::Deallocator::deallocateXLarge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): (bmalloc::Deallocator::deallocateSmallLine): (bmalloc::Deallocator::allocateSmallLine): (bmalloc::Deallocator::deallocateMediumLine): (bmalloc::Deallocator::allocateMediumLine): * bmalloc/Deallocator.h: Added. (bmalloc::Deallocator::deallocateFastCase): (bmalloc::Deallocator::deallocate): * bmalloc/EndTag.h: Added. (bmalloc::EndTag::operator=): * bmalloc/FixedVector.h: Added. (bmalloc::FixedVector::begin): (bmalloc::FixedVector::end): (bmalloc::FixedVector::size): (bmalloc::FixedVector::capacity): (bmalloc::FixedVector::clear): (bmalloc::FixedVector::isEmpty): (bmalloc::Capacity>::FixedVector): (bmalloc::Capacity>::operator): (bmalloc::Capacity>::push): (bmalloc::Capacity>::pop): (bmalloc::Capacity>::shrink): * bmalloc/Heap.cpp: Added. (bmalloc::sleep): (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeMediumPages): (bmalloc::Heap::scavengeLargeRanges): (bmalloc::Heap::allocateSmallLineSlowCase): (bmalloc::Heap::allocateMediumLineSlowCase): (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::deallocateXLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: Added. (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallLine): (bmalloc::Heap::deallocateMediumLine): (bmalloc::Heap::allocateMediumLine): * bmalloc/Inline.h: Added. * bmalloc/LargeChunk.h: Added. (bmalloc::LargeChunk::begin): (bmalloc::LargeChunk::end): (bmalloc::LargeChunk::create): (bmalloc::LargeChunk::get): (bmalloc::LargeChunk::beginTag): (bmalloc::LargeChunk::endTag): * bmalloc/Line.h: Added. (bmalloc::Line<Traits>::begin): (bmalloc::Line<Traits>::end): (bmalloc::Line<Traits>::concurrentRef): (bmalloc::Line<Traits>::deref): * bmalloc/MediumAllocator.h: Added. (bmalloc::MediumAllocator::isNull): (bmalloc::MediumAllocator::MediumAllocator): (bmalloc::MediumAllocator::line): (bmalloc::MediumAllocator::allocate): (bmalloc::MediumAllocator::derefCount): (bmalloc::MediumAllocator::refill): * bmalloc/MediumChunk.h: Added. * bmalloc/MediumLine.h: Added. * bmalloc/MediumPage.h: Added. * bmalloc/MediumTraits.h: Added. * bmalloc/Mutex.cpp: Added. (bmalloc::Mutex::lockSlowCase): * bmalloc/Mutex.h: Added. (bmalloc::Mutex::Mutex): (bmalloc::Mutex::try_lock): (bmalloc::Mutex::lock): (bmalloc::Mutex::unlock): * bmalloc/ObjectType.cpp: Added. (bmalloc::objectType): * bmalloc/ObjectType.h: Added. (bmalloc::isSmallOrMedium): (bmalloc::isSmall): * bmalloc/Page.h: Added. (bmalloc::Page<Traits>::ref): (bmalloc::Page<Traits>::deref): (bmalloc::Page<Traits>::refCount): * bmalloc/PerProcess.h: Added. (bmalloc::PerProcess::mutex): (bmalloc::PerProcess<T>::getFastCase): (bmalloc::PerProcess<T>::get): (bmalloc::PerProcess<T>::getSlowCase): * bmalloc/PerThread.h: Added. (bmalloc::PerThreadStorage<Cache>::get): (bmalloc::PerThreadStorage<Cache>::init): (bmalloc::PerThreadStorage::get): (bmalloc::PerThreadStorage::init): (bmalloc::PerThread<T>::getFastCase): (bmalloc::PerThread<T>::get): (bmalloc::PerThread<T>::destructor): (bmalloc::PerThread<T>::getSlowCase): * bmalloc/Range.h: Added. (bmalloc::Range::Range): (bmalloc::Range::begin): (bmalloc::Range::end): (bmalloc::Range::size): (bmalloc::Range::operator!): (bmalloc::Range::operator<): * bmalloc/SegregatedFreeList.cpp: Added. (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: Added. * bmalloc/Sizes.h: Added. * bmalloc/SmallAllocator.h: Added. (bmalloc::SmallAllocator::isNull): (bmalloc::SmallAllocator::canAllocate): (bmalloc::SmallAllocator::SmallAllocator): (bmalloc::SmallAllocator::line): (bmalloc::SmallAllocator::allocate): (bmalloc::SmallAllocator::objectCount): (bmalloc::SmallAllocator::derefCount): (bmalloc::SmallAllocator::refill): * bmalloc/SmallChunk.h: Added. * bmalloc/SmallLine.h: Added. * bmalloc/SmallPage.h: Added. * bmalloc/SmallTraits.h: Added. * bmalloc/Syscall.h: Added. * bmalloc/VMAllocate.h: Added. (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::vmAllocate): (bmalloc::vmDeallocate): (bmalloc::vmDeallocatePhysicalPages): (bmalloc::vmAllocatePhysicalPages): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): * bmalloc/VMHeap.cpp: Added. (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::allocateMediumChunk): (bmalloc::VMHeap::allocateLargeChunk): * bmalloc/VMHeap.h: Added. (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeRange): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::deallocateMediumPage): (bmalloc::VMHeap::deallocateLargeRange): * bmalloc/Vector.h: Added. (bmalloc::Vector::begin): (bmalloc::Vector::end): (bmalloc::Vector::size): (bmalloc::Vector::capacity): (bmalloc::Vector::last): (bmalloc::Vector::pop): (bmalloc::Vector<T>::Vector): (bmalloc::Vector<T>::~Vector): (bmalloc::Vector<T>::operator): (bmalloc::Vector<T>::push): (bmalloc::Vector<T>::pop): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::reallocateBuffer): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): * bmalloc/XLargeChunk.h: Added. (bmalloc::XLargeChunk::get): (bmalloc::XLargeChunk::begin): (bmalloc::XLargeChunk::XLargeChunk): (bmalloc::XLargeChunk::create): (bmalloc::XLargeChunk::destroy): (bmalloc::XLargeChunk::range): (bmalloc::XLargeChunk::size): * bmalloc/bmalloc.h: Added. (bmalloc::api::malloc): (bmalloc::api::free): (bmalloc::api::realloc): * bmalloc/mbmalloc.cpp: Added. Canonical link: https://commits.webkit.org/149378@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166893 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-07 23:54:11 +00:00
/*
bmalloc should do partial scavenges more frequently https://bugs.webkit.org/show_bug.cgi?id=184176 Reviewed by Filip Pizlo. This patch adds the ability for bmalloc to do a partial scavenge. bmalloc will now do a partial scavenge with some frequency even when the heap is growing. For Heap, this means tracking the high water mark of where the Heap has allocated since the last scavenge. Partial scavenging is just decommitting entries in the LargeMap that are past this high water mark. Because we allocate in first fit order out of LargeMap, tracking the high water mark is a good heuristic of how much memory a partial scavenge should decommit. For IsoHeaps, each IsoDirectory also keeps track of its high water mark for the furthest page it allocates into. Similar to Heap, we scavenge pages past that high water mark. IsoHeapImpl then tracks the high water mark for the IsoDirectory it allocates into. We then scavenge all directories including and past the directory high water mark. This includes scavenging the inline directory when its the only thing we allocate out of since the last scavenge. This patch also adds some other capabilities to bmalloc: Heaps and IsoHeaps now track how much memory is freeable. Querying this number is now cheap. Heaps no longer hold the global lock when decommitting large ranges. Instead, that range is just marked as non eligible to be allocated. Then, without the lock held, the scavenger will decommit those ranges. Once this is done, the scavenger will then reacquire the lock and mark these ranges as eligible. This lessens lock contention between the scavenger and the allocation slow path since threads that are taking an allocation slow path can now allocate concurrently to the scavenger's decommits. The main consideration in adding this functionality is that a large allocation may fail while the scavenger is in the process of decommitting memory. When the Heap fails to allocate a large range when the scavenger is in the middle of a decommit, Heap will wait for the Scavenger to finish and then it will try to allocate a large range again. Decommitting from Heap now aggregates the ranges to decommit and tries to merge them together to lower the number of calls to vmDeallocatePhysicalPages. This is analogous to what IsoHeaps already do. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::tryAllocate): (bmalloc::Allocator::allocateImpl): (bmalloc::Allocator::reallocate): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::allocateLarge): * bmalloc/BulkDecommit.h: Added. (bmalloc::BulkDecommit::addEager): (bmalloc::BulkDecommit::addLazy): (bmalloc::BulkDecommit::processEager): (bmalloc::BulkDecommit::processLazy): (bmalloc::BulkDecommit::add): (bmalloc::BulkDecommit::process): * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: (bmalloc::Deallocator::lineCache): * bmalloc/Heap.cpp: (bmalloc::Heap::freeableMemory): (bmalloc::Heap::markAllLargeAsEligibile): (bmalloc::Heap::decommitLargeRange): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeToHighWatermark): (bmalloc::Heap::deallocateLineCache): (bmalloc::Heap::allocateSmallChunk): (bmalloc::Heap::deallocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::isLarge): (bmalloc::Heap::largeSize): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): (bmalloc::Heap::externalCommit): (bmalloc::Heap::externalDecommit): * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): * bmalloc/IsoDirectory.h: * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::didBecome): (bmalloc::passedNumPages>::didDecommit): (bmalloc::passedNumPages>::scavengePage): (bmalloc::passedNumPages>::scavenge): (bmalloc::passedNumPages>::scavengeToHighWatermark): (bmalloc::passedNumPages>::freeableMemory): Deleted. * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::takeFirstEligible): (bmalloc::IsoHeapImpl<Config>::scavenge): (bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark): (bmalloc::IsoHeapImpl<Config>::freeableMemory): (bmalloc::IsoHeapImpl<Config>::isNowFreeable): (bmalloc::IsoHeapImpl<Config>::isNoLongerFreeable): * bmalloc/LargeMap.cpp: (bmalloc::LargeMap::remove): (bmalloc::LargeMap::markAllAsEligibile): * bmalloc/LargeMap.h: (bmalloc::LargeMap::size): (bmalloc::LargeMap::at): * bmalloc/LargeRange.h: (bmalloc::LargeRange::setEligible): (bmalloc::LargeRange::isEligibile const): (bmalloc::canMerge): * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/Scavenger.cpp: (bmalloc::PrintTime::PrintTime): (bmalloc::PrintTime::~PrintTime): (bmalloc::PrintTime::print): (bmalloc::Scavenger::timeSinceLastFullScavenge): (bmalloc::Scavenger::timeSinceLastPartialScavenge): (bmalloc::Scavenger::scavenge): (bmalloc::Scavenger::partialScavenge): (bmalloc::Scavenger::freeableMemory): (bmalloc::Scavenger::threadRunLoop): * bmalloc/Scavenger.h: * bmalloc/SmallLine.h: (bmalloc::SmallLine::refCount): (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): * bmalloc/SmallPage.h: (bmalloc::SmallPage::refCount): (bmalloc::SmallPage::hasFreeLines const): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): * bmalloc/bmalloc.cpp: (bmalloc::api::tryLargeZeroedMemalignVirtual): (bmalloc::api::freeLargeVirtual): Canonical link: https://commits.webkit.org/200026@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230501 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-04-10 23:34:42 +00:00
* Copyright (C) 2014-2018 Apple Inc. All rights reserved.
bmalloc https://bugs.webkit.org/show_bug.cgi?id=131170 Reviewed by Andreas Kling. Initial commit. * bmalloc: Added. * bmalloc.xcodeproj: Added. * bmalloc.xcodeproj/project.pbxproj: Added. * bmalloc/Algorithm.h: Added. (bmalloc::max): (bmalloc::min): (bmalloc::mask): (bmalloc::test): (bmalloc::roundUpToMultipleOf): (bmalloc::roundDownToMultipleOf): (bmalloc::sizeOf): (bmalloc::bitCount): (bmalloc::isPowerOfTwo): * bmalloc/Allocator.cpp: Added. (bmalloc::Allocator::Allocator): (bmalloc::Allocator::~Allocator): (bmalloc::Allocator::log): (bmalloc::Allocator::processSmallAllocatorLog): (bmalloc::Allocator::processMediumAllocatorLog): (bmalloc::Allocator::allocateLarge): (bmalloc::Allocator::allocateXLarge): (bmalloc::Allocator::allocateMedium): (bmalloc::Allocator::allocateSlowCase): * bmalloc/Allocator.h: Added. (bmalloc::Allocator::smallAllocatorFor): (bmalloc::Allocator::allocateFastCase): (bmalloc::Allocator::allocate): * bmalloc/AsyncTask.cpp: Added. (bmalloc::AsyncTask<Function>::runSlowCase): (bmalloc::AsyncTask<Function>::pthreadEntryPoint): (bmalloc::AsyncTask<Function>::entryPoint): * bmalloc/AsyncTask.h: Added. (bmalloc::Function>::AsyncTask): (bmalloc::Function>::join): (bmalloc::Function>::run): (bmalloc::Function>::runSlowCase): (bmalloc::Function>::pthreadEntryPoint): (bmalloc::Function>::entryPoint): * bmalloc/BAssert.h: Added. * bmalloc/BeginTag.h: Added. (bmalloc::BeginTag::isInFreeList): * bmalloc/BoundaryTag.h: Added. (bmalloc::BoundaryTag::isXLarge): (bmalloc::BoundaryTag::setXLarge): (bmalloc::BoundaryTag::isFree): (bmalloc::BoundaryTag::setFree): (bmalloc::BoundaryTag::isEnd): (bmalloc::BoundaryTag::setEnd): (bmalloc::BoundaryTag::hasPhysicalPages): (bmalloc::BoundaryTag::setHasPhysicalPages): (bmalloc::BoundaryTag::isNull): (bmalloc::BoundaryTag::clear): (bmalloc::BoundaryTag::size): (bmalloc::BoundaryTag::setSize): (bmalloc::BoundaryTag::prev): (bmalloc::BoundaryTag::next): * bmalloc/BoundaryTagInlines.h: Added. (bmalloc::validate): (bmalloc::validatePrev): (bmalloc::validateNext): (bmalloc::BoundaryTag::init): (bmalloc::BoundaryTag::mergeLargeLeft): (bmalloc::BoundaryTag::mergeLargeRight): (bmalloc::BoundaryTag::mergeLarge): (bmalloc::BoundaryTag::deallocate): (bmalloc::BoundaryTag::splitLarge): (bmalloc::BoundaryTag::allocate): * bmalloc/Cache.cpp: Added. (bmalloc::Cache::operator new): (bmalloc::Cache::operator delete): (bmalloc::Cache::Cache): (bmalloc::Cache::allocateSlowCase): (bmalloc::Cache::allocateSlowCaseNullCache): (bmalloc::Cache::deallocateSlowCase): (bmalloc::Cache::deallocateSlowCaseNullCache): * bmalloc/Cache.h: Added. (bmalloc::Cache::allocator): (bmalloc::Cache::deallocator): (bmalloc::Cache::allocateFastCase): (bmalloc::Cache::deallocateFastCase): (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): * bmalloc/Chunk.h: Added. (bmalloc::Chunk::begin): (bmalloc::Chunk::end): (bmalloc::Chunk::lines): (bmalloc::Chunk::pages): * bmalloc/Deallocator.cpp: Added. (bmalloc::Deallocator::Deallocator): (bmalloc::Deallocator::~Deallocator): (bmalloc::Deallocator::deallocateLarge): (bmalloc::Deallocator::deallocateXLarge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): (bmalloc::Deallocator::deallocateSmallLine): (bmalloc::Deallocator::allocateSmallLine): (bmalloc::Deallocator::deallocateMediumLine): (bmalloc::Deallocator::allocateMediumLine): * bmalloc/Deallocator.h: Added. (bmalloc::Deallocator::deallocateFastCase): (bmalloc::Deallocator::deallocate): * bmalloc/EndTag.h: Added. (bmalloc::EndTag::operator=): * bmalloc/FixedVector.h: Added. (bmalloc::FixedVector::begin): (bmalloc::FixedVector::end): (bmalloc::FixedVector::size): (bmalloc::FixedVector::capacity): (bmalloc::FixedVector::clear): (bmalloc::FixedVector::isEmpty): (bmalloc::Capacity>::FixedVector): (bmalloc::Capacity>::operator): (bmalloc::Capacity>::push): (bmalloc::Capacity>::pop): (bmalloc::Capacity>::shrink): * bmalloc/Heap.cpp: Added. (bmalloc::sleep): (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeMediumPages): (bmalloc::Heap::scavengeLargeRanges): (bmalloc::Heap::allocateSmallLineSlowCase): (bmalloc::Heap::allocateMediumLineSlowCase): (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::deallocateXLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: Added. (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallLine): (bmalloc::Heap::deallocateMediumLine): (bmalloc::Heap::allocateMediumLine): * bmalloc/Inline.h: Added. * bmalloc/LargeChunk.h: Added. (bmalloc::LargeChunk::begin): (bmalloc::LargeChunk::end): (bmalloc::LargeChunk::create): (bmalloc::LargeChunk::get): (bmalloc::LargeChunk::beginTag): (bmalloc::LargeChunk::endTag): * bmalloc/Line.h: Added. (bmalloc::Line<Traits>::begin): (bmalloc::Line<Traits>::end): (bmalloc::Line<Traits>::concurrentRef): (bmalloc::Line<Traits>::deref): * bmalloc/MediumAllocator.h: Added. (bmalloc::MediumAllocator::isNull): (bmalloc::MediumAllocator::MediumAllocator): (bmalloc::MediumAllocator::line): (bmalloc::MediumAllocator::allocate): (bmalloc::MediumAllocator::derefCount): (bmalloc::MediumAllocator::refill): * bmalloc/MediumChunk.h: Added. * bmalloc/MediumLine.h: Added. * bmalloc/MediumPage.h: Added. * bmalloc/MediumTraits.h: Added. * bmalloc/Mutex.cpp: Added. (bmalloc::Mutex::lockSlowCase): * bmalloc/Mutex.h: Added. (bmalloc::Mutex::Mutex): (bmalloc::Mutex::try_lock): (bmalloc::Mutex::lock): (bmalloc::Mutex::unlock): * bmalloc/ObjectType.cpp: Added. (bmalloc::objectType): * bmalloc/ObjectType.h: Added. (bmalloc::isSmallOrMedium): (bmalloc::isSmall): * bmalloc/Page.h: Added. (bmalloc::Page<Traits>::ref): (bmalloc::Page<Traits>::deref): (bmalloc::Page<Traits>::refCount): * bmalloc/PerProcess.h: Added. (bmalloc::PerProcess::mutex): (bmalloc::PerProcess<T>::getFastCase): (bmalloc::PerProcess<T>::get): (bmalloc::PerProcess<T>::getSlowCase): * bmalloc/PerThread.h: Added. (bmalloc::PerThreadStorage<Cache>::get): (bmalloc::PerThreadStorage<Cache>::init): (bmalloc::PerThreadStorage::get): (bmalloc::PerThreadStorage::init): (bmalloc::PerThread<T>::getFastCase): (bmalloc::PerThread<T>::get): (bmalloc::PerThread<T>::destructor): (bmalloc::PerThread<T>::getSlowCase): * bmalloc/Range.h: Added. (bmalloc::Range::Range): (bmalloc::Range::begin): (bmalloc::Range::end): (bmalloc::Range::size): (bmalloc::Range::operator!): (bmalloc::Range::operator<): * bmalloc/SegregatedFreeList.cpp: Added. (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: Added. * bmalloc/Sizes.h: Added. * bmalloc/SmallAllocator.h: Added. (bmalloc::SmallAllocator::isNull): (bmalloc::SmallAllocator::canAllocate): (bmalloc::SmallAllocator::SmallAllocator): (bmalloc::SmallAllocator::line): (bmalloc::SmallAllocator::allocate): (bmalloc::SmallAllocator::objectCount): (bmalloc::SmallAllocator::derefCount): (bmalloc::SmallAllocator::refill): * bmalloc/SmallChunk.h: Added. * bmalloc/SmallLine.h: Added. * bmalloc/SmallPage.h: Added. * bmalloc/SmallTraits.h: Added. * bmalloc/Syscall.h: Added. * bmalloc/VMAllocate.h: Added. (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::vmAllocate): (bmalloc::vmDeallocate): (bmalloc::vmDeallocatePhysicalPages): (bmalloc::vmAllocatePhysicalPages): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): * bmalloc/VMHeap.cpp: Added. (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::allocateMediumChunk): (bmalloc::VMHeap::allocateLargeChunk): * bmalloc/VMHeap.h: Added. (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeRange): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::deallocateMediumPage): (bmalloc::VMHeap::deallocateLargeRange): * bmalloc/Vector.h: Added. (bmalloc::Vector::begin): (bmalloc::Vector::end): (bmalloc::Vector::size): (bmalloc::Vector::capacity): (bmalloc::Vector::last): (bmalloc::Vector::pop): (bmalloc::Vector<T>::Vector): (bmalloc::Vector<T>::~Vector): (bmalloc::Vector<T>::operator): (bmalloc::Vector<T>::push): (bmalloc::Vector<T>::pop): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::reallocateBuffer): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): * bmalloc/XLargeChunk.h: Added. (bmalloc::XLargeChunk::get): (bmalloc::XLargeChunk::begin): (bmalloc::XLargeChunk::XLargeChunk): (bmalloc::XLargeChunk::create): (bmalloc::XLargeChunk::destroy): (bmalloc::XLargeChunk::range): (bmalloc::XLargeChunk::size): * bmalloc/bmalloc.h: Added. (bmalloc::api::malloc): (bmalloc::api::free): (bmalloc::api::realloc): * bmalloc/mbmalloc.cpp: Added. Canonical link: https://commits.webkit.org/149378@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166893 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-07 23:54:11 +00:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SmallPage_h
#define SmallPage_h
bmalloc https://bugs.webkit.org/show_bug.cgi?id=131170 Reviewed by Andreas Kling. Initial commit. * bmalloc: Added. * bmalloc.xcodeproj: Added. * bmalloc.xcodeproj/project.pbxproj: Added. * bmalloc/Algorithm.h: Added. (bmalloc::max): (bmalloc::min): (bmalloc::mask): (bmalloc::test): (bmalloc::roundUpToMultipleOf): (bmalloc::roundDownToMultipleOf): (bmalloc::sizeOf): (bmalloc::bitCount): (bmalloc::isPowerOfTwo): * bmalloc/Allocator.cpp: Added. (bmalloc::Allocator::Allocator): (bmalloc::Allocator::~Allocator): (bmalloc::Allocator::log): (bmalloc::Allocator::processSmallAllocatorLog): (bmalloc::Allocator::processMediumAllocatorLog): (bmalloc::Allocator::allocateLarge): (bmalloc::Allocator::allocateXLarge): (bmalloc::Allocator::allocateMedium): (bmalloc::Allocator::allocateSlowCase): * bmalloc/Allocator.h: Added. (bmalloc::Allocator::smallAllocatorFor): (bmalloc::Allocator::allocateFastCase): (bmalloc::Allocator::allocate): * bmalloc/AsyncTask.cpp: Added. (bmalloc::AsyncTask<Function>::runSlowCase): (bmalloc::AsyncTask<Function>::pthreadEntryPoint): (bmalloc::AsyncTask<Function>::entryPoint): * bmalloc/AsyncTask.h: Added. (bmalloc::Function>::AsyncTask): (bmalloc::Function>::join): (bmalloc::Function>::run): (bmalloc::Function>::runSlowCase): (bmalloc::Function>::pthreadEntryPoint): (bmalloc::Function>::entryPoint): * bmalloc/BAssert.h: Added. * bmalloc/BeginTag.h: Added. (bmalloc::BeginTag::isInFreeList): * bmalloc/BoundaryTag.h: Added. (bmalloc::BoundaryTag::isXLarge): (bmalloc::BoundaryTag::setXLarge): (bmalloc::BoundaryTag::isFree): (bmalloc::BoundaryTag::setFree): (bmalloc::BoundaryTag::isEnd): (bmalloc::BoundaryTag::setEnd): (bmalloc::BoundaryTag::hasPhysicalPages): (bmalloc::BoundaryTag::setHasPhysicalPages): (bmalloc::BoundaryTag::isNull): (bmalloc::BoundaryTag::clear): (bmalloc::BoundaryTag::size): (bmalloc::BoundaryTag::setSize): (bmalloc::BoundaryTag::prev): (bmalloc::BoundaryTag::next): * bmalloc/BoundaryTagInlines.h: Added. (bmalloc::validate): (bmalloc::validatePrev): (bmalloc::validateNext): (bmalloc::BoundaryTag::init): (bmalloc::BoundaryTag::mergeLargeLeft): (bmalloc::BoundaryTag::mergeLargeRight): (bmalloc::BoundaryTag::mergeLarge): (bmalloc::BoundaryTag::deallocate): (bmalloc::BoundaryTag::splitLarge): (bmalloc::BoundaryTag::allocate): * bmalloc/Cache.cpp: Added. (bmalloc::Cache::operator new): (bmalloc::Cache::operator delete): (bmalloc::Cache::Cache): (bmalloc::Cache::allocateSlowCase): (bmalloc::Cache::allocateSlowCaseNullCache): (bmalloc::Cache::deallocateSlowCase): (bmalloc::Cache::deallocateSlowCaseNullCache): * bmalloc/Cache.h: Added. (bmalloc::Cache::allocator): (bmalloc::Cache::deallocator): (bmalloc::Cache::allocateFastCase): (bmalloc::Cache::deallocateFastCase): (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): * bmalloc/Chunk.h: Added. (bmalloc::Chunk::begin): (bmalloc::Chunk::end): (bmalloc::Chunk::lines): (bmalloc::Chunk::pages): * bmalloc/Deallocator.cpp: Added. (bmalloc::Deallocator::Deallocator): (bmalloc::Deallocator::~Deallocator): (bmalloc::Deallocator::deallocateLarge): (bmalloc::Deallocator::deallocateXLarge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): (bmalloc::Deallocator::deallocateSmallLine): (bmalloc::Deallocator::allocateSmallLine): (bmalloc::Deallocator::deallocateMediumLine): (bmalloc::Deallocator::allocateMediumLine): * bmalloc/Deallocator.h: Added. (bmalloc::Deallocator::deallocateFastCase): (bmalloc::Deallocator::deallocate): * bmalloc/EndTag.h: Added. (bmalloc::EndTag::operator=): * bmalloc/FixedVector.h: Added. (bmalloc::FixedVector::begin): (bmalloc::FixedVector::end): (bmalloc::FixedVector::size): (bmalloc::FixedVector::capacity): (bmalloc::FixedVector::clear): (bmalloc::FixedVector::isEmpty): (bmalloc::Capacity>::FixedVector): (bmalloc::Capacity>::operator): (bmalloc::Capacity>::push): (bmalloc::Capacity>::pop): (bmalloc::Capacity>::shrink): * bmalloc/Heap.cpp: Added. (bmalloc::sleep): (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeMediumPages): (bmalloc::Heap::scavengeLargeRanges): (bmalloc::Heap::allocateSmallLineSlowCase): (bmalloc::Heap::allocateMediumLineSlowCase): (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::deallocateXLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: Added. (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallLine): (bmalloc::Heap::deallocateMediumLine): (bmalloc::Heap::allocateMediumLine): * bmalloc/Inline.h: Added. * bmalloc/LargeChunk.h: Added. (bmalloc::LargeChunk::begin): (bmalloc::LargeChunk::end): (bmalloc::LargeChunk::create): (bmalloc::LargeChunk::get): (bmalloc::LargeChunk::beginTag): (bmalloc::LargeChunk::endTag): * bmalloc/Line.h: Added. (bmalloc::Line<Traits>::begin): (bmalloc::Line<Traits>::end): (bmalloc::Line<Traits>::concurrentRef): (bmalloc::Line<Traits>::deref): * bmalloc/MediumAllocator.h: Added. (bmalloc::MediumAllocator::isNull): (bmalloc::MediumAllocator::MediumAllocator): (bmalloc::MediumAllocator::line): (bmalloc::MediumAllocator::allocate): (bmalloc::MediumAllocator::derefCount): (bmalloc::MediumAllocator::refill): * bmalloc/MediumChunk.h: Added. * bmalloc/MediumLine.h: Added. * bmalloc/MediumPage.h: Added. * bmalloc/MediumTraits.h: Added. * bmalloc/Mutex.cpp: Added. (bmalloc::Mutex::lockSlowCase): * bmalloc/Mutex.h: Added. (bmalloc::Mutex::Mutex): (bmalloc::Mutex::try_lock): (bmalloc::Mutex::lock): (bmalloc::Mutex::unlock): * bmalloc/ObjectType.cpp: Added. (bmalloc::objectType): * bmalloc/ObjectType.h: Added. (bmalloc::isSmallOrMedium): (bmalloc::isSmall): * bmalloc/Page.h: Added. (bmalloc::Page<Traits>::ref): (bmalloc::Page<Traits>::deref): (bmalloc::Page<Traits>::refCount): * bmalloc/PerProcess.h: Added. (bmalloc::PerProcess::mutex): (bmalloc::PerProcess<T>::getFastCase): (bmalloc::PerProcess<T>::get): (bmalloc::PerProcess<T>::getSlowCase): * bmalloc/PerThread.h: Added. (bmalloc::PerThreadStorage<Cache>::get): (bmalloc::PerThreadStorage<Cache>::init): (bmalloc::PerThreadStorage::get): (bmalloc::PerThreadStorage::init): (bmalloc::PerThread<T>::getFastCase): (bmalloc::PerThread<T>::get): (bmalloc::PerThread<T>::destructor): (bmalloc::PerThread<T>::getSlowCase): * bmalloc/Range.h: Added. (bmalloc::Range::Range): (bmalloc::Range::begin): (bmalloc::Range::end): (bmalloc::Range::size): (bmalloc::Range::operator!): (bmalloc::Range::operator<): * bmalloc/SegregatedFreeList.cpp: Added. (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: Added. * bmalloc/Sizes.h: Added. * bmalloc/SmallAllocator.h: Added. (bmalloc::SmallAllocator::isNull): (bmalloc::SmallAllocator::canAllocate): (bmalloc::SmallAllocator::SmallAllocator): (bmalloc::SmallAllocator::line): (bmalloc::SmallAllocator::allocate): (bmalloc::SmallAllocator::objectCount): (bmalloc::SmallAllocator::derefCount): (bmalloc::SmallAllocator::refill): * bmalloc/SmallChunk.h: Added. * bmalloc/SmallLine.h: Added. * bmalloc/SmallPage.h: Added. * bmalloc/SmallTraits.h: Added. * bmalloc/Syscall.h: Added. * bmalloc/VMAllocate.h: Added. (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::vmAllocate): (bmalloc::vmDeallocate): (bmalloc::vmDeallocatePhysicalPages): (bmalloc::vmAllocatePhysicalPages): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): * bmalloc/VMHeap.cpp: Added. (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::allocateMediumChunk): (bmalloc::VMHeap::allocateLargeChunk): * bmalloc/VMHeap.h: Added. (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeRange): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::deallocateMediumPage): (bmalloc::VMHeap::deallocateLargeRange): * bmalloc/Vector.h: Added. (bmalloc::Vector::begin): (bmalloc::Vector::end): (bmalloc::Vector::size): (bmalloc::Vector::capacity): (bmalloc::Vector::last): (bmalloc::Vector::pop): (bmalloc::Vector<T>::Vector): (bmalloc::Vector<T>::~Vector): (bmalloc::Vector<T>::operator): (bmalloc::Vector<T>::push): (bmalloc::Vector<T>::pop): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::reallocateBuffer): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): * bmalloc/XLargeChunk.h: Added. (bmalloc::XLargeChunk::get): (bmalloc::XLargeChunk::begin): (bmalloc::XLargeChunk::XLargeChunk): (bmalloc::XLargeChunk::create): (bmalloc::XLargeChunk::destroy): (bmalloc::XLargeChunk::range): (bmalloc::XLargeChunk::size): * bmalloc/bmalloc.h: Added. (bmalloc::api::malloc): (bmalloc::api::free): (bmalloc::api::realloc): * bmalloc/mbmalloc.cpp: Added. Canonical link: https://commits.webkit.org/149378@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166893 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-07 23:54:11 +00:00
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
#include "BAssert.h"
#include "List.h"
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
#include "Mutex.h"
#include "VMAllocate.h"
#include <mutex>
bmalloc https://bugs.webkit.org/show_bug.cgi?id=131170 Reviewed by Andreas Kling. Initial commit. * bmalloc: Added. * bmalloc.xcodeproj: Added. * bmalloc.xcodeproj/project.pbxproj: Added. * bmalloc/Algorithm.h: Added. (bmalloc::max): (bmalloc::min): (bmalloc::mask): (bmalloc::test): (bmalloc::roundUpToMultipleOf): (bmalloc::roundDownToMultipleOf): (bmalloc::sizeOf): (bmalloc::bitCount): (bmalloc::isPowerOfTwo): * bmalloc/Allocator.cpp: Added. (bmalloc::Allocator::Allocator): (bmalloc::Allocator::~Allocator): (bmalloc::Allocator::log): (bmalloc::Allocator::processSmallAllocatorLog): (bmalloc::Allocator::processMediumAllocatorLog): (bmalloc::Allocator::allocateLarge): (bmalloc::Allocator::allocateXLarge): (bmalloc::Allocator::allocateMedium): (bmalloc::Allocator::allocateSlowCase): * bmalloc/Allocator.h: Added. (bmalloc::Allocator::smallAllocatorFor): (bmalloc::Allocator::allocateFastCase): (bmalloc::Allocator::allocate): * bmalloc/AsyncTask.cpp: Added. (bmalloc::AsyncTask<Function>::runSlowCase): (bmalloc::AsyncTask<Function>::pthreadEntryPoint): (bmalloc::AsyncTask<Function>::entryPoint): * bmalloc/AsyncTask.h: Added. (bmalloc::Function>::AsyncTask): (bmalloc::Function>::join): (bmalloc::Function>::run): (bmalloc::Function>::runSlowCase): (bmalloc::Function>::pthreadEntryPoint): (bmalloc::Function>::entryPoint): * bmalloc/BAssert.h: Added. * bmalloc/BeginTag.h: Added. (bmalloc::BeginTag::isInFreeList): * bmalloc/BoundaryTag.h: Added. (bmalloc::BoundaryTag::isXLarge): (bmalloc::BoundaryTag::setXLarge): (bmalloc::BoundaryTag::isFree): (bmalloc::BoundaryTag::setFree): (bmalloc::BoundaryTag::isEnd): (bmalloc::BoundaryTag::setEnd): (bmalloc::BoundaryTag::hasPhysicalPages): (bmalloc::BoundaryTag::setHasPhysicalPages): (bmalloc::BoundaryTag::isNull): (bmalloc::BoundaryTag::clear): (bmalloc::BoundaryTag::size): (bmalloc::BoundaryTag::setSize): (bmalloc::BoundaryTag::prev): (bmalloc::BoundaryTag::next): * bmalloc/BoundaryTagInlines.h: Added. (bmalloc::validate): (bmalloc::validatePrev): (bmalloc::validateNext): (bmalloc::BoundaryTag::init): (bmalloc::BoundaryTag::mergeLargeLeft): (bmalloc::BoundaryTag::mergeLargeRight): (bmalloc::BoundaryTag::mergeLarge): (bmalloc::BoundaryTag::deallocate): (bmalloc::BoundaryTag::splitLarge): (bmalloc::BoundaryTag::allocate): * bmalloc/Cache.cpp: Added. (bmalloc::Cache::operator new): (bmalloc::Cache::operator delete): (bmalloc::Cache::Cache): (bmalloc::Cache::allocateSlowCase): (bmalloc::Cache::allocateSlowCaseNullCache): (bmalloc::Cache::deallocateSlowCase): (bmalloc::Cache::deallocateSlowCaseNullCache): * bmalloc/Cache.h: Added. (bmalloc::Cache::allocator): (bmalloc::Cache::deallocator): (bmalloc::Cache::allocateFastCase): (bmalloc::Cache::deallocateFastCase): (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): * bmalloc/Chunk.h: Added. (bmalloc::Chunk::begin): (bmalloc::Chunk::end): (bmalloc::Chunk::lines): (bmalloc::Chunk::pages): * bmalloc/Deallocator.cpp: Added. (bmalloc::Deallocator::Deallocator): (bmalloc::Deallocator::~Deallocator): (bmalloc::Deallocator::deallocateLarge): (bmalloc::Deallocator::deallocateXLarge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): (bmalloc::Deallocator::deallocateSmallLine): (bmalloc::Deallocator::allocateSmallLine): (bmalloc::Deallocator::deallocateMediumLine): (bmalloc::Deallocator::allocateMediumLine): * bmalloc/Deallocator.h: Added. (bmalloc::Deallocator::deallocateFastCase): (bmalloc::Deallocator::deallocate): * bmalloc/EndTag.h: Added. (bmalloc::EndTag::operator=): * bmalloc/FixedVector.h: Added. (bmalloc::FixedVector::begin): (bmalloc::FixedVector::end): (bmalloc::FixedVector::size): (bmalloc::FixedVector::capacity): (bmalloc::FixedVector::clear): (bmalloc::FixedVector::isEmpty): (bmalloc::Capacity>::FixedVector): (bmalloc::Capacity>::operator): (bmalloc::Capacity>::push): (bmalloc::Capacity>::pop): (bmalloc::Capacity>::shrink): * bmalloc/Heap.cpp: Added. (bmalloc::sleep): (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeMediumPages): (bmalloc::Heap::scavengeLargeRanges): (bmalloc::Heap::allocateSmallLineSlowCase): (bmalloc::Heap::allocateMediumLineSlowCase): (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::deallocateXLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: Added. (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallLine): (bmalloc::Heap::deallocateMediumLine): (bmalloc::Heap::allocateMediumLine): * bmalloc/Inline.h: Added. * bmalloc/LargeChunk.h: Added. (bmalloc::LargeChunk::begin): (bmalloc::LargeChunk::end): (bmalloc::LargeChunk::create): (bmalloc::LargeChunk::get): (bmalloc::LargeChunk::beginTag): (bmalloc::LargeChunk::endTag): * bmalloc/Line.h: Added. (bmalloc::Line<Traits>::begin): (bmalloc::Line<Traits>::end): (bmalloc::Line<Traits>::concurrentRef): (bmalloc::Line<Traits>::deref): * bmalloc/MediumAllocator.h: Added. (bmalloc::MediumAllocator::isNull): (bmalloc::MediumAllocator::MediumAllocator): (bmalloc::MediumAllocator::line): (bmalloc::MediumAllocator::allocate): (bmalloc::MediumAllocator::derefCount): (bmalloc::MediumAllocator::refill): * bmalloc/MediumChunk.h: Added. * bmalloc/MediumLine.h: Added. * bmalloc/MediumPage.h: Added. * bmalloc/MediumTraits.h: Added. * bmalloc/Mutex.cpp: Added. (bmalloc::Mutex::lockSlowCase): * bmalloc/Mutex.h: Added. (bmalloc::Mutex::Mutex): (bmalloc::Mutex::try_lock): (bmalloc::Mutex::lock): (bmalloc::Mutex::unlock): * bmalloc/ObjectType.cpp: Added. (bmalloc::objectType): * bmalloc/ObjectType.h: Added. (bmalloc::isSmallOrMedium): (bmalloc::isSmall): * bmalloc/Page.h: Added. (bmalloc::Page<Traits>::ref): (bmalloc::Page<Traits>::deref): (bmalloc::Page<Traits>::refCount): * bmalloc/PerProcess.h: Added. (bmalloc::PerProcess::mutex): (bmalloc::PerProcess<T>::getFastCase): (bmalloc::PerProcess<T>::get): (bmalloc::PerProcess<T>::getSlowCase): * bmalloc/PerThread.h: Added. (bmalloc::PerThreadStorage<Cache>::get): (bmalloc::PerThreadStorage<Cache>::init): (bmalloc::PerThreadStorage::get): (bmalloc::PerThreadStorage::init): (bmalloc::PerThread<T>::getFastCase): (bmalloc::PerThread<T>::get): (bmalloc::PerThread<T>::destructor): (bmalloc::PerThread<T>::getSlowCase): * bmalloc/Range.h: Added. (bmalloc::Range::Range): (bmalloc::Range::begin): (bmalloc::Range::end): (bmalloc::Range::size): (bmalloc::Range::operator!): (bmalloc::Range::operator<): * bmalloc/SegregatedFreeList.cpp: Added. (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: Added. * bmalloc/Sizes.h: Added. * bmalloc/SmallAllocator.h: Added. (bmalloc::SmallAllocator::isNull): (bmalloc::SmallAllocator::canAllocate): (bmalloc::SmallAllocator::SmallAllocator): (bmalloc::SmallAllocator::line): (bmalloc::SmallAllocator::allocate): (bmalloc::SmallAllocator::objectCount): (bmalloc::SmallAllocator::derefCount): (bmalloc::SmallAllocator::refill): * bmalloc/SmallChunk.h: Added. * bmalloc/SmallLine.h: Added. * bmalloc/SmallPage.h: Added. * bmalloc/SmallTraits.h: Added. * bmalloc/Syscall.h: Added. * bmalloc/VMAllocate.h: Added. (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::vmAllocate): (bmalloc::vmDeallocate): (bmalloc::vmDeallocatePhysicalPages): (bmalloc::vmAllocatePhysicalPages): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): * bmalloc/VMHeap.cpp: Added. (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::allocateMediumChunk): (bmalloc::VMHeap::allocateLargeChunk): * bmalloc/VMHeap.h: Added. (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeRange): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::deallocateMediumPage): (bmalloc::VMHeap::deallocateLargeRange): * bmalloc/Vector.h: Added. (bmalloc::Vector::begin): (bmalloc::Vector::end): (bmalloc::Vector::size): (bmalloc::Vector::capacity): (bmalloc::Vector::last): (bmalloc::Vector::pop): (bmalloc::Vector<T>::Vector): (bmalloc::Vector<T>::~Vector): (bmalloc::Vector<T>::operator): (bmalloc::Vector<T>::push): (bmalloc::Vector<T>::pop): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::reallocateBuffer): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): * bmalloc/XLargeChunk.h: Added. (bmalloc::XLargeChunk::get): (bmalloc::XLargeChunk::begin): (bmalloc::XLargeChunk::XLargeChunk): (bmalloc::XLargeChunk::create): (bmalloc::XLargeChunk::destroy): (bmalloc::XLargeChunk::range): (bmalloc::XLargeChunk::size): * bmalloc/bmalloc.h: Added. (bmalloc::api::malloc): (bmalloc::api::free): (bmalloc::api::realloc): * bmalloc/mbmalloc.cpp: Added. Canonical link: https://commits.webkit.org/149378@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166893 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-07 23:54:11 +00:00
namespace bmalloc {
bmalloc: Add a per-thread line cache https://bugs.webkit.org/show_bug.cgi?id=173552 Reviewed by Darin Adler. Previously, any thread could allocate out of any page with free lines. Now, the first thread to free a line in a page owns that page's free lines until the whole page becomes free. This patch is a big speedup on multi-threaded benchmarks. tree_churn --parallel gets 14% faster on a 2-core (4-hyper-core) MacBook Air and 2.85X faster on 12-core (24-hyper-core) Mac Pro. Other parallel benchmarks show significant but smaller speedups. Thread affinity is a great predictor of object lifetime. The per-thread line cache avoids the pathology of shuffling pages between threads, turning predictable lifetimes into unpredictable lifetimes, increasing fragmentation. On tree_churn --parallel, the per-thread line cache increases free memory found per page scanned by 2.85X. Free line scanning in fragmented pages is pretty expensive relative to other allocate / initialize / free operations. According to Instruments, on tree_churn --parallel, scanning is about 10X more expensive than freeing. This explains why a 2.85X improvement in scanning efficiency translates into a 2.85X overall speedup on tree_churn --parallel. * bmalloc/Allocator.cpp: (bmalloc::Allocator::refillAllocatorSlowCase): Pass through our line cache so the Heap can fill it. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): Scavenge our line cache. (bmalloc::Deallocator::processObjectLog): Deleted. * bmalloc/Deallocator.h: (bmalloc::Deallocator::lineCache): Added a line cache. * bmalloc/Heap.cpp: (bmalloc::Heap::deallocateLineCache): Deallocation function for thread destruction. (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): Consult the new per-thread line cache for allocation and deallocation. * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): * bmalloc/List.h: (bmalloc::List::remove): Remove has always been a logically static operation. Declare it static now so that the Heap can remove a page from a thread's line cache without holding a direct pointer to the cache. * bmalloc/SmallPage.h: Canonical link: https://commits.webkit.org/190669@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218788 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-24 20:14:33 +00:00
class SmallLine;
class SmallPage : public ListNode<SmallPage> {
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
public:
[bmalloc] Define alias for std::lock_guard and std::unique_lock for better readability https://bugs.webkit.org/show_bug.cgi?id=206443 Reviewed by Yusuke Suzuki. There are two types of lock holder in bmalloc: std::lock_guard and std::unique_lock. Their names are relatively long and a bit harder to distinguish them each other. Define simple type name for them, LockHolder and UniqueLockHolder. * bmalloc/AllIsoHeaps.cpp: (bmalloc::AllIsoHeaps::AllIsoHeaps): (bmalloc::AllIsoHeaps::add): (bmalloc::AllIsoHeaps::head): * bmalloc/AllIsoHeaps.h: * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocateImpl): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::allocateLarge): * bmalloc/CryptoRandom.cpp: (bmalloc::ARC4RandomNumberGenerator::ARC4RandomNumberGenerator): (bmalloc::ARC4RandomNumberGenerator::randomValues): * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: (bmalloc::Deallocator::lineCache): * bmalloc/DebugHeap.cpp: (bmalloc::DebugHeap::DebugHeap): (bmalloc::DebugHeap::memalignLarge): (bmalloc::DebugHeap::freeLarge): * bmalloc/DebugHeap.h: * bmalloc/DeferredTrigger.h: * bmalloc/DeferredTriggerInlines.h: (bmalloc::DeferredTrigger<trigger>::didBecome): (bmalloc::DeferredTrigger<trigger>::handleDeferral): * bmalloc/Environment.cpp: (bmalloc::Environment::Environment): * bmalloc/Environment.h: * bmalloc/Gigacage.cpp: (bmalloc::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks): (Gigacage::disablePrimitiveGigacage): (Gigacage::addPrimitiveDisableCallback): (Gigacage::removePrimitiveDisableCallback): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::freeableMemory): (bmalloc::Heap::markAllLargeAsEligibile): (bmalloc::Heap::decommitLargeRange): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeToHighWatermark): (bmalloc::Heap::deallocateLineCache): (bmalloc::Heap::allocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::isLarge): (bmalloc::Heap::largeSize): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): (bmalloc::Heap::externalCommit): (bmalloc::Heap::externalDecommit): * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): * bmalloc/HeapConstants.cpp: (bmalloc::HeapConstants::HeapConstants): * bmalloc/HeapConstants.h: * bmalloc/IsoAllocatorInlines.h: (bmalloc::IsoAllocator<Config>::allocateSlow): (bmalloc::IsoAllocator<Config>::scavenge): * bmalloc/IsoDeallocatorInlines.h: (bmalloc::IsoDeallocator<Config>::deallocate): (bmalloc::IsoDeallocator<Config>::scavenge): * bmalloc/IsoDirectory.h: * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::didBecome): (bmalloc::passedNumPages>::didDecommit): (bmalloc::passedNumPages>::scavengePage): (bmalloc::passedNumPages>::scavenge): (bmalloc::passedNumPages>::scavengeToHighWatermark): (bmalloc::passedNumPages>::forEachCommittedPage): * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::takeFirstEligible): (bmalloc::IsoHeapImpl<Config>::didBecomeEligibleOrDecommited): (bmalloc::IsoHeapImpl<Config>::scavenge): (bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark): (bmalloc::IsoHeapImpl<Config>::numLiveObjects): (bmalloc::IsoHeapImpl<Config>::numCommittedPages): (bmalloc::IsoHeapImpl<Config>::forEachDirectory): (bmalloc::IsoHeapImpl<Config>::forEachCommittedPage): (bmalloc::IsoHeapImpl<Config>::forEachLiveObject): (bmalloc::IsoHeapImpl<Config>::allocateFromShared): * bmalloc/IsoPage.h: * bmalloc/IsoPageInlines.h: (bmalloc::IsoPage<Config>::free): (bmalloc::IsoPage<Config>::startAllocating): (bmalloc::IsoPage<Config>::stopAllocating): (bmalloc::IsoPage<Config>::forEachLiveObject): * bmalloc/IsoSharedHeap.h: (bmalloc::IsoSharedHeap::IsoSharedHeap): * bmalloc/IsoSharedHeapInlines.h: (bmalloc::IsoSharedHeap::allocateNew): (bmalloc::IsoSharedHeap::allocateSlow): * bmalloc/IsoSharedPage.h: * bmalloc/IsoSharedPageInlines.h: (bmalloc::IsoSharedPage::free): (bmalloc::IsoSharedPage::startAllocating): (bmalloc::IsoSharedPage::stopAllocating): * bmalloc/IsoTLSDeallocatorEntry.h: * bmalloc/IsoTLSDeallocatorEntryInlines.h: (bmalloc::IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry): * bmalloc/IsoTLSInlines.h: (bmalloc::IsoTLS::ensureHeap): * bmalloc/IsoTLSLayout.cpp: (bmalloc::IsoTLSLayout::IsoTLSLayout): (bmalloc::IsoTLSLayout::add): * bmalloc/IsoTLSLayout.h: * bmalloc/Mutex.h: (bmalloc::sleep): (bmalloc::waitUntilFalse): * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/PerProcess.cpp: (bmalloc::getPerProcessData): * bmalloc/PerProcess.h: (bmalloc::PerProcess::getSlowCase): * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::Scavenger): (bmalloc::Scavenger::run): (bmalloc::Scavenger::runSoon): (bmalloc::Scavenger::scheduleIfUnderMemoryPressure): (bmalloc::Scavenger::schedule): (bmalloc::Scavenger::timeSinceLastFullScavenge): (bmalloc::Scavenger::timeSinceLastPartialScavenge): (bmalloc::Scavenger::scavenge): (bmalloc::Scavenger::partialScavenge): (bmalloc::Scavenger::freeableMemory): (bmalloc::Scavenger::threadRunLoop): * bmalloc/Scavenger.h: * bmalloc/SmallLine.h: (bmalloc::SmallLine::refCount): (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): * bmalloc/SmallPage.h: (bmalloc::SmallPage::refCount): (bmalloc::SmallPage::hasFreeLines const): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): * bmalloc/StaticPerProcess.h: * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): * bmalloc/VMHeap.h: * bmalloc/Zone.cpp: (bmalloc::Zone::Zone): * bmalloc/Zone.h: * bmalloc/bmalloc.cpp: (bmalloc::api::tryLargeZeroedMemalignVirtual): (bmalloc::api::freeLargeVirtual): (bmalloc::api::setScavengerThreadQOSClass): Canonical link: https://commits.webkit.org/219521@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254781 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-18 00:43:00 +00:00
void ref(UniqueLockHolder&);
bool deref(UniqueLockHolder&);
unsigned refCount(UniqueLockHolder&) { return m_refCount; }
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
size_t sizeClass() { return m_sizeClass; }
void setSizeClass(size_t sizeClass) { m_sizeClass = sizeClass; }
[bmalloc] Define alias for std::lock_guard and std::unique_lock for better readability https://bugs.webkit.org/show_bug.cgi?id=206443 Reviewed by Yusuke Suzuki. There are two types of lock holder in bmalloc: std::lock_guard and std::unique_lock. Their names are relatively long and a bit harder to distinguish them each other. Define simple type name for them, LockHolder and UniqueLockHolder. * bmalloc/AllIsoHeaps.cpp: (bmalloc::AllIsoHeaps::AllIsoHeaps): (bmalloc::AllIsoHeaps::add): (bmalloc::AllIsoHeaps::head): * bmalloc/AllIsoHeaps.h: * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocateImpl): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::allocateLarge): * bmalloc/CryptoRandom.cpp: (bmalloc::ARC4RandomNumberGenerator::ARC4RandomNumberGenerator): (bmalloc::ARC4RandomNumberGenerator::randomValues): * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: (bmalloc::Deallocator::lineCache): * bmalloc/DebugHeap.cpp: (bmalloc::DebugHeap::DebugHeap): (bmalloc::DebugHeap::memalignLarge): (bmalloc::DebugHeap::freeLarge): * bmalloc/DebugHeap.h: * bmalloc/DeferredTrigger.h: * bmalloc/DeferredTriggerInlines.h: (bmalloc::DeferredTrigger<trigger>::didBecome): (bmalloc::DeferredTrigger<trigger>::handleDeferral): * bmalloc/Environment.cpp: (bmalloc::Environment::Environment): * bmalloc/Environment.h: * bmalloc/Gigacage.cpp: (bmalloc::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks): (Gigacage::disablePrimitiveGigacage): (Gigacage::addPrimitiveDisableCallback): (Gigacage::removePrimitiveDisableCallback): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::freeableMemory): (bmalloc::Heap::markAllLargeAsEligibile): (bmalloc::Heap::decommitLargeRange): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeToHighWatermark): (bmalloc::Heap::deallocateLineCache): (bmalloc::Heap::allocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::isLarge): (bmalloc::Heap::largeSize): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): (bmalloc::Heap::externalCommit): (bmalloc::Heap::externalDecommit): * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): * bmalloc/HeapConstants.cpp: (bmalloc::HeapConstants::HeapConstants): * bmalloc/HeapConstants.h: * bmalloc/IsoAllocatorInlines.h: (bmalloc::IsoAllocator<Config>::allocateSlow): (bmalloc::IsoAllocator<Config>::scavenge): * bmalloc/IsoDeallocatorInlines.h: (bmalloc::IsoDeallocator<Config>::deallocate): (bmalloc::IsoDeallocator<Config>::scavenge): * bmalloc/IsoDirectory.h: * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::didBecome): (bmalloc::passedNumPages>::didDecommit): (bmalloc::passedNumPages>::scavengePage): (bmalloc::passedNumPages>::scavenge): (bmalloc::passedNumPages>::scavengeToHighWatermark): (bmalloc::passedNumPages>::forEachCommittedPage): * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::takeFirstEligible): (bmalloc::IsoHeapImpl<Config>::didBecomeEligibleOrDecommited): (bmalloc::IsoHeapImpl<Config>::scavenge): (bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark): (bmalloc::IsoHeapImpl<Config>::numLiveObjects): (bmalloc::IsoHeapImpl<Config>::numCommittedPages): (bmalloc::IsoHeapImpl<Config>::forEachDirectory): (bmalloc::IsoHeapImpl<Config>::forEachCommittedPage): (bmalloc::IsoHeapImpl<Config>::forEachLiveObject): (bmalloc::IsoHeapImpl<Config>::allocateFromShared): * bmalloc/IsoPage.h: * bmalloc/IsoPageInlines.h: (bmalloc::IsoPage<Config>::free): (bmalloc::IsoPage<Config>::startAllocating): (bmalloc::IsoPage<Config>::stopAllocating): (bmalloc::IsoPage<Config>::forEachLiveObject): * bmalloc/IsoSharedHeap.h: (bmalloc::IsoSharedHeap::IsoSharedHeap): * bmalloc/IsoSharedHeapInlines.h: (bmalloc::IsoSharedHeap::allocateNew): (bmalloc::IsoSharedHeap::allocateSlow): * bmalloc/IsoSharedPage.h: * bmalloc/IsoSharedPageInlines.h: (bmalloc::IsoSharedPage::free): (bmalloc::IsoSharedPage::startAllocating): (bmalloc::IsoSharedPage::stopAllocating): * bmalloc/IsoTLSDeallocatorEntry.h: * bmalloc/IsoTLSDeallocatorEntryInlines.h: (bmalloc::IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry): * bmalloc/IsoTLSInlines.h: (bmalloc::IsoTLS::ensureHeap): * bmalloc/IsoTLSLayout.cpp: (bmalloc::IsoTLSLayout::IsoTLSLayout): (bmalloc::IsoTLSLayout::add): * bmalloc/IsoTLSLayout.h: * bmalloc/Mutex.h: (bmalloc::sleep): (bmalloc::waitUntilFalse): * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/PerProcess.cpp: (bmalloc::getPerProcessData): * bmalloc/PerProcess.h: (bmalloc::PerProcess::getSlowCase): * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::Scavenger): (bmalloc::Scavenger::run): (bmalloc::Scavenger::runSoon): (bmalloc::Scavenger::scheduleIfUnderMemoryPressure): (bmalloc::Scavenger::schedule): (bmalloc::Scavenger::timeSinceLastFullScavenge): (bmalloc::Scavenger::timeSinceLastPartialScavenge): (bmalloc::Scavenger::scavenge): (bmalloc::Scavenger::partialScavenge): (bmalloc::Scavenger::freeableMemory): (bmalloc::Scavenger::threadRunLoop): * bmalloc/Scavenger.h: * bmalloc/SmallLine.h: (bmalloc::SmallLine::refCount): (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): * bmalloc/SmallPage.h: (bmalloc::SmallPage::refCount): (bmalloc::SmallPage::hasFreeLines const): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): * bmalloc/StaticPerProcess.h: * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): * bmalloc/VMHeap.h: * bmalloc/Zone.cpp: (bmalloc::Zone::Zone): * bmalloc/Zone.h: * bmalloc/bmalloc.cpp: (bmalloc::api::tryLargeZeroedMemalignVirtual): (bmalloc::api::freeLargeVirtual): (bmalloc::api::setScavengerThreadQOSClass): Canonical link: https://commits.webkit.org/219521@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254781 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-18 00:43:00 +00:00
bool hasFreeLines(UniqueLockHolder&) const { return m_hasFreeLines; }
void setHasFreeLines(UniqueLockHolder&, bool hasFreeLines) { m_hasFreeLines = hasFreeLines; }
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
bmalloc: Small and large objects should share memory https://bugs.webkit.org/show_bug.cgi?id=172880 <rdar://problem/31494732> Reviewed by Sam Weinig. This reduces our high water mark memory usage on JetStream on macOS by 10%-20%. It also has the nice side effect that we can free small object metadata after returning from a high water mark. No change in throughput. Our old algorithm allocated small object chunks and large objects in segregated virtual memory and never recycled addresses between them. This provided a slight security benefit because we could apply guard pages between the segregated ranges and we would never reuse the same virtual address for object and metadata memory. Our new algorithm allocates small object chunks from the large object allocator. This naturally recycles memory between small chunks and large objects, and between small chunks of different page classes. This allows us to shift memory between allocation types as a program moves between different phases of allocation, and to delete small object chunk metadata when a program shrinks back from a high water mark. Two intuitions I had about memory use turned out to be backwards in this context: (1) I thought that this optimization would work because it allowed you to allocate and free a 4MB object and then reuse that large allocation to service small allocations. In practice, the common benefit seems to be the opposite: After you allocate and free many small objects, you can stitch them together to allocate a large object without growing the heap. (2) I thought that it would be more memory-efficient to allocate fine-grained pages from the large object allocator. In practice, giving the large object allocator too many arbitrarily-sized ranges to manage leads to fragmentation. Meanwhile, segregated fit is a powerful memory optimization. So, it's best to return small object memory to the large allocator only when a whole small object chunk is free. * bmalloc/Chunk.h: (bmalloc::Chunk::ref): (bmalloc::Chunk::deref): (bmalloc::Chunk::refCount): (bmalloc::Chunk::freePages): We keep a free list per chunk and refcount each chunk so we can notice when a chunk becomes empty, and return it to the large allocator. (bmalloc::forEachPage): A new helper function for iterating the pages in a Chunk. (bmalloc::Chunk::Chunk): Use forEachPage instead of manual iteration. Use { } initialization because we don't get zero-initialized by the OS anymore. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavenge): Don't bother unlocking while scavenging. I wasn't able to show it to be a consistent speedup. A more promising approach, if we find a motivating example, is for the scavenger to give up and return early if any other client is waiting on the lock. (bmalloc::Heap::allocateSmallChunk): New helper function for allocating a small chunk. It allocates through the large allocator to facilitate sharing. We still allocate a chunk at a time instead of a page at a time. Surprisingly, more precise page-at-a-time allocation is worse for memory use because of fragmentation. Segregated fit is a powerful optimization. (bmalloc::Heap::deallocateSmallChunk): New helper function for deallocating a small chunk. (bmalloc::Heap::allocateSmallPage): Updated for new APIs. (bmalloc::Heap::deallocateSmallLine): Updated for new APIs. Note that we cache one free chunk per page class. This avoids churn in the large allocator when you free(malloc(X)). (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::scavengeSmallPages): Deleted. (bmalloc::Heap::scavengeLargeObjects): Deleted. * bmalloc/Heap.h: * bmalloc/LargeMap.h: (bmalloc::LargeMap::begin): (bmalloc::LargeMap::end): Added iteration helpers for scavenging. * bmalloc/LargeRange.h: (bmalloc::LargeRange::physicalSize): Added a comment about something that I confused myself about in this patch. * bmalloc/List.h: (bmalloc::List::iterator::operator*): (bmalloc::List::iterator::operator->): (bmalloc::List::iterator::operator!=): (bmalloc::List::iterator::operator++): (bmalloc::List::begin): (bmalloc::List::end): (bmalloc::List::pushFront): (bmalloc::List::remove): (bmalloc::ListNode::ListNode): Deleted. Added iteration helpers for scavenging. Changed the default state of a Node to null pointers instead of self pointers to distinguish the null node from the empty node for easier debugging. * bmalloc/Sizes.h: Changed the chunk size to 1MB to increase the chances of a chunk becoming free and recyclable. * bmalloc/SmallPage.h: (bmalloc::SmallPage::hasPhysicalPages): (bmalloc::SmallPage::setHasPhysicalPages): Track physical state by page instead of implicitly by which list a page is in. It's simpler not to have to move chunks and pages between physical vs virtual lists. (bmalloc::SmallPage::SmallPage): Deleted. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::tryAllocateLargeChunk): (bmalloc::VMHeap::allocateSmallChunk): Deleted. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): Deleted. (bmalloc::VMHeap::deallocateSmallPage): Deleted. Small chunk allocation just forwards to the large allocator now. * bmalloc/bmalloc.h: (bmalloc::api::scavenge): Canonical link: https://commits.webkit.org/189836@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217811 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-06 02:21:11 +00:00
bool hasPhysicalPages() { return m_hasPhysicalPages; }
void setHasPhysicalPages(bool hasPhysicalPages) { m_hasPhysicalPages = hasPhysicalPages; }
[BMalloc] Scavenger should react to recent memory activity https://bugs.webkit.org/show_bug.cgi?id=195895 Reviewed by Geoffrey Garen. This change adds a recently used bit to objects that are scavenged. When an object is allocated, that bit is set. When we scavenge, if the bit is set, we clear it. If the bit was already clear, we decommit the object. The timing to scavenging has been changed as well. We perform our first scavne almost immediately after bmalloc is initialized (10ms later). Subsequent scavenging is done as a multiple of the time it took to scavenge. We bound this computed time between a minimum and maximum. Through empirical testing, the multiplier, minimum and maximum are 150x, 100ms and 10,000ms respectively. For mini-mode, when the JIT is disabled, we use much more aggressive values of 50x, 25ms and 500ms. Eliminated partial scavenging since this change allows for any scavenge to be partial or full based on recent use of the objects on the various free lists. * bmalloc/Chunk.h: (bmalloc::Chunk::usedSinceLastScavenge): (bmalloc::Chunk::clearUsedSinceLastScavenge): (bmalloc::Chunk::setUsedSinceLastScavenge): * bmalloc/Heap.cpp: (bmalloc::Heap::scavenge): (bmalloc::Heap::allocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::scavengeToHighWatermark): Deleted. * bmalloc/Heap.h: * bmalloc/IsoDirectory.h: * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::scavenge): (bmalloc::passedNumPages>::scavengeToHighWatermark): Deleted. * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark): Deleted. * bmalloc/LargeRange.h: (bmalloc::LargeRange::LargeRange): (bmalloc::LargeRange::usedSinceLastScavenge): (bmalloc::LargeRange::clearUsedSinceLastScavenge): (bmalloc::LargeRange::setUsedSinceLastScavenge): (): Deleted. * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::Scavenger): (bmalloc::Scavenger::threadRunLoop): (bmalloc::Scavenger::timeSinceLastPartialScavenge): Deleted. (bmalloc::Scavenger::partialScavenge): Deleted. * bmalloc/Scavenger.h: * bmalloc/SmallPage.h: (bmalloc::SmallPage::usedSinceLastScavenge): (bmalloc::SmallPage::clearUsedSinceLastScavenge): (bmalloc::SmallPage::setUsedSinceLastScavenge): Canonical link: https://commits.webkit.org/210213@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243144 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-19 17:31:01 +00:00
bool usedSinceLastScavenge() { return m_usedSinceLastScavenge; }
void clearUsedSinceLastScavenge() { m_usedSinceLastScavenge = false; }
void setUsedSinceLastScavenge() { m_usedSinceLastScavenge = true; }
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
SmallLine* begin();
bmalloc: page size should be configurable at runtime https://bugs.webkit.org/show_bug.cgi?id=155993 Reviewed by Andreas Kling. This is a memory win on 32bit iOS devices, since their page sizes are 4kB and not 16kB. It's also a step toward supporting 64bit iOS devices that have a 16kB/4kB virtual/physical page size split. * bmalloc/Chunk.h: Align to largeAlignment since 2 * smallMax isn't required by the boundary tag allocator. (bmalloc::Chunk::page): Account for the slide when accessing a page. Each SmallPage hashes 4kB of memory. When we want to allocate a region of memory larger than 4kB, we store our metadata in the first SmallPage in the region and we assign a slide to the remaining SmallPages, so they forward to that first SmallPage when accessed. NOTE: We could use a less flexible technique that just hashed by vmPageSize() instead of 4kB at runtime, with no slide, but I think we'll be able to use this slide technique to make even more page sizes dynamically at runtime, which should save some memory and simplify the allocator. (bmalloc::SmallPage::begin): It's invalid to access a SmallPage with a slide, since such SmallPages do not contain meaningful data. (bmalloc::SmallPage::end): Account for smallPageCount when computing the size of a page. (bmalloc::Chunk::pageBegin): Deleted. (bmalloc::Chunk::pageEnd): Deleted. (bmalloc::Object::pageBegin): Deleted. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): Cache vmPageSize because computing it might require a syscall. (bmalloc::Heap::initializeLineMetadata): Line metadata is a vector instead of a 2D array because we don't know how much metadata we'll need until we know the page size. (bmalloc::Heap::scavengeSmallPage): Be sure to revert the slide when deallocating a page. Otherwise, the next attempt to allocate the page will slide when initializing it, sliding to nowhere. (bmalloc::Heap::allocateSmallBumpRanges): Account for vector change to line metadata. (bmalloc::Heap::allocateSmallPage): Initialize slide and smallPageCount since they aren't constant anymore. (bmalloc::Heap::allocateLarge): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateXLarge): (bmalloc::Heap::shrinkXLarge): Adopt dynamic page size. * bmalloc/Heap.h: * bmalloc/Sizes.h: smallPageSize is no longer equal to the VM page size -- it's just the smallest VM page size we're interested in supporting. * bmalloc/SmallPage.h: (bmalloc::SmallPage::slide): (bmalloc::SmallPage::setSlide): (bmalloc::SmallPage::smallPageCount): (bmalloc::SmallPage::setSmallPageCount): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): Support slide and small page count as dynamic values. This doesn't increase metadata size since sizeof(SmallPage) rounds up to alignment anyway. * bmalloc/VMAllocate.h: (bmalloc::vmPageSize): (bmalloc::vmPageShift): (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::tryVMAllocate): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): Treat page size as a variable. * bmalloc/Vector.h: (bmalloc::Vector::initialCapacity): (bmalloc::Vector<T>::insert): (bmalloc::Vector<T>::grow): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): Treat page size as a variable. Canonical link: https://commits.webkit.org/174120@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198821 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-30 02:22:47 +00:00
unsigned char slide() const { return m_slide; }
void setSlide(unsigned char slide) { m_slide = slide; }
bmalloc: segregate small and large objects again, and allocate more objects on the small path https://bugs.webkit.org/show_bug.cgi?id=156152 Reviewed by Sam Weinig. Microbenchmark data suggested that it was a good idea for small and large objects to share memory. But r198675 did not improve memory use in full browser benchmarks. This patch reverts to segregating small and large objects -- but without going back to doubled VM usage -- in order to capture a few benefits: (*) Small pages fragment the large heap. Separating them out saves a lot of memory in our worst case fragmentation recording: nimlang 276,076kB 209,636kB ^ 1.32x smaller (*) Small objects are common enough that even their slow paths benefit from simpler code: Execution Time: ... facebook 234ms 216ms ^ 1.08x faster reddit 114ms 108ms ^ 1.06x faster flickr 118ms 111ms ^ 1.06x faster theverge 146ms 140ms ^ 1.04x faster ... <arithmetic mean> 107ms 102ms ^ 1.04x faster (*) We can use less metadata: Memory at End: ... list_allocate 460kB 384kB ^ 1.2x smaller tree_allocate 492kB 424kB ^ 1.16x smaller tree_churn 480kB 404kB ^ 1.19x smaller fragment 532kB 452kB ^ 1.18x smaller fragment_iterate 712kB 588kB ^ 1.21x smaller medium 15,152kB 11,796kB ^ 1.28x smaller big 15,044kB 10,976kB ^ 1.37x smaller ... <arithmetic mean> 7,724kB 7,190kB ^ 1.07x smaller This patch also takes advantage of our support for varying the page size at runtime by allocating more objects on the small object path: medium 178ms 150ms ^ 1.19x faster Some microbenchmarks report memory use increases from this change -- like they reported memory use decreases from r198675 -- but I'm ignoring them for now because I expect our full browser memory benchmarks to confirm that this patch is fine. * bmalloc/BumpAllocator.h: (bmalloc::BumpAllocator::BumpAllocator): Use a full unsigned because we can allocate objects larger than 16kB - 1, and a full unsigned does not make BumpAllocator any larger on 64bit systems. * bmalloc/Chunk.h: (bmalloc::Chunk::begin): (bmalloc::Chunk::end): (bmalloc::Chunk::size): (bmalloc::Chunk::objectType): Store ObjectType in the Chunk, since it only varies by Chunk now, and not from page to page within a Chunk. Also, union together small and large object metadata, since we will only use one or the other. This saves memory. (bmalloc::Chunk::Chunk): Conditionalize initialization based on object type, since only one kind of metadata or the other can be used at runtime. (bmalloc::Object::Object): (bmalloc::Object::begin): (bmalloc::SmallPage::end): Deleted. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::initializeLineMetadata): Save a little space, since we know that lines are only 256 bytes long. (bmalloc::Heap::initializePageMetadata): Store a dynamic page size for each size class. We used to use only one page size (the system page size) but that limited our ability to allocate objects larger than 1kB on the small object path. Now we can handle any object size we want by storing objects of that size in a custom page size. (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeSmallPages): Revert to our old linked list strategy for storing small pages. (bmalloc::Heap::splitAndAllocate): Object type is per Chunk now. (bmalloc::Heap::allocateLarge): Don't nuke the small page list when allocating a large object because the two don't share memory anymore. (bmalloc::Heap::allocateSmallPage): Revert to our old linked list strategy for storing small pages. (bmalloc::Heap::deallocateSmallLine): Don't return early in the case where this is the first free object in the page. In the case of large-ish objects, the first free object might also be the last free object, since there's one object per page. (bmalloc::Heap::allocateSmallBumpRangesByMetadata): Split out some helper lambdas to make this code clearer. (bmalloc::Heap::allocateSmallBumpRangesByObject): Added a fast scan for objects larger than the line size. When multiple objects fit in a single line, it's an optimization to scan a line at a time. But when it's one object per line, or one object per 64 lines, it's better just to scan an object at a time. * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): Match the changes above. * bmalloc/LineMetadata.h: We weren't using all those bits. * bmalloc/List.h: (bmalloc::List::remove): Put a removed Node fully back into the default (empty) state it was in before it entered the list. This change is not observable, but it makes things clearer when you're debugging. * bmalloc/Object.h: (bmalloc::Object::Object): (bmalloc::Object::chunk): (bmalloc::Object::offset): (bmalloc::Object::operator+): (bmalloc::Object::operator<=): Added some helpers for iterating by object. * bmalloc/ObjectType.cpp: (bmalloc::objectType): Updated for API change. * bmalloc/Sizes.h: (bmalloc::Sizes::maskObjectSize): (bmalloc::Sizes::objectSize): (bmalloc::Sizes::pageSize): Support more page sizes. * bmalloc/SmallPage.h: (bmalloc::SmallPage::SmallPage): (bmalloc::SmallPage::objectType): Deleted. (bmalloc::SmallPage::setObjectType): Deleted. (bmalloc::SmallPage::smallPageCount): Deleted. (bmalloc::SmallPage::setSmallPageCount): Deleted. Object type is per Chunk now, and we can infer page count from size class. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateChunk): (bmalloc::VMHeap::allocateSmallChunk): * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::allocateLargeObject): Support our old behavior of storing free pages in linked lists. Canonical link: https://commits.webkit.org/174274@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198995 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-04 05:26:43 +00:00
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
private:
unsigned char m_hasFreeLines: 1;
bmalloc: Small and large objects should share memory https://bugs.webkit.org/show_bug.cgi?id=172880 <rdar://problem/31494732> Reviewed by Sam Weinig. This reduces our high water mark memory usage on JetStream on macOS by 10%-20%. It also has the nice side effect that we can free small object metadata after returning from a high water mark. No change in throughput. Our old algorithm allocated small object chunks and large objects in segregated virtual memory and never recycled addresses between them. This provided a slight security benefit because we could apply guard pages between the segregated ranges and we would never reuse the same virtual address for object and metadata memory. Our new algorithm allocates small object chunks from the large object allocator. This naturally recycles memory between small chunks and large objects, and between small chunks of different page classes. This allows us to shift memory between allocation types as a program moves between different phases of allocation, and to delete small object chunk metadata when a program shrinks back from a high water mark. Two intuitions I had about memory use turned out to be backwards in this context: (1) I thought that this optimization would work because it allowed you to allocate and free a 4MB object and then reuse that large allocation to service small allocations. In practice, the common benefit seems to be the opposite: After you allocate and free many small objects, you can stitch them together to allocate a large object without growing the heap. (2) I thought that it would be more memory-efficient to allocate fine-grained pages from the large object allocator. In practice, giving the large object allocator too many arbitrarily-sized ranges to manage leads to fragmentation. Meanwhile, segregated fit is a powerful memory optimization. So, it's best to return small object memory to the large allocator only when a whole small object chunk is free. * bmalloc/Chunk.h: (bmalloc::Chunk::ref): (bmalloc::Chunk::deref): (bmalloc::Chunk::refCount): (bmalloc::Chunk::freePages): We keep a free list per chunk and refcount each chunk so we can notice when a chunk becomes empty, and return it to the large allocator. (bmalloc::forEachPage): A new helper function for iterating the pages in a Chunk. (bmalloc::Chunk::Chunk): Use forEachPage instead of manual iteration. Use { } initialization because we don't get zero-initialized by the OS anymore. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavenge): Don't bother unlocking while scavenging. I wasn't able to show it to be a consistent speedup. A more promising approach, if we find a motivating example, is for the scavenger to give up and return early if any other client is waiting on the lock. (bmalloc::Heap::allocateSmallChunk): New helper function for allocating a small chunk. It allocates through the large allocator to facilitate sharing. We still allocate a chunk at a time instead of a page at a time. Surprisingly, more precise page-at-a-time allocation is worse for memory use because of fragmentation. Segregated fit is a powerful optimization. (bmalloc::Heap::deallocateSmallChunk): New helper function for deallocating a small chunk. (bmalloc::Heap::allocateSmallPage): Updated for new APIs. (bmalloc::Heap::deallocateSmallLine): Updated for new APIs. Note that we cache one free chunk per page class. This avoids churn in the large allocator when you free(malloc(X)). (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::scavengeSmallPages): Deleted. (bmalloc::Heap::scavengeLargeObjects): Deleted. * bmalloc/Heap.h: * bmalloc/LargeMap.h: (bmalloc::LargeMap::begin): (bmalloc::LargeMap::end): Added iteration helpers for scavenging. * bmalloc/LargeRange.h: (bmalloc::LargeRange::physicalSize): Added a comment about something that I confused myself about in this patch. * bmalloc/List.h: (bmalloc::List::iterator::operator*): (bmalloc::List::iterator::operator->): (bmalloc::List::iterator::operator!=): (bmalloc::List::iterator::operator++): (bmalloc::List::begin): (bmalloc::List::end): (bmalloc::List::pushFront): (bmalloc::List::remove): (bmalloc::ListNode::ListNode): Deleted. Added iteration helpers for scavenging. Changed the default state of a Node to null pointers instead of self pointers to distinguish the null node from the empty node for easier debugging. * bmalloc/Sizes.h: Changed the chunk size to 1MB to increase the chances of a chunk becoming free and recyclable. * bmalloc/SmallPage.h: (bmalloc::SmallPage::hasPhysicalPages): (bmalloc::SmallPage::setHasPhysicalPages): Track physical state by page instead of implicitly by which list a page is in. It's simpler not to have to move chunks and pages between physical vs virtual lists. (bmalloc::SmallPage::SmallPage): Deleted. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::tryAllocateLargeChunk): (bmalloc::VMHeap::allocateSmallChunk): Deleted. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): Deleted. (bmalloc::VMHeap::deallocateSmallPage): Deleted. Small chunk allocation just forwards to the large allocator now. * bmalloc/bmalloc.h: (bmalloc::api::scavenge): Canonical link: https://commits.webkit.org/189836@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217811 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-06 02:21:11 +00:00
unsigned char m_hasPhysicalPages: 1;
[BMalloc] Scavenger should react to recent memory activity https://bugs.webkit.org/show_bug.cgi?id=195895 Reviewed by Geoffrey Garen. This change adds a recently used bit to objects that are scavenged. When an object is allocated, that bit is set. When we scavenge, if the bit is set, we clear it. If the bit was already clear, we decommit the object. The timing to scavenging has been changed as well. We perform our first scavne almost immediately after bmalloc is initialized (10ms later). Subsequent scavenging is done as a multiple of the time it took to scavenge. We bound this computed time between a minimum and maximum. Through empirical testing, the multiplier, minimum and maximum are 150x, 100ms and 10,000ms respectively. For mini-mode, when the JIT is disabled, we use much more aggressive values of 50x, 25ms and 500ms. Eliminated partial scavenging since this change allows for any scavenge to be partial or full based on recent use of the objects on the various free lists. * bmalloc/Chunk.h: (bmalloc::Chunk::usedSinceLastScavenge): (bmalloc::Chunk::clearUsedSinceLastScavenge): (bmalloc::Chunk::setUsedSinceLastScavenge): * bmalloc/Heap.cpp: (bmalloc::Heap::scavenge): (bmalloc::Heap::allocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::scavengeToHighWatermark): Deleted. * bmalloc/Heap.h: * bmalloc/IsoDirectory.h: * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::scavenge): (bmalloc::passedNumPages>::scavengeToHighWatermark): Deleted. * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark): Deleted. * bmalloc/LargeRange.h: (bmalloc::LargeRange::LargeRange): (bmalloc::LargeRange::usedSinceLastScavenge): (bmalloc::LargeRange::clearUsedSinceLastScavenge): (bmalloc::LargeRange::setUsedSinceLastScavenge): (): Deleted. * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::Scavenger): (bmalloc::Scavenger::threadRunLoop): (bmalloc::Scavenger::timeSinceLastPartialScavenge): Deleted. (bmalloc::Scavenger::partialScavenge): Deleted. * bmalloc/Scavenger.h: * bmalloc/SmallPage.h: (bmalloc::SmallPage::usedSinceLastScavenge): (bmalloc::SmallPage::clearUsedSinceLastScavenge): (bmalloc::SmallPage::setUsedSinceLastScavenge): Canonical link: https://commits.webkit.org/210213@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243144 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-19 17:31:01 +00:00
unsigned char m_usedSinceLastScavenge: 1;
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
unsigned char m_refCount: 7;
unsigned char m_sizeClass;
bmalloc: page size should be configurable at runtime https://bugs.webkit.org/show_bug.cgi?id=155993 Reviewed by Andreas Kling. This is a memory win on 32bit iOS devices, since their page sizes are 4kB and not 16kB. It's also a step toward supporting 64bit iOS devices that have a 16kB/4kB virtual/physical page size split. * bmalloc/Chunk.h: Align to largeAlignment since 2 * smallMax isn't required by the boundary tag allocator. (bmalloc::Chunk::page): Account for the slide when accessing a page. Each SmallPage hashes 4kB of memory. When we want to allocate a region of memory larger than 4kB, we store our metadata in the first SmallPage in the region and we assign a slide to the remaining SmallPages, so they forward to that first SmallPage when accessed. NOTE: We could use a less flexible technique that just hashed by vmPageSize() instead of 4kB at runtime, with no slide, but I think we'll be able to use this slide technique to make even more page sizes dynamically at runtime, which should save some memory and simplify the allocator. (bmalloc::SmallPage::begin): It's invalid to access a SmallPage with a slide, since such SmallPages do not contain meaningful data. (bmalloc::SmallPage::end): Account for smallPageCount when computing the size of a page. (bmalloc::Chunk::pageBegin): Deleted. (bmalloc::Chunk::pageEnd): Deleted. (bmalloc::Object::pageBegin): Deleted. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): Cache vmPageSize because computing it might require a syscall. (bmalloc::Heap::initializeLineMetadata): Line metadata is a vector instead of a 2D array because we don't know how much metadata we'll need until we know the page size. (bmalloc::Heap::scavengeSmallPage): Be sure to revert the slide when deallocating a page. Otherwise, the next attempt to allocate the page will slide when initializing it, sliding to nowhere. (bmalloc::Heap::allocateSmallBumpRanges): Account for vector change to line metadata. (bmalloc::Heap::allocateSmallPage): Initialize slide and smallPageCount since they aren't constant anymore. (bmalloc::Heap::allocateLarge): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateXLarge): (bmalloc::Heap::shrinkXLarge): Adopt dynamic page size. * bmalloc/Heap.h: * bmalloc/Sizes.h: smallPageSize is no longer equal to the VM page size -- it's just the smallest VM page size we're interested in supporting. * bmalloc/SmallPage.h: (bmalloc::SmallPage::slide): (bmalloc::SmallPage::setSlide): (bmalloc::SmallPage::smallPageCount): (bmalloc::SmallPage::setSmallPageCount): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): Support slide and small page count as dynamic values. This doesn't increase metadata size since sizeof(SmallPage) rounds up to alignment anyway. * bmalloc/VMAllocate.h: (bmalloc::vmPageSize): (bmalloc::vmPageShift): (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::tryVMAllocate): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): Treat page size as a variable. * bmalloc/Vector.h: (bmalloc::Vector::initialCapacity): (bmalloc::Vector<T>::insert): (bmalloc::Vector<T>::grow): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): Treat page size as a variable. Canonical link: https://commits.webkit.org/174120@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198821 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-30 02:22:47 +00:00
unsigned char m_slide;
bmalloc: use a log scale for large-ish size classes https://bugs.webkit.org/show_bug.cgi?id=155770 Reviewed by Michael Saboff. At larger sizes, precise allocation sizes don't save much memory -- and they can cost memory when objects of distinct size classes can't allocate together. This is a small savings up to our current allocation limits, and it may enable changing those limits in the long term. * bmalloc/Algorithm.h: (bmalloc::log2): We use this to compute large-ish size classes. * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): Iterate by size class instead of by object size so we can change object size limits without breaking stuff. (bmalloc::Allocator::scavenge): Ditto. (bmalloc::Allocator::allocateLogSizeClass): New helper function for allocating based on log size classes. (bmalloc::Allocator::allocateSlowCase): Account for extra size class possibilities. * bmalloc/Allocator.h: (bmalloc::Allocator::allocateFastCase): We only handle up to 512b on the fastest fast path now. * bmalloc/BumpAllocator.h: (bmalloc::BumpAllocator::validate): Deleted. I noticed that this function had been refactored not to do anything anymore. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): Iterate by size class. (See Allocator::Allocator.) * bmalloc/Heap.h: Use the sizeClassCount constant instead of hard coding things. * bmalloc/Sizes.h: (bmalloc::Sizes::maskSizeClass): (bmalloc::Sizes::maskObjectSize): (bmalloc::Sizes::logSizeClass): (bmalloc::Sizes::logObjectSize): (bmalloc::Sizes::sizeClass): (bmalloc::Sizes::objectSize): Separate size class calculation between simple size classes that can be computed with a mask and are 8-byte-precise and complex size classes that require more math and are less precise. * bmalloc/SmallLine.h: (bmalloc::SmallLine::ref): * bmalloc/SmallPage.h: (bmalloc::SmallPage::SmallPage): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): Cleaned up some ASSERTs that triggered while working on this patch. * bmalloc/Zone.cpp: (bmalloc::statistics): (bmalloc::zoneSize): (bmalloc::Zone::Zone): (bmalloc::size): Deleted. Renamed these symbols to work around an lldb bug that makes it impossible to print out variables named 'size' -- which can be a problem when working on malloc. Canonical link: https://commits.webkit.org/173886@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198571 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-23 01:39:36 +00:00
static_assert(
sizeClassCount <= std::numeric_limits<decltype(m_sizeClass)>::max(),
"Largest size class must fit in SmallPage metadata");
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
};
bmalloc: Add a per-thread line cache https://bugs.webkit.org/show_bug.cgi?id=173552 Reviewed by Darin Adler. Previously, any thread could allocate out of any page with free lines. Now, the first thread to free a line in a page owns that page's free lines until the whole page becomes free. This patch is a big speedup on multi-threaded benchmarks. tree_churn --parallel gets 14% faster on a 2-core (4-hyper-core) MacBook Air and 2.85X faster on 12-core (24-hyper-core) Mac Pro. Other parallel benchmarks show significant but smaller speedups. Thread affinity is a great predictor of object lifetime. The per-thread line cache avoids the pathology of shuffling pages between threads, turning predictable lifetimes into unpredictable lifetimes, increasing fragmentation. On tree_churn --parallel, the per-thread line cache increases free memory found per page scanned by 2.85X. Free line scanning in fragmented pages is pretty expensive relative to other allocate / initialize / free operations. According to Instruments, on tree_churn --parallel, scanning is about 10X more expensive than freeing. This explains why a 2.85X improvement in scanning efficiency translates into a 2.85X overall speedup on tree_churn --parallel. * bmalloc/Allocator.cpp: (bmalloc::Allocator::refillAllocatorSlowCase): Pass through our line cache so the Heap can fill it. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): Scavenge our line cache. (bmalloc::Deallocator::processObjectLog): Deleted. * bmalloc/Deallocator.h: (bmalloc::Deallocator::lineCache): Added a line cache. * bmalloc/Heap.cpp: (bmalloc::Heap::deallocateLineCache): Deallocation function for thread destruction. (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): Consult the new per-thread line cache for allocation and deallocation. * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): * bmalloc/List.h: (bmalloc::List::remove): Remove has always been a logically static operation. Declare it static now so that the Heap can remove a page from a thread's line cache without holding a direct pointer to the cache. * bmalloc/SmallPage.h: Canonical link: https://commits.webkit.org/190669@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218788 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-24 20:14:33 +00:00
using LineCache = std::array<List<SmallPage>, sizeClassCount>;
[bmalloc] Define alias for std::lock_guard and std::unique_lock for better readability https://bugs.webkit.org/show_bug.cgi?id=206443 Reviewed by Yusuke Suzuki. There are two types of lock holder in bmalloc: std::lock_guard and std::unique_lock. Their names are relatively long and a bit harder to distinguish them each other. Define simple type name for them, LockHolder and UniqueLockHolder. * bmalloc/AllIsoHeaps.cpp: (bmalloc::AllIsoHeaps::AllIsoHeaps): (bmalloc::AllIsoHeaps::add): (bmalloc::AllIsoHeaps::head): * bmalloc/AllIsoHeaps.h: * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocateImpl): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::allocateLarge): * bmalloc/CryptoRandom.cpp: (bmalloc::ARC4RandomNumberGenerator::ARC4RandomNumberGenerator): (bmalloc::ARC4RandomNumberGenerator::randomValues): * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: (bmalloc::Deallocator::lineCache): * bmalloc/DebugHeap.cpp: (bmalloc::DebugHeap::DebugHeap): (bmalloc::DebugHeap::memalignLarge): (bmalloc::DebugHeap::freeLarge): * bmalloc/DebugHeap.h: * bmalloc/DeferredTrigger.h: * bmalloc/DeferredTriggerInlines.h: (bmalloc::DeferredTrigger<trigger>::didBecome): (bmalloc::DeferredTrigger<trigger>::handleDeferral): * bmalloc/Environment.cpp: (bmalloc::Environment::Environment): * bmalloc/Environment.h: * bmalloc/Gigacage.cpp: (bmalloc::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks): (Gigacage::disablePrimitiveGigacage): (Gigacage::addPrimitiveDisableCallback): (Gigacage::removePrimitiveDisableCallback): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::freeableMemory): (bmalloc::Heap::markAllLargeAsEligibile): (bmalloc::Heap::decommitLargeRange): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeToHighWatermark): (bmalloc::Heap::deallocateLineCache): (bmalloc::Heap::allocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::isLarge): (bmalloc::Heap::largeSize): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): (bmalloc::Heap::externalCommit): (bmalloc::Heap::externalDecommit): * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): * bmalloc/HeapConstants.cpp: (bmalloc::HeapConstants::HeapConstants): * bmalloc/HeapConstants.h: * bmalloc/IsoAllocatorInlines.h: (bmalloc::IsoAllocator<Config>::allocateSlow): (bmalloc::IsoAllocator<Config>::scavenge): * bmalloc/IsoDeallocatorInlines.h: (bmalloc::IsoDeallocator<Config>::deallocate): (bmalloc::IsoDeallocator<Config>::scavenge): * bmalloc/IsoDirectory.h: * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::didBecome): (bmalloc::passedNumPages>::didDecommit): (bmalloc::passedNumPages>::scavengePage): (bmalloc::passedNumPages>::scavenge): (bmalloc::passedNumPages>::scavengeToHighWatermark): (bmalloc::passedNumPages>::forEachCommittedPage): * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::takeFirstEligible): (bmalloc::IsoHeapImpl<Config>::didBecomeEligibleOrDecommited): (bmalloc::IsoHeapImpl<Config>::scavenge): (bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark): (bmalloc::IsoHeapImpl<Config>::numLiveObjects): (bmalloc::IsoHeapImpl<Config>::numCommittedPages): (bmalloc::IsoHeapImpl<Config>::forEachDirectory): (bmalloc::IsoHeapImpl<Config>::forEachCommittedPage): (bmalloc::IsoHeapImpl<Config>::forEachLiveObject): (bmalloc::IsoHeapImpl<Config>::allocateFromShared): * bmalloc/IsoPage.h: * bmalloc/IsoPageInlines.h: (bmalloc::IsoPage<Config>::free): (bmalloc::IsoPage<Config>::startAllocating): (bmalloc::IsoPage<Config>::stopAllocating): (bmalloc::IsoPage<Config>::forEachLiveObject): * bmalloc/IsoSharedHeap.h: (bmalloc::IsoSharedHeap::IsoSharedHeap): * bmalloc/IsoSharedHeapInlines.h: (bmalloc::IsoSharedHeap::allocateNew): (bmalloc::IsoSharedHeap::allocateSlow): * bmalloc/IsoSharedPage.h: * bmalloc/IsoSharedPageInlines.h: (bmalloc::IsoSharedPage::free): (bmalloc::IsoSharedPage::startAllocating): (bmalloc::IsoSharedPage::stopAllocating): * bmalloc/IsoTLSDeallocatorEntry.h: * bmalloc/IsoTLSDeallocatorEntryInlines.h: (bmalloc::IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry): * bmalloc/IsoTLSInlines.h: (bmalloc::IsoTLS::ensureHeap): * bmalloc/IsoTLSLayout.cpp: (bmalloc::IsoTLSLayout::IsoTLSLayout): (bmalloc::IsoTLSLayout::add): * bmalloc/IsoTLSLayout.h: * bmalloc/Mutex.h: (bmalloc::sleep): (bmalloc::waitUntilFalse): * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/PerProcess.cpp: (bmalloc::getPerProcessData): * bmalloc/PerProcess.h: (bmalloc::PerProcess::getSlowCase): * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::Scavenger): (bmalloc::Scavenger::run): (bmalloc::Scavenger::runSoon): (bmalloc::Scavenger::scheduleIfUnderMemoryPressure): (bmalloc::Scavenger::schedule): (bmalloc::Scavenger::timeSinceLastFullScavenge): (bmalloc::Scavenger::timeSinceLastPartialScavenge): (bmalloc::Scavenger::scavenge): (bmalloc::Scavenger::partialScavenge): (bmalloc::Scavenger::freeableMemory): (bmalloc::Scavenger::threadRunLoop): * bmalloc/Scavenger.h: * bmalloc/SmallLine.h: (bmalloc::SmallLine::refCount): (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): * bmalloc/SmallPage.h: (bmalloc::SmallPage::refCount): (bmalloc::SmallPage::hasFreeLines const): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): * bmalloc/StaticPerProcess.h: * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): * bmalloc/VMHeap.h: * bmalloc/Zone.cpp: (bmalloc::Zone::Zone): * bmalloc/Zone.h: * bmalloc/bmalloc.cpp: (bmalloc::api::tryLargeZeroedMemalignVirtual): (bmalloc::api::freeLargeVirtual): (bmalloc::api::setScavengerThreadQOSClass): Canonical link: https://commits.webkit.org/219521@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254781 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-18 00:43:00 +00:00
inline void SmallPage::ref(UniqueLockHolder&)
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
{
bmalloc: page size should be configurable at runtime https://bugs.webkit.org/show_bug.cgi?id=155993 Reviewed by Andreas Kling. This is a memory win on 32bit iOS devices, since their page sizes are 4kB and not 16kB. It's also a step toward supporting 64bit iOS devices that have a 16kB/4kB virtual/physical page size split. * bmalloc/Chunk.h: Align to largeAlignment since 2 * smallMax isn't required by the boundary tag allocator. (bmalloc::Chunk::page): Account for the slide when accessing a page. Each SmallPage hashes 4kB of memory. When we want to allocate a region of memory larger than 4kB, we store our metadata in the first SmallPage in the region and we assign a slide to the remaining SmallPages, so they forward to that first SmallPage when accessed. NOTE: We could use a less flexible technique that just hashed by vmPageSize() instead of 4kB at runtime, with no slide, but I think we'll be able to use this slide technique to make even more page sizes dynamically at runtime, which should save some memory and simplify the allocator. (bmalloc::SmallPage::begin): It's invalid to access a SmallPage with a slide, since such SmallPages do not contain meaningful data. (bmalloc::SmallPage::end): Account for smallPageCount when computing the size of a page. (bmalloc::Chunk::pageBegin): Deleted. (bmalloc::Chunk::pageEnd): Deleted. (bmalloc::Object::pageBegin): Deleted. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): Cache vmPageSize because computing it might require a syscall. (bmalloc::Heap::initializeLineMetadata): Line metadata is a vector instead of a 2D array because we don't know how much metadata we'll need until we know the page size. (bmalloc::Heap::scavengeSmallPage): Be sure to revert the slide when deallocating a page. Otherwise, the next attempt to allocate the page will slide when initializing it, sliding to nowhere. (bmalloc::Heap::allocateSmallBumpRanges): Account for vector change to line metadata. (bmalloc::Heap::allocateSmallPage): Initialize slide and smallPageCount since they aren't constant anymore. (bmalloc::Heap::allocateLarge): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateXLarge): (bmalloc::Heap::shrinkXLarge): Adopt dynamic page size. * bmalloc/Heap.h: * bmalloc/Sizes.h: smallPageSize is no longer equal to the VM page size -- it's just the smallest VM page size we're interested in supporting. * bmalloc/SmallPage.h: (bmalloc::SmallPage::slide): (bmalloc::SmallPage::setSlide): (bmalloc::SmallPage::smallPageCount): (bmalloc::SmallPage::setSmallPageCount): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): Support slide and small page count as dynamic values. This doesn't increase metadata size since sizeof(SmallPage) rounds up to alignment anyway. * bmalloc/VMAllocate.h: (bmalloc::vmPageSize): (bmalloc::vmPageShift): (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::tryVMAllocate): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): Treat page size as a variable. * bmalloc/Vector.h: (bmalloc::Vector::initialCapacity): (bmalloc::Vector<T>::insert): (bmalloc::Vector<T>::grow): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): Treat page size as a variable. Canonical link: https://commits.webkit.org/174120@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198821 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-30 02:22:47 +00:00
BASSERT(!m_slide);
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
++m_refCount;
bmalloc: use a log scale for large-ish size classes https://bugs.webkit.org/show_bug.cgi?id=155770 Reviewed by Michael Saboff. At larger sizes, precise allocation sizes don't save much memory -- and they can cost memory when objects of distinct size classes can't allocate together. This is a small savings up to our current allocation limits, and it may enable changing those limits in the long term. * bmalloc/Algorithm.h: (bmalloc::log2): We use this to compute large-ish size classes. * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): Iterate by size class instead of by object size so we can change object size limits without breaking stuff. (bmalloc::Allocator::scavenge): Ditto. (bmalloc::Allocator::allocateLogSizeClass): New helper function for allocating based on log size classes. (bmalloc::Allocator::allocateSlowCase): Account for extra size class possibilities. * bmalloc/Allocator.h: (bmalloc::Allocator::allocateFastCase): We only handle up to 512b on the fastest fast path now. * bmalloc/BumpAllocator.h: (bmalloc::BumpAllocator::validate): Deleted. I noticed that this function had been refactored not to do anything anymore. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): Iterate by size class. (See Allocator::Allocator.) * bmalloc/Heap.h: Use the sizeClassCount constant instead of hard coding things. * bmalloc/Sizes.h: (bmalloc::Sizes::maskSizeClass): (bmalloc::Sizes::maskObjectSize): (bmalloc::Sizes::logSizeClass): (bmalloc::Sizes::logObjectSize): (bmalloc::Sizes::sizeClass): (bmalloc::Sizes::objectSize): Separate size class calculation between simple size classes that can be computed with a mask and are 8-byte-precise and complex size classes that require more math and are less precise. * bmalloc/SmallLine.h: (bmalloc::SmallLine::ref): * bmalloc/SmallPage.h: (bmalloc::SmallPage::SmallPage): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): Cleaned up some ASSERTs that triggered while working on this patch. * bmalloc/Zone.cpp: (bmalloc::statistics): (bmalloc::zoneSize): (bmalloc::Zone::Zone): (bmalloc::size): Deleted. Renamed these symbols to work around an lldb bug that makes it impossible to print out variables named 'size' -- which can be a problem when working on malloc. Canonical link: https://commits.webkit.org/173886@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198571 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-23 01:39:36 +00:00
BASSERT(m_refCount);
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
}
[bmalloc] Define alias for std::lock_guard and std::unique_lock for better readability https://bugs.webkit.org/show_bug.cgi?id=206443 Reviewed by Yusuke Suzuki. There are two types of lock holder in bmalloc: std::lock_guard and std::unique_lock. Their names are relatively long and a bit harder to distinguish them each other. Define simple type name for them, LockHolder and UniqueLockHolder. * bmalloc/AllIsoHeaps.cpp: (bmalloc::AllIsoHeaps::AllIsoHeaps): (bmalloc::AllIsoHeaps::add): (bmalloc::AllIsoHeaps::head): * bmalloc/AllIsoHeaps.h: * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocateImpl): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::allocateLarge): * bmalloc/CryptoRandom.cpp: (bmalloc::ARC4RandomNumberGenerator::ARC4RandomNumberGenerator): (bmalloc::ARC4RandomNumberGenerator::randomValues): * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: (bmalloc::Deallocator::lineCache): * bmalloc/DebugHeap.cpp: (bmalloc::DebugHeap::DebugHeap): (bmalloc::DebugHeap::memalignLarge): (bmalloc::DebugHeap::freeLarge): * bmalloc/DebugHeap.h: * bmalloc/DeferredTrigger.h: * bmalloc/DeferredTriggerInlines.h: (bmalloc::DeferredTrigger<trigger>::didBecome): (bmalloc::DeferredTrigger<trigger>::handleDeferral): * bmalloc/Environment.cpp: (bmalloc::Environment::Environment): * bmalloc/Environment.h: * bmalloc/Gigacage.cpp: (bmalloc::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks): (Gigacage::disablePrimitiveGigacage): (Gigacage::addPrimitiveDisableCallback): (Gigacage::removePrimitiveDisableCallback): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::freeableMemory): (bmalloc::Heap::markAllLargeAsEligibile): (bmalloc::Heap::decommitLargeRange): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeToHighWatermark): (bmalloc::Heap::deallocateLineCache): (bmalloc::Heap::allocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::isLarge): (bmalloc::Heap::largeSize): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): (bmalloc::Heap::externalCommit): (bmalloc::Heap::externalDecommit): * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): * bmalloc/HeapConstants.cpp: (bmalloc::HeapConstants::HeapConstants): * bmalloc/HeapConstants.h: * bmalloc/IsoAllocatorInlines.h: (bmalloc::IsoAllocator<Config>::allocateSlow): (bmalloc::IsoAllocator<Config>::scavenge): * bmalloc/IsoDeallocatorInlines.h: (bmalloc::IsoDeallocator<Config>::deallocate): (bmalloc::IsoDeallocator<Config>::scavenge): * bmalloc/IsoDirectory.h: * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::didBecome): (bmalloc::passedNumPages>::didDecommit): (bmalloc::passedNumPages>::scavengePage): (bmalloc::passedNumPages>::scavenge): (bmalloc::passedNumPages>::scavengeToHighWatermark): (bmalloc::passedNumPages>::forEachCommittedPage): * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::takeFirstEligible): (bmalloc::IsoHeapImpl<Config>::didBecomeEligibleOrDecommited): (bmalloc::IsoHeapImpl<Config>::scavenge): (bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark): (bmalloc::IsoHeapImpl<Config>::numLiveObjects): (bmalloc::IsoHeapImpl<Config>::numCommittedPages): (bmalloc::IsoHeapImpl<Config>::forEachDirectory): (bmalloc::IsoHeapImpl<Config>::forEachCommittedPage): (bmalloc::IsoHeapImpl<Config>::forEachLiveObject): (bmalloc::IsoHeapImpl<Config>::allocateFromShared): * bmalloc/IsoPage.h: * bmalloc/IsoPageInlines.h: (bmalloc::IsoPage<Config>::free): (bmalloc::IsoPage<Config>::startAllocating): (bmalloc::IsoPage<Config>::stopAllocating): (bmalloc::IsoPage<Config>::forEachLiveObject): * bmalloc/IsoSharedHeap.h: (bmalloc::IsoSharedHeap::IsoSharedHeap): * bmalloc/IsoSharedHeapInlines.h: (bmalloc::IsoSharedHeap::allocateNew): (bmalloc::IsoSharedHeap::allocateSlow): * bmalloc/IsoSharedPage.h: * bmalloc/IsoSharedPageInlines.h: (bmalloc::IsoSharedPage::free): (bmalloc::IsoSharedPage::startAllocating): (bmalloc::IsoSharedPage::stopAllocating): * bmalloc/IsoTLSDeallocatorEntry.h: * bmalloc/IsoTLSDeallocatorEntryInlines.h: (bmalloc::IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry): * bmalloc/IsoTLSInlines.h: (bmalloc::IsoTLS::ensureHeap): * bmalloc/IsoTLSLayout.cpp: (bmalloc::IsoTLSLayout::IsoTLSLayout): (bmalloc::IsoTLSLayout::add): * bmalloc/IsoTLSLayout.h: * bmalloc/Mutex.h: (bmalloc::sleep): (bmalloc::waitUntilFalse): * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/PerProcess.cpp: (bmalloc::getPerProcessData): * bmalloc/PerProcess.h: (bmalloc::PerProcess::getSlowCase): * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::Scavenger): (bmalloc::Scavenger::run): (bmalloc::Scavenger::runSoon): (bmalloc::Scavenger::scheduleIfUnderMemoryPressure): (bmalloc::Scavenger::schedule): (bmalloc::Scavenger::timeSinceLastFullScavenge): (bmalloc::Scavenger::timeSinceLastPartialScavenge): (bmalloc::Scavenger::scavenge): (bmalloc::Scavenger::partialScavenge): (bmalloc::Scavenger::freeableMemory): (bmalloc::Scavenger::threadRunLoop): * bmalloc/Scavenger.h: * bmalloc/SmallLine.h: (bmalloc::SmallLine::refCount): (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): * bmalloc/SmallPage.h: (bmalloc::SmallPage::refCount): (bmalloc::SmallPage::hasFreeLines const): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): * bmalloc/StaticPerProcess.h: * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): * bmalloc/VMHeap.h: * bmalloc/Zone.cpp: (bmalloc::Zone::Zone): * bmalloc/Zone.h: * bmalloc/bmalloc.cpp: (bmalloc::api::tryLargeZeroedMemalignVirtual): (bmalloc::api::freeLargeVirtual): (bmalloc::api::setScavengerThreadQOSClass): Canonical link: https://commits.webkit.org/219521@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254781 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-18 00:43:00 +00:00
inline bool SmallPage::deref(UniqueLockHolder&)
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
{
bmalloc: page size should be configurable at runtime https://bugs.webkit.org/show_bug.cgi?id=155993 Reviewed by Andreas Kling. This is a memory win on 32bit iOS devices, since their page sizes are 4kB and not 16kB. It's also a step toward supporting 64bit iOS devices that have a 16kB/4kB virtual/physical page size split. * bmalloc/Chunk.h: Align to largeAlignment since 2 * smallMax isn't required by the boundary tag allocator. (bmalloc::Chunk::page): Account for the slide when accessing a page. Each SmallPage hashes 4kB of memory. When we want to allocate a region of memory larger than 4kB, we store our metadata in the first SmallPage in the region and we assign a slide to the remaining SmallPages, so they forward to that first SmallPage when accessed. NOTE: We could use a less flexible technique that just hashed by vmPageSize() instead of 4kB at runtime, with no slide, but I think we'll be able to use this slide technique to make even more page sizes dynamically at runtime, which should save some memory and simplify the allocator. (bmalloc::SmallPage::begin): It's invalid to access a SmallPage with a slide, since such SmallPages do not contain meaningful data. (bmalloc::SmallPage::end): Account for smallPageCount when computing the size of a page. (bmalloc::Chunk::pageBegin): Deleted. (bmalloc::Chunk::pageEnd): Deleted. (bmalloc::Object::pageBegin): Deleted. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): Cache vmPageSize because computing it might require a syscall. (bmalloc::Heap::initializeLineMetadata): Line metadata is a vector instead of a 2D array because we don't know how much metadata we'll need until we know the page size. (bmalloc::Heap::scavengeSmallPage): Be sure to revert the slide when deallocating a page. Otherwise, the next attempt to allocate the page will slide when initializing it, sliding to nowhere. (bmalloc::Heap::allocateSmallBumpRanges): Account for vector change to line metadata. (bmalloc::Heap::allocateSmallPage): Initialize slide and smallPageCount since they aren't constant anymore. (bmalloc::Heap::allocateLarge): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateXLarge): (bmalloc::Heap::shrinkXLarge): Adopt dynamic page size. * bmalloc/Heap.h: * bmalloc/Sizes.h: smallPageSize is no longer equal to the VM page size -- it's just the smallest VM page size we're interested in supporting. * bmalloc/SmallPage.h: (bmalloc::SmallPage::slide): (bmalloc::SmallPage::setSlide): (bmalloc::SmallPage::smallPageCount): (bmalloc::SmallPage::setSmallPageCount): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): Support slide and small page count as dynamic values. This doesn't increase metadata size since sizeof(SmallPage) rounds up to alignment anyway. * bmalloc/VMAllocate.h: (bmalloc::vmPageSize): (bmalloc::vmPageShift): (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::tryVMAllocate): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): Treat page size as a variable. * bmalloc/Vector.h: (bmalloc::Vector::initialCapacity): (bmalloc::Vector<T>::insert): (bmalloc::Vector<T>::grow): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): Treat page size as a variable. Canonical link: https://commits.webkit.org/174120@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198821 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-03-30 02:22:47 +00:00
BASSERT(!m_slide);
bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. Canonical link: https://commits.webkit.org/172589@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196847 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-20 01:06:49 +00:00
BASSERT(m_refCount);
--m_refCount;
return !m_refCount;
}
bmalloc https://bugs.webkit.org/show_bug.cgi?id=131170 Reviewed by Andreas Kling. Initial commit. * bmalloc: Added. * bmalloc.xcodeproj: Added. * bmalloc.xcodeproj/project.pbxproj: Added. * bmalloc/Algorithm.h: Added. (bmalloc::max): (bmalloc::min): (bmalloc::mask): (bmalloc::test): (bmalloc::roundUpToMultipleOf): (bmalloc::roundDownToMultipleOf): (bmalloc::sizeOf): (bmalloc::bitCount): (bmalloc::isPowerOfTwo): * bmalloc/Allocator.cpp: Added. (bmalloc::Allocator::Allocator): (bmalloc::Allocator::~Allocator): (bmalloc::Allocator::log): (bmalloc::Allocator::processSmallAllocatorLog): (bmalloc::Allocator::processMediumAllocatorLog): (bmalloc::Allocator::allocateLarge): (bmalloc::Allocator::allocateXLarge): (bmalloc::Allocator::allocateMedium): (bmalloc::Allocator::allocateSlowCase): * bmalloc/Allocator.h: Added. (bmalloc::Allocator::smallAllocatorFor): (bmalloc::Allocator::allocateFastCase): (bmalloc::Allocator::allocate): * bmalloc/AsyncTask.cpp: Added. (bmalloc::AsyncTask<Function>::runSlowCase): (bmalloc::AsyncTask<Function>::pthreadEntryPoint): (bmalloc::AsyncTask<Function>::entryPoint): * bmalloc/AsyncTask.h: Added. (bmalloc::Function>::AsyncTask): (bmalloc::Function>::join): (bmalloc::Function>::run): (bmalloc::Function>::runSlowCase): (bmalloc::Function>::pthreadEntryPoint): (bmalloc::Function>::entryPoint): * bmalloc/BAssert.h: Added. * bmalloc/BeginTag.h: Added. (bmalloc::BeginTag::isInFreeList): * bmalloc/BoundaryTag.h: Added. (bmalloc::BoundaryTag::isXLarge): (bmalloc::BoundaryTag::setXLarge): (bmalloc::BoundaryTag::isFree): (bmalloc::BoundaryTag::setFree): (bmalloc::BoundaryTag::isEnd): (bmalloc::BoundaryTag::setEnd): (bmalloc::BoundaryTag::hasPhysicalPages): (bmalloc::BoundaryTag::setHasPhysicalPages): (bmalloc::BoundaryTag::isNull): (bmalloc::BoundaryTag::clear): (bmalloc::BoundaryTag::size): (bmalloc::BoundaryTag::setSize): (bmalloc::BoundaryTag::prev): (bmalloc::BoundaryTag::next): * bmalloc/BoundaryTagInlines.h: Added. (bmalloc::validate): (bmalloc::validatePrev): (bmalloc::validateNext): (bmalloc::BoundaryTag::init): (bmalloc::BoundaryTag::mergeLargeLeft): (bmalloc::BoundaryTag::mergeLargeRight): (bmalloc::BoundaryTag::mergeLarge): (bmalloc::BoundaryTag::deallocate): (bmalloc::BoundaryTag::splitLarge): (bmalloc::BoundaryTag::allocate): * bmalloc/Cache.cpp: Added. (bmalloc::Cache::operator new): (bmalloc::Cache::operator delete): (bmalloc::Cache::Cache): (bmalloc::Cache::allocateSlowCase): (bmalloc::Cache::allocateSlowCaseNullCache): (bmalloc::Cache::deallocateSlowCase): (bmalloc::Cache::deallocateSlowCaseNullCache): * bmalloc/Cache.h: Added. (bmalloc::Cache::allocator): (bmalloc::Cache::deallocator): (bmalloc::Cache::allocateFastCase): (bmalloc::Cache::deallocateFastCase): (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): * bmalloc/Chunk.h: Added. (bmalloc::Chunk::begin): (bmalloc::Chunk::end): (bmalloc::Chunk::lines): (bmalloc::Chunk::pages): * bmalloc/Deallocator.cpp: Added. (bmalloc::Deallocator::Deallocator): (bmalloc::Deallocator::~Deallocator): (bmalloc::Deallocator::deallocateLarge): (bmalloc::Deallocator::deallocateXLarge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): (bmalloc::Deallocator::deallocateSmallLine): (bmalloc::Deallocator::allocateSmallLine): (bmalloc::Deallocator::deallocateMediumLine): (bmalloc::Deallocator::allocateMediumLine): * bmalloc/Deallocator.h: Added. (bmalloc::Deallocator::deallocateFastCase): (bmalloc::Deallocator::deallocate): * bmalloc/EndTag.h: Added. (bmalloc::EndTag::operator=): * bmalloc/FixedVector.h: Added. (bmalloc::FixedVector::begin): (bmalloc::FixedVector::end): (bmalloc::FixedVector::size): (bmalloc::FixedVector::capacity): (bmalloc::FixedVector::clear): (bmalloc::FixedVector::isEmpty): (bmalloc::Capacity>::FixedVector): (bmalloc::Capacity>::operator): (bmalloc::Capacity>::push): (bmalloc::Capacity>::pop): (bmalloc::Capacity>::shrink): * bmalloc/Heap.cpp: Added. (bmalloc::sleep): (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeMediumPages): (bmalloc::Heap::scavengeLargeRanges): (bmalloc::Heap::allocateSmallLineSlowCase): (bmalloc::Heap::allocateMediumLineSlowCase): (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::deallocateXLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: Added. (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallLine): (bmalloc::Heap::deallocateMediumLine): (bmalloc::Heap::allocateMediumLine): * bmalloc/Inline.h: Added. * bmalloc/LargeChunk.h: Added. (bmalloc::LargeChunk::begin): (bmalloc::LargeChunk::end): (bmalloc::LargeChunk::create): (bmalloc::LargeChunk::get): (bmalloc::LargeChunk::beginTag): (bmalloc::LargeChunk::endTag): * bmalloc/Line.h: Added. (bmalloc::Line<Traits>::begin): (bmalloc::Line<Traits>::end): (bmalloc::Line<Traits>::concurrentRef): (bmalloc::Line<Traits>::deref): * bmalloc/MediumAllocator.h: Added. (bmalloc::MediumAllocator::isNull): (bmalloc::MediumAllocator::MediumAllocator): (bmalloc::MediumAllocator::line): (bmalloc::MediumAllocator::allocate): (bmalloc::MediumAllocator::derefCount): (bmalloc::MediumAllocator::refill): * bmalloc/MediumChunk.h: Added. * bmalloc/MediumLine.h: Added. * bmalloc/MediumPage.h: Added. * bmalloc/MediumTraits.h: Added. * bmalloc/Mutex.cpp: Added. (bmalloc::Mutex::lockSlowCase): * bmalloc/Mutex.h: Added. (bmalloc::Mutex::Mutex): (bmalloc::Mutex::try_lock): (bmalloc::Mutex::lock): (bmalloc::Mutex::unlock): * bmalloc/ObjectType.cpp: Added. (bmalloc::objectType): * bmalloc/ObjectType.h: Added. (bmalloc::isSmallOrMedium): (bmalloc::isSmall): * bmalloc/Page.h: Added. (bmalloc::Page<Traits>::ref): (bmalloc::Page<Traits>::deref): (bmalloc::Page<Traits>::refCount): * bmalloc/PerProcess.h: Added. (bmalloc::PerProcess::mutex): (bmalloc::PerProcess<T>::getFastCase): (bmalloc::PerProcess<T>::get): (bmalloc::PerProcess<T>::getSlowCase): * bmalloc/PerThread.h: Added. (bmalloc::PerThreadStorage<Cache>::get): (bmalloc::PerThreadStorage<Cache>::init): (bmalloc::PerThreadStorage::get): (bmalloc::PerThreadStorage::init): (bmalloc::PerThread<T>::getFastCase): (bmalloc::PerThread<T>::get): (bmalloc::PerThread<T>::destructor): (bmalloc::PerThread<T>::getSlowCase): * bmalloc/Range.h: Added. (bmalloc::Range::Range): (bmalloc::Range::begin): (bmalloc::Range::end): (bmalloc::Range::size): (bmalloc::Range::operator!): (bmalloc::Range::operator<): * bmalloc/SegregatedFreeList.cpp: Added. (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: Added. * bmalloc/Sizes.h: Added. * bmalloc/SmallAllocator.h: Added. (bmalloc::SmallAllocator::isNull): (bmalloc::SmallAllocator::canAllocate): (bmalloc::SmallAllocator::SmallAllocator): (bmalloc::SmallAllocator::line): (bmalloc::SmallAllocator::allocate): (bmalloc::SmallAllocator::objectCount): (bmalloc::SmallAllocator::derefCount): (bmalloc::SmallAllocator::refill): * bmalloc/SmallChunk.h: Added. * bmalloc/SmallLine.h: Added. * bmalloc/SmallPage.h: Added. * bmalloc/SmallTraits.h: Added. * bmalloc/Syscall.h: Added. * bmalloc/VMAllocate.h: Added. (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::vmAllocate): (bmalloc::vmDeallocate): (bmalloc::vmDeallocatePhysicalPages): (bmalloc::vmAllocatePhysicalPages): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): * bmalloc/VMHeap.cpp: Added. (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::allocateMediumChunk): (bmalloc::VMHeap::allocateLargeChunk): * bmalloc/VMHeap.h: Added. (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeRange): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::deallocateMediumPage): (bmalloc::VMHeap::deallocateLargeRange): * bmalloc/Vector.h: Added. (bmalloc::Vector::begin): (bmalloc::Vector::end): (bmalloc::Vector::size): (bmalloc::Vector::capacity): (bmalloc::Vector::last): (bmalloc::Vector::pop): (bmalloc::Vector<T>::Vector): (bmalloc::Vector<T>::~Vector): (bmalloc::Vector<T>::operator): (bmalloc::Vector<T>::push): (bmalloc::Vector<T>::pop): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::reallocateBuffer): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): * bmalloc/XLargeChunk.h: Added. (bmalloc::XLargeChunk::get): (bmalloc::XLargeChunk::begin): (bmalloc::XLargeChunk::XLargeChunk): (bmalloc::XLargeChunk::create): (bmalloc::XLargeChunk::destroy): (bmalloc::XLargeChunk::range): (bmalloc::XLargeChunk::size): * bmalloc/bmalloc.h: Added. (bmalloc::api::malloc): (bmalloc::api::free): (bmalloc::api::realloc): * bmalloc/mbmalloc.cpp: Added. Canonical link: https://commits.webkit.org/149378@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166893 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-07 23:54:11 +00:00
} // namespace bmalloc
#endif // SmallPage_h