Changeset 39056 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Dec 5, 2008, 5:05:06 PM (16 years ago)
Author:
[email protected]
Message:

<rdar://problem/6331749> Provide a mechanism to disable perfect hashing in the DOM at build time

Reviewed by Darin Adler.

Initial patch by Yosen Lin. Adapted for ToT WebKit by David Kilzer.

Added back the code that generates a "compact" hash (instead of a
perfect hash) as a build-time option using the
ENABLE(PERFECT_HASH_SIZE) macro as defined in Lookup.h.

JavaScriptCore:

  • create_hash_table: Rename variables to differentiate perfect hash values from compact hash values. Added back code to compute compact hash tables. Generate both hash table sizes and emit conditionalized code based on ENABLE(PERFECT_HASH_SIZE).
  • runtime/Lookup.cpp: (JSC::HashTable::createTable): Added version of createTable() for use with compact hash tables. (JSC::HashTable::deleteTable): Updated to work with compact hash tables.
  • runtime/Lookup.h: Defined ENABLE(PERFECT_HASH_SIZE) macro here. (JSC::HashEntry::initialize): Set m_next to zero when using compact hash tables. (JSC::HashEntry::setNext): Added for compact hash tables. (JSC::HashEntry::next): Added for compact hash tables. (JSC::HashTable::entry): Added version of entry() for use with compact hash tables.
  • runtime/Structure.cpp: (JSC::Structure::getEnumerablePropertyNames): Updated to work with compact hash tables.

WebCore:

  • bindings/scripts/CodeGeneratorJS.pm: (GenerateImplementation): Compute the number of elements that will be stored in each hash table and pass it to GenerateHashTable(). (GenerateHashTable): Added new second parameter representing the number of elements to store in the compact hash table. Added back code to compute compact hash tables. Generate both hash table sizes and emit conditionalized code based on ENABLE(PERFECT_HASH_SIZE).
Location:
trunk/JavaScriptCore/runtime
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Lookup.cpp

    r38137 r39056  
    2727void HashTable::createTable(JSGlobalData* globalData) const
    2828{
     29#if ENABLE(PERFECT_HASH_SIZE)
    2930    ASSERT(!table);
    3031    HashEntry* entries = new HashEntry[hashSizeMask + 1];
     
    3839    }
    3940    table = entries;
     41#else
     42    ASSERT(!table);
     43    int linkIndex = compactHashSizeMask + 1;
     44    HashEntry* entries = new HashEntry[compactSize];
     45    for (int i = 0; i < compactSize; ++i)
     46        entries[i].setKey(0);
     47    for (int i = 0; values[i].key; ++i) {
     48        UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
     49        int hashIndex = identifier->computedHash() & compactHashSizeMask;
     50        HashEntry* entry = &entries[hashIndex];
     51
     52        if (entry->key()) {
     53            while (entry->next()) {
     54                entry = entry->next();
     55            }
     56            ASSERT(linkIndex < compactSize);
     57            entry->setNext(&entries[linkIndex++]);
     58            entry = entry->next();
     59        }
     60
     61        entry->initialize(identifier, values[i].attributes, values[i].value1, values[i].value2);
     62    }
     63    table = entries;
     64#endif
    4065}
    4166
     
    4368{
    4469    if (table) {
    45         for (int i = 0; i != hashSizeMask + 1; ++i) {
     70#if ENABLE(PERFECT_HASH_SIZE)
     71        int max = hashSizeMask + 1;
     72#else
     73        int max = compactSize;
     74#endif
     75        for (int i = 0; i != max; ++i) {
    4676            if (UString::Rep* key = table[i].key())
    4777                key->deref();
  • trunk/JavaScriptCore/runtime/Lookup.h

    r38528 r39056  
    3131#include <wtf/Assertions.h>
    3232
     33// Set ENABLE_PERFECT_HASH_SIZE to 0 to save memory at the
     34// cost of speed.  Test your platform as results may vary.
     35#define ENABLE_PERFECT_HASH_SIZE 1
     36
    3337namespace JSC {
    3438
     
    5458            m_u.store.value1 = v1;
    5559            m_u.store.value2 = v2;
     60#if !ENABLE(PERFECT_HASH_SIZE)
     61            m_next = 0;
     62#endif
    5663        }
    5764
     
    6875
    6976        intptr_t lexerValue() const { ASSERT(!m_attributes); return m_u.lexer.value; }
     77
     78#if !ENABLE(PERFECT_HASH_SIZE)
     79        void setNext(HashEntry *next) { m_next = next; }
     80        HashEntry* next() const { return m_next; }
     81#endif
    7082
    7183    private:
     
    91103            } lexer;
    92104        } m_u;
     105
     106#if !ENABLE(PERFECT_HASH_SIZE)
     107        HashEntry* m_next;
     108#endif
    93109    };
    94110
    95111    struct HashTable {
     112#if ENABLE(PERFECT_HASH_SIZE)
    96113        int hashSizeMask; // Precomputed size for the hash table (minus 1).
     114#else
     115        int compactSize;
     116        int compactHashSizeMask;
     117#endif
    97118        const HashTableValue* values; // Fixed values generated by script.
    98119        mutable const HashEntry* table; // Table allocated at runtime.
     
    128149        ALWAYS_INLINE const HashEntry* entry(const Identifier& identifier) const
    129150        {
     151#if ENABLE(PERFECT_HASH_SIZE)
    130152            ASSERT(table);
    131153            const HashEntry* entry = &table[identifier.ustring().rep()->computedHash() & hashSizeMask];
     
    133155                return 0;
    134156            return entry;
     157#else
     158            ASSERT(table);
     159
     160            const HashEntry* entry = &table[identifier.ustring().rep()->computedHash() & compactHashSizeMask];
     161
     162            if (!entry->key())
     163                return 0;
     164
     165            do {
     166                if (entry->key() == identifier.ustring().rep())
     167                    return entry;
     168                entry = entry->next();
     169            } while (entry);
     170
     171            return 0;
     172#endif
    135173        }
    136174
  • trunk/JavaScriptCore/runtime/Structure.cpp

    r38440 r39056  
    308308        table->initializeIfNeeded(exec);
    309309        ASSERT(table->table);
     310#if ENABLE(PERFECT_HASH_SIZE)
    310311        int hashSizeMask = table->hashSizeMask;
     312#else
     313        int hashSizeMask = table->compactSize - 1;
     314#endif
    311315        const HashEntry* entry = table->table;
    312316        for (int i = 0; i <= hashSizeMask; ++i, ++entry) {
Note: See TracChangeset for help on using the changeset viewer.