Changeset 46511 in webkit for trunk/JavaScriptCore/wtf/TCSystemAlloc.cpp
- Timestamp:
- Jul 28, 2009, 6:09:02 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/TCSystemAlloc.cpp
r43988 r46511 32 32 33 33 #include "config.h" 34 #include "TCSystemAlloc.h" 35 36 #include <algorithm> 37 #include <fcntl.h> 38 #include "Assertions.h" 39 #include "TCSpinLock.h" 40 #include "UnusedParam.h" 41 34 42 #if HAVE(STDINT_H) 35 43 #include <stdint.h> … … 39 47 #include <sys/types.h> 40 48 #endif 49 41 50 #if PLATFORM(WIN_OS) 42 51 #include "windows.h" … … 46 55 #include <sys/mman.h> 47 56 #endif 48 #include <fcntl.h>49 #include "Assertions.h"50 #include "TCSystemAlloc.h"51 #include "TCSpinLock.h"52 #include "UnusedParam.h"53 57 54 58 #ifndef MAP_ANONYMOUS 55 59 #define MAP_ANONYMOUS MAP_ANON 56 60 #endif 61 62 using namespace std; 57 63 58 64 // Structure for discovering alignment … … 442 448 } 443 449 450 #elif HAVE(VIRTUALALLOC) 451 452 void TCMalloc_SystemRelease(void* start, size_t length) 453 { 454 if (VirtualFree(start, length, MEM_DECOMMIT)) 455 return; 456 457 // The decommit may fail if the memory region consists of allocations 458 // from more than one call to VirtualAlloc. In this case, fall back to 459 // using VirtualQuery to retrieve the allocation boundaries and decommit 460 // them each individually. 461 462 char* ptr = static_cast<char*>(start); 463 char* end = ptr + length; 464 MEMORY_BASIC_INFORMATION info; 465 while (ptr < end) { 466 size_t resultSize = VirtualQuery(ptr, &info, sizeof(info)); 467 ASSERT_UNUSED(resultSize, resultSize == sizeof(info)); 468 469 size_t decommitSize = min<size_t>(info.RegionSize, end - ptr); 470 BOOL success = VirtualFree(ptr, decommitSize, MEM_DECOMMIT); 471 ASSERT_UNUSED(success, success); 472 ptr += decommitSize; 473 } 474 } 475 444 476 #else 445 477 … … 458 490 #elif HAVE(VIRTUALALLOC) 459 491 460 void TCMalloc_SystemCommit(void* , size_t)492 void TCMalloc_SystemCommit(void* start, size_t length) 461 493 { 494 if (VirtualAlloc(start, length, MEM_COMMIT, PAGE_READWRITE) == start) 495 return; 496 497 // The commit may fail if the memory region consists of allocations 498 // from more than one call to VirtualAlloc. In this case, fall back to 499 // using VirtualQuery to retrieve the allocation boundaries and commit them 500 // each individually. 501 502 char* ptr = static_cast<char*>(start); 503 char* end = ptr + length; 504 MEMORY_BASIC_INFORMATION info; 505 while (ptr < end) { 506 size_t resultSize = VirtualQuery(ptr, &info, sizeof(info)); 507 ASSERT_UNUSED(resultSize, resultSize == sizeof(info)); 508 509 size_t commitSize = min<size_t>(info.RegionSize, end - ptr); 510 void* newAddress = VirtualAlloc(ptr, commitSize, MEM_COMMIT, PAGE_READWRITE); 511 ASSERT_UNUSED(newAddress, newAddress == ptr); 512 ptr += commitSize; 513 } 462 514 } 463 515
Note:
See TracChangeset
for help on using the changeset viewer.