Reduce memory use for static property maps
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Mar 2014 18:08:35 +0000 (18:08 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Mar 2014 18:08:35 +0000 (18:08 +0000)
commit9e9520c015d4d6f364b8dd72c11bfa97a44178c6
tree69c80ee3b331d1b7132bd2080b036c4326b0bdab
parent2c652c3c8637620666875419e703e864f86ac162
Reduce memory use for static property maps
https://bugs.webkit.org/show_bug.cgi?id=129986

Reviewed by Andreas Kling.

Static property tables are currently duplicated on first use from read-only memory into dirty memory
in every process, and since the entries are large (48 bytes) and the tables can be unusually sparse
(we use a custom hash table without a rehash) a lot of memory may be wasted.

Source/JavaScriptCore:

First, reduce the size of the hashtable. Instead of storing values in the table the hashtable maps
from string hashes to indicies into a densely packed array of values. Compute the index table at
compile time as a part of the derived sources step, such that this may be read-only data.

Second, don't copy all data from the HashTableValue array into a HashEntry objects. Instead refer
directly to the HashTableValue entries. The only data that needs to be allocated at runtime are the
keys, which are Identifiers.

* create_hash_table:
    - emit the hash table index into the derived source (we were calculating this already to ensure chaining does not get too deep).
* parser/Lexer.cpp:
(JSC::Lexer<LChar>::parseIdentifier):
(JSC::Lexer<UChar>::parseIdentifier):
(JSC::Lexer<T>::parseIdentifierSlowCase):
    - HashEntry -> HashTableValue.
* parser/Lexer.h:
(JSC::Keywords::getKeyword):
    - HashEntry -> HashTableValue.
* runtime/ClassInfo.h:
    - removed HashEntry.
* runtime/JSObject.cpp:
(JSC::getClassPropertyNames):
    - use HashTable::ConstIterator.
(JSC::JSObject::put):
(JSC::JSObject::deleteProperty):
(JSC::JSObject::findPropertyHashEntry):
    - HashEntry -> HashTableValue.
(JSC::JSObject::reifyStaticFunctionsForDelete):
    - changed HashTable::ConstIterator interface.
* runtime/JSObject.h:
    - HashEntry -> HashTableValue.
* runtime/Lookup.cpp:
(JSC::HashTable::createTable):
    - table -> keys, keys array is now densely packed.
(JSC::HashTable::deleteTable):
    - table -> keys.
(JSC::setUpStaticFunctionSlot):
    - HashEntry -> HashTableValue.
* runtime/Lookup.h:
(JSC::HashTableValue::builtinGenerator):
(JSC::HashTableValue::function):
(JSC::HashTableValue::functionLength):
(JSC::HashTableValue::propertyGetter):
(JSC::HashTableValue::propertyPutter):
(JSC::HashTableValue::lexerValue):
    - added accessor methods from HashEntry.
(JSC::HashTable::copy):
    - fields changed.
(JSC::HashTable::initializeIfNeeded):
    - table -> keys.
(JSC::HashTable::entry):
    - HashEntry -> HashTableValue.
(JSC::HashTable::ConstIterator::ConstIterator):
    - iterate packed value array, so no need to skipInvalidKeys().
(JSC::HashTable::ConstIterator::value):
(JSC::HashTable::ConstIterator::key):
(JSC::HashTable::ConstIterator::operator->):
    - accessors now get HashTableValue/StringImpl* separately.
(JSC::HashTable::ConstIterator::operator++):
    - iterate packed value array, so no need to skipInvalidKeys().
(JSC::HashTable::end):
    - end is now size of dense not sparse array.
(JSC::getStaticPropertySlot):
(JSC::getStaticFunctionSlot):
(JSC::getStaticValueSlot):
(JSC::putEntry):
(JSC::lookupPut):
    - HashEntry -> HashTableValue.

Source/WebCore:

* bindings/js/JSDOMBinding.h:
(WebCore::getStaticValueSlotEntryWithoutCaching):
(WebCore::getStaticValueSlotEntryWithoutCaching<JSDOMWrapper>):
    - HashEntry -> HashTableValue.
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::JSDOMWindow::getOwnPropertySlot):
    - HashEntry -> HashTableValue.
* bindings/js/JSHistoryCustom.cpp:
(WebCore::JSHistory::getOwnPropertySlotDelegate):
    - HashEntry -> HashTableValue.
* bindings/js/JSLocationCustom.cpp:
(WebCore::JSLocation::getOwnPropertySlotDelegate):
(WebCore::JSLocation::putDelegate):
    - HashEntry -> HashTableValue.
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateGetOwnPropertySlotBody):
    - HashEntry -> HashTableValue.
(GenerateHashTable):
    - emit the hash table index into the derived source (we were calculating this already to ensure chaining does not get too deep).

LayoutTests:

* inspector-protocol/debugger/setPauseOnExceptions-all-expected.txt:
* inspector-protocol/debugger/setPauseOnExceptions-none-expected.txt:
* inspector-protocol/debugger/setPauseOnExceptions-uncaught-expected.txt:
* js/dom/dom-static-property-for-in-iteration-expected.txt:
    - Properties now iterated in correct order, not permuted by hash table.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@165482 268f45cc-cd09-0410-ab3c-d52691b4dbfc
36 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector-protocol/debugger/setPauseOnExceptions-all-expected.txt
LayoutTests/inspector-protocol/debugger/setPauseOnExceptions-none-expected.txt
LayoutTests/inspector-protocol/debugger/setPauseOnExceptions-uncaught-expected.txt
LayoutTests/js/dom/dom-static-property-for-in-iteration-expected.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/create_hash_table
Source/JavaScriptCore/parser/Lexer.cpp
Source/JavaScriptCore/parser/Lexer.h
Source/JavaScriptCore/runtime/ClassInfo.h
Source/JavaScriptCore/runtime/JSObject.cpp
Source/JavaScriptCore/runtime/JSObject.h
Source/JavaScriptCore/runtime/Lookup.cpp
Source/JavaScriptCore/runtime/Lookup.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
Source/WebCore/bindings/js/JSHistoryCustom.cpp
Source/WebCore/bindings/js/JSLocationCustom.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestActiveDOMObject.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestCustomNamedGetter.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestEventConstructor.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestEventTarget.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestException.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestGenerateIsReachable.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestInterface.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestMediaQueryListListener.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNamedConstructor.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.cpp
Source/WebCore/bindings/scripts/test/JS/JSattribute.cpp
Source/WebCore/bindings/scripts/test/JS/JSreadonly.cpp