Changeset 136261 in webkit
- Timestamp:
- Nov 30, 2012 1:09:21 PM (11 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r136246 r136261 1 2012-11-30 Oliver Hunt <oliver@apple.com> 2 3 Add direct string->function code cache 4 https://bugs.webkit.org/show_bug.cgi?id=103764 5 6 Reviewed by Michael Saboff. 7 8 A fairly logically simple patch. We now track the start of the 9 unique portion of a functions body, and use that as our key for 10 unlinked function code. This allows us to cache identical code 11 in different contexts, leading to a small but consistent improvement 12 on the benchmarks we track. 13 14 * bytecode/UnlinkedCodeBlock.cpp: 15 (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): 16 * bytecode/UnlinkedCodeBlock.h: 17 (JSC::UnlinkedFunctionExecutable::functionStartOffset): 18 (UnlinkedFunctionExecutable): 19 * parser/ASTBuilder.h: 20 (ASTBuilder): 21 (JSC::ASTBuilder::setFunctionStart): 22 * parser/Nodes.cpp: 23 * parser/Nodes.h: 24 (JSC::FunctionBodyNode::setFunctionStart): 25 (JSC::FunctionBodyNode::functionStart): 26 (FunctionBodyNode): 27 * parser/Parser.cpp: 28 (JSC::::parseFunctionInfo): 29 * parser/Parser.h: 30 (JSC::Parser::findCachedFunctionInfo): 31 * parser/SyntaxChecker.h: 32 (JSC::SyntaxChecker::setFunctionStart): 33 * runtime/CodeCache.cpp: 34 (JSC::CodeCache::generateFunctionCodeBlock): 35 (JSC::CodeCache::getFunctionCodeBlock): 36 (JSC::CodeCache::usedFunctionCode): 37 * runtime/CodeCache.h: 38 1 39 2012-11-30 Allan Sandfeld Jensen <allan.jensen@digia.com> 2 40 -
trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp
r133975 r136261 67 67 , m_firstLineOffset(node->firstLine() - source.firstLine()) 68 68 , m_lineCount(node->lastLine() - node->firstLine()) 69 , m_functionStartOffset(node->functionStart() - source.startOffset()) 69 70 , m_startOffset(node->source().startOffset() - source.startOffset()) 70 71 , m_sourceLength(node->source().length()) -
trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h
r133975 r136261 99 99 unsigned firstLineOffset() const { return m_firstLineOffset; } 100 100 unsigned lineCount() const { return m_lineCount; } 101 unsigned functionStartOffset() const { return m_functionStartOffset; } 101 102 unsigned startOffset() const { return m_startOffset; } 102 103 unsigned sourceLength() { return m_sourceLength; } … … 154 155 unsigned m_firstLineOffset; 155 156 unsigned m_lineCount; 157 unsigned m_functionStartOffset; 156 158 unsigned m_startOffset; 157 159 unsigned m_sourceLength; -
trunk/Source/JavaScriptCore/parser/ASTBuilder.h
r127987 r136261 268 268 return FunctionBodyNode::create(m_globalData, location, inStrictContext); 269 269 } 270 271 void setFunctionStart(FunctionBodyNode* body, int functionStart) 272 { 273 body->setFunctionStart(functionStart); 274 } 270 275 271 276 template <bool> PropertyNode* createGetterOrSetterProperty(const JSTokenLocation& location, PropertyNode::Type type, const Identifier* name, ParameterNode* params, FunctionBodyNode* body, int openBracePos, int closeBracePos, int bodyStartLine, int bodyEndLine) -
trunk/Source/JavaScriptCore/parser/Nodes.cpp
r129773 r136261 42 42 #include "RegExpObject.h" 43 43 #include "SamplingTool.h" 44 #include "SourceProviderCacheItem.h" 44 45 #include <wtf/Assertions.h> 45 46 #include <wtf/RefCountedLeakCounter.h> -
trunk/Source/JavaScriptCore/parser/Nodes.h
r128234 r136261 47 47 class JSScope; 48 48 class ScopeNode; 49 class SourceProviderCacheItem; 49 50 50 51 typedef unsigned CodeFeatures; … … 1425 1426 FunctionNameIsInScopeToggle functionNameIsInScopeToggle() { return m_functionNameIsInScopeToggle; } 1426 1427 1428 void setFunctionStart(int functionStart) { m_functionStart = functionStart; } 1429 int functionStart() const { return m_functionStart; } 1430 1427 1431 static const bool scopeIsFunction = true; 1428 1432 … … 1435 1439 FunctionNameIsInScopeToggle m_functionNameIsInScopeToggle; 1436 1440 RefPtr<FunctionParameters> m_parameters; 1441 int m_functionStart; 1437 1442 }; 1438 1443 -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r136049 r136261 843 843 844 844 closeBracePos = cachedInfo->closeBracePos; 845 context.setFunctionStart(body, functionStart); 845 846 m_token = cachedInfo->closeBraceToken(); 846 847 m_lexer->setOffset(m_token.m_location.endOffset); … … 870 871 functionScope->saveFunctionInfo(newInfo.get()); 871 872 } 872 873 context.setFunctionStart(body, functionStart); 874 873 875 failIfFalse(popScope(functionScope, TreeBuilder::NeedsFreeVariableInfo)); 874 876 matchOrFail(CLOSEBRACE); -
trunk/Source/JavaScriptCore/parser/Parser.h
r133688 r136261 510 510 ScopeStack m_scopeStack; 511 511 512 const SourceProviderCacheItem* findCachedFunctionInfo(int openBracePos) 512 const SourceProviderCacheItem* findCachedFunctionInfo(int openBracePos) 513 513 { 514 514 return m_functionCache ? m_functionCache->get(openBracePos) : 0; -
trunk/Source/JavaScriptCore/parser/SyntaxChecker.h
r127958 r136261 152 152 ExpressionType createFunctionExpr(const JSTokenLocation&, const Identifier*, int, int, int, int, int, int) { return FunctionExpr; } 153 153 int createFunctionBody(const JSTokenLocation&, bool) { return 1; } 154 void setFunctionStart(int, int) { } 154 155 int createArguments() { return 1; } 155 156 int createArguments(int) { return 1; } -
trunk/Source/JavaScriptCore/runtime/CodeCache.cpp
r133975 r136261 127 127 if (error.m_type != ParserError::ErrorNone) 128 128 return 0; 129 m_ cachedFunctionCode.add(result, Strong<UnlinkedFunctionCodeBlock>(globalData, result));129 m_recentlyUsedFunctionCode.add(result, Strong<UnlinkedFunctionCodeBlock>(globalData, result)); 130 130 return result; 131 131 } … … 133 133 UnlinkedFunctionCodeBlock* CodeCache::getFunctionCodeBlock(JSGlobalData& globalData, UnlinkedFunctionExecutable* executable, const SourceCode& source, CodeSpecializationKind kind, DebuggerMode debuggerMode, ProfilerMode profilerMode, ParserError& error) 134 134 { 135 return generateFunctionCodeBlock(globalData, executable, source, kind, debuggerMode, profilerMode, error); 135 if (debuggerMode == DebuggerOn || profilerMode == ProfilerOn) 136 return generateFunctionCodeBlock(globalData, executable, source, kind, debuggerMode, profilerMode, error); 137 138 SourceCode functionSource(source.provider(), executable->functionStartOffset(), source.endOffset(), source.firstLine()); 139 CodeBlockKey key = makeCodeBlockKey(functionSource, kind == CodeForCall ? FunctionCallType : FunctionConstructType, executable->isInStrictContext() ? JSParseStrict : JSParseNormal); 140 if (const Strong<UnlinkedFunctionCodeBlock>* cacheEntry = m_cachedFunctionExecutables.find(key)) { 141 if (cacheEntry) { 142 UnlinkedFunctionCodeBlock* unlinkedCode = cacheEntry->get(); 143 unsigned firstLine = source.firstLine() + unlinkedCode->firstLine(); 144 executable->recordParse(unlinkedCode->codeFeatures(), unlinkedCode->hasCapturedVariables(), firstLine, firstLine + unlinkedCode->lineCount()); 145 m_recentlyUsedFunctionCode.add(unlinkedCode, *cacheEntry); 146 return unlinkedCode; 147 } 148 } 149 UnlinkedFunctionCodeBlock* result = generateFunctionCodeBlock(globalData, executable, source, kind, debuggerMode, profilerMode, error); 150 m_cachedFunctionExecutables.add(key, Strong<UnlinkedFunctionCodeBlock>(globalData, result)); 151 return result; 136 152 } 137 153 … … 174 190 void CodeCache::usedFunctionCode(JSGlobalData& globalData, UnlinkedFunctionCodeBlock* codeBlock) 175 191 { 176 m_ cachedFunctionCode.add(codeBlock, Strong<UnlinkedFunctionCodeBlock>(globalData, codeBlock));192 m_recentlyUsedFunctionCode.add(codeBlock, Strong<UnlinkedFunctionCodeBlock>(globalData, codeBlock)); 177 193 } 178 194 -
trunk/Source/JavaScriptCore/runtime/CodeCache.h
r134993 r136261 41 41 42 42 class EvalExecutable; 43 class FunctionBodyNode; 43 44 class Identifier; 44 45 class ProgramExecutable; … … 99 100 ~CodeCache(); 100 101 101 enum CodeType { EvalType, ProgramType, Function Type };102 enum CodeType { EvalType, ProgramType, FunctionCallType, FunctionConstructType }; 102 103 typedef std::pair<String, unsigned> CodeBlockKey; 103 104 typedef std::pair<String, String> GlobalFunctionKey; … … 119 120 120 121 CacheMap<CodeBlockKey, Strong<UnlinkedCodeBlock>, kMaxCodeBlockEntries> m_cachedCodeBlocks; 121 CacheMap<GlobalFunctionKey, Strong<UnlinkedFunctionExecutable>, kMaxGlobalFunctionEntries> m_cachedGlobalFunctions; 122 CacheMap<UnlinkedFunctionCodeBlock*, Strong<UnlinkedFunctionCodeBlock>, kMaxFunctionCodeBlocks> m_cachedFunctionCode; 122 CacheMap<CodeBlockKey, Strong<UnlinkedFunctionCodeBlock>, kMaxFunctionCodeBlocks> m_cachedFunctionExecutables; 123 CacheMap<GlobalFunctionKey, Strong<UnlinkedFunctionExecutable>, kMaxFunctionCodeBlocks> m_cachedGlobalFunctions; 124 CacheMap<UnlinkedFunctionCodeBlock*, Strong<UnlinkedFunctionCodeBlock>, kMaxFunctionCodeBlocks> m_recentlyUsedFunctionCode; 123 125 }; 124 126
Note: See TracChangeset
for help on using the changeset viewer.