Title: [111234] trunk/Source/_javascript_Core
Revision
111234
Author
[email protected]
Date
2012-03-19 13:39:15 -0700 (Mon, 19 Mar 2012)

Log Message

[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.

Patch by Yong Li <[email protected]> on 2012-03-19
Reviewed by Rob Buis.

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

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (111233 => 111234)


--- trunk/Source/_javascript_Core/ChangeLog	2012-03-19 20:29:41 UTC (rev 111233)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-03-19 20:39:15 UTC (rev 111234)
@@ -1,3 +1,18 @@
+2012-03-19  Yong Li  <[email protected]>
+
+        [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  <[email protected]>
 
         Unreviewed - revent a couple of files accidentally committed.

Modified: trunk/Source/_javascript_Core/wtf/OSAllocatorPosix.cpp (111233 => 111234)


--- trunk/Source/_javascript_Core/wtf/OSAllocatorPosix.cpp	2012-03-19 20:29:41 UTC (rev 111233)
+++ trunk/Source/_javascript_Core/wtf/OSAllocatorPosix.cpp	2012-03-19 20:39:15 UTC (rev 111234)
@@ -36,15 +36,23 @@
 
 void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable, bool executable, bool includesGuardPages)
 {
+#if OS(QNX)
+    // 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(QNX)
-    posix_madvise(result, bytes, POSIX_MADV_DONTNEED);
-#elif OS(LINUX)
+#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 @@
     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)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to