Changeset 20229 in webkit for trunk/JavaScriptCore/wtf/TCSystemAlloc.cpp
- Timestamp:
- Mar 15, 2007, 10:12:59 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/TCSystemAlloc.cpp
r14256 r20229 39 39 #include <sys/types.h> 40 40 #endif 41 #if !PLATFORM(WIN_OS) 41 #if PLATFORM(WIN_OS) 42 #include "windows.h" 43 #else 42 44 #include <unistd.h> 43 45 #include <sys/mman.h> … … 74 76 static bool use_sbrk = false; 75 77 static bool use_mmap = true; 78 static bool use_VirtualAlloc = true; 76 79 77 80 // Flags to keep us from retrying allocators that failed. … … 79 82 static bool sbrk_failure = false; 80 83 static bool mmap_failure = false; 84 static bool VirtualAlloc_failure = false; 81 85 82 86 #ifndef WTF_CHANGES … … 173 177 #endif /* HAVE(MMAP) */ 174 178 179 #if HAVE(VIRTUALALLOC) 180 181 static void* TryVirtualAlloc(size_t size, size_t alignment) { 182 // Enforce page alignment 183 if (pagesize == 0) { 184 SYSTEM_INFO system_info; 185 GetSystemInfo(&system_info); 186 pagesize = system_info.dwPageSize; 187 } 188 if (alignment < pagesize) alignment = pagesize; 189 size = ((size + alignment - 1) / alignment) * alignment; 190 191 // Ask for extra memory if alignment > pagesize 192 size_t extra = 0; 193 if (alignment > pagesize) { 194 extra = alignment - pagesize; 195 } 196 void* result = VirtualAlloc(NULL, size + extra, 197 MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, 198 PAGE_READWRITE); 199 200 if (result == NULL) { 201 VirtualAlloc_failure = true; 202 return NULL; 203 } 204 205 // Adjust the return memory so it is aligned 206 uintptr_t ptr = reinterpret_cast<uintptr_t>(result); 207 size_t adjust = 0; 208 if ((ptr & (alignment - 1)) != 0) { 209 adjust = alignment - (ptr & (alignment - 1)); 210 } 211 212 // Return the unused memory to the system - we'd like to release but the best we can do 213 // is decommit, since Windows only lets you free the whole allocation. 214 if (adjust > 0) { 215 VirtualFree(reinterpret_cast<void*>(ptr), adjust, MEM_DECOMMIT); 216 } 217 if (adjust < extra) { 218 VirtualFree(reinterpret_cast<void*>(ptr + adjust + size), extra-adjust, MEM_DECOMMIT); 219 } 220 221 ptr += adjust; 222 return reinterpret_cast<void*>(ptr); 223 } 224 225 #endif /* HAVE(MMAP) */ 226 175 227 #ifndef WTF_CHANGES 176 228 static void* TryDevMem(size_t size, size_t alignment) { … … 283 335 #endif 284 336 337 #if HAVE(VIRTUALALLOC) 338 if (use_VirtualAlloc && !VirtualAlloc_failure) { 339 void* result = TryVirtualAlloc(size, alignment); 340 if (result != NULL) return result; 341 } 342 #endif 343 285 344 // nothing worked - reset failure flags and try again 286 345 devmem_failure = false; 287 346 sbrk_failure = false; 288 347 mmap_failure = false; 348 VirtualAlloc_failure = false; 289 349 } 290 350 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.