From 7501c394d00df4a4f8db0b92107250ccefabdfb4 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 25 Mar 2015 13:49:51 +0100 Subject: Continue the work to move Values inside the v4 engine to the js stack Started with objectPrototype, the next commits will move more of them over into the new data structure. Change-Id: I1a048e95149ce69e4e42094db2dd738ce49b50b8 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4argumentsobject.cpp | 2 +- src/qml/jsruntime/qv4engine.cpp | 28 ++++++++++++++-------------- src/qml/jsruntime/qv4engine_p.h | 8 +++++++- src/qml/jsruntime/qv4functionobject.cpp | 4 ++-- src/qml/jsruntime/qv4jsonobject.cpp | 2 +- src/qml/jsruntime/qv4mathobject.cpp | 2 +- src/qml/jsruntime/qv4object_p.h | 12 +++++++----- src/qml/jsruntime/qv4regexpobject_p.h | 2 +- src/qml/jsruntime/qv4runtime.cpp | 2 +- 9 files changed, 35 insertions(+), 27 deletions(-) (limited to 'src/qml') diff --git a/src/qml/jsruntime/qv4argumentsobject.cpp b/src/qml/jsruntime/qv4argumentsobject.cpp index 20983bb362..d7a8127a5b 100644 --- a/src/qml/jsruntime/qv4argumentsobject.cpp +++ b/src/qml/jsruntime/qv4argumentsobject.cpp @@ -41,7 +41,7 @@ DEFINE_OBJECT_VTABLE(ArgumentsObject); Heap::ArgumentsObject::ArgumentsObject(QV4::CallContext *context) : Heap::Object(context->d()->strictMode ? context->d()->engine->strictArgumentsObjectClass : context->d()->engine->argumentsObjectClass, - context->d()->engine->objectPrototype.objectValue()) + context->d()->engine->objectPrototype()) , context(context->d()) , fullyCreated(false) { diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index b05b080fd8..480949b56c 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -228,6 +228,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) exceptionValue = jsAlloca(1); globalObject = static_cast(jsAlloca(1)); + jsObjects = jsAlloca(NJSObjects); #ifdef V4_USE_VALGRIND VALGRIND_MAKE_MEM_UNDEFINED(jsStackBase, 2*JSStackLimit); @@ -282,10 +283,10 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) id_buffer = newIdentifier(QStringLiteral("buffer")); id_lastIndex = newIdentifier(QStringLiteral("lastIndex")); - objectPrototype = memoryManager->alloc(emptyClass, (QV4::Object *)0); + jsObjects[ObjectProto] = memoryManager->alloc(emptyClass, (QV4::Object *)0); arrayClass = emptyClass->addMember(id_length, Attr_NotConfigurable|Attr_NotEnumerable); - arrayPrototype = memoryManager->alloc(arrayClass, objectPrototype.as()); + arrayPrototype = memoryManager->alloc(arrayClass, objectPrototype()); InternalClass *argsClass = emptyClass->addMember(id_length, Attr_NotEnumerable); argumentsObjectClass = argsClass->addMember(id_callee, Attr_Data|Attr_NotEnumerable); @@ -296,15 +297,15 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) Q_ASSERT(globalObject->d()->vtable); initRootContext(); - stringPrototype = memoryManager->alloc(emptyClass, objectPrototype.as()); - numberPrototype = memoryManager->alloc(emptyClass, objectPrototype.as()); - booleanPrototype = memoryManager->alloc(emptyClass, objectPrototype.as()); - datePrototype = memoryManager->alloc(emptyClass, objectPrototype.as()); + stringPrototype = memoryManager->alloc(emptyClass, objectPrototype()); + numberPrototype = memoryManager->alloc(emptyClass, objectPrototype()); + booleanPrototype = memoryManager->alloc(emptyClass, objectPrototype()); + datePrototype = memoryManager->alloc(emptyClass, objectPrototype()); uint index; InternalClass *functionProtoClass = emptyClass->addMember(id_prototype, Attr_NotEnumerable, &index); Q_ASSERT(index == Heap::FunctionObject::Index_Prototype); - functionPrototype = memoryManager->alloc(functionProtoClass, objectPrototype.as()); + functionPrototype = memoryManager->alloc(functionProtoClass, objectPrototype()); functionClass = emptyClass->addMember(id_prototype, Attr_NotEnumerable|Attr_NotConfigurable, &index); Q_ASSERT(index == Heap::FunctionObject::Index_Prototype); simpleScriptFunctionClass = functionClass->addMember(id_name, Attr_ReadOnly, &index); @@ -320,7 +321,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) regExpExecArrayClass = regExpExecArrayClass->addMember(id_input, Attr_Data, &index); Q_ASSERT(index == RegExpObject::Index_ArrayInput); - errorPrototype = memoryManager->alloc(emptyClass, objectPrototype.as()); + errorPrototype = memoryManager->alloc(emptyClass, objectPrototype()); evalErrorPrototype = memoryManager->alloc(emptyClass, errorPrototype.as()); rangeErrorPrototype = memoryManager->alloc(emptyClass, errorPrototype.as()); referenceErrorPrototype = memoryManager->alloc(emptyClass, errorPrototype.as()); @@ -328,8 +329,8 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) typeErrorPrototype = memoryManager->alloc(emptyClass, errorPrototype.as()); uRIErrorPrototype = memoryManager->alloc(emptyClass, errorPrototype.as()); - variantPrototype = memoryManager->alloc(emptyClass, objectPrototype.as()); - Q_ASSERT(variantPrototype.as()->prototype() == objectPrototype.as()->d()); + variantPrototype = memoryManager->alloc(emptyClass, objectPrototype()); + Q_ASSERT(variantPrototype.as()->prototype() == objectPrototype()->d()); Scope scope(this); sequencePrototype = ScopedValue(scope, memoryManager->alloc(arrayClass, arrayPrototype.as())); @@ -351,7 +352,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) typeErrorCtor = memoryManager->alloc(global); uRIErrorCtor = memoryManager->alloc(global); - static_cast(objectPrototype.as())->init(this, objectCtor.as()); + static_cast(objectPrototype())->init(this, objectCtor.as()); static_cast(stringPrototype.as())->init(this, stringCtor.as()); static_cast(numberPrototype.as())->init(this, numberCtor.as()); static_cast(booleanPrototype.as())->init(this, booleanCtor.as()); @@ -374,11 +375,11 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) // typed arrays arrayBufferCtor = memoryManager->alloc(global); - arrayBufferPrototype = memoryManager->alloc(emptyClass, objectPrototype.as()); + arrayBufferPrototype = memoryManager->alloc(emptyClass, objectPrototype()); static_cast(arrayBufferPrototype.as())->init(this, arrayBufferCtor.as()); dataViewCtor = memoryManager->alloc(global); - dataViewPrototype = memoryManager->alloc(emptyClass, objectPrototype.as()); + dataViewPrototype = memoryManager->alloc(emptyClass, objectPrototype()); static_cast(dataViewPrototype.as())->init(this, dataViewCtor.as()); for (int i = 0; i < Heap::TypedArray::NTypes; ++i) { @@ -951,7 +952,6 @@ void ExecutionEngine::markObjects() for (int i = 0; i < Heap::TypedArray::NTypes; ++i) typedArrayCtors[i].mark(this); - objectPrototype.mark(this); arrayPrototype.mark(this); stringPrototype.mark(this); numberPrototype.mark(this); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index a6a05c0483..a71491ac32 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -128,6 +128,12 @@ public: QQmlEngine *qmlEngine() const; QV8Engine *v8Engine; + enum JSObjects { + ObjectProto, + NJSObjects + }; + Value *jsObjects; + Value objectCtor; Value stringCtor; Value numberCtor; @@ -148,7 +154,7 @@ public: enum { NTypedArrayTypes = 9 }; // avoid header dependency Value typedArrayCtors[NTypedArrayTypes]; - Value objectPrototype; + Object *objectPrototype() { return reinterpret_cast(jsObjects + ObjectProto); } Value arrayPrototype; Value stringPrototype; Value numberPrototype; diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 5a68cf6b79..2c8da4c943 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -152,7 +152,7 @@ void FunctionObject::init(String *n, bool createProto) ensureMemberIndex(s.engine, Heap::FunctionObject::Index_Prototype); if (createProto) { - ScopedObject proto(s, scope()->engine->newObject(s.engine->protoClass, s.engine->objectPrototype.as())); + ScopedObject proto(s, scope()->engine->newObject(s.engine->protoClass, s.engine->objectPrototype())); proto->ensureMemberIndex(s.engine, Heap::FunctionObject::Index_ProtoConstructor); proto->memberData()->data[Heap::FunctionObject::Index_ProtoConstructor] = this->asReturnedValue(); memberData()->data[Heap::FunctionObject::Index_Prototype] = proto.asReturnedValue(); @@ -574,7 +574,7 @@ Heap::Object *SimpleScriptFunction::protoForConstructor() ScopedObject p(scope, protoProperty()); if (p) return p->d(); - return scope.engine->objectPrototype.as()->d(); + return scope.engine->objectPrototype()->d(); } diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index e2b27c545b..95d08d7a10 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -852,7 +852,7 @@ QString Stringify::JA(ArrayObject *a) Heap::JsonObject::JsonObject(ExecutionEngine *e) - : Heap::Object(e->emptyClass, e->objectPrototype.objectValue()) + : Heap::Object(e->emptyClass, e->objectPrototype()) { Scope scope(e); ScopedObject o(scope, this); diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index 4e51de9291..c498160c36 100644 --- a/src/qml/jsruntime/qv4mathobject.cpp +++ b/src/qml/jsruntime/qv4mathobject.cpp @@ -48,7 +48,7 @@ DEFINE_OBJECT_VTABLE(MathObject); static const double qt_PI = 2.0 * ::asin(1.0); Heap::MathObject::MathObject(ExecutionEngine *e) - : Heap::Object(e->emptyClass, e->objectPrototype.objectValue()) + : Heap::Object(e->emptyClass, e->objectPrototype()) { Scope scope(e); ScopedObject m(scope, this); diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 87c024b7b9..3375b16116 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -47,11 +47,7 @@ namespace QV4 { namespace Heap { struct Object : Base { - Object(ExecutionEngine *engine) - : internalClass(engine->emptyClass), - prototype(static_cast(engine->objectPrototype.m)) - { - } + inline Object(ExecutionEngine *engine); Object(InternalClass *internal, QV4::Object *prototype); const Property *propertyAt(uint index) const { return reinterpret_cast(memberData->data + index); } @@ -334,6 +330,12 @@ private: namespace Heap { +inline Object::Object(ExecutionEngine *engine) + : internalClass(engine->emptyClass), + prototype(static_cast(engine->objectPrototype()->m)) +{ +} + struct BooleanObject : Object { BooleanObject(InternalClass *ic, QV4::Object *prototype) : Object(ic, prototype), diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h index af83282fe4..29d20614de 100644 --- a/src/qml/jsruntime/qv4regexpobject_p.h +++ b/src/qml/jsruntime/qv4regexpobject_p.h @@ -146,7 +146,7 @@ struct RegExpPrototype: RegExpObject }; inline Heap::RegExpPrototype::RegExpPrototype(ExecutionEngine *e) - : RegExpObject(e->emptyClass, e->objectPrototype.objectValue()) + : RegExpObject(e->emptyClass, e->objectPrototype()) { } diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index bff9eaf927..f2565e2636 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -1200,7 +1200,7 @@ ReturnedValue Runtime::objectLiteral(ExecutionEngine *engine, const QV4::Value * { Scope scope(engine); QV4::InternalClass *klass = engine->currentContext()->compilationUnit->runtimeClasses[classId]; - ScopedObject o(scope, engine->newObject(klass, engine->objectPrototype.as())); + ScopedObject o(scope, engine->newObject(klass, engine->objectPrototype())); { bool needSparseArray = arrayGetterSetterCountAndFlags >> 30; -- cgit v1.2.3