- Revision
- 133812
- Author
- mhahnenb...@apple.com
- Date
- 2012-11-07 15:34:30 -0800 (Wed, 07 Nov 2012)
Log Message
WeakBlocks should be HeapBlocks
https://bugs.webkit.org/show_bug.cgi?id=101411
Reviewed by Oliver Hunt.
Currently WeakBlocks use fastMalloc memory. They are very similar to the other HeapBlocks, however,
so we should change them to being allocated with the BlockAllocator.
* heap/BlockAllocator.cpp:
(JSC::BlockAllocator::BlockAllocator):
* heap/BlockAllocator.h: Added a new RegionSet for WeakBlocks.
(JSC):
(BlockAllocator):
(JSC::WeakBlock):
* heap/Heap.h: Friended WeakSet to allow access to the BlockAllocator.
(Heap):
* heap/WeakBlock.cpp:
(JSC::WeakBlock::create): Refactored to use HeapBlocks rather than fastMalloc.
(JSC::WeakBlock::WeakBlock):
* heap/WeakBlock.h: Changed the WeakBlock size to 4 KB so that it divides evenly into the Region size.
(JSC):
(WeakBlock):
* heap/WeakSet.cpp:
(JSC::WeakSet::~WeakSet):
(JSC::WeakSet::addAllocator):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (133811 => 133812)
--- trunk/Source/_javascript_Core/ChangeLog 2012-11-07 23:25:07 UTC (rev 133811)
+++ trunk/Source/_javascript_Core/ChangeLog 2012-11-07 23:34:30 UTC (rev 133812)
@@ -1,3 +1,31 @@
+2012-11-07 Mark Hahnenberg <mhahnenb...@apple.com>
+
+ WeakBlocks should be HeapBlocks
+ https://bugs.webkit.org/show_bug.cgi?id=101411
+
+ Reviewed by Oliver Hunt.
+
+ Currently WeakBlocks use fastMalloc memory. They are very similar to the other HeapBlocks, however,
+ so we should change them to being allocated with the BlockAllocator.
+
+ * heap/BlockAllocator.cpp:
+ (JSC::BlockAllocator::BlockAllocator):
+ * heap/BlockAllocator.h: Added a new RegionSet for WeakBlocks.
+ (JSC):
+ (BlockAllocator):
+ (JSC::WeakBlock):
+ * heap/Heap.h: Friended WeakSet to allow access to the BlockAllocator.
+ (Heap):
+ * heap/WeakBlock.cpp:
+ (JSC::WeakBlock::create): Refactored to use HeapBlocks rather than fastMalloc.
+ (JSC::WeakBlock::WeakBlock):
+ * heap/WeakBlock.h: Changed the WeakBlock size to 4 KB so that it divides evenly into the Region size.
+ (JSC):
+ (WeakBlock):
+ * heap/WeakSet.cpp:
+ (JSC::WeakSet::~WeakSet):
+ (JSC::WeakSet::addAllocator):
+
2012-11-07 Filip Pizlo <fpi...@apple.com>
Indentation of ArgList.h is wrong
Modified: trunk/Source/_javascript_Core/heap/BlockAllocator.cpp (133811 => 133812)
--- trunk/Source/_javascript_Core/heap/BlockAllocator.cpp 2012-11-07 23:25:07 UTC (rev 133811)
+++ trunk/Source/_javascript_Core/heap/BlockAllocator.cpp 2012-11-07 23:34:30 UTC (rev 133812)
@@ -28,6 +28,7 @@
#include "CopiedBlock.h"
#include "MarkedBlock.h"
+#include "WeakBlock.h"
#include <wtf/CurrentTime.h>
namespace JSC {
@@ -35,6 +36,7 @@
BlockAllocator::BlockAllocator()
: m_copiedRegionSet(CopiedBlock::blockSize)
, m_markedRegionSet(MarkedBlock::blockSize)
+ , m_weakRegionSet(WeakBlock::blockSize)
, m_numberOfEmptyRegions(0)
, m_isCurrentlyAllocating(false)
, m_blockFreeingThreadShouldQuit(false)
Modified: trunk/Source/_javascript_Core/heap/BlockAllocator.h (133811 => 133812)
--- trunk/Source/_javascript_Core/heap/BlockAllocator.h 2012-11-07 23:25:07 UTC (rev 133811)
+++ trunk/Source/_javascript_Core/heap/BlockAllocator.h 2012-11-07 23:34:30 UTC (rev 133812)
@@ -39,6 +39,7 @@
class CopiedBlock;
class MarkedBlock;
class Region;
+class WeakBlock;
// Simple allocator to reduce VM cost by holding onto blocks of memory for
// short periods of time and then freeing them on a secondary thread.
@@ -184,6 +185,7 @@
RegionSet m_copiedRegionSet;
RegionSet m_markedRegionSet;
+ RegionSet m_weakRegionSet;
DoublyLinkedList<Region> m_emptyRegions;
size_t m_numberOfEmptyRegions;
@@ -311,6 +313,12 @@
}
template <>
+inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor<WeakBlock>()
+{
+ return m_weakRegionSet;
+}
+
+template <>
inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor<HeapBlock<CopiedBlock> >()
{
return m_copiedRegionSet;
@@ -322,6 +330,12 @@
return m_markedRegionSet;
}
+template <>
+inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor<HeapBlock<WeakBlock> >()
+{
+ return m_weakRegionSet;
+}
+
template <typename T>
inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor()
{
Modified: trunk/Source/_javascript_Core/heap/Heap.h (133811 => 133812)
--- trunk/Source/_javascript_Core/heap/Heap.h 2012-11-07 23:25:07 UTC (rev 133811)
+++ trunk/Source/_javascript_Core/heap/Heap.h 2012-11-07 23:34:30 UTC (rev 133812)
@@ -188,6 +188,7 @@
friend class SlotVisitor;
friend class IncrementalSweeper;
friend class HeapStatistics;
+ friend class WeakSet;
template<typename T> friend void* allocateCell(Heap&);
template<typename T> friend void* allocateCell(Heap&, size_t);
Modified: trunk/Source/_javascript_Core/heap/WeakBlock.cpp (133811 => 133812)
--- trunk/Source/_javascript_Core/heap/WeakBlock.cpp 2012-11-07 23:25:07 UTC (rev 133811)
+++ trunk/Source/_javascript_Core/heap/WeakBlock.cpp 2012-11-07 23:34:30 UTC (rev 133812)
@@ -34,19 +34,15 @@
namespace JSC {
-WeakBlock* WeakBlock::create()
+WeakBlock* WeakBlock::create(DeadBlock* block)
{
- void* allocation = fastMalloc(blockSize);
- return new (NotNull, allocation) WeakBlock;
+ Region* region = block->region();
+ return new (NotNull, block) WeakBlock(region);
}
-void WeakBlock::destroy(WeakBlock* block)
+WeakBlock::WeakBlock(Region* region)
+ : HeapBlock<WeakBlock>(region)
{
- fastFree(block);
-}
-
-WeakBlock::WeakBlock()
-{
for (size_t i = 0; i < weakImplCount(); ++i) {
WeakImpl* weakImpl = &weakImpls()[i];
new (NotNull, weakImpl) WeakImpl;
Modified: trunk/Source/_javascript_Core/heap/WeakBlock.h (133811 => 133812)
--- trunk/Source/_javascript_Core/heap/WeakBlock.h 2012-11-07 23:25:07 UTC (rev 133811)
+++ trunk/Source/_javascript_Core/heap/WeakBlock.h 2012-11-07 23:34:30 UTC (rev 133812)
@@ -34,14 +34,15 @@
namespace JSC {
+class DeadBlock;
class HeapRootVisitor;
class JSValue;
class WeakHandleOwner;
-class WeakBlock : public DoublyLinkedListNode<WeakBlock> {
+class WeakBlock : public HeapBlock<WeakBlock> {
public:
friend class WTF::DoublyLinkedListNode<WeakBlock>;
- static const size_t blockSize = 3 * KB; // 5% of MarkedBlock size
+ static const size_t blockSize = 4 * KB; // 5% of MarkedBlock size
struct FreeCell {
FreeCell* next;
@@ -55,8 +56,7 @@
FreeCell* freeList;
};
- static WeakBlock* create();
- static void destroy(WeakBlock*);
+ static WeakBlock* create(DeadBlock*);
static WeakImpl* asWeakImpl(FreeCell*);
@@ -73,15 +73,13 @@
private:
static FreeCell* asFreeCell(WeakImpl*);
- WeakBlock();
+ WeakBlock(Region*);
WeakImpl* firstWeakImpl();
void finalize(WeakImpl*);
WeakImpl* weakImpls();
size_t weakImplCount();
void addToFreeList(FreeCell**, WeakImpl*);
- WeakBlock* m_prev;
- WeakBlock* m_next;
SweepResult m_sweepResult;
};
Modified: trunk/Source/_javascript_Core/heap/WeakSet.cpp (133811 => 133812)
--- trunk/Source/_javascript_Core/heap/WeakSet.cpp 2012-11-07 23:25:07 UTC (rev 133811)
+++ trunk/Source/_javascript_Core/heap/WeakSet.cpp 2012-11-07 23:34:30 UTC (rev 133812)
@@ -36,7 +36,7 @@
WeakBlock* next = 0;
for (WeakBlock* block = m_blocks.head(); block; block = next) {
next = block->next();
- WeakBlock::destroy(block);
+ heap()->blockAllocator().deallocate(WeakBlock::destroy(block));
}
m_blocks.clear();
}
@@ -73,7 +73,7 @@
WeakBlock::FreeCell* WeakSet::addAllocator()
{
- WeakBlock* block = WeakBlock::create();
+ WeakBlock* block = WeakBlock::create(heap()->blockAllocator().allocate<WeakBlock>());
heap()->didAllocate(WeakBlock::blockSize);
m_blocks.append(block);
WeakBlock::SweepResult sweepResult = block->takeSweepResult();