From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/JavaScriptCore/runtime/CodeCache.h | 195 +++++++++++++++--------------- 1 file changed, 97 insertions(+), 98 deletions(-) (limited to 'Source/JavaScriptCore/runtime/CodeCache.h') diff --git a/Source/JavaScriptCore/runtime/CodeCache.h b/Source/JavaScriptCore/runtime/CodeCache.h index f3ff7478d..b4ab8e56c 100644 --- a/Source/JavaScriptCore/runtime/CodeCache.h +++ b/Source/JavaScriptCore/runtime/CodeCache.h @@ -23,96 +23,42 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CodeCache_h -#define CodeCache_h +#pragma once -#include "CodeSpecializationKind.h" +#include "BytecodeGenerator.h" +#include "ExecutableInfo.h" +#include "JSCInlines.h" +#include "Parser.h" #include "ParserModes.h" -#include "SourceCode.h" +#include "SourceCodeKey.h" #include "Strong.h" -#include "WeakRandom.h" +#include "StrongInlines.h" +#include "UnlinkedCodeBlock.h" +#include "UnlinkedEvalCodeBlock.h" +#include "UnlinkedModuleProgramCodeBlock.h" +#include "UnlinkedProgramCodeBlock.h" +#include "UnlinkedSourceCode.h" #include #include -#include -#include #include namespace JSC { class EvalExecutable; -class FunctionBodyNode; +class IndirectEvalExecutable; class Identifier; -class JSScope; +class DirectEvalExecutable; +class ModuleProgramExecutable; +class ParserError; class ProgramExecutable; +class SourceCode; class UnlinkedCodeBlock; class UnlinkedEvalCodeBlock; -class UnlinkedFunctionCodeBlock; class UnlinkedFunctionExecutable; +class UnlinkedModuleProgramCodeBlock; 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(); } -}; +class VariableEnvironment; struct SourceCodeValue { SourceCodeValue() @@ -131,7 +77,7 @@ struct SourceCodeValue { class CodeCacheMap { public: - typedef HashMap MapType; + typedef HashMap MapType; typedef MapType::iterator iterator; typedef MapType::AddResult AddResult; @@ -145,18 +91,15 @@ public: { } - AddResult add(const SourceCodeKey& key, const SourceCodeValue& value) + SourceCodeValue* findCacheAndUpdateAge(const SourceCodeKey& key) { prune(); - AddResult addResult = m_map.add(key, value); - if (addResult.isNewEntry) { - m_size += key.length(); - m_age += key.length(); - return addResult; - } + iterator findResult = m_map.find(key); + if (findResult == m_map.end()) + return nullptr; - int64_t age = m_age - addResult.iterator->value.age; + int64_t age = m_age - findResult->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, @@ -171,7 +114,20 @@ public: m_capacity = m_minCapacity; } - addResult.iterator->value.age = m_age; + 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(); m_age += key.length(); return addResult; } @@ -233,30 +189,73 @@ private: int64_t m_age; }; -// Caches top-level code such as