Changeset 64105 in webkit


Ignore:
Timestamp:
Jul 26, 2010 10:02:09 PM (14 years ago)
Author:
barraclough@apple.com
Message:

Bug 43009 - Abstract out page allocation from executable allocators

Reviewed by Oliver Hunt.

JavaScriptCore:

It would be great to have a single platform abstraction for block allocation, rather than copy/paste code.

In this initial implementation I've made Symbian fall back to use malloc/free for non-executable memory.
I think this will match current behaviour for the next client we will want to port across (RegisterFile &
Collector).

(JSC::ExecutableAllocator::intializePageSize):
(JSC::ExecutablePool::systemAlloc):
(JSC::ExecutablePool::systemRelease):
(JSC::ExecutableAllocator::isValid):

  • jit/ExecutableAllocator.h:

(JSC::ExecutablePool::ExecutablePool):
(JSC::ExecutablePool::poolAllocate):

  • jit/ExecutableAllocatorFixedVMPool.cpp:

(JSC::FixedVMPoolAllocator::release):
(JSC::FixedVMPoolAllocator::reuse):
(JSC::FixedVMPoolAllocator::FixedVMPoolAllocator):
(JSC::FixedVMPoolAllocator::alloc):
(JSC::FixedVMPoolAllocator::free):
(JSC::FixedVMPoolAllocator::isValid):
(JSC::FixedVMPoolAllocator::isWithinVMPool):
(JSC::ExecutablePool::systemAlloc):
(JSC::ExecutablePool::systemRelease):

  • jit/ExecutableAllocatorPosix.cpp: Removed.
  • jit/ExecutableAllocatorSymbian.cpp: Removed.
  • jit/ExecutableAllocatorWin.cpp: Removed.
  • wscript:
  • wtf/PageAllocator.cpp: Added.

(WTF::protection):
(WTF::PageAllocation::commit):
(WTF::PageAllocation::decommit):
(WTF::PageAllocator::allocate):
(WTF::PageAllocator::reserve):
(WTF::PageAllocator::deallocate):
(WTF::PageAllocator::pagesize):

  • wtf/PageAllocator.h: Added.

(WTF::PageAllocation::PageAllocation):
(WTF::PageAllocation::base):
(WTF::PageAllocation::size):
(WTF::PageAllocation::chunk):
(WTF::PageAllocation::operator!):
(WTF::PageAllocator::):

JavaScriptGlue:

  • ForwardingHeaders/wtf/PageAllocation.h: Added.

WebCore:

  • ForwardingHeaders/wtf/PageAllocation.h: Added.
Location:
trunk
Files:
4 added
3 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/CMakeListsEfl.txt

    r64101 r64105  
    11LIST(APPEND JavaScriptCore_SOURCES
    22    jit/ExecutableAllocatorFixedVMPool.cpp
    3     jit/ExecutableAllocatorPosix.cpp
     3    jit/ExecutableAllocator.cpp
    44    runtime/MarkStackPosix.cpp
    55)
  • trunk/JavaScriptCore/ChangeLog

    r64101 r64105  
     12010-07-26  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Bug 43009 - Abstract out page allocation from executable allocators
     6
     7        It would be great to have a single platform abstraction for block allocation, rather than copy/paste code.
     8
     9        In this initial implementation I've made Symbian fall back to use malloc/free for non-executable memory.
     10        I think this will match current behaviour for the next client we will want to port across (RegisterFile &
     11        Collector).
     12
     13        * CMakeListsEfl.txt:
     14        * GNUmakefile.am:
     15        * JavaScriptCore.gypi:
     16        * JavaScriptCore.pro:
     17        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
     18        * JavaScriptCore.xcodeproj/project.pbxproj:
     19        * jit/ExecutableAllocator.cpp:
     20        (JSC::ExecutableAllocator::intializePageSize):
     21        (JSC::ExecutablePool::systemAlloc):
     22        (JSC::ExecutablePool::systemRelease):
     23        (JSC::ExecutableAllocator::isValid):
     24        * jit/ExecutableAllocator.h:
     25        (JSC::ExecutablePool::ExecutablePool):
     26        (JSC::ExecutablePool::poolAllocate):
     27        * jit/ExecutableAllocatorFixedVMPool.cpp:
     28        (JSC::FixedVMPoolAllocator::release):
     29        (JSC::FixedVMPoolAllocator::reuse):
     30        (JSC::FixedVMPoolAllocator::FixedVMPoolAllocator):
     31        (JSC::FixedVMPoolAllocator::alloc):
     32        (JSC::FixedVMPoolAllocator::free):
     33        (JSC::FixedVMPoolAllocator::isValid):
     34        (JSC::FixedVMPoolAllocator::isWithinVMPool):
     35        (JSC::ExecutablePool::systemAlloc):
     36        (JSC::ExecutablePool::systemRelease):
     37        * jit/ExecutableAllocatorPosix.cpp: Removed.
     38        * jit/ExecutableAllocatorSymbian.cpp: Removed.
     39        * jit/ExecutableAllocatorWin.cpp: Removed.
     40        * wscript:
     41        * wtf/PageAllocator.cpp: Added.
     42        (WTF::protection):
     43        (WTF::PageAllocation::commit):
     44        (WTF::PageAllocation::decommit):
     45        (WTF::PageAllocator::allocate):
     46        (WTF::PageAllocator::reserve):
     47        (WTF::PageAllocator::deallocate):
     48        (WTF::PageAllocator::pagesize):
     49        * wtf/PageAllocator.h: Added.
     50        (WTF::PageAllocation::PageAllocation):
     51        (WTF::PageAllocation::base):
     52        (WTF::PageAllocation::size):
     53        (WTF::PageAllocation::chunk):
     54        (WTF::PageAllocation::operator!):
     55        (WTF::PageAllocator::):
     56
    1572010-07-26  Gavin Barraclough  <barraclough@apple.com>
    258
  • trunk/JavaScriptCore/GNUmakefile.am

    r64101 r64105  
    527527javascriptcore_sources += \
    528528        JavaScriptCore/wtf/ThreadSpecificWin.cpp \
    529         JavaScriptCore/jit/ExecutableAllocatorWin.cpp \
    530529        JavaScriptCore/runtime/MarkStackWin.cpp
    531530else
    532531javascriptcore_sources += \
    533532        JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp \
    534         JavaScriptCore/jit/ExecutableAllocatorPosix.cpp \
    535533        JavaScriptCore/runtime/MarkStackPosix.cpp
    536534endif
  • trunk/JavaScriptCore/JavaScriptCore.gypi

    r64101 r64105  
    111111            'jit/ExecutableAllocator.h',
    112112            'jit/ExecutableAllocatorFixedVMPool.cpp',
    113             'jit/ExecutableAllocatorPosix.cpp',
    114             'jit/ExecutableAllocatorWin.cpp',
    115113            'jit/JIT.cpp',
    116114            'jit/JIT.h',
  • trunk/JavaScriptCore/JavaScriptCore.pro

    r64101 r64105  
    9595    interpreter/RegisterFile.cpp \
    9696    jit/ExecutableAllocatorFixedVMPool.cpp \
    97     jit/ExecutableAllocatorPosix.cpp \
    98     jit/ExecutableAllocatorSymbian.cpp \
    99     jit/ExecutableAllocatorWin.cpp \
    10097    jit/ExecutableAllocator.cpp \
    10198    jit/JITArithmetic.cpp \
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj

    r64101 r64105  
    16421642                        </File>
    16431643                        <File
    1644                                 RelativePath="..\..\jit\ExecutableAllocatorWin.cpp"
    1645                                 >
    1646                         </File>
    1647                         <File
    16481644                                RelativePath="..\..\jit\JIT.cpp"
    16491645                                >
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r64101 r64105  
    199199                860161E60F3A83C100F84710 /* MacroAssemblerX86Common.h in Headers */ = {isa = PBXBuildFile; fileRef = 860161E20F3A83C100F84710 /* MacroAssemblerX86Common.h */; };
    200200                8626BECF11928E3900782FAB /* StringStatics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8626BECE11928E3900782FAB /* StringStatics.cpp */; };
     201                8627E5EB11F1281900A313B5 /* PageAllocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8627E5E911F1281900A313B5 /* PageAllocation.cpp */; };
     202                8627E5EC11F1281900A313B5 /* PageAllocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 8627E5EA11F1281900A313B5 /* PageAllocation.h */; settings = {ATTRIBUTES = (Private, ); }; };
    201203                863B23E00FC6118900703AA4 /* MacroAssemblerCodeRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 863B23DF0FC60E6200703AA4 /* MacroAssemblerCodeRef.h */; settings = {ATTRIBUTES = (Private, ); }; };
    202204                86565742115BE3DA00291F40 /* CString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86565740115BE3DA00291F40 /* CString.cpp */; };
     
    313315                A76EE6590FAE59D5003F069A /* NativeFunctionWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = A76EE6580FAE59D5003F069A /* NativeFunctionWrapper.h */; settings = {ATTRIBUTES = (Private, ); }; };
    314316                A7795590101A74D500114E55 /* MarkStack.h in Headers */ = {isa = PBXBuildFile; fileRef = A779558F101A74D500114E55 /* MarkStack.h */; settings = {ATTRIBUTES = (Private, ); }; };
    315                 A782F1A50EEC9FA20036273F /* ExecutableAllocatorPosix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A782F1A40EEC9FA20036273F /* ExecutableAllocatorPosix.cpp */; };
    316317                A783A0D111A36DCA00563D20 /* JSObjectWithGlobalObject.h in Headers */ = {isa = PBXBuildFile; fileRef = A783A0D011A36DCA00563D20 /* JSObjectWithGlobalObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
    317318                A783A2AB11A5BE8400563D20 /* JSObjectWithGlobalObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A783A2AA11A5BE8400563D20 /* JSObjectWithGlobalObject.cpp */; };
     
    768769                860161E20F3A83C100F84710 /* MacroAssemblerX86Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MacroAssemblerX86Common.h; sourceTree = "<group>"; };
    769770                8626BECE11928E3900782FAB /* StringStatics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringStatics.cpp; path = text/StringStatics.cpp; sourceTree = "<group>"; };
     771                8627E5E911F1281900A313B5 /* PageAllocation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageAllocation.cpp; sourceTree = "<group>"; };
     772                8627E5EA11F1281900A313B5 /* PageAllocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageAllocation.h; sourceTree = "<group>"; };
    770773                863B23DF0FC60E6200703AA4 /* MacroAssemblerCodeRef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MacroAssemblerCodeRef.h; sourceTree = "<group>"; };
    771774                86565740115BE3DA00291F40 /* CString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CString.cpp; path = text/CString.cpp; sourceTree = "<group>"; };
     
    813816                86D3B3C110159D7F002865E7 /* LinkBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkBuffer.h; sourceTree = "<group>"; };
    814817                86D3B3C210159D7F002865E7 /* RepatchBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RepatchBuffer.h; sourceTree = "<group>"; };
    815                 86DB645F0F954E9100D7D921 /* ExecutableAllocatorWin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExecutableAllocatorWin.cpp; sourceTree = "<group>"; };
    816818                86DB64630F95C6FC00D7D921 /* ExecutableAllocatorFixedVMPool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExecutableAllocatorFixedVMPool.cpp; sourceTree = "<group>"; };
    817819                86E116B00FE75AC800B512BC /* CodeLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodeLocation.h; sourceTree = "<group>"; };
     
    915917                A76EE6580FAE59D5003F069A /* NativeFunctionWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeFunctionWrapper.h; sourceTree = "<group>"; };
    916918                A779558F101A74D500114E55 /* MarkStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkStack.h; sourceTree = "<group>"; };
    917                 A782F1A40EEC9FA20036273F /* ExecutableAllocatorPosix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExecutableAllocatorPosix.cpp; sourceTree = "<group>"; };
    918919                A783A0D011A36DCA00563D20 /* JSObjectWithGlobalObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSObjectWithGlobalObject.h; sourceTree = "<group>"; };
    919920                A783A2AA11A5BE8400563D20 /* JSObjectWithGlobalObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSObjectWithGlobalObject.cpp; sourceTree = "<group>"; };
     
    12541255                                A7B48DB50EE74CFC00DCBDB6 /* ExecutableAllocator.h */,
    12551256                                86DB64630F95C6FC00D7D921 /* ExecutableAllocatorFixedVMPool.cpp */,
    1256                                 A782F1A40EEC9FA20036273F /* ExecutableAllocatorPosix.cpp */,
    1257                                 86DB645F0F954E9100D7D921 /* ExecutableAllocatorWin.cpp */,
    12581257                                1429D92D0ED22D7000B89619 /* JIT.cpp */,
    12591258                                1429D92E0ED22D7000B89619 /* JIT.h */,
     
    14471446                                9303F567099118FA00AD71B8 /* OwnPtr.h */,
    14481447                                440B7AED0FAF7FCB0073323E /* OwnPtrCommon.h */,
     1448                                8627E5E911F1281900A313B5 /* PageAllocation.cpp */,
     1449                                8627E5EA11F1281900A313B5 /* PageAllocation.h */,
    14491450                                44DD48520FAEA85000D6B4EB /* PassOwnPtr.h */,
    14501451                                6580F795094070560082C219 /* PassRefPtr.h */,
     
    21882189                                86D08D5411793613006E5ED0 /* WTFThreadData.h in Headers */,
    21892190                                9688CB160ED12B4E001D649F /* X86Assembler.h in Headers */,
     2191                                8627E5EC11F1281900A313B5 /* PageAllocation.h in Headers */,
    21902192                        );
    21912193                        runOnlyForDeploymentPostprocessing = 0;
     
    24972499                                A7B48F490EE8936F00DCBDB6 /* ExecutableAllocator.cpp in Sources */,
    24982500                                86DB64640F95C6FC00D7D921 /* ExecutableAllocatorFixedVMPool.cpp in Sources */,
    2499                                 A782F1A50EEC9FA20036273F /* ExecutableAllocatorPosix.cpp in Sources */,
    25002501                                14F8BA3E107EC886009892DC /* FastMalloc.cpp in Sources */,
    25012502                                147F39CB107EC37600427A48 /* FunctionConstructor.cpp in Sources */,
     
    26282629                                868BFA17117CF19900B908B1 /* WTFString.cpp in Sources */,
    26292630                                86D08D5311793613006E5ED0 /* WTFThreadData.cpp in Sources */,
     2631                                8627E5EB11F1281900A313B5 /* PageAllocation.cpp in Sources */,
    26302632                        );
    26312633                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/JavaScriptCore/jit/ExecutableAllocator.cpp

    r64101 r64105  
    3434size_t ExecutableAllocator::pageSize = 0;
    3535
     36#if ENABLE(EXECUTABLE_ALLOCATOR_DEMAND)
     37
     38void ExecutableAllocator::intializePageSize()
     39{
     40#if CPU(ARMV5_OR_LOWER)
     41    // The moving memory model (as used in ARMv5 and earlier platforms)
     42    // on Symbian OS limits the number of chunks for each process to 16.
     43    // To mitigate this limitation increase the pagesize to allocate
     44    // fewer, larger chunks. Set the page size to 256 Kb to compensate
     45    // for moving memory model limitation
     46    ExecutableAllocator::pageSize = 256 * 1024;
     47#else
     48    ExecutableAllocator::pageSize = PageAllocation::pagesize();
     49#endif
     50}
     51
     52ExecutablePool::Allocation ExecutablePool::systemAlloc(size_t size)
     53{
     54    PageAllocation allocation = PageAllocation::allocate(size, PageAllocation::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
     55    if (!allocation)
     56        CRASH();
     57    return allocation;
     58}
     59
     60void ExecutablePool::systemRelease(ExecutablePool::Allocation& allocation)
     61{
     62    allocation.deallocate();
     63}
     64
     65bool ExecutableAllocator::isValid() const
     66{
     67    return true;
     68}
     69
     70#endif
     71
    3672#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
     73
     74#if OS(WINDOWS) || OS(SYMBIAN)
     75#error "ASSEMBLER_WX_EXCLUSIVE not yet suported on this platform."
     76#endif
     77
    3778void ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSeting setting)
    3879{
     
    5394    mprotect(pageStart, size, (setting == Writable) ? PROTECTION_FLAGS_RW : PROTECTION_FLAGS_RX);
    5495}
     96
    5597#endif
    5698
    5799#if CPU(ARM_TRADITIONAL) && OS(LINUX) && COMPILER(RVCT)
     100
    58101__asm void ExecutableAllocator::cacheFlush(void* code, size_t size)
    59102{
     
    68111    bx lr
    69112}
     113
    70114#endif
    71115
  • trunk/JavaScriptCore/jit/ExecutableAllocator.h

    r64101 r64105  
    2929#include <limits>
    3030#include <wtf/Assertions.h>
     31#include <wtf/PageAllocation.h>
    3132#include <wtf/PassRefPtr.h>
    3233#include <wtf/RefCounted.h>
     
    5960#define PROTECTION_FLAGS_RW (PROT_READ | PROT_WRITE)
    6061#define PROTECTION_FLAGS_RX (PROT_READ | PROT_EXEC)
    61 #define INITIAL_PROTECTION_FLAGS PROTECTION_FLAGS_RX
    62 #else
    63 #define INITIAL_PROTECTION_FLAGS (PROT_READ | PROT_WRITE | PROT_EXEC)
     62#define EXECUTABLE_POOL_WRITABLE false
     63#else
     64#define EXECUTABLE_POOL_WRITABLE true
    6465#endif
    6566
     
    8687class ExecutablePool : public RefCounted<ExecutablePool> {
    8788private:
    88     struct Allocation {
    89         char* pages;
    90         size_t size;
    91 #if OS(SYMBIAN)
    92         RChunk* chunk;
    93 #endif
    94     };
     89    typedef PageAllocation Allocation;
    9590    typedef Vector<Allocation, 2> AllocationList;
    9691
     
    122117    ~ExecutablePool()
    123118    {
    124         AllocationList::const_iterator end = m_pools.end();
    125         for (AllocationList::const_iterator ptr = m_pools.begin(); ptr != end; ++ptr)
     119        AllocationList::iterator end = m_pools.end();
     120        for (AllocationList::iterator ptr = m_pools.begin(); ptr != end; ++ptr)
    126121            ExecutablePool::systemRelease(*ptr);
    127122    }
     
    131126private:
    132127    static Allocation systemAlloc(size_t n);
    133     static void systemRelease(const Allocation& alloc);
     128    static void systemRelease(Allocation& alloc);
    134129
    135130    ExecutablePool(size_t n);
     
    297292    Allocation mem = systemAlloc(allocSize);
    298293    m_pools.append(mem);
    299     m_freePtr = mem.pages;
     294    m_freePtr = static_cast<char*>(mem.base());
    300295    if (!m_freePtr)
    301296        CRASH(); // Failed to allocate
     
    308303   
    309304    Allocation result = systemAlloc(allocSize);
    310     if (!result.pages)
     305    if (!result.base())
    311306        CRASH(); // Failed to allocate
    312307   
     
    314309    if ((allocSize - n) > static_cast<size_t>(m_end - m_freePtr)) {
    315310        // Replace allocation pool
    316         m_freePtr = result.pages + n;
    317         m_end = result.pages + allocSize;
     311        m_freePtr = static_cast<char*>(result.base()) + n;
     312        m_end = static_cast<char*>(result.base()) + allocSize;
    318313    }
    319314
    320315    m_pools.append(result);
    321     return result.pages;
     316    return result.base();
    322317}
    323318
  • trunk/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp

    r64101 r64105  
    125125    typedef AVLTree<AVLTreeAbstractorForFreeList, 40> SizeSortedFreeTree;
    126126
    127     // Use madvise as apropriate to prevent freed pages from being spilled,
    128     // and to attempt to ensure that used memory is reported correctly.
    129 #if HAVE(MADV_FREE_REUSE)
    130127    void release(void* position, size_t size)
    131128    {
    132         while (madvise(position, size, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
     129        m_allocation.decommit(position, size);
    133130    }
    134131
    135132    void reuse(void* position, size_t size)
    136133    {
    137         while (madvise(position, size, MADV_FREE_REUSE) == -1 && errno == EAGAIN) { }
    138     }
    139 #elif HAVE(MADV_DONTNEED)
    140     void release(void* position, size_t size)
    141     {
    142         while (madvise(position, size, MADV_DONTNEED) == -1 && errno == EAGAIN) { }
    143     }
    144 
    145     void reuse(void*, size_t) {}
    146 #else
    147     void release(void*, size_t) {}
    148     void reuse(void*, size_t) {}
    149 #endif
     134        bool okay = m_allocation.commit(position, size, EXECUTABLE_POOL_WRITABLE, true);
     135        ASSERT_UNUSED(okay, okay);
     136    }
    150137
    151138    // All addition to the free list should go through this method, rather than
     
    289276        : m_commonSize(commonSize)
    290277        , m_countFreedSinceLastCoalesce(0)
    291         , m_totalHeapSize(totalHeapSize)
    292278    {
    293279        // Cook up an address to allocate at, using the following recipe:
     
    300286        // 2^24, which should put up somewhere in the middle of usespace (in the address range
    301287        // 0x200000000000 .. 0x5fffffffffff).
     288#if VM_POOL_ASLR
    302289        intptr_t randomLocation = 0;
    303 #if VM_POOL_ASLR
    304290        randomLocation = arc4random() & ((1 << 25) - 1);
    305291        randomLocation += (1 << 24);
    306292        randomLocation <<= 21;
     293        m_allocation = PageAllocation::reserveAt(reinterpret_cast<void*>(randomLocation), false, totalHeapSize, PageAllocation::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
     294#else
     295        m_allocation = PageAllocation::reserve(totalHeapSize, PageAllocation::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
    307296#endif
    308         m_base = mmap(reinterpret_cast<void*>(randomLocation), m_totalHeapSize, INITIAL_PROTECTION_FLAGS, MAP_PRIVATE | MAP_ANON, VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY, 0);
    309 
    310         if (m_base) {
    311             // For simplicity, we keep all memory in m_freeList in a 'released' state.
    312             // This means that we can simply reuse all memory when allocating, without
    313             // worrying about it's previous state, and also makes coalescing m_freeList
    314             // simpler since we need not worry about the possibility of coalescing released
    315             // chunks with non-released ones.
    316             release(m_base, m_totalHeapSize);
    317             m_freeList.insert(new FreeListEntry(m_base, m_totalHeapSize));
    318         }
     297
     298        if (!!m_allocation)
     299            m_freeList.insert(new FreeListEntry(m_allocation.base(), m_allocation.size()));
    319300#if !ENABLE(INTERPRETER)
    320301        else
     
    323304    }
    324305
    325     void* alloc(size_t size)
     306    PageAllocation alloc(size_t size)
     307    {
     308        return PageAllocation(allocInternal(size), size, m_allocation);
     309    }
     310
     311    void free(PageAllocation allocation)
     312    {
     313        void* pointer = allocation.base();
     314        size_t size = allocation.size();
     315
     316        ASSERT(!!m_allocation);
     317        // Call release to report to the operating system that this
     318        // memory is no longer in use, and need not be paged out.
     319        ASSERT(isWithinVMPool(pointer, size));
     320        release(pointer, size);
     321
     322        // Common-sized allocations are stored in the m_commonSizedAllocations
     323        // vector; all other freed chunks are added to m_freeList.
     324        if (size == m_commonSize)
     325            m_commonSizedAllocations.append(pointer);
     326        else
     327            addToFreeList(new FreeListEntry(pointer, size));
     328
     329        // Do some housekeeping.  Every time we reach a point that
     330        // 16MB of allocations have been freed, sweep m_freeList
     331        // coalescing any neighboring fragments.
     332        m_countFreedSinceLastCoalesce += size;
     333        if (m_countFreedSinceLastCoalesce >= COALESCE_LIMIT) {
     334            m_countFreedSinceLastCoalesce = 0;
     335            coalesceFreeSpace();
     336        }
     337    }
     338
     339    bool isValid() const { return !!m_allocation; }
     340
     341private:
     342    void* allocInternal(size_t size)
    326343    {
    327344#if ENABLE(INTERPRETER)
    328         if (!m_base)
     345        if (!m_allocation)
    329346            return 0;
    330347#else
    331         ASSERT(m_base);
     348        ASSERT(!!m_allocation);
    332349#endif
    333350        void* result;
     
    391408    }
    392409
    393     void free(void* pointer, size_t size)
    394     {
    395         ASSERT(m_base);
    396         // Call release to report to the operating system that this
    397         // memory is no longer in use, and need not be paged out.
    398         ASSERT(isWithinVMPool(pointer, size));
    399         release(pointer, size);
    400 
    401         // Common-sized allocations are stored in the m_commonSizedAllocations
    402         // vector; all other freed chunks are added to m_freeList.
    403         if (size == m_commonSize)
    404             m_commonSizedAllocations.append(pointer);
    405         else
    406             addToFreeList(new FreeListEntry(pointer, size));
    407 
    408         // Do some housekeeping.  Every time we reach a point that
    409         // 16MB of allocations have been freed, sweep m_freeList
    410         // coalescing any neighboring fragments.
    411         m_countFreedSinceLastCoalesce += size;
    412         if (m_countFreedSinceLastCoalesce >= COALESCE_LIMIT) {
    413             m_countFreedSinceLastCoalesce = 0;
    414             coalesceFreeSpace();
    415         }
    416     }
    417 
    418     bool isValid() const { return !!m_base; }
    419 
    420 private:
    421 
    422410#ifndef NDEBUG
    423411    bool isWithinVMPool(void* pointer, size_t size)
    424412    {
    425         return pointer >= m_base && (reinterpret_cast<char*>(pointer) + size <= reinterpret_cast<char*>(m_base) + m_totalHeapSize);
     413        return pointer >= m_allocation.base() && (reinterpret_cast<char*>(pointer) + size <= reinterpret_cast<char*>(m_allocation.base()) + m_allocation.size());
    426414    }
    427415#endif
     
    437425    size_t m_countFreedSinceLastCoalesce;
    438426
    439     void* m_base;
    440     size_t m_totalHeapSize;
     427    PageAllocation m_allocation;
    441428};
    442429
     
    460447{
    461448    SpinLockHolder lock_holder(&spinlock);
    462    
    463449    ASSERT(allocator);
    464     ExecutablePool::Allocation alloc = {reinterpret_cast<char*>(allocator->alloc(size)), size};
    465     return alloc;
    466 }
    467 
    468 void ExecutablePool::systemRelease(const ExecutablePool::Allocation& allocation)
     450    return allocator->alloc(size);
     451}
     452
     453void ExecutablePool::systemRelease(ExecutablePool::Allocation& allocation)
    469454{
    470455    SpinLockHolder lock_holder(&spinlock);
    471 
    472456    ASSERT(allocator);
    473     allocator->free(allocation.pages, allocation.size);
     457    allocator->free(allocation);
    474458}
    475459
  • trunk/JavaScriptCore/wscript

    r64101 r64105  
    3939if building_on_win32:
    4040    jscore_excludes += ['ExecutableAllocatorPosix.cpp', 'MarkStackPosix.cpp', 'ThreadingPthreads.cpp']
    41     sources += ['jit/ExecutableAllocatorWin.cpp', 'runtime/MarkStackWin.cpp']
     41    sources += ['runtime/MarkStackWin.cpp']
    4242else:
    4343    jscore_excludes.append('JSStringRefBSTR.cpp')
  • trunk/JavaScriptGlue/ChangeLog

    r62367 r64105  
     12010-07-26  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Bug 43009 - Abstract out page allocation from executable allocators
     6
     7        * ForwardingHeaders/wtf/PageAllocation.h: Added.
     8
    192010-07-01  Oliver Hunt  <oliver@apple.com>
    210
  • trunk/WebCore/ChangeLog

    r64104 r64105  
     12010-07-26  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Bug 43009 - Abstract out page allocation from executable allocators
     6
     7        * ForwardingHeaders/wtf/PageAllocation.h: Added.
     8
    192010-07-26  Yuta Kitamura  <yutak@chromium.org>
    210
Note: See TracChangeset for help on using the changeset viewer.