Changeset 35691 in webkit
- Timestamp:
- Aug 12, 2008, 1:54:12 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r35665 r35691 1 2008-08-12 Dan Bernstein <mitz@apple.com> 2 3 - JavaScriptCore part of <rdar://problem/6121636> 4 Make fast*alloc() abort() on failure and add "try" variants that 5 return NULL on failure. 6 7 Reviewed by Darin Adler. 8 9 * JavaScriptCore.exp: Exported tryFastCalloc(). 10 * VM/RegisterFile.h: 11 (KJS::RegisterFile::RegisterFile): Removed an ASSERT(). 12 * kjs/JSArray.cpp: 13 (KJS::JSArray::putSlowCase): Changed to use tryFastRealloc(). 14 (KJS::JSArray::increaseVectorLength): Ditto. 15 * kjs/ustring.cpp: 16 (KJS::allocChars): Changed to use tryFastMalloc(). 17 (KJS::reallocChars): Changed to use tryFastRealloc(). 18 * wtf/FastMalloc.cpp: 19 (WTF::fastZeroedMalloc): Removed null checking of fastMalloc()'s result 20 and removed extra call to InvokeNewHook(). 21 (WTF::tryFastZeroedMalloc): Added. Uses tryFastMalloc(). 22 (WTF::tryFastMalloc): Renamed fastMalloc() to this. 23 (WTF::fastMalloc): Added. This version abort()s if allocation fails. 24 (WTF::tryFastCalloc): Renamed fastCalloc() to this. 25 (WTF::fastCalloc): Added. This version abort()s if allocation fails. 26 (WTF::tryFastRealloc): Renamed fastRealloc() to this. 27 (WTF::fastRealloc): Added. This version abort()s if allocation fails. 28 (WTF::do_malloc): Made this a function template. When the abortOnFailure 29 template parameter is set, the function abort()s on failure to allocate. 30 Otherwise, it sets errno to ENOMEM and returns zero. 31 (WTF::TCMallocStats::fastMalloc): Defined to abort() on failure. 32 (WTF::TCMallocStats::tryFastMalloc): Added. Does not abort() on 33 failure. 34 (WTF::TCMallocStats::fastCalloc): Defined to abort() on failure. 35 (WTF::TCMallocStats::tryFastCalloc): Added. Does not abort() on 36 failure. 37 (WTF::TCMallocStats::fastRealloc): Defined to abort() on failure. 38 (WTF::TCMallocStats::tryFastRealloc): Added. Does not abort() on 39 failure. 40 * wtf/FastMalloc.h: Declared the "try" variants. 41 1 42 2008-08-11 Adam Roben <aroben@apple.com> 2 43 -
trunk/JavaScriptCore/JavaScriptCore.exp
r35652 r35691 216 216 __ZN3KJS8JSObject3putEPNS_9ExecStateEjPNS_7JSValueE 217 217 __ZN3KJS8JSObject4markEv 218 __ZN3KJS8Profiler21didFinishAllExecutionEPNS_9ExecStateE219 218 __ZN3KJS8Profiler13stopProfilingEPNS_9ExecStateERKNS_7UStringE 220 219 __ZN3KJS8Profiler14startProfilingEPNS_9ExecStateERKNS_7UStringEPNS_14ProfilerClientE 220 __ZN3KJS8Profiler21didFinishAllExecutionEPNS_9ExecStateE 221 221 __ZN3KJS8Profiler8profilerEv 222 222 __ZN3KJS8jsStringEPNS_9ExecStateEPKc … … 234 234 __ZN3WTF12isMainThreadEv 235 235 __ZN3WTF13currentThreadEv 236 __ZN3WTF13tryFastCallocEmm 236 237 __ZN3WTF15ThreadCondition4waitERNS_5MutexE 237 238 __ZN3WTF15ThreadCondition6signalEv -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r35665 r35691 1619 1619 projectDirPath = ""; 1620 1620 projectRoot = ""; 1621 projectRoots = ( 1622 "", 1623 ); 1621 1624 targets = ( 1622 1625 932F5BE30822A1C700736975 /* All */, -
trunk/JavaScriptCore/VM/RegisterFile.h
r34974 r35691 125 125 // FIXME: Use VirtualAlloc, and commit pages as we go. 126 126 m_buffer = static_cast<Register*>(fastMalloc(bufferLength)); 127 ASSERT(m_buffer);128 127 #else 129 128 #error "Don't know how to reserve virtual memory on this platform." -
trunk/JavaScriptCore/kjs/JSArray.cpp
r35291 r35691 330 330 } 331 331 332 storage = static_cast<ArrayStorage*>( fastRealloc(storage, storageSize(newVectorLength)));332 storage = static_cast<ArrayStorage*>(tryFastRealloc(storage, storageSize(newVectorLength))); 333 333 if (!storage) { 334 334 throwOutOfMemoryError(exec); … … 446 446 unsigned newVectorLength = increasedVectorLength(newLength); 447 447 448 storage = static_cast<ArrayStorage*>( fastRealloc(storage, storageSize(newVectorLength)));448 storage = static_cast<ArrayStorage*>(tryFastRealloc(storage, storageSize(newVectorLength))); 449 449 if (!storage) 450 450 return false; -
trunk/JavaScriptCore/kjs/ustring.cpp
r35458 r35691 65 65 if (length > maxUChars()) 66 66 return 0; 67 return static_cast<UChar*>( fastMalloc(sizeof(UChar) * length));67 return static_cast<UChar*>(tryFastMalloc(sizeof(UChar) * length)); 68 68 } 69 69 … … 73 73 if (length > maxUChars()) 74 74 return 0; 75 return static_cast<UChar*>( fastRealloc(buffer, sizeof(UChar) * length));75 return static_cast<UChar*>(tryFastRealloc(buffer, sizeof(UChar) * length)); 76 76 } 77 77 -
trunk/JavaScriptCore/wtf/FastMalloc.cpp
r35484 r35691 151 151 152 152 namespace WTF { 153 void *fastZeroedMalloc(size_t n) 153 154 void* fastZeroedMalloc(size_t n) 154 155 { 155 void *result = fastMalloc(n); 156 void* result = fastMalloc(n); 157 memset(result, 0, n); 158 return result; 159 } 160 161 void* tryFastZeroedMalloc(size_t n) 162 { 163 void* result = tryFastMalloc(n); 156 164 if (!result) 157 165 return 0; 158 166 memset(result, 0, n); 159 #ifndef WTF_CHANGES160 MallocHook::InvokeNewHook(result, n);161 #endif162 167 return result; 163 168 } 164 165 } 169 170 } // namespace WTF 166 171 167 172 #if FORCE_SYSTEM_MALLOC … … 174 179 namespace WTF { 175 180 176 void *fastMalloc(size_t n)181 void* tryFastMalloc(size_t n) 177 182 { 178 183 ASSERT(!isForbidden()); … … 180 185 } 181 186 182 void *fastCalloc(size_t n_elements, size_t element_size) 187 void* fastMalloc(size_t n) 188 { 189 ASSERT(!isForbidden()); 190 void* result = malloc(n); 191 if (!result) 192 abort(); 193 return result; 194 } 195 196 void* tryFastCalloc(size_t n_elements, size_t element_size) 183 197 { 184 198 ASSERT(!isForbidden()); 185 199 return calloc(n_elements, element_size); 200 } 201 202 void* fastCalloc(size_t n_elements, size_t element_size) 203 { 204 ASSERT(!isForbidden()); 205 void* result = calloc(n_elements, element_size); 206 if (!result) 207 abort(); 208 return result; 186 209 } 187 210 … … 192 215 } 193 216 194 void *fastRealloc(void* p, size_t n)217 void* tryFastRealloc(void* p, size_t n) 195 218 { 196 219 ASSERT(!isForbidden()); 197 220 return realloc(p, n); 221 } 222 223 void* fastRealloc(void* p, size_t n) 224 { 225 ASSERT(!isForbidden()); 226 void* result = realloc(p, n); 227 if (!result) 228 abort(); 229 return result; 198 230 } 199 231 … … 2962 2994 } 2963 2995 2996 #ifdef WTF_CHANGES 2997 template <bool abortOnFailure> 2998 #endif 2964 2999 static ALWAYS_INLINE void* do_malloc(size_t size) { 2965 3000 void* ret = NULL; … … 2991 3026 ret = CheckedMallocResult(heap->Allocate(size)); 2992 3027 } 2993 if (ret == NULL) errno = ENOMEM; 3028 if (!ret) { 3029 #ifdef WTF_CHANGES 3030 if (abortOnFailure) // This branch should be optimized out by the compiler. 3031 abort(); 3032 #else 3033 errno = ENOMEM; 3034 #endif 3035 } 2994 3036 return ret; 2995 3037 } … … 3155 3197 #ifndef WTF_CHANGES 3156 3198 extern "C" 3199 #else 3200 #define do_malloc do_malloc<abortOnFailure> 3201 3202 template <bool abortOnFailure> 3203 void* malloc(size_t); 3204 3205 void* fastMalloc(size_t size) 3206 { 3207 return malloc<true>(size); 3208 } 3209 3210 void* tryFastMalloc(size_t size) 3211 { 3212 return malloc<false>(size); 3213 } 3214 3215 template <bool abortOnFailure> 3216 ALWAYS_INLINE 3157 3217 #endif 3158 3218 void* malloc(size_t size) { … … 3176 3236 #ifndef WTF_CHANGES 3177 3237 extern "C" 3238 #else 3239 template <bool abortOnFailure> 3240 void* calloc(size_t, size_t); 3241 3242 void* fastCalloc(size_t n, size_t elem_size) 3243 { 3244 return calloc<true>(n, elem_size); 3245 } 3246 3247 void* tryFastCalloc(size_t n, size_t elem_size) 3248 { 3249 return calloc<false>(n, elem_size); 3250 } 3251 3252 template <bool abortOnFailure> 3253 ALWAYS_INLINE 3178 3254 #endif 3179 3255 void* calloc(size_t n, size_t elem_size) { … … 3206 3282 #ifndef WTF_CHANGES 3207 3283 extern "C" 3284 #else 3285 template <bool abortOnFailure> 3286 void* realloc(void*, size_t); 3287 3288 void* fastRealloc(void* old_ptr, size_t new_size) 3289 { 3290 return realloc<true>(old_ptr, new_size); 3291 } 3292 3293 void* tryFastRealloc(void* old_ptr, size_t new_size) 3294 { 3295 return realloc<false>(old_ptr, new_size); 3296 } 3297 3298 template <bool abortOnFailure> 3299 ALWAYS_INLINE 3208 3300 #endif 3209 3301 void* realloc(void* old_ptr, size_t new_size) { … … 3265 3357 } 3266 3358 3267 #ifndef WTF_CHANGES 3359 #ifdef WTF_CHANGES 3360 #undef do_malloc 3361 #else 3268 3362 3269 3363 static SpinLock set_new_handler_lock = SPINLOCK_INITIALIZER; -
trunk/JavaScriptCore/wtf/FastMalloc.h
r35055 r35691 28 28 namespace WTF { 29 29 30 void *fastMalloc(size_t n); 31 void *fastZeroedMalloc(size_t n); 32 void *fastCalloc(size_t n_elements, size_t element_size); 30 // These functions call abort() if an allocation fails. 31 void* fastMalloc(size_t n); 32 void* fastZeroedMalloc(size_t n); 33 void* fastCalloc(size_t n_elements, size_t element_size); 34 void* fastRealloc(void* p, size_t n); 35 36 // These functions return NULL if an allocation fails. 37 void* tryFastMalloc(size_t n); 38 void* tryFastZeroedMalloc(size_t n); 39 void* tryFastCalloc(size_t n_elements, size_t element_size); 40 void* tryFastRealloc(void* p, size_t n); 41 33 42 void fastFree(void* p); 34 void *fastRealloc(void* p, size_t n);35 43 36 44 #ifndef NDEBUG … … 47 55 using WTF::fastCalloc; 48 56 using WTF::fastRealloc; 57 using WTF::tryFastMalloc; 58 using WTF::tryFastZeroedMalloc; 59 using WTF::tryFastCalloc; 60 using WTF::tryFastRealloc; 49 61 using WTF::fastFree; 50 62 -
trunk/WebCore/ChangeLog
r35690 r35691 1 2008-08-12 Dan Bernstein <mitz@apple.com> 2 3 - WebCore part of <rdar://problem/6121636> 4 Make fast*alloc() abort() on failure and add "try" variants that 5 return NULL on failure. 6 7 Reviewed by Darin Adler. 8 9 * platform/Arena.cpp: 10 (WebCore::ArenaAllocate): Removed null checking of fastMalloc()'s 11 result. 12 * platform/graphics/cg/ImageBufferCG.cpp: 13 (WebCore::ImageBuffer::create): Changed to use tryFastCalloc(). 14 1 15 2008-08-12 Dan Bernstein <mitz@apple.com> 2 16 -
trunk/WebCore/platform/Arena.cpp
r25754 r35691 181 181 #endif 182 182 a = (Arena*)fastMalloc(sz); 183 if (a) { 184 a->limit = (uword)a + sz; 185 a->base = a->avail = (uword)ARENA_ALIGN(pool, a + 1); 186 rp = (char *)a->avail; 187 a->avail += nb; 188 /* the newly allocated arena is linked after pool->current 189 * and becomes pool->current */ 190 a->next = pool->current->next; 191 pool->current->next = a; 192 pool->current = a; 193 if ( !pool->first.next ) 194 pool->first.next = a; 195 return(rp); 196 } 197 } 198 199 /* we got to here, and there's no memory to allocate */ 200 return(0); 183 // fastMalloc will abort() if it fails, so we are guaranteed that a is not 0. 184 a->limit = (uword)a + sz; 185 a->base = a->avail = (uword)ARENA_ALIGN(pool, a + 1); 186 rp = (char *)a->avail; 187 a->avail += nb; 188 /* the newly allocated arena is linked after pool->current 189 * and becomes pool->current */ 190 a->next = pool->current->next; 191 pool->current->next = a; 192 pool->current = a; 193 if ( !pool->first.next ) 194 pool->first.next = a; 195 return(rp); 196 } 201 197 } /* --- end ArenaAllocate() --- */ 202 198 -
trunk/WebCore/platform/graphics/cg/ImageBufferCG.cpp
r35290 r35691 56 56 } 57 57 58 void* imageBuffer = fastCalloc(size.height(), bytesPerRow);58 void* imageBuffer = tryFastCalloc(size.height(), bytesPerRow); 59 59 if (!imageBuffer) 60 60 return auto_ptr<ImageBuffer>();
Note:
See TracChangeset
for help on using the changeset viewer.