Changeset 21017 in webkit for trunk/JavaScriptCore/kjs/collector.cpp
- Timestamp:
- Apr 22, 2007, 9:01:47 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r21015 r21017 39 39 40 40 #include <mach/mach_port.h> 41 #include <mach/mach_init.h> 41 42 #include <mach/task.h> 42 43 #include <mach/thread_act.h> 44 #include <mach/vm_map.h> 43 45 44 46 #elif PLATFORM(WIN_OS) … … 47 49 48 50 #elif PLATFORM(UNIX) 51 52 #include <stdlib.h> 53 #include <sys/mman.h> 49 54 50 55 #if HAVE(PTHREAD_NP_H) … … 59 64 60 65 namespace KJS { 61 62 66 63 67 … … 68 72 template<> struct CellSize<sizeof(uint64_t)> { static const size_t m_value = 80; }; // 64-bit 69 73 70 const size_t BLOCK_SIZE = ( 8 * 4096);74 const size_t BLOCK_SIZE = (16 * 4096); // 64k 71 75 const size_t SPARE_EMPTY_BLOCKS = 2; 72 76 const size_t MIN_ARRAY_SIZE = 14; … … 76 80 77 81 // derived constants 82 const size_t PTR_IN_BLOCK_MASK = (BLOCK_SIZE - 1); 83 const size_t BLOCK_MASK = (~PTR_IN_BLOCK_MASK); 78 84 const size_t MINIMUM_CELL_SIZE = CellSize<sizeof(void*)>::m_value; 79 85 const size_t CELL_ARRAY_LENGTH = (MINIMUM_CELL_SIZE / sizeof(double)) + (MINIMUM_CELL_SIZE % sizeof(double) != 0 ? 1 : 0); … … 135 141 bool GCLock::isLocked = false; 136 142 #endif 143 144 static CollectorBlock* allocateBlock() 145 { 146 #if PLATFORM(DARWIN) 147 vm_address_t address = 0; 148 vm_map(current_task(), &address, BLOCK_SIZE, PTR_IN_BLOCK_MASK, VM_FLAGS_ANYWHERE, MEMORY_OBJECT_NULL, 0, FALSE, VM_PROT_DEFAULT, VM_PROT_DEFAULT, VM_INHERIT_DEFAULT); 149 #elif PLATFORM(WIN) 150 // windows virtual address granularity is naturally 64k 151 LPVOID address = VirtualAlloc(NULL, BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); 152 #elif HAVE(POSIX_MEMALIGN) 153 void* address; 154 posix_memalign(address, BLOCK_SIZE, BLOCK_SIZE); 155 memset(reinterpret_cast<void*>(address), 0, BLOCK_SIZE); 156 #else 157 static size_t pagesize = getpagesize(); 158 159 size_t extra = 0; 160 if (BLOCK_SIZE > pagesize) 161 extra = BLOCK_SIZE - pagesize; 162 163 void* mmapResult = mmap(NULL, BLOCK_SIZE + extra, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); 164 uintptr_t address = reinterpret_cast<uintptr_t>(mmapResult); 165 166 size_t adjust = 0; 167 if ((address & PTR_IN_BLOCK_MASK) != 0) 168 adjust = BLOCK_SIZE - (address & PTR_IN_BLOCK_MASK); 169 170 if (adjust > 0) 171 munmap(reinterpret_cast<void*>(address), adjust); 172 173 if (adjust < extra) 174 munmap(reinterpret_cast<void*>(address + adjust + BLOCK_SIZE), extra - adjust); 175 176 address += adjust; 177 memset(reinterpret_cast<void*>(address), 0, BLOCK_SIZE); 178 #endif 179 180 return reinterpret_cast<CollectorBlock*>(address); 181 } 182 183 static void freeBlock(CollectorBlock* block) 184 { 185 #if PLATFORM(DARWIN) 186 vm_deallocate(current_task(), reinterpret_cast<vm_address_t>(block), BLOCK_SIZE); 187 #elif PLATFORM(WIN) 188 VirtualFree(block, BLOCK_SIZE, MEM_RELEASE); 189 #elif HAVE(POSIX_MEMALIGN) 190 free(block); 191 #else 192 munmap(block, BLOCK_SIZE); 193 #endif 194 } 137 195 138 196 void* Collector::allocate(size_t s) … … 186 244 } 187 245 188 targetBlock = static_cast<CollectorBlock *>(fastCalloc(1, sizeof(CollectorBlock)));246 targetBlock = allocateBlock(); 189 247 targetBlock->freeList = targetBlock->cells; 190 248 targetBlockUsedCells = 0; … … 800 858 if (emptyBlocks > SPARE_EMPTY_BLOCKS) { 801 859 #if !DEBUG_COLLECTOR 802 f astFree(curBlock);860 freeBlock(curBlock); 803 861 #endif 804 862 // swap with the last block so we compact as we go
Note:
See TracChangeset
for help on using the changeset viewer.