Changeset 28135 in webkit for trunk/JavaScriptCore/wtf
- Timestamp:
- Nov 29, 2007, 12:46:14 AM (17 years ago)
- Location:
- trunk/JavaScriptCore/wtf
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/FastMalloc.cpp
r27711 r28135 498 498 static uint64_t metadata_system_bytes = 0; 499 499 static void* MetaDataAlloc(size_t bytes) { 500 void* result = TCMalloc_SystemAlloc(bytes );500 void* result = TCMalloc_SystemAlloc(bytes, 0); 501 501 if (result != NULL) { 502 502 metadata_system_bytes += bytes; … … 1040 1040 ASSERT(kMaxPages >= kMinSystemAlloc); 1041 1041 Length ask = (n>kMinSystemAlloc) ? n : static_cast<Length>(kMinSystemAlloc); 1042 void* ptr = TCMalloc_SystemAlloc(ask << kPageShift, kPageSize);1042 void* ptr = TCMalloc_SystemAlloc(ask << kPageShift, 0, kPageSize); 1043 1043 if (ptr == NULL) { 1044 1044 if (n < ask) { 1045 1045 // Try growing just "n" pages 1046 1046 ask = n; 1047 ptr = TCMalloc_SystemAlloc(ask << kPageShift, kPageSize);1047 ptr = TCMalloc_SystemAlloc(ask << kPageShift, 0, kPageSize); 1048 1048 } 1049 1049 if (ptr == NULL) return false; … … 1362 1362 1363 1363 void TCMalloc_Central_FreeList::Init(size_t cl) { 1364 lock_.Init();1365 1364 size_class_ = cl; 1366 1365 DLL_Init(&empty_); -
trunk/JavaScriptCore/wtf/TCSpinLock.h
r27709 r28135 1 // Copyright (c) 2005, Google Inc.1 // Copyright (c) 2005, 2006, Google Inc. 2 2 // All rights reserved. 3 3 // … … 58 58 // The following is a struct so that it can be initialized at compile time 59 59 struct TCMalloc_SpinLock { 60 volatile unsigned int private_lockword_; 61 62 inline void Init() { private_lockword_ = 0; } 63 inline void Finalize() { } 64 60 65 61 inline void Lock() { 66 62 int r; … … 69 65 __asm__ __volatile__ 70 66 ("xchgl %0, %1" 71 : "=r"(r), "=m"( private_lockword_)72 : "0"(1), "m"( private_lockword_)73 : "memory"); 74 #else 75 volatile unsigned int *lockword_ptr = & private_lockword_;67 : "=r"(r), "=m"(lockword_) 68 : "0"(1), "m"(lockword_) 69 : "memory"); 70 #else 71 volatile unsigned int *lockword_ptr = &lockword_; 76 72 __asm__ __volatile__ 77 73 ("1: lwarx %0, 0, %1\n\t" … … 85 81 #elif COMPILER(MSVC) 86 82 __asm { 87 mov eax, this ; store & private_lockword_ (which is this+0) in eax83 mov eax, this ; store &lockword_ (which is this+0) in eax 88 84 mov ebx, 1 ; store 1 in ebx 89 xchg [eax], ebx ; exchange private_lockword_ and 190 mov r, ebx ; store old value of private_lockword_ in r91 } 92 #endif 93 if (r) TCMalloc_SlowLock(& private_lockword_);85 xchg [eax], ebx ; exchange lockword_ and 1 86 mov r, ebx ; store old value of lockword_ in r 87 } 88 #endif 89 if (r) TCMalloc_SlowLock(&lockword_); 94 90 } 95 91 … … 99 95 __asm__ __volatile__ 100 96 ("movl $0, %0" 101 : "=m"( private_lockword_)102 : "m" ( private_lockword_)97 : "=m"(lockword_) 98 : "m" (lockword_) 103 99 : "memory"); 104 100 #else … … 107 103 "eieio\n\t" 108 104 "stw %1, %0" 109 : "=o" ( private_lockword_)105 : "=o" (lockword_) 110 106 : "r" (0) 111 107 : "memory"); … … 113 109 #elif COMPILER(MSVC) 114 110 __asm { 115 mov eax, this ; store & private_lockword_ (which is this+0) in eax116 mov [eax], 0 ; set private_lockword_ to 0111 mov eax, this ; store &lockword_ (which is this+0) in eax 112 mov [eax], 0 ; set lockword_ to 0 117 113 } 118 114 #endif 119 115 } 120 121 #ifdef WTF_CHANGES 122 inline bool IsLocked() { 123 return private_lockword_ != 0; 124 } 125 #endif 116 // Report if we think the lock can be held by this thread. 117 // When the lock is truly held by the invoking thread 118 // we will always return true. 119 // Indended to be used as CHECK(lock.IsHeld()); 120 inline bool IsHeld() const { 121 return lockword_ != 0; 122 } 123 124 volatile unsigned int lockword_; 126 125 }; 127 126 -
trunk/JavaScriptCore/wtf/TCSystemAlloc.cpp
r27336 r28135 100 100 #if HAVE(SBRK) 101 101 102 static void* TrySbrk(size_t size, size_t alignment) {102 static void* TrySbrk(size_t size, size_t *actual_size, size_t alignment) { 103 103 size = ((size + alignment - 1) / alignment) * alignment; 104 105 // could theoretically return the "extra" bytes here, but this 106 // is simple and correct. 107 if (actual_size) 108 *actual_size = size; 109 104 110 void* result = sbrk(size); 105 111 if (result == reinterpret_cast<void*>(-1)) { … … 138 144 #if HAVE(MMAP) 139 145 140 static void* TryMmap(size_t size, size_t alignment) {146 static void* TryMmap(size_t size, size_t *actual_size, size_t alignment) { 141 147 // Enforce page alignment 142 148 if (pagesize == 0) pagesize = getpagesize(); 143 149 if (alignment < pagesize) alignment = pagesize; 144 150 size = ((size + alignment - 1) / alignment) * alignment; 145 151 152 // could theoretically return the "extra" bytes here, but this 153 // is simple and correct. 154 if (actual_size) 155 *actual_size = size; 156 146 157 // Ask for extra memory if alignment > pagesize 147 158 size_t extra = 0; … … 181 192 #if HAVE(VIRTUALALLOC) 182 193 183 static void* TryVirtualAlloc(size_t size, size_t alignment) {194 static void* TryVirtualAlloc(size_t size, size_t *actual_size, size_t alignment) { 184 195 // Enforce page alignment 185 196 if (pagesize == 0) { … … 188 199 pagesize = system_info.dwPageSize; 189 200 } 201 190 202 if (alignment < pagesize) alignment = pagesize; 191 203 size = ((size + alignment - 1) / alignment) * alignment; 192 204 205 // could theoretically return the "extra" bytes here, but this 206 // is simple and correct. 207 if (actual_size) 208 *actual_size = size; 209 193 210 // Ask for extra memory if alignment > pagesize 194 211 size_t extra = 0; … … 228 245 229 246 #ifndef WTF_CHANGES 230 static void* TryDevMem(size_t size, size_t alignment) {247 static void* TryDevMem(size_t size, size_t *actual_size, size_t alignment) { 231 248 static bool initialized = false; 232 249 static off_t physmem_base; // next physical memory address to allocate … … 259 276 if (alignment < pagesize) alignment = pagesize; 260 277 size = ((size + alignment - 1) / alignment) * alignment; 261 278 279 // could theoretically return the "extra" bytes here, but this 280 // is simple and correct. 281 if (actual_size) 282 *actual_size = size; 283 262 284 // Ask for extra memory if alignment > pagesize 263 285 size_t extra = 0; … … 300 322 #endif 301 323 302 void* TCMalloc_SystemAlloc(size_t size, size_t alignment) { 303 #ifndef WTF_CHANGES 304 if (TCMallocDebug::level >= TCMallocDebug::kVerbose) { 305 MESSAGE("TCMalloc_SystemAlloc(%" PRIuS ", %" PRIuS")\n", 306 size, alignment); 307 } 308 #endif 324 void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size, size_t alignment) { 325 // Discard requests that overflow 326 if (size + alignment < size) return NULL; 327 309 328 SpinLockHolder lock_holder(&spinlock); 310 329 … … 318 337 #ifndef WTF_CHANGES 319 338 if (use_devmem && !devmem_failure) { 320 void* result = TryDevMem(size, a lignment);339 void* result = TryDevMem(size, actual_size, alignment); 321 340 if (result != NULL) return result; 322 341 } … … 325 344 #if HAVE(SBRK) 326 345 if (use_sbrk && !sbrk_failure) { 327 void* result = TrySbrk(size, a lignment);346 void* result = TrySbrk(size, actual_size, alignment); 328 347 if (result != NULL) return result; 329 348 } … … 332 351 #if HAVE(MMAP) 333 352 if (use_mmap && !mmap_failure) { 334 void* result = TryMmap(size, a lignment);353 void* result = TryMmap(size, actual_size, alignment); 335 354 if (result != NULL) return result; 336 355 } … … 339 358 #if HAVE(VIRTUALALLOC) 340 359 if (use_VirtualAlloc && !VirtualAlloc_failure) { 341 void* result = TryVirtualAlloc(size, a lignment);360 void* result = TryVirtualAlloc(size, actual_size, alignment); 342 361 if (result != NULL) return result; 343 362 } -
trunk/JavaScriptCore/wtf/TCSystemAlloc.h
r11962 r28135 39 39 // REQUIRES: "alignment" is a power of two or "0" to indicate default alignment 40 40 // 41 // Allocate and return "N" bytes of zeroed memory. The returned 42 // pointer is a multiple of "alignment" if non-zero. Returns NULL 43 // when out of memory. 44 extern void* TCMalloc_SystemAlloc(size_t bytes, size_t alignment = 0); 41 // Allocate and return "N" bytes of zeroed memory. 42 // 43 // If actual_bytes is NULL then the returned memory is exactly the 44 // requested size. If actual bytes is non-NULL then the allocator 45 // may optionally return more bytes than asked for (i.e. return an 46 // entire "huge" page if a huge page allocator is in use). 47 // 48 // The returned pointer is a multiple of "alignment" if non-zero. 49 // 50 // Returns NULL when out of memory. 51 extern void* TCMalloc_SystemAlloc(size_t bytes, size_t *actual_bytes, 52 size_t alignment = 0); 53 54 // This call is a hint to the operating system that the pages 55 // contained in the specified range of memory will not be used for a 56 // while, and can be released for use by other processes or the OS. 57 // Pages which are released in this way may be destroyed (zeroed) by 58 // the OS. The benefit of this function is that it frees memory for 59 // use by the system, the cost is that the pages are faulted back into 60 // the address space next time they are touched, which can impact 61 // performance. (Only pages fully covered by the memory region will 62 // be released, partial pages will not.) 63 extern void TCMalloc_SystemRelease(void* start, size_t length); 45 64 46 65 #endif /* TCMALLOC_SYSTEM_ALLOC_H__ */
Note:
See TracChangeset
for help on using the changeset viewer.