From 32761a6cee1d0dee366b885b7b9c777e67885688 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Sun, 10 Apr 2016 09:28:39 +0000 Subject: webkitgtk-2.4.11 --- Source/JavaScriptCore/runtime/CodeCache.h | 113 +++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 33 deletions(-) (limited to 'Source/JavaScriptCore/runtime/CodeCache.h') 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 #include +#include #include -#include #include 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 { + 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