2011-04-04 Sheriff Bot <webkit.review.bot@gmail.com>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Apr 2011 05:33:40 +0000 (05:33 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Apr 2011 05:33:40 +0000 (05:33 +0000)
        Unreviewed, rolling out r82876.
        http://trac.webkit.org/changeset/82876
        https://bugs.webkit.org/show_bug.cgi?id=57816

        Caused a lot of test crashes (Requested by tkent on #webkit).

        * JavaScriptCore.exp:
        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
        * wtf/FastMalloc.cpp:
        (WTF::tryFastMalloc):
        (WTF::fastMalloc):
        (WTF::tryFastCalloc):
        (WTF::fastCalloc):
        (WTF::fastFree):
        (WTF::tryFastRealloc):
        (WTF::fastRealloc):
        (WTF::fastMallocSize):
        (WTF::TCMalloc_PageHeap::isScavengerSuspended):
        (WTF::TCMalloc_PageHeap::scheduleScavenger):
        (WTF::TCMalloc_PageHeap::suspendScavenger):
        (WTF::TCMalloc_PageHeap::signalScavenger):
        (WTF::TCMallocStats::malloc):
        (WTF::TCMallocStats::free):
        (WTF::TCMallocStats::fastCalloc):
        (WTF::TCMallocStats::tryFastCalloc):
        (WTF::TCMallocStats::calloc):
        (WTF::TCMallocStats::fastRealloc):
        (WTF::TCMallocStats::tryFastRealloc):
        (WTF::TCMallocStats::realloc):
        (WTF::TCMallocStats::fastMallocSize):
        * wtf/FastMalloc.h:
        (WTF::Internal::fastMallocMatchValidationType):
        (WTF::Internal::fastMallocMatchValidationValue):
        (WTF::Internal::setFastMallocMatchValidationType):
        (WTF::fastMallocMatchValidateFree):
        * wtf/Platform.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@82905 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.exp
Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
Source/JavaScriptCore/wtf/FastMalloc.cpp
Source/JavaScriptCore/wtf/FastMalloc.h
Source/JavaScriptCore/wtf/Platform.h

index 92f8321..23ceae8 100644 (file)
@@ -1,3 +1,42 @@
+2011-04-04  Sheriff Bot  <webkit.review.bot@gmail.com>
+
+        Unreviewed, rolling out r82876.
+        http://trac.webkit.org/changeset/82876
+        https://bugs.webkit.org/show_bug.cgi?id=57816
+
+        Caused a lot of test crashes (Requested by tkent on #webkit).
+
+        * JavaScriptCore.exp:
+        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
+        * wtf/FastMalloc.cpp:
+        (WTF::tryFastMalloc):
+        (WTF::fastMalloc):
+        (WTF::tryFastCalloc):
+        (WTF::fastCalloc):
+        (WTF::fastFree):
+        (WTF::tryFastRealloc):
+        (WTF::fastRealloc):
+        (WTF::fastMallocSize):
+        (WTF::TCMalloc_PageHeap::isScavengerSuspended):
+        (WTF::TCMalloc_PageHeap::scheduleScavenger):
+        (WTF::TCMalloc_PageHeap::suspendScavenger):
+        (WTF::TCMalloc_PageHeap::signalScavenger):
+        (WTF::TCMallocStats::malloc):
+        (WTF::TCMallocStats::free):
+        (WTF::TCMallocStats::fastCalloc):
+        (WTF::TCMallocStats::tryFastCalloc):
+        (WTF::TCMallocStats::calloc):
+        (WTF::TCMallocStats::fastRealloc):
+        (WTF::TCMallocStats::tryFastRealloc):
+        (WTF::TCMallocStats::realloc):
+        (WTF::TCMallocStats::fastMallocSize):
+        * wtf/FastMalloc.h:
+        (WTF::Internal::fastMallocMatchValidationType):
+        (WTF::Internal::fastMallocMatchValidationValue):
+        (WTF::Internal::setFastMallocMatchValidationType):
+        (WTF::fastMallocMatchValidateFree):
+        * wtf/Platform.h:
+
 2011-04-04  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Antti Koivisto.
index e61e830..b9e5354 100644 (file)
@@ -492,7 +492,6 @@ __ZN3WTF7xmlAtomE
 __ZN3WTF8Collator18setOrderLowerFirstEb
 __ZN3WTF8CollatorC1EPKc
 __ZN3WTF8CollatorD1Ev
-__ZN3WTF8Internal21fastMallocMatchFailedEPv
 __ZN3WTF8fastFreeEPv
 __ZN3WTF8msToYearEd
 __ZN3WTF8nullAtomE
index 13e23be..5c4c374 100644 (file)
@@ -161,7 +161,6 @@ EXPORTS
     ?fastCalloc@WTF@@YAPAXII@Z
     ?fastFree@WTF@@YAXPAX@Z
     ?fastMalloc@WTF@@YAPAXI@Z
-    ?fastMallocMatchFailed@Internal@WTF@@YAXPAX@Z
     ?fastMallocSize@WTF@@YAIPBX@Z
     ?fastRealloc@WTF@@YAPAXPAXI@Z
     ?fastStrDup@WTF@@YAPADPBD@Z
index d056f4a..3b79f6d 100644 (file)
@@ -161,13 +161,10 @@ void fastMallocAllow()
 
 namespace WTF {
 
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
 
 namespace Internal {
-#if !ENABLE(WTF_MALLOC_VALIDATION)
-void fastMallocMatchFailed(void*);
-#else
-COMPILE_ASSERT(((sizeof(ValidationHeader) % sizeof(AllocAlignmentInteger)) == 0), ValidationHeader_must_produce_correct_alignment);
-#endif
+
 void fastMallocMatchFailed(void*)
 {
     CRASH();
@@ -175,6 +172,7 @@ void fastMallocMatchFailed(void*)
 
 } // namespace Internal
 
+#endif
 
 void* fastZeroedMalloc(size_t n) 
 {
@@ -223,20 +221,17 @@ TryMallocReturnValue tryFastMalloc(size_t n)
 {
     ASSERT(!isForbidden());
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    if (std::numeric_limits<size_t>::max() - Internal::ValidationBufferSize <= n)  // If overflow would occur...
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
+    if (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= n)  // If overflow would occur...
         return 0;
 
-    void* result = malloc(n + Internal::ValidationBufferSize);
+    void* result = malloc(n + sizeof(AllocAlignmentInteger));
     if (!result)
         return 0;
-    Internal::ValidationHeader* header = static_cast<Internal::ValidationHeader*>(result);
-    header->m_size = n;
-    header->m_type = Internal::AllocTypeMalloc;
-    header->m_prefix = static_cast<unsigned>(Internal::ValidationPrefix);
-    result = header + 1;
-    *Internal::fastMallocValidationSuffix(result) = Internal::ValidationSuffix;
-    fastMallocValidate(result);
+
+    *static_cast<AllocAlignmentInteger*>(result) = Internal::AllocTypeMalloc;
+    result = static_cast<AllocAlignmentInteger*>(result) + 1;
+
     return result;
 #else
     return malloc(n);
@@ -247,7 +242,7 @@ void* fastMalloc(size_t n)
 {
     ASSERT(!isForbidden());
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     TryMallocReturnValue returnValue = tryFastMalloc(n);
     void* result;
     if (!returnValue.getValue(result))
@@ -273,17 +268,19 @@ TryMallocReturnValue tryFastCalloc(size_t n_elements, size_t element_size)
 {
     ASSERT(!isForbidden());
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     size_t totalBytes = n_elements * element_size;
-    if (n_elements > 1 && element_size && (totalBytes / element_size) != n_elements)
+    if (n_elements > 1 && element_size && (totalBytes / element_size) != n_elements || (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= totalBytes))
         return 0;
 
-    TryMallocReturnValue returnValue = tryFastMalloc(totalBytes);
-    void* result;
-    if (!returnValue.getValue(result))
+    totalBytes += sizeof(AllocAlignmentInteger);
+    void* result = malloc(totalBytes);
+    if (!result)
         return 0;
+
     memset(result, 0, totalBytes);
-    fastMallocValidate(result);
+    *static_cast<AllocAlignmentInteger*>(result) = Internal::AllocTypeMalloc;
+    result = static_cast<AllocAlignmentInteger*>(result) + 1;
     return result;
 #else
     return calloc(n_elements, element_size);
@@ -294,7 +291,7 @@ void* fastCalloc(size_t n_elements, size_t element_size)
 {
     ASSERT(!isForbidden());
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     TryMallocReturnValue returnValue = tryFastCalloc(n_elements, element_size);
     void* result;
     if (!returnValue.getValue(result))
@@ -320,13 +317,13 @@ void fastFree(void* p)
 {
     ASSERT(!isForbidden());
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     if (!p)
         return;
-    
-    fastMallocMatchValidateFree(p, Internal::AllocTypeMalloc);
-    Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(p);
-    memset(p, 0xCC, header->m_size);
+
+    AllocAlignmentInteger* header = Internal::fastMallocMatchValidationValue(p);
+    if (*header != Internal::AllocTypeMalloc)
+        Internal::fastMallocMatchFailed(p);
     free(header);
 #else
     free(p);
@@ -337,18 +334,20 @@ TryMallocReturnValue tryFastRealloc(void* p, size_t n)
 {
     ASSERT(!isForbidden());
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     if (p) {
-        if (std::numeric_limits<size_t>::max() - Internal::ValidationBufferSize <= n)  // If overflow would occur...
+        if (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= n)  // If overflow would occur...
             return 0;
-        fastMallocValidate(p);
-        Internal::ValidationHeader* result = static_cast<Internal::ValidationHeader*>(realloc(Internal::fastMallocValidationHeader(p), n + Internal::ValidationBufferSize));
+        AllocAlignmentInteger* header = Internal::fastMallocMatchValidationValue(p);
+        if (*header != Internal::AllocTypeMalloc)
+            Internal::fastMallocMatchFailed(p);
+        void* result = realloc(header, n + sizeof(AllocAlignmentInteger));
         if (!result)
             return 0;
-        result->m_size = n;
-        result = result + 1;
-        *fastMallocValidationSuffix(result) = Internal::ValidationSuffix;
-        fastMallocValidate(result);
+
+        // This should not be needed because the value is already there:
+        // *static_cast<AllocAlignmentInteger*>(result) = Internal::AllocTypeMalloc;
+        result = static_cast<AllocAlignmentInteger*>(result) + 1;
         return result;
     } else {
         return fastMalloc(n);
@@ -362,7 +361,7 @@ void* fastRealloc(void* p, size_t n)
 {
     ASSERT(!isForbidden());
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     TryMallocReturnValue returnValue = tryFastRealloc(p, n);
     void* result;
     if (!returnValue.getValue(result))
@@ -386,9 +385,7 @@ FastMallocStatistics fastMallocStatistics()
 
 size_t fastMallocSize(const void* p)
 {
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    return Internal::fastMallocValidationHeader(const_cast<void*>(p))->m_size;
-#elif OS(DARWIN)
+#if OS(DARWIN)
     return malloc_size(p);
 #elif OS(WINDOWS) && !PLATFORM(BREWMP)
     // Brew MP uses its own memory allocator, so _msize does not work on the Brew MP simulator.
@@ -1306,8 +1303,6 @@ static const size_t kMinimumFreeCommittedPageCount = kMinSpanListsWithSpans * ((
 
 #endif
 
-static SpinLock pageheap_lock = SPINLOCK_INITIALIZER;
-
 class TCMalloc_PageHeap {
  public:
   void init();
@@ -1534,13 +1529,13 @@ void TCMalloc_PageHeap::initializeScavenger()
 
 ALWAYS_INLINE bool TCMalloc_PageHeap::isScavengerSuspended()
 {
-    ASSERT(pageheap_lock.IsHeld());
+    ASSERT(IsHeld(pageheap_lock));
     return m_scavengingSuspended;
 }
 
 ALWAYS_INLINE void TCMalloc_PageHeap::scheduleScavenger()
 {
-    ASSERT(pageheap_lock.IsHeld());
+    ASSERT(IsHeld(pageheap_lock));
     m_scavengingSuspended = false;
     dispatch_resume(m_scavengeTimer);
 }
@@ -1552,7 +1547,7 @@ ALWAYS_INLINE void TCMalloc_PageHeap::rescheduleScavenger()
 
 ALWAYS_INLINE void TCMalloc_PageHeap::suspendScavenger()
 {
-    ASSERT(pageheap_lock.IsHeld());
+    ASSERT(IsHeld(pageheap_lock));
     m_scavengingSuspended = true;
     dispatch_suspend(m_scavengeTimer);
 }
@@ -2445,6 +2440,7 @@ class TCMalloc_Central_FreeListPadded : public TCMalloc_Central_FreeList {
 static TCMalloc_Central_FreeListPadded central_cache[kNumClasses];
 
 // Page-level allocator
+static SpinLock pageheap_lock = SPINLOCK_INITIALIZER;
 static AllocAlignmentInteger pageheap_memory[(sizeof(TCMalloc_PageHeap) + sizeof(AllocAlignmentInteger) - 1) / sizeof(AllocAlignmentInteger)];
 static bool phinited = false;
 
@@ -2482,7 +2478,7 @@ void TCMalloc_PageHeap::periodicScavenge()
 
 ALWAYS_INLINE void TCMalloc_PageHeap::signalScavenger()
 {
-    ASSERT(pageheap_lock.IsHeld());
+    ASSERT(IsHeld(pageheap_lock));
     if (isScavengerSuspended() && shouldScavenge())
         scheduleScavenger();
 }
@@ -3828,20 +3824,16 @@ template <bool crashOnFailure>
 ALWAYS_INLINE
 #endif
 void* malloc(size_t size) {
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    if (std::numeric_limits<size_t>::max() - Internal::ValidationBufferSize <= size)  // If overflow would occur...
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
+    if (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= size)  // If overflow would occur...
         return 0;
-    void* result = do_malloc(size + Internal::ValidationBufferSize);
+    size += sizeof(AllocAlignmentInteger);
+    void* result = do_malloc(size);
     if (!result)
         return 0;
 
-    Internal::ValidationHeader* header = static_cast<Internal::ValidationHeader*>(result);
-    header->m_size = size;
-    header->m_type = Internal::AllocTypeMalloc;
-    header->m_prefix = static_cast<unsigned>(Internal::ValidationPrefix);
-    result = header + 1;
-    *Internal::fastMallocValidationSuffix(result) = Internal::ValidationSuffix;
-    fastMallocValidate(result);
+    *static_cast<AllocAlignmentInteger*>(result) = Internal::AllocTypeMalloc;
+    result = static_cast<AllocAlignmentInteger*>(result) + 1;
 #else
     void* result = do_malloc(size);
 #endif
@@ -3860,13 +3852,13 @@ void free(void* ptr) {
   MallocHook::InvokeDeleteHook(ptr);
 #endif
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
     if (!ptr)
         return;
 
-    fastMallocValidate(ptr);
-    Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(ptr);
-    memset(ptr, 0xCC, header->m_size);
+    AllocAlignmentInteger* header = Internal::fastMallocMatchValidationValue(ptr);
+    if (*header != Internal::AllocTypeMalloc)
+        Internal::fastMallocMatchFailed(ptr);
     do_free(header);
 #else
     do_free(ptr);
@@ -3881,20 +3873,12 @@ ALWAYS_INLINE void* calloc(size_t, size_t);
 
 void* fastCalloc(size_t n, size_t elem_size)
 {
-    void* result = calloc<true>(n, elem_size);
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    fastMallocValidate(result);
-#endif
-    return result;
+    return calloc<true>(n, elem_size);
 }
 
 TryMallocReturnValue tryFastCalloc(size_t n, size_t elem_size)
 {
-    void* result = calloc<false>(n, elem_size);
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    fastMallocValidate(result);
-#endif
-    return result;
+    return calloc<false>(n, elem_size);
 }
 
 template <bool crashOnFailure>
@@ -3907,13 +3891,18 @@ void* calloc(size_t n, size_t elem_size) {
   if (n > 1 && elem_size && (totalBytes / elem_size) != n)
     return 0;
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    void* result = malloc<crashOnFailure>(totalBytes);
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
+    if (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= totalBytes)  // If overflow would occur...
+        return 0;
+
+    totalBytes += sizeof(AllocAlignmentInteger);
+    void* result = do_malloc(totalBytes);
     if (!result)
         return 0;
 
     memset(result, 0, totalBytes);
-    fastMallocValidate(result);
+    *static_cast<AllocAlignmentInteger*>(result) = Internal::AllocTypeMalloc;
+    result = static_cast<AllocAlignmentInteger*>(result) + 1;
 #else
     void* result = do_malloc(totalBytes);
     if (result != NULL) {
@@ -3948,26 +3937,12 @@ ALWAYS_INLINE void* realloc(void*, size_t);
 
 void* fastRealloc(void* old_ptr, size_t new_size)
 {
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    fastMallocValidate(old_ptr);
-#endif
-    void* result = realloc<true>(old_ptr, new_size);
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    fastMallocValidate(result);
-#endif
-    return result;
+    return realloc<true>(old_ptr, new_size);
 }
 
 TryMallocReturnValue tryFastRealloc(void* old_ptr, size_t new_size)
 {
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    fastMallocValidate(old_ptr);
-#endif
-    void* result = realloc<false>(old_ptr, new_size);
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    fastMallocValidate(result);
-#endif
-    return result;
+    return realloc<false>(old_ptr, new_size);
 }
 
 template <bool crashOnFailure>
@@ -3975,8 +3950,8 @@ ALWAYS_INLINE
 #endif
 void* realloc(void* old_ptr, size_t new_size) {
   if (old_ptr == NULL) {
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    void* result = malloc<crashOnFailure>(new_size);
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
+    void* result = malloc(new_size);
 #else
     void* result = do_malloc(new_size);
 #ifndef WTF_CHANGES
@@ -3993,14 +3968,14 @@ void* realloc(void* old_ptr, size_t new_size) {
     return NULL;
   }
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    if (std::numeric_limits<size_t>::max() - Internal::ValidationBufferSize <= new_size)  // If overflow would occur...
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
+    if (std::numeric_limits<size_t>::max() - sizeof(AllocAlignmentInteger) <= new_size)  // If overflow would occur...
         return 0;
-    Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(old_ptr);
-    fastMallocValidate(old_ptr);
+    new_size += sizeof(AllocAlignmentInteger);
+    AllocAlignmentInteger* header = Internal::fastMallocMatchValidationValue(old_ptr);
+    if (*header != Internal::AllocTypeMalloc)
+        Internal::fastMallocMatchFailed(old_ptr);
     old_ptr = header;
-    header->m_size = new_size;
-    new_size += Internal::ValidationBufferSize;
 #endif
 
   // Get the size of the old entry
@@ -4039,15 +4014,13 @@ void* realloc(void* old_ptr, size_t new_size) {
     // that we already know the sizeclass of old_ptr.  The benefit
     // would be small, so don't bother.
     do_free(old_ptr);
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    new_ptr = static_cast<Internal::ValidationHeader*>(new_ptr) + 1;
-    *Internal::fastMallocValidationSuffix(new_ptr) = Internal::ValidationSuffix;
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
+    new_ptr = static_cast<AllocAlignmentInteger*>(new_ptr) + 1;
 #endif
     return new_ptr;
   } else {
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    old_ptr = static_cast<Internal::ValidationHeader*>(old_ptr) + 1; // Set old_ptr back to the user pointer.
-    *Internal::fastMallocValidationSuffix(old_ptr) = Internal::ValidationSuffix;
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
+    old_ptr = static_cast<AllocAlignmentInteger*>(old_ptr) + 1; // Set old_ptr back to the user pointer.
 #endif
     return old_ptr;
   }
@@ -4308,9 +4281,6 @@ FastMallocStatistics fastMallocStatistics()
 
 size_t fastMallocSize(const void* ptr)
 {
-#if ENABLE(WTF_MALLOC_VALIDATION)
-    return Internal::fastMallocValidationHeader(p)->m_size;
-#else
     const PageID p = reinterpret_cast<uintptr_t>(ptr) >> kPageShift;
     Span* span = pageheap->GetDescriptorEnsureSafe(p);
 
@@ -4326,7 +4296,6 @@ size_t fastMallocSize(const void* ptr)
         return ByteSizeForClass(cl);
 
     return span->length << kPageShift;
-#endif
 }
 
 #if OS(DARWIN)
index 37cf086..9729bc3 100644 (file)
@@ -103,25 +103,9 @@ namespace WTF {
             AllocTypeNew,                   // Encompasses global operator new.
             AllocTypeNewArray               // Encompasses global operator new[].
         };
-
-        enum {
-            ValidationPrefix = 0xf00df00d,
-            ValidationSuffix = 0x0badf00d
-        };
-
-        typedef unsigned ValidationTag;
-
-        struct ValidationHeader {
-            AllocType m_type;
-            unsigned m_size;
-            ValidationTag m_prefix;
-            unsigned m_alignment;
-        };
-
-        static const int ValidationBufferSize = sizeof(ValidationHeader) + sizeof(ValidationTag);
     }
 
-#if ENABLE(WTF_MALLOC_VALIDATION)
+#if ENABLE(FAST_MALLOC_MATCH_VALIDATION)
 
     // Malloc validation is a scheme whereby a tag is attached to an
     // allocation which identifies how it was originally allocated.
@@ -136,36 +120,30 @@ namespace WTF {
     // is implemented.
 
     namespace Internal {
-    
-        // Handle a detected alloc/free mismatch. By default this calls CRASH().
-        void fastMallocMatchFailed(void* p);
 
-        inline ValidationHeader* fastMallocValidationHeader(void* p)
-        {
-            return reinterpret_cast<ValidationHeader*>(static_cast<char*>(p) - sizeof(ValidationHeader));
-        }
-
-        inline ValidationTag* fastMallocValidationSuffix(void* p)
+        // Return the AllocType tag associated with the allocated block p.
+        inline AllocType fastMallocMatchValidationType(const void* p)
         {
-            ValidationHeader* header = fastMallocValidationHeader(p);
-            if (header->m_prefix != static_cast<unsigned>(ValidationPrefix))
-                fastMallocMatchFailed(p);
-            
-            return reinterpret_cast<ValidationTag*>(static_cast<char*>(p) + header->m_size);
+            const AllocAlignmentInteger* type = static_cast<const AllocAlignmentInteger*>(p) - 1;
+            return static_cast<AllocType>(*type);
         }
 
-        // Return the AllocType tag associated with the allocated block p.
-        inline AllocType fastMallocMatchValidationType(void* p)
+        // Return the address of the AllocType tag associated with the allocated block p.
+        inline AllocAlignmentInteger* fastMallocMatchValidationValue(void* p)
         {
-            return fastMallocValidationHeader(p)->m_type;
+            return reinterpret_cast<AllocAlignmentInteger*>(static_cast<char*>(p) - sizeof(AllocAlignmentInteger));
         }
 
         // Set the AllocType tag to be associaged with the allocated block p.
         inline void setFastMallocMatchValidationType(void* p, AllocType allocType)
         {
-            fastMallocValidationHeader(p)->m_type = allocType;
+            AllocAlignmentInteger* type = static_cast<AllocAlignmentInteger*>(p) - 1;
+            *type = static_cast<AllocAlignmentInteger>(allocType);
         }
 
+        // Handle a detected alloc/free mismatch. By default this calls CRASH().
+        void fastMallocMatchFailed(void* p);
+
     } // namespace Internal
 
     // This is a higher level function which is used by FastMalloc-using code.
@@ -178,34 +156,16 @@ namespace WTF {
     }
 
     // This is a higher level function which is used by FastMalloc-using code.
-    inline void fastMallocMatchValidateFree(void* p, Internal::AllocType)
+    inline void fastMallocMatchValidateFree(void* p, Internal::AllocType allocType)
     {
         if (!p)
             return;
-    
-        Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(p);
-        if (header->m_prefix != static_cast<unsigned>(Internal::ValidationPrefix))
-            Internal::fastMallocMatchFailed(p);
 
-        if (*Internal::fastMallocValidationSuffix(p) != Internal::ValidationSuffix)
+        if (Internal::fastMallocMatchValidationType(p) != allocType)
             Internal::fastMallocMatchFailed(p);
-
         Internal::setFastMallocMatchValidationType(p, Internal::AllocTypeMalloc);  // Set it to this so that fastFree thinks it's OK.
     }
 
-    inline void fastMallocValidate(void* p)
-    {
-        if (!p)
-            return;
-        
-        Internal::ValidationHeader* header = Internal::fastMallocValidationHeader(p);
-        if (header->m_prefix != static_cast<unsigned>(Internal::ValidationPrefix))
-            Internal::fastMallocMatchFailed(p);
-        
-        if (*Internal::fastMallocValidationSuffix(p) != Internal::ValidationSuffix)
-            Internal::fastMallocMatchFailed(p);
-    }
-
 #else
 
     inline void fastMallocMatchValidateMalloc(void*, Internal::AllocType)
index d1fe119..e40b1a6 100644 (file)
 
 /* fastMalloc match validation allows for runtime verification that
    new is matched by delete, fastMalloc is matched by fastFree, etc. */
-#if !defined(ENABLE_WTF_MALLOC_VALIDATION)
-#ifndef NDEBUG
-#define ENABLE_WTF_MALLOC_VALIDATION 1
-#else
-#define ENABLE_WTF_MALLOC_VALIDATION 0
-#endif
+#if !defined(ENABLE_FAST_MALLOC_MATCH_VALIDATION)
+#define ENABLE_FAST_MALLOC_MATCH_VALIDATION 0
 #endif
 
 #if !defined(ENABLE_ICONDATABASE)