Changeset 39673 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Jan 6, 2009, 11:41:33 PM (16 years ago)
Author:
[email protected]
Message:

<rdar://problem/6040850> JavaScript register file should use VirtualAlloc on Windows

Reviewed by Gavin Barraclough.

Fairly simple, just reserve 4Mb of address space for the
register file, and then commit one section at a time. We
don't release committed memory as we drop back, but then
mac doesn't either so this probably not too much of a
problem.

Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r39672 r39673  
     12009-01-06  Oliver Hunt  <[email protected]>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        <rdar://problem/6040850> JavaScript register file should use VirtualAlloc on Windows
     6
     7        Fairly simple, just reserve 4Mb of address space for the
     8        register file, and then commit one section at a time.  We
     9        don't release committed memory as we drop back, but then
     10        mac doesn't either so this probably not too much of a
     11        problem.
     12
     13        * interpreter/RegisterFile.cpp:
     14        (JSC::RegisterFile::~RegisterFile):
     15        * interpreter/RegisterFile.h:
     16        (JSC::RegisterFile::RegisterFile):
     17        (JSC::RegisterFile::grow):
     18
    1192009-01-06  Alexey Proskuryakov  <[email protected]>
    220
  • trunk/JavaScriptCore/interpreter/RegisterFile.cpp

    r38520 r39673  
    3737    munmap(m_buffer, ((m_max - m_start) + m_maxGlobals) * sizeof(Register));
    3838#elif HAVE(VIRTUALALLOC)
    39     // FIXME: Use VirtualFree.
    40     fastFree(m_buffer);
     39    VirtualFree(m_buffer, 0, MEM_RELEASE);
    4140#else
    4241    #error "Don't know how to release virtual memory on this platform."
  • trunk/JavaScriptCore/interpreter/RegisterFile.h

    r39351 r39673  
    112112        static const size_t defaultCapacity = 524288;
    113113        static const size_t defaultMaxGlobals = 8192;
     114        static const size_t allocationSize = 1 << 14;
     115        static const size_t allocationSizeMask = allocationSize - 1;
    114116
    115117        RegisterFile(size_t capacity = defaultCapacity, size_t maxGlobals = defaultMaxGlobals)
     
    130132            }
    131133#elif HAVE(VIRTUALALLOC)
    132             // FIXME: Use VirtualAlloc, and commit pages as we go.
    133             m_buffer = static_cast<Register*>(fastMalloc(bufferLength));
     134            // Ensure bufferLength is a multiple of allocation size
     135            bufferLength = (bufferLength + allocationSizeMask) & ~allocationSizeMask;
     136            m_buffer = static_cast<Register*>(VirtualAlloc(0, bufferLength, MEM_RESERVE, PAGE_READWRITE));
     137            if (!m_buffer) {
     138                fprintf(stderr, "Could not allocate register file: %d\n", errno);
     139                CRASH();
     140            }
     141            int initialAllocation = (maxGlobals * sizeof(Register) + allocationSizeMask) & ~allocationSizeMask;
     142            void* commitCheck = VirtualAlloc(m_buffer, initialAllocation, MEM_COMMIT, PAGE_READWRITE);
     143            if (commitCheck != m_buffer) {
     144                fprintf(stderr, "Could not allocate register file: %d\n", errno);
     145                CRASH();
     146            }
     147            m_maxCommitted = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_buffer) + initialAllocation);
    134148#else
    135149            #error "Don't know how to reserve virtual memory on this platform."
     
    161175                    return false;
    162176#if !HAVE(MMAP) && HAVE(VIRTUALALLOC)
    163                 // FIXME: Use VirtualAlloc, and commit pages as we go.
     177                if (newEnd > m_maxCommitted) {
     178                    ptrdiff_t additionalAllocation = ((reinterpret_cast<char*>(newEnd)  - reinterpret_cast<char*>(m_maxCommitted)) + allocationSizeMask) & ~allocationSizeMask;
     179                    if (!VirtualAlloc(m_maxCommitted, additionalAllocation, MEM_COMMIT, PAGE_READWRITE)) {
     180                        fprintf(stderr, "Could not allocate register file: %d\n", errno);
     181                        CRASH();
     182                    }
     183                    m_maxCommitted = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_maxCommitted) + additionalAllocation);
     184                }
    164185#endif
    165186                m_end = newEnd;
     
    184205        Register* m_max;
    185206        Register* m_buffer;
     207#if HAVE(VIRTUALALLOC)
     208        Register* m_maxCommitted;
     209#endif
     210
    186211        JSGlobalObject* m_globalObject; // The global object whose vars are currently stored in the register file.
    187212    };
Note: See TracChangeset for help on using the changeset viewer.