5 #ifndef V8_OBJECTS_COMPILATION_CACHE_INL_H_ 6 #define V8_OBJECTS_COMPILATION_CACHE_INL_H_ 8 #include "src/objects/compilation-cache.h" 10 #include "src/objects/name-inl.h" 11 #include "src/objects/script-inl.h" 12 #include "src/objects/shared-function-info.h" 13 #include "src/objects/smi.h" 14 #include "src/objects/string.h" 17 #include "src/objects/object-macros.h" 22 CompilationCacheTable::CompilationCacheTable(Address ptr)
23 : HashTable<CompilationCacheTable, CompilationCacheShape>(ptr) {
24 SLOW_DCHECK(IsCompilationCacheTable());
27 NEVER_READ_ONLY_SPACE_IMPL(CompilationCacheTable)
28 CAST_ACCESSOR2(CompilationCacheTable)
30 uint32_t CompilationCacheShape::RegExpHash(String
string, Smi flags) {
31 return string->Hash() + flags->value();
34 uint32_t CompilationCacheShape::StringSharedHash(String source,
35 SharedFunctionInfo* shared,
36 LanguageMode language_mode,
39 if (shared->HasSourceCode()) {
45 Script* script(Script::cast(shared->script()));
46 hash ^= String::cast(script->source())->Hash();
47 STATIC_ASSERT(LanguageModeSize == 2);
48 if (is_strict(language_mode)) hash ^= 0x8000;
54 uint32_t CompilationCacheShape::HashForObject(Isolate* isolate,
56 if (object->IsNumber())
return static_cast<uint32_t>(object->Number());
58 FixedArray val = FixedArray::cast(
object);
59 if (val->map() == val->GetReadOnlyRoots().fixed_cow_array_map()) {
60 DCHECK_EQ(4, val->length());
61 SharedFunctionInfo* shared = SharedFunctionInfo::cast(val->get(0));
62 String source = String::cast(val->get(1));
63 int language_unchecked = Smi::ToInt(val->get(2));
64 DCHECK(is_valid_language_mode(language_unchecked));
65 LanguageMode language_mode =
static_cast<LanguageMode
>(language_unchecked);
66 int position = Smi::ToInt(val->get(3));
67 return StringSharedHash(source, shared, language_mode, position);
69 DCHECK_LT(2, val->length());
70 return RegExpHash(String::cast(val->get(JSRegExp::kSourceIndex)),
71 Smi::cast(val->get(JSRegExp::kFlagsIndex)));
77 #include "src/objects/object-macros-undef.h" 79 #endif // V8_OBJECTS_COMPILATION_CACHE_INL_H_