Changeset 164261 in webkit


Ignore:
Timestamp:
Feb 17, 2014 5:32:18 PM (10 years ago)
Author:
andersca@apple.com
Message:

Remove ENABLE_GLOBAL_FASTMALLOC_NEW
https://bugs.webkit.org/show_bug.cgi?id=127067

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

  • parser/Nodes.h:

Source/WebCore:

  • platform/Timer.h:

Source/WTF:

Remove the global operator new/operator delete overrides. Having ALWAYS_INLINE operators
like we do is really undefined behavior according to the C++ standard and we've been lucky enough
to get away with it so far, but any code that calls operator new/operator delete inside from the C++ standard
library (not from headers that are included) will be mismatched and potentially crash. libc++ calls
delete in it's std::thread implementation for example.

The only supported way to override operator new and operator delete globally is to not use inline
functions, but that would mean that any application using WebKit would not be able to provide custom
operator new/operator delete functions so we'll just reuse the already existing infrastructure consisting
of the WTF_MAKE_FAST_ALLOCATED macro.

  • wtf/FastMalloc.cpp:

(WTF::TCMalloc_ThreadCache::CreateCacheIfNecessary):

  • wtf/FastMalloc.h:
  • wtf/Platform.h:
Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r164245 r164261  
     12014-02-17  Anders Carlsson  <andersca@apple.com>
     2
     3        Remove ENABLE_GLOBAL_FASTMALLOC_NEW
     4        https://bugs.webkit.org/show_bug.cgi?id=127067
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * parser/Nodes.h:
     9
    1102014-02-17  Sergio Correia  <sergio.correia@openbossa.org>
    211
  • trunk/Source/JavaScriptCore/parser/Nodes.h

    r164139 r164261  
    113113
    114114    class ParserArenaRefCounted : public RefCounted<ParserArenaRefCounted> {
    115         WTF_FASTMALLOC_OPERATORS;
     115        WTF_MAKE_FAST_ALLOCATED;
    116116    protected:
    117117        ParserArenaRefCounted(VM*);
  • trunk/Source/WTF/ChangeLog

    r164220 r164261  
     12014-02-17  Anders Carlsson  <andersca@apple.com>
     2
     3        Remove ENABLE_GLOBAL_FASTMALLOC_NEW
     4        https://bugs.webkit.org/show_bug.cgi?id=127067
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Remove the global operator new/operator delete overrides. Having ALWAYS_INLINE operators
     9        like we do is really undefined behavior according to the C++ standard and we've been lucky enough
     10        to get away with it so far, but any code that calls operator new/operator delete inside from the C++ standard
     11        library (not from headers that are included) will be mismatched and potentially crash. libc++ calls
     12        delete in it's std::thread implementation for example.
     13       
     14        The only supported way to override operator new and operator delete globally is to not use inline
     15        functions, but that would mean that any application using WebKit would not be able to provide custom
     16        operator new/operator delete functions so we'll just reuse the already existing infrastructure consisting
     17        of the WTF_MAKE_FAST_ALLOCATED macro.
     18
     19        * wtf/FastMalloc.cpp:
     20        (WTF::TCMalloc_ThreadCache::CreateCacheIfNecessary):
     21        * wtf/FastMalloc.h:
     22        * wtf/Platform.h:
     23
    1242014-02-17  Ryan Lortie  <desrt@desrt.ca>
    225
  • trunk/Source/WTF/wtf/FastMalloc.cpp

    r157474 r164261  
    45324532}
    45334533
    4534 #if ENABLE(GLOBAL_FASTMALLOC_NEW)
    4535 
    4536 void* operator new(size_t size) {
    4537   void* p = cpp_alloc(size, false);
    4538   // We keep this next instruction out of cpp_alloc for a reason: when
    4539   // it's in, and new just calls cpp_alloc, the optimizer may fold the
    4540   // new call into cpp_alloc, which messes up our whole section-based
    4541   // stacktracing (see ATTRIBUTE_SECTION, above).  This ensures cpp_alloc
    4542   // isn't the last thing this fn calls, and prevents the folding.
    4543   MallocHook::InvokeNewHook(p, size);
    4544   return p;
    4545 }
    4546 
    4547 void* operator new(size_t size, const std::nothrow_t&) __THROW {
    4548   void* p = cpp_alloc(size, true);
    4549   MallocHook::InvokeNewHook(p, size);
    4550   return p;
    4551 }
    4552 
    4553 void operator delete(void* p) __THROW {
    4554   MallocHook::InvokeDeleteHook(p);
    4555   do_free(p);
    4556 }
    4557 
    4558 void operator delete(void* p, const std::nothrow_t&) __THROW {
    4559   MallocHook::InvokeDeleteHook(p);
    4560   do_free(p);
    4561 }
    4562 
    4563 void* operator new[](size_t size) {
    4564   void* p = cpp_alloc(size, false);
    4565   // We keep this next instruction out of cpp_alloc for a reason: when
    4566   // it's in, and new just calls cpp_alloc, the optimizer may fold the
    4567   // new call into cpp_alloc, which messes up our whole section-based
    4568   // stacktracing (see ATTRIBUTE_SECTION, above).  This ensures cpp_alloc
    4569   // isn't the last thing this fn calls, and prevents the folding.
    4570   MallocHook::InvokeNewHook(p, size);
    4571   return p;
    4572 }
    4573 
    4574 void* operator new[](size_t size, const std::nothrow_t&) __THROW {
    4575   void* p = cpp_alloc(size, true);
    4576   MallocHook::InvokeNewHook(p, size);
    4577   return p;
    4578 }
    4579 
    4580 void operator delete[](void* p) __THROW {
    4581   MallocHook::InvokeDeleteHook(p);
    4582   do_free(p);
    4583 }
    4584 
    4585 void operator delete[](void* p, const std::nothrow_t&) __THROW {
    4586   MallocHook::InvokeDeleteHook(p);
    4587   do_free(p);
    4588 }
    4589 
    4590 #endif
    4591 
    45924534extern "C" void* memalign(size_t align, size_t size) __THROW {
    45934535  void* result = do_memalign(align, size);
  • trunk/Source/WTF/wtf/FastMalloc.h

    r160838 r164261  
    249249#endif
    250250
    251 #if !defined(_CRTDBG_MAP_ALLOC) && !(defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC)
    252 
    253 // The nothrow functions here are actually not all that helpful, because fastMalloc will
    254 // call CRASH() rather than returning 0, and returning 0 is what nothrow is all about.
    255 // But since WebKit code never uses exceptions or nothrow at all, this is probably OK.
    256 // Long term we will adopt FastAllocBase.h everywhere, and and replace this with
    257 // debug-only code to make sure we don't use the system malloc via the default operator
    258 // new by accident.
    259 
    260 #if ENABLE(GLOBAL_FASTMALLOC_NEW)
    261 
    262 #if COMPILER(MSVC)
    263 #pragma warning(push)
    264 #pragma warning(disable: 4290) // Disable the C++ exception specification ignored warning.
    265 #elif COMPILER(CLANG) && defined(__has_warning)
    266 #pragma clang diagnostic push
    267 #if __has_warning("-Winline-new-delete")
    268 // FIXME: The operator new, delete definitions cannot be inline per replacement.functions (17.6.4.6/3) of the C++
    269 // standard. As a workaround, disable warnings for such usage. See <https://bugs.webkit.org/show_bug.cgi?id=124186>.
    270 #pragma clang diagnostic ignored "-Winline-new-delete"
    271 #endif
    272 #endif
    273 WTF_PRIVATE_INLINE void* operator new(size_t size) throw (std::bad_alloc) { return fastMalloc(size); }
    274 WTF_PRIVATE_INLINE void* operator new(size_t size, const std::nothrow_t&) throw() { return fastMalloc(size); }
    275 WTF_PRIVATE_INLINE void operator delete(void* p) throw() { fastFree(p); }
    276 WTF_PRIVATE_INLINE void operator delete(void* p, const std::nothrow_t&) throw() { fastFree(p); }
    277 WTF_PRIVATE_INLINE void* operator new[](size_t size) throw (std::bad_alloc) { return fastMalloc(size); }
    278 WTF_PRIVATE_INLINE void* operator new[](size_t size, const std::nothrow_t&) throw() { return fastMalloc(size); }
    279 WTF_PRIVATE_INLINE void operator delete[](void* p) throw() { fastFree(p); }
    280 WTF_PRIVATE_INLINE void operator delete[](void* p, const std::nothrow_t&) throw() { fastFree(p); }
    281 #if COMPILER(MSVC)
    282 #pragma warning(pop)
    283 #elif COMPILER(CLANG) && defined(__has_warning)
    284 #pragma clang diagnostic pop
    285 #endif
    286 
    287 #endif // ENABLE(GLOBAL_FASTMALLOC_NEW)
    288 #endif // !defined(_CRTDBG_MAP_ALLOC) && !(defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC)
    289 
    290 #define WTF_FASTMALLOC_OPERATORS \
     251#define WTF_MAKE_FAST_ALLOCATED \
    291252public: \
    292253    void* operator new(size_t, void* p) { return p; } \
     
    326287typedef int __thisIsHereToForceASemicolonAfterThisMacro
    327288
    328 #if ENABLE(GLOBAL_FASTMALLOC_NEW)
    329 #define WTF_MAKE_FAST_ALLOCATED
    330 #else
    331 #define WTF_MAKE_FAST_ALLOCATED WTF_FASTMALLOC_OPERATORS
    332 #endif
    333 
    334 
    335289#endif /* WTF_FastMalloc_h */
  • trunk/Source/WTF/wtf/Platform.h

    r164220 r164261  
    450450#define WTF_USE_SOUP 1
    451451#define WTF_USE_WEBP 1
    452 #define ENABLE_GLOBAL_FASTMALLOC_NEW 0
    453452#endif
    454453
     
    602601#include <wtf/FeatureDefines.h>
    603602
    604 #if PLATFORM(EFL)
    605 #define ENABLE_GLOBAL_FASTMALLOC_NEW 0
    606 #endif
    607 
    608603#if OS(WINDOWS)
    609 #define ENABLE_GLOBAL_FASTMALLOC_NEW 0
    610604#define USE_SYSTEM_MALLOC 1
    611 #endif
    612 
    613 #if !defined(ENABLE_GLOBAL_FASTMALLOC_NEW)
    614 #define ENABLE_GLOBAL_FASTMALLOC_NEW 1
    615605#endif
    616606
  • trunk/Source/WebCore/ChangeLog

    r164259 r164261  
     12014-02-17  Anders Carlsson  <andersca@apple.com>
     2
     3        Remove ENABLE_GLOBAL_FASTMALLOC_NEW
     4        https://bugs.webkit.org/show_bug.cgi?id=127067
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * platform/Timer.h:
     9
    1102014-02-17  Sam Weinig  <sam@webkit.org>
    211
  • trunk/Source/WebCore/platform/Timer.h

    r162716 r164261  
    4545class TimerBase {
    4646    WTF_MAKE_NONCOPYABLE(TimerBase);
    47     WTF_FASTMALLOC_OPERATORS;
     47    WTF_MAKE_FAST_ALLOCATED;
    4848public:
    4949    TimerBase();
Note: See TracChangeset for help on using the changeset viewer.