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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.