<?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>60990</bug_id>
          
          <creation_ts>2011-05-17 14:43:25 -0700</creation_ts>
          <short_desc>JSGlobalContextRelease should not trigger a synchronous garbage collection</short_desc>
          <delta_ts>2011-05-18 14:54:59 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</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="Sam Weinig">sam</reporter>
          <assigned_to name="Sam Weinig">sam</assigned_to>
          <cc>ap</cc>
    
    <cc>aroben</cc>
    
    <cc>barraclough</cc>
    
    <cc>ggaren</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>405296</commentid>
    <comment_count>0</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2011-05-17 14:43:25 -0700</bug_when>
    <thetext>JSGlobalContextRelease should not trigger a synchronous garbage collection</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405298</commentid>
    <comment_count>1</comment_count>
      <attachid>93818</attachid>
    <who name="Sam Weinig">sam</who>
    <bug_when>2011-05-17 14:47:26 -0700</bug_when>
    <thetext>Created attachment 93818
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405339</commentid>
    <comment_count>2</comment_count>
      <attachid>93818</attachid>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2011-05-17 15:31:19 -0700</bug_when>
    <thetext>Comment on attachment 93818
Patch

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

&gt; Source/JavaScriptCore/API/JSContextRef.cpp:142
&gt; +    //   garbarge collect soon.

garbarge?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405341</commentid>
    <comment_count>3</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2011-05-17 15:32:51 -0700</bug_when>
    <thetext>Committed r86712: &lt;http://trac.webkit.org/changeset/86712&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405348</commentid>
    <comment_count>4</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2011-05-17 15:39:52 -0700</bug_when>
    <thetext>What&apos;s the motivation for this? Neither this bug nor the ChangeLog say!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405357</commentid>
    <comment_count>5</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2011-05-17 15:49:03 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; What&apos;s the motivation for this? Neither this bug nor the ChangeLog say!

The motivation is to coalesce garbage collections that are triggered as a result of releasing a global context.  Otherwise, repeated calls to JSGlobalContextRelease would each trigger a full collection, where one at the end would be much better.

As a general rule, synchronous full garbage collection should be avoided as it is very expensive, and should definitely not happen unexpectedly as was happening with JSGlobalContextRelease.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405482</commentid>
    <comment_count>6</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-05-17 20:39:10 -0700</bug_when>
    <thetext>We discussed this in person, but I&apos;m not sure how the landed version avoids leaking objects in a worker context. Worker threads don&apos;t even have CFRunLoops to schedule timers on.

Is this patch correct?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405501</commentid>
    <comment_count>7</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2011-05-17 21:36:25 -0700</bug_when>
    <thetext>&gt; We discussed this in person, but I&apos;m not sure how the landed version avoids leaking objects in a worker context. Worker threads don&apos;t even have CFRunLoops to schedule timers on.

When a worker thread exits, it releases the last reference to its context group (JSGlobalData), which calls Heap::destroy().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405504</commentid>
    <comment_count>8</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2011-05-17 21:43:16 -0700</bug_when>
    <thetext>(In reply to comment #6)
&gt; We discussed this in person, but I&apos;m not sure how the landed version avoids leaking objects in a worker context. Worker threads don&apos;t even have CFRunLoops to schedule timers on.
&gt; 
&gt; Is this patch correct?

What Geoff said.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405513</commentid>
    <comment_count>9</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-05-17 21:57:57 -0700</bug_when>
    <thetext>Thanks. I verified that &quot;run-webkit-tests fast/workers --leaks&quot; reports no leaks.

What about arbitrary clients of JSC API? These still don&apos;t need to have a CFRunLoop, which DefaultGCActivityCallback seems to require.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405677</commentid>
    <comment_count>10</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2011-05-18 06:38:39 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; (In reply to comment #4)
&gt; &gt; What&apos;s the motivation for this? Neither this bug nor the ChangeLog say!
&gt; 
&gt; The motivation is to coalesce garbage collections that are triggered as a result of releasing a global context.  Otherwise, repeated calls to JSGlobalContextRelease would each trigger a full collection, where one at the end would be much better.
&gt; 
&gt; As a general rule, synchronous full garbage collection should be avoided as it is very expensive, and should definitely not happen unexpectedly as was happening with JSGlobalContextRelease.

Thanks, Sam!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405976</commentid>
    <comment_count>11</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2011-05-18 13:10:30 -0700</bug_when>
    <thetext>&gt; What about arbitrary clients of JSC API? These still don&apos;t need to have a CFRunLoop, which DefaultGCActivityCallback seems to require.

As we&apos;ve discussed before, on CF platforms, DefaultGCActivityCallback is optimized for CFRunLoop, but doesn&apos;t require it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405987</commentid>
    <comment_count>12</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-05-18 13:20:59 -0700</bug_when>
    <thetext>For my education, could you please describe how it works without CFRunLoop?

The only call to heap-&gt;collectAllGarbage() in CGActivityCallbackCF.cpp is in DefaultGCActivityCallbackPlatformData::trigger(), and the only call to trigger() is through a CFRunLoopTimer. This is the only GCActivityCallback subclass in JSC.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>405988</commentid>
    <comment_count>13</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2011-05-18 13:23:27 -0700</bug_when>
    <thetext>(In reply to comment #12)
&gt; For my education, could you please describe how it works without CFRunLoop?

If a CF-configured client doesn&apos;t run the CFRunLoop, DefaultGCActivityCallback&apos;s optimization to GC from the runloop just doesn&apos;t kick in.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>406008</commentid>
    <comment_count>14</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-05-18 13:54:58 -0700</bug_when>
    <thetext>&gt; DefaultGCActivityCallback&apos;s optimization to GC from the runloop just doesn&apos;t kick in

This patch replaced code that works in such threads (globalData.heap.collectAllGarbage()) with code that&apos;s effectively no-op. Are you saying that this is OK?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>406009</commentid>
    <comment_count>15</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2011-05-18 14:00:30 -0700</bug_when>
    <thetext>&gt; This patch replaced code that works in such threads (globalData.heap.collectAllGarbage()) with code that&apos;s effectively no-op. Are you saying that this is OK?

I don&apos;t think that&apos;s an accurate characterization. The old code didn&apos;t &quot;work.&quot; It sometimes eagerly reclaimed memory, sometimes didn&apos;t eagerly reclaim memory, and sometimes caused O(N^2) hangs.

The new code does coalesced attempts at reclaiming memory on threads that run the CFRunLoop, and nothing on threads that don&apos;t. Whether that&apos;s OK or not depends on the thread and its requirements. On all the threads that I&apos;ve observed in WebKit, the new code resolves the O(N^2) issue without a regression in memory use.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>406041</commentid>
    <comment_count>16</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-05-18 14:54:59 -0700</bug_when>
    <thetext>The code was added a long time ago (http://trac.webkit.org/changeset/35917), and unfortunately, the commit that added it didn&apos;t have a lot of detail in ChangeLog. All I remember is that non-WebKit JavaScriptCore API clients&apos; needs dictated when JSGlobalContextRelease should perform GC.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>93818</attachid>
            <date>2011-05-17 14:47:26 -0700</date>
            <delta_ts>2011-05-17 15:31:19 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-60990-20110517144725.patch</filename>
            <type>text/plain</type>
            <size>1989</size>
            <attacher name="Sam Weinig">sam</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gODY3MDcpCisrKyBTb3VyY2Uv
SmF2YVNjcmlwdENvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBAIC0xLDMgKzEsMTQgQEAK
KzIwMTEtMDUtMTcgIFNhbSBXZWluaWcgIDxzYW1Ad2Via2l0Lm9yZz4KKworICAgICAgICBSZXZp
ZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAgICB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l2aXR5
Q2FsbGJhY2soKSkoKTsKKyAgICB9CiAKICAgICBnbG9iYWxEYXRhLmRlcmVmKCk7CiAK
</data>
<flag name="review"
          id="87045"
          type_id="1"
          status="+"
          setter="oliver"
    />
          </attachment>
      

    </bug>

</bugzilla>