Changeset 64782 in webkit
- Timestamp:
- Aug 5, 2010 1:57:33 PM (14 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r64773 r64782 1 2010-08-05 Gavin Barraclough <barraclough@apple.com> 2 3 Reviewed by Sam Weinig. 4 5 Bug 43185 - Switch RegisterFile over to use PageAllocation 6 7 Remove platform-specific memory allocation code. 8 9 * interpreter/RegisterFile.cpp: 10 (JSC::RegisterFile::~RegisterFile): 11 (JSC::RegisterFile::releaseExcessCapacity): 12 * interpreter/RegisterFile.h: 13 (JSC::RegisterFile::RegisterFile): 14 (JSC::RegisterFile::grow): 15 (JSC::RegisterFile::checkAllocatedOkay): 16 * wtf/PageAllocation.cpp: 17 (WTF::PageAllocation::lastError): 18 * wtf/PageAllocation.h: 19 (WTF::PageAllocation::allocate): 20 (WTF::PageAllocation::allocateAt): 21 (WTF::PageAllocation::allocateAligned): 22 (WTF::PageAllocation::pageSize): 23 (WTF::PageAllocation::isPageAligned): 24 (WTF::PageAllocation::isPowerOfTwo): 25 * wtf/PageReservation.h: 26 (WTF::PageReservation::commit): 27 (WTF::PageReservation::decommit): 28 (WTF::PageReservation::reserve): 29 (WTF::PageReservation::reserveAt): 30 1 31 2010-08-05 Michael Saboff <msaboff@apple.com> 2 32 -
trunk/JavaScriptCore/interpreter/RegisterFile.cpp
r58267 r64782 36 36 RegisterFile::~RegisterFile() 37 37 { 38 #if HAVE(MMAP) 39 munmap(m_buffer, ((m_max - m_start) + m_maxGlobals) * sizeof(Register)); 40 #elif HAVE(VIRTUALALLOC) 41 #if OS(WINCE) 42 VirtualFree(m_buffer, DWORD(m_commitEnd) - DWORD(m_buffer), MEM_DECOMMIT); 43 #endif 44 VirtualFree(m_buffer, 0, MEM_RELEASE); 45 #else 46 fastFree(m_buffer); 47 #endif 38 void* base = m_reservation.base(); 39 m_reservation.decommit(base, reinterpret_cast<intptr_t>(m_commitEnd) - reinterpret_cast<intptr_t>(base)); 40 m_reservation.deallocate(); 48 41 } 49 42 50 43 void RegisterFile::releaseExcessCapacity() 51 44 { 52 #if HAVE(MMAP) && HAVE(MADV_FREE) && !HAVE(VIRTUALALLOC) 53 while (madvise(m_start, (m_max - m_start) * sizeof(Register), MADV_FREE) == -1 && errno == EAGAIN) { } 54 #elif HAVE(VIRTUALALLOC) 55 VirtualFree(m_start, (m_max - m_start) * sizeof(Register), MEM_DECOMMIT); 45 m_reservation.decommit(m_start, reinterpret_cast<intptr_t>(m_commitEnd) - reinterpret_cast<intptr_t>(m_start)); 56 46 m_commitEnd = m_start; 57 #endif58 47 m_maxUsed = m_start; 59 48 } -
trunk/JavaScriptCore/interpreter/RegisterFile.h
r59939 r64782 36 36 #include <stdio.h> 37 37 #include <wtf/Noncopyable.h> 38 #include <wtf/PageReservation.h> 38 39 #include <wtf/VMTags.h> 39 40 #if HAVE(MMAP)41 #include <errno.h>42 #include <sys/mman.h>43 #endif44 40 45 41 namespace JSC { … … 110 106 enum { ProgramCodeThisRegister = -CallFrameHeaderSize - 1 }; 111 107 112 static const size_t defaultCapacity = 5 24288;113 static const size_t defaultMaxGlobals = 8 192;114 static const size_t commitSize = 1 << 14;108 static const size_t defaultCapacity = 512 * 1024; 109 static const size_t defaultMaxGlobals = 8 * 1024; 110 static const size_t commitSize = 16 * 1024; 115 111 // Allow 8k of excess registers before we start trying to reap the registerfile 116 112 static const ptrdiff_t maxExcessCapacity = 8 * 1024; … … 140 136 141 137 private: 138 void checkAllocatedOkay(bool okay); 139 142 140 void releaseExcessCapacity(); 143 141 size_t m_numGlobals; … … 146 144 Register* m_end; 147 145 Register* m_max; 148 Register* m_buffer;149 146 Register* m_maxUsed; 150 151 #if HAVE(VIRTUALALLOC)152 147 Register* m_commitEnd; 153 #endif 148 PageReservation m_reservation; 154 149 155 150 WeakGCPtr<JSGlobalObject> m_globalObject; // The global object whose vars are currently stored in the register file. 156 151 }; 157 158 // FIXME: Add a generic getpagesize() to WTF, then move this function to WTF as well.159 inline bool isPageAligned(size_t size) { return size != 0 && size % (8 * 1024) == 0; }160 152 161 153 inline RegisterFile::RegisterFile(size_t capacity, size_t maxGlobals) … … 165 157 , m_end(0) 166 158 , m_max(0) 167 , m_buffer(0) 168 { 169 // Verify that our values will play nice with mmap and VirtualAlloc. 170 ASSERT(isPageAligned(maxGlobals)); 171 ASSERT(isPageAligned(capacity)); 159 { 160 ASSERT(maxGlobals && PageAllocation::isPageAligned(maxGlobals)); 161 ASSERT(capacity && PageAllocation::isPageAligned(capacity)); 172 162 173 163 size_t bufferLength = (capacity + maxGlobals) * sizeof(Register); 174 #if HAVE(MMAP) 175 m_buffer = static_cast<Register*>(mmap(0, bufferLength, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, VM_TAG_FOR_REGISTERFILE_MEMORY, 0)); 176 if (m_buffer == MAP_FAILED) { 177 #if OS(WINCE) 178 fprintf(stderr, "Could not allocate register file: %d\n", GetLastError()); 179 #else 180 fprintf(stderr, "Could not allocate register file: %d\n", errno); 181 #endif 182 CRASH(); 183 } 184 #elif HAVE(VIRTUALALLOC) 185 m_buffer = static_cast<Register*>(VirtualAlloc(0, roundUpAllocationSize(bufferLength, commitSize), MEM_RESERVE, PAGE_READWRITE)); 186 if (!m_buffer) { 187 #if OS(WINCE) 188 fprintf(stderr, "Could not allocate register file: %d\n", GetLastError()); 189 #else 190 fprintf(stderr, "Could not allocate register file: %d\n", errno); 191 #endif 192 CRASH(); 193 } 164 m_reservation = PageReservation::reserve(roundUpAllocationSize(bufferLength, commitSize), PageAllocation::JSVMStackPages); 165 void* base = m_reservation.base(); 166 checkAllocatedOkay(base); 194 167 size_t committedSize = roundUpAllocationSize(maxGlobals * sizeof(Register), commitSize); 195 void* commitCheck = VirtualAlloc(m_buffer, committedSize, MEM_COMMIT, PAGE_READWRITE); 196 if (commitCheck != m_buffer) { 197 #if OS(WINCE) 198 fprintf(stderr, "Could not allocate register file: %d\n", GetLastError()); 199 #else 200 fprintf(stderr, "Could not allocate register file: %d\n", errno); 201 #endif 202 CRASH(); 203 } 204 m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_buffer) + committedSize); 205 #else 206 /* 207 * If neither MMAP nor VIRTUALALLOC are available - use fastMalloc instead. 208 * 209 * Please note that this is the fallback case, which is non-optimal. 210 * If any possible, the platform should provide for a better memory 211 * allocation mechanism that allows for "lazy commit" or dynamic 212 * pre-allocation, similar to mmap or VirtualAlloc, to avoid waste of memory. 213 */ 214 m_buffer = static_cast<Register*>(fastMalloc(bufferLength)); 215 #endif 216 m_start = m_buffer + maxGlobals; 168 checkAllocatedOkay(m_reservation.commit(base, committedSize)); 169 m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(base) + committedSize); 170 m_start = static_cast<Register*>(base) + maxGlobals; 217 171 m_end = m_start; 218 172 m_maxUsed = m_end; … … 237 191 return false; 238 192 239 #if !HAVE(MMAP) && HAVE(VIRTUALALLOC)240 193 if (newEnd > m_commitEnd) { 241 194 size_t size = roundUpAllocationSize(reinterpret_cast<char*>(newEnd) - reinterpret_cast<char*>(m_commitEnd), commitSize); 242 if (!VirtualAlloc(m_commitEnd, size, MEM_COMMIT, PAGE_READWRITE)) { 243 #if OS(WINCE) 244 fprintf(stderr, "Could not allocate register file: %d\n", GetLastError()); 245 #else 246 fprintf(stderr, "Could not allocate register file: %d\n", errno); 247 #endif 248 CRASH(); 249 } 195 checkAllocatedOkay(m_reservation.commit(m_commitEnd, size)); 250 196 m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_commitEnd) + size); 251 197 } 252 #endif253 198 254 199 if (newEnd > m_maxUsed) … … 259 204 } 260 205 206 inline void RegisterFile::checkAllocatedOkay(bool okay) 207 { 208 if (!okay) { 209 #ifndef NDEBUG 210 fprintf(stderr, "Could not allocate register file: %d\n", PageReservation::lastError()); 211 #endif 212 CRASH(); 213 } 214 } 215 261 216 } // namespace JSC 262 217 -
trunk/JavaScriptCore/wtf/PageAllocation.cpp
r64695 r64782 33 33 size_t PageAllocation::s_pageSize = 0; 34 34 35 #ifndef NDEBUG 36 37 int PageAllocation::lastError() 38 { 39 #if OS(WINCE) 40 return GetLastError(); 41 #else 42 return errno; 43 #endif 35 44 } 45 46 #endif 47 48 } -
trunk/JavaScriptCore/wtf/PageAllocation.h
r64695 r64782 109 109 static PageAllocation allocate(size_t size, Usage usage = UnknownUsage, bool writable = true, bool executable = false) 110 110 { 111 // size must be a multiple of pageSize. 112 ASSERT(!(size & (pageSize() - 1))); 111 ASSERT(isPageAligned(size)); 113 112 return systemAllocate(size, usage, writable, executable); 114 113 } … … 117 116 static PageAllocation allocateAt(void* address, bool fixed, size_t size, Usage usage = UnknownUsage, bool writable = true, bool executable = false) 118 117 { 119 // size must be a multiple of pageSize. 120 ASSERT(!(size & (pageSize() - 1))); 121 // address must be aligned to pageSize. 122 ASSERT(!(reinterpret_cast<intptr_t>(address) & (pageSize() - 1))); 118 ASSERT(isPageAligned(address)); 119 ASSERT(isPageAligned(size)); 123 120 return systemAllocateAt(address, fixed, size, usage, writable, executable); 124 121 } … … 128 125 static PageAllocation allocateAligned(size_t size, Usage usage = UnknownUsage) 129 126 { 130 // size must be a multiple of pageSize. 131 ASSERT(!(size & (pageSize() - 1))); 132 // size must be a power of two. 133 ASSERT(!(size & (size - 1))); 127 ASSERT(isPageAligned(size)); 128 ASSERT(isPowerOfTwo(size)); 134 129 return systemAllocateAligned(size, usage); 135 130 } … … 144 139 static size_t pageSize() 145 140 { 146 if (!s_pageSize) {141 if (!s_pageSize) 147 142 s_pageSize = systemPageSize(); 148 // system page size must be a power of two. 149 ASSERT(!(s_pageSize & (s_pageSize - 1))); 150 } 143 ASSERT(isPowerOfTwo(s_pageSize)); 151 144 return s_pageSize; 152 145 } 146 147 #ifndef NDEBUG 148 static bool isPageAligned(void* address) { return !(reinterpret_cast<intptr_t>(address) & (pageSize() - 1)); } 149 static bool isPageAligned(size_t size) { return !(size & (pageSize() - 1)); } 150 static bool isPowerOfTwo(size_t size) { return !(size & (size - 1)); } 151 static int lastError(); 152 #endif 153 153 154 154 protected: -
trunk/JavaScriptCore/wtf/PageReservation.h
r64703 r64782 73 73 { 74 74 ASSERT(m_base); 75 // size must be a multiple of pageSize. 76 ASSERT(!(size & (pageSize() - 1))); 77 // address must be aligned to pageSize. 78 ASSERT(!(reinterpret_cast<intptr_t>(start) & (pageSize() - 1))); 75 ASSERT(isPageAligned(start)); 76 ASSERT(isPageAligned(size)); 79 77 80 78 bool commited = systemCommit(start, size); … … 88 86 { 89 87 ASSERT(m_base); 90 // size must be a multiple of pageSize. 91 ASSERT(!(size & (pageSize() - 1))); 92 // address must be aligned to pageSize. 93 ASSERT(!(reinterpret_cast<intptr_t>(start) & (pageSize() - 1))); 88 ASSERT(isPageAligned(start)); 89 ASSERT(isPageAligned(size)); 94 90 95 91 #ifndef NDEBUG … … 101 97 static PageReservation reserve(size_t size, Usage usage = UnknownUsage, bool writable = true, bool executable = false) 102 98 { 103 // size must be a multiple of pageSize. 104 ASSERT(!(size & (pageSize() - 1))); 99 ASSERT(isPageAligned(size)); 105 100 return systemReserve(size, usage, writable, executable); 106 101 } … … 109 104 static PageReservation reserveAt(void* address, bool fixed, size_t size, Usage usage = UnknownUsage, bool writable = true, bool executable = false) 110 105 { 111 // size must be a multiple of pageSize. 112 ASSERT(!(size & (pageSize() - 1))); 113 // address must be aligned to pageSize. 114 ASSERT(!(reinterpret_cast<intptr_t>(address) & (pageSize() - 1))); 106 ASSERT(isPageAligned(address)); 107 ASSERT(isPageAligned(size)); 115 108 return systemReserveAt(address, fixed, size, usage, writable, executable); 116 109 } … … 123 116 systemDeallocate(false); 124 117 } 118 119 #ifndef NDEBUG 120 using PageAllocation::lastError; 121 #endif 125 122 126 123 private:
Note: See TracChangeset
for help on using the changeset viewer.