Skip to content

Commit 67bc1a7

Browse files
author
Gavin Barraclough
committed
Bug 54786 - Devirtualize JSCell::classInfo()
Reviewed by Sam Weinig. Instead of making a virtual function call, add a pointer to the ClassInfo onto Structure. This removes a virtual function call, and paves the way towards removing all the createStructure methods, and StructureFlags/AnonymousSlotCount properties (these should be able to move onto ClassInfo). Calls to Structure::create must now pass a pointer to the ClassInfo for the structure. All objects now have a ClassInfo pointer, non-object cell types still do not. Changes are most mechanical, involving three steps: * Remove virtual classInfo() methods. * Add &s_info parameter to calls to Structure::create. * Rename ClassInfo static members on classes from 'info' to 's_info', for consistency. Source/JavaScriptCore: * API/JSCallbackConstructor.cpp: * API/JSCallbackConstructor.h: * API/JSCallbackFunction.cpp: * API/JSCallbackFunction.h: * API/JSCallbackObject.cpp: * API/JSCallbackObject.h: * API/JSCallbackObjectFunctions.h: * API/JSObjectRef.cpp: * API/JSValueRef.cpp: * API/JSWeakObjectMapRefPrivate.cpp: * JavaScriptCore.exp: * debugger/Debugger.cpp: * debugger/DebuggerActivation.h: * debugger/DebuggerCallFrame.cpp: * interpreter/Interpreter.cpp: * jit/JITCall32_64.cpp: * jit/JITOpcodes.cpp: * jit/JITStubs.cpp: * profiler/Profiler.cpp: * runtime/Arguments.cpp: * runtime/Arguments.h: * runtime/ArrayConstructor.cpp: * runtime/ArrayPrototype.cpp: * runtime/ArrayPrototype.h: * runtime/BooleanObject.cpp: * runtime/BooleanObject.h: * runtime/BooleanPrototype.cpp: * runtime/DateConstructor.cpp: * runtime/DateInstance.cpp: * runtime/DateInstance.h: * runtime/DatePrototype.cpp: * runtime/DatePrototype.h: * runtime/ErrorInstance.cpp: * runtime/ErrorInstance.h: * runtime/ErrorPrototype.cpp: * runtime/FunctionPrototype.cpp: * runtime/FunctionPrototype.h: * runtime/GetterSetter.h: * runtime/GlobalEvalFunction.h: * runtime/InternalFunction.cpp: * runtime/InternalFunction.h: * runtime/JSAPIValueWrapper.h: * runtime/JSActivation.cpp: * runtime/JSActivation.h: * runtime/JSArray.cpp: * runtime/JSArray.h: * runtime/JSByteArray.cpp: * runtime/JSByteArray.h: * runtime/JSCell.cpp: * runtime/JSCell.h: * runtime/JSFunction.cpp: * runtime/JSFunction.h: * runtime/JSGlobalData.cpp: * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/JSNotAnObject.h: * runtime/JSONObject.cpp: * runtime/JSONObject.h: * runtime/JSObject.cpp: * runtime/JSObject.h: * runtime/JSObjectWithGlobalObject.h: * runtime/JSPropertyNameIterator.h: * runtime/JSStaticScopeObject.h: * runtime/JSString.h: * runtime/JSVariableObject.h: * runtime/JSWrapperObject.h: * runtime/JSZombie.cpp: * runtime/JSZombie.h: * runtime/Lookup.cpp: * runtime/MathObject.cpp: * runtime/MathObject.h: * runtime/NativeErrorConstructor.cpp: * runtime/NativeErrorConstructor.h: * runtime/NumberConstructor.cpp: * runtime/NumberConstructor.h: * runtime/NumberObject.cpp: * runtime/NumberObject.h: * runtime/NumberPrototype.cpp: * runtime/ObjectConstructor.cpp: * runtime/ObjectPrototype.cpp: * runtime/RegExpConstructor.cpp: * runtime/RegExpConstructor.h: * runtime/RegExpObject.cpp: * runtime/RegExpObject.h: * runtime/RegExpPrototype.cpp: * runtime/ScopeChain.cpp: * runtime/StringConstructor.cpp: * runtime/StringObject.cpp: * runtime/StringObject.h: * runtime/StringObjectThatMasqueradesAsUndefined.h: * runtime/StringPrototype.cpp: * runtime/StringPrototype.h: * runtime/Structure.cpp: * runtime/Structure.h: Source/JavaScriptGlue: * JSUtils.cpp: (KJSValueToJSObject): (KJSValueToCFTypeInternal): * UserObjectImp.cpp: * UserObjectImp.h: (UserObjectImp::createStructure): Source/WebCore: * WebCore.exp.in: * bindings/js/JSAudioConstructor.cpp: * bindings/js/JSAudioConstructor.h: * bindings/js/JSDOMBinding.cpp: * bindings/js/JSDOMBinding.h: * bindings/js/JSDOMGlobalObject.cpp: * bindings/js/JSDOMGlobalObject.h: * bindings/js/JSDOMWindowBase.cpp: * bindings/js/JSDOMWindowBase.h: * bindings/js/JSDOMWindowShell.cpp: * bindings/js/JSDOMWindowShell.h: * bindings/js/JSGeolocationCustom.cpp: * bindings/js/JSImageConstructor.cpp: * bindings/js/JSImageConstructor.h: * bindings/js/JSImageDataCustom.cpp: * bindings/js/JSOptionConstructor.cpp: * bindings/js/JSOptionConstructor.h: * bindings/js/JSWorkerContextBase.cpp: * bindings/js/JSWorkerContextBase.h: * bindings/js/SerializedScriptValue.cpp: * bindings/scripts/CodeGeneratorJS.pm: * bridge/c/CRuntimeObject.cpp: * bridge/c/CRuntimeObject.h: * bridge/c/c_instance.cpp: * bridge/jni/jsc/JNIUtilityPrivate.cpp: * bridge/jni/jsc/JavaInstanceJSC.cpp: * bridge/jni/jsc/JavaRuntimeObject.cpp: * bridge/jni/jsc/JavaRuntimeObject.h: * bridge/jsc/BridgeJSC.cpp: * bridge/objc/ObjCRuntimeObject.h: * bridge/objc/ObjCRuntimeObject.mm: * bridge/objc/objc_instance.mm: * bridge/objc/objc_runtime.h: * bridge/objc/objc_runtime.mm: * bridge/runtime_array.cpp: * bridge/runtime_array.h: * bridge/runtime_method.cpp: * bridge/runtime_method.h: * bridge/runtime_object.cpp: * bridge/runtime_object.h: Source/WebKit/mac: * Plugins/Hosted/ProxyInstance.mm: (WebKit::ProxyRuntimeMethod::ProxyRuntimeMethod): (WebKit::ProxyRuntimeMethod::createStructure): * Plugins/Hosted/ProxyRuntimeObject.h: (WebKit::ProxyRuntimeObject::createStructure): * Plugins/Hosted/ProxyRuntimeObject.mm: (WebKit::ProxyRuntimeObject::ProxyRuntimeObject): * WebView/WebView.mm: (aeDescFromJSValue): Source/WebKit2: * WebProcess/Plugins/Netscape/JSNPMethod.cpp: (WebKit::JSNPMethod::JSNPMethod): * WebProcess/Plugins/Netscape/JSNPMethod.h: (WebKit::JSNPMethod::createStructure): * WebProcess/Plugins/Netscape/JSNPObject.cpp: (WebKit::JSNPObject::JSNPObject): * WebProcess/Plugins/Netscape/JSNPObject.h: (WebKit::JSNPObject::createStructure): Canonical link: https://commits.webkit.org/69070@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@79132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 93dca5f commit 67bc1a7

159 files changed

Lines changed: 824 additions & 476 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Source/JavaScriptCore/API/JSCallbackConstructor.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
namespace JSC {
3838

39-
const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0, 0 };
39+
const ClassInfo JSCallbackConstructor::s_info = { "CallbackConstructor", &JSObjectWithGlobalObject::s_info, 0, 0 };
4040

4141
JSCallbackConstructor::JSCallbackConstructor(JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback)
4242
: JSObjectWithGlobalObject(globalObject, structure)

‎Source/JavaScriptCore/API/JSCallbackConstructor.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,18 @@ class JSCallbackConstructor : public JSObjectWithGlobalObject {
3737
virtual ~JSCallbackConstructor();
3838
JSClassRef classRef() const { return m_class; }
3939
JSObjectCallAsConstructorCallback callback() const { return m_callback; }
40-
static const ClassInfo info;
41-
40+
static const ClassInfo s_info;
41+
4242
static PassRefPtr<Structure> createStructure(JSValue proto)
43-
{
44-
return Structure::create(proto, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount);
43+
{
44+
return Structure::create(proto, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
4545
}
4646

4747
protected:
4848
static const unsigned StructureFlags = ImplementsHasInstance | JSObject::StructureFlags;
4949

5050
private:
5151
virtual ConstructType getConstructData(ConstructData&);
52-
virtual const ClassInfo* classInfo() const { return &info; }
5352

5453
JSClassRef m_class;
5554
JSObjectCallAsConstructorCallback m_callback;

‎Source/JavaScriptCore/API/JSCallbackFunction.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace JSC {
4040

4141
ASSERT_CLASS_FITS_IN_CELL(JSCallbackFunction);
4242

43-
const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunction::info, 0, 0 };
43+
const ClassInfo JSCallbackFunction::s_info = { "CallbackFunction", &InternalFunction::s_info, 0, 0 };
4444

4545
JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, const Identifier& name)
4646
: InternalFunction(&exec->globalData(), globalObject, globalObject->callbackFunctionStructure(), name)

‎Source/JavaScriptCore/API/JSCallbackFunction.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,17 @@ class JSCallbackFunction : public InternalFunction {
3535
public:
3636
JSCallbackFunction(ExecState*, JSGlobalObject*, JSObjectCallAsFunctionCallback, const Identifier& name);
3737

38-
static const ClassInfo info;
38+
static const ClassInfo s_info;
3939

4040
// InternalFunction mish-mashes constructor and function behavior -- we should
4141
// refactor the code so this override isn't necessary
4242
static PassRefPtr<Structure> createStructure(JSValue proto)
4343
{
44-
return Structure::create(proto, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount);
44+
return Structure::create(proto, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
4545
}
4646

4747
private:
4848
virtual CallType getCallData(CallData&);
49-
virtual const ClassInfo* classInfo() const { return &info; }
5049

5150
static EncodedJSValue JSC_HOST_CALL call(ExecState*);
5251

‎Source/JavaScriptCore/API/JSCallbackObject.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ASSERT_CLASS_FITS_IN_CELL(JSCallbackObject<JSObjectWithGlobalObject>);
3636
ASSERT_CLASS_FITS_IN_CELL(JSCallbackObject<JSGlobalObject>);
3737

3838
// Define the two types of JSCallbackObjects we support.
39-
template <> const ClassInfo JSCallbackObject<JSObjectWithGlobalObject>::info = { "CallbackObject", 0, 0, 0 };
40-
template <> const ClassInfo JSCallbackObject<JSGlobalObject>::info = { "CallbackGlobalObject", 0, 0, 0 };
39+
template <> const ClassInfo JSCallbackObject<JSObjectWithGlobalObject>::s_info = { "CallbackObject", &JSObjectWithGlobalObject::s_info, 0, 0 };
40+
template <> const ClassInfo JSCallbackObject<JSGlobalObject>::s_info = { "CallbackGlobalObject", &JSGlobalObject::s_info, 0, 0 };
4141

4242
} // namespace JSC

‎Source/JavaScriptCore/API/JSCallbackObject.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ class JSCallbackObject : public Base {
123123
void setPrivate(void* data);
124124
void* getPrivate();
125125

126-
static const ClassInfo info;
126+
static const ClassInfo s_info;
127127

128128
JSClassRef classRef() const { return m_callbackObjectData->jsClass; }
129129
bool inherits(JSClassRef) const;
130130

131131
static PassRefPtr<Structure> createStructure(JSValue proto)
132132
{
133-
return Structure::create(proto, TypeInfo(ObjectType, StructureFlags), Base::AnonymousSlotCount);
133+
return Structure::create(proto, TypeInfo(ObjectType, StructureFlags), Base::AnonymousSlotCount, &s_info);
134134
}
135135

136136
JSValue getPrivateProperty(const Identifier& propertyName) const
@@ -171,7 +171,6 @@ class JSCallbackObject : public Base {
171171

172172
virtual ConstructType getConstructData(ConstructData&);
173173
virtual CallType getCallData(CallData&);
174-
virtual const ClassInfo* classInfo() const { return &info; }
175174

176175
virtual void markChildren(MarkStack& markStack)
177176
{

‎Source/JavaScriptCore/API/JSCallbackObjectFunctions.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace JSC {
4545
template <class Base>
4646
inline JSCallbackObject<Base>* JSCallbackObject<Base>::asCallbackObject(JSValue value)
4747
{
48-
ASSERT(asObject(value)->inherits(&info));
48+
ASSERT(asObject(value)->inherits(&s_info));
4949
return static_cast<JSCallbackObject*>(asObject(value));
5050
}
5151

‎Source/JavaScriptCore/API/JSObjectRef.cpp‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ void* JSObjectGetPrivate(JSObjectRef object)
340340
{
341341
JSObject* jsObject = toJS(object);
342342

343-
if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info))
343+
if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::s_info))
344344
return static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->getPrivate();
345-
else if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info))
345+
if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::s_info))
346346
return static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(jsObject)->getPrivate();
347347

348348
return 0;
@@ -352,10 +352,11 @@ bool JSObjectSetPrivate(JSObjectRef object, void* data)
352352
{
353353
JSObject* jsObject = toJS(object);
354354

355-
if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info)) {
355+
if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::s_info)) {
356356
static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->setPrivate(data);
357357
return true;
358-
} else if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info)) {
358+
}
359+
if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::s_info)) {
359360
static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(jsObject)->setPrivate(data);
360361
return true;
361362
}
@@ -370,9 +371,9 @@ JSValueRef JSObjectGetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSSt
370371
JSObject* jsObject = toJS(object);
371372
JSValue result;
372373
Identifier name(propertyName->identifier(&exec->globalData()));
373-
if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info))
374+
if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::s_info))
374375
result = static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->getPrivateProperty(name);
375-
else if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info))
376+
else if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::s_info))
376377
result = static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(jsObject)->getPrivateProperty(name);
377378
return toRef(exec, result);
378379
}
@@ -384,11 +385,11 @@ bool JSObjectSetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRe
384385
JSObject* jsObject = toJS(object);
385386
JSValue jsValue = value ? toJS(exec, value) : JSValue();
386387
Identifier name(propertyName->identifier(&exec->globalData()));
387-
if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info)) {
388+
if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::s_info)) {
388389
static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->setPrivateProperty(exec->globalData(), name, jsValue);
389390
return true;
390391
}
391-
if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info)) {
392+
if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::s_info)) {
392393
static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(jsObject)->setPrivateProperty(exec->globalData(), name, jsValue);
393394
return true;
394395
}
@@ -401,11 +402,11 @@ bool JSObjectDeletePrivateProperty(JSContextRef ctx, JSObjectRef object, JSStrin
401402
APIEntryShim entryShim(exec);
402403
JSObject* jsObject = toJS(object);
403404
Identifier name(propertyName->identifier(&exec->globalData()));
404-
if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info)) {
405+
if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::s_info)) {
405406
static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->deletePrivateProperty(name);
406407
return true;
407408
}
408-
if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info)) {
409+
if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::s_info)) {
409410
static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(jsObject)->deletePrivateProperty(name);
410411
return true;
411412
}

‎Source/JavaScriptCore/API/JSValueRef.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsCla
129129
JSValue jsValue = toJS(exec, value);
130130

131131
if (JSObject* o = jsValue.getObject()) {
132-
if (o->inherits(&JSCallbackObject<JSGlobalObject>::info))
132+
if (o->inherits(&JSCallbackObject<JSGlobalObject>::s_info))
133133
return static_cast<JSCallbackObject<JSGlobalObject>*>(o)->inherits(jsClass);
134-
else if (o->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info))
134+
if (o->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::s_info))
135135
return static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(o)->inherits(jsClass);
136136
}
137137
return false;

‎Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void JSWeakObjectMapSet(JSContextRef ctx, JSWeakObjectMapRef map, void* key, JSO
5757
JSObject* obj = toJS(object);
5858
if (!obj)
5959
return;
60-
ASSERT(obj->inherits(&JSCallbackObject<JSGlobalObject>::info) || obj->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info));
60+
ASSERT(obj->inherits(&JSCallbackObject<JSGlobalObject>::s_info) || obj->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::s_info));
6161
map->map().set(key, obj);
6262
}
6363

0 commit comments

Comments
 (0)