source: webkit/trunk/JavaScriptCore/kjs/StructureID.h@ 36310

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

JavaScriptCore:

2008-09-08 Sam Weinig <[email protected]>

Reviewed by Maciej Stachowiak and Oliver Hunt.

Split storage of properties out of the PropertyMap and into the JSObject
to allow sharing PropertyMap on the StructureID. In order to get this
function correctly, the StructureID's transition mappings were changed to
transition based on property name and attribute pairs, instead of just
property name.

  • Removes the single property optimization now that the PropertyMap is shared. This will be replaced by in-lining some values on the JSObject.

This is a wash on Sunspider and a 6.7% win on the v8 test suite.

  • JavaScriptCore.base.exp:
  • VM/CTI.cpp: (JSC::CTI::privateCompileGetByIdSelf): Get the storage directly off the JSObject. (JSC::CTI::privateCompileGetByIdProto): Ditto. (JSC::CTI::privateCompileGetByIdChain): Ditto. (JSC::CTI::privateCompilePutByIdReplace): Ditto.
  • kjs/JSObject.cpp: (JSC::JSObject::mark): Mark the PropertyStorage. (JSC::JSObject::put): Update to get the propertyMap of the StructureID. (JSC::JSObject::deleteProperty): Ditto. (JSC::JSObject::defineGetter): Return early if the property is already a getter/setter. (JSC::JSObject::defineSetter): Ditto. (JSC::JSObject::getPropertyAttributes): Update to get the propertyMap of the StructureID (JSC::JSObject::getPropertyNames): Ditto. (JSC::JSObject::removeDirect): Ditto.
  • kjs/JSObject.h: Remove PropertyMap and add PropertyStorage. (JSC::JSObject::propertyStorage): return the PropertyStorage. (JSC::JSObject::getDirect): Update to get the propertyMap of the StructureID. (JSC::JSObject::getDirectLocation): Ditto. (JSC::JSObject::offsetForLocation): Compute location directly. (JSC::JSObject::hasCustomProperties): Update to get the propertyMap of the StructureID. (JSC::JSObject::hasGetterSetterProperties): Ditto. (JSC::JSObject::getDirectOffset): Get by indexing into PropertyStorage. (JSC::JSObject::putDirectOffset): Put by indexing into PropertyStorage. (JSC::JSObject::getOwnPropertySlotForWrite): Update to get the propertyMap of the StructureID. (JSC::JSObject::getOwnPropertySlot): Ditto. (JSC::JSObject::putDirect): Move putting into the StructureID unless the property already exists.
  • kjs/PropertyMap.cpp: Use the propertyStorage as the storage for the JSValues. (JSC::PropertyMap::checkConsistency): (JSC::PropertyMap::operator=): (JSC::PropertyMap::~PropertyMap): (JSC::PropertyMap::get): (JSC::PropertyMap::getLocation): (JSC::PropertyMap::put): (JSC::PropertyMap::getOffset): (JSC::PropertyMap::insert): (JSC::PropertyMap::expand): (JSC::PropertyMap::rehash): (JSC::PropertyMap::createTable): (JSC::PropertyMap::resizePropertyStorage): Resize the storage to match the size of the map (JSC::PropertyMap::remove): (JSC::PropertyMap::getEnumerablePropertyNames):
  • kjs/PropertyMap.h: (JSC::PropertyMapEntry::PropertyMapEntry): (JSC::PropertyMap::isEmpty): (JSC::PropertyMap::size): (JSC::PropertyMap::makingCount): (JSC::PropertyMap::PropertyMap):
  • kjs/StructureID.cpp: (JSC::StructureID::addPropertyTransition): Transitions now are based off the property name and attributes. (JSC::StructureID::toDictionaryTransition): Copy the map. (JSC::StructureID::changePrototypeTransition): Copy the map. (JSC::StructureID::getterSetterTransition): Copy the map. (JSC::StructureID::~StructureID):
  • kjs/StructureID.h: (JSC::TransitionTableHash::hash): Custom hash for transition map. (JSC::TransitionTableHash::equal): Ditto. (JSC::TransitionTableHashTraits::emptyValue): Custom traits for transition map (JSC::TransitionTableHashTraits::constructDeletedValue): Ditto. (JSC::TransitionTableHashTraits::isDeletedValue): Ditto. (JSC::StructureID::propertyMap): Added.

JavaScriptGlue:

2008-09-08 Sam Weinig <[email protected]>

Reviewed by Maciej Stachowiak and Oliver Hunt.

Add forwarding headers.

  • ForwardingHeaders/wtf/HashFunctions.h: Added.
  • ForwardingHeaders/wtf/HashTraits.h: Added.

WebCore:

2008-09-08 Sam Weinig <[email protected]>

Reviewed by Maciej Stachowiak and Oliver Hunt.

Add forwarding headers.

  • ForwardingHeaders/wtf/HashFunctions.h: Added.
File size: 5.3 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef StructureID_h
27#define StructureID_h
28
29#include "JSValue.h"
30#include "PropertyMap.h"
31#include "ustring.h"
32#include <wtf/HashFunctions.h>
33#include <wtf/HashTraits.h>
34#include <wtf/OwnArrayPtr.h>
35#include <wtf/PassRefPtr.h>
36#include <wtf/RefCounted.h>
37
38namespace JSC {
39
40 class JSValue;
41 class StructureIDChain;
42
43 struct TransitionTableHash {
44 typedef std::pair<RefPtr<UString::Rep>, unsigned> TransitionTableKey;
45 static unsigned hash(const TransitionTableKey& p)
46 {
47 return p.first->computedHash();
48 }
49
50 static bool equal(const TransitionTableKey& a, const TransitionTableKey& b)
51 {
52 return a == b;
53 }
54
55 static const bool safeToCompareToEmptyOrDeleted = true;
56 };
57
58 struct TransitionTableHashTraits {
59 typedef WTF::HashTraits<RefPtr<UString::Rep> > FirstTraits;
60 typedef WTF::GenericHashTraits<unsigned> SecondTraits;
61 typedef std::pair<FirstTraits::TraitType, SecondTraits::TraitType> TraitType;
62
63 static const bool emptyValueIsZero = FirstTraits::emptyValueIsZero && SecondTraits::emptyValueIsZero;
64 static TraitType emptyValue() { return std::make_pair(FirstTraits::emptyValue(), SecondTraits::emptyValue()); }
65
66 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction;
67
68 static void constructDeletedValue(TraitType& slot) { FirstTraits::constructDeletedValue(slot.first); }
69 static bool isDeletedValue(const TraitType& value) { return FirstTraits::isDeletedValue(value.first); }
70 };
71
72 class StructureID : public RefCounted<StructureID> {
73 public:
74 static PassRefPtr<StructureID> create(JSValue* prototype)
75 {
76 return adoptRef(new StructureID(prototype));
77 }
78
79 static PassRefPtr<StructureID> changePrototypeTransition(StructureID*, JSValue* prototype);
80 static PassRefPtr<StructureID> addPropertyTransition(StructureID*, const Identifier& propertyName, JSValue*, unsigned attributes, bool checkReadOnly, JSObject* slotBase, PutPropertySlot&, PropertyStorage&);
81 static PassRefPtr<StructureID> getterSetterTransition(StructureID*);
82 static PassRefPtr<StructureID> toDictionaryTransition(StructureID*);
83 static PassRefPtr<StructureID> fromDictionaryTransition(StructureID*);
84
85 ~StructureID();
86
87 void mark()
88 {
89 if (!m_prototype->marked())
90 m_prototype->mark();
91 }
92
93 bool isDictionary() const { return m_isDictionary; }
94
95 JSValue* prototype() const { return m_prototype; }
96
97 void setCachedPrototypeChain(PassRefPtr<StructureIDChain> cachedPrototypeChain) { m_cachedPrototypeChain = cachedPrototypeChain; }
98 StructureIDChain* cachedPrototypeChain() const { return m_cachedPrototypeChain.get(); }
99
100 const PropertyMap& propertyMap() const { return m_propertyMap; }
101 PropertyMap& propertyMap() { return m_propertyMap; }
102
103 private:
104 typedef std::pair<RefPtr<UString::Rep>, unsigned> TransitionTableKey;
105 typedef HashMap<TransitionTableKey, StructureID*, TransitionTableHash, TransitionTableHashTraits> TransitionTable;
106
107 StructureID(JSValue* prototype);
108
109 static const size_t s_maxTransitionLength = 64;
110
111 bool m_isDictionary;
112
113 JSValue* m_prototype;
114 RefPtr<StructureIDChain> m_cachedPrototypeChain;
115
116 RefPtr<StructureID> m_previous;
117 UString::Rep* m_nameInPrevious;
118 unsigned m_attributesInPrevious;
119
120 size_t m_transitionCount;
121 TransitionTable m_transitionTable;
122
123 PropertyMap m_propertyMap;
124 };
125
126 class StructureIDChain : public RefCounted<StructureIDChain> {
127 public:
128 static PassRefPtr<StructureIDChain> create(StructureID* structureID) { return adoptRef(new StructureIDChain(structureID)); }
129
130 RefPtr<StructureID>* head() { return m_vector.get(); }
131
132 private:
133 StructureIDChain(StructureID* structureID);
134
135 OwnArrayPtr<RefPtr<StructureID> > m_vector;
136 };
137
138} // namespace JSC
139
140#endif // StructureID_h
Note: See TracBrowser for help on using the repository browser.