Changeset 64782 in webkit for trunk/JavaScriptCore/interpreter
- Timestamp:
- Aug 5, 2010, 1:57:33 PM (15 years ago)
- Location:
- trunk/JavaScriptCore/interpreter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.