aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4string_p.h
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2015-07-03 13:20:18 +0200
committerErik Verbruggen <erik.verbruggen@theqtcompany.com>2015-07-10 13:52:18 +0000
commitc749f37c83cbb458e25a7d5200facf8634ac959e (patch)
treea1dc5909acccfb67f5534ff459ea3dae924e80f5 /src/qml/jsruntime/qv4string_p.h
parent0c7fe9a33e696b8a319f96daaaf730ed03e9b233 (diff)
V4: track C++ heap usage for Strings in the MemoryManager
... and do a GC run when it exceeds a threshold. The issue with Strings is that they hold on to QString instances that store the real content. However, the GC only sees the light-weight JS handle, and doesn't take the size of the backing content into account. So it could happen that big QStrings accumulate in the heap as long as the GC didn't reach its threshold. The newly introduced unmanaged heap threshold is upped by a factor of two when exceeded, and lowered by a factor of 2 when the used heap space falls below a quarter of the threshold. Also grow the threshold if there is enough space after running the GC, but another GC run would be triggered for the next allocation. There is a special case for Heap::String::append, because this method will copy the data from the left and right substrings into a new QString. To track this, append notifies the memory manager directly of the new length. The pointer to the memory manager is stored in Heap::String, growing it from 40 bytes to 48 bytes (which makes it still fit in the same bucket, so no extra memory is allocated). Task-number: QTBUG-42002 Change-Id: I71313915e593a9908a2b227b0bc4d768e375ee17 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/jsruntime/qv4string_p.h')
-rw-r--r--src/qml/jsruntime/qv4string_p.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h
index 5a0c83b4b9..1cf8f51a29 100644
--- a/src/qml/jsruntime/qv4string_p.h
+++ b/src/qml/jsruntime/qv4string_p.h
@@ -53,8 +53,8 @@ struct Q_QML_PRIVATE_EXPORT String : Base {
StringType_ArrayIndex
};
- String(const QString &text);
- String(String *l, String *n);
+ String(MemoryManager *mm, const QString &text);
+ String(MemoryManager *mm, String *l, String *n);
~String() {
if (!largestSubLength && !text->ref.deref())
QStringData::deallocate(text);
@@ -66,6 +66,9 @@ struct Q_QML_PRIVATE_EXPORT String : Base {
len == (uint)text->size);
return len;
}
+ std::size_t retainedTextSize() const {
+ return largestSubLength ? 0 : (std::size_t(text->size) * sizeof(QChar));
+ }
void createHashValue() const;
inline unsigned hashValue() const {
if (subtype == StringType_Unknown)
@@ -107,6 +110,7 @@ struct Q_QML_PRIVATE_EXPORT String : Base {
mutable uint stringHash;
mutable uint largestSubLength;
uint len;
+ MemoryManager *mm;
private:
static void append(const String *data, QChar *ch);
};