#include "WeakRandom.h"
#include <wtf/CurrentTime.h>
#include <wtf/Forward.h>
-#include <wtf/PassOwnPtr.h>
#include <wtf/RandomNumber.h>
#include <wtf/text/WTFString.h>
class FunctionBodyNode;
class Identifier;
class JSScope;
+class ParserError;
class ProgramExecutable;
class UnlinkedCodeBlock;
class UnlinkedEvalCodeBlock;
class UnlinkedFunctionExecutable;
class UnlinkedProgramCodeBlock;
class VM;
-struct ParserError;
class SourceCode;
class SourceProvider;
{
}
- SourceCodeKey(const SourceCode& sourceCode, const String& name, CodeType codeType, JSParserStrictness jsParserStrictness)
+ SourceCodeKey(const SourceCode& sourceCode, const String& name, CodeType codeType, JSParserBuiltinMode builtinMode,
+ JSParserStrictMode strictMode, ThisTDZMode thisTDZMode = ThisTDZMode::CheckIfNeeded)
: m_sourceCode(sourceCode)
, m_name(name)
- , m_flags((codeType << 2) | jsParserStrictness)
+ , m_flags(
+ (static_cast<unsigned>(codeType) << 3)
+ | (static_cast<unsigned>(builtinMode) << 2)
+ | (static_cast<unsigned>(strictMode) << 1)
+ | static_cast<unsigned>(thisTDZMode))
, m_hash(string().impl()->hash())
{
}
{
}
- 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,
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;
}
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, DebuggerMode, ProfilerMode, ParserError&);
UnlinkedFunctionExecutable* getFunctionExecutableFromGlobalCode(VM&, const Identifier&, const SourceCode&, ParserError&);
- ~CodeCache();
void clear()
{
}
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, DebuggerMode, ProfilerMode, ParserError&);
CodeCacheMap m_sourceCode;
};