Ignore:
Timestamp:
Mar 5, 2018, 11:25:14 PM (7 years ago)
Author:
Yusuke Suzuki
Message:

Fix std::make_unique / new[] using system malloc
https://bugs.webkit.org/show_bug.cgi?id=182975

Reviewed by JF Bastien.

Source/JavaScriptCore:

Use Vector, FAST_ALLOCATED, or UniqueArray instead.

  • API/JSStringRefCF.cpp:

(JSStringCreateWithCFString):

  • bytecode/BytecodeKills.h:
  • bytecode/BytecodeLivenessAnalysis.cpp:

(JSC::BytecodeLivenessAnalysis::computeKills):

  • dfg/DFGDisassembler.cpp:

(JSC::DFG::Disassembler::dumpDisassembly):

  • jit/PolymorphicCallStubRoutine.cpp:

(JSC::PolymorphicCallStubRoutine::PolymorphicCallStubRoutine):

  • jit/PolymorphicCallStubRoutine.h:
  • jit/Repatch.cpp:

(JSC::linkPolymorphicCall):

  • jsc.cpp:

(currentWorkingDirectory):

  • llint/LLIntData.cpp:

(JSC::LLInt::initialize):

  • llint/LLIntData.h:
  • runtime/ArgList.h:
  • runtime/StructureChain.h:
  • runtime/StructureIDTable.cpp:

(JSC::StructureIDTable::StructureIDTable):
(JSC::StructureIDTable::resize):

  • runtime/StructureIDTable.h:
  • runtime/TypeProfilerLog.cpp:

(JSC::TypeProfilerLog::TypeProfilerLog):
(JSC::TypeProfilerLog::initializeLog): Deleted.

  • runtime/TypeProfilerLog.h:

(JSC::TypeProfilerLog::TypeProfilerLog): Deleted.

  • runtime/VM.cpp:

(JSC::VM::~VM):
(JSC::VM::acquireRegExpPatternContexBuffer):

  • runtime/VM.h:
  • testRegExp.cpp:

(runFromFiles):

  • tools/HeapVerifier.cpp:

(JSC::HeapVerifier::HeapVerifier):

  • tools/HeapVerifier.h:

Source/WebCore:

Use Vector, FAST_ALLOCATED, or UniqueArray instead.

  • Modules/webaudio/AudioBufferSourceNode.cpp:

(WebCore::AudioBufferSourceNode::setBuffer):

  • Modules/webaudio/AudioBufferSourceNode.h:
  • css/StyleRule.h:
  • cssjit/CompiledSelector.h:
  • html/HTMLFrameSetElement.h:
  • html/canvas/WebGLRenderingContextBase.cpp:

(WebCore::WebGLRenderingContextBase::copyTexSubImage2D):
(WebCore::WebGLRenderingContextBase::simulateVertexAttrib0):
(WebCore::WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache):
(WebCore::WebGLRenderingContextBase::LRUImageBufferCache::imageBuffer):
(WebCore::WebGLRenderingContextBase::LRUImageBufferCache::bubbleToFront):

  • html/canvas/WebGLRenderingContextBase.h:
  • platform/Length.cpp:

(WebCore::newCoordsArray):
(WebCore::newLengthArray):
(): Deleted.

  • platform/Length.h:
  • platform/audio/DynamicsCompressor.cpp:

(WebCore::DynamicsCompressor::setNumberOfChannels):

  • platform/audio/DynamicsCompressor.h:
  • platform/audio/FFTFrame.h:
  • platform/audio/gstreamer/FFTFrameGStreamer.cpp:

(WebCore::FFTFrame::FFTFrame):

  • platform/graphics/FormatConverter.h:

(WebCore::FormatConverter::FormatConverter):

  • platform/graphics/GraphicsContext3D.cpp:

(WebCore::GraphicsContext3D::texImage2DResourceSafe):

  • platform/graphics/GraphicsContext3D.h:
  • platform/graphics/ca/win/CACFLayerTreeHost.cpp:

(WebCore::getDirtyRects):

  • platform/graphics/cairo/CairoUtilities.cpp:

(WebCore::flipImageSurfaceVertically):

  • platform/graphics/cg/GraphicsContext3DCG.cpp:

(WebCore::GraphicsContext3D::ImageExtractor::extractImage):

  • platform/graphics/gpu/Texture.cpp:

(WebCore::Texture::updateSubRect):

  • platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:

(WebCore::GraphicsContext3D::paintRenderingResultsToCanvas):
(WebCore::GraphicsContext3D::compileShader):
(WebCore::GraphicsContext3D::getActiveAttribImpl):
(WebCore::GraphicsContext3D::getActiveUniformImpl):
(WebCore::GraphicsContext3D::getProgramInfoLog):
(WebCore::GraphicsContext3D::getShaderInfoLog):

  • platform/graphics/texmap/TextureMapperShaderProgram.cpp:

(WebCore::getShaderLog):
(WebCore::getProgramLog):

  • platform/graphics/win/ImageBufferDataDirect2D.cpp:

(WebCore::ImageBufferData::putData):

  • platform/image-decoders/png/PNGImageDecoder.cpp:

(WebCore::PNGImageReader::PNGImageReader):
(WebCore::PNGImageReader::close):
(WebCore::PNGImageReader::interlaceBuffer const):
(WebCore::PNGImageReader::createInterlaceBuffer):

  • platform/image-decoders/webp/WEBPImageDecoder.cpp:

(WebCore::WEBPImageDecoder::decodeFrame):

  • platform/network/curl/SocketStreamHandleImpl.h:

(WebCore::SocketStreamHandleImpl::SocketData::SocketData):

  • platform/network/curl/SocketStreamHandleImplCurl.cpp:

(WebCore::createCopy):
(WebCore::SocketStreamHandleImpl::readData):
(): Deleted.

  • platform/network/soup/SocketStreamHandleImpl.h:
  • platform/network/soup/SocketStreamHandleImplSoup.cpp:

(WebCore::SocketStreamHandleImpl::connected):

  • platform/win/LoggingWin.cpp:

(WebCore::logLevelString):

Source/WebCore/PAL:

Use Vector instead.

  • pal/win/LoggingWin.cpp:

(PAL::logLevelString):

Source/WebKit:

Use Vector instead.

  • NetworkProcess/win/SystemProxyWin.cpp:

(WindowsSystemProxy::getSystemHttpProxy):

  • Platform/IPC/unix/ConnectionUnix.cpp:

(IPC::Connection::processMessage):
(IPC::Connection::sendOutputMessage):

  • Platform/win/LoggingWin.cpp:

(WebKit::logLevelString):

  • Shared/SandboxExtension.h:
  • Shared/mac/SandboxExtensionMac.mm:

(WebKit::SandboxExtension::HandleArray::allocate):
(WebKit::SandboxExtension::HandleArray::operator[]):
(WebKit::SandboxExtension::HandleArray::operator[] const):
(WebKit::SandboxExtension::HandleArray::size const):
(WebKit::SandboxExtension::HandleArray::encode const):

Source/WebKitLegacy/win:

Use Vector instead.

  • MarshallingHelpers.cpp:

(MarshallingHelpers::safeArrayToStringArray):
(MarshallingHelpers::safeArrayToIntArray):

  • Plugins/PluginPackageWin.cpp:

(WebCore::PluginPackage::fetchInfo):

  • WebPreferences.cpp:

(WebPreferences::copyWebKitPreferencesToCFPreferences):

  • WebView.cpp:

(WebView::onMenuCommand):

Source/WTF:

If we use make_unique<char[]>(num) or new char[num], allocation is
done by the system malloc instead of bmalloc. This patch fixes this issue
by following three changes.

  1. Introduce UniqueArray<T>. It allocates memory from FastMalloc. While C++

array with new need to hold the size to call destructor correctly, our
UniqueArray only supports type T which does not have a non trivial destructor.
It reduces the allocation size since we do not need to track the size of the
array compared to standard new T[]. This is basically usable if we want to
have raw array which pointer won't be changed even if the container is moved.
In addition, we also extend UniqueArray<T> for types which have non trivial
destructors.

  1. Use Vector<T> instead.
  1. Annotate allocated types with MAKE_FAST_ALLOCATED. Since it introduces

new[] and delete[] operators, make_unique<T[]>(num) will allocate memory
from FastMalloc.

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

(WTF::FastFree::operator() const):
(WTF::FastFree<T::operator() const):

  • wtf/MallocPtr.h:

(WTF::MallocPtr::operator bool const):

  • wtf/StackShot.h:

(WTF::StackShot::StackShot):
(WTF::StackShot::operator=):

  • wtf/SystemFree.h:

(WTF::SystemFree<T::operator() const):

  • wtf/UniqueArray.h: Copied from Source/WebKit/Platform/win/LoggingWin.cpp.

(WTF::makeUniqueArray):

  • wtf/Vector.h:

(WTF::VectorTypeOperations::forceInitialize):

Tools:

  • TestWebKitAPI/CMakeLists.txt:
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WTF/UniqueArray.cpp: Copied from Source/WebKit/Platform/win/LoggingWin.cpp.

(TestWebKitAPI::NonTrivialDestructor::NonTrivialDestructor):
(TestWebKitAPI::NonTrivialDestructor::~NonTrivialDestructor):
(TestWebKitAPI::NonTrivialDestructor::setLog):
(TestWebKitAPI::TEST):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/testRegExp.cpp

    r229209 r229309  
    2929#include <stdlib.h>
    3030#include <string.h>
     31#include <wtf/Vector.h>
    3132#include <wtf/text/StringBuilder.h>
    3233
     
    416417    unsigned tests = 0;
    417418    unsigned failures = 0;
    418     char* lineBuffer = new char[MaxLineLength + 1];
     419    Vector<char> lineBuffer(MaxLineLength + 1);
    419420
    420421    VM& vm = globalObject->vm();
     
    435436        const char* regexpError = nullptr;
    436437
    437         while ((linePtr = fgets(&lineBuffer[0], MaxLineLength, testCasesFile))) {
     438        while ((linePtr = fgets(lineBuffer.data(), MaxLineLength, testCasesFile))) {
    438439            lineLength = strlen(linePtr);
    439440            if (linePtr[lineLength - 1] == '\n') {
     
    484485        printf("%u tests passed\n", tests);
    485486
    486     delete[] lineBuffer;
    487 
    488487#if ENABLE(REGEXP_TRACING)
    489488    vm.dumpRegExpTrace();
Note: See TracChangeset for help on using the changeset viewer.