Ignore:
Timestamp:
Mar 24, 2013, 3:45:36 PM (12 years ago)
Author:
[email protected]
Message:

HandleSet should use HeapBlocks for storing handles
https://bugs.webkit.org/show_bug.cgi?id=113145

Reviewed by Geoffrey Garen.

  • GNUmakefile.list.am: Build project changes.
  • JavaScriptCore.gypi: Ditto.
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: Ditto.
  • JavaScriptCore.vcxproj/JavaScriptCore.vcxproj: Ditto.
  • JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters: Ditto.
  • JavaScriptCore.xcodeproj/project.pbxproj: Ditto.
  • heap/BlockAllocator.cpp: Rename the RegionSet to m_fourKBBlockRegionSet because there are

too many block types to include them all in the name now.
(JSC::BlockAllocator::BlockAllocator):

  • heap/BlockAllocator.h:

(BlockAllocator): Add the appropriate override for regionSetFor.
(JSC::WeakBlock):
(JSC::MarkStackSegment):
(JSC::HandleBlock):

  • heap/HandleBlock.h: Added.

(HandleBlock): New class for HandleBlocks.
(JSC::HandleBlock::blockFor): Static method to get the block of the given HandleNode pointer. Allows
us to quickly figure out which HandleSet the HandleNode belongs to without storing the pointer to it
in the HandleNode.
(JSC::HandleBlock::handleSet): Getter.

  • heap/HandleBlockInlines.h: Added.

(JSC::HandleBlock::create):
(JSC::HandleBlock::HandleBlock):
(JSC::HandleBlock::payloadEnd):
(JSC::HandleBlock::payload):
(JSC::HandleBlock::nodes):
(JSC::HandleBlock::nodeAtIndex):
(JSC::HandleBlock::nodeCapacity):

  • heap/HandleSet.cpp:

(JSC::HandleSet::~HandleSet):
(JSC::HandleSet::grow):

  • heap/HandleSet.h:

(HandleNode): Move the internal Node class from HandleSet to be its own public class so it can be
used by HandleBlock.
(HandleSet): Add a typedef so that Node refers to the new HandleNode class.
(JSC::HandleSet::toHandle):
(JSC::HandleSet::toNode):
(JSC::HandleSet::allocate):
(JSC::HandleSet::deallocate):
(JSC::HandleNode::HandleNode):
(JSC::HandleNode::slot):
(JSC::HandleNode::handleSet): Use the new blockFor static function to get the right HandleBlock and lookup
the HandleSet.
(JSC::HandleNode::setPrev):
(JSC::HandleNode::prev):
(JSC::HandleNode::setNext):
(JSC::HandleNode::next):
(JSC::HandleSet::forEachStrongHandle):

  • heap/Heap.h: Friend HandleSet so that it can access the BlockAllocator when allocating HandleBlocks.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/heap/HandleSet.h

    r140584 r146734  
    2727#define HandleSet_h
    2828
    29 #include <wtf/BlockStack.h>
    3029#include "Handle.h"
     30#include "HandleBlock.h"
     31#include <wtf/DoublyLinkedList.h>
    3132#include <wtf/HashCountedSet.h>
    3233#include <wtf/SentinelLinkedList.h>
     
    3536namespace JSC {
    3637
     38class HandleBlock;
    3739class HandleSet;
    3840class HeapRootVisitor;
     
    4143class SlotVisitor;
    4244
     45class HandleNode {
     46public:
     47    HandleNode(WTF::SentinelTag);
     48    HandleNode();
     49   
     50    HandleSlot slot();
     51    HandleSet* handleSet();
     52
     53    void setPrev(HandleNode*);
     54    HandleNode* prev();
     55
     56    void setNext(HandleNode*);
     57    HandleNode* next();
     58
     59private:
     60    JSValue m_value;
     61    HandleNode* m_prev;
     62    HandleNode* m_next;
     63};
     64
    4365class HandleSet {
     66    friend class HandleBlock;
    4467public:
    4568    static HandleSet* heapFor(HandleSlot);
    4669
    4770    HandleSet(JSGlobalData*);
    48    
     71    ~HandleSet();
     72
    4973    JSGlobalData* globalData();
    5074
     
    6185
    6286private:
    63     class Node {
    64     public:
    65         Node(WTF::SentinelTag);
    66         Node(HandleSet*);
    67        
    68         HandleSlot slot();
    69         HandleSet* handleSet();
    70 
    71         void setPrev(Node*);
    72         Node* prev();
    73 
    74         void setNext(Node*);
    75         Node* next();
    76 
    77     private:
    78         JSValue m_value;
    79         HandleSet* m_handleSet;
    80         Node* m_prev;
    81         Node* m_next;
    82     };
    83 
     87    typedef HandleNode Node;
    8488    static HandleSlot toHandle(Node*);
    8589    static Node* toNode(HandleSlot);
     
    9296
    9397    JSGlobalData* m_globalData;
    94     BlockStack<Node> m_blockStack;
     98    DoublyLinkedList<HandleBlock> m_blockList;
    9599
    96100    SentinelLinkedList<Node> m_strongList;
     
    110114}
    111115
    112 inline HandleSlot HandleSet::toHandle(Node* node)
     116inline HandleSlot HandleSet::toHandle(HandleSet::Node* node)
    113117{
    114118    return reinterpret_cast<HandleSlot>(node);
     
    117121inline HandleSet::Node* HandleSet::toNode(HandleSlot handle)
    118122{
    119     return reinterpret_cast<Node*>(handle);
     123    return reinterpret_cast<HandleSet::Node*>(handle);
    120124}
    121125
     
    129133        grow();
    130134
    131     Node* node = m_freeList.pop();
    132     new (NotNull, node) Node(this);
     135    HandleSet::Node* node = m_freeList.pop();
     136    new (NotNull, node) HandleSet::Node();
    133137    m_immediateList.push(node);
    134138    return toHandle(node);
     
    137141inline void HandleSet::deallocate(HandleSlot handle)
    138142{
    139     Node* node = toNode(handle);
     143    HandleSet::Node* node = toNode(handle);
    140144    if (node == m_nextToFinalize) {
    141145        ASSERT(m_nextToFinalize->next());
     
    143147    }
    144148
    145     SentinelLinkedList<Node>::remove(node);
     149    SentinelLinkedList<HandleSet::Node>::remove(node);
    146150    m_freeList.push(node);
    147151}
    148152
    149 inline HandleSet::Node::Node(HandleSet* handleSet)
    150     : m_handleSet(handleSet)
    151     , m_prev(0)
     153inline HandleNode::HandleNode()
     154    : m_prev(0)
    152155    , m_next(0)
    153156{
    154157}
    155158
    156 inline HandleSet::Node::Node(WTF::SentinelTag)
    157     : m_handleSet(0)
    158     , m_prev(0)
     159inline HandleNode::HandleNode(WTF::SentinelTag)
     160    : m_prev(0)
    159161    , m_next(0)
    160162{
    161163}
    162164
    163 inline HandleSlot HandleSet::Node::slot()
     165inline HandleSlot HandleNode::slot()
    164166{
    165167    return &m_value;
    166168}
    167169
    168 inline HandleSet* HandleSet::Node::handleSet()
    169 {
    170     return m_handleSet;
    171 }
    172 
    173 inline void HandleSet::Node::setPrev(Node* prev)
     170inline HandleSet* HandleNode::handleSet()
     171{
     172    return HandleBlock::blockFor(this)->handleSet();
     173}
     174
     175inline void HandleNode::setPrev(HandleNode* prev)
    174176{
    175177    m_prev = prev;
    176178}
    177179
    178 inline HandleSet::Node* HandleSet::Node::prev()
     180inline HandleNode* HandleNode::prev()
    179181{
    180182    return m_prev;
    181183}
    182184
    183 inline void HandleSet::Node::setNext(Node* next)
     185inline void HandleNode::setNext(HandleNode* next)
    184186{
    185187    m_next = next;
    186188}
    187189
    188 inline HandleSet::Node* HandleSet::Node::next()
     190inline HandleNode* HandleNode::next()
    189191{
    190192    return m_next;
     
    193195template<typename Functor> void HandleSet::forEachStrongHandle(Functor& functor, const HashCountedSet<JSCell*>& skipSet)
    194196{
    195     Node* end = m_strongList.end();
    196     for (Node* node = m_strongList.begin(); node != end; node = node->next()) {
     197    HandleSet::Node* end = m_strongList.end();
     198    for (HandleSet::Node* node = m_strongList.begin(); node != end; node = node->next()) {
    197199        JSValue value = *node->slot();
    198200        if (!value || !value.isCell())
Note: See TracChangeset for help on using the changeset viewer.