Changeset 39450 in webkit for trunk/JavaScriptCore/jit/ExecutableAllocator.h
- Timestamp:
- Dec 22, 2008, 11:08:59 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/jit/ExecutableAllocator.h
r39083 r39450 36 36 #include <limits> 37 37 38 #define JIT_ALLOCATOR_PAGE_ MASK (ExecutableAllocator::pageSize - 1)38 #define JIT_ALLOCATOR_PAGE_SIZE (ExecutableAllocator::pageSize) 39 39 #define JIT_ALLOCATOR_LARGE_ALLOC_SIZE (ExecutableAllocator::pageSize * 4) 40 40 … … 57 57 void* alloc(size_t n) 58 58 { 59 if (n < static_cast<size_t>(m_end - m_freePtr)) { 60 char* result = m_freePtr; 61 // ensure m_freePtr is word aligned. 62 m_freePtr += n + (sizeof(void*) - n & (sizeof(void*) - 1)); 59 ASSERT(m_freePtr <= m_end); 60 61 // Round 'n' up to a multiple of word size; if all allocations are of 62 // word sized quantities, then all subsequent allocations will be aligned. 63 n = roundUpAllocationSize(n, sizeof(void*)); 64 65 if (static_cast<ptrdiff_t>(n) < (m_end - m_freePtr)) { 66 void* result = m_freePtr; 67 m_freePtr += n; 63 68 return result; 64 69 } … … 82 87 static void systemRelease(const Allocation& alloc); 83 88 84 ExecutablePool(size_t n)89 inline size_t roundUpAllocationSize(size_t request, size_t granularity) 85 90 { 86 size_t allocSize = sizeForAllocation(n); 87 Allocation mem = systemAlloc(allocSize); 88 m_pools.append(mem); 89 m_freePtr = mem.pages; 90 if (!m_freePtr) 91 CRASH(); // Failed to allocate 92 m_end = m_freePtr + allocSize; 91 if ((std::numeric_limits<size_t>::max() - granularity) <= request) 92 CRASH(); // Allocation is too large 93 94 // Round up to next page boundary 95 size_t size = request + (granularity - 1); 96 size = size & ~(granularity - 1); 97 ASSERT(size >= request); 98 return size; 93 99 } 94 100 95 static inline size_t sizeForAllocation(size_t request);101 ExecutablePool(size_t n); 96 102 97 void* poolAllocate(size_t n) 98 { 99 size_t allocSize = sizeForAllocation(n); 100 101 Allocation result = systemAlloc(allocSize); 102 if (!result.pages) 103 CRASH(); // Failed to allocate 104 105 ASSERT(m_end >= m_freePtr); 106 if ((allocSize - n) > static_cast<size_t>(m_end - m_freePtr)) { 107 // Replace allocation pool 108 m_freePtr = result.pages + n; 109 m_end = result.pages + allocSize; 110 } 111 112 m_pools.append(result); 113 return result.pages; 114 } 103 void* poolAllocate(size_t n); 115 104 116 105 char* m_freePtr; … … 154 143 }; 155 144 156 inline size_t ExecutablePool::sizeForAllocation(size_t request)145 inline ExecutablePool::ExecutablePool(size_t n) 157 146 { 158 if ((std::numeric_limits<size_t>::max() - ExecutableAllocator::pageSize) <= request) 159 CRASH(); // Allocation is too large 147 size_t allocSize = roundUpAllocationSize(n, JIT_ALLOCATOR_PAGE_SIZE); 148 Allocation mem = systemAlloc(allocSize); 149 m_pools.append(mem); 150 m_freePtr = mem.pages; 151 if (!m_freePtr) 152 CRASH(); // Failed to allocate 153 m_end = m_freePtr + allocSize; 154 } 155 156 inline void* ExecutablePool::poolAllocate(size_t n) 157 { 158 size_t allocSize = roundUpAllocationSize(n, JIT_ALLOCATOR_PAGE_SIZE); 160 159 161 // Round up to next page boundary 162 size_t size = request + JIT_ALLOCATOR_PAGE_MASK; 163 size = size & ~JIT_ALLOCATOR_PAGE_MASK; 164 ASSERT(size >= request); 165 return size; 160 Allocation result = systemAlloc(allocSize); 161 if (!result.pages) 162 CRASH(); // Failed to allocate 163 164 ASSERT(m_end >= m_freePtr); 165 if ((allocSize - n) > static_cast<size_t>(m_end - m_freePtr)) { 166 // Replace allocation pool 167 m_freePtr = result.pages + n; 168 m_end = result.pages + allocSize; 169 } 170 171 m_pools.append(result); 172 return result.pages; 166 173 } 167 174
Note:
See TracChangeset
for help on using the changeset viewer.