Title: [185824] trunk/Source/WebKit2
Revision
185824
Author
[email protected]
Date
2015-06-22 05:06:46 -0700 (Mon, 22 Jun 2015)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (185823 => 185824)


--- trunk/Source/WebKit2/ChangeLog	2015-06-22 11:55:45 UTC (rev 185823)
+++ trunk/Source/WebKit2/ChangeLog	2015-06-22 12:06:46 UTC (rev 185824)
@@ -1,3 +1,30 @@
+2015-06-22  Zan Dobersek  <[email protected]>
+
+        [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):
+
 2015-06-22  Gyuyoung Kim  <[email protected]>
 
         [EFL] test_ewk2_application_cache_manager has been failed since r185527

Modified: trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp (185823 => 185824)


--- trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp	2015-06-22 11:55:45 UTC (rev 185823)
+++ trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp	2015-06-22 12:06:46 UTC (rev 185824)
@@ -94,6 +94,7 @@
 };
 
 class AttachmentInfo {
+    WTF_MAKE_FAST_ALLOCATED;
 public:
     AttachmentInfo()
         : m_type(Attachment::Uninitialized)
@@ -274,8 +275,8 @@
     memset(&iov, 0, sizeof(iov));
 
     message.msg_controllen = CMSG_SPACE(sizeof(int) * attachmentMaxAmount);
-    auto attachmentDescriptorBuffer = std::make_unique<char[]>(message.msg_controllen);
-    memset(attachmentDescriptorBuffer.get(), 0, message.msg_controllen);
+    MallocPtr<char> attachmentDescriptorBuffer = MallocPtr<char>::malloc(sizeof(char) * message.msg_controllen);
+    memset(attachmentDescriptorBuffer.get(), 0, sizeof(char) * message.msg_controllen);
     message.msg_control = attachmentDescriptorBuffer.get();
 
     iov[0].iov_base = buffer;
@@ -438,21 +439,20 @@
     iov[0].iov_base = reinterpret_cast<void*>(&messageInfo);
     iov[0].iov_len = sizeof(messageInfo);
 
-    auto attachmentInfo = std::make_unique<AttachmentInfo[]>(attachments.size());
+    std::unique_ptr<AttachmentInfo[]> attachmentInfo;
+    MallocPtr<char> attachmentFDBuffer;
 
-    size_t attachmentFDBufferLength = 0;
     if (!attachments.isEmpty()) {
-        for (size_t i = 0; i < attachments.size(); ++i) {
-            if (attachments[i].fileDescriptor() != -1)
-                attachmentFDBufferLength++;
-        }
-    }
-    auto attachmentFDBuffer = std::make_unique<char[]>(CMSG_SPACE(sizeof(int) * attachmentFDBufferLength));
-
-    if (!attachments.isEmpty()) {
         int* fdPtr = 0;
 
+        size_t attachmentFDBufferLength = std::count_if(attachments.begin(), attachments.end(),
+            [](const Attachment& attachment) {
+                return attachment.fileDescriptor() != -1;
+            });
+
         if (attachmentFDBufferLength) {
+            attachmentFDBuffer = MallocPtr<char>::malloc(sizeof(char) * CMSG_SPACE(sizeof(int) * attachmentFDBufferLength));
+
             message.msg_control = attachmentFDBuffer.get();
             message.msg_controllen = CMSG_SPACE(sizeof(int) * attachmentFDBufferLength);
             memset(message.msg_control, 0, message.msg_controllen);
@@ -465,6 +465,7 @@
             fdPtr = reinterpret_cast<int*>(CMSG_DATA(cmsg));
         }
 
+        attachmentInfo = std::make_unique<AttachmentInfo[]>(attachments.size());
         int fdIndex = 0;
         for (size_t i = 0; i < attachments.size(); ++i) {
             attachmentInfo[i].setType(attachments[i].type());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to