summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/CodeCache.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-05-24 08:28:08 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-05-24 08:28:08 +0000
commita4e969f4965059196ca948db781e52f7cfebf19e (patch)
tree6ca352808c8fdc52006a0f33f6ae3c593b23867d /Source/JavaScriptCore/runtime/CodeCache.h
parent41386e9cb918eed93b3f13648cbef387e371e451 (diff)
downloadWebKitGtk-tarball-a4e969f4965059196ca948db781e52f7cfebf19e.tar.gz
webkitgtk-2.12.3webkitgtk-2.12.3
Diffstat (limited to 'Source/JavaScriptCore/runtime/CodeCache.h')
-rw-r--r--Source/JavaScriptCore/runtime/CodeCache.h113
1 files changed, 33 insertions, 80 deletions
diff --git a/Source/JavaScriptCore/runtime/CodeCache.h b/Source/JavaScriptCore/runtime/CodeCache.h
index f3ff7478d..2132f0c19 100644
--- a/Source/JavaScriptCore/runtime/CodeCache.h
+++ b/Source/JavaScriptCore/runtime/CodeCache.h
@@ -29,91 +29,34 @@
#include "CodeSpecializationKind.h"
#include "ParserModes.h"
#include "SourceCode.h"
+#include "SourceCodeKey.h"
#include "Strong.h"
-#include "WeakRandom.h"
+#include "VariableEnvironment.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 FunctionBodyNode;
+class FunctionMetadataNode;
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()
{
@@ -145,18 +88,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 +111,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;
}
@@ -235,13 +188,15 @@ private:
// Caches top-level code such as <script>, eval(), new Function, and JSEvaluateScript().
class CodeCache {
+ WTF_MAKE_FAST_ALLOCATED;
public:
- static PassOwnPtr<CodeCache> create() { return adoptPtr(new CodeCache); }
+ CodeCache();
+ ~CodeCache();
- UnlinkedProgramCodeBlock* getProgramCodeBlock(VM&, ProgramExecutable*, const SourceCode&, JSParserStrictness, DebuggerMode, ProfilerMode, ParserError&);
- UnlinkedEvalCodeBlock* getEvalCodeBlock(VM&, EvalExecutable*, const SourceCode&, JSParserStrictness, DebuggerMode, ProfilerMode, ParserError&);
+ 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&);
UnlinkedFunctionExecutable* getFunctionExecutableFromGlobalCode(VM&, const Identifier&, const SourceCode&, ParserError&);
- ~CodeCache();
void clear()
{
@@ -249,10 +204,8 @@ public:
}
private:
- CodeCache();
-
template <class UnlinkedCodeBlockType, class ExecutableType>
- UnlinkedCodeBlockType* getGlobalCodeBlock(VM&, ExecutableType*, const SourceCode&, JSParserStrictness, DebuggerMode, ProfilerMode, ParserError&);
+ UnlinkedCodeBlockType* getGlobalCodeBlock(VM&, ExecutableType*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, ThisTDZMode, bool, DebuggerMode, ProfilerMode, ParserError&, const VariableEnvironment*);
CodeCacheMap m_sourceCode;
};