From 927a46b1af9728c770dabb82f0b2233600636d2a Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 27 Jan 2014 10:12:43 +0100 Subject: Rename Referenced to ManagedRef First step of removing the templates here and turning this into a class hierarchy. This is required, so we can move all member methods into the Ref classes and make objects movable during GC. Change-Id: Ie14af07fd3e72a7d84a528d0042189ff12ba21bb Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4engine.cpp | 2 +- src/qml/jsruntime/qv4engine_p.h | 2 +- src/qml/jsruntime/qv4global_p.h | 11 +++--- src/qml/jsruntime/qv4managed_p.h | 60 ++++++++++++++------------------- src/qml/jsruntime/qv4persistent_p.h | 4 +-- src/qml/jsruntime/qv4qobjectwrapper.cpp | 2 +- src/qml/jsruntime/qv4regexpobject.cpp | 2 +- src/qml/jsruntime/qv4regexpobject_p.h | 2 +- src/qml/jsruntime/qv4scopedvalue_p.h | 27 ++++++++------- src/qml/jsruntime/qv4value_p.h | 5 +-- src/qml/qml/qqmlvmemetaobject.cpp | 2 +- 11 files changed, 53 insertions(+), 66 deletions(-) (limited to 'src/qml') diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 4c1d3fceb2..6de40f437c 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -560,7 +560,7 @@ Returned *ExecutionEngine::newRegExpObject(const QString &pattern, return newRegExpObject(re, global); } -Returned *ExecutionEngine::newRegExpObject(Referenced re, bool global) +Returned *ExecutionEngine::newRegExpObject(ManagedRef re, bool global) { RegExpObject *object = new (memoryManager) RegExpObject(this, re, global); return object->asReturned(); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 6974835e8b..4fbef14f86 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -317,7 +317,7 @@ public: Returned *newDateObject(const QDateTime &dt); Returned *newRegExpObject(const QString &pattern, int flags); - Returned *newRegExpObject(Referenced re, bool global); + Returned *newRegExpObject(ManagedRef re, bool global); Returned *newRegExpObject(const QRegExp &re); Returned *newErrorObject(const ValueRef value); diff --git a/src/qml/jsruntime/qv4global_p.h b/src/qml/jsruntime/qv4global_p.h index 0337e336b9..d3764d0515 100644 --- a/src/qml/jsruntime/qv4global_p.h +++ b/src/qml/jsruntime/qv4global_p.h @@ -156,12 +156,11 @@ template struct Returned; typedef Returned ReturnedString; typedef Returned ReturnedObject; typedef Returned ReturnedFunctionObject; -template struct Referenced; -typedef Referenced ManagedRef; -typedef Referenced StringRef; -typedef Referenced ObjectRef; -typedef Referenced ArrayObjectRef; -typedef Referenced FunctionObjectRef; +template struct ManagedRef; +typedef ManagedRef StringRef; +typedef ManagedRef ObjectRef; +typedef ManagedRef ArrayObjectRef; +typedef ManagedRef FunctionObjectRef; struct PersistentValuePrivate; class PersistentValue; diff --git a/src/qml/jsruntime/qv4managed_p.h b/src/qml/jsruntime/qv4managed_p.h index aa9fb0d0fb..ed4637e4f5 100644 --- a/src/qml/jsruntime/qv4managed_p.h +++ b/src/qml/jsruntime/qv4managed_p.h @@ -354,34 +354,36 @@ private: }; template -struct Referenced { - // Important: Do NOT add a copy constructor to this class +struct ManagedRef { + // Important: Do NOT add a copy constructor to this class or any derived class // adding a copy constructor actually changes the calling convention, ie. // is not even binary compatible. Adding it would break assumptions made // in the jit'ed code. - Referenced(const Scoped &v); - Referenced(TypedValue &v) { ptr = &v; } - Referenced(Value &v) { + ManagedRef(const ScopedValue); + ManagedRef(const Scoped &v); + ManagedRef(TypedValue &v) { ptr = &v; } + ManagedRef(Value &v) { ptr = value_cast(v) ? &v : 0; } - static Referenced fromValuePointer(Value *s) { - return Referenced(s); + static ManagedRef fromValuePointer(Value *s) { + ManagedRef r(s); + if (sizeof(void *) == 8) + r.ptr->val = 0; + else + *r.ptr = Value::fromManaged(0); + return r; } - Referenced &operator=(const Referenced &o) - { *ptr = *o.ptr; return *this; } - Referenced &operator=(T *t) + ManagedRef &operator=(T *t) { -#if QT_POINTER_SIZE == 4 - ptr->tag = Value::Managed_Type; -#endif + if (sizeof(void *) == 4) + ptr->tag = Value::Managed_Type; ptr->m = t; return *this; } - Referenced &operator=(Returned *t) { -#if QT_POINTER_SIZE == 4 - ptr->tag = Value::Managed_Type; -#endif + ManagedRef &operator=(Returned *t) { + if (sizeof(void *) == 4) + ptr->tag = Value::Managed_Type; ptr->m = t->getPointer(); return *this; } @@ -406,38 +408,26 @@ struct Referenced { ReturnedValue asReturnedValue() const { return ptr ? ptr->val : Primitive::undefinedValue().asReturnedValue(); } operator Returned *() const { return ptr ? Returned::create(getPointer()) : 0; } - bool operator==(const Referenced &other) { + bool operator==(const ManagedRef &other) { if (ptr == other.ptr) return true; return ptr && other.ptr && ptr->m == other.ptr->m; } - bool operator!=(const Referenced &other) { - if (ptr == other.ptr) - return false; - return !ptr || ptr->m != other.ptr->m; + bool operator!=(const ManagedRef &other) { + return !operator==(other); } bool operator!() const { return !ptr || !ptr->managed(); } - static Referenced null() { return Referenced(Null); } + static ManagedRef null() { return ManagedRef((Value *)0); } bool isNull() const { return !ptr; } -private: - Referenced(Value *v) { +protected: + ManagedRef(Value *v) { ptr = v; -#if QT_POINTER_SIZE == 8 - ptr->val = 0; -#else - *ptr = Value::fromManaged(0); -#endif } - enum _Null { Null }; - Referenced(_Null) { ptr = 0; } Value *ptr; }; -typedef Referenced ManagedRef; - - template<> inline Managed *value_cast(const Value &v) { return v.asManaged(); diff --git a/src/qml/jsruntime/qv4persistent_p.h b/src/qml/jsruntime/qv4persistent_p.h index 07e8ee9775..34cf9ba50d 100644 --- a/src/qml/jsruntime/qv4persistent_p.h +++ b/src/qml/jsruntime/qv4persistent_p.h @@ -85,13 +85,13 @@ public: template PersistentValue(Returned *obj); template - PersistentValue(const Referenced obj); + PersistentValue(const ManagedRef obj); PersistentValue &operator=(const ValueRef other); PersistentValue &operator =(ReturnedValue other); template PersistentValue &operator=(Returned *obj); template - PersistentValue &operator=(const Referenced obj); + PersistentValue &operator=(const ManagedRef obj); ~PersistentValue(); ReturnedValue value() const { diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 25b1aee281..4645efcbeb 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1702,7 +1702,7 @@ QV4::ReturnedValue CallArgument::toValue(QV8Engine *engine) } else if (type == -1 || type == qMetaTypeId()) { QVariant value = *qvariantPtr; QV4::ScopedValue rv(scope, engine->fromVariant(value)); - if (QV4::Referenced qobjectWrapper = rv->asRef()) { + if (QV4::ManagedRef qobjectWrapper = rv) { if (QObject *object = qobjectWrapper->object()) QQmlData::get(object, true)->setImplicitDestructible(); } diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index 3b1dc02194..35ba9bc483 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -80,7 +80,7 @@ RegExpObject::RegExpObject(InternalClass *ic) init(ic->engine); } -RegExpObject::RegExpObject(ExecutionEngine *engine, Referenced value, bool global) +RegExpObject::RegExpObject(ExecutionEngine *engine, ManagedRef value, bool global) : Object(engine->regExpClass) , value(value) , global(global) diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h index cf699509cd..ce3d01725f 100644 --- a/src/qml/jsruntime/qv4regexpobject_p.h +++ b/src/qml/jsruntime/qv4regexpobject_p.h @@ -84,7 +84,7 @@ struct RegExpObject: Object { Property *lastIndexProperty(ExecutionContext *ctx); bool global; - RegExpObject(ExecutionEngine *engine, Referenced value, bool global); + RegExpObject(ExecutionEngine *engine, ManagedRef value, bool global); RegExpObject(ExecutionEngine *engine, const QRegExp &re); ~RegExpObject() {} diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index ce21404a53..9b9f062a9a 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -379,9 +379,9 @@ struct ScopedCallData { }; -typedef Referenced StringRef; -typedef Referenced ObjectRef; -typedef Referenced FunctionObjectRef; +typedef ManagedRef StringRef; +typedef ManagedRef ObjectRef; +typedef ManagedRef FunctionObjectRef; template inline Scoped::Scoped(const Scope &scope, const ValueRef &v) @@ -464,12 +464,6 @@ inline Returned *Value::as() return Returned::create(value_cast(*this)); } -template inline -Referenced Value::asRef() -{ - return Referenced(*this); -} - template inline TypedValue &TypedValue::operator =(T *t) { @@ -492,7 +486,7 @@ inline TypedValue &TypedValue::operator=(Returned *t) } template -inline TypedValue &TypedValue::operator =(const Referenced &v) +inline TypedValue &TypedValue::operator =(const ManagedRef &v) { val = v.asReturnedValue(); return *this; @@ -524,7 +518,7 @@ PersistentValue::PersistentValue(Returned *obj) } template -inline PersistentValue::PersistentValue(const Referenced obj) +inline PersistentValue::PersistentValue(const ManagedRef obj) : d(new PersistentValuePrivate(*obj.ptr)) { } @@ -536,7 +530,7 @@ inline PersistentValue &PersistentValue::operator=(Returned *obj) } template -inline PersistentValue &PersistentValue::operator=(const Referenced obj) +inline PersistentValue &PersistentValue::operator=(const ManagedRef obj) { return operator=(*obj.ptr); } @@ -577,8 +571,15 @@ inline ValueRef &ValueRef::operator=(const ScopedValue &o) return *this; } + +template +ManagedRef::ManagedRef(const ScopedValue v) +{ + ptr = value_cast(*v.ptr) ? v.ptr : 0; +} + template -Referenced::Referenced(const Scoped &v) +ManagedRef::ManagedRef(const Scoped &v) : ptr(v.ptr) {} diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 536057ef26..2aefcc4f30 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -356,9 +356,6 @@ struct Q_QML_EXPORT Value } template inline Returned *as(); - template - inline Referenced asRef(); - }; inline Managed *Value::asManaged() const @@ -436,7 +433,7 @@ struct TypedValue : public Value } TypedValue &operator =(T *t); TypedValue &operator =(const Scoped &v); - TypedValue &operator =(const Referenced &v); + TypedValue &operator =(const ManagedRef &v); TypedValue &operator =(Returned *t); TypedValue &operator =(const TypedValue &t); diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 0b966484ca..48893c1b7f 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -1086,7 +1086,7 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) // And, if the new value is a scarce resource, we need to ensure that it does not get // automatically released by the engine until no other references to it exist. QV4::ScopedValue newv(scope, QQmlEnginePrivate::get(ctxt->engine)->v8engine()->fromVariant(value)); - if (QV4::Referenced v = newv->asRef()) + if (QV4::ManagedRef v = newv) v->addVmePropertyReference(); // Write the value and emit change signal as appropriate. -- cgit v1.2.3