source: webkit/trunk/JavaScriptCore/wtf/FastMalloc.h@ 35691

Last change on this file since 35691 was 35691, checked in by [email protected], 17 years ago

JavaScriptCore:

  • JavaScriptCore part of <rdar://problem/6121636> Make fast*alloc() abort() on failure and add "try" variants that return NULL on failure.

Reviewed by Darin Adler.

  • JavaScriptCore.exp: Exported tryFastCalloc().
  • VM/RegisterFile.h: (KJS::RegisterFile::RegisterFile): Removed an ASSERT().
  • kjs/JSArray.cpp: (KJS::JSArray::putSlowCase): Changed to use tryFastRealloc(). (KJS::JSArray::increaseVectorLength): Ditto.
  • kjs/ustring.cpp: (KJS::allocChars): Changed to use tryFastMalloc(). (KJS::reallocChars): Changed to use tryFastRealloc().
  • wtf/FastMalloc.cpp: (WTF::fastZeroedMalloc): Removed null checking of fastMalloc()'s result and removed extra call to InvokeNewHook(). (WTF::tryFastZeroedMalloc): Added. Uses tryFastMalloc(). (WTF::tryFastMalloc): Renamed fastMalloc() to this. (WTF::fastMalloc): Added. This version abort()s if allocation fails. (WTF::tryFastCalloc): Renamed fastCalloc() to this. (WTF::fastCalloc): Added. This version abort()s if allocation fails. (WTF::tryFastRealloc): Renamed fastRealloc() to this. (WTF::fastRealloc): Added. This version abort()s if allocation fails. (WTF::do_malloc): Made this a function template. When the abortOnFailure template parameter is set, the function abort()s on failure to allocate. Otherwise, it sets errno to ENOMEM and returns zero. (WTF::TCMallocStats::fastMalloc): Defined to abort() on failure. (WTF::TCMallocStats::tryFastMalloc): Added. Does not abort() on failure. (WTF::TCMallocStats::fastCalloc): Defined to abort() on failure. (WTF::TCMallocStats::tryFastCalloc): Added. Does not abort() on failure. (WTF::TCMallocStats::fastRealloc): Defined to abort() on failure. (WTF::TCMallocStats::tryFastRealloc): Added. Does not abort() on failure.
  • wtf/FastMalloc.h: Declared the "try" variants.

WebCore:

  • WebCore part of <rdar://problem/6121636> Make fast*alloc() abort() on failure and add "try" variants that return NULL on failure.

Reviewed by Darin Adler.

  • platform/Arena.cpp: (WebCore::ArenaAllocate): Removed null checking of fastMalloc()'s result.
  • platform/graphics/cg/ImageBufferCG.cpp: (WebCore::ImageBuffer::create): Changed to use tryFastCalloc().
  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1/*
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef WTF_FastMalloc_h
22#define WTF_FastMalloc_h
23
24#include "Platform.h"
25#include <stdlib.h>
26#include <new>
27
28namespace WTF {
29
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
42 void fastFree(void* p);
43
44#ifndef NDEBUG
45 void fastMallocForbid();
46 void fastMallocAllow();
47#endif
48
49 void releaseFastMallocFreeMemory();
50
51} // namespace WTF
52
53using WTF::fastMalloc;
54using WTF::fastZeroedMalloc;
55using WTF::fastCalloc;
56using WTF::fastRealloc;
57using WTF::tryFastMalloc;
58using WTF::tryFastZeroedMalloc;
59using WTF::tryFastCalloc;
60using WTF::tryFastRealloc;
61using WTF::fastFree;
62
63#ifndef NDEBUG
64using WTF::fastMallocForbid;
65using WTF::fastMallocAllow;
66#endif
67
68#if COMPILER(GCC) && PLATFORM(DARWIN)
69#define WTF_PRIVATE_INLINE __private_extern__ inline __attribute__((always_inline))
70#elif COMPILER(GCC)
71#define WTF_PRIVATE_INLINE inline __attribute__((always_inline))
72#elif COMPILER(MSVC)
73#define WTF_PRIVATE_INLINE __forceinline
74#else
75#define WTF_PRIVATE_INLINE inline
76#endif
77
78#ifndef _CRTDBG_MAP_ALLOC
79
80#if !defined(USE_SYSTEM_MALLOC) || !(USE_SYSTEM_MALLOC)
81WTF_PRIVATE_INLINE void* operator new(size_t s) { return fastMalloc(s); }
82WTF_PRIVATE_INLINE void operator delete(void* p) { fastFree(p); }
83WTF_PRIVATE_INLINE void* operator new[](size_t s) { return fastMalloc(s); }
84WTF_PRIVATE_INLINE void operator delete[](void* p) { fastFree(p); }
85#endif
86
87#endif // _CRTDBG_MAP_ALLOC
88
89#endif /* WTF_FastMalloc_h */
Note: See TracBrowser for help on using the repository browser.