source: webkit/trunk/JavaScriptCore/runtime/PropertyMapHashTable.h@ 38477

Last change on this file since 38477 was 38407, checked in by [email protected], 17 years ago

2008-11-13 Sam Weinig <[email protected]>

Reviewed by Darin Adler

Fix for https://bugs.webkit.org/show_bug.cgi?id=22269
Reduce PropertyMap usage

From observation of StructureID statistics, it became clear that many
StructureID's were not being used as StructureIDs themselves, but rather
only being necessary as links in the transition chain. Acknowledging this
and that PropertyMaps stored in StructureIDs can be treated as caches, that
is that they can be reconstructed on demand, it became clear that we could
reduce the memory consumption of StructureIDs by only keeping PropertyMaps
for the StructureIDs that need them the most.

The specific strategy used to reduce the number of StructureIDs with
PropertyMaps is to take the previous StructureIDs PropertyMap when initially
transitioning (addPropertyTransition) from it and clearing out the pointer
in the process. The next time we need to do the same transition, for instance
repeated calls to the same constructor, we use the new addPropertyTransitionToExistingStructure
first, which allows us not to need the PropertyMap to determine if the property
exists already, since a transition to that property would require it not already
be present in the StructureID. Should there be no transition, the PropertyMap
can be constructed on demand (via materializePropertyMap) to determine if the put is a
replace or a transition to a new StructureID.

Reduces memory use on Membuster head test (30 pages open) by ~15MB.

  • JavaScriptCore.exp:
  • runtime/JSObject.h: (JSC::JSObject::putDirect): First use addPropertyTransitionToExistingStructure so that we can avoid building the PropertyMap on subsequent similar object creations.
  • runtime/PropertyMapHashTable.h: (JSC::PropertyMapEntry::PropertyMapEntry): Add version of constructor which takes all values to be used when lazily building the PropertyMap.
  • runtime/StructureID.cpp: (JSC::StructureID::dumpStatistics): Add statistics on the number of StructureIDs with PropertyMaps. (JSC::StructureID::StructureID): Rename m_cachedTransistionOffset to m_offset (JSC::isPowerOf2): (JSC::nextPowerOf2): (JSC::sizeForKeyCount): Returns the expected size of a PropertyMap for a key count. (JSC::StructureID::materializePropertyMap): Builds the PropertyMap out of its previous pointer chain. (JSC::StructureID::addPropertyTransitionToExistingStructure): Only transitions if there is a an existing transition. (JSC::StructureID::addPropertyTransition): Instead of always copying the ProperyMap, try and take it from it previous pointer. (JSC::StructureID::removePropertyTransition): Simplify by calling toDictionaryTransition() to do transition work. (JSC::StructureID::changePrototypeTransition): Build the PropertyMap if necessary before transitioning because once you have transitioned, you will not be able to reconstruct it afterwards as there is no previous pointer, pinning the ProperyMap as well. (JSC::StructureID::getterSetterTransition): Ditto. (JSC::StructureID::toDictionaryTransition): Pin the PropertyMap so that it is not destroyed on further transitions. (JSC::StructureID::fromDictionaryTransition): We can only transition back from a dictionary transition if there are no deleted offsets. (JSC::StructureID::addPropertyWithoutTransition): Build PropertyMap on demands and pin. (JSC::StructureID::removePropertyWithoutTransition): Ditto. (JSC::StructureID::get): Build on demand. (JSC::StructureID::createPropertyMapHashTable): Add version of create that takes a size for on demand building. (JSC::StructureID::expandPropertyMapHashTable): (JSC::StructureID::rehashPropertyMapHashTable): (JSC::StructureID::getEnumerablePropertyNamesInternal): Build PropertyMap on demand.
  • runtime/StructureID.h: (JSC::StructureID::propertyStorageSize): Account for StructureIDs without PropertyMaps. (JSC::StructureID::isEmpty): Ditto. (JSC::StructureID::materializePropertyMapIfNecessary): (JSC::StructureID::get): Build PropertyMap on demand
  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1/*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef PropertyMapHashTable_h
22#define PropertyMapHashTable_h
23
24#include "UString.h"
25
26namespace JSC {
27
28 struct PropertyMapEntry {
29 UString::Rep* key;
30 unsigned offset;
31 unsigned attributes;
32 unsigned index;
33
34 PropertyMapEntry(UString::Rep* key, unsigned attributes)
35 : key(key)
36 , offset(0)
37 , attributes(attributes)
38 , index(0)
39 {
40 }
41
42 PropertyMapEntry(UString::Rep* key, unsigned offset, unsigned attributes, unsigned index)
43 : key(key)
44 , offset(offset)
45 , attributes(attributes)
46 , index(index)
47 {
48 }
49 };
50
51 // lastIndexUsed is an ever-increasing index used to identify the order items
52 // were inserted into the property map. It's required that getEnumerablePropertyNames
53 // return the properties in the order they were added for compatibility with other
54 // browsers' JavaScript implementations.
55 struct PropertyMapHashTable {
56 unsigned sizeMask;
57 unsigned size;
58 unsigned keyCount;
59 unsigned deletedSentinelCount;
60 unsigned lastIndexUsed;
61 unsigned entryIndices[1];
62
63 PropertyMapEntry* entries()
64 {
65 // The entries vector comes after the indices vector.
66 // The 0th item in the entries vector is not really used; it has to
67 // have a 0 in its key to allow the hash table lookup to handle deleted
68 // sentinels without any special-case code, but the other fields are unused.
69 return reinterpret_cast<PropertyMapEntry*>(&entryIndices[size]);
70 }
71
72 static size_t allocationSize(unsigned size)
73 {
74 // We never let a hash table get more than half full,
75 // So the number of indices we need is the size of the hash table.
76 // But the number of entries is half that (plus one for the deleted sentinel).
77 return sizeof(PropertyMapHashTable)
78 + (size - 1) * sizeof(unsigned)
79 + (1 + size / 2) * sizeof(PropertyMapEntry);
80 }
81 };
82
83} // namespace JSC
84
85#endif // PropertyMapHashTable_h
Note: See TracBrowser for help on using the repository browser.