Bug 51723

Summary: Avoid manual ref/deref in AsyncScriptRunner by using PendingScript
Product: WebKit Reporter: Tony Gentilcore <tonyg>
Component: New BugsAssignee: Tony Gentilcore <tonyg>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, buildbot, commit-queue, eric, rniwa, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Other   
OS: OS X 10.5   
Attachments:
Description Flags
Patch
none
Patch
none
Patch for landing none

Tony Gentilcore
Reported 2010-12-29 14:03:01 PST
Avoid manual ref/deref in AsyncScriptRunner by using PendingScript
Attachments
Patch (6.03 KB, patch)
2010-12-29 14:06 PST, Tony Gentilcore
no flags
Patch (6.37 KB, patch)
2011-01-04 10:54 PST, Tony Gentilcore
no flags
Patch for landing (7.02 KB, patch)
2011-01-04 13:32 PST, Tony Gentilcore
no flags
Tony Gentilcore
Comment 1 2010-12-29 14:06:57 PST
Darin Adler
Comment 2 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.
Eric Seidel (no email)
Comment 3 2010-12-30 09:24:19 PST
I would suggest running WebCore/benchmarks/parser/ before landing just to make sure.
Tony Gentilcore
Comment 4 2011-01-04 10:54:58 PST
Tony Gentilcore
Comment 5 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?
Ryosuke Niwa
Comment 6 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?
Tony Gentilcore
Comment 7 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.
Ryosuke Niwa
Comment 8 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.
WebKit Commit Bot
Comment 9 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
Build Bot
Comment 10 2011-01-04 13:28:17 PST
Tony Gentilcore
Comment 11 2011-01-04 13:32:43 PST
Created attachment 77924 [details] Patch for landing
Tony Gentilcore
Comment 12 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.
WebKit Commit Bot
Comment 13 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.
WebKit Commit Bot
Comment 14 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>
WebKit Commit Bot
Comment 15 2011-01-04 21:30:24 PST
All reviewed patches have been landed. Closing bug.
WebKit Review Bot
Comment 16 2011-01-04 22:42:31 PST
http://trac.webkit.org/changeset/75045 might have broken Leopard Intel Debug (Tests)
Note You need to log in before you can comment on or make changes to this bug.