Changeset 198778 in webkit for trunk/Source/JavaScriptCore/bytecode/EvalCodeCache.h
- Timestamp:
- Mar 29, 2016, 3:25:44 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/bytecode/EvalCodeCache.h
r194449 r198778 35 35 #include "Options.h" 36 36 #include "SourceCode.h" 37 #include "SourceCodeKey.h"38 37 #include <wtf/HashMap.h> 39 38 #include <wtf/RefPtr.h> … … 46 45 class EvalCodeCache { 47 46 public: 48 EvalExecutable* tryGet(bool inStrictContext, const SourceCode& evalSource, ThisTDZMode thisTDZMode, JSScope* scope) 47 class CacheKey { 48 public: 49 CacheKey(const String& source, bool isArrowFunctionContext) 50 : m_source(source.impl()) 51 , m_isArrowFunctionContext(isArrowFunctionContext) 52 { 53 } 54 55 CacheKey(WTF::HashTableDeletedValueType) 56 : m_source(WTF::HashTableDeletedValue) 57 { 58 } 59 60 CacheKey() = default; 61 62 unsigned hash() const { return m_source->hash(); } 63 64 bool isEmptyValue() const { return !m_source; } 65 66 bool operator==(const CacheKey& other) const 67 { 68 return m_source == other.m_source && m_isArrowFunctionContext == other.m_isArrowFunctionContext; 69 } 70 71 bool isHashTableDeletedValue() const { return m_source.isHashTableDeletedValue(); } 72 73 struct Hash { 74 static unsigned hash(const CacheKey& key) 75 { 76 return key.hash(); 77 } 78 static bool equal(const CacheKey& lhs, const CacheKey& rhs) 79 { 80 return StringHash::equal(lhs.m_source, rhs.m_source) && lhs.m_isArrowFunctionContext == rhs.m_isArrowFunctionContext; 81 } 82 static const bool safeToCompareToEmptyOrDeleted = false; 83 }; 84 85 typedef SimpleClassHashTraits<CacheKey> HashTraits; 86 87 private: 88 RefPtr<StringImpl> m_source; 89 bool m_isArrowFunctionContext { false }; 90 }; 91 92 EvalExecutable* tryGet(bool inStrictContext, const String& evalSource, bool isArrowFunctionContext, JSScope* scope) 49 93 { 50 94 if (isCacheable(inStrictContext, evalSource, scope)) { 51 95 ASSERT(!inStrictContext); 52 SourceCodeKey sourceCodeKey(evalSource, String(), SourceCodeKey::EvalType, JSParserBuiltinMode::NotBuiltin, JSParserStrictMode::NotStrict, thisTDZMode); 53 return m_cacheMap.get(sourceCodeKey).get(); 96 return m_cacheMap.fastGet(CacheKey(evalSource, isArrowFunctionContext)).get(); 54 97 } 55 98 return nullptr; 56 99 } 57 100 58 EvalExecutable* getSlow(ExecState* exec, JSCell* owner, bool inStrictContext, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isArrowFunctionContext, const S ourceCode& evalSource, JSScope* scope)101 EvalExecutable* getSlow(ExecState* exec, JSCell* owner, bool inStrictContext, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isArrowFunctionContext, const String& evalSource, JSScope* scope) 59 102 { 60 103 VariableEnvironment variablesUnderTDZ; 61 104 JSScope::collectVariablesUnderTDZ(scope, variablesUnderTDZ); 62 EvalExecutable* evalExecutable = EvalExecutable::create(exec, evalSource, inStrictContext, thisTDZMode, derivedContextType, isArrowFunctionContext, &variablesUnderTDZ); 63 105 EvalExecutable* evalExecutable = EvalExecutable::create(exec, makeSource(evalSource), inStrictContext, thisTDZMode, derivedContextType, isArrowFunctionContext, &variablesUnderTDZ); 64 106 if (!evalExecutable) 65 107 return nullptr; … … 67 109 if (isCacheable(inStrictContext, evalSource, scope) && m_cacheMap.size() < maxCacheEntries) { 68 110 ASSERT(!inStrictContext); 69 SourceCodeKey sourceCodeKey(evalSource, String(), SourceCodeKey::EvalType, JSParserBuiltinMode::NotBuiltin, JSParserStrictMode::NotStrict, thisTDZMode); 70 m_cacheMap.set(sourceCodeKey, WriteBarrier<EvalExecutable>(exec->vm(), owner, evalExecutable)); 111 ASSERT_WITH_MESSAGE(thisTDZMode == ThisTDZMode::CheckIfNeeded, "Always CheckIfNeeded because the caching is enabled only in the sloppy mode."); 112 ASSERT_WITH_MESSAGE(derivedContextType == DerivedContextType::None, "derivedContextType is always None because class methods and class constructors are always evaluated as the strict code."); 113 m_cacheMap.set(CacheKey(evalSource, isArrowFunctionContext), WriteBarrier<EvalExecutable>(exec->vm(), owner, evalExecutable)); 71 114 } 72 115 … … 89 132 } 90 133 91 ALWAYS_INLINE bool isCacheable(bool inStrictContext, const S ourceCode& evalSource, JSScope* scope)134 ALWAYS_INLINE bool isCacheable(bool inStrictContext, const String& evalSource, JSScope* scope) 92 135 { 93 136 // If eval() is called and it has access to a lexical scope, we can't soundly cache it. … … 99 142 static const int maxCacheEntries = 64; 100 143 101 typedef HashMap< SourceCodeKey, WriteBarrier<EvalExecutable>, SourceCodeKeyHash, SourceCodeKeyHashTraits> EvalCacheMap;144 typedef HashMap<CacheKey, WriteBarrier<EvalExecutable>, CacheKey::Hash, CacheKey::HashTraits> EvalCacheMap; 102 145 EvalCacheMap m_cacheMap; 103 146 };
Note:
See TracChangeset
for help on using the changeset viewer.