Changeset 62511 in webkit


Ignore:
Timestamp:
Jul 5, 2010 5:22:42 PM (14 years ago)
Author:
barraclough@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=41641

Reviewed by Sam Weinig.

Update compile flags to allow use of ExecutableAllocatorFixedVMPool on platforms
other than x86-64 (this may be useful on 32-bit platforms, too).

Simplify ifdefs by dividing into thwo broad allocation strategies
(ENABLE_EXECUTABLE_ALLOCATOR_FIXED & ENABLE_EXECUTABLE_ALLOCATOR_DEMAND).

Rename constant used in the code to have names descriptive of their purpose,
rather than their specific value on a given platform.

  • jit/ExecutableAllocator.cpp:

(JSC::ExecutableAllocator::reprotectRegion):
(JSC::ExecutableAllocator::cacheFlush):

  • jit/ExecutableAllocatorFixedVMPool.cpp:

(JSC::FixedVMPoolAllocator::FixedVMPoolAllocator):
(JSC::FixedVMPoolAllocator::free):
(JSC::ExecutablePool::systemAlloc):

  • jit/ExecutableAllocatorPosix.cpp:
  • jit/ExecutableAllocatorSymbian.cpp:
  • jit/ExecutableAllocatorWin.cpp:
  • wtf/Platform.h:
Location:
trunk/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r62493 r62511  
     12010-07-05  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=41641
     6
     7        Update compile flags to allow use of ExecutableAllocatorFixedVMPool on platforms
     8        other than x86-64 (this may be useful on 32-bit platforms, too).
     9
     10        Simplify ifdefs by dividing into thwo broad allocation strategies
     11        (ENABLE_EXECUTABLE_ALLOCATOR_FIXED & ENABLE_EXECUTABLE_ALLOCATOR_DEMAND).
     12
     13        Rename constant used in the code to have names descriptive of their purpose,
     14        rather than their specific value on a given platform.
     15
     16        * jit/ExecutableAllocator.cpp:
     17        (JSC::ExecutableAllocator::reprotectRegion):
     18        (JSC::ExecutableAllocator::cacheFlush):
     19        * jit/ExecutableAllocatorFixedVMPool.cpp:
     20        (JSC::FixedVMPoolAllocator::FixedVMPoolAllocator):
     21        (JSC::FixedVMPoolAllocator::free):
     22        (JSC::ExecutablePool::systemAlloc):
     23        * jit/ExecutableAllocatorPosix.cpp:
     24        * jit/ExecutableAllocatorSymbian.cpp:
     25        * jit/ExecutableAllocatorWin.cpp:
     26        * wtf/Platform.h:
     27
    1282010-07-05  Steve Block  <steveblock@google.com>
    229
  • trunk/JavaScriptCore/jit/ExecutableAllocator.cpp

    r39083 r62511  
    3434size_t ExecutableAllocator::pageSize = 0;
    3535
     36#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
     37void ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSeting setting)
     38{
     39    if (!pageSize)
     40        intializePageSize();
     41
     42    // Calculate the start of the page containing this region,
     43    // and account for this extra memory within size.
     44    intptr_t startPtr = reinterpret_cast<intptr_t>(start);
     45    intptr_t pageStartPtr = startPtr & ~(pageSize - 1);
     46    void* pageStart = reinterpret_cast<void*>(pageStartPtr);
     47    size += (startPtr - pageStartPtr);
     48
     49    // Round size up
     50    size += (pageSize - 1);
     51    size &= ~(pageSize - 1);
     52
     53    mprotect(pageStart, size, (setting == Writable) ? PROTECTION_FLAGS_RW : PROTECTION_FLAGS_RX);
     54}
     55#endif
     56
     57#if CPU(ARM_TRADITIONAL) && OS(LINUX) && COMPILER(RVCT)
     58__asm void ExecutableAllocator::cacheFlush(void* code, size_t size)
     59{
     60    ARM
     61    push {r7}
     62    add r1, r1, r0
     63    mov r7, #0xf0000
     64    add r7, r7, #0x2
     65    mov r2, #0x0
     66    svc #0x0
     67    pop {r7}
     68    bx lr
     69}
     70#endif
     71
    3672}
    3773
  • trunk/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp

    r57821 r62511  
    2828#include "ExecutableAllocator.h"
    2929
    30 #if ENABLE(ASSEMBLER) && OS(DARWIN) && CPU(X86_64)
     30#if ENABLE(EXECUTABLE_ALLOCATOR_FIXED)
    3131
    3232#include <errno.h>
     
    4040#include <wtf/VMTags.h>
    4141
     42#if CPU(X86_64)
     43    // These limits suitable on 64-bit platforms (particularly x86-64, where we require all jumps to have a 2Gb max range).
     44    #define VM_POOL_SIZE (2u * 1024u * 1024u * 1024u) // 2Gb
     45    #define COALESCE_LIMIT (16u * 1024u * 1024u) // 16Mb
     46    #define VM_POOL_ASLR 1
     47#else
     48    // These limits are hopefully sensible on embedded platforms.
     49    #define VM_POOL_SIZE (32u * 1024u * 1024u) // 32Mb
     50    #define COALESCE_LIMIT (4u * 1024u * 1024u) // 4Mb
     51    #define VM_POOL_ASLR 0
     52#endif
     53
    4254using namespace WTF;
    4355
    4456namespace JSC {
    45 
    46 #define TWO_GB (2u * 1024u * 1024u * 1024u)
    47 #define SIXTEEN_MB (16u * 1024u * 1024u)
    4857
    4958// FreeListEntry describes a free chunk of memory, stored in the freeList.
     
    292301        // 2^24, which should put up somewhere in the middle of usespace (in the address range
    293302        // 0x200000000000 .. 0x5fffffffffff).
    294         intptr_t randomLocation = arc4random() & ((1 << 25) - 1);
     303        intptr_t randomLocation = 0;
     304#if VM_POOL_ASLR
     305        randomLocation = arc4random() & ((1 << 25) - 1);
    295306        randomLocation += (1 << 24);
    296307        randomLocation <<= 21;
     308#endif
    297309        m_base = mmap(reinterpret_cast<void*>(randomLocation), m_totalHeapSize, INITIAL_PROTECTION_FLAGS, MAP_PRIVATE | MAP_ANON, VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY, 0);
    298310        if (!m_base)
     
    388400        // coalescing any neighboring fragments.
    389401        m_countFreedSinceLastCoalesce += size;
    390         if (m_countFreedSinceLastCoalesce >= SIXTEEN_MB) {
     402        if (m_countFreedSinceLastCoalesce >= COALESCE_LIMIT) {
    391403            m_countFreedSinceLastCoalesce = 0;
    392404            coalesceFreeSpace();
     
    430442
    431443    if (!allocator)
    432         allocator = new FixedVMPoolAllocator(JIT_ALLOCATOR_LARGE_ALLOC_SIZE, TWO_GB);
     444        allocator = new FixedVMPoolAllocator(JIT_ALLOCATOR_LARGE_ALLOC_SIZE, VM_POOL_SIZE);
    433445    ExecutablePool::Allocation alloc = {reinterpret_cast<char*>(allocator->alloc(size)), size};
    434446    return alloc;
  • trunk/JavaScriptCore/jit/ExecutableAllocatorPosix.cpp

    r58167 r62511  
    2828#include "ExecutableAllocator.h"
    2929
    30 #if ENABLE(ASSEMBLER) && OS(UNIX) && !OS(SYMBIAN)
     30#if ENABLE(EXECUTABLE_ALLOCATOR_DEMAND) && !OS(WINDOWS) && !OS(SYMBIAN)
    3131
    3232#include <sys/mman.h>
     
    3535
    3636namespace JSC {
    37 
    38 #if !(OS(DARWIN) && CPU(X86_64))
    3937
    4038void ExecutableAllocator::intializePageSize()
     
    5856}
    5957
    60 #endif // !(OS(DARWIN) && CPU(X86_64))
    61 
    62 #if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
    63 void ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSeting setting)
    64 {
    65     if (!pageSize)
    66         intializePageSize();
    67 
    68     // Calculate the start of the page containing this region,
    69     // and account for this extra memory within size.
    70     intptr_t startPtr = reinterpret_cast<intptr_t>(start);
    71     intptr_t pageStartPtr = startPtr & ~(pageSize - 1);
    72     void* pageStart = reinterpret_cast<void*>(pageStartPtr);
    73     size += (startPtr - pageStartPtr);
    74 
    75     // Round size up
    76     size += (pageSize - 1);
    77     size &= ~(pageSize - 1);
    78 
    79     mprotect(pageStart, size, (setting == Writable) ? PROTECTION_FLAGS_RW : PROTECTION_FLAGS_RX);
    80 }
    81 #endif
    82 
    83 #if CPU(ARM_TRADITIONAL) && OS(LINUX) && COMPILER(RVCT)
    84 __asm void ExecutableAllocator::cacheFlush(void* code, size_t size)
    85 {
    86     ARM
    87     push {r7}
    88     add r1, r1, r0
    89     mov r7, #0xf0000
    90     add r7, r7, #0x2
    91     mov r2, #0x0
    92     svc #0x0
    93     pop {r7}
    94     bx lr
    95 }
    96 #endif
    97 
    9858}
    9959
    100 #endif // HAVE(ASSEMBLER)
     60#endif
  • trunk/JavaScriptCore/jit/ExecutableAllocatorSymbian.cpp

    r52791 r62511  
    2323#include "ExecutableAllocator.h"
    2424
    25 #if ENABLE(ASSEMBLER) && OS(SYMBIAN)
     25#if ENABLE(EXECUTABLE_ALLOCATOR_DEMAND) && OS(SYMBIAN)
    2626
    2727#include <e32hal.h>
  • trunk/JavaScriptCore/jit/ExecutableAllocatorWin.cpp

    r52791 r62511  
    2828#include "ExecutableAllocator.h"
    2929
    30 #if ENABLE(ASSEMBLER) && OS(WINDOWS)
     30#if ENABLE(EXECUTABLE_ALLOCATOR_DEMAND) && OS(WINDOWS)
    3131
    3232#include "windows.h"
  • trunk/JavaScriptCore/wtf/Platform.h

    r62422 r62511  
    10441044#endif
    10451045
     1046/* Pick which allocator to use; we only need an executable allocator if the assembler is compiled in.
     1047   On x86-64 we use a single fixed mmap, on other platforms we mmap on demand. */
     1048#if ENABLE(ASSEMBLER)
     1049#if CPU(X86_64)
     1050#define ENABLE_EXECUTABLE_ALLOCATOR_FIXED 1
     1051#else
     1052#define ENABLE_EXECUTABLE_ALLOCATOR_DEMAND 1
     1053#endif
     1054#endif
     1055
    10461056#if !defined(ENABLE_PAN_SCROLLING) && OS(WINDOWS)
    10471057#define ENABLE_PAN_SCROLLING 1
Note: See TracChangeset for help on using the changeset viewer.