diff options
Diffstat (limited to 'src/qml/memory/qv4mmdefs_p.h')
-rw-r--r-- | src/qml/memory/qv4mmdefs_p.h | 113 |
1 files changed, 51 insertions, 62 deletions
diff --git a/src/qml/memory/qv4mmdefs_p.h b/src/qml/memory/qv4mmdefs_p.h index 8a53492822..b77b615e6c 100644 --- a/src/qml/memory/qv4mmdefs_p.h +++ b/src/qml/memory/qv4mmdefs_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QV4MMDEFS_P_H #define QV4MMDEFS_P_H @@ -53,10 +17,12 @@ #include <private/qv4global_p.h> #include <private/qv4runtimeapi_p.h> #include <QtCore/qalgorithms.h> -#include <qdebug.h> +#include <QtCore/qmath.h> QT_BEGIN_NAMESPACE +class QDeadlineTimer; + namespace QV4 { struct MarkStack; @@ -95,7 +61,7 @@ struct Chunk { SlotSizeShift = 5, NumSlots = ChunkSize/SlotSize, BitmapSize = NumSlots/8, - HeaderSize = 4*BitmapSize, + HeaderSize = 3*BitmapSize, DataSize = ChunkSize - HeaderSize, AvailableSlots = DataSize/SlotSize, #if QT_POINTER_SIZE == 8 @@ -107,7 +73,6 @@ struct Chunk { #endif EntriesInBitmap = BitmapSize/sizeof(quintptr) }; - quintptr grayBitmap[BitmapSize/sizeof(quintptr)]; quintptr blackBitmap[BitmapSize/sizeof(quintptr)]; quintptr objectBitmap[BitmapSize/sizeof(quintptr)]; quintptr extendsBitmap[BitmapSize/sizeof(quintptr)]; @@ -188,7 +153,6 @@ struct Chunk { bool sweep(ClassDestroyStatsCallback classCountPtr); void resetBlackBits(); - void collectGrayItems(QV4::MarkStack *markStack); bool sweep(ExecutionEngine *engine); void freeAll(ExecutionEngine *engine); @@ -212,19 +176,14 @@ struct HeapItem { return reinterpret_cast<Chunk *>(reinterpret_cast<quintptr>(this) >> Chunk::ChunkShift << Chunk::ChunkShift); } - bool isGray() const { - Chunk *c = chunk(); - uint index = this - c->realBase(); - return Chunk::testBit(c->grayBitmap, index); - } bool isBlack() const { Chunk *c = chunk(); - uint index = this - c->realBase(); + std::ptrdiff_t index = this - c->realBase(); return Chunk::testBit(c->blackBitmap, index); } bool isInUse() const { Chunk *c = chunk(); - uint index = this - c->realBase(); + std::ptrdiff_t index = this - c->realBase(); return Chunk::testBit(c->objectBitmap, index); } @@ -243,10 +202,10 @@ struct HeapItem { // Doesn't report correctly for huge items size_t size() const { Chunk *c = chunk(); - uint index = this - c->realBase(); + std::ptrdiff_t index = this - c->realBase(); Q_ASSERT(Chunk::testBit(c->objectBitmap, index)); // ### optimize me - uint end = index + 1; + std::ptrdiff_t end = index + 1; while (end < Chunk::NumSlots && Chunk::testBit(c->extendsBitmap, end)) ++end; return (end - index)*sizeof(HeapItem); @@ -270,22 +229,52 @@ Q_STATIC_ASSERT(sizeof(HeapItem) == Chunk::SlotSize); Q_STATIC_ASSERT(QT_POINTER_SIZE*8 == Chunk::Bits); Q_STATIC_ASSERT((1 << Chunk::BitShift) == Chunk::Bits); -struct MarkStack { +struct Q_QML_EXPORT MarkStack { MarkStack(ExecutionEngine *engine); - Heap::Base **top = nullptr; - Heap::Base **base = nullptr; - Heap::Base **limit = nullptr; - ExecutionEngine *engine; + ~MarkStack() { /* we drain manually */ } + void push(Heap::Base *m) { - *top = m; - ++top; + *(m_top++) = m; + + if (m_top < m_softLimit) + return; + + // If at or above soft limit, partition the remaining space into at most 64 segments and + // allow one C++ recursion of drain() per segment, plus one for the fence post. + const quintptr segmentSize = qNextPowerOfTwo(quintptr(m_hardLimit - m_softLimit) / 64u); + if (m_drainRecursion * segmentSize <= quintptr(m_top - m_softLimit)) { + ++m_drainRecursion; + drain(); + --m_drainRecursion; + } else if (m_top == m_hardLimit) { + qFatal("GC mark stack overrun. Either simplify your application or" + "increase QV4_GC_MAX_STACK_SIZE"); + } } - Heap::Base *pop() { - --top; - return *top; + + bool isEmpty() const { return m_top == m_base; } + + qptrdiff remainingBeforeSoftLimit() const + { + return m_softLimit - m_top; } + + ExecutionEngine *engine() const { return m_engine; } + void drain(); + enum class DrainState { Ongoing, Complete }; + DrainState drain(QDeadlineTimer deadline); +private: + Heap::Base *pop() { return *(--m_top); } + + Heap::Base **m_top = nullptr; + Heap::Base **m_base = nullptr; + Heap::Base **m_softLimit = nullptr; + Heap::Base **m_hardLimit = nullptr; + + ExecutionEngine *m_engine = nullptr; + quintptr m_drainRecursion = 0; }; // Some helper to automate the generation of our @@ -329,7 +318,7 @@ struct MarkStack { struct name##SizeStruct : base, name##OffsetStruct {}; \ struct name##Data { \ typedef base SuperClass; \ - static Q_CONSTEXPR size_t baseOffset = sizeof(name##SizeStruct) - sizeof(name##OffsetStruct); \ + static constexpr size_t baseOffset = sizeof(name##SizeStruct) - sizeof(name##OffsetStruct); \ name##Members(name, HEAP_OBJECT_MEMBER_EXPANSION) \ }; \ Q_STATIC_ASSERT(sizeof(name##SizeStruct) == sizeof(name##Data) + name##Data::baseOffset); \ |