Commit 7bf9de1d authored by darin@apple.com's avatar darin@apple.com

2009-05-10 Darin Adler <darin@apple.com>

        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.exp: Updated.

        * 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.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@43479 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bea1fa03
2009-05-10 Darin Adler <darin@apple.com>
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.exp: Updated.
* 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.
2009-05-10 David Kilzer <ddkilzer@apple.com>
Part 2: Try to fix the Windows build by adding a symbol which is really just a re-mangling of a changed method signature
......@@ -107,6 +107,7 @@ __ZN3JSC11JSImmediate12toThisObjectENS_7JSValueEPNS_9ExecStateE
__ZN3JSC11JSImmediate8toObjectENS_7JSValueEPNS_9ExecStateE
__ZN3JSC11JSImmediate8toStringENS_7JSValueE
__ZN3JSC11JSImmediate9prototypeENS_7JSValueEPNS_9ExecStateE
__ZN3JSC11ParserArena5resetEv
__ZN3JSC11checkSyntaxEPNS_9ExecStateERKNS_10SourceCodeE
__ZN3JSC12DateInstance4infoE
__ZN3JSC12JSGlobalData10ClientDataD2Ev
......
......@@ -136,6 +136,8 @@
86EAC49C0F93E8D1008EC948 /* RegexPattern.h in Headers */ = {isa = PBXBuildFile; fileRef = 86EAC4940F93E8D1008EC948 /* RegexPattern.h */; };
905B02AE0E28640F006DF882 /* RefCountedLeakCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 905B02AD0E28640F006DF882 /* RefCountedLeakCounter.cpp */; };
90D3469C0E285280009492EE /* RefCountedLeakCounter.h in Headers */ = {isa = PBXBuildFile; fileRef = 90D3469B0E285280009492EE /* RefCountedLeakCounter.h */; settings = {ATTRIBUTES = (Private, ); }; };
93052C340FB792190048FDC3 /* ParserArena.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93052C320FB792190048FDC3 /* ParserArena.cpp */; };
93052C350FB792190048FDC3 /* ParserArena.h in Headers */ = {isa = PBXBuildFile; fileRef = 93052C330FB792190048FDC3 /* ParserArena.h */; settings = {ATTRIBUTES = (Private, ); }; };
930754C108B0F68000AB3056 /* pcre_compile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 930754BF08B0F68000AB3056 /* pcre_compile.cpp */; };
930754D008B0F74600AB3056 /* pcre_tables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 930754CE08B0F74500AB3056 /* pcre_tables.cpp */; };
930754EB08B0F78500AB3056 /* pcre_exec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 930754E908B0F78500AB3056 /* pcre_exec.cpp */; settings = {COMPILER_FLAGS = "-fno-move-loop-invariants"; }; };
......@@ -631,6 +633,8 @@
9303F567099118FA00AD71B8 /* OwnPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OwnPtr.h; sourceTree = "<group>"; };
9303F5690991190000AD71B8 /* Noncopyable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Noncopyable.h; sourceTree = "<group>"; };
9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OwnArrayPtr.h; sourceTree = "<group>"; };
93052C320FB792190048FDC3 /* ParserArena.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParserArena.cpp; sourceTree = "<group>"; };
93052C330FB792190048FDC3 /* ParserArena.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParserArena.h; sourceTree = "<group>"; };
930754BF08B0F68000AB3056 /* pcre_compile.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pcre_compile.cpp; sourceTree = "<group>"; tabWidth = 8; };
930754CE08B0F74500AB3056 /* pcre_tables.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pcre_tables.cpp; sourceTree = "<group>"; tabWidth = 8; };
930754E908B0F78500AB3056 /* pcre_exec.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pcre_exec.cpp; sourceTree = "<group>"; tabWidth = 8; };
......@@ -1256,6 +1260,8 @@
F692A86E0255597D01FF60F7 /* Nodes.h */,
93F0B3A909BB4DC00068FCE3 /* Parser.cpp */,
93F0B3AA09BB4DC00068FCE3 /* Parser.h */,
93052C320FB792190048FDC3 /* ParserArena.cpp */,
93052C330FB792190048FDC3 /* ParserArena.h */,
869EBCB60E8C6D4A008722CC /* ResultType.h */,
65E866EE0DD59AFA00A2B2A1 /* SourceCode.h */,
65E866ED0DD59AFA00A2B2A1 /* SourceProvider.h */,
......@@ -1803,6 +1809,7 @@
96DD73790F9DA3100027FBCC /* VMTags.h in Headers */,
A76EE6590FAE59D5003F069A /* NativeFunctionWrapper.h in Headers */,
A7E2EA6B0FB460CF00601F06 /* LiteralParser.h in Headers */,
93052C350FB792190048FDC3 /* ParserArena.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -2161,6 +2168,7 @@
86EAC4990F93E8D1008EC948 /* RegexJIT.cpp in Sources */,
86DB64640F95C6FC00D7D921 /* ExecutableAllocatorFixedVMPool.cpp in Sources */,
A7E2EA6C0FB460CF00601F06 /* LiteralParser.cpp in Sources */,
93052C340FB792190048FDC3 /* ParserArena.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
This diff is collapsed.
......@@ -26,19 +26,27 @@
namespace JSC {
#ifdef NDEBUG
inline ParserRefCounted::ParserRefCounted(JSGlobalData* globalData)
void* ParserArenaDeletable::operator new(size_t size, JSGlobalData* globalData)
{
globalData->parserArena.append(adoptRef(this));
ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(fastMalloc(size));
globalData->parser->arena().deleteWithArena(deletable);
return deletable;
}
#endif
inline Node::Node(JSGlobalData* globalData)
: ParserRefCounted(globalData)
, m_line(globalData->lexer->lineNumber())
void* ParserArenaDeletable::operator new(size_t size)
{
return fastMalloc(size);
}
inline ParserArenaRefCounted::ParserArenaRefCounted(JSGlobalData* globalData)
{
globalData->parser->arena().derefWithArena(adoptRef(this));
}
inline Node::Node(JSGlobalData* globalData)
: m_line(globalData->lexer->lineNumber())
{
}
inline ExpressionNode::ExpressionNode(JSGlobalData* globalData, ResultType resultType)
: Node(globalData)
......@@ -94,17 +102,15 @@ namespace JSC {
{
}
inline ElementNode::ElementNode(JSGlobalData* globalData, int elision, ExpressionNode* node)
: ParserRefCounted(globalData)
, m_next(0)
inline ElementNode::ElementNode(JSGlobalData*, int elision, ExpressionNode* node)
: m_next(0)
, m_elision(elision)
, m_node(node)
{
}
inline ElementNode::ElementNode(JSGlobalData* globalData, ElementNode* l, int elision, ExpressionNode* node)
: ParserRefCounted(globalData)
, m_next(0)
inline ElementNode::ElementNode(JSGlobalData*, ElementNode* l, int elision, ExpressionNode* node)
: m_next(0)
, m_elision(elision)
, m_node(node)
{
......@@ -135,9 +141,8 @@ namespace JSC {
{
}
inline PropertyNode::PropertyNode(JSGlobalData* globalData, const Identifier& name, ExpressionNode* assign, Type type)
: ParserRefCounted(globalData)
, m_name(name)
inline PropertyNode::PropertyNode(JSGlobalData*, const Identifier& name, ExpressionNode* assign, Type type)
: m_name(name)
, m_assign(assign)
, m_type(type)
{
......@@ -200,15 +205,13 @@ namespace JSC {
listNode->m_next = this;
}
inline ArgumentsNode::ArgumentsNode(JSGlobalData* globalData)
: ParserRefCounted(globalData)
, m_listNode(0)
inline ArgumentsNode::ArgumentsNode(JSGlobalData*)
: m_listNode(0)
{
}
inline ArgumentsNode::ArgumentsNode(JSGlobalData* globalData, ArgumentListNode* listNode)
: ParserRefCounted(globalData)
, m_listNode(listNode)
inline ArgumentsNode::ArgumentsNode(JSGlobalData*, ArgumentListNode* listNode)
: m_listNode(listNode)
{
}
......@@ -666,8 +669,7 @@ namespace JSC {
{
}
inline SourceElements::SourceElements(JSGlobalData* globalData)
: ParserRefCounted(globalData)
inline SourceElements::SourceElements(JSGlobalData*)
{
}
......@@ -791,24 +793,22 @@ namespace JSC {
{
}
inline ParameterNode::ParameterNode(JSGlobalData* globalData, const Identifier& ident)
: ParserRefCounted(globalData)
, m_ident(ident)
inline ParameterNode::ParameterNode(JSGlobalData*, const Identifier& ident)
: m_ident(ident)
, m_next(0)
{
}
inline ParameterNode::ParameterNode(JSGlobalData* globalData, ParameterNode* l, const Identifier& ident)
: ParserRefCounted(globalData)
, m_ident(ident)
inline ParameterNode::ParameterNode(JSGlobalData*, ParameterNode* l, const Identifier& ident)
: m_ident(ident)
, m_next(0)
{
l->m_next = this;
}
inline FuncExprNode::FuncExprNode(JSGlobalData* globalData, const Identifier& ident, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter)
: ExpressionNode(globalData)
, ParserArenaRefCounted(globalData)
, m_ident(ident)
, m_body(body)
{
......@@ -817,44 +817,40 @@ namespace JSC {
inline FuncDeclNode::FuncDeclNode(JSGlobalData* globalData, const Identifier& ident, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter)
: StatementNode(globalData)
, ParserArenaRefCounted(globalData)
, m_ident(ident)
, m_body(body)
{
m_body->finishParsing(source, parameter);
}
inline CaseClauseNode::CaseClauseNode(JSGlobalData* globalData, ExpressionNode* expr)
: ParserRefCounted(globalData)
, m_expr(expr)
inline CaseClauseNode::CaseClauseNode(JSGlobalData*, ExpressionNode* expr)
: m_expr(expr)
{
}
inline CaseClauseNode::CaseClauseNode(JSGlobalData* globalData, ExpressionNode* expr, SourceElements* children)
: ParserRefCounted(globalData)
, m_expr(expr)
inline CaseClauseNode::CaseClauseNode(JSGlobalData*, ExpressionNode* expr, SourceElements* children)
: m_expr(expr)
{
if (children)
children->releaseContentsIntoVector(m_children);
}
inline ClauseListNode::ClauseListNode(JSGlobalData* globalData, CaseClauseNode* clause)
: ParserRefCounted(globalData)
, m_clause(clause)
inline ClauseListNode::ClauseListNode(JSGlobalData*, CaseClauseNode* clause)
: m_clause(clause)
, m_next(0)
{
}
inline ClauseListNode::ClauseListNode(JSGlobalData* globalData, ClauseListNode* clauseList, CaseClauseNode* clause)
: ParserRefCounted(globalData)
, m_clause(clause)
inline ClauseListNode::ClauseListNode(JSGlobalData*, ClauseListNode* clauseList, CaseClauseNode* clause)
: m_clause(clause)
, m_next(0)
{
clauseList->m_next = this;
}
inline CaseBlockNode::CaseBlockNode(JSGlobalData* globalData, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2)
: ParserRefCounted(globalData)
, m_list1(list1)
inline CaseBlockNode::CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2)
: m_list1(list1)
, m_defaultClause(defaultClause)
, m_list2(list2)
{
......
......@@ -43,8 +43,8 @@ namespace JSC {
template <typename T> struct NodeDeclarationInfo {
T m_node;
ParserRefCountedData<DeclarationStacks::VarStack>* m_varDeclarations;
ParserRefCountedData<DeclarationStacks::FunctionStack>* m_funcDeclarations;
ParserArenaData<DeclarationStacks::VarStack>* m_varDeclarations;
ParserArenaData<DeclarationStacks::FunctionStack>* m_funcDeclarations;
CodeFeatures m_features;
int m_numConstants;
};
......
......@@ -51,25 +51,6 @@ namespace JSC {
static void substitute(UString& string, const UString& substring) JSC_FAST_CALL;
// ------------------------------ ParserRefCounted -----------------------------------------
#ifndef NDEBUG
static RefCountedLeakCounter parserRefCountedCounter("JSC::Node");
ALWAYS_INLINE ParserRefCounted::ParserRefCounted(JSGlobalData* globalData)
{
globalData->parserArena.append(adoptRef(this));
parserRefCountedCounter.increment();
}
ALWAYS_INLINE ParserRefCounted::~ParserRefCounted()
{
parserRefCountedCounter.decrement();
}
#endif
// ------------------------------ ThrowableExpressionData --------------------------------
static void substitute(UString& string, const UString& substring)
......@@ -1839,6 +1820,7 @@ void ScopeNodeData::mark()
ScopeNode::ScopeNode(JSGlobalData* globalData)
: StatementNode(globalData)
, ParserArenaRefCounted(globalData)
, m_features(NoFeatures)
{
#if ENABLE(CODEBLOCK_SAMPLING)
......@@ -1848,7 +1830,8 @@ ScopeNode::ScopeNode(JSGlobalData* globalData)
ScopeNode::ScopeNode(JSGlobalData* globalData, const SourceCode& source, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, CodeFeatures features, int numConstants)
: StatementNode(globalData)
, m_data(new ScopeNodeData(globalData->parserArena, children, varStack, funcStack, numConstants))
, ParserArenaRefCounted(globalData)
, m_data(new ScopeNodeData(globalData->parser->arena(), children, varStack, funcStack, numConstants))
, m_features(features)
, m_source(source)
{
......@@ -1866,11 +1849,11 @@ inline ProgramNode::ProgramNode(JSGlobalData* globalData, SourceElements* childr
PassRefPtr<ProgramNode> ProgramNode::create(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, const SourceCode& source, CodeFeatures features, int numConstants)
{
RefPtr<ProgramNode> node = new (globalData) ProgramNode(globalData, children, varStack, funcStack, source, features, numConstants);
RefPtr<ProgramNode> node = new ProgramNode(globalData, children, varStack, funcStack, source, features, numConstants);
ASSERT(node->data()->m_arena.last() == node);
node->data()->m_arena.removeLast();
ASSERT(node->data()->m_arena.find(node.get()) == notFound);
ASSERT(!node->data()->m_arena.contains(node.get()));
return node.release();
}
......@@ -1910,11 +1893,11 @@ inline EvalNode::EvalNode(JSGlobalData* globalData, SourceElements* children, Va
PassRefPtr<EvalNode> EvalNode::create(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, const SourceCode& source, CodeFeatures features, int numConstants)
{
RefPtr<EvalNode> node = new (globalData) EvalNode(globalData, children, varStack, funcStack, source, features, numConstants);
RefPtr<EvalNode> node = new EvalNode(globalData, children, varStack, funcStack, source, features, numConstants);
ASSERT(node->data()->m_arena.last() == node);
node->data()->m_arena.removeLast();
ASSERT(node->data()->m_arena.find(node.get()) == notFound);
ASSERT(!node->data()->m_arena.contains(node.get()));
return node.release();
}
......@@ -2025,8 +2008,8 @@ void FunctionBodyNode::mark()
#if ENABLE(JIT)
PassRefPtr<FunctionBodyNode> FunctionBodyNode::createNativeThunk(JSGlobalData* globalData)
{
RefPtr<FunctionBodyNode> body = new (globalData) FunctionBodyNode(globalData);
globalData->parserArena.shrink(0);
RefPtr<FunctionBodyNode> body = new FunctionBodyNode(globalData);
globalData->parser->arena().reset();
body->m_jitCode = globalData->jitStubs.ctiNativeCallThunk();
return body.release();
}
......@@ -2034,16 +2017,16 @@ PassRefPtr<FunctionBodyNode> FunctionBodyNode::createNativeThunk(JSGlobalData* g
FunctionBodyNode* FunctionBodyNode::create(JSGlobalData* globalData)
{
return new (globalData) FunctionBodyNode(globalData);
return new FunctionBodyNode(globalData);
}
PassRefPtr<FunctionBodyNode> FunctionBodyNode::create(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, const SourceCode& sourceCode, CodeFeatures features, int numConstants)
{
RefPtr<FunctionBodyNode> node = new (globalData) FunctionBodyNode(globalData, children, varStack, funcStack, sourceCode, features, numConstants);
RefPtr<FunctionBodyNode> node = new FunctionBodyNode(globalData, children, varStack, funcStack, sourceCode, features, numConstants);
ASSERT(node->data()->m_arena.last() == node);
node->data()->m_arena.removeLast();
ASSERT(node->data()->m_arena.find(node.get()) == notFound);
ASSERT(!node->data()->m_arena.contains(node.get()));
return node.release();
}
......
......@@ -29,6 +29,7 @@
#include "Error.h"
#include "JITCode.h"
#include "Opcode.h"
#include "ParserArena.h"
#include "ResultType.h"
#include "SourceCode.h"
#include "SymbolTable.h"
......@@ -101,30 +102,37 @@ namespace JSC {
SwitchType switchType;
};
class ParserRefCounted : public RefCounted<ParserRefCounted> {
class ParserArenaDeletable {
protected:
ParserRefCounted(JSGlobalData*);
ParserArenaDeletable() { }
public:
virtual ~ParserRefCounted();
virtual ~ParserArenaDeletable() { }
// Placeholder: To be changed to arena allocation.
void* operator new(size_t size, JSGlobalData*) { return fastMalloc(size); }
// Objects created with this version of new are deleted when the arena is deleted.
void* operator new(size_t, JSGlobalData*);
private:
// Objects created with this version of new are not deleted when the arena is deleted.
// Other arrangements must be made.
void* operator new(size_t);
};
#ifdef NDEBUG
inline ParserRefCounted::~ParserRefCounted()
{
}
#endif
class ParserArenaRefCounted : public RefCounted<ParserArenaRefCounted> {
protected:
ParserArenaRefCounted(JSGlobalData*);
class Node : public ParserRefCounted {
public:
virtual ~ParserArenaRefCounted()
{
ASSERT(deletionHasBegun());
}
};
class Node : public ParserArenaDeletable {
protected:
Node(JSGlobalData*);
public:
/*
Return value: The register holding the production's value.
dst: An optional parameter specifying the most efficient
......@@ -386,7 +394,7 @@ namespace JSC {
int32_t m_startOffset;
};
class ElementNode : public ParserRefCounted {
class ElementNode : public ParserArenaDeletable {
public:
ElementNode(JSGlobalData*, int elision, ExpressionNode*);
ElementNode(JSGlobalData*, ElementNode*, int elision, ExpressionNode*);
......@@ -419,7 +427,7 @@ namespace JSC {
bool m_optional;
};
class PropertyNode : public ParserRefCounted {
class PropertyNode : public ParserArenaDeletable {
public:
enum Type { Constant, Getter, Setter };
......@@ -504,7 +512,7 @@ namespace JSC {
virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL;
};
class ArgumentsNode : public ParserRefCounted {
class ArgumentsNode : public ParserArenaDeletable {
public:
ArgumentsNode(JSGlobalData*);
ArgumentsNode(JSGlobalData*, ArgumentListNode*);
......@@ -1129,7 +1137,7 @@ namespace JSC {
typedef Vector<StatementNode*> StatementVector;
class SourceElements : public ParserRefCounted {
class SourceElements : public ParserArenaDeletable {
public:
SourceElements(JSGlobalData*);
......@@ -1356,7 +1364,7 @@ namespace JSC {
bool m_catchHasEval;
};
class ParameterNode : public ParserRefCounted {
class ParameterNode : public ParserArenaDeletable {
public:
ParameterNode(JSGlobalData*, const Identifier&);
ParameterNode(JSGlobalData*, ParameterNode*, const Identifier&);
......@@ -1369,9 +1377,6 @@ namespace JSC {
ParameterNode* m_next;
};
// Placholder. Later this will become a true arena.
typedef Vector<RefPtr<ParserRefCounted> > ParserArena;
struct ScopeNodeData {
typedef DeclarationStacks::VarStack VarStack;
typedef DeclarationStacks::FunctionStack FunctionStack;
......@@ -1387,7 +1392,7 @@ namespace JSC {
void mark();
};
class ScopeNode : public StatementNode {
class ScopeNode : public StatementNode, public ParserArenaRefCounted {
public:
typedef DeclarationStacks::VarStack VarStack;
typedef DeclarationStacks::FunctionStack FunctionStack;
......@@ -1397,7 +1402,7 @@ namespace JSC {
void adoptData(std::auto_ptr<ScopeNodeData> data)
{
ASSERT(data->m_arena.find(this) == notFound);
ASSERT(!data->m_arena.contains(this));
ASSERT(!m_data);
m_data.adopt(data);
}
......@@ -1567,7 +1572,7 @@ namespace JSC {
OwnPtr<CodeBlock> m_code;
};
class FuncExprNode : public ExpressionNode {
class FuncExprNode : public ExpressionNode, public ParserArenaRefCounted {
public:
FuncExprNode(JSGlobalData*, const Identifier&, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter = 0);
......@@ -1584,7 +1589,7 @@ namespace JSC {
RefPtr<FunctionBodyNode> m_body;
};
class FuncDeclNode : public StatementNode {
class FuncDeclNode : public StatementNode, public ParserArenaRefCounted {
public:
FuncDeclNode(JSGlobalData*, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0);
......@@ -1600,7 +1605,7 @@ namespace JSC {
RefPtr<FunctionBodyNode> m_body;
};
class CaseClauseNode : public ParserRefCounted {
class CaseClauseNode : public ParserArenaDeletable {
public:
CaseClauseNode(JSGlobalData*, ExpressionNode*);
CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements*);
......@@ -1613,7 +1618,7 @@ namespace JSC {
StatementVector m_children;
};
class ClauseListNode : public ParserRefCounted {
class ClauseListNode : public ParserArenaDeletable {
public:
ClauseListNode(JSGlobalData*, CaseClauseNode*);
ClauseListNode(JSGlobalData*, ClauseListNode*, CaseClauseNode*);
......@@ -1626,7 +1631,7 @@ namespace JSC {
ClauseListNode* m_next;
};
class CaseBlockNode : public ParserRefCounted {
class CaseBlockNode : public ParserArenaDeletable {
public:
CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2);
......
......@@ -39,7 +39,7 @@ namespace JSC {
void Parser::parse(JSGlobalData* globalData, int* errLine, UString* errMsg)
{
ASSERT(!m_sourceElements);
m_sourceElements = 0;
int defaultErrLine;
UString defaultErrMsg;
......@@ -63,7 +63,7 @@ void Parser::parse(JSGlobalData* globalData, int* errLine, UString* errMsg)
if (parseError || lexError) {
*errLine = lineNumber;
*errMsg = "Parse error";
m_sourceElements.clear();
m_sourceElements = 0;
}
}
......@@ -76,8 +76,8 @@ void Parser::reparseInPlace(JSGlobalData* globalData, FunctionBodyNode* function
parse(globalData, 0, 0);
ASSERT(m_sourceElements);
functionBodyNode->adoptData(std::auto_ptr<ScopeNodeData>(new ScopeNodeData(globalData->parserArena,
m_sourceElements.get(),
functionBodyNode->adoptData(std::auto_ptr<ScopeNodeData>(new ScopeNodeData(globalData->parser->arena(),
m_sourceElements,
m_varDeclarations ? &m_varDeclarations->data : 0,
m_funcDeclarations ? &m_funcDeclarations->data : 0,
m_numConstants)));
......@@ -86,7 +86,7 @@ void Parser::reparseInPlace(JSGlobalData* globalData, FunctionBodyNode* function
if (usesArguments && !functionBodyNode->usesArguments())
functionBodyNode->setUsesArguments();
ASSERT(globalData->parserArena.isEmpty());
ASSERT(globalData->parser->arena().isEmpty());
m_source = 0;
m_sourceElements = 0;
......@@ -94,8 +94,8 @@ void Parser::reparseInPlace(JSGlobalData* globalData, FunctionBodyNode* function
m_funcDeclarations = 0;
}
void Parser::didFinishParsing(SourceElements* sourceElements, ParserRefCountedData<DeclarationStacks::VarStack>* varStack,
ParserRefCountedData<DeclarationStacks::FunctionStack>* funcStack, CodeFeatures features, int lastLine, int numConstants)
void Parser::didFinishParsing(SourceElements* sourceElements, ParserArenaData<DeclarationStacks::VarStack>* varStack,
ParserArenaData<DeclarationStacks::FunctionStack>* funcStack, CodeFeatures features, int lastLine, int numConstants)
{
m_sourceElements = sourceElements;
m_varDeclarations = varStack;
......
......@@ -23,9 +23,9 @@
#ifndef Parser_h
#define Parser_h
#include "SourceProvider.h"
#include "Debugger.h"
#include "Nodes.h"
#include "SourceProvider.h"
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
#include <wtf/OwnPtr.h>
......@@ -37,15 +37,7 @@ namespace JSC {
class ProgramNode;
class UString;