<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>45909</bug_id>
          
          <creation_ts>2010-09-16 11:07:57 -0700</creation_ts>
          <short_desc>BlobData should be copied for it to be used cross-thread in ThreadableBlobRegistry</short_desc>
          <delta_ts>2010-12-15 11:47:15 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore JavaScript</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jian Li">jianli</reporter>
          <assigned_to name="Jian Li">jianli</assigned_to>
          <cc>eric</cc>
    
    <cc>levin</cc>
    
    <cc>michaeln</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>280217</commentid>
    <comment_count>0</comment_count>
    <who name="Jian Li">jianli</who>
    <bug_when>2010-09-16 11:07:57 -0700</bug_when>
    <thetext>BlobData should be copied for it to be used cross-thread in ThreadableBlobRegistry. This is to pull part of the fix from bug 45576. Other part of the fix remain in that bug and will be relanded when the discussion is settled.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280222</commentid>
    <comment_count>1</comment_count>
      <attachid>67820</attachid>
    <who name="Jian Li">jianli</who>
    <bug_when>2010-09-16 11:24:30 -0700</bug_when>
    <thetext>Created attachment 67820
Proposed Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280225</commentid>
    <comment_count>2</comment_count>
      <attachid>67820</attachid>
    <who name="David Levin">levin</who>
    <bug_when>2010-09-16 11:27:50 -0700</bug_when>
    <thetext>Comment on attachment 67820
Proposed Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=67820&amp;action=prettypatch

&gt; LayoutTests/ChangeLog:8
&gt; +        Also fix a test issue. 

This is a bit generic. It would be nice to say what test issue is being fixed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280862</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Nordman">michaeln</who>
    <bug_when>2010-09-17 14:24:46 -0700</bug_when>
    <thetext>ownership of the BlobData instance is being passed to the registry... why does it need to be copied?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280868</commentid>
    <comment_count>4</comment_count>
    <who name="Jian Li">jianli</who>
    <bug_when>2010-09-17 14:29:08 -0700</bug_when>
    <thetext>This is because BlobData contains String and KURL that need to be copied explicitly in order for it to be used in other thread.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280877</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Nordman">michaeln</who>
    <bug_when>2010-09-17 14:35:50 -0700</bug_when>
    <thetext>what about the underlying CString&apos;s in BlobDataItems... do copies of those strings need to be made?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280894</commentid>
    <comment_count>6</comment_count>
    <who name="Jian Li">jianli</who>
    <bug_when>2010-09-17 15:01:30 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; what about the underlying CString&apos;s in BlobDataItems... do copies of those strings need to be made?

This is fine. See comment at line 42 in BlobData.cpp.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280900</commentid>
    <comment_count>7</comment_count>
    <who name="Michael Nordman">michaeln</who>
    <bug_when>2010-09-17 15:12:02 -0700</bug_when>
    <thetext>I see that line...
    data = item.data; // This is OK because the underlying storage is Vector&lt;char&gt;.
... and it appears that a copy is being made

My point is do we need to make a copy since the registry has been given of ownership. It looks like a copy will be made and the original promptly deleted, so why make the copy?

Sorry for harping on the copies, but I think we should expect largish amounts of data in these elements. I can&apos;t help but notice when I see a copy being made. I haven&apos;t counted the total number of memcpys involved to actually get one of these registered in chrome... that should be interesting.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280909</commentid>
    <comment_count>8</comment_count>
    <who name="David Levin">levin</who>
    <bug_when>2010-09-17 15:23:43 -0700</bug_when>
    <thetext>(In reply to comment #7)
&gt; I see that line...
&gt;     data = item.data; // This is OK because the underlying storage is Vector&lt;char&gt;.
&gt; ... and it appears that a copy is being made
&gt; 
&gt; My point is do we need to make a copy since the registry has been given of ownership. It looks like a copy will be made and the original promptly deleted, so why make the copy?
&gt; 
&gt; Sorry for harping on the copies, but I think we should expect largish amounts of data in these elements. I can&apos;t help but notice when I see a copy being made. I haven&apos;t counted the total number of memcpys involved to actually get one of these registered in chrome... that should be interesting.

fwiw, strings may be &quot;copied&quot; very quickly actually.

The key problem is that once you have a String (which is ref counted in a non-threadsafe manner) you don&apos;t know who else on the thread may have it also referenced.

It seems best that we get this code correct and then optimize.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280910</commentid>
    <comment_count>9</comment_count>
    <who name="David Levin">levin</who>
    <bug_when>2010-09-17 15:24:39 -0700</bug_when>
    <thetext>(In reply to comment #8)
&gt; It seems best that we get this code correct and then optimize.

I meant to say optimize as needed. :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280933</commentid>
    <comment_count>10</comment_count>
    <who name="Michael Nordman">michaeln</who>
    <bug_when>2010-09-17 15:37:30 -0700</bug_when>
    <thetext>Ok... I&apos;ll try to continue to point out the unneeded copies and continue to wonder how many years it will take for them to be removed ;)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280956</commentid>
    <comment_count>11</comment_count>
    <who name="David Levin">levin</who>
    <bug_when>2010-09-17 16:03:14 -0700</bug_when>
    <thetext>michaeln pointed out that this line is incorrrect: 
  data = item.data; // This is OK because the underlying storage is Vector&lt;char&gt;.

Because data isn&apos;t a Vector&lt;char&gt; nor a wrapper around one. It is a CString which is a thin wrapper around a RefCounted object.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280958</commentid>
    <comment_count>12</comment_count>
    <who name="Jian Li">jianli</who>
    <bug_when>2010-09-17 16:06:19 -0700</bug_when>
    <thetext>(In reply to comment #11)
&gt; michaeln pointed out that this line is incorrrect: 
&gt;   data = item.data; // This is OK because the underlying storage is Vector&lt;char&gt;.
&gt; 
&gt; Because data isn&apos;t a Vector&lt;char&gt; nor a wrapper around one. It is a CString which is a thin wrapper around a RefCounted object.

Will fix. Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>280996</commentid>
    <comment_count>13</comment_count>
    <who name="Michael Nordman">michaeln</who>
    <bug_when>2010-09-17 17:00:44 -0700</bug_when>
    <thetext>(In reply to comment #7)
&gt; I see that line...
&gt;     data = item.data; // This is OK because the underlying storage is Vector&lt;char&gt;.
&gt; ... and it appears that a copy is being made
&gt; 
&gt; My point is do we need to make a copy since the registry has been given of ownership. It looks like a copy will be made and the original promptly deleted, so why make the copy?
&gt; 
&gt; Sorry for harping on the copies, but I think we should expect largish amounts of data in these elements. I can&apos;t help but notice when I see a copy being made. I haven&apos;t counted the total number of memcpys involved to actually get one of these registered in chrome... that should be interesting.

Some observations from our chat...

We&apos;re using &apos;copy()&apos; semantics here in order to pass ownership from one thread to another. Copy works for that, but is also overkill for that since we don&apos;t need to retain an instance for use on the original thread. A method like &apos;detachFromThread&apos; or &apos;disconnectFromThread&apos; might make a better fit than this usage of blobData.copy().

I wonder if we should even have a copy() method on BlobData? I would prefer a way to produce a deep copy were not so readily available to help avoid that from happening.

COM has semantics like prepareToSwitchThreads() and switchThreads() for objects with thread affinity, where the former happens on the originating thread and the later on the new &apos;owning&apos; thread. Maybe something along those lines for BlobData objects?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>321840</commentid>
    <comment_count>14</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2010-12-14 01:59:24 -0800</bug_when>
    <thetext>What&apos;s the status on this patch?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>322718</commentid>
    <comment_count>15</comment_count>
    <who name="Jian Li">jianli</who>
    <bug_when>2010-12-15 11:42:03 -0800</bug_when>
    <thetext>Forgot to close.

Committed as http://trac.webkit.org/changeset/67646.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>322723</commentid>
    <comment_count>16</comment_count>
    <who name="David Levin">levin</who>
    <bug_when>2010-12-15 11:47:15 -0800</bug_when>
    <thetext>(In reply to comment #15)
&gt; Forgot to close.
&gt; 
&gt; Committed as http://trac.webkit.org/changeset/67646.

Is there a new bug for the semantics that Michael described to reduce copies?</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>67820</attachid>
            <date>2010-09-16 11:24:30 -0700</date>
            <delta_ts>2010-09-16 11:27:49 -0700</delta_ts>
            <desc>Proposed Patch</desc>
            <filename>45909</filename>
            <type>text/plain</type>
            <size>2420</size>
            <attacher name="Jian Li">jianli</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL0xheW91dFRlc3RzL0NoYW5nZUxvZyBiL0xheW91dFRlc3RzL0NoYW5nZUxv
ZwppbmRleCA1MDBhMDg2Li5iOTVjYWMxIDEwMDY0NAotLS0gYS9MYXlvdXRUZXN0cy9DaGFuZ2VM
b2cKKysrIGIvTGF5b3V0VGVzdHMvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMTQgQEAKKzIwMTAtMDkt
MTYgIEppYW4gTGkgIDxqaWFubGlAY2hyb21pdW0ub3JnPgorCisgICAgICAgIFJldmlld2VkIGJ5
IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAgIEJsb2JEYXRhIHNob3VsZCBiZSBjb3BpZWQgZm9y
IGl0IHRvIGJlIHVzZWQgY3Jvc3MtdGhyZWFkIGluIFR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ICAgIFJldmlld2VkIGJ5IFRvbnkgQ2hhbmcu
CmRpZmYgLS1naXQgYS9XZWJDb3JlL2ZpbGVhcGkvVGhyZWFkYWJsZUJsb2JSZWdpc3RyeS5jcHAg
Yi9XZWJDb3JlL2ZpbGVhcGkvVGhyZWFkYWJsZUJsb2JSZWdpc3RyeS5jcHAKaW5kZXggN2UwNzQ1
Zi4uZjc0YzY4MCAxMDA2NDQKLS0tIGEvV2ViQ29yZS9maWxlYXBpL1RocmVhZGFibGVCbG9iUmVn
aXN0cnkuY3BwCisrKyBiL1dlYkNvcmUvZmlsZWFwaS9UaHJlYWRhYmxlQmxvYlJlZ2lzdHJ5LmNw
cApAQCAtNDEsNyArNDEsNyBAQCBuYW1lc3BhY2UgV2ViQ29yZSB7CiBzdHJ1Y3QgQmxvYlJlZ2lz
dHJ5Q29udGV4dCB7CiAgICAgQmxvYlJlZ2lzdHJ5Q29udGV4dChjb25zdCBLVVJMJiB1cmwsIFBh
c3NPd25QdHI8QmxvYkRhdGE+IGJsb2JEYXRhKQogICAgICAgICA6IHVybCh1cmwuY29weSgpKQot
ICAgICAgICAsIGJsb2JEYXRhKGJsb2JEYXRhKQorICAgICAgICAsIGJsb2JEYXRhKGJsb2JEYXRh
LT5jb3B5KCkpCiAgICAgewogICAgIH0KIAo=
</data>
<flag name="review"
          id="57231"
          type_id="1"
          status="+"
          setter="levin"
    />
    <flag name="commit-queue"
          id="57232"
          type_id="3"
          status="-"
          setter="jianli"
    />
          </attachment>
      

    </bug>

</bugzilla>