From 17a0c271e0ec606d15fc87dab23b2e3750c0e301 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 27 Aug 2015 12:17:21 +0200 Subject: Move more objects over to the new allocation scheme Change-Id: I0241efe10d115f8e4a646f840e47e220eb6cfc18 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4arraybuffer.cpp | 12 +++++------- src/qml/jsruntime/qv4arraybuffer_p.h | 4 ++-- src/qml/jsruntime/qv4dateobject.cpp | 3 +-- src/qml/jsruntime/qv4dateobject_p.h | 8 +++----- src/qml/jsruntime/qv4engine.cpp | 37 ++++++++++++++++------------------- src/qml/jsruntime/qv4engine_p.h | 2 ++ src/qml/jsruntime/qv4object_p.h | 31 ++++++++--------------------- src/qml/jsruntime/qv4stringobject.cpp | 18 +++++------------ src/qml/jsruntime/qv4stringobject_p.h | 8 ++++++-- src/qml/jsruntime/qv4typedarray.cpp | 24 +++++++++++++---------- src/qml/jsruntime/qv4typedarray_p.h | 4 +++- 11 files changed, 66 insertions(+), 85 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4arraybuffer.cpp b/src/qml/jsruntime/qv4arraybuffer.cpp index 23c9695cf4..0a3aa414de 100644 --- a/src/qml/jsruntime/qv4arraybuffer.cpp +++ b/src/qml/jsruntime/qv4arraybuffer.cpp @@ -58,7 +58,7 @@ ReturnedValue ArrayBufferCtor::construct(const Managed *m, CallData *callData) if (len != dl) return v4->throwRangeError(QLatin1String("ArrayBuffer constructor: invalid length")); - Scoped a(scope, v4->memoryManager->alloc(v4, len)); + Scoped a(scope, v4->newArrayBuffer(len)); if (scope.engine->hasException) return Encode::undefined(); return a.asReturnedValue(); @@ -83,22 +83,20 @@ ReturnedValue ArrayBufferCtor::method_isView(CallContext *ctx) } -Heap::ArrayBuffer::ArrayBuffer(ExecutionEngine *e, size_t length) - : Heap::Object(e->emptyClass, e->arrayBufferPrototype()) +Heap::ArrayBuffer::ArrayBuffer(size_t length) { data = QTypedArrayData::allocate(length + 1); if (!data) { data = 0; - e->throwRangeError(QStringLiteral("ArrayBuffer: out of memory")); + internalClass->engine->throwRangeError(QStringLiteral("ArrayBuffer: out of memory")); return; } data->size = int(length); memset(data->data(), 0, length + 1); } -Heap::ArrayBuffer::ArrayBuffer(ExecutionEngine *e, const QByteArray& array) - : Heap::Object(e->emptyClass, e->arrayBufferPrototype()) - , data(const_cast(array).data_ptr()) +Heap::ArrayBuffer::ArrayBuffer(const QByteArray& array) + : data(const_cast(array).data_ptr()) { data->ref.ref(); } diff --git a/src/qml/jsruntime/qv4arraybuffer_p.h b/src/qml/jsruntime/qv4arraybuffer_p.h index a7f9e92c80..2a5b812546 100644 --- a/src/qml/jsruntime/qv4arraybuffer_p.h +++ b/src/qml/jsruntime/qv4arraybuffer_p.h @@ -47,8 +47,8 @@ struct ArrayBufferCtor : FunctionObject { }; struct Q_QML_PRIVATE_EXPORT ArrayBuffer : Object { - ArrayBuffer(ExecutionEngine *e, size_t length); - ArrayBuffer(ExecutionEngine *e, const QByteArray& array); + ArrayBuffer(size_t length); + ArrayBuffer(const QByteArray& array); ~ArrayBuffer(); QTypedArrayData *data; diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index 3f45751695..a6e1f47d91 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -628,8 +628,7 @@ static double getLocalTZA() DEFINE_OBJECT_VTABLE(DateObject); -Heap::DateObject::DateObject(QV4::ExecutionEngine *engine, const QDateTime &date) - : Heap::Object(engine->emptyClass, engine->datePrototype()) +Heap::DateObject::DateObject(const QDateTime &date) { this->date = date.isValid() ? date.toMSecsSinceEpoch() : qSNaN(); } diff --git a/src/qml/jsruntime/qv4dateobject_p.h b/src/qml/jsruntime/qv4dateobject_p.h index 7a6413e820..434eebfa43 100644 --- a/src/qml/jsruntime/qv4dateobject_p.h +++ b/src/qml/jsruntime/qv4dateobject_p.h @@ -46,18 +46,16 @@ namespace QV4 { namespace Heap { struct DateObject : Object { - DateObject(InternalClass *ic, QV4::Object *prototype) - : Object(ic, prototype) + DateObject() { date = qSNaN(); } - DateObject(QV4::ExecutionEngine *engine, const Value &date) - : Object(engine->emptyClass, engine->datePrototype()) + DateObject(const Value &date) { this->date = date.toNumber(); } - DateObject(QV4::ExecutionEngine *engine, const QDateTime &date); + DateObject(const QDateTime &date); double date; }; diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 6c2705871a..e9c285ea45 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -312,10 +312,12 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) Q_ASSERT(globalObject->d()->vtable()); initRootContext(); - jsObjects[StringProto] = memoryManager->alloc(emptyClass, objectPrototype()); - jsObjects[NumberProto] = memoryManager->alloc(emptyClass, objectPrototype()); - jsObjects[BooleanProto] = memoryManager->alloc(emptyClass, objectPrototype()); - jsObjects[DateProto] = memoryManager->alloc(emptyClass, objectPrototype()); + stringClass = emptyClass->addMember(id_length(), Attr_ReadOnly); + Q_ASSERT(stringClass->find(id_length()) == Heap::StringObject::LengthPropertyIndex); + jsObjects[StringProto] = memoryManager->allocObject(stringClass, objectPrototype()); + jsObjects[NumberProto] = memoryManager->allocObject(emptyClass, objectPrototype()); + jsObjects[BooleanProto] = memoryManager->allocObject(emptyClass, objectPrototype()); + jsObjects[DateProto] = memoryManager->allocObject(emptyClass, objectPrototype()); uint index; InternalClass *functionProtoClass = emptyClass->addMember(id_prototype(), Attr_NotEnumerable, &index); @@ -561,23 +563,17 @@ Heap::String *ExecutionEngine::newIdentifier(const QString &text) Heap::Object *ExecutionEngine::newStringObject(const String *string) { - Scope scope(this); - Scoped object(scope, memoryManager->alloc(this, string)); - return object->d(); + return memoryManager->allocObject(stringClass, stringPrototype(), string); } Heap::Object *ExecutionEngine::newNumberObject(double value) { - Scope scope(this); - Scoped object(scope, memoryManager->alloc(this, value)); - return object->d(); + return memoryManager->allocObject(emptyClass, numberPrototype(), value); } Heap::Object *ExecutionEngine::newBooleanObject(bool b) { - Scope scope(this); - ScopedObject object(scope, memoryManager->alloc(this, b)); - return object->d(); + return memoryManager->allocObject(emptyClass, booleanPrototype(), b); } Heap::ArrayObject *ExecutionEngine::newArrayObject(int count) @@ -609,23 +605,24 @@ Heap::ArrayObject *ExecutionEngine::newArrayObject(InternalClass *internalClass, Heap::ArrayBuffer *ExecutionEngine::newArrayBuffer(const QByteArray &array) { - Scope scope(this); - Scoped object(scope, memoryManager->alloc(this, array)); - return object->d(); + return memoryManager->allocObject(emptyClass, arrayBufferPrototype(), array); +} + +Heap::ArrayBuffer *ExecutionEngine::newArrayBuffer(size_t length) +{ + return memoryManager->allocObject(emptyClass, arrayBufferPrototype(), length); } Heap::DateObject *ExecutionEngine::newDateObject(const Value &value) { - Scope scope(this); - Scoped object(scope, memoryManager->alloc(this, value)); - return object->d(); + return memoryManager->allocObject(emptyClass, datePrototype(), value); } Heap::DateObject *ExecutionEngine::newDateObject(const QDateTime &dt) { Scope scope(this); - Scoped object(scope, memoryManager->alloc(this, dt)); + Scoped object(scope, memoryManager->allocObject(emptyClass, datePrototype(), dt)); return object->d(); } diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index ce3b235a91..dc57f05ba1 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -223,6 +223,7 @@ public: InternalClass *emptyClass; InternalClass *arrayClass; + InternalClass *stringClass; InternalClass *functionClass; InternalClass *simpleScriptFunctionClass; @@ -369,6 +370,7 @@ public: Heap::ArrayObject *newArrayObject(InternalClass *ic, Object *prototype); Heap::ArrayBuffer *newArrayBuffer(const QByteArray &array); + Heap::ArrayBuffer *newArrayBuffer(size_t length); Heap::DateObject *newDateObject(const Value &value); Heap::DateObject *newDateObject(const QDateTime &dt); diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 636755808b..578e4065c3 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -340,32 +340,18 @@ inline Object::Object(ExecutionEngine *engine) } struct BooleanObject : Object { - BooleanObject(InternalClass *ic, QV4::Object *prototype) - : Object(ic, prototype), - b(false) - { - } - - BooleanObject(ExecutionEngine *engine, bool b) - : Object(engine->emptyClass, engine->booleanPrototype()), - b(b) - { - } + BooleanObject() {} + BooleanObject(bool b) + : b(b) + {} bool b; }; struct NumberObject : Object { - NumberObject(InternalClass *ic, QV4::Object *prototype) - : Object(ic, prototype), - value(0) - { - } - - NumberObject(ExecutionEngine *engine, double val) - : Object(engine->emptyClass, engine->numberPrototype()), - value(val) - { - } + NumberObject() {} + NumberObject(double val) + : value(val) + {} double value; }; @@ -375,7 +361,6 @@ struct ArrayObject : Object { }; ArrayObject() - : Heap::Object() { init(); } ArrayObject(const QStringList &list); void init() diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index 2d90935c2a..757ec6c6bf 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -67,25 +67,17 @@ using namespace QV4; DEFINE_OBJECT_VTABLE(StringObject); -Heap::StringObject::StringObject(InternalClass *ic, QV4::Object *prototype) - : Heap::Object(ic, prototype) +Heap::StringObject::StringObject() { Q_ASSERT(vtable() == QV4::StringObject::staticVTable()); - string = ic->engine->newString(); - - Scope scope(ic->engine); - ScopedObject s(scope, this); - s->defineReadonlyProperty(ic->engine->id_length(), Primitive::fromInt32(0)); + string = internalClass->engine->id_empty()->d(); + *propertyData(LengthPropertyIndex) = Primitive::fromInt32(0); } -Heap::StringObject::StringObject(ExecutionEngine *engine, const QV4::String *str) - : Heap::Object(engine->emptyClass, engine->stringPrototype()) +Heap::StringObject::StringObject(const QV4::String *str) { string = str->d(); - - Scope scope(engine); - ScopedObject s(scope, this); - s->defineReadonlyProperty(engine->id_length(), Primitive::fromUInt32(length())); + *propertyData(LengthPropertyIndex) = Primitive::fromInt32(length()); } Heap::String *Heap::StringObject::getIndex(uint index) const diff --git a/src/qml/jsruntime/qv4stringobject_p.h b/src/qml/jsruntime/qv4stringobject_p.h index aa56a79bc3..4a7a0b383e 100644 --- a/src/qml/jsruntime/qv4stringobject_p.h +++ b/src/qml/jsruntime/qv4stringobject_p.h @@ -44,8 +44,12 @@ namespace QV4 { namespace Heap { struct StringObject : Object { - StringObject(InternalClass *ic, QV4::Object *prototype); - StringObject(ExecutionEngine *engine, const QV4::String *string); + enum { + LengthPropertyIndex = 0 + }; + + StringObject(); + StringObject(const QV4::String *string); String *string; Heap::String *getIndex(uint index) const; diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp index 56e3a98be2..b45bbb713c 100644 --- a/src/qml/jsruntime/qv4typedarray.cpp +++ b/src/qml/jsruntime/qv4typedarray.cpp @@ -216,11 +216,11 @@ ReturnedValue TypedArrayCtor::construct(const Managed *m, CallData *callData) if (l != len) scope.engine->throwRangeError(QStringLiteral("Non integer length for typed array.")); uint byteLength = len * operations[that->d()->type].bytesPerElement; - Scoped buffer(scope, scope.engine->memoryManager->alloc(scope.engine, byteLength)); + Scoped buffer(scope, scope.engine->newArrayBuffer(byteLength)); if (scope.engine->hasException) return Encode::undefined(); - Scoped array(scope, scope.engine->memoryManager->alloc(scope.engine, that->d()->type)); + Scoped array(scope, TypedArray::create(scope.engine, that->d()->type)); array->d()->buffer = buffer->d(); array->d()->byteLength = byteLength; array->d()->byteOffset = 0; @@ -236,11 +236,11 @@ ReturnedValue TypedArrayCtor::construct(const Managed *m, CallData *callData) uint byteLength = typedArray->d()->byteLength; uint destByteLength = byteLength*destElementSize/srcElementSize; - Scoped newBuffer(scope, scope.engine->memoryManager->alloc(scope.engine, destByteLength)); + Scoped newBuffer(scope, scope.engine->newArrayBuffer(destByteLength)); if (scope.engine->hasException) return Encode::undefined(); - Scoped array(scope, scope.engine->memoryManager->alloc(scope.engine, that->d()->type)); + Scoped array(scope, TypedArray::create(scope.engine, that->d()->type)); array->d()->buffer = newBuffer->d(); array->d()->byteLength = destByteLength; array->d()->byteOffset = 0; @@ -290,7 +290,7 @@ ReturnedValue TypedArrayCtor::construct(const Managed *m, CallData *callData) byteLength = (uint)l; } - Scoped array(scope, scope.engine->memoryManager->alloc(scope.engine, that->d()->type)); + Scoped array(scope, TypedArray::create(scope.engine, that->d()->type)); array->d()->buffer = buffer->d(); array->d()->byteLength = byteLength; array->d()->byteOffset = byteOffset; @@ -305,11 +305,11 @@ ReturnedValue TypedArrayCtor::construct(const Managed *m, CallData *callData) return scope.engine->throwTypeError(); uint elementSize = operations[that->d()->type].bytesPerElement; - Scoped newBuffer(scope, scope.engine->memoryManager->alloc(scope.engine, l * elementSize)); + Scoped newBuffer(scope, scope.engine->newArrayBuffer(l * elementSize)); if (scope.engine->hasException) return Encode::undefined(); - Scoped array(scope, scope.engine->memoryManager->alloc(scope.engine, that->d()->type)); + Scoped array(scope, TypedArray::create(scope.engine, that->d()->type)); array->d()->buffer = newBuffer->d(); array->d()->byteLength = l * elementSize; array->d()->byteOffset = 0; @@ -335,13 +335,17 @@ ReturnedValue TypedArrayCtor::call(const Managed *that, CallData *callData) return construct(that, callData); } -Heap::TypedArray::TypedArray(ExecutionEngine *e, Type t) - : Heap::Object(e->emptyClass, e->typedArrayPrototype + t), - type(operations + t), +Heap::TypedArray::TypedArray(Type t) + : type(operations + t), arrayType(t) { } +Heap::TypedArray *TypedArray::create(ExecutionEngine *e, Heap::TypedArray::Type t) +{ + return e->memoryManager->allocObject(e->emptyClass, e->typedArrayPrototype + t, t); +} + void TypedArray::markObjects(Heap::Base *that, ExecutionEngine *e) { static_cast(that)->buffer->mark(e); diff --git a/src/qml/jsruntime/qv4typedarray_p.h b/src/qml/jsruntime/qv4typedarray_p.h index 8e1090dcd2..b07fccba09 100644 --- a/src/qml/jsruntime/qv4typedarray_p.h +++ b/src/qml/jsruntime/qv4typedarray_p.h @@ -69,7 +69,7 @@ struct TypedArray : Object { NTypes }; - TypedArray(ExecutionEngine *e, Type t); + TypedArray(Type t); const TypedArrayOperations *type; Pointer buffer; @@ -96,6 +96,8 @@ struct Q_QML_PRIVATE_EXPORT TypedArray : Object { V4_OBJECT2(TypedArray, Object) + static Heap::TypedArray *create(QV4::ExecutionEngine *e, Heap::TypedArray::Type t); + uint byteLength() const { return d()->byteLength; } -- cgit v1.2.3