Add an actual write barrier and centralize it in one place
All stores into the Heap from C++ and Moth should now go through the write barrier. Change-Id: Iae9347754b90d68c10fade9f345842e86ec460cd Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
c13baa8873
commit
b214d6cc2f
|
@ -366,8 +366,8 @@ QV4DataCollector::Ref QV4DataCollector::addRef(QV4::Value value, bool deduplicat
|
|||
{
|
||||
class ExceptionStateSaver
|
||||
{
|
||||
quint32 *hasExceptionLoc;
|
||||
quint32 hadException;
|
||||
quint8 *hasExceptionLoc;
|
||||
quint8 hadException;
|
||||
|
||||
public:
|
||||
ExceptionStateSaver(QV4::ExecutionEngine *engine)
|
||||
|
|
|
@ -1249,7 +1249,7 @@ public:
|
|||
const RegisterInformation &fpRegistersToSave);
|
||||
|
||||
void checkException() {
|
||||
load32(Address(EngineRegister, qOffsetOf(QV4::ExecutionEngine, hasException)), ScratchRegister);
|
||||
this->load8(Address(EngineRegister, qOffsetOf(QV4::ExecutionEngine, hasException)), ScratchRegister);
|
||||
Jump exceptionThrown = branch32(RelationalCondition::NotEqual, ScratchRegister, TrustedImm32(0));
|
||||
if (catchBlock)
|
||||
addPatch(catchBlock, exceptionThrown);
|
||||
|
|
|
@ -100,7 +100,9 @@ public:
|
|||
Heap::ExecutionContext *current;
|
||||
|
||||
Value *jsStackTop;
|
||||
quint32 hasException;
|
||||
quint8 hasException;
|
||||
quint8 writeBarrierActive = false;
|
||||
quint16 unused = 0;
|
||||
qint32 callDepth;
|
||||
|
||||
MemoryManager *memoryManager;
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "qv4global_p.h"
|
||||
#include "qv4value_p.h"
|
||||
#include <private/qv4heap_p.h>
|
||||
#include <private/qv4writebarrier_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
@ -708,52 +708,6 @@ inline unsigned int Value::toUInt32() const
|
|||
return (unsigned int)toInt32();
|
||||
}
|
||||
|
||||
template <size_t offset>
|
||||
struct HeapValue : Value {
|
||||
void set(ExecutionEngine *e, const Value &newVal) {
|
||||
Q_UNUSED(e);
|
||||
setRawValue(newVal.rawValue());
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t offset>
|
||||
struct ValueArray {
|
||||
uint size;
|
||||
uint alloc;
|
||||
Value values[1];
|
||||
|
||||
void set(ExecutionEngine *e, uint index, Value v) {
|
||||
Q_UNUSED(e);
|
||||
Q_ASSERT(index < alloc);
|
||||
values[index] = v;
|
||||
}
|
||||
void set(ExecutionEngine *e, uint index, Heap::Base *b) {
|
||||
Q_UNUSED(e);
|
||||
Q_ASSERT(index < alloc);
|
||||
values[index] = b;
|
||||
}
|
||||
inline const Value &operator[] (uint index) const {
|
||||
Q_ASSERT(index < alloc);
|
||||
return values[index];
|
||||
}
|
||||
inline const Value *data() const {
|
||||
return values;
|
||||
}
|
||||
|
||||
void insertData(ExecutionEngine *e, uint index, Value v) {
|
||||
for (uint i = size - 1; i > index; --i) {
|
||||
values[i] = values[i - 1];
|
||||
}
|
||||
set(e, index, v);
|
||||
}
|
||||
void removeData(ExecutionEngine *e, uint index, int n = 1) {
|
||||
Q_UNUSED(e);
|
||||
for (uint i = index; i < size - n; ++i) {
|
||||
values[i] = values[i + n];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
@ -344,8 +344,13 @@ Param traceParam(const Param ¶m)
|
|||
QV4::ReturnedValue tmp = (value); \
|
||||
if (engine->hasException) \
|
||||
goto catchException; \
|
||||
VALUE(param) = tmp; \
|
||||
}
|
||||
if (Q_LIKELY(!engine->writeBarrierActive || !scopes[param.scope].base)) { \
|
||||
VALUE(param) = tmp; \
|
||||
} else { \
|
||||
QV4::WriteBarrier::write(engine, scopes[param.scope].base, VALUEPTR(param), QV4::Value::fromReturnedValue(tmp)); \
|
||||
} \
|
||||
}
|
||||
|
||||
// qv4scopedvalue_p.h also defines a CHECK_EXCEPTION macro
|
||||
#ifdef CHECK_EXCEPTION
|
||||
#undef CHECK_EXCEPTION
|
||||
|
|
|
@ -7,7 +7,8 @@ SOURCES += \
|
|||
|
||||
HEADERS += \
|
||||
$$PWD/qv4mm_p.h \
|
||||
$$PWD/qv4mmdefs_p.h
|
||||
$$PWD/qv4mmdefs_p.h \
|
||||
$$PWD/qv4writebarrier_p.h
|
||||
}
|
||||
|
||||
HEADERS += \
|
||||
|
|
|
@ -164,26 +164,6 @@ struct Q_QML_EXPORT Base {
|
|||
};
|
||||
V4_ASSERT_IS_TRIVIAL(Base)
|
||||
|
||||
template <typename T, size_t o>
|
||||
struct Pointer {
|
||||
static Q_CONSTEXPR size_t offset = o;
|
||||
T operator->() const { return ptr; }
|
||||
operator T () const { return ptr; }
|
||||
|
||||
void set(ExecutionEngine *e, T newVal) {
|
||||
Q_UNUSED(e);
|
||||
ptr = newVal;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
Type *cast() { return static_cast<Type *>(ptr); }
|
||||
|
||||
private:
|
||||
T ptr;
|
||||
};
|
||||
typedef Pointer<char *, 0> V4PointerCheck;
|
||||
V4_ASSERT_IS_TRIVIAL(V4PointerCheck)
|
||||
|
||||
}
|
||||
|
||||
#ifdef QT_NO_QOBJECT
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtQml module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
#ifndef QV4WRITEBARRIER_P_H
|
||||
#define QV4WRITEBARRIER_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <private/qv4global_p.h>
|
||||
#include <private/qv4value_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace QV4 {
|
||||
|
||||
namespace WriteBarrier {
|
||||
|
||||
inline void write(QV4::ExecutionEngine *engine, QV4::Heap::Base *base, QV4::Value *slot, QV4::Value value)
|
||||
{
|
||||
Q_UNUSED(engine);
|
||||
Q_UNUSED(base);
|
||||
*slot = value;
|
||||
}
|
||||
|
||||
inline void write(QV4::ExecutionEngine *engine, QV4::Heap::Base *base, QV4::Heap::Base **slot, QV4::Heap::Base *value)
|
||||
{
|
||||
Q_UNUSED(engine);
|
||||
Q_UNUSED(base);
|
||||
*slot = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Heap {
|
||||
|
||||
template <typename T, size_t o>
|
||||
struct Pointer {
|
||||
static Q_CONSTEXPR size_t offset = o;
|
||||
T operator->() const { return ptr; }
|
||||
operator T () const { return ptr; }
|
||||
|
||||
void set(ExecutionEngine *e, T newVal) {
|
||||
Q_UNUSED(e);
|
||||
ptr = newVal;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
Type *cast() { return static_cast<Type *>(ptr); }
|
||||
|
||||
private:
|
||||
T ptr;
|
||||
};
|
||||
typedef Pointer<char *, 0> V4PointerCheck;
|
||||
V4_ASSERT_IS_TRIVIAL(V4PointerCheck)
|
||||
|
||||
}
|
||||
|
||||
template <size_t offset>
|
||||
struct HeapValue : Value {
|
||||
void set(ExecutionEngine *e, const Value &newVal) {
|
||||
Q_UNUSED(e);
|
||||
setRawValue(newVal.rawValue());
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t offset>
|
||||
struct ValueArray {
|
||||
uint size;
|
||||
uint alloc;
|
||||
Value values[1];
|
||||
|
||||
void set(ExecutionEngine *e, uint index, Value v) {
|
||||
Q_UNUSED(e);
|
||||
Q_ASSERT(index < alloc);
|
||||
values[index] = v;
|
||||
}
|
||||
void set(ExecutionEngine *e, uint index, Heap::Base *b) {
|
||||
Q_UNUSED(e);
|
||||
Q_ASSERT(index < alloc);
|
||||
values[index] = b;
|
||||
}
|
||||
inline const Value &operator[] (uint index) const {
|
||||
Q_ASSERT(index < alloc);
|
||||
return values[index];
|
||||
}
|
||||
inline const Value *data() const {
|
||||
return values;
|
||||
}
|
||||
|
||||
void insertData(ExecutionEngine *e, uint index, Value v) {
|
||||
for (uint i = size - 1; i > index; --i) {
|
||||
values[i] = values[i - 1];
|
||||
}
|
||||
set(e, index, v);
|
||||
}
|
||||
void removeData(ExecutionEngine *e, uint index, int n = 1) {
|
||||
Q_UNUSED(e);
|
||||
for (uint i = index; i < size - n; ++i) {
|
||||
values[i] = values[i + n];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue