Changeset 43479 in webkit for trunk/JavaScriptCore/parser/Nodes.h


Ignore:
Timestamp:
May 10, 2009, 9:30:14 PM (16 years ago)
Author:
Darin Adler
Message:

2009-05-10 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Bug 25674: syntax tree nodes should use arena allocation
https://bugs.webkit.org/show_bug.cgi?id=25674

Part two: Remove reference counting from most nodes.

  • JavaScriptCore.xcodeproj/project.pbxproj: Added ParserArena.h and .cpp.
  • parser/Grammar.y: Replaced uses of ParserRefCountedData with uses of ParserArenaData. Took out now-nonfunctional code that tries to manually release declaration list. Changed the new calls that create FuncDeclNode and FuncExprNode so that they use the proper version of operator new for the reference-counted idiom, not the deletion idiom.
  • parser/NodeConstructors.h: (JSC::ParserArenaDeletable::operator new): Added. (JSC::ParserArenaRefCounted::ParserArenaRefCounted): Added. (JSC::Node::Node): Removed ParserRefCounted initializer. (JSC::ElementNode::ElementNode): Ditto. (JSC::PropertyNode::PropertyNode): Ditto. (JSC::ArgumentsNode::ArgumentsNode): Ditto. (JSC::SourceElements::SourceElements): Ditto. (JSC::ParameterNode::ParameterNode): Ditto. (JSC::FuncExprNode::FuncExprNode): Added ParserArenaRefCounted initializer. (JSC::FuncDeclNode::FuncDeclNode): Ditto. (JSC::CaseClauseNode::CaseClauseNode): Removed ParserRefCounted initializer. (JSC::ClauseListNode::ClauseListNode): Ditto. (JSC::CaseBlockNode::CaseBlockNode): Ditto.
  • parser/NodeInfo.h: Replaced uses of ParserRefCountedData with uses of ParserArenaData.
  • parser/Nodes.cpp: (JSC::ScopeNode::ScopeNode): Added ParserArenaRefCounted initializer. (JSC::ProgramNode::create): Use the proper version of operator new for the reference-counted idiom, not the deletion idiom. Use the arena contains function instead of the vecctor find function. (JSC::EvalNode::create): Use the proper version of operator new for the reference-counted idiom, not the deletion idiom. Use the arena reset function instead of the vector shrink function. (JSC::FunctionBodyNode::createNativeThunk): Use the proper version of operator new for the reference-counted idiom, not the deletion idiom. (JSC::FunctionBodyNode::create): More of the same.
  • parser/Nodes.h: Added ParserArenaDeletable and ParserArenaRefCounted to replace ParserRefCounted. Fixed inheritance so only the classes that need reference counting inherit from ParserArenaRefCounted.
  • parser/Parser.cpp: (JSC::Parser::parse): Set m_sourceElements to 0 since it now starts uninitialized. Just set it to 0 again in the failure case, since it's now just a raw pointer, not an owning one. (JSC::Parser::reparseInPlace): Removed now-unneeded get() function. (JSC::Parser::didFinishParsing): Replaced uses of ParserRefCountedData with uses of ParserArenaData.
  • parser/Parser.h: Less RefPtr, more arena.
  • parser/ParserArena.cpp: Added.
  • parser/ParserArena.h: Added.
  • runtime/JSGlobalData.cpp: (JSC::JSGlobalData::~JSGlobalData): Removed arena-related code, since it's now in the Parser. (JSC::JSGlobalData::createLeaked): Removed unneeded #ifndef. (JSC::JSGlobalData::createNativeThunk): Tweaked #if a bit.
  • runtime/JSGlobalData.h: Removed parserArena, which is now in Parser.
  • wtf/RefCounted.h: Added deletionHasBegun function, for use in assertions to catch deletion not done by the deref function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/parser/Nodes.h

    r43471 r43479  
    3030#include "JITCode.h"
    3131#include "Opcode.h"
     32#include "ParserArena.h"
    3233#include "ResultType.h"
    3334#include "SourceCode.h"
     
    102103    };
    103104
    104     class ParserRefCounted : public RefCounted<ParserRefCounted> {
     105    class ParserArenaDeletable {
    105106    protected:
    106         ParserRefCounted(JSGlobalData*);
    107 
    108     public:
    109         virtual ~ParserRefCounted();
    110 
    111         // Placeholder: To be changed to arena allocation.
    112         void* operator new(size_t size, JSGlobalData*) { return fastMalloc(size); }
    113 
    114     private:
     107        ParserArenaDeletable() { }
     108
     109    public:
     110        virtual ~ParserArenaDeletable() { }
     111
     112        // Objects created with this version of new are deleted when the arena is deleted.
     113        void* operator new(size_t, JSGlobalData*);
     114
     115        // Objects created with this version of new are not deleted when the arena is deleted.
     116        // Other arrangements must be made.
    115117        void* operator new(size_t);
    116118    };
    117119
    118 #ifdef NDEBUG
    119     inline ParserRefCounted::~ParserRefCounted()
    120     {
    121     }
    122 #endif
    123 
    124     class Node : public ParserRefCounted {
    125     public:
     120    class ParserArenaRefCounted : public RefCounted<ParserArenaRefCounted> {
     121    protected:
     122        ParserArenaRefCounted(JSGlobalData*);
     123
     124    public:
     125        virtual ~ParserArenaRefCounted()
     126        {
     127            ASSERT(deletionHasBegun());
     128        }
     129    };
     130
     131    class Node : public ParserArenaDeletable {
     132    protected:
    126133        Node(JSGlobalData*);
    127134
     135    public:
    128136        /*
    129137            Return value: The register holding the production's value.
     
    387395    };
    388396
    389     class ElementNode : public ParserRefCounted {
     397    class ElementNode : public ParserArenaDeletable {
    390398    public:
    391399        ElementNode(JSGlobalData*, int elision, ExpressionNode*);
     
    420428    };
    421429
    422     class PropertyNode : public ParserRefCounted {
     430    class PropertyNode : public ParserArenaDeletable {
    423431    public:
    424432        enum Type { Constant, Getter, Setter };
     
    505513    };
    506514
    507     class ArgumentsNode : public ParserRefCounted {
     515    class ArgumentsNode : public ParserArenaDeletable {
    508516    public:
    509517        ArgumentsNode(JSGlobalData*);
     
    11301138    typedef Vector<StatementNode*> StatementVector;
    11311139
    1132     class SourceElements : public ParserRefCounted {
     1140    class SourceElements : public ParserArenaDeletable {
    11331141    public:
    11341142        SourceElements(JSGlobalData*);
     
    13571365    };
    13581366
    1359     class ParameterNode : public ParserRefCounted {
     1367    class ParameterNode : public ParserArenaDeletable {
    13601368    public:
    13611369        ParameterNode(JSGlobalData*, const Identifier&);
     
    13691377        ParameterNode* m_next;
    13701378    };
    1371 
    1372     // Placholder. Later this will become a true arena.
    1373     typedef Vector<RefPtr<ParserRefCounted> > ParserArena;
    13741379
    13751380    struct ScopeNodeData {
     
    13881393    };
    13891394
    1390     class ScopeNode : public StatementNode {
     1395    class ScopeNode : public StatementNode, public ParserArenaRefCounted {
    13911396    public:
    13921397        typedef DeclarationStacks::VarStack VarStack;
     
    13981403        void adoptData(std::auto_ptr<ScopeNodeData> data)
    13991404        {
    1400             ASSERT(data->m_arena.find(this) == notFound);
     1405            ASSERT(!data->m_arena.contains(this));
    14011406            ASSERT(!m_data);
    14021407            m_data.adopt(data);
     
    15681573    };
    15691574
    1570     class FuncExprNode : public ExpressionNode {
     1575    class FuncExprNode : public ExpressionNode, public ParserArenaRefCounted {
    15711576    public:
    15721577        FuncExprNode(JSGlobalData*, const Identifier&, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter = 0);
     
    15851590    };
    15861591
    1587     class FuncDeclNode : public StatementNode {
     1592    class FuncDeclNode : public StatementNode, public ParserArenaRefCounted {
    15881593    public:
    15891594        FuncDeclNode(JSGlobalData*, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0);
     
    16011606    };
    16021607
    1603     class CaseClauseNode : public ParserRefCounted {
     1608    class CaseClauseNode : public ParserArenaDeletable {
    16041609    public:
    16051610        CaseClauseNode(JSGlobalData*, ExpressionNode*);
     
    16141619    };
    16151620
    1616     class ClauseListNode : public ParserRefCounted {
     1621    class ClauseListNode : public ParserArenaDeletable {
    16171622    public:
    16181623        ClauseListNode(JSGlobalData*, CaseClauseNode*);
     
    16271632    };
    16281633
    1629     class CaseBlockNode : public ParserRefCounted {
     1634    class CaseBlockNode : public ParserArenaDeletable {
    16301635    public:
    16311636        CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2);
Note: See TracChangeset for help on using the changeset viewer.