summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/javascriptcore
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>2012-09-12 15:05:55 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-09-13 00:50:18 (GMT)
commit86f965de44c9b8285d84ac60254276ede4f743eb (patch)
tree012c2406194ee30340205f8d40485cd9b4ad31de /src/3rdparty/javascriptcore
parentcd8bc427d788071ff10c355647094a8364219ff2 (diff)
downloadQt-86f965de44c9b8285d84ac60254276ede4f743eb.zip
Qt-86f965de44c9b8285d84ac60254276ede4f743eb.tar.gz
Qt-86f965de44c9b8285d84ac60254276ede4f743eb.tar.bz2
QNX: Do not initially commit all memory used in RegisterFile
This reduces memory consumption of an application quite a bit. This is a backport of 3958828af8ee5cc046c664d8d8e483314eac06cb from qtjsbackend. At the same time, it is a backport of upstream commit http://trac.webkit.org/changeset/111234, although the patch is quite different as upstream and Qt's JSC have diverged a lot. Change-Id: Ia76359ae614ddd4aeda9c7c7b012e5809b50074d Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com> Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
Diffstat (limited to 'src/3rdparty/javascriptcore')
-rw-r--r--src/3rdparty/javascriptcore/JavaScriptCore/interpreter/RegisterFile.cpp12
-rw-r--r--src/3rdparty/javascriptcore/JavaScriptCore/interpreter/RegisterFile.h31
2 files changed, 39 insertions, 4 deletions
diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/RegisterFile.cpp b/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/RegisterFile.cpp
index 293fc38..ef4f525 100644
--- a/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/RegisterFile.cpp
+++ b/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/RegisterFile.cpp
@@ -49,7 +49,17 @@ RegisterFile::~RegisterFile()
void RegisterFile::releaseExcessCapacity()
{
-#if HAVE(MMAP) && HAVE(MADV_FREE) && !HAVE(VIRTUALALLOC)
+#if OS(QNX)
+ size_t sizeForGlobals = roundUpAllocationSize(m_maxGlobals * sizeof(Register), commitSize);
+ Register *endOfGlobals = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_buffer) + sizeForGlobals);
+ size_t decommitSize = (m_max - endOfGlobals) * sizeof(Register);
+ if (decommitSize > 0) {
+ if (mmap(endOfGlobals, decommitSize, PROT_NONE, MAP_FIXED|MAP_LAZY|MAP_PRIVATE|MAP_ANON, -1, 0) == MAP_FAILED)
+ fprintf(stderr, "Could not decommit register file memory: %d\n", errno);
+ }
+ m_commitEnd = endOfGlobals;
+
+#elif HAVE(MMAP) && HAVE(MADV_FREE) && !HAVE(VIRTUALALLOC)
while (madvise(m_start, (m_max - m_start) * sizeof(Register), MADV_FREE) == -1 && errno == EAGAIN) { }
#elif HAVE(VIRTUALALLOC)
VirtualFree(m_start, (m_max - m_start) * sizeof(Register), MEM_DECOMMIT);
diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/RegisterFile.h b/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/RegisterFile.h
index 49304d9..0b7731c 100644
--- a/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/RegisterFile.h
+++ b/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/RegisterFile.h
@@ -153,7 +153,7 @@ namespace JSC {
Register* m_buffer;
Register* m_maxUsed;
-#if HAVE(VIRTUALALLOC)
+#if HAVE(VIRTUALALLOC) || OS(QNX)
Register* m_commitEnd;
#endif
#if OS(SYMBIAN)
@@ -186,7 +186,23 @@ namespace JSC {
ASSERT(isPageAligned(capacity));
size_t bufferLength = (capacity + maxGlobals) * sizeof(Register);
- #if HAVE(MMAP)
+ #if OS(QNX)
+ // First, reserve uncommitted memory
+ m_buffer = reinterpret_cast<Register*>(mmap(0, bufferLength, PROT_NONE, MAP_LAZY|MAP_PRIVATE|MAP_ANON, VM_TAG_FOR_REGISTERFILE_MEMORY, 0));
+ if (m_buffer == MAP_FAILED) {
+ fprintf(stderr, "Could not reserve register file memory: %d\n", errno);
+ CRASH();
+ }
+
+ // Now, commit as much as we need for the globals
+ size_t committedSize = roundUpAllocationSize(maxGlobals * sizeof(Register), commitSize);
+ if (mmap(m_buffer, committedSize, PROT_READ|PROT_WRITE, MAP_FIXED|MAP_PRIVATE|MAP_ANON, VM_TAG_FOR_REGISTERFILE_MEMORY, 0) == MAP_FAILED) {
+ fprintf(stderr, "Could not commit register file memory: %d\n", errno);
+ CRASH();
+ }
+ m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_buffer) + committedSize);
+
+ #elif HAVE(MMAP)
m_buffer = reinterpret_cast<Register*>(mmap(0, bufferLength, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, VM_TAG_FOR_REGISTERFILE_MEMORY, 0));
if (m_buffer == MAP_FAILED) {
#if OS(WINCE)
@@ -262,7 +278,16 @@ namespace JSC {
if (newEnd > m_max)
return false;
-#if !HAVE(MMAP) && HAVE(VIRTUALALLOC)
+#if OS(QNX)
+ if (newEnd > m_commitEnd) {
+ size_t size = roundUpAllocationSize(reinterpret_cast<char*>(newEnd) - reinterpret_cast<char*>(m_commitEnd), commitSize);
+ if (mmap(m_commitEnd, size, PROT_READ|PROT_WRITE, MAP_FIXED|MAP_PRIVATE|MAP_ANON, VM_TAG_FOR_REGISTERFILE_MEMORY, 0) == MAP_FAILED) {
+ fprintf(stderr, "Could not grow committed register file memory: %d\n", errno);
+ CRASH();
+ }
+ m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_commitEnd) + size);
+ }
+#elif !HAVE(MMAP) && HAVE(VIRTUALALLOC)
if (newEnd > m_commitEnd) {
size_t size = roundUpAllocationSize(reinterpret_cast<char*>(newEnd) - reinterpret_cast<char*>(m_commitEnd), commitSize);
if (!VirtualAlloc(m_commitEnd, size, MEM_COMMIT, PAGE_READWRITE)) {