Changeset 221384 in webkit


Ignore:
Timestamp:
Aug 30, 2017 10:46:55 AM (7 years ago)
Author:
fpizlo@apple.com
Message:

Strings need to be in some kind of gigacage
https://bugs.webkit.org/show_bug.cgi?id=174924

Reviewed by Oliver Hunt.
Source/bmalloc:


This adds a StringGigacage.

  • bmalloc/Gigacage.cpp:
  • bmalloc/Gigacage.h:

(Gigacage::name):
(Gigacage::basePtr):
(Gigacage::forEachKind):

  • bmalloc/HeapKind.h:

(bmalloc::isGigacage):
(bmalloc::gigacageKind):
(bmalloc::heapKind):

Source/JavaScriptCore:

  • runtime/JSString.cpp:

(JSC::JSRopeString::resolveRopeToAtomicString const):
(JSC::JSRopeString::resolveRope const):

  • runtime/JSString.h:

(JSC::JSString::create):
(JSC::JSString::createHasOtherOwner):

  • runtime/JSStringBuilder.h:
  • runtime/VM.h:

(JSC::VM::gigacageAuxiliarySpace):

Source/WebCore:

No new tests because no new behavior.

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::normalizeSpaces):

Source/WTF:


This makes all strings allocations come from the string gigacage. Because we expect string allocation
to be a hot path, I created specialized allocation paths for the string gigacage. These paths are
accessible via <wtf/text/StringMalloc.h>. However, those paths are equivalent to saying
Gigacage::malloc and friends with the Gigacage::String kind.

  • WTF.xcodeproj/project.pbxproj:
  • wtf/CMakeLists.txt:
  • wtf/Deque.h:
  • wtf/FastMalloc.cpp:

(WTF::fastFree):

  • wtf/FastMalloc.h:

(WTF::FastMalloc::malloc):
(WTF::FastMalloc::tryMalloc):
(WTF::FastMalloc::realloc):
(WTF::FastMalloc::free):

  • wtf/Forward.h:
  • wtf/Gigacage.cpp:

(Gigacage::tryMalloc):

  • wtf/Gigacage.h:

(Gigacage::name):

  • wtf/Vector.h:

(WTF::VectorBufferBase::allocateBuffer):
(WTF::VectorBufferBase::tryAllocateBuffer):
(WTF::VectorBufferBase::reallocateBuffer):
(WTF::VectorBufferBase::deallocateBuffer):
(WTF::Malloc>::Vector):
(WTF::=):
(WTF::Malloc>::contains const):
(WTF::Malloc>::findMatching const):
(WTF::Malloc>::find const):
(WTF::Malloc>::reverseFind const):
(WTF::Malloc>::appendIfNotContains):
(WTF::Malloc>::fill):
(WTF::Malloc>::appendRange):
(WTF::Malloc>::expandCapacity):
(WTF::Malloc>::tryExpandCapacity):
(WTF::Malloc>::resize):
(WTF::Malloc>::resizeToFit):
(WTF::Malloc>::shrink):
(WTF::Malloc>::grow):
(WTF::Malloc>::asanSetInitialBufferSizeTo):
(WTF::Malloc>::asanSetBufferSizeToFullCapacity):
(WTF::Malloc>::asanBufferSizeWillChangeTo):
(WTF::Malloc>::reserveCapacity):
(WTF::Malloc>::tryReserveCapacity):
(WTF::Malloc>::reserveInitialCapacity):
(WTF::Malloc>::shrinkCapacity):
(WTF::Malloc>::append):
(WTF::Malloc>::tryAppend):
(WTF::Malloc>::constructAndAppend):
(WTF::Malloc>::tryConstructAndAppend):
(WTF::Malloc>::appendSlowCase):
(WTF::Malloc>::constructAndAppendSlowCase):
(WTF::Malloc>::tryConstructAndAppendSlowCase):
(WTF::Malloc>::uncheckedAppend):
(WTF::Malloc>::appendVector):
(WTF::Malloc>::insert):
(WTF::Malloc>::insertVector):
(WTF::Malloc>::remove):
(WTF::Malloc>::removeFirst):
(WTF::Malloc>::removeFirstMatching):
(WTF::Malloc>::removeAll):
(WTF::Malloc>::removeAllMatching):
(WTF::Malloc>::reverse):
(WTF::Malloc>::map const):
(WTF::Malloc>::releaseBuffer):
(WTF::Malloc>::checkConsistency):
(WTF::swap):
(WTF::operator==):
(WTF::operator!=):
(WTF::removeRepeatedElements):
(WTF::minCapacity>::Vector): Deleted.
(WTF::minCapacity>::contains const): Deleted.
(WTF::minCapacity>::findMatching const): Deleted.
(WTF::minCapacity>::find const): Deleted.
(WTF::minCapacity>::reverseFind const): Deleted.
(WTF::minCapacity>::appendIfNotContains): Deleted.
(WTF::minCapacity>::fill): Deleted.
(WTF::minCapacity>::appendRange): Deleted.
(WTF::minCapacity>::expandCapacity): Deleted.
(WTF::minCapacity>::tryExpandCapacity): Deleted.
(WTF::minCapacity>::resize): Deleted.
(WTF::minCapacity>::resizeToFit): Deleted.
(WTF::minCapacity>::shrink): Deleted.
(WTF::minCapacity>::grow): Deleted.
(WTF::minCapacity>::asanSetInitialBufferSizeTo): Deleted.
(WTF::minCapacity>::asanSetBufferSizeToFullCapacity): Deleted.
(WTF::minCapacity>::asanBufferSizeWillChangeTo): Deleted.
(WTF::minCapacity>::reserveCapacity): Deleted.
(WTF::minCapacity>::tryReserveCapacity): Deleted.
(WTF::minCapacity>::reserveInitialCapacity): Deleted.
(WTF::minCapacity>::shrinkCapacity): Deleted.
(WTF::minCapacity>::append): Deleted.
(WTF::minCapacity>::tryAppend): Deleted.
(WTF::minCapacity>::constructAndAppend): Deleted.
(WTF::minCapacity>::tryConstructAndAppend): Deleted.
(WTF::minCapacity>::appendSlowCase): Deleted.
(WTF::minCapacity>::constructAndAppendSlowCase): Deleted.
(WTF::minCapacity>::tryConstructAndAppendSlowCase): Deleted.
(WTF::minCapacity>::uncheckedAppend): Deleted.
(WTF::minCapacity>::appendVector): Deleted.
(WTF::minCapacity>::insert): Deleted.
(WTF::minCapacity>::insertVector): Deleted.
(WTF::minCapacity>::remove): Deleted.
(WTF::minCapacity>::removeFirst): Deleted.
(WTF::minCapacity>::removeFirstMatching): Deleted.
(WTF::minCapacity>::removeAll): Deleted.
(WTF::minCapacity>::removeAllMatching): Deleted.
(WTF::minCapacity>::reverse): Deleted.
(WTF::minCapacity>::map const): Deleted.
(WTF::minCapacity>::releaseBuffer): Deleted.
(WTF::minCapacity>::checkConsistency): Deleted.

  • wtf/text/AtomicStringImpl.h:
  • wtf/text/CString.cpp:

(WTF::CStringBuffer::createUninitialized):

  • wtf/text/CString.h:
  • wtf/text/StringBuffer.h:

(WTF::StringBuffer::StringBuffer):
(WTF::StringBuffer::~StringBuffer):
(WTF::StringBuffer::resize):

  • wtf/text/StringImpl.cpp:

(WTF::StringImpl::~StringImpl):
(WTF::StringImpl::destroy):
(WTF::StringImpl::createUninitializedInternalNonEmpty):
(WTF::StringImpl::reallocateInternal):
(WTF::StringImpl::releaseAssertCaged const):

  • wtf/text/StringImpl.h:

(WTF::StringImpl::createSubstringSharingImpl):
(WTF::StringImpl::tryCreateUninitialized):
(WTF::StringImpl::adopt):
(WTF::StringImpl::bufferOwnership const):
(WTF::StringImpl::assertCaged const):

  • wtf/text/StringMalloc.cpp: Added.

(WTF::tryStringMalloc):
(WTF::stringMalloc):
(WTF::stringRealloc):
(WTF::stringFree):

  • wtf/text/StringMalloc.h: Added.

(WTF::StringMalloc::malloc):
(WTF::StringMalloc::tryMalloc):
(WTF::StringMalloc::realloc):
(WTF::StringMalloc::free):

  • wtf/text/StringVector.h: Added.
  • wtf/text/SymbolImpl.h:
  • wtf/text/UniquedStringImpl.h:
  • wtf/text/WTFString.h:

(WTF::String::adopt):
(WTF::String::assertCaged const):
(WTF::String::releaseAssertCaged const):

Location:
trunk/Source
Files:
3 added
39 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r221358 r221384  
     12017-08-22  Filip Pizlo  <fpizlo@apple.com>
     2
     3        Strings need to be in some kind of gigacage
     4        https://bugs.webkit.org/show_bug.cgi?id=174924
     5
     6        Reviewed by Oliver Hunt.
     7
     8        * runtime/JSString.cpp:
     9        (JSC::JSRopeString::resolveRopeToAtomicString const):
     10        (JSC::JSRopeString::resolveRope const):
     11        * runtime/JSString.h:
     12        (JSC::JSString::create):
     13        (JSC::JSString::createHasOtherOwner):
     14        * runtime/JSStringBuilder.h:
     15        * runtime/VM.h:
     16        (JSC::VM::gigacageAuxiliarySpace):
     17
    1182017-08-30  Oleksandr Skachkov  <gskachkov@gmail.com>
    219
  • trunk/Source/JavaScriptCore/runtime/JSString.cpp

    r217108 r221384  
    179179void JSRopeString::resolveRopeToAtomicString(ExecState* exec) const
    180180{
    181     if (length() > maxLengthForOnStackResolve) {
    182         resolveRope(exec);
    183         m_value = AtomicString(m_value);
    184         setIs8Bit(m_value.impl()->is8Bit());
    185         return;
    186     }
    187 
    188     if (is8Bit()) {
    189         LChar buffer[maxLengthForOnStackResolve];
    190         resolveRopeInternal8(buffer);
    191         m_value = AtomicString(buffer, length());
    192         setIs8Bit(m_value.impl()->is8Bit());
    193     } else {
    194         UChar buffer[maxLengthForOnStackResolve];
    195         resolveRopeInternal16(buffer);
    196         m_value = AtomicString(buffer, length());
    197         setIs8Bit(m_value.impl()->is8Bit());
    198     }
    199 
    200     clearFibers();
    201 
    202     // If we resolved a string that didn't previously exist, notify the heap that we've grown.
    203     if (m_value.impl()->hasOneRef())
    204         Heap::heap(this)->reportExtraMemoryAllocated(m_value.impl()->cost());
     181    [&] () {
     182        if (length() > maxLengthForOnStackResolve) {
     183            resolveRope(exec);
     184            m_value = AtomicString(m_value);
     185            setIs8Bit(m_value.impl()->is8Bit());
     186            return;
     187        }
     188
     189        if (is8Bit()) {
     190            LChar buffer[maxLengthForOnStackResolve];
     191            resolveRopeInternal8(buffer);
     192            m_value = AtomicString(buffer, length());
     193            setIs8Bit(m_value.impl()->is8Bit());
     194        } else {
     195            UChar buffer[maxLengthForOnStackResolve];
     196            resolveRopeInternal16(buffer);
     197            m_value = AtomicString(buffer, length());
     198            setIs8Bit(m_value.impl()->is8Bit());
     199        }
     200
     201        clearFibers();
     202
     203        // If we resolved a string that didn't previously exist, notify the heap that we've grown.
     204        if (m_value.impl()->hasOneRef())
     205            Heap::heap(this)->reportExtraMemoryAllocated(m_value.impl()->cost());
     206    }();
     207   
     208    m_value.releaseAssertCaged();
    205209}
    206210
     
    249253void JSRopeString::resolveRope(ExecState* exec) const
    250254{
    251     ASSERT(isRope());
    252    
    253     if (isSubstring()) {
    254         ASSERT(!substringBase()->isRope());
    255         m_value = substringBase()->m_value.substringSharingImpl(substringOffset(), length());
    256         substringBase().clear();
    257         return;
    258     }
    259    
    260     if (is8Bit()) {
    261         LChar* buffer;
     255    [&] () {
     256        ASSERT(isRope());
     257       
     258        if (isSubstring()) {
     259            ASSERT(!substringBase()->isRope());
     260            m_value = substringBase()->m_value.substringSharingImpl(substringOffset(), length());
     261            substringBase().clear();
     262            return;
     263        }
     264       
     265        if (is8Bit()) {
     266            LChar* buffer;
     267            if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) {
     268                Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost());
     269                m_value = WTFMove(newImpl);
     270            } else {
     271                outOfMemory(exec);
     272                return;
     273            }
     274            resolveRopeInternal8NoSubstring(buffer);
     275            clearFibers();
     276            ASSERT(!isRope());
     277            return;
     278        }
     279       
     280        UChar* buffer;
    262281        if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) {
    263282            Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost());
     
    267286            return;
    268287        }
    269         resolveRopeInternal8NoSubstring(buffer);
     288       
     289        resolveRopeInternal16NoSubstring(buffer);
    270290        clearFibers();
    271291        ASSERT(!isRope());
    272         return;
    273     }
    274 
    275     UChar* buffer;
    276     if (auto newImpl = StringImpl::tryCreateUninitialized(length(), buffer)) {
    277         Heap::heap(this)->reportExtraMemoryAllocated(newImpl->cost());
    278         m_value = WTFMove(newImpl);
    279     } else {
    280         outOfMemory(exec);
    281         return;
    282     }
    283 
    284     resolveRopeInternal16NoSubstring(buffer);
    285     clearFibers();
    286     ASSERT(!isRope());
     292    }();
     293
     294    m_value.releaseAssertCaged();
    287295}
    288296
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r221192 r221384  
    140140    static JSString* create(VM& vm, Ref<StringImpl>&& value)
    141141    {
     142        value->assertCaged();
    142143        unsigned length = value->length();
    143144        size_t cost = value->cost();
     
    148149    static JSString* createHasOtherOwner(VM& vm, Ref<StringImpl>&& value)
    149150    {
     151        value->assertCaged();
    150152        size_t length = value->length();
    151153        JSString* newString = new (NotNull, allocateCell<JSString>(vm.heap)) JSString(vm, WTFMove(value));
  • trunk/Source/JavaScriptCore/runtime/JSStringBuilder.h

    r221192 r221384  
    11/*
    2  * Copyright (C) 2009, 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828#include "ExceptionHelpers.h"
    2929#include "JSString.h"
    30 #include <wtf/Vector.h>
     30#include <wtf/text/StringVector.h>
    3131
    3232namespace JSC {
     
    114114    }
    115115
    116     Vector<LChar, 64, UnsafeVectorOverflow> buffer8;
    117     Vector<UChar, 64, UnsafeVectorOverflow> buffer16;
     116    StringVector<LChar, 64, UnsafeVectorOverflow> buffer8;
     117    StringVector<UChar, 64, UnsafeVectorOverflow> buffer16;
    118118    bool m_okay;
    119119    bool m_is8Bit;
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r221223 r221384  
    309309        case Gigacage::JSValue:
    310310            return jsValueGigacageAuxiliarySpace;
     311        case Gigacage::String:
     312            break;
    311313        }
    312314        RELEASE_ASSERT_NOT_REACHED();
  • trunk/Source/WTF/ChangeLog

    r221330 r221384  
     12017-08-22  Filip Pizlo  <fpizlo@apple.com>
     2
     3        Strings need to be in some kind of gigacage
     4        https://bugs.webkit.org/show_bug.cgi?id=174924
     5
     6        Reviewed by Oliver Hunt.
     7       
     8        This makes all strings allocations come from the string gigacage. Because we expect string allocation
     9        to be a hot path, I created specialized allocation paths for the string gigacage. These paths are
     10        accessible via <wtf/text/StringMalloc.h>. However, those paths are equivalent to saying
     11        Gigacage::malloc and friends with the Gigacage::String kind.
     12
     13        * WTF.xcodeproj/project.pbxproj:
     14        * wtf/CMakeLists.txt:
     15        * wtf/Deque.h:
     16        * wtf/FastMalloc.cpp:
     17        (WTF::fastFree):
     18        * wtf/FastMalloc.h:
     19        (WTF::FastMalloc::malloc):
     20        (WTF::FastMalloc::tryMalloc):
     21        (WTF::FastMalloc::realloc):
     22        (WTF::FastMalloc::free):
     23        * wtf/Forward.h:
     24        * wtf/Gigacage.cpp:
     25        (Gigacage::tryMalloc):
     26        * wtf/Gigacage.h:
     27        (Gigacage::name):
     28        * wtf/Vector.h:
     29        (WTF::VectorBufferBase::allocateBuffer):
     30        (WTF::VectorBufferBase::tryAllocateBuffer):
     31        (WTF::VectorBufferBase::reallocateBuffer):
     32        (WTF::VectorBufferBase::deallocateBuffer):
     33        (WTF::Malloc>::Vector):
     34        (WTF::=):
     35        (WTF::Malloc>::contains const):
     36        (WTF::Malloc>::findMatching const):
     37        (WTF::Malloc>::find const):
     38        (WTF::Malloc>::reverseFind const):
     39        (WTF::Malloc>::appendIfNotContains):
     40        (WTF::Malloc>::fill):
     41        (WTF::Malloc>::appendRange):
     42        (WTF::Malloc>::expandCapacity):
     43        (WTF::Malloc>::tryExpandCapacity):
     44        (WTF::Malloc>::resize):
     45        (WTF::Malloc>::resizeToFit):
     46        (WTF::Malloc>::shrink):
     47        (WTF::Malloc>::grow):
     48        (WTF::Malloc>::asanSetInitialBufferSizeTo):
     49        (WTF::Malloc>::asanSetBufferSizeToFullCapacity):
     50        (WTF::Malloc>::asanBufferSizeWillChangeTo):
     51        (WTF::Malloc>::reserveCapacity):
     52        (WTF::Malloc>::tryReserveCapacity):
     53        (WTF::Malloc>::reserveInitialCapacity):
     54        (WTF::Malloc>::shrinkCapacity):
     55        (WTF::Malloc>::append):
     56        (WTF::Malloc>::tryAppend):
     57        (WTF::Malloc>::constructAndAppend):
     58        (WTF::Malloc>::tryConstructAndAppend):
     59        (WTF::Malloc>::appendSlowCase):
     60        (WTF::Malloc>::constructAndAppendSlowCase):
     61        (WTF::Malloc>::tryConstructAndAppendSlowCase):
     62        (WTF::Malloc>::uncheckedAppend):
     63        (WTF::Malloc>::appendVector):
     64        (WTF::Malloc>::insert):
     65        (WTF::Malloc>::insertVector):
     66        (WTF::Malloc>::remove):
     67        (WTF::Malloc>::removeFirst):
     68        (WTF::Malloc>::removeFirstMatching):
     69        (WTF::Malloc>::removeAll):
     70        (WTF::Malloc>::removeAllMatching):
     71        (WTF::Malloc>::reverse):
     72        (WTF::Malloc>::map const):
     73        (WTF::Malloc>::releaseBuffer):
     74        (WTF::Malloc>::checkConsistency):
     75        (WTF::swap):
     76        (WTF::operator==):
     77        (WTF::operator!=):
     78        (WTF::removeRepeatedElements):
     79        (WTF::minCapacity>::Vector): Deleted.
     80        (WTF::minCapacity>::contains const): Deleted.
     81        (WTF::minCapacity>::findMatching const): Deleted.
     82        (WTF::minCapacity>::find const): Deleted.
     83        (WTF::minCapacity>::reverseFind const): Deleted.
     84        (WTF::minCapacity>::appendIfNotContains): Deleted.
     85        (WTF::minCapacity>::fill): Deleted.
     86        (WTF::minCapacity>::appendRange): Deleted.
     87        (WTF::minCapacity>::expandCapacity): Deleted.
     88        (WTF::minCapacity>::tryExpandCapacity): Deleted.
     89        (WTF::minCapacity>::resize): Deleted.
     90        (WTF::minCapacity>::resizeToFit): Deleted.
     91        (WTF::minCapacity>::shrink): Deleted.
     92        (WTF::minCapacity>::grow): Deleted.
     93        (WTF::minCapacity>::asanSetInitialBufferSizeTo): Deleted.
     94        (WTF::minCapacity>::asanSetBufferSizeToFullCapacity): Deleted.
     95        (WTF::minCapacity>::asanBufferSizeWillChangeTo): Deleted.
     96        (WTF::minCapacity>::reserveCapacity): Deleted.
     97        (WTF::minCapacity>::tryReserveCapacity): Deleted.
     98        (WTF::minCapacity>::reserveInitialCapacity): Deleted.
     99        (WTF::minCapacity>::shrinkCapacity): Deleted.
     100        (WTF::minCapacity>::append): Deleted.
     101        (WTF::minCapacity>::tryAppend): Deleted.
     102        (WTF::minCapacity>::constructAndAppend): Deleted.
     103        (WTF::minCapacity>::tryConstructAndAppend): Deleted.
     104        (WTF::minCapacity>::appendSlowCase): Deleted.
     105        (WTF::minCapacity>::constructAndAppendSlowCase): Deleted.
     106        (WTF::minCapacity>::tryConstructAndAppendSlowCase): Deleted.
     107        (WTF::minCapacity>::uncheckedAppend): Deleted.
     108        (WTF::minCapacity>::appendVector): Deleted.
     109        (WTF::minCapacity>::insert): Deleted.
     110        (WTF::minCapacity>::insertVector): Deleted.
     111        (WTF::minCapacity>::remove): Deleted.
     112        (WTF::minCapacity>::removeFirst): Deleted.
     113        (WTF::minCapacity>::removeFirstMatching): Deleted.
     114        (WTF::minCapacity>::removeAll): Deleted.
     115        (WTF::minCapacity>::removeAllMatching): Deleted.
     116        (WTF::minCapacity>::reverse): Deleted.
     117        (WTF::minCapacity>::map const): Deleted.
     118        (WTF::minCapacity>::releaseBuffer): Deleted.
     119        (WTF::minCapacity>::checkConsistency): Deleted.
     120        * wtf/text/AtomicStringImpl.h:
     121        * wtf/text/CString.cpp:
     122        (WTF::CStringBuffer::createUninitialized):
     123        * wtf/text/CString.h:
     124        * wtf/text/StringBuffer.h:
     125        (WTF::StringBuffer::StringBuffer):
     126        (WTF::StringBuffer::~StringBuffer):
     127        (WTF::StringBuffer::resize):
     128        * wtf/text/StringImpl.cpp:
     129        (WTF::StringImpl::~StringImpl):
     130        (WTF::StringImpl::destroy):
     131        (WTF::StringImpl::createUninitializedInternalNonEmpty):
     132        (WTF::StringImpl::reallocateInternal):
     133        (WTF::StringImpl::releaseAssertCaged const):
     134        * wtf/text/StringImpl.h:
     135        (WTF::StringImpl::createSubstringSharingImpl):
     136        (WTF::StringImpl::tryCreateUninitialized):
     137        (WTF::StringImpl::adopt):
     138        (WTF::StringImpl::bufferOwnership const):
     139        (WTF::StringImpl::assertCaged const):
     140        * wtf/text/StringMalloc.cpp: Added.
     141        (WTF::tryStringMalloc):
     142        (WTF::stringMalloc):
     143        (WTF::stringRealloc):
     144        (WTF::stringFree):
     145        * wtf/text/StringMalloc.h: Added.
     146        (WTF::StringMalloc::malloc):
     147        (WTF::StringMalloc::tryMalloc):
     148        (WTF::StringMalloc::realloc):
     149        (WTF::StringMalloc::free):
     150        * wtf/text/StringVector.h: Added.
     151        * wtf/text/SymbolImpl.h:
     152        * wtf/text/UniquedStringImpl.h:
     153        * wtf/text/WTFString.h:
     154        (WTF::String::adopt):
     155        (WTF::String::assertCaged const):
     156        (WTF::String::releaseAssertCaged const):
     157
    11582017-08-28  Yusuke Suzuki  <utatane.tea@gmail.com>
    2159
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r221330 r221384  
    2222
    2323/* Begin PBXBuildFile section */
     24                0F0F526B1F421FF8004A452C /* StringMalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F0F52691F421FF8004A452C /* StringMalloc.cpp */; };
    2425                0F30BA901E78708E002CA847 /* GlobalVersion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F30BA8A1E78708E002CA847 /* GlobalVersion.cpp */; };
    2526                0F43D8F11DB5ADDC00108FB6 /* AutomaticThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F43D8EF1DB5ADDC00108FB6 /* AutomaticThread.cpp */; };
     
    164165/* Begin PBXFileReference section */
    165166                0F0D85B317234CB100338210 /* NoLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NoLock.h; sourceTree = "<group>"; };
     167                0F0F52691F421FF8004A452C /* StringMalloc.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StringMalloc.cpp; sourceTree = "<group>"; };
     168                0F0F526A1F421FF8004A452C /* StringMalloc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StringMalloc.h; sourceTree = "<group>"; };
    166169                0F0FCDDD1DD167F900CCAB53 /* LockAlgorithm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LockAlgorithm.h; sourceTree = "<group>"; };
    167170                0F2AC5601E89F70C0001EE3F /* Range.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Range.h; sourceTree = "<group>"; };
     
    177180                0F30BA8F1E78708E002CA847 /* LoggingHashTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoggingHashTraits.h; sourceTree = "<group>"; };
    178181                0F31DD701F1308BC0072EB4A /* LockAlgorithmInlines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LockAlgorithmInlines.h; sourceTree = "<group>"; };
     182                0F348C7D1F47AA9D003CFEF2 /* StringVector.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StringVector.h; sourceTree = "<group>"; };
    179183                0F3501631BB258C800F0A2A3 /* WeakRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakRandom.h; sourceTree = "<group>"; };
    180184                0F43D8EF1DB5ADDC00108FB6 /* AutomaticThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutomaticThread.cpp; sourceTree = "<group>"; };
     
    10891093                                A8A47328151A825B004123FF /* StringImpl.cpp */,
    10901094                                A8A47329151A825B004123FF /* StringImpl.h */,
     1095                                0F0F52691F421FF8004A452C /* StringMalloc.cpp */,
     1096                                0F0F526A1F421FF8004A452C /* StringMalloc.h */,
    10911097                                A8A4732A151A825B004123FF /* StringOperators.h */,
     1098                                0F348C7D1F47AA9D003CFEF2 /* StringVector.h */,
    10921099                                93F1993D19D7958D00C2390B /* StringView.cpp */,
    10931100                                1A6EB1DF187D0BD30030126F /* StringView.h */,
     
    13361343                                A8A4739A151A825B004123FF /* CryptographicallyRandomNumber.cpp in Sources */,
    13371344                                E15556F518A0CC18006F48FB /* CryptographicUtilities.cpp in Sources */,
     1345                                0F0F526B1F421FF8004A452C /* StringMalloc.cpp in Sources */,
    13381346                                A8A47439151A825B004123FF /* CString.cpp in Sources */,
    13391347                                A8A4739C151A825B004123FF /* CurrentTime.cpp in Sources */,
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r221330 r221384  
    183183    text/StringHash.h
    184184    text/StringImpl.h
     185    text/StringMalloc.h
     186    text/StringVector.h
    185187    text/StringView.h
    186188    text/SymbolImpl.h
     
    287289    text/StringBuilderJSON.cpp
    288290    text/StringImpl.cpp
     291    text/StringMalloc.cpp
    289292    text/StringView.cpp
    290293    text/SymbolImpl.cpp
  • trunk/Source/WTF/wtf/Deque.h

    r219274 r221384  
    114114    friend class DequeIteratorBase<T, inlineCapacity>;
    115115
    116     typedef VectorBuffer<T, inlineCapacity> Buffer;
     116    typedef VectorBuffer<T, inlineCapacity, FastMalloc> Buffer;
    117117    typedef VectorTypeOperations<T> TypeOperations;
    118118    typedef DequeIteratorBase<T, inlineCapacity> IteratorBase;
  • trunk/Source/WTF/wtf/FastMalloc.h

    r219491 r221384  
    130130template<typename T, typename U> inline bool operator!=(const FastAllocator<T>&, const FastAllocator<U>&) { return false; }
    131131
     132struct FastMalloc {
     133    static void* malloc(size_t size) { return fastMalloc(size); }
     134   
     135    static void* tryMalloc(size_t size)
     136    {
     137        auto result = tryFastMalloc(size);
     138        void* realResult;
     139        if (result.getValue(realResult))
     140            return realResult;
     141        return nullptr;
     142    }
     143   
     144    static void* realloc(void* p, size_t size) { return fastRealloc(p, size); }
     145   
     146    static void free(void* p) { fastFree(p); }
     147};
    132148
    133149} // namespace WTF
     
    137153#endif
    138154
     155using WTF::FastAllocator;
     156using WTF::FastMalloc;
    139157using WTF::isFastMallocEnabled;
    140158using WTF::fastCalloc;
     
    152170using WTF::fastAlignedMalloc;
    153171using WTF::fastAlignedFree;
    154 using WTF::FastAllocator;
    155172
    156173#if COMPILER(GCC_OR_CLANG) && OS(DARWIN)
  • trunk/Source/WTF/wtf/Forward.h

    r216839 r221384  
    3838
    3939template<typename... T> class Variant;
    40 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> class Vector;
     40template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc> class Vector;
    4141
    4242class AtomicString;
  • trunk/Source/WTF/wtf/Gigacage.cpp

    r220712 r221384  
    4141void* tryMalloc(Kind, size_t size)
    4242{
    43     auto result = tryFastMalloc(size);
    44     void* realResult;
    45     if (result.getValue(realResult))
    46         return realResult;
    47     return nullptr;
     43    return FastMalloc::tryMalloc(size);
    4844}
    4945
  • trunk/Source/WTF/wtf/Gigacage.h

    r221211 r221384  
    4141enum Kind {
    4242    Primitive,
    43     JSValue
     43    JSValue,
     44    String
    4445};
    4546
     
    6465    case JSValue:
    6566        return "JSValue";
     67    case String:
     68        return "String";
    6669    }
    6770    RELEASE_ASSERT_NOT_REACHED();
  • trunk/Source/WTF/wtf/Vector.h

    r219702 r221384  
    11/*
    2  *  Copyright (C) 2005, 2006, 2007, 2008, 2014 Apple Inc. All rights reserved.
     2 *  Copyright (C) 2005-2017 Apple Inc. All rights reserved.
    33 *
    44 *  This library is free software; you can redistribute it and/or
     
    255255};
    256256
    257 template<typename T>
     257template<typename T, typename Malloc>
    258258class VectorBufferBase {
    259259    WTF_MAKE_NONCOPYABLE(VectorBufferBase);
     
    266266        size_t sizeToAllocate = newCapacity * sizeof(T);
    267267        m_capacity = sizeToAllocate / sizeof(T);
    268         m_buffer = static_cast<T*>(fastMalloc(sizeToAllocate));
     268        m_buffer = static_cast<T*>(Malloc::malloc(sizeToAllocate));
    269269    }
    270270
     
    276276
    277277        size_t sizeToAllocate = newCapacity * sizeof(T);
    278         T* newBuffer;
    279         if (tryFastMalloc(sizeToAllocate).getValue(newBuffer)) {
    280             m_capacity = sizeToAllocate / sizeof(T);
    281             m_buffer = newBuffer;
    282             return true;
    283         }
    284         return false;
     278        T* newBuffer = static_cast<T*>(Malloc::tryMalloc(sizeToAllocate));
     279        if (!newBuffer)
     280            return false;
     281        m_capacity = sizeToAllocate / sizeof(T);
     282        m_buffer = newBuffer;
     283        return true;
    285284    }
    286285
     
    297296        size_t sizeToAllocate = newCapacity * sizeof(T);
    298297        m_capacity = sizeToAllocate / sizeof(T);
    299         m_buffer = static_cast<T*>(fastRealloc(m_buffer, sizeToAllocate));
     298        m_buffer = static_cast<T*>(Malloc::realloc(m_buffer, sizeToAllocate));
    300299    }
    301300
     
    310309        }
    311310
    312         fastFree(bufferToDeallocate);
     311        Malloc::free(bufferToDeallocate);
    313312    }
    314313
     
    351350};
    352351
    353 template<typename T, size_t inlineCapacity>
     352template<typename T, size_t inlineCapacity, typename Malloc>
    354353class VectorBuffer;
    355354
    356 template<typename T>
    357 class VectorBuffer<T, 0> : private VectorBufferBase<T> {
     355template<typename T, typename Malloc>
     356class VectorBuffer<T, 0, Malloc> : private VectorBufferBase<T, Malloc> {
    358357private:
    359     typedef VectorBufferBase<T> Base;
     358    typedef VectorBufferBase<T, Malloc> Base;
    360359public:
    361360    VectorBuffer()
     
    377376    }
    378377   
    379     void swap(VectorBuffer<T, 0>& other, size_t, size_t)
     378    void swap(VectorBuffer<T, 0, Malloc>& other, size_t, size_t)
    380379    {
    381380        std::swap(m_buffer, other.m_buffer);
     
    412411};
    413412
    414 template<typename T, size_t inlineCapacity>
    415 class VectorBuffer : private VectorBufferBase<T> {
     413template<typename T, size_t inlineCapacity, typename Malloc>
     414class VectorBuffer : private VectorBufferBase<T, Malloc> {
    416415    WTF_MAKE_NONCOPYABLE(VectorBuffer);
    417416private:
    418     typedef VectorBufferBase<T> Base;
     417    typedef VectorBufferBase<T, Malloc> Base;
    419418public:
    420419    VectorBuffer()
     
    577576};
    578577
    579 template<typename T, size_t inlineCapacity = 0, typename OverflowHandler = CrashOnOverflow, size_t minCapacity = 16>
    580 class Vector : private VectorBuffer<T, inlineCapacity> {
     578template<typename T, size_t inlineCapacity = 0, typename OverflowHandler = CrashOnOverflow, size_t minCapacity = 16, typename Malloc = FastMalloc>
     579class Vector : private VectorBuffer<T, inlineCapacity, Malloc> {
    581580    WTF_MAKE_FAST_ALLOCATED;
    582581private:
    583     typedef VectorBuffer<T, inlineCapacity> Base;
     582    typedef VectorBuffer<T, inlineCapacity, Malloc> Base;
    584583    typedef VectorTypeOperations<T> TypeOperations;
    585584
     
    634633
    635634    Vector(const Vector&);
    636     template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity>
    637     explicit Vector(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity>&);
     635    template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity, typename OtherMalloc>
     636    explicit Vector(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity, OtherMalloc>&);
    638637
    639638    Vector& operator=(const Vector&);
    640     template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity>
    641     Vector& operator=(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity>&);
     639    template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity, typename OtherMalloc>
     640    Vector& operator=(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity, OtherMalloc>&);
    642641
    643642    Vector(Vector&&);
     
    815814};
    816815
    817 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    818 Vector<T, inlineCapacity, OverflowHandler, minCapacity>::Vector(const Vector& other)
     816template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     817Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::Vector(const Vector& other)
    819818    : Base(other.capacity(), other.size())
    820819{
     
    825824}
    826825
    827 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    828 template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity>
    829 Vector<T, inlineCapacity, OverflowHandler, minCapacity>::Vector(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity>& other)
     826template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     827template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity, typename OtherMalloc>
     828Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::Vector(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity, OtherMalloc>& other)
    830829    : Base(other.capacity(), other.size())
    831830{
     
    836835}
    837836
    838 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    839 Vector<T, inlineCapacity, OverflowHandler, minCapacity>& Vector<T, inlineCapacity, OverflowHandler, minCapacity>::operator=(const Vector<T, inlineCapacity, OverflowHandler, minCapacity>& other)
     837template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     838Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::operator=(const Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& other)
    840839{
    841840    if (&other == this)
     
    861860inline bool typelessPointersAreEqual(const void* a, const void* b) { return a == b; }
    862861
    863 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    864 template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity>
    865 Vector<T, inlineCapacity, OverflowHandler, minCapacity>& Vector<T, inlineCapacity, OverflowHandler, minCapacity>::operator=(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity>& other)
     862template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     863template<size_t otherCapacity, typename otherOverflowBehaviour, size_t otherMinimumCapacity, typename OtherMalloc>
     864Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::operator=(const Vector<T, otherCapacity, otherOverflowBehaviour, otherMinimumCapacity, OtherMalloc>& other)
    866865{
    867866    // If the inline capacities match, we should call the more specific
     
    887886}
    888887
    889 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    890 inline Vector<T, inlineCapacity, OverflowHandler, minCapacity>::Vector(Vector<T, inlineCapacity, OverflowHandler, minCapacity>&& other)
     888template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     889inline Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::Vector(Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>&& other)
    891890{
    892891    swap(other);
    893892}
    894893
    895 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    896 inline Vector<T, inlineCapacity, OverflowHandler, minCapacity>& Vector<T, inlineCapacity, OverflowHandler, minCapacity>::operator=(Vector<T, inlineCapacity, OverflowHandler, minCapacity>&& other)
     894template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     895inline Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::operator=(Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>&& other)
    897896{
    898897    swap(other);
     
    900899}
    901900
    902 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     901template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    903902template<typename U>
    904 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::contains(const U& value) const
     903bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::contains(const U& value) const
    905904{
    906905    return find(value) != notFound;
    907906}
    908907
    909 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     908template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    910909template<typename MatchFunction>
    911 size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity>::findMatching(const MatchFunction& matches) const
     910size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::findMatching(const MatchFunction& matches) const
    912911{
    913912    for (size_t i = 0; i < size(); ++i) {
     
    918917}
    919918
    920 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     919template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    921920template<typename U>
    922 size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity>::find(const U& value) const
     921size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::find(const U& value) const
    923922{
    924923    return findMatching([&](auto& item) {
     
    927926}
    928927
    929 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     928template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    930929template<typename U>
    931 size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity>::reverseFind(const U& value) const
     930size_t Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::reverseFind(const U& value) const
    932931{
    933932    for (size_t i = 1; i <= size(); ++i) {
     
    939938}
    940939
    941 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     940template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    942941template<typename U>
    943 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::appendIfNotContains(const U& value)
     942bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendIfNotContains(const U& value)
    944943{
    945944    if (contains(value))
     
    949948}
    950949
    951 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    952 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::fill(const T& val, size_t newSize)
     950template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     951void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::fill(const T& val, size_t newSize)
    953952{
    954953    if (size() > newSize)
     
    967966}
    968967
    969 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     968template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    970969template<typename Iterator>
    971 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::appendRange(Iterator start, Iterator end)
     970void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendRange(Iterator start, Iterator end)
    972971{
    973972    for (Iterator it = start; it != end; ++it)
     
    975974}
    976975
    977 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    978 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::expandCapacity(size_t newMinCapacity)
     976template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     977void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::expandCapacity(size_t newMinCapacity)
    979978{
    980979    reserveCapacity(std::max(newMinCapacity, std::max(static_cast<size_t>(minCapacity), capacity() + capacity() / 4 + 1)));
    981980}
    982981
    983 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    984 T* Vector<T, inlineCapacity, OverflowHandler, minCapacity>::expandCapacity(size_t newMinCapacity, T* ptr)
     982template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     983T* Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::expandCapacity(size_t newMinCapacity, T* ptr)
    985984{
    986985    if (ptr < begin() || ptr >= end()) {
     
    993992}
    994993
    995 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    996 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::tryExpandCapacity(size_t newMinCapacity)
     994template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     995bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryExpandCapacity(size_t newMinCapacity)
    997996{
    998997    return tryReserveCapacity(std::max(newMinCapacity, std::max(static_cast<size_t>(minCapacity), capacity() + capacity() / 4 + 1)));
    999998}
    1000999
    1001 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1002 const T* Vector<T, inlineCapacity, OverflowHandler, minCapacity>::tryExpandCapacity(size_t newMinCapacity, const T* ptr)
     1000template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1001const T* Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryExpandCapacity(size_t newMinCapacity, const T* ptr)
    10031002{
    10041003    if (ptr < begin() || ptr >= end()) {
     
    10131012}
    10141013
    1015 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U>
    1016 inline U* Vector<T, inlineCapacity, OverflowHandler, minCapacity>::expandCapacity(size_t newMinCapacity, U* ptr)
     1014template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1015template<typename U>
     1016inline U* Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::expandCapacity(size_t newMinCapacity, U* ptr)
    10171017{
    10181018    expandCapacity(newMinCapacity);
     
    10201020}
    10211021
    1022 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1023 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::resize(size_t size)
     1022template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1023inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::resize(size_t size)
    10241024{
    10251025    if (size <= m_size) {
     
    10371037}
    10381038
    1039 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1040 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::resizeToFit(size_t size)
     1039template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1040void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::resizeToFit(size_t size)
    10411041{
    10421042    reserveCapacity(size);
     
    10441044}
    10451045
    1046 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1047 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::shrink(size_t size)
     1046template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1047void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::shrink(size_t size)
    10481048{
    10491049    ASSERT(size <= m_size);
     
    10531053}
    10541054
    1055 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1056 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::grow(size_t size)
     1055template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1056void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::grow(size_t size)
    10571057{
    10581058    ASSERT(size >= m_size);
     
    10651065}
    10661066
    1067 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1068 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::asanSetInitialBufferSizeTo(size_t size)
     1067template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1068inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::asanSetInitialBufferSizeTo(size_t size)
    10691069{
    10701070#if ASAN_ENABLED
     
    10811081}
    10821082
    1083 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1084 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::asanSetBufferSizeToFullCapacity(size_t size)
     1083template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1084inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::asanSetBufferSizeToFullCapacity(size_t size)
    10851085{
    10861086#if ASAN_ENABLED
     
    10951095}
    10961096
    1097 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1098 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::asanBufferSizeWillChangeTo(size_t newSize)
     1097template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1098inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::asanBufferSizeWillChangeTo(size_t newSize)
    10991099{
    11001100#if ASAN_ENABLED
     
    11091109}
    11101110
    1111 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1112 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::reserveCapacity(size_t newCapacity)
     1111template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1112void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::reserveCapacity(size_t newCapacity)
    11131113{
    11141114    if (newCapacity <= capacity())
     
    11281128}
    11291129
    1130 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1131 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::tryReserveCapacity(size_t newCapacity)
     1130template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1131bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryReserveCapacity(size_t newCapacity)
    11321132{
    11331133    if (newCapacity <= capacity())
     
    11511151}
    11521152
    1153 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1154 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::reserveInitialCapacity(size_t initialCapacity)
     1153template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1154inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::reserveInitialCapacity(size_t initialCapacity)
    11551155{
    11561156    ASSERT(!m_size);
     
    11601160}
    11611161
    1162 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1163 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::shrinkCapacity(size_t newCapacity)
     1162template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1163void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::shrinkCapacity(size_t newCapacity)
    11641164{
    11651165    if (newCapacity >= capacity())
     
    11911191}
    11921192
    1193 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U>
    1194 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::append(const U* data, size_t dataSize)
     1193template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1194template<typename U>
     1195void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::append(const U* data, size_t dataSize)
    11951196{
    11961197    size_t newSize = m_size + dataSize;
     
    12071208}
    12081209
    1209 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U>
    1210 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::tryAppend(const U* data, size_t dataSize)
     1210template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1211template<typename U>
     1212bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryAppend(const U* data, size_t dataSize)
    12111213{
    12121214    size_t newSize = m_size + dataSize;
     
    12261228}
    12271229
    1228 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U>
    1229 ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::append(U&& value)
     1230template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1231template<typename U>
     1232ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::append(U&& value)
    12301233{
    12311234    if (size() != capacity()) {
     
    12391242}
    12401243
    1241 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename... Args>
    1242 ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::constructAndAppend(Args&&... args)
     1244template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1245template<typename... Args>
     1246ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::constructAndAppend(Args&&... args)
    12431247{
    12441248    if (size() != capacity()) {
     
    12521256}
    12531257
    1254 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename... Args>
    1255 ALWAYS_INLINE bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::tryConstructAndAppend(Args&&... args)
     1258template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1259template<typename... Args>
     1260ALWAYS_INLINE bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryConstructAndAppend(Args&&... args)
    12561261{
    12571262    if (size() != capacity()) {
     
    12651270}
    12661271
    1267 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U>
    1268 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::appendSlowCase(U&& value)
     1272template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1273template<typename U>
     1274void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendSlowCase(U&& value)
    12691275{
    12701276    ASSERT(size() == capacity());
     
    12791285}
    12801286
    1281 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename... Args>
    1282 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::constructAndAppendSlowCase(Args&&... args)
     1287template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1288template<typename... Args>
     1289void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::constructAndAppendSlowCase(Args&&... args)
    12831290{
    12841291    ASSERT(size() == capacity());
     
    12921299}
    12931300
    1294 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename... Args>
    1295 bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::tryConstructAndAppendSlowCase(Args&&... args)
     1301template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1302template<typename... Args>
     1303bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::tryConstructAndAppendSlowCase(Args&&... args)
    12961304{
    12971305    ASSERT(size() == capacity());
     
    13101318// vector's capacity is large enough for the append to succeed.
    13111319
    1312 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U>
    1313 ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::uncheckedAppend(U&& value)
     1320template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1321template<typename U>
     1322ALWAYS_INLINE void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::uncheckedAppend(U&& value)
    13141323{
    13151324    ASSERT(size() < capacity());
     
    13221331}
    13231332
    1324 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U, size_t otherCapacity>
    1325 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::appendVector(const Vector<U, otherCapacity>& val)
     1333template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1334template<typename U, size_t otherCapacity>
     1335inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::appendVector(const Vector<U, otherCapacity>& val)
    13261336{
    13271337    append(val.begin(), val.size());
    13281338}
    13291339
    1330 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U>
    1331 void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::insert(size_t position, const U* data, size_t dataSize)
     1340template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1341template<typename U>
     1342void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::insert(size_t position, const U* data, size_t dataSize)
    13321343{
    13331344    ASSERT_WITH_SECURITY_IMPLICATION(position <= size());
     
    13461357}
    13471358 
    1348 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U>
    1349 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::insert(size_t position, U&& value)
     1359template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1360template<typename U>
     1361inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::insert(size_t position, U&& value)
    13501362{
    13511363    ASSERT_WITH_SECURITY_IMPLICATION(position <= size());
     
    13651377}
    13661378
    1367 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename U, size_t c>
    1368 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::insertVector(size_t position, const Vector<U, c>& val)
     1379template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1380template<typename U, size_t c>
     1381inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::insertVector(size_t position, const Vector<U, c>& val)
    13691382{
    13701383    insert(position, val.begin(), val.size());
    13711384}
    13721385
    1373 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1374 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::remove(size_t position)
     1386template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1387inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::remove(size_t position)
    13751388{
    13761389    ASSERT_WITH_SECURITY_IMPLICATION(position < size());
     
    13821395}
    13831396
    1384 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1385 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::remove(size_t position, size_t length)
     1397template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1398inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::remove(size_t position, size_t length)
    13861399{
    13871400    ASSERT_WITH_SECURITY_IMPLICATION(position <= size());
     
    13951408}
    13961409
    1397 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     1410template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    13981411template<typename U>
    1399 inline bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::removeFirst(const U& value)
     1412inline bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::removeFirst(const U& value)
    14001413{
    14011414    return removeFirstMatching([&value] (const T& current) {
     
    14041417}
    14051418
    1406 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     1419template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    14071420template<typename MatchFunction>
    1408 inline bool Vector<T, inlineCapacity, OverflowHandler, minCapacity>::removeFirstMatching(const MatchFunction& matches, size_t startIndex)
     1421inline bool Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::removeFirstMatching(const MatchFunction& matches, size_t startIndex)
    14091422{
    14101423    for (size_t i = startIndex; i < size(); ++i) {
     
    14171430}
    14181431
    1419 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     1432template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    14201433template<typename U>
    1421 inline unsigned Vector<T, inlineCapacity, OverflowHandler, minCapacity>::removeAll(const U& value)
     1434inline unsigned Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::removeAll(const U& value)
    14221435{
    14231436    return removeAllMatching([&value] (const T& current) {
     
    14261439}
    14271440
    1428 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     1441template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
    14291442template<typename MatchFunction>
    1430 inline unsigned Vector<T, inlineCapacity, OverflowHandler, minCapacity>::removeAllMatching(const MatchFunction& matches, size_t startIndex)
     1443inline unsigned Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::removeAllMatching(const MatchFunction& matches, size_t startIndex)
    14311444{
    14321445    iterator holeBegin = end();
     
    14531466}
    14541467
    1455 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1456 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::reverse()
     1468template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1469inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::reverse()
    14571470{
    14581471    for (size_t i = 0; i < m_size / 2; ++i)
     
    14601473}
    14611474
    1462 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename MapFunction, typename R>
    1463 inline Vector<R> Vector<T, inlineCapacity, OverflowHandler, minCapacity>::map(MapFunction mapFunction) const
     1475template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1476template<typename MapFunction, typename R>
     1477inline Vector<R> Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::map(MapFunction mapFunction) const
    14641478{
    14651479    Vector<R> result;
     
    14701484}
    14711485
    1472 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1473 inline MallocPtr<T> Vector<T, inlineCapacity, OverflowHandler, minCapacity>::releaseBuffer()
     1486template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1487inline MallocPtr<T> Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::releaseBuffer()
    14741488{
    14751489    // FIXME: Find a way to preserve annotations on the returned buffer.
     
    14841498        // we create a brand new buffer so the caller always gets one.
    14851499        size_t bytes = m_size * sizeof(T);
    1486         buffer = adoptMallocPtr(static_cast<T*>(fastMalloc(bytes)));
     1500        buffer = adoptMallocPtr(static_cast<T*>(Malloc::malloc(bytes)));
    14871501        memcpy(buffer.get(), data(), bytes);
    14881502    }
     
    14921506}
    14931507
    1494 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1495 inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::checkConsistency()
     1508template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1509inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>::checkConsistency()
    14961510{
    14971511#if !ASSERT_DISABLED
     
    15011515}
    15021516
    1503 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1504 inline void swap(Vector<T, inlineCapacity, OverflowHandler, minCapacity>& a, Vector<T, inlineCapacity, OverflowHandler, minCapacity>& b)
     1517template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1518inline void swap(Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& a, Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& b)
    15051519{
    15061520    a.swap(b);
    15071521}
    15081522
    1509 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1510 bool operator==(const Vector<T, inlineCapacity, OverflowHandler, minCapacity>& a, const Vector<T, inlineCapacity, OverflowHandler, minCapacity>& b)
     1523template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1524bool operator==(const Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& a, const Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& b)
    15111525{
    15121526    if (a.size() != b.size())
     
    15161530}
    15171531
    1518 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1519 inline bool operator!=(const Vector<T, inlineCapacity, OverflowHandler, minCapacity>& a, const Vector<T, inlineCapacity, OverflowHandler, minCapacity>& b)
     1532template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1533inline bool operator!=(const Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& a, const Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& b)
    15201534{
    15211535    return !(a == b);
     
    15411555}
    15421556
    1543 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
    1544 size_t removeRepeatedElements(Vector<T, inlineCapacity, OverflowHandler, minCapacity>& vector)
     1557template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity, typename Malloc>
     1558size_t removeRepeatedElements(Vector<T, inlineCapacity, OverflowHandler, minCapacity, Malloc>& vector)
    15451559{
    15461560    return removeRepeatedElements(vector, [] (T& a, T& b) { return a == b; });
  • trunk/Source/WTF/wtf/text/AtomicStringImpl.h

    r219347 r221384  
    104104// AtomicStringImpls created from StaticStringImpl will ASSERT
    105105// in the generic ValueCheck<T>::checkConsistency
    106 // as they are not allocated by fastMalloc.
     106// as they are not allocated by StringMalloc.
    107107// We don't currently have any way to detect that case
    108108// so we ignore the consistency check for all AtomicStringImpls*.
  • trunk/Source/WTF/wtf/text/CString.cpp

    r201782 r221384  
    11/*
    2  * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2003-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030#include <string.h>
    3131#include <wtf/Hasher.h>
     32#include <wtf/text/StringMalloc.h>
    3233
    3334namespace WTF {
     
    3940    // The +1 is for the terminating null character.
    4041    size_t size = sizeof(CStringBuffer) + length + 1;
    41     CStringBuffer* stringBuffer = static_cast<CStringBuffer*>(fastMalloc(size));
     42    CStringBuffer* stringBuffer = static_cast<CStringBuffer*>(stringMalloc(size));
    4243    return adoptRef(*new (NotNull, stringBuffer) CStringBuffer(length));
    4344}
  • trunk/Source/WTF/wtf/text/CString.h

    r201782 r221384  
    11/*
    2  * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2003-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3131#include <wtf/Ref.h>
    3232#include <wtf/RefCounted.h>
     33#include <wtf/text/StringMalloc.h>
    3334
    3435namespace WTF {
     
    3738// The data is implicitly allocated 1 character longer than length(), as it is zero-terminated.
    3839class CStringBuffer : public RefCounted<CStringBuffer> {
     40    WTF_MAKE_STRING_ALLOCATED;
    3941public:
    4042    const char* data() { return mutableData(); }
  • trunk/Source/WTF/wtf/text/StringBuffer.h

    r163310 r221384  
    3131
    3232#include <wtf/Assertions.h>
     33#include <wtf/text/StringMalloc.h>
    3334#include <limits>
    3435#include <unicode/utypes.h>
     
    4243    explicit StringBuffer(unsigned length)
    4344        : m_length(length)
    44         , m_data(m_length ? static_cast<CharType*>(fastMalloc((Checked<size_t>(m_length) * sizeof(CharType)).unsafeGet())) : nullptr)
     45        , m_data(m_length ? static_cast<CharType*>(stringMalloc((Checked<size_t>(m_length) * sizeof(CharType)).unsafeGet())) : nullptr)
    4546    {
    4647    }
     
    4849    ~StringBuffer()
    4950    {
    50         fastFree(m_data);
     51        stringFree(m_data);
    5152    }
    5253
     
    6263            if (newLength > std::numeric_limits<unsigned>::max() / sizeof(UChar))
    6364                CRASH();
    64             m_data = static_cast<UChar*>(fastRealloc(m_data, newLength * sizeof(UChar)));
     65            m_data = static_cast<UChar*>(stringRealloc(m_data, newLength * sizeof(UChar)));
    6566        }
    6667        m_length = newLength;
  • trunk/Source/WTF/wtf/text/StringImpl.cpp

    r219237 r221384  
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    44 *           (C) 2001 Dirk Mueller ( mueller@kde.org )
    5  * Copyright (C) 2003-2009, 2013-2016 Apple Inc. All rights reserved.
     5 * Copyright (C) 2003-2017 Apple Inc. All rights reserved.
    66 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
    77 *
     
    2929#include "StringBuffer.h"
    3030#include "StringHash.h"
     31#include <wtf/Gigacage.h>
    3132#include <wtf/ProcessID.h>
    3233#include <wtf/StdLibExtras.h>
    3334#include <wtf/text/CString.h>
     35#include <wtf/text/StringMalloc.h>
    3436#include <wtf/text/StringView.h>
    3537#include <wtf/text/SymbolImpl.h>
     
    130132        // We use m_data8, but since it is a union with m_data16 this works either way.
    131133        ASSERT(m_data8);
    132         fastFree(const_cast<LChar*>(m_data8));
     134        stringFree(const_cast<LChar*>(m_data8));
    133135        return;
    134136    }
     
    142144{
    143145    stringImpl->~StringImpl();
    144     fastFree(stringImpl);
     146    stringFree(stringImpl);
    145147}
    146148
     
    193195    if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(CharType)))
    194196        CRASH();
    195     StringImpl* string = static_cast<StringImpl*>(fastMalloc(allocationSize<CharType>(length)));
     197    StringImpl* string = static_cast<StringImpl*>(stringMalloc(allocationSize<CharType>(length)));
    196198
    197199    data = string->tailPointer<CharType>();
     
    220222    }
    221223
    222     // Same as createUninitialized() except here we use fastRealloc.
     224    // Same as createUninitialized() except here we use stringRealloc.
    223225    if (length > ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(CharType)))
    224226        CRASH();
    225227
    226228    originalString->~StringImpl();
    227     auto* string = static_cast<StringImpl*>(fastRealloc(&originalString.leakRef(), allocationSize<CharType>(length)));
     229    auto* string = static_cast<StringImpl*>(stringRealloc(&originalString.leakRef(), allocationSize<CharType>(length)));
    228230
    229231    data = string->tailPointer<CharType>();
     
    21782180}
    21792181
     2182void StringImpl::releaseAssertCaged() const
     2183{
     2184    if (isStatic())
     2185        return;
     2186    RELEASE_ASSERT(!GIGACAGE_ENABLED || Gigacage::isCaged(Gigacage::String, this));
     2187    if (bufferOwnership() != BufferOwned)
     2188        return;
     2189    RELEASE_ASSERT(!GIGACAGE_ENABLED || Gigacage::isCaged(Gigacage::String, m_data8));
     2190}
     2191
    21802192} // namespace WTF
  • trunk/Source/WTF/wtf/text/StringImpl.h

    r220053 r221384  
    3636#include <wtf/text/ConversionMode.h>
    3737#include <wtf/text/StringCommon.h>
     38#include <wtf/text/StringMalloc.h>
     39#include <wtf/text/StringVector.h>
    3840
    3941#if USE(CF)
     
    179181
    180182class StringImpl : private StringImplShape {
    181     WTF_MAKE_NONCOPYABLE(StringImpl); WTF_MAKE_FAST_ALLOCATED;
     183    WTF_MAKE_NONCOPYABLE(StringImpl); WTF_MAKE_STRING_ALLOCATED;
    182184    friend struct WTF::CStringTranslator;
    183185    template<typename CharacterType> friend struct WTF::HashAndCharactersTranslator;
     
    194196    friend class RegisteredSymbolImpl;
    195197   
    196 private:
     198public:
    197199    enum BufferOwnership {
    198200        BufferInternal,
     
    202204
    203205    // The bottom 6 bits in the hash are flags.
    204 public:
    205206    static constexpr const unsigned s_flagCount = 6;
    206207private:
     
    338339
    339340        // We allocate a buffer that contains both the StringImpl struct as well as the pointer to the owner string.
    340         auto* stringImpl = static_cast<StringImpl*>(fastMalloc(allocationSize<StringImpl*>(1)));
     341        auto* stringImpl = static_cast<StringImpl*>(stringMalloc(allocationSize<StringImpl*>(1)));
    341342        if (rep.is8Bit())
    342343            return adoptRef(*new (NotNull, stringImpl) StringImpl(rep.m_data8 + offset, length, *ownerRep));
     
    373374            return nullptr;
    374375        }
    375         StringImpl* resultImpl;
    376         if (!tryFastMalloc(allocationSize<T>(length)).getValue(resultImpl)) {
     376        StringImpl* resultImpl = static_cast<StringImpl*>(tryStringMalloc(allocationSize<T>(length)));
     377        if (!resultImpl) {
    377378            output = nullptr;
    378379            return nullptr;
     
    396397    static unsigned dataOffset() { return OBJECT_OFFSETOF(StringImpl, m_data8); }
    397398
    398     template<typename CharType, size_t inlineCapacity, typename OverflowHandler>
    399     static Ref<StringImpl> adopt(Vector<CharType, inlineCapacity, OverflowHandler>&& vector)
     399    template<typename CharType, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     400    static Ref<StringImpl> adopt(StringVector<CharType, inlineCapacity, OverflowHandler, minCapacity>&& vector)
    400401    {
    401402        if (size_t size = vector.size()) {
     
    758759#endif
    759760
     761    BufferOwnership bufferOwnership() const { return static_cast<BufferOwnership>(m_hashAndFlags & s_hashMaskBufferOwnership); }
     762   
     763    void assertCaged() const
     764    {
     765        if (!ASSERT_DISABLED)
     766            releaseAssertCaged();
     767    }
     768   
     769    WTF_EXPORT_PRIVATE void releaseAssertCaged() const;
     770
    760771protected:
    761772    ~StringImpl();
     
    847858    template<CaseConvertType type, typename CharacterType> static Ref<StringImpl> convertASCIICase(StringImpl&, const CharacterType*, unsigned);
    848859
    849     BufferOwnership bufferOwnership() const { return static_cast<BufferOwnership>(m_hashAndFlags & s_hashMaskBufferOwnership); }
    850860    template <class UCharPredicate> Ref<StringImpl> stripMatchedCharacters(UCharPredicate);
    851861    template <typename CharType, class UCharPredicate> Ref<StringImpl> simplifyMatchedCharactersToSpace(UCharPredicate);
     
    882892// StringImpls created from StaticStringImpl will ASSERT
    883893// in the generic ValueCheck<T>::checkConsistency
    884 // as they are not allocated by fastMalloc.
     894// as they are not allocated by stringMalloc.
    885895// We don't currently have any way to detect that case
    886896// so we ignore the consistency check for all StringImpl*.
  • trunk/Source/WTF/wtf/text/SymbolImpl.h

    r220053 r221384  
    203203// SymbolImpls created from StaticStringImpl will ASSERT
    204204// in the generic ValueCheck<T>::checkConsistency
    205 // as they are not allocated by fastMalloc.
     205// as they are not allocated by stringMalloc.
    206206// We don't currently have any way to detect that case
    207207// so we ignore the consistency check for all SymbolImpls*.
  • trunk/Source/WTF/wtf/text/UniquedStringImpl.h

    r210227 r221384  
    4545// UniquedStringImpls created from StaticStringImpl will ASSERT
    4646// in the generic ValueCheck<T>::checkConsistency
    47 // as they are not allocated by fastMalloc.
     47// as they are not allocated by stringMalloc.
    4848// We don't currently have any way to detect that case
    4949// so we ignore the consistency check for all UniquedStringImpls*.
  • trunk/Source/WTF/wtf/text/WTFString.h

    r221203 r221384  
    147147    static String adopt(StringBuffer<LChar>&& buffer) { return StringImpl::adopt(WTFMove(buffer)); }
    148148    static String adopt(StringBuffer<UChar>&& buffer) { return StringImpl::adopt(WTFMove(buffer)); }
    149     template<typename CharacterType, size_t inlineCapacity, typename OverflowHandler>
    150     static String adopt(Vector<CharacterType, inlineCapacity, OverflowHandler>&& vector) { return StringImpl::adopt(WTFMove(vector)); }
     149    template<typename CharacterType, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
     150    static String adopt(StringVector<CharacterType, inlineCapacity, OverflowHandler, minCapacity>&& vector) { return StringImpl::adopt(WTFMove(vector)); }
    151151
    152152    bool isNull() const { return !m_impl; }
     
    499499        if (m_impl && m_impl->hasOneRef())
    500500            m_impl = nullptr;
     501    }
     502   
     503    void assertCaged() const
     504    {
     505        if (m_impl)
     506            m_impl->assertCaged();
     507    }
     508
     509    void releaseAssertCaged() const
     510    {
     511        if (m_impl)
     512            m_impl->releaseAssertCaged();
    501513    }
    502514
  • trunk/Source/WebCore/ChangeLog

    r221381 r221384  
     12017-08-22  Filip Pizlo  <fpizlo@apple.com>
     2
     3        Strings need to be in some kind of gigacage
     4        https://bugs.webkit.org/show_bug.cgi?id=174924
     5
     6        Reviewed by Oliver Hunt.
     7
     8        No new tests because no new behavior.
     9
     10        * html/canvas/CanvasRenderingContext2D.cpp:
     11        (WebCore::normalizeSpaces):
     12
    1132017-08-30  Andy Estes  <aestes@apple.com>
    214
  • trunk/Source/WebCore/Modules/indexeddb/server/IDBSerialization.cpp

    r215262 r221384  
    327327            return false;
    328328
    329         Vector<UChar> buffer;
     329        StringVector<UChar> buffer;
    330330        buffer.reserveInitialCapacity(length);
    331331        for (size_t i = 0; i < length; i++) {
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp

    r221110 r221384  
    19511951        ptr += length * sizeof(UChar);
    19521952#else
    1953         Vector<UChar> buffer;
     1953        StringVector<UChar> buffer;
    19541954        buffer.reserveCapacity(length);
    19551955        for (unsigned i = 0; i < length; i++) {
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r220503 r221384  
    23262326
    23272327    unsigned textLength = text.length();
    2328     Vector<UChar> charVector(textLength);
     2328    StringVector<UChar> charVector(textLength);
    23292329    StringView(text).getCharactersWithUpconvert(charVector.data());
    23302330
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp

    r219237 r221384  
    206206    {
    207207        ASSERT(!isEmpty());
    208         Vector<LChar, 8> whitespace;
     208        StringVector<LChar, 8> whitespace;
    209209        do {
    210210            UChar character = m_text[0];
  • trunk/Source/WebCore/platform/URLParser.cpp

    r221195 r221384  
    534534}
    535535
    536 static void percentEncodeByte(uint8_t byte, Vector<LChar>& buffer)
     536static void percentEncodeByte(uint8_t byte, StringVector<LChar>& buffer)
    537537{
    538538    buffer.append('%');
     
    28152815}
    28162816
    2817 static void serializeURLEncodedForm(const String& input, Vector<LChar>& output)
     2817static void serializeURLEncodedForm(const String& input, StringVector<LChar>& output)
    28182818{
    28192819    auto utf8 = input.utf8(StrictConversion);
     
    28412841        return { };
    28422842
    2843     Vector<LChar> output;
     2843    StringVector<LChar> output;
    28442844    for (auto& tuple : tuples) {
    28452845        if (!output.isEmpty())
  • trunk/Source/WebCore/platform/URLParser.h

    r213686 r221384  
    5959
    6060    URL m_url;
    61     Vector<LChar> m_asciiBuffer;
     61    StringVector<LChar> m_asciiBuffer;
    6262    bool m_urlIsSpecial { false };
    6363    bool m_urlIsFile { false };
  • trunk/Source/WebCore/platform/graphics/FourCC.cpp

    r217933 r221384  
    4343String FourCC::toString() const
    4444{
    45     Vector<LChar, 4> data = {
     45    StringVector<LChar, 4> data = {
    4646        LChar(value >> 24),
    4747        LChar((value >> 16) & 0xFF),
  • trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp

    r220503 r221384  
    26992699    size_t vectorSize = (depth + bitsPerUChar - 1) / bitsPerUChar;
    27002700   
    2701     Vector<UChar> result(vectorSize);
     2701    StringVector<UChar> result(vectorSize);
    27022702    result.fill(0);
    27032703
  • trunk/Source/WebCore/platform/text/LocaleICU.cpp

    r206196 r221384  
    7474    if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR)
    7575        return String();
    76     Vector<UChar> buffer(bufferLength);
     76    StringVector<UChar> buffer(bufferLength);
    7777    status = U_ZERO_ERROR;
    7878    unum_getSymbol(m_numberFormat, symbol, buffer.data(), bufferLength, &status);
     
    8989    if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR)
    9090        return String();
    91     Vector<UChar> buffer(bufferLength);
     91    StringVector<UChar> buffer(bufferLength);
    9292    status = U_ZERO_ERROR;
    9393    unum_getTextAttribute(m_numberFormat, tag, buffer.data(), bufferLength, &status);
     
    154154    if (status != U_BUFFER_OVERFLOW_ERROR || !length)
    155155        return emptyString();
    156     Vector<UChar> buffer(length);
     156    StringVector<UChar> buffer(length);
    157157    status = U_ZERO_ERROR;
    158158    udat_toPattern(dateFormat, TRUE, buffer.data(), length, &status);
     
    176176        if (status != U_BUFFER_OVERFLOW_ERROR)
    177177            return std::make_unique<Vector<String>>();
    178         Vector<UChar> buffer(length);
     178        StringVector<UChar> buffer(length);
    179179        status = U_ZERO_ERROR;
    180180        udat_getSymbols(dateFormat, type, startIndex + i, buffer.data(), length, &status);
     
    267267    int32_t length = udatpg_getBestPattern(patternGenerator, skeleton, skeletonLength, 0, 0, &status);
    268268    if (status == U_BUFFER_OVERFLOW_ERROR && length) {
    269         Vector<UChar> buffer(length);
     269        StringVector<UChar> buffer(length);
    270270        status = U_ZERO_ERROR;
    271271        udatpg_getBestPattern(patternGenerator, skeleton, skeletonLength, buffer.data(), length, &status);
  • trunk/Source/WebCore/platform/text/mac/TextCodecMac.cpp

    r206196 r221384  
    202202        return String();
    203203   
    204     Vector<UChar> result;
     204    StringVector<UChar> result;
    205205
    206206    const unsigned char* sourcePointer = reinterpret_cast<const unsigned char*>(bytes);
  • trunk/Source/WebCore/platform/win/FileSystemWin.cpp

    r221177 r221384  
    186186String pathByAppendingComponent(const String& path, const String& component)
    187187{
    188     Vector<UChar> buffer(MAX_PATH);
     188    StringVector<UChar> buffer(MAX_PATH);
    189189
    190190    if (path.length() + 1 > buffer.size())
     
    277277static String storageDirectory(DWORD pathIdentifier)
    278278{
    279     Vector<UChar> buffer(MAX_PATH);
     279    StringVector<UChar> buffer(MAX_PATH);
    280280    if (FAILED(SHGetFolderPathW(0, pathIdentifier | CSIDL_FLAG_CREATE, 0, 0, buffer.data())))
    281281        return String();
  • trunk/Source/bmalloc/ChangeLog

    r221213 r221384  
     12017-08-22  Filip Pizlo  <fpizlo@apple.com>
     2
     3        Strings need to be in some kind of gigacage
     4        https://bugs.webkit.org/show_bug.cgi?id=174924
     5
     6        Reviewed by Oliver Hunt.
     7       
     8        This adds a StringGigacage.
     9
     10        * bmalloc/Gigacage.cpp:
     11        * bmalloc/Gigacage.h:
     12        (Gigacage::name):
     13        (Gigacage::basePtr):
     14        (Gigacage::forEachKind):
     15        * bmalloc/HeapKind.h:
     16        (bmalloc::isGigacage):
     17        (bmalloc::gigacageKind):
     18        (bmalloc::heapKind):
     19
    1202017-08-25  Daniel Bates  <dabates@apple.com>
    221
  • trunk/Source/bmalloc/bmalloc/Gigacage.cpp

    r221148 r221384  
    3737void* g_primitiveGigacageBasePtr;
    3838void* g_jsValueGigacageBasePtr;
     39void* g_stringGigacageBasePtr;
    3940
    4041using namespace bmalloc;
  • trunk/Source/bmalloc/bmalloc/Gigacage.h

    r221148 r221384  
    3535#define PRIMITIVE_GIGACAGE_SIZE 0x800000000llu
    3636#define JSVALUE_GIGACAGE_SIZE 0x400000000llu
     37#define STRING_GIGACAGE_SIZE 0x400000000llu
    3738
    3839#define GIGACAGE_SIZE_TO_MASK(size) ((size) - 1)
     
    4041#define PRIMITIVE_GIGACAGE_MASK GIGACAGE_SIZE_TO_MASK(PRIMITIVE_GIGACAGE_SIZE)
    4142#define JSVALUE_GIGACAGE_MASK GIGACAGE_SIZE_TO_MASK(JSVALUE_GIGACAGE_SIZE)
     43#define STRING_GIGACAGE_MASK GIGACAGE_SIZE_TO_MASK(STRING_GIGACAGE_SIZE)
    4244
    4345// FIXME: Consider making this 32GB, in case unsigned 32-bit indices find their way into indexed accesses.
     
    4850// https://bugs.webkit.org/show_bug.cgi?id=175921
    4951#define JSVALUE_GIGACAGE_RUNWAY 0
     52#define STRING_GIGACAGE_RUNWAY 0
    5053
    5154#if BOS(DARWIN) && BCPU(X86_64)
     
    5760extern "C" BEXPORT void* g_primitiveGigacageBasePtr;
    5861extern "C" BEXPORT void* g_jsValueGigacageBasePtr;
     62extern "C" BEXPORT void* g_stringGigacageBasePtr;
    5963
    6064namespace Gigacage {
     
    6266enum Kind {
    6367    Primitive,
    64     JSValue
     68    JSValue,
     69    String
    6570};
    6671
     
    8691    case JSValue:
    8792        return "JSValue";
     93    case String:
     94        return "String";
    8895    }
    8996    BCRASH();
     
    98105    case JSValue:
    99106        return g_jsValueGigacageBasePtr;
     107    case String:
     108        return g_stringGigacageBasePtr;
    100109    }
    101110    BCRASH();
     
    110119    case JSValue:
    111120        return static_cast<size_t>(JSVALUE_GIGACAGE_SIZE);
     121    case String:
     122        return static_cast<size_t>(STRING_GIGACAGE_SIZE);
    112123    }
    113124    BCRASH();
     
    132143    case JSValue:
    133144        return static_cast<size_t>(JSVALUE_GIGACAGE_RUNWAY);
     145    case String:
     146        return static_cast<size_t>(STRING_GIGACAGE_RUNWAY);
    134147    }
    135148    BCRASH();
     
    147160    func(Primitive);
    148161    func(JSValue);
     162    func(String);
    149163}
    150164
  • trunk/Source/bmalloc/bmalloc/HeapKind.h

    r220352 r221384  
    3535    Primary,
    3636    PrimitiveGigacage,
    37     JSValueGigacage
     37    JSValueGigacage,
     38    StringGigacage
    3839};
    3940
    40 static constexpr unsigned numHeaps = 3;
     41static constexpr unsigned numHeaps = 4;
    4142
    4243BINLINE bool isGigacage(HeapKind heapKind)
     
    4748    case HeapKind::PrimitiveGigacage:
    4849    case HeapKind::JSValueGigacage:
     50    case HeapKind::StringGigacage:
    4951        return true;
    5052    }
     
    6365    case HeapKind::JSValueGigacage:
    6466        return Gigacage::JSValue;
     67    case HeapKind::StringGigacage:
     68        return Gigacage::String;
    6569    }
    6670    BCRASH();
     
    7579    case Gigacage::JSValue:
    7680        return HeapKind::JSValueGigacage;
     81    case Gigacage::String:
     82        return HeapKind::StringGigacage;
    7783    }
    7884    BCRASH();
Note: See TracChangeset for help on using the changeset viewer.