/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#ifndef CopyWorkList_h
#define CopyWorkList_h
+#include "CopyToken.h"
+#include <wtf/DoublyLinkedList.h>
#include <wtf/Vector.h>
namespace JSC {
class JSCell;
-class CopyWorkListSegment : public HeapBlock<CopyWorkListSegment> {
+class CopyWorklistItem {
public:
- static CopyWorkListSegment* create(DeadBlock* block)
+ CopyWorklistItem()
+ : m_value(0)
{
- return new (NotNull, block) CopyWorkListSegment(block->region());
+ }
+
+ CopyWorklistItem(JSCell* cell, CopyToken token)
+ : m_value(bitwise_cast<uintptr_t>(cell) | static_cast<uintptr_t>(token))
+ {
+ ASSERT(!(bitwise_cast<uintptr_t>(cell) & static_cast<uintptr_t>(mask)));
+ ASSERT(static_cast<uintptr_t>(token) <= mask);
+ }
+
+ JSCell* cell() const { return bitwise_cast<JSCell*>(m_value & ~static_cast<uintptr_t>(mask)); }
+ CopyToken token() const { return static_cast<CopyToken>(m_value & mask); }
+
+private:
+ static const unsigned requiredAlignment = 8;
+ static const unsigned mask = requiredAlignment - 1;
+
+ uintptr_t m_value;
+};
+
+class CopyWorkListSegment : public DoublyLinkedListNode<CopyWorkListSegment> {
+ friend class WTF::DoublyLinkedListNode<CopyWorkListSegment>;
+public:
+ static CopyWorkListSegment* create()
+ {
+ return new (NotNull, fastMalloc(blockSize)) CopyWorkListSegment();
+ }
+
+ static void destroy(CopyWorkListSegment* segment)
+ {
+ segment->~CopyWorkListSegment();
+ fastFree(segment);
}
size_t size() { return m_size; }
bool isFull() { return reinterpret_cast<char*>(&data()[size()]) >= endOfBlock(); }
- JSCell* get(size_t index) { return data()[index]; }
+ CopyWorklistItem get(size_t index) { return data()[index]; }
- void append(JSCell* cell)
+ void append(CopyWorklistItem item)
{
ASSERT(!isFull());
- data()[m_size] = cell;
+ data()[m_size] = item;
m_size += 1;
}
static const size_t blockSize = 512;
private:
- CopyWorkListSegment(Region* region)
- : HeapBlock<CopyWorkListSegment>(region)
+ CopyWorkListSegment()
+ : DoublyLinkedListNode<CopyWorkListSegment>()
, m_size(0)
{
}
- JSCell** data() { return reinterpret_cast<JSCell**>(this + 1); }
+ CopyWorklistItem* data() { return reinterpret_cast<CopyWorklistItem*>(this + 1); }
char* endOfBlock() { return reinterpret_cast<char*>(this) + blockSize; }
+ CopyWorkListSegment* m_prev;
+ CopyWorkListSegment* m_next;
size_t m_size;
};
class CopyWorkListIterator {
friend class CopyWorkList;
public:
- JSCell* get() { return m_currentSegment->get(m_currentIndex); }
- JSCell* operator*() { return get(); }
- JSCell* operator->() { return get(); }
+ CopyWorklistItem get() { return m_currentSegment->get(m_currentIndex); }
+ CopyWorklistItem operator*() { return get(); }
+ CopyWorklistItem operator->() { return get(); }
CopyWorkListIterator& operator++()
{
};
class CopyWorkList {
+ WTF_MAKE_FAST_ALLOCATED;
public:
typedef CopyWorkListIterator iterator;
- CopyWorkList(BlockAllocator&);
+ CopyWorkList();
~CopyWorkList();
- void append(JSCell*);
+ void append(CopyWorklistItem);
iterator begin();
iterator end();
private:
DoublyLinkedList<CopyWorkListSegment> m_segments;
- BlockAllocator& m_blockAllocator;
};
-inline CopyWorkList::CopyWorkList(BlockAllocator& blockAllocator)
- : m_blockAllocator(blockAllocator)
+inline CopyWorkList::CopyWorkList()
{
}
inline CopyWorkList::~CopyWorkList()
{
while (!m_segments.isEmpty())
- m_blockAllocator.deallocate(CopyWorkListSegment::destroy(m_segments.removeHead()));
+ CopyWorkListSegment::destroy(m_segments.removeHead());
}
-inline void CopyWorkList::append(JSCell* cell)
+inline void CopyWorkList::append(CopyWorklistItem item)
{
if (m_segments.isEmpty() || m_segments.tail()->isFull())
- m_segments.append(CopyWorkListSegment::create(m_blockAllocator.allocate<CopyWorkListSegment>()));
+ m_segments.append(CopyWorkListSegment::create());
ASSERT(!m_segments.tail()->isFull());
- m_segments.tail()->append(cell);
+ m_segments.tail()->append(item);
}
inline CopyWorkList::iterator CopyWorkList::begin()