Bug 51723 - Avoid manual ref/deref in AsyncScriptRunner by using PendingScript
Summary: Avoid manual ref/deref in AsyncScriptRunner by using PendingScript
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Tony Gentilcore
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-29 14:03 PST by Tony Gentilcore
Modified: 2011-01-04 22:42 PST (History)
6 users (show)

See Also:


Attachments
Patch (6.03 KB, patch)
2010-12-29 14:06 PST, Tony Gentilcore
no flags Details | Formatted Diff | Diff
Patch (6.37 KB, patch)
2011-01-04 10:54 PST, Tony Gentilcore
no flags Details | Formatted Diff | Diff
Patch for landing (7.02 KB, patch)
2011-01-04 13:32 PST, Tony Gentilcore
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tony Gentilcore 2010-12-29 14:03:01 PST
Avoid manual ref/deref in AsyncScriptRunner by using PendingScript
Comment 1 Tony Gentilcore 2010-12-29 14:06:57 PST
Created attachment 77642 [details]
Patch
Comment 2 Darin Adler 2010-12-29 18:32:33 PST
Comment on attachment 77642 [details]
Patch

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

I’m going to say review+ but I do wonder why the PendingScript changes here were needed at all.

> WebCore/ChangeLog:23
> +        * dom/PendingScript.cpp:
> +        (WebCore::PendingScript::PendingScript):
> +        * dom/PendingScript.h:

No explanation of why you changed this class to no longer inline its constructors. It doesn’t seem required by the rest of the patch. And you didn’t touch the assignment operator. I’m a bit puzzled. Why?

> WebCore/dom/AsyncScriptRunner.cpp:48
>      for (size_t i = 0; i < m_scriptsToExecuteSoon.size(); ++i) {
> -        m_scriptsToExecuteSoon[i].first->element()->deref(); // Balances ref() in executeScriptSoon().
>          m_document->decrementLoadEventDelayCount();
>      }

No braces needed now that this is a 1-line for loop body.

> WebCore/dom/AsyncScriptRunner.cpp:61
> +    PendingScript pendingScript;
> +    pendingScript.adoptElement(element);

Should we make a suitable constructor. It seems it would be better to construct the PendingScript ready to go rather than empty-constructing it and then setting the two pieces separately.

Also, the function name adoptElement is not good! This function doesn’t “adopt” an element. In WebKit we call a function “adopt” when it takes ownership of something in a unusual way, such as when a String takes over storage formerly owned by a Vector or a smart pointer takes a reference in the function adoptRef.

> WebCore/dom/PendingScript.h:44
>  class PendingScript : public CachedResourceClient {

The dual nature of the PendingScript class is not great. We treat these as data objects that we can copy around, but they are also CachedResourceClient objects that can perform loading. It seems impossible to correctly copy one while its loading.

> WebCore/dom/PendingScript.h:47
> +    PendingScript(const PendingScript& other);

No need for the argument name “other” here.
Comment 3 Eric Seidel (no email) 2010-12-30 09:24:19 PST
I would suggest running WebCore/benchmarks/parser/ before landing just to make sure.
Comment 4 Tony Gentilcore 2011-01-04 10:54:58 PST
Created attachment 77908 [details]
Patch
Comment 5 Tony Gentilcore 2011-01-04 10:55:41 PST
> No explanation of why you changed this class to no longer inline its constructors. It doesn’t seem required by the rest of the patch. And you didn’t touch the assignment operator. I’m a bit puzzled. Why?
Reverted.

> No braces needed now that this is a 1-line for loop body.
Done.

> Should we make a suitable constructor. It seems it would be better to construct the PendingScript ready to go rather than empty-constructing it and then setting the two pieces separately.
Agreed. Done.

> Also, the function name adoptElement is not good! This function doesn’t “adopt” an element. In WebKit we call a function “adopt” when it takes ownership of something in a unusual way, such as when a String takes over storage formerly owned by a Vector or a smart pointer takes a reference in the function adoptRef.
Renamed to setElement().

> The dual nature of the PendingScript class is not great. We treat these as data objects that we can copy around, but they are also CachedResourceClient objects that can perform loading. It seems impossible to correctly copy one while its loading.
It is quite possible I am missing something, so please explain if I am. But the CachedResourceClient here is never actually used. It only exist to keep a reference so that the CachedResource's buffer isn't purged. This allows the owner of a PendingScript to not have to worry about the data being purged out from under it.

> No need for the argument name “other” here.
Moot now that it is inlined again.

> I would suggest running WebCore/benchmarks/parser/ before landing just to make sure.
I take it this is moot now that the inlining in PendingScript isn't changed?
Comment 6 Ryosuke Niwa 2011-01-04 11:45:29 PST
Comment on attachment 77908 [details]
Patch

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

> WebCore/dom/AsyncScriptRunner.cpp:87
> +        CachedScript* cachedScript = scripts[i].cachedScript();
> +        RefPtr<Element> element = scripts[i].releaseElementAndClear();
> +        toScriptElement(element.get())->execute(cachedScript);

releaseElementAndClear and ScriptElement::execute BOTH calls m_cachedScript->removeClient().  Are you sure we want to do this?
Comment 7 Tony Gentilcore 2011-01-04 12:49:12 PST
(In reply to comment #6)
> (From update of attachment 77908 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=77908&action=review
> 
> > WebCore/dom/AsyncScriptRunner.cpp:87
> > +        CachedScript* cachedScript = scripts[i].cachedScript();
> > +        RefPtr<Element> element = scripts[i].releaseElementAndClear();
> > +        toScriptElement(element.get())->execute(cachedScript);
> 
> releaseElementAndClear and ScriptElement::execute BOTH calls m_cachedScript->removeClient().  Are you sure we want to do this?

Yes, they are different clients. releaseElementAndClear removes the PendingScript client and execute removes the ScriptElement client.
Comment 8 Ryosuke Niwa 2011-01-04 12:59:44 PST
Comment on attachment 77908 [details]
Patch

(In reply to comment #7)
> > releaseElementAndClear and ScriptElement::execute BOTH calls m_cachedScript->removeClient().  Are you sure we want to do this?
> 
> Yes, they are different clients. releaseElementAndClear removes the PendingScript client and execute removes the ScriptElement client.

OK, now I see it. r=me.
Comment 9 WebKit Commit Bot 2011-01-04 13:21:02 PST
Comment on attachment 77908 [details]
Patch

Rejecting attachment 77908 [details] from commit-queue.

Failed to run "['./Tools/Scripts/webkit-patch', '--status-host=queues.webkit.org', '--bot-id=eseidel-sf-cq', 'build', '--no-clean', '--no-update', '--build-style=both']" exit_code: 2
Last 500 characters of output:
hbc/WebCorePrefix.h -c /Projects/CommitQueue/WebCore/html/HTMLVideoElement.cpp -o /Projects/CommitQueue/WebKitBuild/WebCore.build/Debug/WebCore.build/Objects-normal/x86_64/HTMLVideoElement.o

** BUILD FAILED **


The following build commands failed:
WebCore:
	CompileC /Projects/CommitQueue/WebKitBuild/WebCore.build/Debug/WebCore.build/Objects-normal/x86_64/HTMLScriptRunner.o /Projects/CommitQueue/WebCore/html/parser/HTMLScriptRunner.cpp normal x86_64 c++ com.apple.compilers.gcc.4_2
(1 failure)


Full output: http://queues.webkit.org/results/7345060
Comment 10 Build Bot 2011-01-04 13:28:17 PST
Attachment 77908 [details] did not build on win:
Build output: http://queues.webkit.org/results/7266406
Comment 11 Tony Gentilcore 2011-01-04 13:32:43 PST
Created attachment 77924 [details]
Patch for landing
Comment 12 Tony Gentilcore 2011-01-04 13:36:52 PST
> ** BUILD FAILED **

Was a merge error with http://trac.webkit.org/changeset/74995. Just needed to rename a new call to setElement.
Comment 13 WebKit Commit Bot 2011-01-04 21:29:10 PST
The commit-queue encountered the following flaky tests while processing attachment 77924 [details]:

http/tests/xmlhttprequest/basic-auth.html bug 51613 (author: ap@webkit.org)
The commit-queue is continuing to process your patch.
Comment 14 WebKit Commit Bot 2011-01-04 21:30:17 PST
Comment on attachment 77924 [details]
Patch for landing

Clearing flags on attachment: 77924

Committed r75045: <http://trac.webkit.org/changeset/75045>
Comment 15 WebKit Commit Bot 2011-01-04 21:30:24 PST
All reviewed patches have been landed.  Closing bug.
Comment 16 WebKit Review Bot 2011-01-04 22:42:31 PST
http://trac.webkit.org/changeset/75045 might have broken Leopard Intel Debug (Tests)