<?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>125172</bug_id>
          
          <creation_ts>2013-12-03 11:34:21 -0800</creation_ts>
          <short_desc>ObjectAllocationProfile is racy and the DFG should be cool with that</short_desc>
          <delta_ts>2013-12-06 13:27:19 -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>JavaScriptCore</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>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Filip Pizlo">fpizlo</reporter>
          <assigned_to name="Filip Pizlo">fpizlo</assigned_to>
          <cc>barraclough</cc>
    
    <cc>darin</cc>
    
    <cc>ggaren</cc>
    
    <cc>mark.lam</cc>
    
    <cc>mhahnenberg</cc>
    
    <cc>msaboff</cc>
    
    <cc>oliver</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>956007</commentid>
    <comment_count>0</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-03 11:34:21 -0800</bug_when>
    <thetext>Patch forthcoming

&lt;rdar://problem/15233487&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>956014</commentid>
    <comment_count>1</comment_count>
      <attachid>218318</attachid>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-03 11:36:08 -0800</bug_when>
    <thetext>Created attachment 218318
the patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>956015</commentid>
    <comment_count>2</comment_count>
      <attachid>218318</attachid>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2013-12-03 11:38:30 -0800</bug_when>
    <thetext>Comment on attachment 218318
the patch

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>956100</commentid>
    <comment_count>3</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-03 14:22:18 -0800</bug_when>
    <thetext>Landed in http://trac.webkit.org/changeset/160038</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>956112</commentid>
    <comment_count>4</comment_count>
      <attachid>218318</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2013-12-03 14:31:00 -0800</bug_when>
    <thetext>Comment on attachment 218318
the patch

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

&gt; Source/JavaScriptCore/dfg/DFGAbstractValue.cpp:156
&gt; +    ASSERT(structure);

When you find yourself writing this assertion, it’s worth considering making the argument Structure&amp; instead of Structure*.

&gt; Source/JavaScriptCore/runtime/JSFunction.h:141
&gt; +        Structure* allocationStructure() { return m_allocationProfile.structure(); }

If this can never be null we should consider returning Structure&amp;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>956128</commentid>
    <comment_count>5</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-03 14:41:30 -0800</bug_when>
    <thetext>(In reply to comment #4)
&gt; (From update of attachment 218318 [details])
&gt; View in context: https://bugs.webkit.org/attachment.cgi?id=218318&amp;action=review
&gt; 
&gt; &gt; Source/JavaScriptCore/dfg/DFGAbstractValue.cpp:156
&gt; &gt; +    ASSERT(structure);
&gt; 
&gt; When you find yourself writing this assertion, it’s worth considering making the argument Structure&amp; instead of Structure*.

This would be strange.  We use * for JSC heap pointers and Structure is a JSC heap object.  There is no precedent for using &amp; to refer to JSC heap objects.  I expect accesses to the JSC heap to use -&gt; and not &quot;.&quot;.

It would be weird to me if the same kind of object was referred to using both &amp; and *.  This is confusing; you end up with a mix of . and -&gt; to access its members, and you find yourself having to use &amp; and * in a bunch of places to convert from one pointer style to the other.  We have this issue with JSC::VM and it&apos;s really gross.

But overall, I just really don&apos;t like &amp;.  I wish it wasn&apos;t part of the language.

&gt; 
&gt; &gt; Source/JavaScriptCore/runtime/JSFunction.h:141
&gt; &gt; +        Structure* allocationStructure() { return m_allocationProfile.structure(); }
&gt; 
&gt; If this can never be null we should consider returning Structure&amp;.

It can be null, and that&apos;s OK.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>956943</commentid>
    <comment_count>6</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2013-12-05 10:03:32 -0800</bug_when>
    <thetext>(In reply to comment #5)
&gt; But overall, I just really don&apos;t like &amp;.  I wish it wasn&apos;t part of the language.

OK, that seems like the real issue.

We need to get you together with the folks currently setting the style elsewhere in WebKit, because elsewhere we are seeing improvements that come from switching from pointers to references.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>957372</commentid>
    <comment_count>7</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-06 13:27:19 -0800</bug_when>
    <thetext>(In reply to comment #6)
&gt; (In reply to comment #5)
&gt; &gt; But overall, I just really don&apos;t like &amp;.  I wish it wasn&apos;t part of the language.
&gt; 
&gt; OK, that seems like the real issue.
&gt; 
&gt; We need to get you together with the folks currently setting the style elsewhere in WebKit, because elsewhere we are seeing improvements that come from switching from pointers to references.

I think that the bigger issue for this particular case is just that we always use pointers, not references, to refer to things allocated in the JS heap (i.e. JSCell and friends).  We then leverage this with idioms that either allow or require JSCell* to possibly be null, for example:

if (JSObject* object = jsDynamicCast&lt;JSObject*&gt;(jsValue)) {
    // do things for the case that jsValue is an object.
} else {
    // do things for the case that it ain&apos;t
}

This is sort of fitting because of the dynamic nature of JSCells and JSValues.  They are the C++-side proxies for values in a dynamic language, and so it is quite rare that we have a guarantee like &quot;I know that I have a pointer to Blah and it&apos;s not null&quot;.

There may be a separate debate regarding whether &amp; is better than * for WebCore or broadly for &quot;most objects&quot; in WebKit.  Even if the outcome of that debate is (or was, past tense) that &amp; is usually better, I still think it&apos;s sensible to ask questions like:

- Does it make the code better, or worse, if we make one particular reference to an object use &amp; even though it&apos;s a convention to always use * for that object?

- Is it a good use of time to attempt to change all or some of the * pointers to a kind of object into &amp; references?

- If we incrementally start changing all references to an object to be &amp; instead of *, how much of a cost will this incur in the meantime for other people trying to do things to the codebase?

For JSCell, I propose that the answers are, respectively: worse, bad use, too much.  The reason for my pessimism is that I would guess that there will be very few places where we can reasonably use &amp; instead of * for JSCells and so those few places will just stick out like sore thumbs.  For example, they will degrade readability because those of us who stare at the code the most are accustomed to &quot;.&quot; and &quot;&amp;&quot; meaning &quot;it ain&apos;t GC&apos;d&quot;.  Getting to the point where we find those places (where JSCell&amp; would work at all) will take a non-trivial amount of effort and will produce relatively small gains.

The trade-off may be different for other kinds of objects.  Personally, I would always err on the side of * instead of &amp;, but in my arguments above I&apos;m trying to step back from that bias and make a more objective argument.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>218318</attachid>
            <date>2013-12-03 11:36:08 -0800</date>
            <delta_ts>2013-12-03 14:31:00 -0800</delta_ts>
            <desc>the patch</desc>
            <filename>blah.patch</filename>
            <type>text/plain</type>
            <size>5000</size>
            <attacher name="Filip Pizlo">fpizlo</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gMTYwMDIxKQorKysgU291cmNl
L0phdmFTY3Jpc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0LCBPcEluZm8oc3RydWN0dXJl
KSkpOwogICAgICAgICAgICAgICAgICAgICBhbHJlYWR5RW1pdHRlZCA9IHRydWU7CiAgICAgICAg
ICAgICAgICAgfQogICAgICAgICAgICAgfQotICAgICAgICAgICAgaWYgKCFhbHJlYWR5RW1pdHRl
ZCkKKyAgICAgICAgICAgIGlmICghYWxyZWFkeUVtaXR0ZWQpIHsKICAgICAgICAgICAgICAgICBz
ZXQoVmlydHVhbFJlZ2lzdGVyKGN1cnJlbnRJbnN0cnVjdGlvblsxXS51Lm9wZXJhbmQpLAogICAg
ICAgICAgICAgICAgICAgICBhZGRUb0dyYXBoKENyZWF0ZVRoaXMsIE9wSW5mbyhjdXJyZW50SW5z
dHJ1Y3Rpb25bM10udS5vcGVyYW5kKSwgY2FsbGVlKSk7CisgICAgICAgICAgICB9CiAgICAgICAg
ICAgICBORVhUX09QQ09ERShvcF9jcmVhdGVfdGhpcyk7CiAgICAgICAgIH0KIApJbmRleDogU291
cmNlL0phdmFTY3JpcHRDb3JlL3J1bnRpbWUvSlNGdW5jdGlvbi5oCj09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFNv
dXJjZS9KYXZhU2NyaXB0Q29yZS9ydW50aW1lL0pTRnVuY3Rpb24uaAkocmV2aXNpb24gMTYwMDEz
KQorKysgU291cmNlL0phdmFTY3JpcHRDb3JlL3J1bnRpbWUvSlNGdW5jdGlvbi5oCSh3b3JraW5n
IGNvcHkpCkBAIC0xMzcsMjIgKzEzNyw5IEBAIG5hbWVzcGFjZSBKU0MgewogICAgICAgICAgICAg
ICAgIHJldHVybiBjcmVhdGVBbGxvY2F0aW9uUHJvZmlsZShleGVjLCBpbmxpbmVDYXBhY2l0eSk7
CiAgICAgICAgICAgICByZXR1cm4gJm1fYWxsb2NhdGlvblByb2ZpbGU7CiAgICAgICAgIH0KLQot
ICAgICAgICBPYmplY3RBbGxvY2F0aW9uUHJvZmlsZSogdHJ5R2V0QWxsb2NhdGlvblByb2ZpbGUo
KQotICAgICAgICB7Ci0gICAgICAgICAgICBpZiAobV9hbGxvY2F0aW9uUHJvZmlsZS5pc051bGwo
KSkKLSAgICAgICAgICAgICAgICByZXR1cm4gMDsKLSAgICAgICAgICAgIGlmIChtX2FsbG9jYXRp
b25Qcm9maWxlV2F0Y2hwb2ludC5oYXNCZWVuSW52YWxpZGF0ZWQoKSkKLSAgICAgICAgICAgICAg
ICByZXR1cm4gMDsKLSAgICAgICAgICAgIHJldHVybiAmbV9hbGxvY2F0aW9uUHJvZmlsZTsKLSAg
ICAgICAgfQotICAgICAgICAKLSAgICAgICAgdm9pZCBhZGRBbGxvY2F0aW9uUHJvZmlsZVdhdGNo
cG9pbnQoV2F0Y2hwb2ludCogd2F0Y2hwb2ludCkKLSAgICAgICAgewotICAgICAgICAgICAgQVNT
RVJUKHRyeUdldEFsbG9jYXRpb25Qcm9maWxlKCkpOwotICAgICAgICAgICAgbV9hbGxvY2F0aW9u
UHJvZmlsZVdhdGNocG9pbnQuYWRkKHdhdGNocG9pbnQpOwotICAgICAgICB9CiAgICAgICAgIAor
ICAgICAgICBTdHJ1Y3R1cmUqIGFsbG9jYXRpb25TdHJ1Y3R1cmUoKSB7IHJldHVybiBtX2FsbG9j
YXRpb25Qcm9maWxlLnN0cnVjdHVyZSgpOyB9CisKICAgICAgICAgSW5saW5lV2F0Y2hwb2ludFNl
dCYgYWxsb2NhdGlvblByb2ZpbGVXYXRjaHBvaW50U2V0KCkKICAgICAgICAgewogICAgICAgICAg
ICAgcmV0dXJuIG1fYWxsb2NhdGlvblByb2ZpbGVXYXRjaHBvaW50Owo=
</data>
<flag name="review"
          id="241697"
          type_id="1"
          status="+"
          setter="mhahnenberg"
    />
          </attachment>
      

    </bug>

</bugzilla>