Changeset 20229 in webkit for trunk/JavaScriptCore/wtf
- Timestamp:
- Mar 15, 2007, 10:12:59 PM (18 years ago)
- Location:
- trunk/JavaScriptCore/wtf
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/FastMalloc.cpp
r20026 r20229 190 190 #include <stdio.h> 191 191 #include <string.h> 192 #include <unistd.h>193 192 194 193 #if WTF_CHANGES … … 329 328 #endif 330 329 331 static inline int SizeClass(size_t size) {330 static inline size_t SizeClass(size_t size) { 332 331 if (size == 0) size = 1; 333 332 const int lg = LgFloor(size); 334 333 const int align = size_shift[lg]; 335 return s tatic_cast<int>(size_base[lg])+ ((size-1) >> align);334 return size_base[lg] + ((size-1) >> align); 336 335 } 337 336 … … 350 349 351 350 size_t next_class = 1; 352 intalignshift = kAlignShift;351 unsigned char alignshift = kAlignShift; 353 352 int last_lg = -1; 354 353 for (size_t size = kAlignment; size <= kMaxSize; size += (1 << alignshift)) { … … 365 364 alignshift++; 366 365 } 367 size_base[lg] = next_class - ((size-1) >> alignshift);366 size_base[lg] = static_cast<unsigned char>(next_class - ((size-1) >> alignshift)); 368 367 size_shift[lg] = alignshift; 369 368 } … … 819 818 Event(span, 'T', n); 820 819 821 const intextra = span->length - n;820 const Length extra = span->length - n; 822 821 Span* leftover = NewSpan(span->start + n, extra); 823 822 Event(leftover, 'U', extra); … … 909 908 ASSERT(GetDescriptor(span->start+span->length-1) == span); 910 909 Event(span, 'C', sc); 911 span->sizeclass = s c;910 span->sizeclass = static_cast<unsigned int>(sc); 912 911 for (Length i = 1; i < span->length-1; i++) { 913 912 pagemap_.set(span->start+i, span); … … 1142 1141 // REQUIRES: lock_ is held 1143 1142 // Number of free objects in cache 1144 int length() const { return counter_; }1143 size_t length() const { return counter_; } 1145 1144 1146 1145 // Lock -- exposed because caller grabs it before touching this object … … 1565 1564 #endif 1566 1565 for (TCMalloc_ThreadCache* h = thread_heaps; h != NULL; h = h->next_) { 1567 if ( h->tid_ == zero) {1566 if (pthread_equal(h->tid_, zero)) { 1568 1567 h->tid_ = pthread_self(); 1569 1568 } … … 1589 1588 // and added to the linked list. So we search for that first. 1590 1589 for (TCMalloc_ThreadCache* h = thread_heaps; h != NULL; h = h->next_) { 1591 if ( h->tid_ == me) {1590 if (pthread_equal(h->tid_, me)) { 1592 1591 heap = h; 1593 1592 break; -
trunk/JavaScriptCore/wtf/TCSpinLock.h
r19245 r20229 35 35 36 36 #include "config.h" 37 38 #if (PLATFORM(X86) || PLATFORM(PPC)) && COMPILER(GCC) 39 37 40 #include <time.h> /* For nanosleep() */ 41 38 42 #include <sched.h> /* For sched_yield() */ 43 39 44 #if HAVE(STDINT_H) 40 45 #include <stdint.h> … … 46 51 #include <stdlib.h> /* for abort() */ 47 52 48 #if (PLATFORM(X86) || PLATFORM(PPC)) && COMPILER(GCC)49 53 static void TCMalloc_SlowLock(volatile unsigned int* lockword); 50 54 -
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.