Changeset 43479 in webkit for trunk/JavaScriptCore
- Timestamp:
- May 10, 2009, 9:30:14 PM (16 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r43478 r43479 1 2009-05-10 Darin Adler <[email protected]> 2 3 Reviewed by Cameron Zwarich. 4 5 Bug 25674: syntax tree nodes should use arena allocation 6 https://bugs.webkit.org/show_bug.cgi?id=25674 7 8 Part two: Remove reference counting from most nodes. 9 10 * JavaScriptCore.exp: Updated. 11 12 * JavaScriptCore.xcodeproj/project.pbxproj: Added ParserArena.h and .cpp. 13 14 * parser/Grammar.y: Replaced uses of ParserRefCountedData with uses of 15 ParserArenaData. Took out now-nonfunctional code that tries to manually 16 release declaration list. Changed the new calls that create FuncDeclNode 17 and FuncExprNode so that they use the proper version of operator new for 18 the reference-counted idiom, not the deletion idiom. 19 20 * parser/NodeConstructors.h: 21 (JSC::ParserArenaDeletable::operator new): Added. 22 (JSC::ParserArenaRefCounted::ParserArenaRefCounted): Added. 23 (JSC::Node::Node): Removed ParserRefCounted initializer. 24 (JSC::ElementNode::ElementNode): Ditto. 25 (JSC::PropertyNode::PropertyNode): Ditto. 26 (JSC::ArgumentsNode::ArgumentsNode): Ditto. 27 (JSC::SourceElements::SourceElements): Ditto. 28 (JSC::ParameterNode::ParameterNode): Ditto. 29 (JSC::FuncExprNode::FuncExprNode): Added ParserArenaRefCounted initializer. 30 (JSC::FuncDeclNode::FuncDeclNode): Ditto. 31 (JSC::CaseClauseNode::CaseClauseNode): Removed ParserRefCounted initializer. 32 (JSC::ClauseListNode::ClauseListNode): Ditto. 33 (JSC::CaseBlockNode::CaseBlockNode): Ditto. 34 35 * parser/NodeInfo.h: Replaced uses of ParserRefCountedData with uses of 36 ParserArenaData. 37 38 * parser/Nodes.cpp: 39 (JSC::ScopeNode::ScopeNode): Added ParserArenaRefCounted initializer. 40 (JSC::ProgramNode::create): Use the proper version of operator new for 41 the reference-counted idiom, not the deletion idiom. Use the arena 42 contains function instead of the vecctor find function. 43 (JSC::EvalNode::create): Use the proper version of operator new for 44 the reference-counted idiom, not the deletion idiom. Use the arena 45 reset function instead of the vector shrink function. 46 (JSC::FunctionBodyNode::createNativeThunk): Use the proper version 47 of operator new for the reference-counted idiom, not the deletion idiom. 48 (JSC::FunctionBodyNode::create): More of the same. 49 50 * parser/Nodes.h: Added ParserArenaDeletable and ParserArenaRefCounted 51 to replace ParserRefCounted. Fixed inheritance so only the classes that 52 need reference counting inherit from ParserArenaRefCounted. 53 54 * parser/Parser.cpp: 55 (JSC::Parser::parse): Set m_sourceElements to 0 since it now starts 56 uninitialized. Just set it to 0 again in the failure case, since it's 57 now just a raw pointer, not an owning one. 58 (JSC::Parser::reparseInPlace): Removed now-unneeded get() function. 59 (JSC::Parser::didFinishParsing): Replaced uses of ParserRefCountedData 60 with uses of ParserArenaData. 61 62 * parser/Parser.h: Less RefPtr, more arena. 63 64 * parser/ParserArena.cpp: Added. 65 * parser/ParserArena.h: Added. 66 67 * runtime/JSGlobalData.cpp: 68 (JSC::JSGlobalData::~JSGlobalData): Removed arena-related code, since it's 69 now in the Parser. 70 (JSC::JSGlobalData::createLeaked): Removed unneeded #ifndef. 71 (JSC::JSGlobalData::createNativeThunk): Tweaked #if a bit. 72 73 * runtime/JSGlobalData.h: Removed parserArena, which is now in Parser. 74 75 * wtf/RefCounted.h: Added deletionHasBegun function, for use in 76 assertions to catch deletion not done by the deref function. 77 1 78 2009-05-10 David Kilzer <[email protected]> 2 79 -
trunk/JavaScriptCore/JavaScriptCore.exp
r43471 r43479 108 108 __ZN3JSC11JSImmediate8toStringENS_7JSValueE 109 109 __ZN3JSC11JSImmediate9prototypeENS_7JSValueEPNS_9ExecStateE 110 __ZN3JSC11ParserArena5resetEv 110 111 __ZN3JSC11checkSyntaxEPNS_9ExecStateERKNS_10SourceCodeE 111 112 __ZN3JSC12DateInstance4infoE -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r43424 r43479 137 137 905B02AE0E28640F006DF882 /* RefCountedLeakCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 905B02AD0E28640F006DF882 /* RefCountedLeakCounter.cpp */; }; 138 138 90D3469C0E285280009492EE /* RefCountedLeakCounter.h in Headers */ = {isa = PBXBuildFile; fileRef = 90D3469B0E285280009492EE /* RefCountedLeakCounter.h */; settings = {ATTRIBUTES = (Private, ); }; }; 139 93052C340FB792190048FDC3 /* ParserArena.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93052C320FB792190048FDC3 /* ParserArena.cpp */; }; 140 93052C350FB792190048FDC3 /* ParserArena.h in Headers */ = {isa = PBXBuildFile; fileRef = 93052C330FB792190048FDC3 /* ParserArena.h */; settings = {ATTRIBUTES = (Private, ); }; }; 139 141 930754C108B0F68000AB3056 /* pcre_compile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 930754BF08B0F68000AB3056 /* pcre_compile.cpp */; }; 140 142 930754D008B0F74600AB3056 /* pcre_tables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 930754CE08B0F74500AB3056 /* pcre_tables.cpp */; }; … … 632 634 9303F5690991190000AD71B8 /* Noncopyable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Noncopyable.h; sourceTree = "<group>"; }; 633 635 9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OwnArrayPtr.h; sourceTree = "<group>"; }; 636 93052C320FB792190048FDC3 /* ParserArena.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParserArena.cpp; sourceTree = "<group>"; }; 637 93052C330FB792190048FDC3 /* ParserArena.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParserArena.h; sourceTree = "<group>"; }; 634 638 930754BF08B0F68000AB3056 /* pcre_compile.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pcre_compile.cpp; sourceTree = "<group>"; tabWidth = 8; }; 635 639 930754CE08B0F74500AB3056 /* pcre_tables.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pcre_tables.cpp; sourceTree = "<group>"; tabWidth = 8; }; … … 1257 1261 93F0B3A909BB4DC00068FCE3 /* Parser.cpp */, 1258 1262 93F0B3AA09BB4DC00068FCE3 /* Parser.h */, 1263 93052C320FB792190048FDC3 /* ParserArena.cpp */, 1264 93052C330FB792190048FDC3 /* ParserArena.h */, 1259 1265 869EBCB60E8C6D4A008722CC /* ResultType.h */, 1260 1266 65E866EE0DD59AFA00A2B2A1 /* SourceCode.h */, … … 1804 1810 A76EE6590FAE59D5003F069A /* NativeFunctionWrapper.h in Headers */, 1805 1811 A7E2EA6B0FB460CF00601F06 /* LiteralParser.h in Headers */, 1812 93052C350FB792190048FDC3 /* ParserArena.h in Headers */, 1806 1813 ); 1807 1814 runOnlyForDeploymentPostprocessing = 0; … … 2162 2169 86DB64640F95C6FC00D7D921 /* ExecutableAllocatorFixedVMPool.cpp in Sources */, 2163 2170 A7E2EA6C0FB460CF00601F06 /* LiteralParser.cpp in Sources */, 2171 93052C340FB792190048FDC3 /* ParserArena.cpp in Sources */, 2164 2172 ); 2165 2173 runOnlyForDeploymentPostprocessing = 0; -
trunk/JavaScriptCore/parser/Grammar.y
r43471 r43479 100 100 #define YYLEX_PARAM globalPtr 101 101 102 template <typename T> NodeDeclarationInfo<T> createNodeDeclarationInfo(T node, Parser RefCountedData<DeclarationStacks::VarStack>* varDecls,103 Parser RefCountedData<DeclarationStacks::FunctionStack>* funcDecls,102 template <typename T> NodeDeclarationInfo<T> createNodeDeclarationInfo(T node, ParserArenaData<DeclarationStacks::VarStack>* varDecls, 103 ParserArenaData<DeclarationStacks::FunctionStack>* funcDecls, 104 104 CodeFeatures info, 105 105 int numConstants) 106 106 { 107 107 ASSERT((info & ~AllFeatures) == 0); 108 NodeDeclarationInfo<T> result = { node, varDecls, funcDecls, info, numConstants};108 NodeDeclarationInfo<T> result = { node, varDecls, funcDecls, info, numConstants }; 109 109 return result; 110 110 } … … 113 113 { 114 114 ASSERT((info & ~AllFeatures) == 0); 115 NodeInfo<T> result = { node, info, numConstants};115 NodeInfo<T> result = { node, info, numConstants }; 116 116 return result; 117 117 } 118 118 119 template <typename T> T mergeDeclarationLists(T decls1, T decls2)119 template <typename T> inline T mergeDeclarationLists(T decls1, T decls2) 120 120 { 121 121 // decls1 or both are null … … 129 129 decls1->data.append(decls2->data); 130 130 131 // We manually release the declaration lists to avoid accumulating many many132 // unused heap allocated vectors133 decls2-> ref();134 decls2->deref(); 131 // Manually release as much as possible from the now-defunct declaration lists 132 // to avoid accumulating so many unused heap allocated vectors. 133 decls2->data.clear(); 134 135 135 return decls1; 136 136 } 137 137 138 static void appendToVarDeclarationList(void* globalPtr, Parser RefCountedData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs)138 static void appendToVarDeclarationList(void* globalPtr, ParserArenaData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs) 139 139 { 140 140 if (!varDecls) 141 varDecls = new (GLOBAL_DATA) Parser RefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);141 varDecls = new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::VarStack>; 142 142 143 143 varDecls->data.append(make_pair(ident, attrs)); … … 145 145 } 146 146 147 static inline void appendToVarDeclarationList(void* globalPtr, Parser RefCountedData<DeclarationStacks::VarStack>*& varDecls, ConstDeclNode* decl)147 static inline void appendToVarDeclarationList(void* globalPtr, ParserArenaData<DeclarationStacks::VarStack>*& varDecls, ConstDeclNode* decl) 148 148 { 149 149 unsigned attrs = DeclarationStacks::IsConstant; … … 265 265 %type <statementNode> FunctionDeclaration 266 266 %type <funcExprNode> FunctionExpr 267 %type <functionBodyNode> 267 %type <functionBodyNode> FunctionBody 268 268 %type <sourceElements> SourceElements 269 269 %type <parameterList> FormalParameterList … … 829 829 VariableDeclarationList: 830 830 IDENT { $$.m_node = 0; 831 $$.m_varDeclarations = new (GLOBAL_DATA) Parser RefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);831 $$.m_varDeclarations = new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::VarStack>; 832 832 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, 0); 833 833 $$.m_funcDeclarations = 0; … … 838 838 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.first_column + 1, @2.last_column); 839 839 $$.m_node = node; 840 $$.m_varDeclarations = new (GLOBAL_DATA) Parser RefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);840 $$.m_varDeclarations = new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::VarStack>; 841 841 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, DeclarationStacks::HasInitializer); 842 842 $$.m_funcDeclarations = 0; … … 866 866 VariableDeclarationListNoIn: 867 867 IDENT { $$.m_node = 0; 868 $$.m_varDeclarations = new (GLOBAL_DATA) Parser RefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);868 $$.m_varDeclarations = new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::VarStack>; 869 869 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, 0); 870 870 $$.m_funcDeclarations = 0; … … 875 875 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.first_column + 1, @2.last_column); 876 876 $$.m_node = node; 877 $$.m_varDeclarations = new (GLOBAL_DATA) Parser RefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);877 $$.m_varDeclarations = new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::VarStack>; 878 878 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, DeclarationStacks::HasInitializer); 879 879 $$.m_funcDeclarations = 0; … … 912 912 ConstDeclaration { $$.m_node.head = $1.m_node; 913 913 $$.m_node.tail = $$.m_node.head; 914 $$.m_varDeclarations = new (GLOBAL_DATA) Parser RefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);914 $$.m_varDeclarations = new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::VarStack>; 915 915 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, $1.m_node); 916 916 $$.m_funcDeclarations = 0; … … 959 959 | IF '(' Expr ')' Statement ELSE Statement 960 960 { $$ = createNodeDeclarationInfo<StatementNode*>(new (GLOBAL_DATA) IfElseNode(GLOBAL_DATA, $3.m_node, $5.m_node, $7.m_node), 961 mergeDeclarationLists($5.m_varDeclarations, $7.m_varDeclarations), mergeDeclarationLists($5.m_funcDeclarations, $7.m_funcDeclarations), 961 mergeDeclarationLists($5.m_varDeclarations, $7.m_varDeclarations), 962 mergeDeclarationLists($5.m_funcDeclarations, $7.m_funcDeclarations), 962 963 $3.m_features | $5.m_features | $7.m_features, 963 964 $3.m_numConstants + $5.m_numConstants + $7.m_numConstants); … … 1169 1170 1170 1171 FunctionDeclaration: 1171 FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeDeclarationInfo<StatementNode*>(new (GLOBAL_DATA) FuncDeclNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), 0, new (GLOBAL_DATA) ParserRefCountedData<DeclarationStacks::FunctionStack>(GLOBAL_DATA), ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | ClosureFeature, 0); DBG($6, @5, @7); $$.m_funcDeclarations->data.append(static_cast<FuncDeclNode*>($$.m_node)); }1172 FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeDeclarationInfo<StatementNode*>(new FuncDeclNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), 0, new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::FunctionStack>, ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | ClosureFeature, 0); DBG($6, @5, @7); $$.m_funcDeclarations->data.append(static_cast<FuncDeclNode*>($$.m_node)); } 1172 1173 | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE 1173 1174 { 1174 $$ = createNodeDeclarationInfo<StatementNode*>(new (GLOBAL_DATA) FuncDeclNode(GLOBAL_DATA, *$2, $7, LEXER->sourceCode($6, $8, @6.first_line), $4.m_node.head), 0, new (GLOBAL_DATA) ParserRefCountedData<DeclarationStacks::FunctionStack>(GLOBAL_DATA), ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $4.m_features | ClosureFeature, 0);1175 $$ = createNodeDeclarationInfo<StatementNode*>(new FuncDeclNode(GLOBAL_DATA, *$2, $7, LEXER->sourceCode($6, $8, @6.first_line), $4.m_node.head), 0, new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::FunctionStack>, ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $4.m_features | ClosureFeature, 0); 1175 1176 if ($4.m_features & ArgumentsFeature) 1176 1177 $7->setUsesArguments(); … … 1181 1182 1182 1183 FunctionExpr: 1183 FUNCTION '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo(new (GLOBAL_DATA)FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, $5, LEXER->sourceCode($4, $6, @4.first_line)), ClosureFeature, 0); DBG($5, @4, @6); }1184 FUNCTION '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo(new FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, $5, LEXER->sourceCode($4, $6, @4.first_line)), ClosureFeature, 0); DBG($5, @4, @6); } 1184 1185 | FUNCTION '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE 1185 1186 { 1186 $$ = createNodeInfo(new (GLOBAL_DATA)FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, $6, LEXER->sourceCode($5, $7, @5.first_line), $3.m_node.head), $3.m_features | ClosureFeature, 0);1187 $$ = createNodeInfo(new FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, $6, LEXER->sourceCode($5, $7, @5.first_line), $3.m_node.head), $3.m_features | ClosureFeature, 0); 1187 1188 if ($3.m_features & ArgumentsFeature) 1188 1189 $6->setUsesArguments(); 1189 1190 DBG($6, @5, @7); 1190 1191 } 1191 | FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo(new (GLOBAL_DATA)FuncExprNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), ClosureFeature, 0); DBG($6, @5, @7); }1192 | FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo(new FuncExprNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), ClosureFeature, 0); DBG($6, @5, @7); } 1192 1193 | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE 1193 1194 { 1194 $$ = createNodeInfo(new (GLOBAL_DATA)FuncExprNode(GLOBAL_DATA, *$2, $7, LEXER->sourceCode($6, $8, @6.first_line), $4.m_node.head), $4.m_features | ClosureFeature, 0);1195 $$ = createNodeInfo(new FuncExprNode(GLOBAL_DATA, *$2, $7, LEXER->sourceCode($6, $8, @6.first_line), $4.m_node.head), $4.m_features | ClosureFeature, 0); 1195 1196 if ($4.m_features & ArgumentsFeature) 1196 1197 $7->setUsesArguments(); … … 1972 1973 else 1973 1974 return 0; 1974 return new (GLOBAL_DATA) PropertyNode(GLOBAL_DATA, name, new (GLOBAL_DATA)FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, body, source, params), type);1975 return new (GLOBAL_DATA) PropertyNode(GLOBAL_DATA, name, new FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, body, source, params), type); 1975 1976 } 1976 1977 -
trunk/JavaScriptCore/parser/NodeConstructors.h
r43471 r43479 27 27 namespace JSC { 28 28 29 #ifdef NDEBUG 30 inline ParserRefCounted::ParserRefCounted(JSGlobalData* globalData) 31 { 32 globalData->parserArena.append(adoptRef(this)); 33 } 34 #endif 29 void* ParserArenaDeletable::operator new(size_t size, JSGlobalData* globalData) 30 { 31 ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(fastMalloc(size)); 32 globalData->parser->arena().deleteWithArena(deletable); 33 return deletable; 34 } 35 36 void* ParserArenaDeletable::operator new(size_t size) 37 { 38 return fastMalloc(size); 39 } 40 41 inline ParserArenaRefCounted::ParserArenaRefCounted(JSGlobalData* globalData) 42 { 43 globalData->parser->arena().derefWithArena(adoptRef(this)); 44 } 35 45 36 46 inline Node::Node(JSGlobalData* globalData) 37 : ParserRefCounted(globalData) 38 , m_line(globalData->lexer->lineNumber()) 39 { 40 } 41 47 : m_line(globalData->lexer->lineNumber()) 48 { 49 } 42 50 43 51 inline ExpressionNode::ExpressionNode(JSGlobalData* globalData, ResultType resultType) … … 95 103 } 96 104 97 inline ElementNode::ElementNode(JSGlobalData* globalData, int elision, ExpressionNode* node) 98 : ParserRefCounted(globalData) 99 , m_next(0) 105 inline ElementNode::ElementNode(JSGlobalData*, int elision, ExpressionNode* node) 106 : m_next(0) 100 107 , m_elision(elision) 101 108 , m_node(node) … … 103 110 } 104 111 105 inline ElementNode::ElementNode(JSGlobalData* globalData, ElementNode* l, int elision, ExpressionNode* node) 106 : ParserRefCounted(globalData) 107 , m_next(0) 112 inline ElementNode::ElementNode(JSGlobalData*, ElementNode* l, int elision, ExpressionNode* node) 113 : m_next(0) 108 114 , m_elision(elision) 109 115 , m_node(node) … … 136 142 } 137 143 138 inline PropertyNode::PropertyNode(JSGlobalData* globalData, const Identifier& name, ExpressionNode* assign, Type type) 139 : ParserRefCounted(globalData) 140 , m_name(name) 144 inline PropertyNode::PropertyNode(JSGlobalData*, const Identifier& name, ExpressionNode* assign, Type type) 145 : m_name(name) 141 146 , m_assign(assign) 142 147 , m_type(type) … … 201 206 } 202 207 203 inline ArgumentsNode::ArgumentsNode(JSGlobalData* globalData) 204 : ParserRefCounted(globalData) 205 , m_listNode(0) 206 { 207 } 208 209 inline ArgumentsNode::ArgumentsNode(JSGlobalData* globalData, ArgumentListNode* listNode) 210 : ParserRefCounted(globalData) 211 , m_listNode(listNode) 208 inline ArgumentsNode::ArgumentsNode(JSGlobalData*) 209 : m_listNode(0) 210 { 211 } 212 213 inline ArgumentsNode::ArgumentsNode(JSGlobalData*, ArgumentListNode* listNode) 214 : m_listNode(listNode) 212 215 { 213 216 } … … 667 670 } 668 671 669 inline SourceElements::SourceElements(JSGlobalData* globalData) 670 : ParserRefCounted(globalData) 672 inline SourceElements::SourceElements(JSGlobalData*) 671 673 { 672 674 } … … 792 794 } 793 795 794 inline ParameterNode::ParameterNode(JSGlobalData* globalData, const Identifier& ident) 795 : ParserRefCounted(globalData) 796 , m_ident(ident) 796 inline ParameterNode::ParameterNode(JSGlobalData*, const Identifier& ident) 797 : m_ident(ident) 797 798 , m_next(0) 798 799 { 799 800 } 800 801 801 inline ParameterNode::ParameterNode(JSGlobalData* globalData, ParameterNode* l, const Identifier& ident) 802 : ParserRefCounted(globalData) 803 , m_ident(ident) 802 inline ParameterNode::ParameterNode(JSGlobalData*, ParameterNode* l, const Identifier& ident) 803 : m_ident(ident) 804 804 , m_next(0) 805 805 { … … 807 807 } 808 808 809 810 809 inline FuncExprNode::FuncExprNode(JSGlobalData* globalData, const Identifier& ident, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter) 811 810 : ExpressionNode(globalData) 811 , ParserArenaRefCounted(globalData) 812 812 , m_ident(ident) 813 813 , m_body(body) … … 818 818 inline FuncDeclNode::FuncDeclNode(JSGlobalData* globalData, const Identifier& ident, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter) 819 819 : StatementNode(globalData) 820 , ParserArenaRefCounted(globalData) 820 821 , m_ident(ident) 821 822 , m_body(body) … … 824 825 } 825 826 826 inline CaseClauseNode::CaseClauseNode(JSGlobalData* globalData, ExpressionNode* expr) 827 : ParserRefCounted(globalData) 828 , m_expr(expr) 829 { 830 } 831 832 inline CaseClauseNode::CaseClauseNode(JSGlobalData* globalData, ExpressionNode* expr, SourceElements* children) 833 : ParserRefCounted(globalData) 834 , m_expr(expr) 827 inline CaseClauseNode::CaseClauseNode(JSGlobalData*, ExpressionNode* expr) 828 : m_expr(expr) 829 { 830 } 831 832 inline CaseClauseNode::CaseClauseNode(JSGlobalData*, ExpressionNode* expr, SourceElements* children) 833 : m_expr(expr) 835 834 { 836 835 if (children) … … 838 837 } 839 838 840 inline ClauseListNode::ClauseListNode(JSGlobalData* globalData, CaseClauseNode* clause) 841 : ParserRefCounted(globalData) 842 , m_clause(clause) 839 inline ClauseListNode::ClauseListNode(JSGlobalData*, CaseClauseNode* clause) 840 : m_clause(clause) 843 841 , m_next(0) 844 842 { 845 843 } 846 844 847 inline ClauseListNode::ClauseListNode(JSGlobalData* globalData, ClauseListNode* clauseList, CaseClauseNode* clause) 848 : ParserRefCounted(globalData) 849 , m_clause(clause) 845 inline ClauseListNode::ClauseListNode(JSGlobalData*, ClauseListNode* clauseList, CaseClauseNode* clause) 846 : m_clause(clause) 850 847 , m_next(0) 851 848 { … … 853 850 } 854 851 855 inline CaseBlockNode::CaseBlockNode(JSGlobalData* globalData, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2) 856 : ParserRefCounted(globalData) 857 , m_list1(list1) 852 inline CaseBlockNode::CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2) 853 : m_list1(list1) 858 854 , m_defaultClause(defaultClause) 859 855 , m_list2(list2) -
trunk/JavaScriptCore/parser/NodeInfo.h
r38205 r43479 44 44 template <typename T> struct NodeDeclarationInfo { 45 45 T m_node; 46 Parser RefCountedData<DeclarationStacks::VarStack>* m_varDeclarations;47 Parser RefCountedData<DeclarationStacks::FunctionStack>* m_funcDeclarations;46 ParserArenaData<DeclarationStacks::VarStack>* m_varDeclarations; 47 ParserArenaData<DeclarationStacks::FunctionStack>* m_funcDeclarations; 48 48 CodeFeatures m_features; 49 49 int m_numConstants; -
trunk/JavaScriptCore/parser/Nodes.cpp
r43475 r43479 51 51 52 52 static void substitute(UString& string, const UString& substring) JSC_FAST_CALL; 53 54 // ------------------------------ ParserRefCounted -----------------------------------------55 56 #ifndef NDEBUG57 58 static RefCountedLeakCounter parserRefCountedCounter("JSC::Node");59 60 ALWAYS_INLINE ParserRefCounted::ParserRefCounted(JSGlobalData* globalData)61 {62 globalData->parserArena.append(adoptRef(this));63 parserRefCountedCounter.increment();64 }65 66 ALWAYS_INLINE ParserRefCounted::~ParserRefCounted()67 {68 parserRefCountedCounter.decrement();69 }70 71 #endif72 53 73 54 // ------------------------------ ThrowableExpressionData -------------------------------- … … 1840 1821 ScopeNode::ScopeNode(JSGlobalData* globalData) 1841 1822 : StatementNode(globalData) 1823 , ParserArenaRefCounted(globalData) 1842 1824 , m_features(NoFeatures) 1843 1825 { … … 1849 1831 ScopeNode::ScopeNode(JSGlobalData* globalData, const SourceCode& source, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, CodeFeatures features, int numConstants) 1850 1832 : StatementNode(globalData) 1851 , m_data(new ScopeNodeData(globalData->parserArena, children, varStack, funcStack, numConstants)) 1833 , ParserArenaRefCounted(globalData) 1834 , m_data(new ScopeNodeData(globalData->parser->arena(), children, varStack, funcStack, numConstants)) 1852 1835 , m_features(features) 1853 1836 , m_source(source) … … 1867 1850 PassRefPtr<ProgramNode> ProgramNode::create(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, const SourceCode& source, CodeFeatures features, int numConstants) 1868 1851 { 1869 RefPtr<ProgramNode> node = new (globalData)ProgramNode(globalData, children, varStack, funcStack, source, features, numConstants);1852 RefPtr<ProgramNode> node = new ProgramNode(globalData, children, varStack, funcStack, source, features, numConstants); 1870 1853 1871 1854 ASSERT(node->data()->m_arena.last() == node); 1872 1855 node->data()->m_arena.removeLast(); 1873 ASSERT( node->data()->m_arena.find(node.get()) == notFound);1856 ASSERT(!node->data()->m_arena.contains(node.get())); 1874 1857 1875 1858 return node.release(); … … 1911 1894 PassRefPtr<EvalNode> EvalNode::create(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, const SourceCode& source, CodeFeatures features, int numConstants) 1912 1895 { 1913 RefPtr<EvalNode> node = new (globalData)EvalNode(globalData, children, varStack, funcStack, source, features, numConstants);1896 RefPtr<EvalNode> node = new EvalNode(globalData, children, varStack, funcStack, source, features, numConstants); 1914 1897 1915 1898 ASSERT(node->data()->m_arena.last() == node); 1916 1899 node->data()->m_arena.removeLast(); 1917 ASSERT( node->data()->m_arena.find(node.get()) == notFound);1900 ASSERT(!node->data()->m_arena.contains(node.get())); 1918 1901 1919 1902 return node.release(); … … 2026 2009 PassRefPtr<FunctionBodyNode> FunctionBodyNode::createNativeThunk(JSGlobalData* globalData) 2027 2010 { 2028 RefPtr<FunctionBodyNode> body = new (globalData)FunctionBodyNode(globalData);2029 globalData->parser Arena.shrink(0);2011 RefPtr<FunctionBodyNode> body = new FunctionBodyNode(globalData); 2012 globalData->parser->arena().reset(); 2030 2013 body->m_jitCode = globalData->jitStubs.ctiNativeCallThunk(); 2031 2014 return body.release(); … … 2035 2018 FunctionBodyNode* FunctionBodyNode::create(JSGlobalData* globalData) 2036 2019 { 2037 return new (globalData)FunctionBodyNode(globalData);2020 return new FunctionBodyNode(globalData); 2038 2021 } 2039 2022 2040 2023 PassRefPtr<FunctionBodyNode> FunctionBodyNode::create(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, const SourceCode& sourceCode, CodeFeatures features, int numConstants) 2041 2024 { 2042 RefPtr<FunctionBodyNode> node = new (globalData)FunctionBodyNode(globalData, children, varStack, funcStack, sourceCode, features, numConstants);2025 RefPtr<FunctionBodyNode> node = new FunctionBodyNode(globalData, children, varStack, funcStack, sourceCode, features, numConstants); 2043 2026 2044 2027 ASSERT(node->data()->m_arena.last() == node); 2045 2028 node->data()->m_arena.removeLast(); 2046 ASSERT( node->data()->m_arena.find(node.get()) == notFound);2029 ASSERT(!node->data()->m_arena.contains(node.get())); 2047 2030 2048 2031 return node.release(); -
trunk/JavaScriptCore/parser/Nodes.h
r43471 r43479 30 30 #include "JITCode.h" 31 31 #include "Opcode.h" 32 #include "ParserArena.h" 32 33 #include "ResultType.h" 33 34 #include "SourceCode.h" … … 102 103 }; 103 104 104 class Parser RefCounted : public RefCounted<ParserRefCounted>{105 class ParserArenaDeletable { 105 106 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. 115 117 void* operator new(size_t); 116 118 }; 117 119 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: 126 133 Node(JSGlobalData*); 127 134 135 public: 128 136 /* 129 137 Return value: The register holding the production's value. … … 387 395 }; 388 396 389 class ElementNode : public Parser RefCounted{397 class ElementNode : public ParserArenaDeletable { 390 398 public: 391 399 ElementNode(JSGlobalData*, int elision, ExpressionNode*); … … 420 428 }; 421 429 422 class PropertyNode : public Parser RefCounted{430 class PropertyNode : public ParserArenaDeletable { 423 431 public: 424 432 enum Type { Constant, Getter, Setter }; … … 505 513 }; 506 514 507 class ArgumentsNode : public Parser RefCounted{515 class ArgumentsNode : public ParserArenaDeletable { 508 516 public: 509 517 ArgumentsNode(JSGlobalData*); … … 1130 1138 typedef Vector<StatementNode*> StatementVector; 1131 1139 1132 class SourceElements : public Parser RefCounted{1140 class SourceElements : public ParserArenaDeletable { 1133 1141 public: 1134 1142 SourceElements(JSGlobalData*); … … 1357 1365 }; 1358 1366 1359 class ParameterNode : public Parser RefCounted{1367 class ParameterNode : public ParserArenaDeletable { 1360 1368 public: 1361 1369 ParameterNode(JSGlobalData*, const Identifier&); … … 1369 1377 ParameterNode* m_next; 1370 1378 }; 1371 1372 // Placholder. Later this will become a true arena.1373 typedef Vector<RefPtr<ParserRefCounted> > ParserArena;1374 1379 1375 1380 struct ScopeNodeData { … … 1388 1393 }; 1389 1394 1390 class ScopeNode : public StatementNode {1395 class ScopeNode : public StatementNode, public ParserArenaRefCounted { 1391 1396 public: 1392 1397 typedef DeclarationStacks::VarStack VarStack; … … 1398 1403 void adoptData(std::auto_ptr<ScopeNodeData> data) 1399 1404 { 1400 ASSERT( data->m_arena.find(this) == notFound);1405 ASSERT(!data->m_arena.contains(this)); 1401 1406 ASSERT(!m_data); 1402 1407 m_data.adopt(data); … … 1568 1573 }; 1569 1574 1570 class FuncExprNode : public ExpressionNode {1575 class FuncExprNode : public ExpressionNode, public ParserArenaRefCounted { 1571 1576 public: 1572 1577 FuncExprNode(JSGlobalData*, const Identifier&, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter = 0); … … 1585 1590 }; 1586 1591 1587 class FuncDeclNode : public StatementNode {1592 class FuncDeclNode : public StatementNode, public ParserArenaRefCounted { 1588 1593 public: 1589 1594 FuncDeclNode(JSGlobalData*, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0); … … 1601 1606 }; 1602 1607 1603 class CaseClauseNode : public Parser RefCounted{1608 class CaseClauseNode : public ParserArenaDeletable { 1604 1609 public: 1605 1610 CaseClauseNode(JSGlobalData*, ExpressionNode*); … … 1614 1619 }; 1615 1620 1616 class ClauseListNode : public Parser RefCounted{1621 class ClauseListNode : public ParserArenaDeletable { 1617 1622 public: 1618 1623 ClauseListNode(JSGlobalData*, CaseClauseNode*); … … 1627 1632 }; 1628 1633 1629 class CaseBlockNode : public Parser RefCounted{1634 class CaseBlockNode : public ParserArenaDeletable { 1630 1635 public: 1631 1636 CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2); -
trunk/JavaScriptCore/parser/Parser.cpp
r43471 r43479 40 40 void Parser::parse(JSGlobalData* globalData, int* errLine, UString* errMsg) 41 41 { 42 ASSERT(!m_sourceElements);42 m_sourceElements = 0; 43 43 44 44 int defaultErrLine; … … 64 64 *errLine = lineNumber; 65 65 *errMsg = "Parse error"; 66 m_sourceElements .clear();66 m_sourceElements = 0; 67 67 } 68 68 } … … 77 77 ASSERT(m_sourceElements); 78 78 79 functionBodyNode->adoptData(std::auto_ptr<ScopeNodeData>(new ScopeNodeData(globalData->parser Arena,80 m_sourceElements .get(),79 functionBodyNode->adoptData(std::auto_ptr<ScopeNodeData>(new ScopeNodeData(globalData->parser->arena(), 80 m_sourceElements, 81 81 m_varDeclarations ? &m_varDeclarations->data : 0, 82 82 m_funcDeclarations ? &m_funcDeclarations->data : 0, … … 87 87 functionBodyNode->setUsesArguments(); 88 88 89 ASSERT(globalData->parser Arena.isEmpty());89 ASSERT(globalData->parser->arena().isEmpty()); 90 90 91 91 m_source = 0; … … 95 95 } 96 96 97 void Parser::didFinishParsing(SourceElements* sourceElements, Parser RefCountedData<DeclarationStacks::VarStack>* varStack,98 Parser RefCountedData<DeclarationStacks::FunctionStack>* funcStack, CodeFeatures features, int lastLine, int numConstants)97 void Parser::didFinishParsing(SourceElements* sourceElements, ParserArenaData<DeclarationStacks::VarStack>* varStack, 98 ParserArenaData<DeclarationStacks::FunctionStack>* funcStack, CodeFeatures features, int lastLine, int numConstants) 99 99 { 100 100 m_sourceElements = sourceElements; -
trunk/JavaScriptCore/parser/Parser.h
r43471 r43479 24 24 #define Parser_h 25 25 26 #include "SourceProvider.h"27 26 #include "Debugger.h" 28 27 #include "Nodes.h" 28 #include "SourceProvider.h" 29 29 #include <wtf/Forward.h> 30 30 #include <wtf/Noncopyable.h> … … 38 38 class UString; 39 39 40 template <typename T> 41 struct ParserRefCountedData : ParserRefCounted { 42 ParserRefCountedData(JSGlobalData* globalData) 43 : ParserRefCounted(globalData) 44 { 45 } 46 47 T data; 48 }; 40 template <typename T> struct ParserArenaData : ParserArenaDeletable { T data; }; 49 41 50 42 class Parser : Noncopyable { … … 54 46 void reparseInPlace(JSGlobalData*, FunctionBodyNode*); 55 47 56 void didFinishParsing(SourceElements*, ParserRefCountedData<DeclarationStacks::VarStack>*, 57 ParserRefCountedData<DeclarationStacks::FunctionStack>*, CodeFeatures features, int lastLine, int numConstants); 48 void didFinishParsing(SourceElements*, ParserArenaData<DeclarationStacks::VarStack>*, 49 ParserArenaData<DeclarationStacks::FunctionStack>*, CodeFeatures features, int lastLine, int numConstants); 50 51 ParserArena& arena() { return m_arena; } 58 52 59 53 private: 60 54 void parse(JSGlobalData*, int* errLine, UString* errMsg); 61 55 56 ParserArena m_arena; 62 57 const SourceCode* m_source; 63 RefPtr<SourceElements>m_sourceElements;64 RefPtr<ParserRefCountedData<DeclarationStacks::VarStack> >m_varDeclarations;65 RefPtr<ParserRefCountedData<DeclarationStacks::FunctionStack> >m_funcDeclarations;58 SourceElements* m_sourceElements; 59 ParserArenaData<DeclarationStacks::VarStack>* m_varDeclarations; 60 ParserArenaData<DeclarationStacks::FunctionStack>* m_funcDeclarations; 66 61 CodeFeatures m_features; 67 62 int m_lastLine; … … 76 71 if (m_sourceElements) { 77 72 result = ParsedNode::create(&exec->globalData(), 78 m_sourceElements .get(),73 m_sourceElements, 79 74 m_varDeclarations ? &m_varDeclarations->data : 0, 80 75 m_funcDeclarations ? &m_funcDeclarations->data : 0, … … 85 80 } 86 81 87 exec->globalData().parserArena.shrink(0);82 m_arena.reset(); 88 83 89 84 m_source = 0; 90 m_sourceElements = 0;91 85 m_varDeclarations = 0; 92 86 m_funcDeclarations = 0; … … 104 98 if (m_sourceElements) { 105 99 result = ParsedNode::create(globalData, 106 m_sourceElements .get(),100 m_sourceElements, 107 101 m_varDeclarations ? &m_varDeclarations->data : 0, 108 102 m_funcDeclarations ? &m_funcDeclarations->data : 0, … … 113 107 } 114 108 115 globalData->parserArena.shrink(0);109 m_arena.reset(); 116 110 117 111 m_source = 0; 118 m_sourceElements = 0;119 112 m_varDeclarations = 0; 120 113 m_funcDeclarations = 0; -
trunk/JavaScriptCore/runtime/JSGlobalData.cpp
r43471 r43479 184 184 185 185 delete clientData; 186 187 ASSERT(parserArena.isEmpty());188 186 } 189 187 … … 195 193 PassRefPtr<JSGlobalData> JSGlobalData::createLeaked() 196 194 { 197 #ifndef NDEBUG198 195 Structure::startIgnoringLeaks(); 199 196 RefPtr<JSGlobalData> data = create(); 200 197 Structure::stopIgnoringLeaks(); 201 198 return data.release(); 202 #else203 return create();204 #endif205 199 } 206 200 … … 229 223 } 230 224 225 #if ENABLE(JIT) 226 231 227 void JSGlobalData::createNativeThunk() 232 228 { 233 #if ENABLE(JIT)234 229 lazyNativeFunctionThunk = FunctionBodyNode::createNativeThunk(this); 235 #endif 236 } 230 } 231 232 #endif 237 233 238 234 // FIXME: We can also detect forms like v1 < v2 ? -1 : 0, reverse comparison, etc. -
trunk/JavaScriptCore/runtime/JSGlobalData.h
r43471 r43479 1 1 /* 2 * Copyright (C) 2008 Apple Inc. All rights reserved.2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 45 45 namespace JSC { 46 46 47 class ArgList;48 47 class CommonIdentifiers; 49 48 class FunctionBodyNode; 50 class Heap;51 49 class IdentifierTable; 52 50 class Instruction; … … 56 54 class Lexer; 57 55 class Parser; 58 class ParserRefCounted;59 56 class ScopeNode; 60 57 class Structure; … … 148 145 HashSet<JSObject*> arrayVisitedElements; 149 146 150 Vector<RefPtr<ParserRefCounted> > parserArena;151 147 ScopeNode* scopeNodeBeingReparsed; 152 148 … … 156 152 void createNativeThunk(); 157 153 }; 154 158 155 } // namespace JSC 159 156 -
trunk/JavaScriptCore/wtf/RefCounted.h
r43317 r43479 84 84 } 85 85 86 #ifndef NDEBUG 87 bool deletionHasBegun() const 88 { 89 return m_deletionHasBegun; 90 } 91 #endif 92 86 93 private: 87 94 template<class T>
Note:
See TracChangeset
for help on using the changeset viewer.