Changeset 188824 in webkit
- Timestamp:
- Aug 22, 2015, 11:05:50 AM (10 years ago)
- Location:
- trunk/Source
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r188810 r188824 1 2015-08-22 Andreas Kling <[email protected]> 2 3 [JSC] Static hash tables should be 100% compile-time constant. 4 <https://webkit.org/b/148359> 5 6 Reviewed by Michael Saboff. 7 8 We were dirtying the memory pages containing static hash tables the 9 first time they were used, when a dynamically allocated index-to-key 10 table was built and cached in the HashTable struct. 11 12 It turns out that this "optimization" was completely useless, since 13 we've long since decoupled static hash tables from the JSC::VM and 14 we can get the key for an index via HashTable::values[index].m_key! 15 16 We also get rid of VM::keywords which was a little wrapper around 17 a VM-specific copy of JSC::mainTable. There was nothing VM-specific 18 about it at all, so clients now use JSC::mainTable directly. 19 20 After this change all fooHashTable structs end up in __DATA __const 21 and no runtime initialization/allocation takes place. 22 23 * create_hash_table: 24 * jsc.cpp: 25 * parser/Lexer.cpp: 26 (JSC::isLexerKeyword): 27 (JSC::Lexer<LChar>::parseIdentifier): 28 (JSC::Lexer<UChar>::parseIdentifier): 29 (JSC::Lexer<CharacterType>::parseIdentifierSlowCase): 30 (JSC::Keywords::Keywords): Deleted. 31 * parser/Lexer.h: 32 (JSC::Keywords::isKeyword): Deleted. 33 (JSC::Keywords::getKeyword): Deleted. 34 (JSC::Keywords::~Keywords): Deleted. 35 * runtime/LiteralParser.cpp: 36 (JSC::LiteralParser<CharType>::tryJSONPParse): 37 * runtime/Lookup.cpp: 38 (JSC::HashTable::createTable): Deleted. 39 (JSC::HashTable::deleteTable): Deleted. 40 * runtime/Lookup.h: 41 (JSC::HashTable::entry): 42 (JSC::HashTable::ConstIterator::key): 43 (JSC::HashTable::ConstIterator::skipInvalidKeys): 44 (JSC::HashTable::copy): Deleted. 45 (JSC::HashTable::initializeIfNeeded): Deleted. 46 (JSC::HashTable::begin): Deleted. 47 (JSC::HashTable::end): Deleted. 48 * runtime/VM.cpp: 49 (JSC::VM::VM): Deleted. 50 * runtime/VM.h: 51 * testRegExp.cpp: 52 1 53 2015-08-21 Commit Queue <[email protected]> 2 54 -
trunk/Source/JavaScriptCore/create_hash_table
r185370 r188824 331 331 } 332 332 print "};\n\n"; 333 print " JS_EXPORT_PRIVATE externconst struct HashTable $name =\n";334 print " \{ $packedSize, $compactHashSizeMask, $hasSetter, $nameEntries, 0,$nameIndex \};\n";333 print "static const struct HashTable $name =\n"; 334 print " \{ $packedSize, $compactHashSizeMask, $hasSetter, $nameEntries, $nameIndex \};\n"; 335 335 print "} // namespace\n"; 336 336 } -
trunk/Source/JavaScriptCore/jsc.cpp
r188752 r188824 104 104 using namespace WTF; 105 105 106 namespace JSC {107 WTF_IMPORT extern const struct HashTable globalObjectTable;108 }109 110 106 namespace { 111 107 … … 721 717 }; 722 718 723 const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, &globalObjectTable, CREATE_METHOD_TABLE(GlobalObject) };719 const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, nullptr, CREATE_METHOD_TABLE(GlobalObject) }; 724 720 const GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, 0, &shouldInterruptScriptBeforeTimeout, nullptr, &moduleLoaderFetch, nullptr, nullptr }; 725 721 -
trunk/Source/JavaScriptCore/parser/Lexer.cpp
r188752 r188824 45 45 namespace JSC { 46 46 47 Keywords::Keywords(VM& vm) 48 : m_vm(vm) 49 , m_keywordTable(JSC::mainTable) 50 { 47 bool isLexerKeyword(const Identifier& identifier) 48 { 49 return JSC::mainTable.entry(identifier); 51 50 } 52 51 … … 949 948 ASSERT(shouldCreateIdentifier); 950 949 if (remaining < maxTokenLength) { 951 const HashTableValue* entry = m_vm->keywords->getKeyword(*ident);950 const HashTableValue* entry = JSC::mainTable.entry(*ident); 952 951 ASSERT((remaining < maxTokenLength) || !entry); 953 952 if (!entry) … … 1026 1025 ASSERT(shouldCreateIdentifier); 1027 1026 if (remaining < maxTokenLength) { 1028 const HashTableValue* entry = m_vm->keywords->getKeyword(*ident);1027 const HashTableValue* entry = JSC::mainTable.entry(*ident); 1029 1028 ASSERT((remaining < maxTokenLength) || !entry); 1030 1029 if (!entry) … … 1090 1089 if (LIKELY(!(lexerFlags & LexerFlagsIgnoreReservedWords))) { 1091 1090 ASSERT(shouldCreateIdentifier); 1092 const HashTableValue* entry = m_vm->keywords->getKeyword(*ident);1091 const HashTableValue* entry = JSC::mainTable.entry(*ident); 1093 1092 if (!entry) 1094 1093 return IDENT; -
trunk/Source/JavaScriptCore/parser/Lexer.h
r187587 r188824 34 34 namespace JSC { 35 35 36 class Keywords {37 WTF_MAKE_FAST_ALLOCATED;38 public:39 bool isKeyword(const Identifier& ident) const40 {41 return m_keywordTable.entry(ident);42 }43 44 const HashTableValue* getKeyword(const Identifier& ident) const45 {46 return m_keywordTable.entry(ident);47 }48 49 explicit Keywords(VM&);50 51 ~Keywords()52 {53 m_keywordTable.deleteTable();54 }55 56 private:57 friend class VM;58 59 VM& m_vm;60 const HashTable m_keywordTable;61 };62 63 36 enum LexerFlags { 64 37 LexerFlagsIgnoreReservedWords = 1, … … 68 41 69 42 struct ParsedUnicodeEscapeValue; 43 44 bool isLexerKeyword(const Identifier&); 70 45 71 46 template <typename T> -
trunk/Source/JavaScriptCore/runtime/LiteralParser.cpp
r188085 r188824 71 71 path.append(entry); 72 72 } 73 if ( m_exec->vm().keywords->isKeyword(entry.m_pathEntryName))73 if (isLexerKeyword(entry.m_pathEntryName)) 74 74 return false; 75 75 TokenType tokenType = m_lexer.next(); -
trunk/Source/JavaScriptCore/runtime/Lookup.cpp
r185370 r188824 27 27 28 28 namespace JSC { 29 30 void HashTable::createTable() const31 {32 ASSERT(!keys);33 keys = static_cast<const char**>(fastMalloc(sizeof(char*) * numberOfValues));34 35 for (int i = 0; i < numberOfValues; ++i) {36 if (values[i].m_key)37 keys[i] = values[i].m_key;38 else39 keys[i] = 0;40 }41 }42 43 void HashTable::deleteTable() const44 {45 if (keys) {46 fastFree(keys);47 keys = nullptr;48 }49 }50 29 51 30 void reifyStaticAccessor(VM& vm, const HashTableValue& value, JSObject& thisObj, PropertyName propertyName) -
trunk/Source/JavaScriptCore/runtime/Lookup.h
r185370 r188824 73 73 74 74 struct HashTable { 75 mutableint numberOfValues;75 int numberOfValues; 76 76 int indexMask; 77 77 bool hasSetterOrReadonlyProperties; 78 78 79 79 const HashTableValue* values; // Fixed values generated by script. 80 mutable const char** keys; // Table allocated at runtime.81 80 const CompactHashIndex* index; 82 83 ALWAYS_INLINE HashTable copy() const84 {85 // Don't copy dynamic table since it's thread specific.86 HashTable result = { numberOfValues, indexMask, hasSetterOrReadonlyProperties, values, 0, index };87 return result;88 }89 90 ALWAYS_INLINE void initializeIfNeeded() const91 {92 if (!keys)93 createTable();94 }95 96 JS_EXPORT_PRIVATE void deleteTable() const;97 81 98 82 // Find an entry in the table, and return the entry. 99 83 ALWAYS_INLINE const HashTableValue* entry(PropertyName propertyName) const 100 84 { 101 initializeIfNeeded();102 103 85 if (propertyName.isSymbol()) 104 86 return nullptr; … … 107 89 if (!uid) 108 90 return nullptr; 109 110 ASSERT(keys);111 91 112 92 int indexEntry = IdentifierRepHash::hash(uid) & indexMask; … … 116 96 117 97 while (true) { 118 if (WTF::equal(uid, keys[valueIndex]))98 if (WTF::equal(uid, values[valueIndex].m_key)) 119 99 return &values[valueIndex]; 120 100 … … 143 123 const char* key() 144 124 { 145 return m_table-> keys[m_position];125 return m_table->values[m_position].m_key; 146 126 } 147 127 … … 169 149 { 170 150 ASSERT(m_position <= m_table->numberOfValues); 171 while (m_position < m_table->numberOfValues && !m_table-> keys[m_position])151 while (m_position < m_table->numberOfValues && !m_table->values[m_position].m_key) 172 152 ++m_position; 173 153 ASSERT(m_position <= m_table->numberOfValues); … … 180 160 ConstIterator begin() const 181 161 { 182 initializeIfNeeded();183 162 return ConstIterator(this, 0); 184 163 } 185 164 ConstIterator end() const 186 165 { 187 initializeIfNeeded();188 166 return ConstIterator(this, numberOfValues); 189 167 } 190 191 private:192 // Convert the hash table keys to identifiers.193 JS_EXPORT_PRIVATE void createTable() const;194 168 }; 195 169 -
trunk/Source/JavaScriptCore/runtime/VM.cpp
r188810 r188824 155 155 , stringCache(*this) 156 156 , prototypeMap(*this) 157 , keywords(std::make_unique<Keywords>(*this))158 157 , interpreter(0) 159 158 , jsArrayClassInfo(JSArray::info()) -
trunk/Source/JavaScriptCore/runtime/VM.h
r188810 r188824 87 87 class JSGlobalObject; 88 88 class JSObject; 89 class Keywords;90 89 class LLIntOffsetsExtractor; 91 90 class LegacyProfiler; … … 350 349 typedef HashMap<RefPtr<SourceProvider>, RefPtr<SourceProviderCache>> SourceProviderCacheMap; 351 350 SourceProviderCacheMap sourceProviderCacheMap; 352 std::unique_ptr<Keywords> keywords;353 351 Interpreter* interpreter; 354 352 #if ENABLE(JIT) -
trunk/Source/JavaScriptCore/testRegExp.cpp
r185346 r188824 46 46 #endif 47 47 48 namespace JSC {49 WTF_IMPORT extern const struct HashTable globalObjectTable;50 }51 52 48 const int MaxLineLength = 100 * 1024; 53 49 … … 138 134 }; 139 135 140 const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, &globalObjectTable, CREATE_METHOD_TABLE(GlobalObject) };136 const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, nullptr, CREATE_METHOD_TABLE(GlobalObject) }; 141 137 142 138 GlobalObject::GlobalObject(VM& vm, Structure* structure, const Vector<String>& arguments) -
trunk/Source/WebCore/ChangeLog
r188823 r188824 1 2015-08-22 Andreas Kling <[email protected]> 2 3 [JSC] Static hash tables should be 100% compile-time constant. 4 <https://webkit.org/b/148359> 5 6 Reviewed by Michael Saboff. 7 8 Adjust WebCore bindings generator for new JSC::HashTable layout 9 and rebaseline the bindings tests for that change. 10 11 * bindings/scripts/CodeGeneratorJS.pm: 12 (GenerateHashTable): 13 * bindings/scripts/test/JS/JSTestActiveDOMObject.cpp: 14 * bindings/scripts/test/JS/JSTestCustomNamedGetter.cpp: 15 * bindings/scripts/test/JS/JSTestEventTarget.cpp: 16 * bindings/scripts/test/JS/JSTestException.cpp: 17 * bindings/scripts/test/JS/JSTestInterface.cpp: 18 * bindings/scripts/test/JS/JSTestObj.cpp: 19 * bindings/scripts/test/JS/JSTestOverrideBuiltins.cpp: 20 * bindings/scripts/test/JS/JSTestTypedefs.cpp: 21 1 22 2015-08-22 Michael Catanzaro <[email protected]> 2 23 -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r188663 r188824 4229 4229 4230 4230 my $compactSizeMask = $numEntries - 1; 4231 push(@implContent, "static const HashTable $name = { $packedSize, $compactSizeMask, $hasSetter, $nameEntries, 0,$nameIndex };\n");4231 push(@implContent, "static const HashTable $name = { $packedSize, $compactSizeMask, $hasSetter, $nameEntries, $nameIndex };\n"); 4232 4232 } 4233 4233 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestActiveDOMObject.cpp
r188590 r188824 105 105 }; 106 106 107 static const HashTable JSTestActiveDOMObjectTable = { 2, 3, true, JSTestActiveDOMObjectTableValues, 0,JSTestActiveDOMObjectTableIndex };107 static const HashTable JSTestActiveDOMObjectTable = { 2, 3, true, JSTestActiveDOMObjectTableValues, JSTestActiveDOMObjectTableIndex }; 108 108 const ClassInfo JSTestActiveDOMObjectConstructor::s_info = { "TestActiveDOMObjectConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestActiveDOMObjectConstructor) }; 109 109 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCustomNamedGetter.cpp
r188663 r188824 100 100 }; 101 101 102 static const HashTable JSTestCustomNamedGetterTable = { 1, 1, true, JSTestCustomNamedGetterTableValues, 0,JSTestCustomNamedGetterTableIndex };102 static const HashTable JSTestCustomNamedGetterTable = { 1, 1, true, JSTestCustomNamedGetterTableValues, JSTestCustomNamedGetterTableIndex }; 103 103 const ClassInfo JSTestCustomNamedGetterConstructor::s_info = { "TestCustomNamedGetterConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestCustomNamedGetterConstructor) }; 104 104 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestEventTarget.cpp
r188663 r188824 109 109 }; 110 110 111 static const HashTable JSTestEventTargetTable = { 1, 1, true, JSTestEventTargetTableValues, 0,JSTestEventTargetTableIndex };111 static const HashTable JSTestEventTargetTable = { 1, 1, true, JSTestEventTargetTableValues, JSTestEventTargetTableIndex }; 112 112 const ClassInfo JSTestEventTargetConstructor::s_info = { "TestEventTargetConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestEventTargetConstructor) }; 113 113 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestException.cpp
r188590 r188824 96 96 }; 97 97 98 static const HashTable JSTestExceptionTable = { 1, 1, true, JSTestExceptionTableValues, 0,JSTestExceptionTableIndex };98 static const HashTable JSTestExceptionTable = { 1, 1, true, JSTestExceptionTableValues, JSTestExceptionTableIndex }; 99 99 const ClassInfo JSTestExceptionConstructor::s_info = { "TestExceptionConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestExceptionConstructor) }; 100 100 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestInterface.cpp
r188590 r188824 195 195 }; 196 196 197 static const HashTable JSTestInterfaceTable = { 2, 3, true, JSTestInterfaceTableValues, 0,JSTestInterfaceTableIndex };197 static const HashTable JSTestInterfaceTable = { 2, 3, true, JSTestInterfaceTableValues, JSTestInterfaceTableIndex }; 198 198 /* Hash table for constructor */ 199 199 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
r188590 r188824 395 395 }; 396 396 397 static const HashTable JSTestObjTable = { 6, 15, true, JSTestObjTableValues, 0,JSTestObjTableIndex };397 static const HashTable JSTestObjTable = { 6, 15, true, JSTestObjTableValues, JSTestObjTableIndex }; 398 398 /* Hash table for constructor */ 399 399 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestOverrideBuiltins.cpp
r188663 r188824 102 102 }; 103 103 104 static const HashTable JSTestOverrideBuiltinsTable = { 1, 1, true, JSTestOverrideBuiltinsTableValues, 0,JSTestOverrideBuiltinsTableIndex };104 static const HashTable JSTestOverrideBuiltinsTable = { 1, 1, true, JSTestOverrideBuiltinsTableValues, JSTestOverrideBuiltinsTableIndex }; 105 105 const ClassInfo JSTestOverrideBuiltinsConstructor::s_info = { "TestOverrideBuiltinsConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestOverrideBuiltinsConstructor) }; 106 106 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.cpp
r188590 r188824 136 136 }; 137 137 138 static const HashTable JSTestTypedefsTable = { 0, 1, false, JSTestTypedefsTableValues, 0,JSTestTypedefsTableIndex };138 static const HashTable JSTestTypedefsTable = { 0, 1, false, JSTestTypedefsTableValues, JSTestTypedefsTableIndex }; 139 139 /* Hash table for constructor */ 140 140
Note:
See TracChangeset
for help on using the changeset viewer.