Changeset 111234 in webkit


Ignore:
Timestamp:
Mar 19, 2012 1:39:15 PM (12 years ago)
Author:
commit-queue@webkit.org
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 <yoli@rim.com> on 2012-03-19
Reviewed by Rob Buis.

  • wtf/OSAllocatorPosix.cpp:

(WTF::OSAllocator::reserveUncommitted):
(WTF::OSAllocator::commit):
(WTF::OSAllocator::decommit):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r111223 r111234  
     12012-03-19  Yong Li  <yoli@rim.com>
     2
     3        [BlackBerry] Implement OSAllocator::commit/decommit in the correct way
     4        https://bugs.webkit.org/show_bug.cgi?id=77013
     5
     6        We should use mmap(PROT_NONE, MAP_LAZY) instead of posix_madvise() to
     7        implement memory decommitting for QNX.
     8
     9        Reviewed by Rob Buis.
     10
     11        * wtf/OSAllocatorPosix.cpp:
     12        (WTF::OSAllocator::reserveUncommitted):
     13        (WTF::OSAllocator::commit):
     14        (WTF::OSAllocator::decommit):
     15
    1162012-03-19  Gavin Barraclough  <barraclough@apple.com>
    217
  • trunk/Source/JavaScriptCore/wtf/OSAllocatorPosix.cpp

    r110874 r111234  
    3737void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable, bool executable, bool includesGuardPages)
    3838{
     39#if OS(QNX)
     40    // Reserve memory with PROT_NONE and MAP_LAZY so it isn't committed now.
     41    void* result = mmap(0, bytes, PROT_NONE, MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
     42    if (result == MAP_FAILED)
     43        CRASH();
     44#else // OS(QNX)
     45
    3946    void* result = reserveAndCommit(bytes, usage, writable, executable, includesGuardPages);
    40 #if OS(QNX)
    41     posix_madvise(result, bytes, POSIX_MADV_DONTNEED);
    42 #elif OS(LINUX)
     47#if OS(LINUX)
    4348    madvise(result, bytes, MADV_DONTNEED);
    4449#elif HAVE(MADV_FREE_REUSE)
     
    4651    while (madvise(result, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
    4752#endif
     53
     54#endif // OS(QNX)
     55
    4856    return result;
    4957}
     
    123131}
    124132
    125 void OSAllocator::commit(void* address, size_t bytes, bool, bool)
     133void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable)
    126134{
    127135#if OS(QNX)
    128     posix_madvise(address, bytes, POSIX_MADV_WILLNEED);
     136    int protection = PROT_READ;
     137    if (writable)
     138        protection |= PROT_WRITE;
     139    if (executable)
     140        protection |= PROT_EXEC;
     141    if (MAP_FAILED == mmap(address, bytes, protection, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0))
     142        CRASH();
    129143#elif OS(LINUX)
     144    UNUSED_PARAM(writable);
     145    UNUSED_PARAM(executable);
    130146    madvise(address, bytes, MADV_WILLNEED);
    131147#elif HAVE(MADV_FREE_REUSE)
     148    UNUSED_PARAM(writable);
     149    UNUSED_PARAM(executable);
    132150    while (madvise(address, bytes, MADV_FREE_REUSE) == -1 && errno == EAGAIN) { }
    133151#else
     
    135153    UNUSED_PARAM(address);
    136154    UNUSED_PARAM(bytes);
     155    UNUSED_PARAM(writable);
     156    UNUSED_PARAM(executable);
    137157#endif
    138158}
     
    141161{
    142162#if OS(QNX)
    143     posix_madvise(address, bytes, POSIX_MADV_DONTNEED);
     163    // Use PROT_NONE and MAP_LAZY to decommit the pages.
     164    mmap(address, bytes, PROT_NONE, MAP_FIXED | MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
    144165#elif OS(LINUX)
    145166    madvise(address, bytes, MADV_DONTNEED);
Note: See TracChangeset for help on using the changeset viewer.