[bmalloc] Add StaticPerProcess for known types to save pages
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2019 08:02:00 +0000 (08:02 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2019 08:02:00 +0000 (08:02 +0000)
commitd2adc3d2b656e25c3bca0366e1c03edec1b9f543
tree2bc1d8c549aed277e8f928a6c61c8c030677b80c
parent79717ebe8c9b17ced87472dfae05f49105bdb14f
[bmalloc] Add StaticPerProcess for known types to save pages
https://bugs.webkit.org/show_bug.cgi?id=195691

Reviewed by Mark Lam.

As initial memory footprint of VM + JSGlobalObject becomes 488KB dirty size in fast malloc memory (w/ JSC_useJIT=0 and Malloc=1), pages for PerProcess is costly.
For example, under Malloc=1 mode, we still need to allocate PerProcess<DebugHeap> and PerProcess<Environment>. And sizeof(Environment) is only 1 (bool flag), and
sizeof(DebugHeap) is 120. But we are allocating 1 pages for them. Since page size in iOS is 16KB, this 121B consumes 16KB dirty memory, and it is not negligible
size if we keep in mind that the current fast malloc heap size is 488KB. Putting them into the __DATA section, close to the other mutable data, we can avoid allocating
this page.

This patch revives the SafePerProcess concept in r228107. We add "StaticPerProcess<T>", which allocates underlying storage statically in the __DATA section instead of
allocating it at runtime. And we use this StaticPerProcess<T> for types where (1) T is known a priori, and (2) sizeof(T) is not huge.

* bmalloc.xcodeproj/project.pbxproj:
* bmalloc/AllIsoHeaps.cpp:
* bmalloc/AllIsoHeaps.h:
* bmalloc/Allocator.cpp:
(bmalloc::Allocator::Allocator):
* bmalloc/Cache.cpp:
(bmalloc::Cache::Cache):
* bmalloc/CryptoRandom.cpp:
(bmalloc::cryptoRandom):
* bmalloc/Deallocator.cpp:
(bmalloc::Deallocator::Deallocator):
* bmalloc/DebugHeap.cpp:
* bmalloc/DebugHeap.h:
(bmalloc::DebugHeap::tryGet):
* bmalloc/Environment.cpp:
* bmalloc/Environment.h:
* bmalloc/Gigacage.cpp:
(Gigacage::Callback::Callback):
(Gigacage::Callback::function):
(bmalloc::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks):
(Gigacage::disablePrimitiveGigacage):
(Gigacage::addPrimitiveDisableCallback):
(Gigacage::removePrimitiveDisableCallback):
(Gigacage::shouldBeEnabled):
(Gigacage::bmalloc::Callback::Callback): Deleted.
(Gigacage::bmalloc::Callback::function): Deleted.
(Gigacage::bmalloc::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks): Deleted.
* bmalloc/Heap.cpp:
(bmalloc::Heap::Heap):
(bmalloc::Heap::tryAllocateLarge):
* bmalloc/IsoDirectoryInlines.h:
(bmalloc::passedNumPages>::takeFirstEligible):
(bmalloc::passedNumPages>::didBecome):
* bmalloc/IsoHeapImpl.cpp:
(bmalloc::IsoHeapImplBase::addToAllIsoHeaps):
* bmalloc/IsoPage.cpp:
(bmalloc::IsoPageBase::allocatePageMemory):
* bmalloc/IsoTLS.cpp:
(bmalloc::IsoTLS::IsoTLS):
(bmalloc::IsoTLS::ensureEntries):
(bmalloc::IsoTLS::forEachEntry):
* bmalloc/IsoTLSEntry.cpp:
(bmalloc::IsoTLSEntry::IsoTLSEntry):
* bmalloc/IsoTLSInlines.h:
(bmalloc::IsoTLS::allocateSlow):
(bmalloc::IsoTLS::deallocateSlow):
* bmalloc/IsoTLSLayout.cpp:
* bmalloc/IsoTLSLayout.h:
* bmalloc/Scavenger.cpp:
(bmalloc::Scavenger::Scavenger):
(bmalloc::dumpStats):
(bmalloc::Scavenger::scavenge):
(bmalloc::Scavenger::partialScavenge):
(bmalloc::Scavenger::freeableMemory):
(bmalloc::Scavenger::footprint):
* bmalloc/Scavenger.h:
* bmalloc/StaticPerProcess.h: Added.
* bmalloc/VMHeap.cpp:
* bmalloc/VMHeap.h:
* bmalloc/Zone.h:
* bmalloc/bmalloc.cpp:
(bmalloc::api::scavenge):
(bmalloc::api::isEnabled):
(bmalloc::api::setScavengerThreadQOSClass):
(bmalloc::api::enableMiniMode):
* test/testbmalloc.cpp:
(assertEmptyPointerSet):
(assertHasObjects):
(assertHasOnlyObjects):
(assertClean):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242938 268f45cc-cd09-0410-ab3c-d52691b4dbfc
30 files changed:
Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc.xcodeproj/project.pbxproj
Source/bmalloc/bmalloc/AllIsoHeaps.cpp
Source/bmalloc/bmalloc/AllIsoHeaps.h
Source/bmalloc/bmalloc/Allocator.cpp
Source/bmalloc/bmalloc/Cache.cpp
Source/bmalloc/bmalloc/CryptoRandom.cpp
Source/bmalloc/bmalloc/Deallocator.cpp
Source/bmalloc/bmalloc/DebugHeap.cpp
Source/bmalloc/bmalloc/DebugHeap.h
Source/bmalloc/bmalloc/Environment.cpp
Source/bmalloc/bmalloc/Environment.h
Source/bmalloc/bmalloc/Gigacage.cpp
Source/bmalloc/bmalloc/Heap.cpp
Source/bmalloc/bmalloc/IsoDirectoryInlines.h
Source/bmalloc/bmalloc/IsoHeapImpl.cpp
Source/bmalloc/bmalloc/IsoPage.cpp
Source/bmalloc/bmalloc/IsoTLS.cpp
Source/bmalloc/bmalloc/IsoTLSEntry.cpp
Source/bmalloc/bmalloc/IsoTLSInlines.h
Source/bmalloc/bmalloc/IsoTLSLayout.cpp
Source/bmalloc/bmalloc/IsoTLSLayout.h
Source/bmalloc/bmalloc/Scavenger.cpp
Source/bmalloc/bmalloc/Scavenger.h
Source/bmalloc/bmalloc/StaticPerProcess.h [new file with mode: 0644]
Source/bmalloc/bmalloc/VMHeap.cpp
Source/bmalloc/bmalloc/VMHeap.h
Source/bmalloc/bmalloc/Zone.h
Source/bmalloc/bmalloc/bmalloc.cpp
Source/bmalloc/test/testbmalloc.cpp