[BlackBerry] Implement OSAllocator::commit/decommit in the correct way
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Mar 2012 20:39:15 +0000 (20:39 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Mar 2012 20:39:15 +0000 (20:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77013

We should use mmap(PROT_NONE, MAP_LAZY) instead of posix_madvise() to
implement memory decommitting for QNX.

Patch by Yong Li <yoli@rim.com> on 2012-03-19
Reviewed by Rob Buis.

* wtf/OSAllocatorPosix.cpp:
(WTF::OSAllocator::reserveUncommitted):
(WTF::OSAllocator::commit):
(WTF::OSAllocator::decommit):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@111234 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/wtf/OSAllocatorPosix.cpp

index 2454ffe98f6fbb6f97ef5a71b8641fae639966e1..8d6ef3f210e50c9cf69ae093d8e01a13ba8c9078 100644 (file)
@@ -1,3 +1,18 @@
+2012-03-19  Yong Li  <yoli@rim.com>
+
+        [BlackBerry] Implement OSAllocator::commit/decommit in the correct way
+        https://bugs.webkit.org/show_bug.cgi?id=77013
+
+        We should use mmap(PROT_NONE, MAP_LAZY) instead of posix_madvise() to
+        implement memory decommitting for QNX.
+
+        Reviewed by Rob Buis.
+
+        * wtf/OSAllocatorPosix.cpp:
+        (WTF::OSAllocator::reserveUncommitted):
+        (WTF::OSAllocator::commit):
+        (WTF::OSAllocator::decommit):
+
 2012-03-19  Gavin Barraclough  <barraclough@apple.com>
 
         Unreviewed - revent a couple of files accidentally committed.
index f14ecb8da82f421afae9d319f19c4a2cd0108331..d1df2d0e918ff60b9a916cc028e6e62b1df7568d 100644 (file)
@@ -36,15 +36,23 @@ namespace WTF {
 
 void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable, bool executable, bool includesGuardPages)
 {
-    void* result = reserveAndCommit(bytes, usage, writable, executable, includesGuardPages);
 #if OS(QNX)
-    posix_madvise(result, bytes, POSIX_MADV_DONTNEED);
-#elif OS(LINUX)
+    // Reserve memory with PROT_NONE and MAP_LAZY so it isn't committed now.
+    void* result = mmap(0, bytes, PROT_NONE, MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
+    if (result == MAP_FAILED)
+        CRASH();
+#else // OS(QNX)
+
+    void* result = reserveAndCommit(bytes, usage, writable, executable, includesGuardPages);
+#if OS(LINUX)
     madvise(result, bytes, MADV_DONTNEED);
 #elif HAVE(MADV_FREE_REUSE)
     // To support the "reserve then commit" model, we have to initially decommit.
     while (madvise(result, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
 #endif
+
+#endif // OS(QNX)
+
     return result;
 }
 
@@ -122,25 +130,38 @@ void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bo
     return result;
 }
 
-void OSAllocator::commit(void* address, size_t bytes, bool, bool)
+void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable)
 {
 #if OS(QNX)
-    posix_madvise(address, bytes, POSIX_MADV_WILLNEED);
+    int protection = PROT_READ;
+    if (writable)
+        protection |= PROT_WRITE;
+    if (executable)
+        protection |= PROT_EXEC;
+    if (MAP_FAILED == mmap(address, bytes, protection, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0))
+        CRASH();
 #elif OS(LINUX)
+    UNUSED_PARAM(writable);
+    UNUSED_PARAM(executable);
     madvise(address, bytes, MADV_WILLNEED);
 #elif HAVE(MADV_FREE_REUSE)
+    UNUSED_PARAM(writable);
+    UNUSED_PARAM(executable);
     while (madvise(address, bytes, MADV_FREE_REUSE) == -1 && errno == EAGAIN) { }
 #else
     // Non-MADV_FREE_REUSE reservations automatically commit on demand.
     UNUSED_PARAM(address);
     UNUSED_PARAM(bytes);
+    UNUSED_PARAM(writable);
+    UNUSED_PARAM(executable);
 #endif
 }
 
 void OSAllocator::decommit(void* address, size_t bytes)
 {
 #if OS(QNX)
-    posix_madvise(address, bytes, POSIX_MADV_DONTNEED);
+    // Use PROT_NONE and MAP_LAZY to decommit the pages.
+    mmap(address, bytes, PROT_NONE, MAP_FIXED | MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
 #elif OS(LINUX)
     madvise(address, bytes, MADV_DONTNEED);
 #elif HAVE(MADV_FREE_REUSE)