X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/f9bf01c6616d5ddcf65b13b33cedf9e387ff7a63..93a3786624b2768d89bfa27e46598dc64e2fb70a:/bytecode/EvalCodeCache.h diff --git a/bytecode/EvalCodeCache.h b/bytecode/EvalCodeCache.h index 05834fc..5d04637 100644 --- a/bytecode/EvalCodeCache.h +++ b/bytecode/EvalCodeCache.h @@ -31,44 +31,62 @@ #include "Executable.h" #include "JSGlobalObject.h" -#include "Nodes.h" -#include "Parser.h" #include "SourceCode.h" -#include "UString.h" #include #include +#include namespace JSC { + class CodeCache; + class SlotVisitor; + class EvalCodeCache { public: - PassRefPtr get(ExecState* exec, const UString& evalSource, ScopeChainNode* scopeChain, JSValue& exceptionValue) + EvalExecutable* tryGet(bool inStrictContext, const String& evalSource, JSScope* scope) { - RefPtr evalExecutable; - - if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject()) - evalExecutable = m_cacheMap.get(evalSource.rep()); + if (!inStrictContext && evalSource.length() < maxCacheableSourceLength && scope->begin()->isVariableObject()) + return m_cacheMap.get(evalSource.impl()).get(); + return 0; + } + + EvalExecutable* getSlow(ExecState* exec, CodeCache* codeCache, ScriptExecutable* owner, bool inStrictContext, const String& evalSource, JSScope* scope, JSValue& exceptionValue) + { + EvalExecutable* evalExecutable = EvalExecutable::create(exec, codeCache, makeSource(evalSource), inStrictContext); + exceptionValue = evalExecutable->compile(exec, scope); + if (exceptionValue) + return 0; + + if (!inStrictContext && evalSource.length() < maxCacheableSourceLength && scope->begin()->isVariableObject() && m_cacheMap.size() < maxCacheEntries) + m_cacheMap.set(evalSource.impl(), WriteBarrier(exec->vm(), owner, evalExecutable)); + + return evalExecutable; + } - if (!evalExecutable) { - evalExecutable = EvalExecutable::create(exec, makeSource(evalSource)); - exceptionValue = evalExecutable->compile(exec, scopeChain); - if (exceptionValue) - return 0; + EvalExecutable* get(ExecState* exec, CodeCache* codeCache, ScriptExecutable* owner, bool inStrictContext, const String& evalSource, JSScope* scope, JSValue& exceptionValue) + { + EvalExecutable* evalExecutable = tryGet(inStrictContext, evalSource, scope); - if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject() && m_cacheMap.size() < maxCacheEntries) - m_cacheMap.set(evalSource.rep(), evalExecutable); - } + if (!evalExecutable) + evalExecutable = getSlow(exec, codeCache, owner, inStrictContext, evalSource, scope, exceptionValue); - return evalExecutable.release(); + return evalExecutable; } bool isEmpty() const { return m_cacheMap.isEmpty(); } + void visitAggregate(SlotVisitor&); + + void clear() + { + m_cacheMap.clear(); + } + private: - static const int maxCacheableSourceLength = 256; + static const unsigned maxCacheableSourceLength = 256; static const int maxCacheEntries = 64; - typedef HashMap, RefPtr > EvalCacheMap; + typedef HashMap, WriteBarrier > EvalCacheMap; EvalCacheMap m_cacheMap; };