]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - bytecode/EvalCodeCache.h
JavaScriptCore-1218.tar.gz
[apple/javascriptcore.git] / bytecode / EvalCodeCache.h
index 27c479d4e51c12fb3df93d671f5690a00bfaae39..5d04637f439e56c1e9b24e11fb2cd5c89533279b 100644 (file)
 
 #include "Executable.h"
 #include "JSGlobalObject.h"
-#include "Nodes.h"
-#include "Parser.h"
 #include "SourceCode.h"
-#include "UString.h"
 #include <wtf/HashMap.h>
 #include <wtf/RefPtr.h>
 #include <wtf/text/StringHash.h>
 
 namespace JSC {
 
+    class CodeCache;
+    class SlotVisitor;
+
     class EvalCodeCache {
     public:
-        PassRefPtr<EvalExecutable> get(ExecState* exec, const UString& evalSource, ScopeChainNode* scopeChain, JSValue& exceptionValue)
+        EvalExecutable* tryGet(bool inStrictContext, const String& evalSource, JSScope* scope)
         {
-            RefPtr<EvalExecutable> 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<EvalExecutable>(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 unsigned maxCacheableSourceLength = 256;
         static const int maxCacheEntries = 64;
 
-        typedef HashMap<RefPtr<UString::Rep>, RefPtr<EvalExecutable> > EvalCacheMap;
+        typedef HashMap<RefPtr<StringImpl>, WriteBarrier<EvalExecutable> > EvalCacheMap;
         EvalCacheMap m_cacheMap;
     };