source: webkit/trunk/JavaScriptCore/runtime/JSVariableObject.h@ 49323

Last change on this file since 49323 was 48836, checked in by [email protected], 16 years ago

NotNullPassRefPtr: smart pointer optimized for passing references that are not null
https://bugs.webkit.org/show_bug.cgi?id=29822

Patch by Geoffrey Garen <[email protected]> on 2009-09-28
Reviewed by Darin Adler.

JavaScriptCore:

Added NotNullPassRefPtr, and deployed it in all places that initialize
JavaScript objects.

2.2% speedup on bench-allocate-nonretained.js.

  • API/JSCallbackConstructor.cpp:

(JSC::JSCallbackConstructor::JSCallbackConstructor):

  • API/JSCallbackConstructor.h:
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:

(JSC::JSCallbackObject::JSCallbackObject):

(JSC::CodeBlock::addFunctionDecl):
(JSC::CodeBlock::addFunctionExpr):

  • runtime/ArrayConstructor.cpp:

(JSC::ArrayConstructor::ArrayConstructor):

  • runtime/ArrayConstructor.h:
  • runtime/ArrayPrototype.cpp:

(JSC::ArrayPrototype::ArrayPrototype):

  • runtime/ArrayPrototype.h:
  • runtime/BooleanConstructor.cpp:

(JSC::BooleanConstructor::BooleanConstructor):

  • runtime/BooleanConstructor.h:
  • runtime/BooleanObject.cpp:

(JSC::BooleanObject::BooleanObject):

  • runtime/BooleanObject.h:
  • runtime/BooleanPrototype.cpp:

(JSC::BooleanPrototype::BooleanPrototype):

  • runtime/BooleanPrototype.h:
  • runtime/DateConstructor.cpp:

(JSC::DateConstructor::DateConstructor):

  • runtime/DateConstructor.h:
  • runtime/DateInstance.cpp:

(JSC::DateInstance::DateInstance):

  • runtime/DateInstance.h:
  • runtime/DatePrototype.cpp:

(JSC::DatePrototype::DatePrototype):

  • runtime/DatePrototype.h:
  • runtime/ErrorConstructor.cpp:

(JSC::ErrorConstructor::ErrorConstructor):

  • runtime/ErrorConstructor.h:
  • runtime/ErrorInstance.cpp:

(JSC::ErrorInstance::ErrorInstance):

  • runtime/ErrorInstance.h:
  • runtime/ErrorPrototype.cpp:

(JSC::ErrorPrototype::ErrorPrototype):

  • runtime/ErrorPrototype.h:
  • runtime/FunctionConstructor.cpp:

(JSC::FunctionConstructor::FunctionConstructor):

  • runtime/FunctionConstructor.h:
  • runtime/FunctionPrototype.cpp:

(JSC::FunctionPrototype::FunctionPrototype):

  • runtime/FunctionPrototype.h:
  • runtime/GlobalEvalFunction.cpp:

(JSC::GlobalEvalFunction::GlobalEvalFunction):

  • runtime/GlobalEvalFunction.h:
  • runtime/InternalFunction.cpp:

(JSC::InternalFunction::InternalFunction):

  • runtime/InternalFunction.h:

(JSC::InternalFunction::InternalFunction):

  • runtime/JSActivation.cpp:

(JSC::JSActivation::JSActivation):

  • runtime/JSActivation.h:

(JSC::JSActivation::JSActivationData::JSActivationData):

  • runtime/JSArray.cpp:

(JSC::JSArray::JSArray):

  • runtime/JSArray.h:
  • runtime/JSByteArray.cpp:

(JSC::JSByteArray::JSByteArray):

  • runtime/JSByteArray.h:
  • runtime/JSFunction.cpp:

(JSC::JSFunction::JSFunction):

  • runtime/JSFunction.h:
  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::JSGlobalObject):

  • runtime/JSONObject.h:

(JSC::JSONObject::JSONObject):

  • runtime/JSObject.h:

(JSC::JSObject::JSObject):
(JSC::JSObject::setStructure):

  • runtime/JSVariableObject.h:

(JSC::JSVariableObject::JSVariableObject):

  • runtime/JSWrapperObject.h:

(JSC::JSWrapperObject::JSWrapperObject):

  • runtime/MathObject.cpp:

(JSC::MathObject::MathObject):

  • runtime/MathObject.h:
  • runtime/NativeErrorConstructor.cpp:

(JSC::NativeErrorConstructor::NativeErrorConstructor):

  • runtime/NativeErrorConstructor.h:
  • runtime/NativeErrorPrototype.cpp:

(JSC::NativeErrorPrototype::NativeErrorPrototype):

  • runtime/NativeErrorPrototype.h:
  • runtime/NumberConstructor.cpp:

(JSC::NumberConstructor::NumberConstructor):

  • runtime/NumberConstructor.h:
  • runtime/NumberObject.cpp:

(JSC::NumberObject::NumberObject):

  • runtime/NumberObject.h:
  • runtime/NumberPrototype.cpp:

(JSC::NumberPrototype::NumberPrototype):

  • runtime/NumberPrototype.h:
  • runtime/ObjectConstructor.cpp:

(JSC::ObjectConstructor::ObjectConstructor):

  • runtime/ObjectConstructor.h:
  • runtime/ObjectPrototype.cpp:

(JSC::ObjectPrototype::ObjectPrototype):

  • runtime/ObjectPrototype.h:
  • runtime/PropertyNameArray.h:

(JSC::PropertyNameArrayData::setCachedPrototypeChain):

  • runtime/PrototypeFunction.cpp:

(JSC::PrototypeFunction::PrototypeFunction):

  • runtime/PrototypeFunction.h:
  • runtime/RegExpConstructor.cpp:

(JSC::RegExpConstructor::RegExpConstructor):

  • runtime/RegExpConstructor.h:
  • runtime/RegExpObject.cpp:

(JSC::RegExpObject::RegExpObject):

  • runtime/RegExpObject.h:

(JSC::RegExpObject::RegExpObjectData::RegExpObjectData):

  • runtime/RegExpPrototype.cpp:

(JSC::RegExpPrototype::RegExpPrototype):

  • runtime/RegExpPrototype.h:
  • runtime/StringConstructor.cpp:

(JSC::StringConstructor::StringConstructor):

  • runtime/StringConstructor.h:
  • runtime/StringObject.cpp:

(JSC::StringObject::StringObject):

  • runtime/StringObject.h:
  • runtime/StringObjectThatMasqueradesAsUndefined.h:

(JSC::StringObjectThatMasqueradesAsUndefined::StringObjectThatMasqueradesAsUndefined):

  • runtime/StringPrototype.cpp:

(JSC::StringPrototype::StringPrototype):

  • runtime/StringPrototype.h:
  • wtf/PassRefPtr.h:

(WTF::NotNullPassRefPtr::NotNullPassRefPtr):
(WTF::NotNullPassRefPtr::~NotNullPassRefPtr):
(WTF::NotNullPassRefPtr::get):
(WTF::NotNullPassRefPtr::clear):
(WTF::NotNullPassRefPtr::releaseRef):
(WTF::NotNullPassRefPtr::operator*):
(WTF::NotNullPassRefPtr::operator->):
(WTF::NotNullPassRefPtr::operator!):
(WTF::NotNullPassRefPtr::operator UnspecifiedBoolType):

  • wtf/RefPtr.h:

(WTF::RefPtr::RefPtr):
(WTF::operator==):

WebCore:

Added NotNullPassRefPtr, and deployed it in all places that initialize
JavaScript objects.

  • bindings/js/DOMObjectWithSVGContext.h:

(WebCore::DOMObjectWithSVGContext::DOMObjectWithSVGContext):

  • bindings/js/JSDOMBinding.cpp:

(WebCore::cacheDOMStructure):

  • bindings/js/JSDOMBinding.h:

(WebCore::DOMObject::DOMObject):
(WebCore::DOMObjectWithGlobalPointer::DOMObjectWithGlobalPointer):
(WebCore::DOMConstructorObject::DOMConstructorObject):
(WebCore::DOMConstructorWithDocument::DOMConstructorWithDocument):

  • bindings/js/JSDOMGlobalObject.cpp:

(WebCore::JSDOMGlobalObject::JSDOMGlobalObject):

  • bindings/js/JSDOMGlobalObject.h:
  • bindings/js/JSDOMWindowBase.cpp:

(WebCore::JSDOMWindowBase::JSDOMWindowBase):

  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSHTMLAllCollection.h:

(WebCore::JSHTMLAllCollection::JSHTMLAllCollection):

  • bindings/js/JSInspectedObjectWrapper.cpp:

(WebCore::JSInspectedObjectWrapper::JSInspectedObjectWrapper):

  • bindings/js/JSInspectedObjectWrapper.h:
  • bindings/js/JSInspectorCallbackWrapper.cpp:

(WebCore::JSInspectorCallbackWrapper::JSInspectorCallbackWrapper):

  • bindings/js/JSInspectorCallbackWrapper.h:
  • bindings/js/JSQuarantinedObjectWrapper.cpp:

(WebCore::JSQuarantinedObjectWrapper::JSQuarantinedObjectWrapper):

  • bindings/js/JSQuarantinedObjectWrapper.h:
  • bindings/js/JSWorkerContextBase.cpp:

(WebCore::JSWorkerContextBase::JSWorkerContextBase):

  • bindings/js/JSWorkerContextBase.h:
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/runtime_object.cpp:

(JSC::RuntimeObjectImp::RuntimeObjectImp):

  • bridge/runtime_object.h:
  • Property svn:eol-style set to native
File size: 6.6 KB
Line 
1/*
2 * Copyright (C) 2007, 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 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef JSVariableObject_h
30#define JSVariableObject_h
31
32#include "JSObject.h"
33#include "Register.h"
34#include "SymbolTable.h"
35#include "UnusedParam.h"
36#include <wtf/OwnArrayPtr.h>
37#include <wtf/UnusedParam.h>
38
39namespace JSC {
40
41 class Register;
42
43 class JSVariableObject : public JSObject {
44 friend class JIT;
45
46 public:
47 SymbolTable& symbolTable() const { return *d->symbolTable; }
48
49 virtual void putWithAttributes(ExecState*, const Identifier&, JSValue, unsigned attributes) = 0;
50
51 virtual bool deleteProperty(ExecState*, const Identifier&);
52 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&);
53
54 virtual bool isVariableObject() const;
55 virtual bool isDynamicScope() const = 0;
56
57 virtual bool getPropertyAttributes(ExecState*, const Identifier& propertyName, unsigned& attributes) const;
58
59 Register& registerAt(int index) const { return d->registers[index]; }
60
61 static PassRefPtr<Structure> createStructure(JSValue prototype)
62 {
63 return Structure::create(prototype, TypeInfo(ObjectType, HasStandardGetOwnPropertySlot | HasDefaultMark));
64 }
65
66 protected:
67 // Subclasses of JSVariableObject can subclass this struct to add data
68 // without increasing their own size (since there's a hard limit on the
69 // size of a JSCell).
70 struct JSVariableObjectData {
71 JSVariableObjectData(SymbolTable* symbolTable, Register* registers)
72 : symbolTable(symbolTable)
73 , registers(registers)
74 {
75 ASSERT(symbolTable);
76 }
77
78 SymbolTable* symbolTable; // Maps name -> offset from "r" in register file.
79 Register* registers; // "r" in the register file.
80 OwnArrayPtr<Register> registerArray; // Independent copy of registers, used when a variable object copies its registers out of the register file.
81
82 private:
83 JSVariableObjectData(const JSVariableObjectData&);
84 JSVariableObjectData& operator=(const JSVariableObjectData&);
85 };
86
87 JSVariableObject(NonNullPassRefPtr<Structure> structure, JSVariableObjectData* data)
88 : JSObject(structure)
89 , d(data) // Subclass owns this pointer.
90 {
91 }
92
93 Register* copyRegisterArray(Register* src, size_t count);
94 void setRegisters(Register* r, Register* registerArray);
95
96 bool symbolTableGet(const Identifier&, PropertySlot&);
97 bool symbolTableGet(const Identifier&, PropertyDescriptor&);
98 bool symbolTableGet(const Identifier&, PropertySlot&, bool& slotIsWriteable);
99 bool symbolTablePut(const Identifier&, JSValue);
100 bool symbolTablePutWithAttributes(const Identifier&, JSValue, unsigned attributes);
101
102 JSVariableObjectData* d;
103 };
104
105 inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot)
106 {
107 SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
108 if (!entry.isNull()) {
109 slot.setRegisterSlot(&registerAt(entry.getIndex()));
110 return true;
111 }
112 return false;
113 }
114
115 inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot, bool& slotIsWriteable)
116 {
117 SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
118 if (!entry.isNull()) {
119 slot.setRegisterSlot(&registerAt(entry.getIndex()));
120 slotIsWriteable = !entry.isReadOnly();
121 return true;
122 }
123 return false;
124 }
125
126 inline bool JSVariableObject::symbolTablePut(const Identifier& propertyName, JSValue value)
127 {
128 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
129
130 SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
131 if (entry.isNull())
132 return false;
133 if (entry.isReadOnly())
134 return true;
135 registerAt(entry.getIndex()) = value;
136 return true;
137 }
138
139 inline bool JSVariableObject::symbolTablePutWithAttributes(const Identifier& propertyName, JSValue value, unsigned attributes)
140 {
141 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
142
143 SymbolTable::iterator iter = symbolTable().find(propertyName.ustring().rep());
144 if (iter == symbolTable().end())
145 return false;
146 SymbolTableEntry& entry = iter->second;
147 ASSERT(!entry.isNull());
148 entry.setAttributes(attributes);
149 registerAt(entry.getIndex()) = value;
150 return true;
151 }
152
153 inline Register* JSVariableObject::copyRegisterArray(Register* src, size_t count)
154 {
155 Register* registerArray = new Register[count];
156 memcpy(registerArray, src, count * sizeof(Register));
157
158 return registerArray;
159 }
160
161 inline void JSVariableObject::setRegisters(Register* registers, Register* registerArray)
162 {
163 ASSERT(registerArray != d->registerArray.get());
164 d->registerArray.set(registerArray);
165 d->registers = registers;
166 }
167
168} // namespace JSC
169
170#endif // JSVariableObject_h
Note: See TracBrowser for help on using the repository browser.