Commit 446dffa4 authored by ggaren@apple.com's avatar ggaren@apple.com

Some renaming in the CodeCache

https://bugs.webkit.org/show_bug.cgi?id=105966

Reviewed by Gavin Barraclough.

CodeBlockKey => SourceCodeKey because the key is not a CodeBlock.

m_recentlyUsedFunctionCode => m_recentlyUsedFunctions to match other names.

GlobalFunctionKey => FunctionKey because the key is not unique to globalness.

m_cachedGlobalFunctions => m_globalFunctions because "cached" is redundant
for data members in an object called "CodeCache".

kMaxRootCodeBlockEntries => kMaxRootEntries because there are no non-CodeBlock
entries in a CodeBlock cache.

kMaxFunctionCodeBlocks => kMaxChildFunctionEntries to clarify that this
number models a parent-child relationship.

Also removed the initial "k" from enum constants. That's an interesting
style for calling out constants, but it's not the WebKit style.

Finally, a behavior change: Use MaxRootEntries for the limit on global
functions, and not MaxChildFunctionEntries. Previously, there was an
unused constant that seemed to have been intended for this purpose.

* runtime/CodeCache.cpp:
(JSC::CodeCache::makeSourceCodeKey):
(JSC::CodeCache::getCodeBlock):
(JSC::CodeCache::generateFunctionCodeBlock):
(JSC::CodeCache::makeFunctionKey):
(JSC::CodeCache::getFunctionExecutableFromGlobalCode):
(JSC::CodeCache::usedFunctionCode):
* runtime/CodeCache.h:
(JSC::CodeCache::clear):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@138675 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f53e9e37
2013-01-02 Geoffrey Garen <ggaren@apple.com>
Some renaming in the CodeCache
https://bugs.webkit.org/show_bug.cgi?id=105966
Reviewed by Gavin Barraclough.
CodeBlockKey => SourceCodeKey because the key is not a CodeBlock.
m_recentlyUsedFunctionCode => m_recentlyUsedFunctions to match other names.
GlobalFunctionKey => FunctionKey because the key is not unique to globalness.
m_cachedGlobalFunctions => m_globalFunctions because "cached" is redundant
for data members in an object called "CodeCache".
kMaxRootCodeBlockEntries => kMaxRootEntries because there are no non-CodeBlock
entries in a CodeBlock cache.
kMaxFunctionCodeBlocks => kMaxChildFunctionEntries to clarify that this
number models a parent-child relationship.
Also removed the initial "k" from enum constants. That's an interesting
style for calling out constants, but it's not the WebKit style.
Finally, a behavior change: Use MaxRootEntries for the limit on global
functions, and not MaxChildFunctionEntries. Previously, there was an
unused constant that seemed to have been intended for this purpose.
* runtime/CodeCache.cpp:
(JSC::CodeCache::makeSourceCodeKey):
(JSC::CodeCache::getCodeBlock):
(JSC::CodeCache::generateFunctionCodeBlock):
(JSC::CodeCache::makeFunctionKey):
(JSC::CodeCache::getFunctionExecutableFromGlobalCode):
(JSC::CodeCache::usedFunctionCode):
* runtime/CodeCache.h:
(JSC::CodeCache::clear):
2013-01-02 Filip Pizlo <fpizlo@apple.com>
DFG inlining machinery should be robust against the inline callee varying while the executable stays the same
......
......@@ -43,7 +43,7 @@ CodeCache::~CodeCache()
{
}
CodeCache::CodeBlockKey CodeCache::makeCodeBlockKey(const SourceCode& source, CodeCache::CodeType type, JSParserStrictness strictness)
CodeCache::SourceCodeKey CodeCache::makeSourceCodeKey(const SourceCode& source, CodeCache::CodeType type, JSParserStrictness strictness)
{
return std::make_pair(source.toString(), (type << 1) | strictness);
}
......@@ -63,10 +63,10 @@ template <> struct CacheTypes<UnlinkedEvalCodeBlock> {
template <class UnlinkedCodeBlockType, class ExecutableType>
UnlinkedCodeBlockType* CodeCache::getCodeBlock(JSGlobalData& globalData, ExecutableType* executable, const SourceCode& source, JSParserStrictness strictness, DebuggerMode debuggerMode, ProfilerMode profilerMode, ParserError& error)
{
CodeBlockKey key = makeCodeBlockKey(source, CacheTypes<UnlinkedCodeBlockType>::codeType, strictness);
SourceCodeKey key = makeSourceCodeKey(source, CacheTypes<UnlinkedCodeBlockType>::codeType, strictness);
bool storeInCache = false;
if (debuggerMode == DebuggerOff && profilerMode == ProfilerOff) {
const Strong<UnlinkedCodeBlock>* result = m_cachedCodeBlocks.find(key);
const Strong<UnlinkedCodeBlock>* result = m_sourceCode.find(key);
if (result) {
UnlinkedCodeBlockType* unlinkedCode = jsCast<UnlinkedCodeBlockType*>(result->get());
unsigned firstLine = source.firstLine() + unlinkedCode->firstLine();
......@@ -91,7 +91,7 @@ UnlinkedCodeBlockType* CodeCache::getCodeBlock(JSGlobalData& globalData, Executa
return 0;
if (storeInCache)
m_cachedCodeBlocks.add(key, Strong<UnlinkedCodeBlock>(globalData, unlinkedCode));
m_sourceCode.add(key, Strong<UnlinkedCodeBlock>(globalData, unlinkedCode));
return unlinkedCode;
}
......@@ -126,7 +126,7 @@ UnlinkedFunctionCodeBlock* CodeCache::generateFunctionCodeBlock(JSGlobalData& gl
body->destroyData();
if (error.m_type != ParserError::ErrorNone)
return 0;
m_recentlyUsedFunctionCode.add(result, Strong<UnlinkedFunctionCodeBlock>(globalData, result));
m_recentlyUsedFunctions.add(result, Strong<UnlinkedFunctionCodeBlock>(globalData, result));
return result;
}
......@@ -135,15 +135,15 @@ UnlinkedFunctionCodeBlock* CodeCache::getFunctionCodeBlock(JSGlobalData& globalD
return generateFunctionCodeBlock(globalData, executable, source, kind, debuggerMode, profilerMode, error);
}
CodeCache::GlobalFunctionKey CodeCache::makeGlobalFunctionKey(const SourceCode& source, const String& name)
CodeCache::FunctionKey CodeCache::makeFunctionKey(const SourceCode& source, const String& name)
{
return GlobalFunctionKey(source.toString(), name);
return FunctionKey(source.toString(), name);
}
UnlinkedFunctionExecutable* CodeCache::getFunctionExecutableFromGlobalCode(JSGlobalData& globalData, const Identifier& name, const SourceCode& source, ParserError& error)
{
GlobalFunctionKey key = makeGlobalFunctionKey(source, name.string());
const Strong<UnlinkedFunctionExecutable>* result = m_cachedGlobalFunctions.find(key);
FunctionKey key = makeFunctionKey(source, name.string());
const Strong<UnlinkedFunctionExecutable>* result = m_globalFunctions.find(key);
if (result)
return result->get();
......@@ -167,13 +167,13 @@ UnlinkedFunctionExecutable* CodeCache::getFunctionExecutableFromGlobalCode(JSGlo
UnlinkedFunctionExecutable* functionExecutable = UnlinkedFunctionExecutable::create(&globalData, source, body);
functionExecutable->m_nameValue.set(globalData, functionExecutable, jsString(&globalData, name.string()));
m_cachedGlobalFunctions.add(key, Strong<UnlinkedFunctionExecutable>(globalData, functionExecutable));
m_globalFunctions.add(key, Strong<UnlinkedFunctionExecutable>(globalData, functionExecutable));
return functionExecutable;
}
void CodeCache::usedFunctionCode(JSGlobalData& globalData, UnlinkedFunctionCodeBlock* codeBlock)
{
m_recentlyUsedFunctionCode.add(codeBlock, Strong<UnlinkedFunctionCodeBlock>(globalData, codeBlock));
m_recentlyUsedFunctions.add(codeBlock, Strong<UnlinkedFunctionCodeBlock>(globalData, codeBlock));
}
}
......@@ -112,14 +112,14 @@ public:
void clear()
{
m_cachedCodeBlocks.clear();
m_cachedGlobalFunctions.clear();
m_recentlyUsedFunctionCode.clear();
m_sourceCode.clear();
m_globalFunctions.clear();
m_recentlyUsedFunctions.clear();
}
enum CodeType { EvalType, ProgramType, FunctionCallType, FunctionConstructType };
typedef std::pair<String, unsigned> CodeBlockKey;
typedef std::pair<String, String> GlobalFunctionKey;
typedef std::pair<String, unsigned> SourceCodeKey;
typedef std::pair<String, String> FunctionKey;
private:
CodeCache();
......@@ -127,24 +127,17 @@ private:
UnlinkedFunctionCodeBlock* generateFunctionCodeBlock(JSGlobalData&, UnlinkedFunctionExecutable*, const SourceCode&, CodeSpecializationKind, DebuggerMode, ProfilerMode, ParserError&);
template <class UnlinkedCodeBlockType, class ExecutableType> inline UnlinkedCodeBlockType* getCodeBlock(JSGlobalData&, ExecutableType*, const SourceCode&, JSParserStrictness, DebuggerMode, ProfilerMode, ParserError&);
CodeBlockKey makeCodeBlockKey(const SourceCode&, CodeType, JSParserStrictness);
GlobalFunctionKey makeGlobalFunctionKey(const SourceCode&, const String&);
SourceCodeKey makeSourceCodeKey(const SourceCode&, CodeType, JSParserStrictness);
FunctionKey makeFunctionKey(const SourceCode&, const String&);
enum {
kMaxRootCodeBlockEntries = 1024,
kMaxGlobalFunctionEntries = 1024,
// Sampling content on a number of sites indicates that
// on average there are 6-7 functions used per root codeblock.
// So we'll allow an average of 8 to give some leeway for increasing
// page complexity over time. Note that is simply a probabalistic
// measure and does not result in a hard limit of cache entries
// in each code block.
kMaxFunctionCodeBlocks = kMaxRootCodeBlockEntries * 8
MaxRootEntries = 1024, // Top-level code such as <script>, eval(), JSEvaluateScript(), etc.
MaxChildFunctionEntries = MaxRootEntries * 8 // Sampling shows that each root holds about 6 functions. 8 is enough to usually cache all the child functions for each top-level entry.
};
CacheMap<CodeBlockKey, Strong<UnlinkedCodeBlock>, kMaxRootCodeBlockEntries> m_cachedCodeBlocks;
CacheMap<GlobalFunctionKey, Strong<UnlinkedFunctionExecutable>, kMaxFunctionCodeBlocks> m_cachedGlobalFunctions;
CacheMap<UnlinkedFunctionCodeBlock*, Strong<UnlinkedFunctionCodeBlock>, kMaxFunctionCodeBlocks> m_recentlyUsedFunctionCode;
CacheMap<SourceCodeKey, Strong<UnlinkedCodeBlock>, MaxRootEntries> m_sourceCode;
CacheMap<FunctionKey, Strong<UnlinkedFunctionExecutable>, MaxRootEntries> m_globalFunctions;
CacheMap<UnlinkedFunctionCodeBlock*, Strong<UnlinkedFunctionCodeBlock>, MaxChildFunctionEntries> m_recentlyUsedFunctions;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment