summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/heap/CopiedBlock.h
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-10-15 16:08:57 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2012-10-15 16:08:57 +0200
commit5466563f4b5b6b86523e3f89bb7f77e5b5270c78 (patch)
tree8caccf7cd03a15207cde3ba282c88bf132482a91 /Source/JavaScriptCore/heap/CopiedBlock.h
parent33b26980cb24288b5a9f2590ccf32a949281bb79 (diff)
downloadqtwebkit-5466563f4b5b6b86523e3f89bb7f77e5b5270c78.tar.gz
Imported WebKit commit 0dc6cd75e1d4836eaffbb520be96fac4847cc9d2 (http://svn.webkit.org/repository/webkit/trunk@131300)
WebKit update which introduces the QtWebKitWidgets module that contains the WK1 widgets based API. (In fact it renames QtWebKit to QtWebKitWidgets while we're working on completing the entire split as part of https://bugs.webkit.org/show_bug.cgi?id=99314
Diffstat (limited to 'Source/JavaScriptCore/heap/CopiedBlock.h')
-rw-r--r--Source/JavaScriptCore/heap/CopiedBlock.h92
1 files changed, 79 insertions, 13 deletions
diff --git a/Source/JavaScriptCore/heap/CopiedBlock.h b/Source/JavaScriptCore/heap/CopiedBlock.h
index ad5dbb46b..eb57efca2 100644
--- a/Source/JavaScriptCore/heap/CopiedBlock.h
+++ b/Source/JavaScriptCore/heap/CopiedBlock.h
@@ -26,9 +26,12 @@
#ifndef CopiedBlock_h
#define CopiedBlock_h
+#include "BlockAllocator.h"
#include "HeapBlock.h"
#include "JSValue.h"
#include "JSValueInlineMethods.h"
+#include "Options.h"
+#include <wtf/Atomics.h>
namespace JSC {
@@ -38,8 +41,17 @@ class CopiedBlock : public HeapBlock<CopiedBlock> {
friend class CopiedSpace;
friend class CopiedAllocator;
public:
- static CopiedBlock* create(const PageAllocationAligned&);
- static CopiedBlock* createNoZeroFill(const PageAllocationAligned&);
+ static CopiedBlock* create(DeadBlock*);
+ static CopiedBlock* createNoZeroFill(DeadBlock*);
+
+ bool isPinned();
+
+ unsigned liveBytes();
+ void reportLiveBytes(unsigned);
+ void didSurviveGC();
+ bool didEvacuateBytes(unsigned);
+ bool shouldEvacuate();
+ bool canBeRecycled();
// The payload is the region of the block that is usable for allocations.
char* payload();
@@ -60,24 +72,28 @@ public:
size_t size();
size_t capacity();
+ static const size_t blockSize = 64 * KB;
+
private:
- CopiedBlock(const PageAllocationAligned&);
+ CopiedBlock(Region*);
void zeroFillWilderness(); // Can be called at any time to zero-fill to the end of the block.
size_t m_remaining;
uintptr_t m_isPinned;
+ unsigned m_liveBytes;
};
-inline CopiedBlock* CopiedBlock::createNoZeroFill(const PageAllocationAligned& allocation)
+inline CopiedBlock* CopiedBlock::createNoZeroFill(DeadBlock* block)
{
- return new(NotNull, allocation.base()) CopiedBlock(allocation);
+ Region* region = block->region();
+ return new(NotNull, block) CopiedBlock(region);
}
-inline CopiedBlock* CopiedBlock::create(const PageAllocationAligned& allocation)
+inline CopiedBlock* CopiedBlock::create(DeadBlock* block)
{
- CopiedBlock* block = createNoZeroFill(allocation);
- block->zeroFillWilderness();
- return block;
+ CopiedBlock* newBlock = createNoZeroFill(block);
+ newBlock->zeroFillWilderness();
+ return newBlock;
}
inline void CopiedBlock::zeroFillWilderness()
@@ -92,14 +108,64 @@ inline void CopiedBlock::zeroFillWilderness()
#endif
}
-inline CopiedBlock::CopiedBlock(const PageAllocationAligned& allocation)
- : HeapBlock<CopiedBlock>(allocation)
+inline CopiedBlock::CopiedBlock(Region* region)
+ : HeapBlock<CopiedBlock>(region)
, m_remaining(payloadCapacity())
, m_isPinned(false)
+ , m_liveBytes(0)
{
ASSERT(is8ByteAligned(reinterpret_cast<void*>(m_remaining)));
}
+inline void CopiedBlock::reportLiveBytes(unsigned bytes)
+{
+ unsigned oldValue = 0;
+ unsigned newValue = 0;
+ do {
+ oldValue = m_liveBytes;
+ newValue = oldValue + bytes;
+ } while (!WTF::weakCompareAndSwap(&m_liveBytes, oldValue, newValue));
+}
+
+inline void CopiedBlock::didSurviveGC()
+{
+ m_liveBytes = 0;
+ m_isPinned = false;
+}
+
+inline bool CopiedBlock::didEvacuateBytes(unsigned bytes)
+{
+ ASSERT(m_liveBytes >= bytes);
+ unsigned oldValue = 0;
+ unsigned newValue = 0;
+ do {
+ oldValue = m_liveBytes;
+ newValue = oldValue - bytes;
+ } while (!WTF::weakCompareAndSwap(&m_liveBytes, oldValue, newValue));
+ ASSERT(m_liveBytes < oldValue);
+ return !newValue;
+}
+
+inline bool CopiedBlock::canBeRecycled()
+{
+ return !m_liveBytes;
+}
+
+inline bool CopiedBlock::shouldEvacuate()
+{
+ return static_cast<double>(m_liveBytes) / static_cast<double>(payloadCapacity()) <= Options::minCopiedBlockUtilization();
+}
+
+inline bool CopiedBlock::isPinned()
+{
+ return m_isPinned;
+}
+
+inline unsigned CopiedBlock::liveBytes()
+{
+ return m_liveBytes;
+}
+
inline char* CopiedBlock::payload()
{
return reinterpret_cast<char*>(this) + ((sizeof(CopiedBlock) + 7) & ~7);
@@ -107,7 +173,7 @@ inline char* CopiedBlock::payload()
inline char* CopiedBlock::payloadEnd()
{
- return reinterpret_cast<char*>(this) + allocation().size();
+ return reinterpret_cast<char*>(this) + region()->blockSize();
}
inline size_t CopiedBlock::payloadCapacity()
@@ -152,7 +218,7 @@ inline size_t CopiedBlock::size()
inline size_t CopiedBlock::capacity()
{
- return allocation().size();
+ return region()->blockSize();
}
} // namespace JSC