diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-04-10 09:28:39 +0000 |
commit | 32761a6cee1d0dee366b885b7b9c777e67885688 (patch) | |
tree | d6bec92bebfb216f4126356e55518842c2f476a1 /Source/JavaScriptCore/runtime/CodeCache.h | |
parent | a4e969f4965059196ca948db781e52f7cfebf19e (diff) | |
download | WebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz |
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/JavaScriptCore/runtime/CodeCache.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/CodeCache.h | 113 |
1 files changed, 80 insertions, 33 deletions
diff --git a/Source/JavaScriptCore/runtime/CodeCache.h b/Source/JavaScriptCore/runtime/CodeCache.h index 2132f0c19..f3ff7478d 100644 --- a/Source/JavaScriptCore/runtime/CodeCache.h +++ b/Source/JavaScriptCore/runtime/CodeCache.h @@ -29,34 +29,91 @@ #include "CodeSpecializationKind.h" #include "ParserModes.h" #include "SourceCode.h" -#include "SourceCodeKey.h" #include "Strong.h" -#include "VariableEnvironment.h" +#include "WeakRandom.h" #include <wtf/CurrentTime.h> #include <wtf/Forward.h> +#include <wtf/PassOwnPtr.h> #include <wtf/RandomNumber.h> -#include <wtf/WeakRandom.h> #include <wtf/text/WTFString.h> namespace JSC { class EvalExecutable; -class FunctionMetadataNode; +class FunctionBodyNode; class Identifier; class JSScope; -class ParserError; class ProgramExecutable; -class ModuleProgramExecutable; class UnlinkedCodeBlock; class UnlinkedEvalCodeBlock; -class UnlinkedModuleProgramCodeBlock; class UnlinkedFunctionCodeBlock; class UnlinkedFunctionExecutable; class UnlinkedProgramCodeBlock; class VM; +struct ParserError; class SourceCode; class SourceProvider; +class SourceCodeKey { +public: + enum CodeType { EvalType, ProgramType, FunctionType }; + + SourceCodeKey() + { + } + + SourceCodeKey(const SourceCode& sourceCode, const String& name, CodeType codeType, JSParserStrictness jsParserStrictness) + : m_sourceCode(sourceCode) + , m_name(name) + , m_flags((codeType << 1) | jsParserStrictness) + , m_hash(string().impl()->hash()) + { + } + + SourceCodeKey(WTF::HashTableDeletedValueType) + : m_sourceCode(WTF::HashTableDeletedValue) + { + } + + bool isHashTableDeletedValue() const { return m_sourceCode.isHashTableDeletedValue(); } + + unsigned hash() const { return m_hash; } + + size_t length() const { return m_sourceCode.length(); } + + bool isNull() const { return m_sourceCode.isNull(); } + + // To save memory, we compute our string on demand. It's expected that source + // providers cache their strings to make this efficient. + String string() const { return m_sourceCode.toString(); } + + bool operator==(const SourceCodeKey& other) const + { + return m_hash == other.m_hash + && length() == other.length() + && m_flags == other.m_flags + && m_name == other.m_name + && string() == other.string(); + } + +private: + SourceCode m_sourceCode; + String m_name; + unsigned m_flags; + unsigned m_hash; +}; + +struct SourceCodeKeyHash { + static unsigned hash(const SourceCodeKey& key) { return key.hash(); } + static bool equal(const SourceCodeKey& a, const SourceCodeKey& b) { return a == b; } + static const bool safeToCompareToEmptyOrDeleted = false; +}; + +struct SourceCodeKeyHashTraits : SimpleClassHashTraits<SourceCodeKey> { + static const bool hasIsEmptyValueFunction = true; + static bool isEmptyValue(const SourceCodeKey& sourceCodeKey) { return sourceCodeKey.isNull(); } +}; + struct SourceCodeValue { SourceCodeValue() { @@ -88,15 +145,18 @@ public: { } - SourceCodeValue* findCacheAndUpdateAge(const SourceCodeKey& key) + AddResult add(const SourceCodeKey& key, const SourceCodeValue& value) { prune(); - iterator findResult = m_map.find(key); - if (findResult == m_map.end()) - return nullptr; + AddResult addResult = m_map.add(key, value); + if (addResult.isNewEntry) { + m_size += key.length(); + m_age += key.length(); + return addResult; + } - int64_t age = m_age - findResult->value.age; + int64_t age = m_age - addResult.iterator->value.age; if (age > m_capacity) { // A requested object is older than the cache's capacity. We can // infer that requested objects are subject to high eviction probability, @@ -111,20 +171,7 @@ public: m_capacity = m_minCapacity; } - findResult->value.age = m_age; - m_age += key.length(); - - return &findResult->value; - } - - AddResult addCache(const SourceCodeKey& key, const SourceCodeValue& value) - { - prune(); - - AddResult addResult = m_map.add(key, value); - ASSERT(addResult.isNewEntry); - - m_size += key.length(); + addResult.iterator->value.age = m_age; m_age += key.length(); return addResult; } @@ -188,15 +235,13 @@ private: // Caches top-level code such as <script>, eval(), new Function, and JSEvaluateScript(). class CodeCache { - WTF_MAKE_FAST_ALLOCATED; public: - CodeCache(); - ~CodeCache(); + static PassOwnPtr<CodeCache> create() { return adoptPtr(new CodeCache); } - UnlinkedProgramCodeBlock* getProgramCodeBlock(VM&, ProgramExecutable*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, DebuggerMode, ProfilerMode, ParserError&); - UnlinkedEvalCodeBlock* getEvalCodeBlock(VM&, EvalExecutable*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, ThisTDZMode, bool, DebuggerMode, ProfilerMode, ParserError&, const VariableEnvironment*); - UnlinkedModuleProgramCodeBlock* getModuleProgramCodeBlock(VM&, ModuleProgramExecutable*, const SourceCode&, JSParserBuiltinMode, DebuggerMode, ProfilerMode, ParserError&); + UnlinkedProgramCodeBlock* getProgramCodeBlock(VM&, ProgramExecutable*, const SourceCode&, JSParserStrictness, DebuggerMode, ProfilerMode, ParserError&); + UnlinkedEvalCodeBlock* getEvalCodeBlock(VM&, EvalExecutable*, const SourceCode&, JSParserStrictness, DebuggerMode, ProfilerMode, ParserError&); UnlinkedFunctionExecutable* getFunctionExecutableFromGlobalCode(VM&, const Identifier&, const SourceCode&, ParserError&); + ~CodeCache(); void clear() { @@ -204,8 +249,10 @@ public: } private: + CodeCache(); + template <class UnlinkedCodeBlockType, class ExecutableType> - UnlinkedCodeBlockType* getGlobalCodeBlock(VM&, ExecutableType*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, ThisTDZMode, bool, DebuggerMode, ProfilerMode, ParserError&, const VariableEnvironment*); + UnlinkedCodeBlockType* getGlobalCodeBlock(VM&, ExecutableType*, const SourceCode&, JSParserStrictness, DebuggerMode, ProfilerMode, ParserError&); CodeCacheMap m_sourceCode; }; |