Commit 5d0b30a2 authored by mhahnenberg@apple.com's avatar mhahnenberg@apple.com

Implement a new allocator for backing stores

https://bugs.webkit.org/show_bug.cgi?id=75181

Reviewed by Filip Pizlo.

Source/JavaScriptCore: 

We want to move away from using fastMalloc for the backing stores for 
some of our objects (e.g. JSArray, JSObject, JSString, etc).  These backing 
stores have a nice property in that they only have a single owner (i.e. a 
single pointer to them at any one time).  One way that we can take advantage 
of this property is to implement a simple bump allocator/copying collector, 
which will run alongside our normal mark/sweep collector, that only needs to 
update the single owner pointer rather than having to redirect an arbitrary 
number of pointers in from-space to to-space.

This plan can give us a number of benefits. We can beat fastMalloc in terms 
of both performance and memory usage, we can track how much memory we're using 
far more accurately than our rough estimation now through the use of 
reportExtraMemoryCost, and we can allocate arbitrary size objects (as opposed 
to being limited to size classes like we have been historically). This is also 
another step toward moving away from lazy destruction, which will improve our memory footprint.

We start by creating said allocator and moving the ArrayStorage for JSArray 
to use it rather than fastMalloc.

The design of the collector is as follows:
Allocation:
-The collector allocates 64KB chunks from the OS to use for object allocation.
-Each chunk contains an offset, a flag indicating if the block has been pinned, 
 and a payload, along with next and prev pointers so that they can be put in DoublyLinkedLists.
-Any allocation greater than 64KB gets its own separate oversize block, which 
 is managed separately from the rest.
-If the allocator receives a request for more than the remaining amount in the 
 current block, it grabs a fresh block.
-Grabbing a fresh block means grabbing one off of the global free list (which is now 
 shared between the mark/sweep allocator and the bump allocator) if there is one. 
 If there isn't a new one we do one of two things: allocate a new block from the OS 
 if we're not ready for a GC yet, or run a GC and then try again. If we still don't 
 have enough space after the GC, we allocate a new block from the OS.

Garbage collection:
-At the start of garbage collection during conservative stack scanning, if we encounter 
 what appears to be a pointer to a bump-allocated block of memory, we pin that block so 
 that it will not be copied for this round of collection.
-We also pin any oversize blocks that we encounter, which effectively doubles as a 
 "mark bit" for that block. Any oversize blocks that aren't pinned at the end of copying 
 are given back to the OS.
-Marking threads are now also responsible for copying bump-allocated objects to newSpace
-Each marking thread has a private 64KB block into which it copies bump-allocated objects that it encounters.
-When that block fills up, the marking thread gives it back to the allocator and requests a new one.
-When all marking has concluded, each thread gives back its copy block, even if it isn't full.
-At the conclusion of copying (which is done by the end of the marking phase), we un-pin 
 any pinned blocks and give any blocks left in from-space to the global free list.

* CMakeLists.txt:
* GNUmakefile.list.am:
* JavaScriptCore.gypi:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
* JavaScriptCore.vcproj/WTF/WTF.vcproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* Target.pri:
* heap/AllocationSpace.cpp:
(JSC::AllocationSpace::allocateSlowCase):
(JSC::AllocationSpace::allocateBlock):
(JSC::AllocationSpace::freeBlocks):
* heap/AllocationSpace.h:
(JSC::AllocationSpace::waterMark):
* heap/BumpBlock.h: Added.
(JSC::BumpBlock::BumpBlock):
* heap/BumpSpace.cpp: Added.
(JSC::BumpSpace::tryAllocateSlowCase):
* heap/BumpSpace.h: Added.
(JSC::BumpSpace::isInCopyPhase):
(JSC::BumpSpace::totalMemoryAllocated):
(JSC::BumpSpace::totalMemoryUtilized):
* heap/BumpSpaceInlineMethods.h: Added.
(JSC::BumpSpace::BumpSpace):
(JSC::BumpSpace::init):
(JSC::BumpSpace::contains):
(JSC::BumpSpace::pin):
(JSC::BumpSpace::startedCopying):
(JSC::BumpSpace::doneCopying):
(JSC::BumpSpace::doneFillingBlock):
(JSC::BumpSpace::recycleBlock):
(JSC::BumpSpace::getFreshBlock):
(JSC::BumpSpace::borrowBlock):
(JSC::BumpSpace::addNewBlock):
(JSC::BumpSpace::allocateNewBlock):
(JSC::BumpSpace::fitsInBlock):
(JSC::BumpSpace::fitsInCurrentBlock):
(JSC::BumpSpace::tryAllocate):
(JSC::BumpSpace::tryAllocateOversize):
(JSC::BumpSpace::allocateFromBlock):
(JSC::BumpSpace::tryReallocate):
(JSC::BumpSpace::tryReallocateOversize):
(JSC::BumpSpace::isOversize):
(JSC::BumpSpace::isPinned):
(JSC::BumpSpace::oversizeBlockFor):
(JSC::BumpSpace::blockFor):
* heap/ConservativeRoots.cpp:
(JSC::ConservativeRoots::ConservativeRoots):
(JSC::ConservativeRoots::genericAddPointer):
(JSC::ConservativeRoots::add):
* heap/ConservativeRoots.h:
* heap/Heap.cpp:
(JSC::Heap::Heap):
(JSC::Heap::blockFreeingThreadMain):
(JSC::Heap::reportExtraMemoryCostSlowCase):
(JSC::Heap::getConservativeRegisterRoots):
(JSC::Heap::markRoots):
(JSC::Heap::collect):
(JSC::Heap::releaseFreeBlocks):
* heap/Heap.h:
(JSC::Heap::waterMark):
(JSC::Heap::highWaterMark):
(JSC::Heap::setHighWaterMark):
(JSC::Heap::tryAllocateStorage):
(JSC::Heap::tryReallocateStorage):
* heap/HeapBlock.h: Added.
(JSC::HeapBlock::HeapBlock):
* heap/MarkStack.cpp:
(JSC::MarkStackThreadSharedData::MarkStackThreadSharedData):
(JSC::SlotVisitor::drain):
(JSC::SlotVisitor::drainFromShared):
(JSC::SlotVisitor::startCopying):
(JSC::SlotVisitor::allocateNewSpace):
(JSC::SlotVisitor::copy):
(JSC::SlotVisitor::copyAndAppend):
(JSC::SlotVisitor::doneCopying):
* heap/MarkStack.h:
* heap/MarkedBlock.cpp:
(JSC::MarkedBlock::recycle):
(JSC::MarkedBlock::MarkedBlock):
* heap/MarkedBlock.h:
* heap/MarkedSpace.cpp:
(JSC::MarkedSpace::MarkedSpace):
* heap/MarkedSpace.h:
(JSC::MarkedSpace::allocate):
(JSC::MarkedSpace::forEachBlock):
(JSC::MarkedSpace::SizeClass::resetAllocator):
* heap/SlotVisitor.h:
(JSC::SlotVisitor::SlotVisitor):
* heap/TinyBloomFilter.h:
(JSC::TinyBloomFilter::reset):
* runtime/JSArray.cpp:
(JSC::JSArray::JSArray):
(JSC::JSArray::finishCreation):
(JSC::JSArray::tryFinishCreationUninitialized):
(JSC::JSArray::~JSArray):
(JSC::JSArray::enterSparseMode):
(JSC::JSArray::defineOwnNumericProperty):
(JSC::JSArray::setLengthWritable):
(JSC::JSArray::getOwnPropertySlotByIndex):
(JSC::JSArray::getOwnPropertyDescriptor):
(JSC::JSArray::putByIndexBeyondVectorLength):
(JSC::JSArray::deletePropertyByIndex):
(JSC::JSArray::getOwnPropertyNames):
(JSC::JSArray::increaseVectorLength):
(JSC::JSArray::unshiftCountSlowCase):
(JSC::JSArray::setLength):
(JSC::JSArray::pop):
(JSC::JSArray::unshiftCount):
(JSC::JSArray::visitChildren):
(JSC::JSArray::sortNumeric):
(JSC::JSArray::sort):
(JSC::JSArray::compactForSorting):
(JSC::JSArray::subclassData):
(JSC::JSArray::setSubclassData):
(JSC::JSArray::checkConsistency):
* runtime/JSArray.h:
(JSC::JSArray::inSparseMode):
(JSC::JSArray::isLengthWritable):
* wtf/CheckedBoolean.h: Added.
(CheckedBoolean::CheckedBoolean):
(CheckedBoolean::~CheckedBoolean):
(CheckedBoolean::operator bool):
* wtf/DoublyLinkedList.h:
(WTF::::push):
* wtf/StdLibExtras.h:
(WTF::isPointerAligned):

Source/JavaScriptGlue: 

Added forwarding header for new CheckedBoolean used in the bump allocator.

* ForwardingHeaders/wtf/CheckedBoolean.h: Added.

Source/WebCore: 

No new tests.

Added forwarding header for new CheckedBoolean used in the bump allocator.

* ForwardingHeaders/wtf/CheckedBoolean.h: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105442 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6c2ef9d0
......@@ -70,6 +70,7 @@ SET(JavaScriptCore_SOURCES
dfg/DFGThunks.cpp
heap/AllocationSpace.cpp
heap/BumpSpace.cpp
heap/DFGCodeBlocks.cpp
heap/Heap.cpp
heap/HandleHeap.cpp
......
2012-01-19 Mark Hahnenberg <mhahnenberg@apple.com>
Implement a new allocator for backing stores
https://bugs.webkit.org/show_bug.cgi?id=75181
Reviewed by Filip Pizlo.
We want to move away from using fastMalloc for the backing stores for
some of our objects (e.g. JSArray, JSObject, JSString, etc). These backing
stores have a nice property in that they only have a single owner (i.e. a
single pointer to them at any one time). One way that we can take advantage
of this property is to implement a simple bump allocator/copying collector,
which will run alongside our normal mark/sweep collector, that only needs to
update the single owner pointer rather than having to redirect an arbitrary
number of pointers in from-space to to-space.
This plan can give us a number of benefits. We can beat fastMalloc in terms
of both performance and memory usage, we can track how much memory we're using
far more accurately than our rough estimation now through the use of
reportExtraMemoryCost, and we can allocate arbitrary size objects (as opposed
to being limited to size classes like we have been historically). This is also
another step toward moving away from lazy destruction, which will improve our memory footprint.
We start by creating said allocator and moving the ArrayStorage for JSArray
to use it rather than fastMalloc.
The design of the collector is as follows:
Allocation:
-The collector allocates 64KB chunks from the OS to use for object allocation.
-Each chunk contains an offset, a flag indicating if the block has been pinned,
and a payload, along with next and prev pointers so that they can be put in DoublyLinkedLists.
-Any allocation greater than 64KB gets its own separate oversize block, which
is managed separately from the rest.
-If the allocator receives a request for more than the remaining amount in the
current block, it grabs a fresh block.
-Grabbing a fresh block means grabbing one off of the global free list (which is now
shared between the mark/sweep allocator and the bump allocator) if there is one.
If there isn't a new one we do one of two things: allocate a new block from the OS
if we're not ready for a GC yet, or run a GC and then try again. If we still don't
have enough space after the GC, we allocate a new block from the OS.
Garbage collection:
-At the start of garbage collection during conservative stack scanning, if we encounter
what appears to be a pointer to a bump-allocated block of memory, we pin that block so
that it will not be copied for this round of collection.
-We also pin any oversize blocks that we encounter, which effectively doubles as a
"mark bit" for that block. Any oversize blocks that aren't pinned at the end of copying
are given back to the OS.
-Marking threads are now also responsible for copying bump-allocated objects to newSpace
-Each marking thread has a private 64KB block into which it copies bump-allocated objects that it encounters.
-When that block fills up, the marking thread gives it back to the allocator and requests a new one.
-When all marking has concluded, each thread gives back its copy block, even if it isn't full.
-At the conclusion of copying (which is done by the end of the marking phase), we un-pin
any pinned blocks and give any blocks left in from-space to the global free list.
* CMakeLists.txt:
* GNUmakefile.list.am:
* JavaScriptCore.gypi:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
* JavaScriptCore.vcproj/WTF/WTF.vcproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* Target.pri:
* heap/AllocationSpace.cpp:
(JSC::AllocationSpace::allocateSlowCase):
(JSC::AllocationSpace::allocateBlock):
(JSC::AllocationSpace::freeBlocks):
* heap/AllocationSpace.h:
(JSC::AllocationSpace::waterMark):
* heap/BumpBlock.h: Added.
(JSC::BumpBlock::BumpBlock):
* heap/BumpSpace.cpp: Added.
(JSC::BumpSpace::tryAllocateSlowCase):
* heap/BumpSpace.h: Added.
(JSC::BumpSpace::isInCopyPhase):
(JSC::BumpSpace::totalMemoryAllocated):
(JSC::BumpSpace::totalMemoryUtilized):
* heap/BumpSpaceInlineMethods.h: Added.
(JSC::BumpSpace::BumpSpace):
(JSC::BumpSpace::init):
(JSC::BumpSpace::contains):
(JSC::BumpSpace::pin):
(JSC::BumpSpace::startedCopying):
(JSC::BumpSpace::doneCopying):
(JSC::BumpSpace::doneFillingBlock):
(JSC::BumpSpace::recycleBlock):
(JSC::BumpSpace::getFreshBlock):
(JSC::BumpSpace::borrowBlock):
(JSC::BumpSpace::addNewBlock):
(JSC::BumpSpace::allocateNewBlock):
(JSC::BumpSpace::fitsInBlock):
(JSC::BumpSpace::fitsInCurrentBlock):
(JSC::BumpSpace::tryAllocate):
(JSC::BumpSpace::tryAllocateOversize):
(JSC::BumpSpace::allocateFromBlock):
(JSC::BumpSpace::tryReallocate):
(JSC::BumpSpace::tryReallocateOversize):
(JSC::BumpSpace::isOversize):
(JSC::BumpSpace::isPinned):
(JSC::BumpSpace::oversizeBlockFor):
(JSC::BumpSpace::blockFor):
* heap/ConservativeRoots.cpp:
(JSC::ConservativeRoots::ConservativeRoots):
(JSC::ConservativeRoots::genericAddPointer):
(JSC::ConservativeRoots::add):
* heap/ConservativeRoots.h:
* heap/Heap.cpp:
(JSC::Heap::Heap):
(JSC::Heap::blockFreeingThreadMain):
(JSC::Heap::reportExtraMemoryCostSlowCase):
(JSC::Heap::getConservativeRegisterRoots):
(JSC::Heap::markRoots):
(JSC::Heap::collect):
(JSC::Heap::releaseFreeBlocks):
* heap/Heap.h:
(JSC::Heap::waterMark):
(JSC::Heap::highWaterMark):
(JSC::Heap::setHighWaterMark):
(JSC::Heap::tryAllocateStorage):
(JSC::Heap::tryReallocateStorage):
* heap/HeapBlock.h: Added.
(JSC::HeapBlock::HeapBlock):
* heap/MarkStack.cpp:
(JSC::MarkStackThreadSharedData::MarkStackThreadSharedData):
(JSC::SlotVisitor::drain):
(JSC::SlotVisitor::drainFromShared):
(JSC::SlotVisitor::startCopying):
(JSC::SlotVisitor::allocateNewSpace):
(JSC::SlotVisitor::copy):
(JSC::SlotVisitor::copyAndAppend):
(JSC::SlotVisitor::doneCopying):
* heap/MarkStack.h:
* heap/MarkedBlock.cpp:
(JSC::MarkedBlock::recycle):
(JSC::MarkedBlock::MarkedBlock):
* heap/MarkedBlock.h:
* heap/MarkedSpace.cpp:
(JSC::MarkedSpace::MarkedSpace):
* heap/MarkedSpace.h:
(JSC::MarkedSpace::allocate):
(JSC::MarkedSpace::forEachBlock):
(JSC::MarkedSpace::SizeClass::resetAllocator):
* heap/SlotVisitor.h:
(JSC::SlotVisitor::SlotVisitor):
* heap/TinyBloomFilter.h:
(JSC::TinyBloomFilter::reset):
* runtime/JSArray.cpp:
(JSC::JSArray::JSArray):
(JSC::JSArray::finishCreation):
(JSC::JSArray::tryFinishCreationUninitialized):
(JSC::JSArray::~JSArray):
(JSC::JSArray::enterSparseMode):
(JSC::JSArray::defineOwnNumericProperty):
(JSC::JSArray::setLengthWritable):
(JSC::JSArray::getOwnPropertySlotByIndex):
(JSC::JSArray::getOwnPropertyDescriptor):
(JSC::JSArray::putByIndexBeyondVectorLength):
(JSC::JSArray::deletePropertyByIndex):
(JSC::JSArray::getOwnPropertyNames):
(JSC::JSArray::increaseVectorLength):
(JSC::JSArray::unshiftCountSlowCase):
(JSC::JSArray::setLength):
(JSC::JSArray::pop):
(JSC::JSArray::unshiftCount):
(JSC::JSArray::visitChildren):
(JSC::JSArray::sortNumeric):
(JSC::JSArray::sort):
(JSC::JSArray::compactForSorting):
(JSC::JSArray::subclassData):
(JSC::JSArray::setSubclassData):
(JSC::JSArray::checkConsistency):
* runtime/JSArray.h:
(JSC::JSArray::inSparseMode):
(JSC::JSArray::isLengthWritable):
* wtf/CheckedBoolean.h: Added.
(CheckedBoolean::CheckedBoolean):
(CheckedBoolean::~CheckedBoolean):
(CheckedBoolean::operator bool):
* wtf/DoublyLinkedList.h:
(WTF::::push):
* wtf/StdLibExtras.h:
(WTF::isPointerAligned):
2012-01-19 Joi Sigurdsson <joi@chromium.org>
Enable use of precompiled headers in Chromium port on Windows.
......@@ -172,6 +172,10 @@ javascriptcore_sources += \
Source/JavaScriptCore/dfg/DFGVariableAccessData.h \
Source/JavaScriptCore/heap/AllocationSpace.cpp \
Source/JavaScriptCore/heap/AllocationSpace.h \
Source/JavaScriptCore/heap/BumpBlock.h \
Source/JavaScriptCore/heap/BumpSpace.cpp \
Source/JavaScriptCore/heap/BumpSpace.h \
Source/JavaScriptCore/heap/BumpSpaceInlineMethods.h \
Source/JavaScriptCore/heap/CardSet.h \
Source/JavaScriptCore/heap/ConservativeRoots.cpp \
Source/JavaScriptCore/heap/ConservativeRoots.h \
......@@ -180,6 +184,7 @@ javascriptcore_sources += \
Source/JavaScriptCore/heap/Handle.h \
Source/JavaScriptCore/heap/HandleHeap.cpp \
Source/JavaScriptCore/heap/HandleHeap.h \
Source/JavaScriptCore/heap/HeapBlock.h \
Source/JavaScriptCore/heap/SlotVisitor.h \
Source/JavaScriptCore/heap/HandleStack.cpp \
Source/JavaScriptCore/heap/HandleStack.h \
......@@ -533,6 +538,7 @@ javascriptcore_sources += \
Source/JavaScriptCore/wtf/ByteArray.cpp \
Source/JavaScriptCore/wtf/ByteArray.h \
Source/JavaScriptCore/wtf/CheckedArithmetic.h \
Source/JavaScriptCore/wtf/CheckedBoolean.h \
Source/JavaScriptCore/wtf/Compiler.h \
Source/JavaScriptCore/wtf/CryptographicallyRandomNumber.cpp \
Source/JavaScriptCore/wtf/CryptographicallyRandomNumber.h \
......
......@@ -28,9 +28,13 @@
'assembler/MacroAssemblerCodeRef.h',
'bytecode/Opcode.h',
'heap/AllocationSpace.h',
'heap/BumpBlock.h',
'heap/BumpSpace.h',
'heap/BumpSpaceInlineMethods.h',
'heap/ConservativeRoots.h',
'heap/Handle.h',
'heap/HandleHeap.h',
'heap/HeapBlock.h',
'heap/SlotVisitor.h',
'heap/HandleStack.h',
'heap/HandleTypes.h',
......@@ -144,6 +148,7 @@
'wtf/BumpPointerAllocator.h',
'wtf/ByteArray.h',
'wtf/CheckedArithmetic.h',
'wtf/CheckedBoolean.h',
'wtf/Compiler.h',
'wtf/Complex.h',
'wtf/CryptographicallyRandomNumber.h',
......
......@@ -1973,6 +1973,22 @@
RelativePath="..\..\heap\AllocationSpace.h"
>
</File>
<File
RelativePath="..\..\heap\BumpBlock.h"
>
</File>
<File
RelativePath="..\..\heap\BumpSpace.cpp"
>
</File>
<File
RelativePath="..\..\heap\BumpSpace.h"
>
</File>
<File
RelativePath="..\..\heap\BumpSpaceInlineMethods.h"
>
</File>
<File
RelativePath="..\..\heap\ConservativeRoots.cpp"
>
......@@ -2025,6 +2041,10 @@
RelativePath="..\..\heap\Heap.h"
>
</File>
<File
RelativePath="..\..\heap\HeapBlock.h"
>
</File>
<File
RelativePath="..\..\heap\Strong.h"
>
......
......@@ -692,6 +692,10 @@
RelativePath="..\..\wtf\CheckedArithmetic.h"
>
</File>
<File
RelativePath="..\..\wtf\CheckedBoolean.h"
>
</File>
<File
RelativePath="..\..\wtf\Compiler.h"
>
......
......@@ -710,6 +710,12 @@
C22C531313FAF6EF00B7DC0D /* strtod.cc in Sources */ = {isa = PBXBuildFile; fileRef = C22C52B913FAF6EF00B7DC0D /* strtod.cc */; };
C22C531413FAF6EF00B7DC0D /* strtod.h in Headers */ = {isa = PBXBuildFile; fileRef = C22C52BA13FAF6EF00B7DC0D /* strtod.h */; settings = {ATTRIBUTES = (Private, ); }; };
C22C531513FAF6EF00B7DC0D /* utils.h in Headers */ = {isa = PBXBuildFile; fileRef = C22C52BB13FAF6EF00B7DC0D /* utils.h */; settings = {ATTRIBUTES = (Private, ); }; };
C240305514B404E60079EB64 /* BumpSpace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C240305314B404C90079EB64 /* BumpSpace.cpp */; };
C2C8D02D14A3C6E000578E65 /* BumpSpaceInlineMethods.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02B14A3C6B200578E65 /* BumpSpaceInlineMethods.h */; settings = {ATTRIBUTES = (Private, ); }; };
C2C8D03014A3CEFC00578E65 /* BumpBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02E14A3CEFC00578E65 /* BumpBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
C2C8D03114A3CEFC00578E65 /* HeapBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02F14A3CEFC00578E65 /* HeapBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
C2D9CA1314BCC04600304B46 /* CheckedBoolean.h in Headers */ = {isa = PBXBuildFile; fileRef = C2D9CA1214BCC04600304B46 /* CheckedBoolean.h */; settings = {ATTRIBUTES = (Private, ); }; };
C2EAA3FA149A835E00FCE112 /* BumpSpace.h in Headers */ = {isa = PBXBuildFile; fileRef = C2EAA3F8149A830800FCE112 /* BumpSpace.h */; settings = {ATTRIBUTES = (Private, ); }; };
C2EE59A013FC973F009CEAFE /* DecimalNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = C2EE599E13FC972A009CEAFE /* DecimalNumber.h */; settings = {ATTRIBUTES = (Private, ); }; };
C2EE59A113FC9768009CEAFE /* DecimalNumber.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2EE599D13FC972A009CEAFE /* DecimalNumber.cpp */; };
D7A46A4F1338FFEA00ED695C /* DynamicAnnotations.h in Headers */ = {isa = PBXBuildFile; fileRef = D75AF59612F8CB9500FC0ADF /* DynamicAnnotations.h */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -1475,6 +1481,12 @@
C22C52B913FAF6EF00B7DC0D /* strtod.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = strtod.cc; sourceTree = "<group>"; };
C22C52BA13FAF6EF00B7DC0D /* strtod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = strtod.h; sourceTree = "<group>"; };
C22C52BB13FAF6EF00B7DC0D /* utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utils.h; sourceTree = "<group>"; };
C240305314B404C90079EB64 /* BumpSpace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BumpSpace.cpp; sourceTree = "<group>"; };
C2C8D02B14A3C6B200578E65 /* BumpSpaceInlineMethods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BumpSpaceInlineMethods.h; sourceTree = "<group>"; };
C2C8D02E14A3CEFC00578E65 /* BumpBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BumpBlock.h; sourceTree = "<group>"; };
C2C8D02F14A3CEFC00578E65 /* HeapBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeapBlock.h; sourceTree = "<group>"; };
C2D9CA1214BCC04600304B46 /* CheckedBoolean.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CheckedBoolean.h; sourceTree = "<group>"; };
C2EAA3F8149A830800FCE112 /* BumpSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BumpSpace.h; sourceTree = "<group>"; };
C2EE599D13FC972A009CEAFE /* DecimalNumber.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DecimalNumber.cpp; sourceTree = "<group>"; };
C2EE599E13FC972A009CEAFE /* DecimalNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DecimalNumber.h; sourceTree = "<group>"; };
D21202280AD4310C00ED79B6 /* DateConversion.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DateConversion.cpp; sourceTree = "<group>"; };
......@@ -1745,6 +1757,10 @@
children = (
A70456AE1427FB030037DA68 /* AllocationSpace.cpp */,
A70456AF1427FB150037DA68 /* AllocationSpace.h */,
C2C8D02E14A3CEFC00578E65 /* BumpBlock.h */,
C240305314B404C90079EB64 /* BumpSpace.cpp */,
C2EAA3F8149A830800FCE112 /* BumpSpace.h */,
C2C8D02B14A3C6B200578E65 /* BumpSpaceInlineMethods.h */,
A7521E121429169A003C8D0C /* CardSet.h */,
146B14DB12EB5B12001BEC1B /* ConservativeRoots.cpp */,
149DAAF212EB559D0083B12B /* ConservativeRoots.h */,
......@@ -1758,6 +1774,7 @@
146FA5A81378F6B0003627A3 /* HandleTypes.h */,
14BA7A9513AADFF8005B7C2C /* Heap.cpp */,
14BA7A9613AADFF8005B7C2C /* Heap.h */,
C2C8D02F14A3CEFC00578E65 /* HeapBlock.h */,
14F97446138C853E00DA1C67 /* HeapRootVisitor.h */,
0F431736146BAC65007E3890 /* ListableHandler.h */,
142E3130134FF0A600AFADB5 /* Local.h */,
......@@ -2083,6 +2100,7 @@
96DD73780F9DA3100027FBCC /* VMTags.h */,
86D08D5111793613006E5ED0 /* WTFThreadData.cpp */,
86D08D5211793613006E5ED0 /* WTFThreadData.h */,
C2D9CA1214BCC04600304B46 /* CheckedBoolean.h */,
);
path = wtf;
sourceTree = "<group>";
......@@ -2613,6 +2631,7 @@
86D3B2C410156BDE002865E7 /* ARMAssembler.h in Headers */,
86ADD1450FDDEA980006EEC2 /* ARMv7Assembler.h in Headers */,
A73BE169148420520091204B /* ArrayBuffer.h in Headers */,
C2D9CA1314BCC04600304B46 /* CheckedBoolean.h in Headers */,
A73BE16B148420520091204B /* ArrayBufferView.h in Headers */,
BC18C3E60E16F5CD00B34460 /* ArrayConstructor.h in Headers */,
BC18C3E70E16F5CD00B34460 /* ArrayPrototype.h in Headers */,
......@@ -2639,7 +2658,10 @@
E4D8CEFB12FC439600BC9F5A /* BloomFilter.h in Headers */,
BC18C3EC0E16F5CD00B34460 /* BooleanObject.h in Headers */,
0FD82E85141F3FE300179C94 /* BoundsCheckedPointer.h in Headers */,
C2C8D03014A3CEFC00578E65 /* BumpBlock.h in Headers */,
86676D5211FED9BC004B6863 /* BumpPointerAllocator.h in Headers */,
C2EAA3FA149A835E00FCE112 /* BumpSpace.h in Headers */,
C2C8D02D14A3C6E000578E65 /* BumpSpaceInlineMethods.h in Headers */,
A7A1F7AD0F252B3C00E184E2 /* ByteArray.h in Headers */,
969A07230ED1CE3300F1F681 /* BytecodeGenerator.h in Headers */,
C22C52F613FAF6EF00B7DC0D /* cached-powers.h in Headers */,
......@@ -2751,6 +2773,7 @@
BC18C40D0E16F5CD00B34460 /* HashTable.h in Headers */,
BC18C40E0E16F5CD00B34460 /* HashTraits.h in Headers */,
14BA7A9813AADFF8005B7C2C /* Heap.h in Headers */,
C2C8D03114A3CEFC00578E65 /* HeapBlock.h in Headers */,
14F97447138C853E00DA1C67 /* HeapRootVisitor.h in Headers */,
7186A6EC13100BA5004479E1 /* HexNumber.h in Headers */,
BC18C40F0E16F5CD00B34460 /* Identifier.h in Headers */,
......@@ -3373,6 +3396,7 @@
14280863107EC11A0013E7B2 /* BooleanConstructor.cpp in Sources */,
14280864107EC11A0013E7B2 /* BooleanObject.cpp in Sources */,
14280865107EC11A0013E7B2 /* BooleanPrototype.cpp in Sources */,
C240305514B404E60079EB64 /* BumpSpace.cpp in Sources */,
A7A1F7AC0F252B3C00E184E2 /* ByteArray.cpp in Sources */,
148F21AA107EC53A0042EC2C /* BytecodeGenerator.cpp in Sources */,
C22C52F513FAF6EF00B7DC0D /* cached-powers.cc in Sources */,
......
......@@ -62,6 +62,7 @@ SOURCES += \
bytecompiler/BytecodeGenerator.cpp \
bytecompiler/NodesCodegen.cpp \
heap/AllocationSpace.cpp \
heap/BumpSpace.cpp \
heap/ConservativeRoots.cpp \
heap/DFGCodeBlocks.cpp \
heap/HandleHeap.cpp \
......
......@@ -29,8 +29,6 @@
#include "Heap.h"
#define COLLECT_ON_EVERY_ALLOCATION 0
namespace JSC {
inline void* AllocationSpace::tryAllocate(MarkedSpace::SizeClass& sizeClass)
......@@ -59,7 +57,7 @@ void* AllocationSpace::allocateSlowCase(MarkedSpace::SizeClass& sizeClass)
#if ENABLE(GGC)
m_markedSpace.nurseryWaterMark() < m_heap->m_minBytesPerCycle
#else
m_markedSpace.waterMark() < m_markedSpace.highWaterMark()
m_heap->waterMark() < m_heap->highWaterMark()
#endif
) || !m_heap->m_isSafeToCollect)
allocationEffort = AllocationMustSucceed;
......@@ -81,7 +79,7 @@ void* AllocationSpace::allocateSlowCase(MarkedSpace::SizeClass& sizeClass)
if (result)
return result;
ASSERT(m_markedSpace.waterMark() < m_markedSpace.highWaterMark());
ASSERT(m_heap->waterMark() < m_heap->highWaterMark());
m_markedSpace.addBlock(sizeClass, allocateBlock(sizeClass.cellSize, AllocationMustSucceed));
......@@ -90,21 +88,21 @@ void* AllocationSpace::allocateSlowCase(MarkedSpace::SizeClass& sizeClass)
return result;
}
MarkedBlock* AllocationSpace::allocateBlock(size_t cellSize, AllocationSpace::AllocationEffort allocationEffort)
MarkedBlock* AllocationSpace::allocateBlock(size_t cellSize, AllocationEffort allocationEffort)
{
MarkedBlock* block;
{
MutexLocker locker(m_heap->m_freeBlockLock);
if (m_heap->m_numberOfFreeBlocks) {
block = m_heap->m_freeBlocks.removeHead();
block = static_cast<MarkedBlock*>(m_heap->m_freeBlocks.removeHead());
ASSERT(block);
m_heap->m_numberOfFreeBlocks--;
} else
block = 0;
}
if (block)
block = MarkedBlock::recycle(block, cellSize);
block = MarkedBlock::recycle(block, m_heap, cellSize);
else if (allocationEffort == AllocationCanFail)
return 0;
else
......@@ -119,7 +117,7 @@ void AllocationSpace::freeBlocks(MarkedBlock* head)
{
MarkedBlock* next;
for (MarkedBlock* block = head; block; block = next) {
next = block->next();
next = static_cast<MarkedBlock*>(block->next());
m_blocks.remove(block);
block->sweep();
......
......@@ -48,8 +48,7 @@ public:
MarkedBlockSet& blocks() { return m_blocks; }
MarkedSpace::SizeClass& sizeClassFor(size_t bytes) { return m_markedSpace.sizeClassFor(bytes); }
void setHighWaterMark(size_t bytes) { m_markedSpace.setHighWaterMark(bytes); }
size_t highWaterMark() { return m_markedSpace.highWaterMark(); }
size_t waterMark() { return m_markedSpace.waterMark(); }
#if ENABLE(GGC)
void gatherDirtyCells(MarkedBlock::DirtyCellVector&);
......@@ -68,8 +67,8 @@ public:
void shrink();
private:
enum AllocationEffort { AllocationMustSucceed, AllocationCanFail };
enum AllocationEffort { AllocationCanFail, AllocationMustSucceed };
void* allocate(MarkedSpace::SizeClass&);
void* tryAllocate(MarkedSpace::SizeClass&);
JS_EXPORT_PRIVATE void* allocateSlowCase(MarkedSpace::SizeClass&);
......
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* 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 BumpBlock_h
#define BumpBlock_h
#include "HeapBlock.h"
namespace JSC {
class BumpSpace;
class BumpBlock : public HeapBlock {
friend class BumpSpace;
public:
BumpBlock(PageAllocationAligned& allocation)
: HeapBlock(allocation)
, m_offset(m_payload)
, m_isPinned(false)
{
}
private:
void* m_offset;
uintptr_t m_isPinned;
char m_payload[1];
};
} // namespace JSC
#endif
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* 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.
*/
#include "config.h"
#include "BumpSpace.h"
#include "BumpSpaceInlineMethods.h"
namespace JSC {
CheckedBoolean BumpSpace::tryAllocateSlowCase(size_t bytes, void** outPtr)
{
if (isOversize(bytes))
return tryAllocateOversize(bytes, outPtr);
m_totalMemoryUtilized += static_cast<size_t>(static_cast<char*>(m_currentBlock->m_offset) - m_currentBlock->m_payload);
if (!addNewBlock()) {
*outPtr = 0;
return false;
}
m_toSpaceFilter.add(reinterpret_cast<Bits>(m_currentBlock));
m_toSpaceSet.add(m_currentBlock);
*outPtr = allocateFromBlock(m_currentBlock, bytes);
return true;
}
} // namespace JSC
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* 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 BumpSpace_h
#define BumpSpace_h
#include "TinyBloomFilter.h"
#include <wtf/Assertions.h>
#include <wtf/CheckedBoolean.h>
#include <wtf/DoublyLinkedList.h>
#include <wtf/HashSet.h>
#include <wtf/OSAllocator.h>
#include <wtf/PageAllocationAligned.h>
#include <wtf/StdLibExtras.h>
#include <wtf/ThreadingPrimitives.h>
namespace JSC {
class Heap;
class BumpBlock;
class HeapBlock;
class BumpSpace {
friend class SlotVisitor;