⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 185824 in webkit


Ignore:
Timestamp:
Jun 22, 2015, 5:06:46 AM (11 years ago)
Author:
zandobersek@gmail.com
Message:

[WK2] ConnectionUnix should use FastMalloc to allocate on-heap resources
https://bugs.webkit.org/show_bug.cgi?id=146143

Reviewed by Carlos Garcia Campos.

IPC handling in Unix-specific IPC::Connection implementation should use
FastMalloc to allocate on-heap resources, instead of allocating via the
system allocator.

The AttachmentInfo class is marked as allocatable through FastMalloc.
That way it can be allocated through FastMalloc while still handled
through std::unique_ptr<>.

The char[] arrays in readBytesFromSocket() and Connection::sendOutgoingMessage()
are now handled through a MallocPtr<> object.

In Connection::sendOutgoingMessage(), both the AttachmentInfo[] and char[]
arrays are now only allocated if there are actual attachments contained
in the message. The code that's conditioned with a non-empty attachments
Vector is now also grouped together, in a single branch.

  • Platform/IPC/unix/ConnectionUnix.cpp:

(IPC::readBytesFromSocket):
(IPC::Connection::sendOutgoingMessage):

Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r185822 r185824  
     12015-06-22  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [WK2] ConnectionUnix should use FastMalloc to allocate on-heap resources
     4        https://bugs.webkit.org/show_bug.cgi?id=146143
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        IPC handling in Unix-specific IPC::Connection implementation should use
     9        FastMalloc to allocate on-heap resources, instead of allocating via the
     10        system allocator.
     11
     12        The AttachmentInfo class is marked as allocatable through FastMalloc.
     13        That way it can be allocated through FastMalloc while still handled
     14        through std::unique_ptr<>.
     15
     16        The char[] arrays in readBytesFromSocket() and Connection::sendOutgoingMessage()
     17        are now handled through a MallocPtr<> object.
     18
     19        In Connection::sendOutgoingMessage(), both the AttachmentInfo[] and char[]
     20        arrays are now only allocated if there are actual attachments contained
     21        in the message. The code that's conditioned with a non-empty attachments
     22        Vector is now also grouped together, in a single branch.
     23
     24        * Platform/IPC/unix/ConnectionUnix.cpp:
     25        (IPC::readBytesFromSocket):
     26        (IPC::Connection::sendOutgoingMessage):
     27
    1282015-06-22  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
    229
  • trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp

    r183746 r185824  
    9595
    9696class AttachmentInfo {
     97    WTF_MAKE_FAST_ALLOCATED;
    9798public:
    9899    AttachmentInfo()
     
    275276
    276277    message.msg_controllen = CMSG_SPACE(sizeof(int) * attachmentMaxAmount);
    277     auto attachmentDescriptorBuffer = std::make_unique<char[]>(message.msg_controllen);
    278     memset(attachmentDescriptorBuffer.get(), 0, message.msg_controllen);
     278    MallocPtr<char> attachmentDescriptorBuffer = MallocPtr<char>::malloc(sizeof(char) * message.msg_controllen);
     279    memset(attachmentDescriptorBuffer.get(), 0, sizeof(char) * message.msg_controllen);
    279280    message.msg_control = attachmentDescriptorBuffer.get();
    280281
     
    439440    iov[0].iov_len = sizeof(messageInfo);
    440441
    441     auto attachmentInfo = std::make_unique<AttachmentInfo[]>(attachments.size());
    442 
    443     size_t attachmentFDBufferLength = 0;
    444     if (!attachments.isEmpty()) {
    445         for (size_t i = 0; i < attachments.size(); ++i) {
    446             if (attachments[i].fileDescriptor() != -1)
    447                 attachmentFDBufferLength++;
    448         }
    449     }
    450     auto attachmentFDBuffer = std::make_unique<char[]>(CMSG_SPACE(sizeof(int) * attachmentFDBufferLength));
     442    std::unique_ptr<AttachmentInfo[]> attachmentInfo;
     443    MallocPtr<char> attachmentFDBuffer;
    451444
    452445    if (!attachments.isEmpty()) {
    453446        int* fdPtr = 0;
    454447
     448        size_t attachmentFDBufferLength = std::count_if(attachments.begin(), attachments.end(),
     449            [](const Attachment& attachment) {
     450                return attachment.fileDescriptor() != -1;
     451            });
     452
    455453        if (attachmentFDBufferLength) {
     454            attachmentFDBuffer = MallocPtr<char>::malloc(sizeof(char) * CMSG_SPACE(sizeof(int) * attachmentFDBufferLength));
     455
    456456            message.msg_control = attachmentFDBuffer.get();
    457457            message.msg_controllen = CMSG_SPACE(sizeof(int) * attachmentFDBufferLength);
     
    466466        }
    467467
     468        attachmentInfo = std::make_unique<AttachmentInfo[]>(attachments.size());
    468469        int fdIndex = 0;
    469470        for (size_t i = 0; i < attachments.size(); ++i) {
Note: See TracChangeset for help on using the changeset viewer.