| 1 | /* |
| 2 | * Copyright (C) 2005, 2006, 2007, 2008, 2009 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_hcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/FastMalloc.h:22:9`! |
| 23 | |
| 24 | #include "Platform.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h`/ |
| 25 | #include "PossiblyNull.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/PossiblyNull.h`/ |
| 26 | #include <stdlib.h> |
| 27 | #include <new> |
| 28 | |
| 29 | namespace WTFcxx . . $ QTWTF/ { |
| 30 | |
| 31 | // These functions call CRASH() if an allocation fails. |
| 32 | void* fastMalloccxx . . $ QTWTF/fastMalloc(bfcfa4d6b7f7ef64).(size_t); |
| 33 | void* fastZeroedMalloccxx . . $ QTWTF/fastZeroedMalloc(bfcfa4d6b7f7ef64).(size_t); |
| 34 | void* fastCalloccxx . . $ QTWTF/fastCalloc(63a7bf2941bfcd7a).(size_t numElements, size_t elementSize); |
| 35 | void* fastRealloccxx . . $ QTWTF/fastRealloc(417ab160f6baadc6).(void*, size_t); |
| 36 | char* fastStrDupcxx . . $ QTWTF/fastStrDup(a8b8e32347182212).(const char*); |
| 37 | |
| 38 | struct TryMallocReturnValuecxx . . $ QTWTF/TryMallocReturnValue# { |
| 39 | TryMallocReturnValuecxx . . $ QTWTF/TryMallocReturnValue#TryMallocReturnValue(5d22bdacc48458e8).(void* data) |
| 40 | : m_datacxx . . $ QTWTF/TryMallocReturnValue#m_data.(data) |
| 41 | { |
| 42 | } |
| 43 | TryMallocReturnValuecxx . . $ QTWTF/TryMallocReturnValue#TryMallocReturnValue(1f58393e1bf9b27e).(const TryMallocReturnValuecxx . . $ QTWTF/TryMallocReturnValue#& source) |
| 44 | : m_datacxx . . $ QTWTF/TryMallocReturnValue#m_data.(source.m_datacxx . . $ QTWTF/TryMallocReturnValue#m_data.) |
| 45 | { |
| 46 | source.m_datacxx . . $ QTWTF/TryMallocReturnValue#m_data. = 0; |
| 47 | } |
| 48 | ~cxx . . $ QTWTF/TryMallocReturnValue#`~TryMallocReturnValue`(49f6e7a06ebc5aa8).TryMallocReturnValuecxx . . $ QTWTF/TryMallocReturnValue#() { ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_data); } |
| 49 | template <typename T> bool getValuecxx . . $ QTWTF/TryMallocReturnValue#getValue(e5bfd7b2d24a2428).(T& data) WARN_UNUSED_RETURNcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:1163:9`!; |
| 50 | template <typename T> operatorcxx . . $ QTWTF/TryMallocReturnValue#`operator PossiblyNull<type-parameter-0-0>`(17b0dc7817bf16a4). PossiblyNullcxx . . $ QTWTF/PossiblyNull#<T>() |
| 51 | { |
| 52 | T value; |
| 53 | getValuecxx . . $ QTWTF/TryMallocReturnValue#getValue(e5bfd7b2d24a2428).(value); |
| 54 | return PossiblyNullcxx . . $ QTWTF/PossiblyNull#<T>(value); |
| 55 | } |
| 56 | private: |
| 57 | mutable void* m_datacxx . . $ QTWTF/TryMallocReturnValue#m_data.; |
| 58 | }; |
| 59 | |
| 60 | template <typename T> bool TryMallocReturnValuecxx . . $ QTWTF/TryMallocReturnValue#::getValuecxx . . $ QTWTF/TryMallocReturnValue#getValue(e5bfd7b2d24a2428).(T& data) |
| 61 | { |
| 62 | union ucxx . . $ QTWTF/TryMallocReturnValue#getValue(e5bfd7b2d24a2428).u# { void* datacxx . . $ QTWTF/TryMallocReturnValue#getValue(e5bfd7b2d24a2428).u#data.; T targetcxx . . $ QTWTF/TryMallocReturnValue#getValue(e5bfd7b2d24a2428).u#target.; } res; |
| 63 | res.datacxx . . $ QTWTF/TryMallocReturnValue#getValue(e5bfd7b2d24a2428).u#data. = m_datacxx . . $ QTWTF/TryMallocReturnValue#m_data.; |
| 64 | data = res.targetcxx . . $ QTWTF/TryMallocReturnValue#getValue(e5bfd7b2d24a2428).u#target.; |
| 65 | bool returnValue = !!m_datacxx . . $ QTWTF/TryMallocReturnValue#m_data.; |
| 66 | m_datacxx . . $ QTWTF/TryMallocReturnValue#m_data. = 0; |
| 67 | return returnValue; |
| 68 | } |
| 69 | |
| 70 | TryMallocReturnValuecxx . . $ QTWTF/TryMallocReturnValue# tryFastMalloccxx . . $ QTWTF/tryFastMalloc(a199d47e2bcba94).(size_t n); |
| 71 | TryMallocReturnValuecxx . . $ QTWTF/TryMallocReturnValue# tryFastZeroedMalloccxx . . $ QTWTF/tryFastZeroedMalloc(a199d47e2bcba94).(size_t n); |
| 72 | TryMallocReturnValuecxx . . $ QTWTF/TryMallocReturnValue# tryFastCalloccxx . . $ QTWTF/tryFastCalloc(a4dbf2e2356fd5e4).(size_t n_elements, size_t element_size); |
| 73 | TryMallocReturnValuecxx . . $ QTWTF/TryMallocReturnValue# tryFastRealloccxx . . $ QTWTF/tryFastRealloc(6696b16547a81308).(void* p, size_t n); |
| 74 | |
| 75 | void fastFreecxx . . $ QTWTF/fastFree(5d22bdacc48458e8).(void*); |
| 76 | |
| 77 | #ifndef NDEBUGcxx . . $ `<built-in>:472:9`! |
| 78 | void fastMallocForbid(); |
| 79 | void fastMallocAllow(); |
| 80 | #endif |
| 81 | |
| 82 | void releaseFastMallocFreeMemorycxx . . $ QTWTF/releaseFastMallocFreeMemory(49f6e7a06ebc5aa8).(); |
| 83 | |
| 84 | struct FastMallocStatisticscxx . . $ QTWTF/FastMallocStatistics# { |
| 85 | size_t heapSizecxx . . $ QTWTF/FastMallocStatistics#heapSize.; |
| 86 | size_t freeSizeInHeapcxx . . $ QTWTF/FastMallocStatistics#freeSizeInHeap.; |
| 87 | size_t freeSizeInCachescxx . . $ QTWTF/FastMallocStatistics#freeSizeInCaches.; |
| 88 | size_t returnedSizecxx . . $ QTWTF/FastMallocStatistics#returnedSize.; |
| 89 | }; |
| 90 | FastMallocStatisticscxx . . $ QTWTF/FastMallocStatistics# fastMallocStatisticscxx . . $ QTWTF/fastMallocStatistics(a25cc48d49a9dad9).(); |
| 91 | |
| 92 | // This defines a type which holds an unsigned integer and is the same |
| 93 | // size as the minimally aligned memory allocation. |
| 94 | typedef unsigned long long AllocAlignmentIntegercxx . . $ QTWTF/AllocAlignmentInteger#; |
| 95 | |
| 96 | namespace Internalcxx . . $ QTWTF/Internal/ { |
| 97 | enum AllocTypecxx . . $ QTWTF/Internal/AllocType# { // Start with an unusual number instead of zero, because zero is common. |
| 98 | AllocTypeMalloccxx . . $ QTWTF/Internal/AllocTypeMalloc. = 0x375d6750, // Encompasses fastMalloc, fastZeroedMalloc, fastCalloc, fastRealloc. |
| 99 | AllocTypeClassNewcxx . . $ QTWTF/Internal/AllocTypeClassNew., // Encompasses class operator new from FastAllocBase. |
| 100 | AllocTypeClassNewArraycxx . . $ QTWTF/Internal/AllocTypeClassNewArray., // Encompasses class operator new[] from FastAllocBase. |
| 101 | AllocTypeFastNewcxx . . $ QTWTF/Internal/AllocTypeFastNew., // Encompasses fastNew. |
| 102 | AllocTypeFastNewArraycxx . . $ QTWTF/Internal/AllocTypeFastNewArray., // Encompasses fastNewArray. |
| 103 | AllocTypeNewcxx . . $ QTWTF/Internal/AllocTypeNew., // Encompasses global operator new. |
| 104 | AllocTypeNewArraycxx . . $ QTWTF/Internal/AllocTypeNewArray. // Encompasses global operator new[]. |
| 105 | }; |
| 106 | } |
| 107 | |
| 108 | #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(FAST_MALLOC_MATCH_VALIDATION) |
| 109 | |
| 110 | // Malloc validation is a scheme whereby a tag is attached to an |
| 111 | // allocation which identifies how it was originally allocated. |
| 112 | // This allows us to verify that the freeing operation matches the |
| 113 | // allocation operation. If memory is allocated with operator new[] |
| 114 | // but freed with free or delete, this system would detect that. |
| 115 | // In the implementation here, the tag is an integer prepended to |
| 116 | // the allocation memory which is assigned one of the AllocType |
| 117 | // enumeration values. An alternative implementation of this |
| 118 | // scheme could store the tag somewhere else or ignore it. |
| 119 | // Users of FastMalloc don't need to know or care how this tagging |
| 120 | // is implemented. |
| 121 | |
| 122 | namespace Internal { |
| 123 | |
| 124 | // Return the AllocType tag associated with the allocated block p. |
| 125 | inline AllocType fastMallocMatchValidationType(const void* p) |
| 126 | { |
| 127 | const AllocAlignmentInteger* type = static_cast<const AllocAlignmentInteger*>(p) - 1; |
| 128 | return static_cast<AllocType>(*type); |
| 129 | } |
| 130 | |
| 131 | // Return the address of the AllocType tag associated with the allocated block p. |
| 132 | inline AllocAlignmentInteger* fastMallocMatchValidationValue(void* p) |
| 133 | { |
| 134 | return reinterpret_cast<AllocAlignmentInteger*>(static_cast<char*>(p) - sizeof(AllocAlignmentInteger)); |
| 135 | } |
| 136 | |
| 137 | // Set the AllocType tag to be associaged with the allocated block p. |
| 138 | inline void setFastMallocMatchValidationType(void* p, AllocType allocType) |
| 139 | { |
| 140 | AllocAlignmentInteger* type = static_cast<AllocAlignmentInteger*>(p) - 1; |
| 141 | *type = static_cast<AllocAlignmentInteger>(allocType); |
| 142 | } |
| 143 | |
| 144 | // Handle a detected alloc/free mismatch. By default this calls CRASH(). |
| 145 | void fastMallocMatchFailed(void* p); |
| 146 | |
| 147 | } // namespace Internal |
| 148 | |
| 149 | // This is a higher level function which is used by FastMalloc-using code. |
| 150 | inline void fastMallocMatchValidateMalloc(void* p, Internal::AllocType allocType) |
| 151 | { |
| 152 | if (!p) |
| 153 | return; |
| 154 | |
| 155 | Internal::setFastMallocMatchValidationType(p, allocType); |
| 156 | } |
| 157 | |
| 158 | // This is a higher level function which is used by FastMalloc-using code. |
| 159 | inline void fastMallocMatchValidateFree(void* p, Internal::AllocType allocType) |
| 160 | { |
| 161 | if (!p) |
| 162 | return; |
| 163 | |
| 164 | if (Internal::fastMallocMatchValidationType(p) != allocType) |
| 165 | Internal::fastMallocMatchFailed(p); |
| 166 | Internal::setFastMallocMatchValidationType(p, Internal::AllocTypeMalloc); // Set it to this so that fastFree thinks it's OK. |
| 167 | } |
| 168 | |
| 169 | #else |
| 170 | |
| 171 | inline void fastMallocMatchValidateMalloccxx . . $ QTWTF/fastMallocMatchValidateMalloc(69548153c9894042).(void*, Internalcxx . . $ QTWTF/Internal/::AllocTypecxx . . $ QTWTF/Internal/AllocType#) |
| 172 | { |
| 173 | } |
| 174 | |
| 175 | inline void fastMallocMatchValidateFreecxx . . $ QTWTF/fastMallocMatchValidateFree(69548153c9894042).(void*, Internalcxx . . $ QTWTF/Internal/::AllocTypecxx . . $ QTWTF/Internal/AllocType#) |
| 176 | { |
| 177 | } |
| 178 | |
| 179 | #endif |
| 180 | |
| 181 | } // namespace WTF |
| 182 | |
| 183 | using WTFcxx . . $ `<built-in>:467:9`!::fastMalloccxx . . $ QTWTF/fastMalloc(bfcfa4d6b7f7ef64).; |
| 184 | using WTFcxx . . $ QTWTF/::fastZeroedMalloccxx . . $ QTWTF/fastZeroedMalloc(bfcfa4d6b7f7ef64).; |
| 185 | using WTFcxx . . $ `<built-in>:467:9`!::fastCalloccxx . . $ fastCalloc(63a7bf2941bfcd7a).; |
| 186 | using WTFcxx . . $ QTWTF/::fastRealloccxx . . $ fastRealloc(417ab160f6baadc6).; |
| 187 | using WTFcxx . . $ QTWTF/::tryFastMalloccxx . . $ tryFastMalloc(a199d47e2bcba94).; |
| 188 | using WTFcxx . . $ `<built-in>:467:9`!::tryFastZeroedMalloccxx . . $ tryFastZeroedMalloc(a199d47e2bcba94).; |
| 189 | using WTFcxx . . $ `<built-in>:467:9`!::tryFastCalloccxx . . $ QTWTF/tryFastCalloc(a4dbf2e2356fd5e4).; |
| 190 | using WTFcxx . . $ `<built-in>:467:9`!::tryFastRealloccxx . . $ tryFastRealloc(6696b16547a81308).; |
| 191 | using WTFcxx . . $ QTWTF/::fastFreecxx . . $ fastFree(5d22bdacc48458e8).; |
| 192 | using WTFcxx . . $ QTWTF/::fastStrDupcxx . . $ QTWTF/fastStrDup(a8b8e32347182212).; |
| 193 | |
| 194 | #ifndef NDEBUGcxx . . $ `<built-in>:472:9`! |
| 195 | using WTF::fastMallocForbid; |
| 196 | using WTF::fastMallocAllow; |
| 197 | #endif |
| 198 | |
| 199 | #if COMPILERcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:39:9`!(GCC) && OScxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:49:9`!(DARWIN) |
| 200 | #define WTF_PRIVATE_INLINE __private_extern__ inline __attribute__((always_inline)) |
| 201 | #elif COMPILERcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:39:9`!(GCC) |
| 202 | #define WTF_PRIVATE_INLINEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/FastMalloc.h:202:9`! inline __attribute__((always_inline)) |
| 203 | #elif COMPILER(MSVC) || COMPILER(RVCT) |
| 204 | #define WTF_PRIVATE_INLINE __forceinline |
| 205 | #else |
| 206 | #define WTF_PRIVATE_INLINE inline |
| 207 | #endif |
| 208 | |
| 209 | #if !defined(_CRTDBG_MAP_ALLOC) && !(defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC) |
| 210 | |
| 211 | // The nothrow functions here are actually not all that helpful, because fastMalloc will |
| 212 | // call CRASH() rather than returning 0, and returning 0 is what nothrow is all about. |
| 213 | // But since WebKit code never uses exceptions or nothrow at all, this is probably OK. |
| 214 | // Long term we will adopt FastAllocBase.h everywhere, and and replace this with |
| 215 | // debug-only code to make sure we don't use the system malloc via the default operator |
| 216 | // new by accident. |
| 217 | |
| 218 | // We musn't customize the global operator new and delete for the Qt port. |
| 219 | #if !PLATFORMcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:33:9`!(QT) |
| 220 | |
| 221 | #if COMPILER(MSVC) |
| 222 | #pragma warning(push) |
| 223 | #pragma warning(disable: 4290) // Disable the C++ exception specification ignored warning. |
| 224 | #endif |
| 225 | WTF_PRIVATE_INLINE void* operator new(size_t size) throw (std::bad_alloc) { return fastMalloc(size); } |
| 226 | WTF_PRIVATE_INLINE void* operator new(size_t size, const std::nothrow_t&) throw() { return fastMalloc(size); } |
| 227 | WTF_PRIVATE_INLINE void operator delete(void* p) throw() { fastFree(p); } |
| 228 | WTF_PRIVATE_INLINE void operator delete(void* p, const std::nothrow_t&) throw() { fastFree(p); } |
| 229 | WTF_PRIVATE_INLINE void* operator new[](size_t size) throw (std::bad_alloc) { return fastMalloc(size); } |
| 230 | WTF_PRIVATE_INLINE void* operator new[](size_t size, const std::nothrow_t&) throw() { return fastMalloc(size); } |
| 231 | WTF_PRIVATE_INLINE void operator delete[](void* p) throw() { fastFree(p); } |
| 232 | WTF_PRIVATE_INLINE void operator delete[](void* p, const std::nothrow_t&) throw() { fastFree(p); } |
| 233 | #if COMPILER(MSVC) |
| 234 | #pragma warning(pop) |
| 235 | #endif |
| 236 | |
| 237 | #endif |
| 238 | |
| 239 | #endif |
| 240 | |
| 241 | #endif /* WTF_FastMalloc_h */ |