Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Issue 21274004: Fix Document leak from NodeFilter. (Closed)

Created:
7 years, 4 months ago by kouhei (in TOK)
Modified:
7 years, 4 months ago
CC:
blink-reviews, Nils Barth (inactive), kojih, jsbell+bindings_chromium.org, eae+blinkwatch, marja+watch_chromium.org, dglazkov+blink, adamk+blink_chromium.org, haraken, Nate Chapin, do-not-use
Visibility:
Public.

Description

Fix Document leak from NodeFilter. * Problem Description When NodeIterator/TreeWalker with filter JS callback is created, the following reference chain was created: NodeIterator -(RefPtr)-> NodeFilter -(RefPtr)-> V8NodeFilterCondition -(ScopedPersistent)-> JS callback object -> window This caused the whole document to be leaked when NodeIterator was referenced from window. For example, the following script created a circular reference which could not be collected. <script> window.foobar = document.createNodeIterator(document, NodeFilter.SHOW_ELEMENT, function(node) { return NodeFilter.FILTER_ACCEPT; }); </script> * Proposal This patch modifies the reference chain to avoid leak. The basic idea is to move the callback's whole reference chain to the V8 side. We change the strong reference to the JS callback object held by V8NodeFilterCondition to a weak reference. The JS callback is instead kept alive by a wrapper of NodeFilter, referenced from NodeIterator wrapper. The new reference chain is illustrated as follows: Blink world: NodeIterator -(RefPtr)-> NodeFilter -(RefPtr)-> V8NodeFilterCondition ^^^ ^^^ vvv(weakref)vvv V8 world: NodeIterator wrap -(HiddenProperty)-> NodeFilter wrap -(HiddenProperty)-> JS callback obj. -> window The new reference chain can be collected correctly, as the whole circular reference chain is visible from V8 GC. BUG=None Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=155425

Patch Set 1 #

Total comments: 7

Patch Set 2 : added overcollect test, passing. #

Patch Set 3 : add leak test / passing #

Patch Set 4 : refactor / fix createTreeWalker #

Patch Set 5 : add TreeWalker leak test #

Total comments: 15

Patch Set 6 : update LayoutTests #

Patch Set 7 : fix layouttests failing #

Patch Set 8 : use customToV8 #

Patch Set 9 : add assertions to wrap #

Total comments: 25

Patch Set 10 : introduce leak-check.js / styling fix #

Patch Set 11 : update expectations #

Total comments: 11

Patch Set 12 : fixed broken selection test #

Patch Set 13 : added haraken's illustration :) / styling fixes #

Patch Set 14 : don't print numberOfLiveDocuments when test passed #

Unified diffs Side-by-side diffs Delta from patch set Stats (+264 lines, -85 lines) Patch
M LayoutTests/editing/selection/leak-document-with-selection-inside.html View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +14 lines, -39 lines 0 comments Download
M LayoutTests/editing/selection/leak-document-with-selection-inside-expected.txt View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +2 lines, -2 lines 0 comments Download
A LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html View 1 2 3 4 5 1 chunk +34 lines, -0 lines 0 comments Download
A LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect-expected.txt View 1 2 3 4 5 1 chunk +10 lines, -0 lines 0 comments Download
A LayoutTests/fast/dom/NodeIterator/NodeIterator-leak-document.html View 1 2 3 4 5 6 7 8 9 1 chunk +18 lines, -0 lines 0 comments Download
A LayoutTests/fast/dom/NodeIterator/NodeIterator-leak-document-expected.txt View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +5 lines, -0 lines 0 comments Download
A LayoutTests/fast/dom/TreeWalker/TreeWalker-leak-document.html View 1 2 3 4 5 6 7 8 9 1 chunk +18 lines, -0 lines 0 comments Download
A LayoutTests/fast/dom/TreeWalker/TreeWalker-leak-document-expected.txt View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +5 lines, -0 lines 0 comments Download
A LayoutTests/fast/dom/resources/leak-check.js View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +68 lines, -0 lines 0 comments Download
Source/bindings/bindings.gypi View 1 2 3 4 5 6 7 2 chunks +2 lines, -0 lines 0 comments Download
M Source/bindings/scripts/deprecated_code_generator_v8.pm View 1 4 5 6 7 1 chunk +1 line, -1 line 0 comments Download
M Source/bindings/v8/V8Binding.h View 4 5 6 7 1 chunk +1 line, -1 line 0 comments Download
M Source/bindings/v8/V8Binding.cpp View 1 2 3 4 5 6 7 8 9 2 chunks +11 lines, -2 lines 0 comments Download
M Source/bindings/v8/V8HiddenPropertyName.h View 1 chunk +1 line, -0 lines 0 comments Download
M Source/bindings/v8/V8NodeFilterCondition.h View 1 2 3 4 5 6 7 8 9 10 11 12 2 chunks +25 lines, -3 lines 0 comments Download
M Source/bindings/v8/V8NodeFilterCondition.cpp View 1 3 chunks +10 lines, -1 line 0 comments Download
A + Source/bindings/v8/custom/V8NodeIteratorCustom.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +14 lines, -17 lines 0 comments Download
A + Source/bindings/v8/custom/V8TreeWalkerCustom.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +14 lines, -17 lines 0 comments Download
M Source/core/dom/NodeFilter.h View 1 chunk +5 lines, -0 lines 0 comments Download
M Source/core/dom/NodeIterator.idl View 1 2 3 4 5 6 7 1 chunk +3 lines, -1 line 0 comments Download
M Source/core/dom/TreeWalker.idl View 1 2 3 4 5 6 7 1 chunk +3 lines, -1 line 0 comments Download

Messages

Total messages: 21 (0 generated)
kouhei (in TOK)
The second leak detected from auto GC leak finder. Reproducing LayoutTest testcase to be added.
7 years, 4 months ago (2013-07-31 05:57:56 UTC) #1
abarth-chromium
Oh, I'm so glad you're fixing this leak. It's been on my list for a ...
7 years, 4 months ago (2013-07-31 06:04:14 UTC) #2
abarth-chromium
7 years, 4 months ago (2013-07-31 06:04:24 UTC) #3
kouhei (in TOK)
Thank you for your comments! > Oh, I'm so glad you're fixing this leak. It's ...
7 years, 4 months ago (2013-07-31 06:21:34 UTC) #4
abarth-chromium
I just look for ScriptValue/ScriptObject/ScopedPersistent being stored in DOM objects. Any time we do that ...
7 years, 4 months ago (2013-07-31 06:28:45 UTC) #5
haraken
Thanks for working on this. I'm very happy you're detecting and fixing *actual* leaks one ...
7 years, 4 months ago (2013-07-31 06:46:12 UTC) #6
dominicc (has gone to gerrit)
DBC inline I look forward to seeing the test. I don't understand what is going ...
7 years, 4 months ago (2013-07-31 14:09:55 UTC) #7
kouhei (in TOK)
Thank you for comments! I refactored the patch. It should be ready for review now. ...
7 years, 4 months ago (2013-08-01 01:12:24 UTC) #8
haraken
https://codereview.chromium.org/21274004/diff/21001/LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html File LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html (right): https://codereview.chromium.org/21274004/diff/21001/LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html#newcode30 LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html:30: shouldBeTrue("callbackObservation.wasCollected", "The callback should be collected when nodeIterator is ...
7 years, 4 months ago (2013-08-01 03:44:14 UTC) #9
dominicc (has gone to gerrit)
https://codereview.chromium.org/21274004/diff/21001/LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html File LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html (right): https://codereview.chromium.org/21274004/diff/21001/LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html#newcode18 LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html:18: callback = null; For style, I would put this ...
7 years, 4 months ago (2013-08-01 04:51:12 UTC) #10
kouhei (in TOK)
Thank you for your comments! Pushed some styling fixes... https://codereview.chromium.org/21274004/diff/21001/LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html File LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html (right): https://codereview.chromium.org/21274004/diff/21001/LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html#newcode18 LayoutTests/fast/dom/NodeIterator/NodeIterator-dont-overcollect.html:18: ...
7 years, 4 months ago (2013-08-01 05:09:53 UTC) #11
kouhei (in TOK)
> I had offline discussion with haraken. The conclusion is to modify the binding > ...
7 years, 4 months ago (2013-08-01 08:33:33 UTC) #12
haraken
The approach looks good! https://codereview.chromium.org/21274004/diff/40001/LayoutTests/fast/dom/NodeFilterCondition-leak-document.html File LayoutTests/fast/dom/NodeFilterCondition-leak-document.html (right): https://codereview.chromium.org/21274004/diff/40001/LayoutTests/fast/dom/NodeFilterCondition-leak-document.html#newcode49 LayoutTests/fast/dom/NodeFilterCondition-leak-document.html:49: frame.src = src; I'm sorry ...
7 years, 4 months ago (2013-08-01 13:32:19 UTC) #13
kouhei (in TOK)
Thank you for comments! Updated patch. I introduced fast/dom/resources/leak-check.js to avoid code duplication. haraken: r? ...
7 years, 4 months ago (2013-08-02 03:26:57 UTC) #14
haraken
LGTM. Great patch. https://codereview.chromium.org/21274004/diff/50001/LayoutTests/fast/dom/resources/leak-check.js File LayoutTests/fast/dom/resources/leak-check.js (right): https://codereview.chromium.org/21274004/diff/50001/LayoutTests/fast/dom/resources/leak-check.js#newcode1 LayoutTests/fast/dom/resources/leak-check.js:1: // include ../../js/resources/js-test-pre.js before this file. ...
7 years, 4 months ago (2013-08-02 03:47:59 UTC) #15
kouhei (in TOK)
Thanks for your comments! Updated patch. https://codereview.chromium.org/21274004/diff/50001/LayoutTests/fast/dom/resources/leak-check.js File LayoutTests/fast/dom/resources/leak-check.js (right): https://codereview.chromium.org/21274004/diff/50001/LayoutTests/fast/dom/resources/leak-check.js#newcode1 LayoutTests/fast/dom/resources/leak-check.js:1: // include ../../js/resources/js-test-pre.js ...
7 years, 4 months ago (2013-08-02 04:04:25 UTC) #16
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/kouhei@chromium.org/21274004/58001
7 years, 4 months ago (2013-08-02 04:05:25 UTC) #17
commit-bot: I haz the power
Retried try job too often on linux_blink_rel for step(s) webkit_tests http://build.chromium.org/p/tryserver.chromium/buildstatus?builder=linux_blink_rel&number=881
7 years, 4 months ago (2013-08-02 06:06:51 UTC) #18
kouhei (in TOK)
On 2013/08/02 06:06:51, I haz the power (commit-bot) wrote: > Retried try job too often ...
7 years, 4 months ago (2013-08-02 07:09:18 UTC) #19
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/kouhei@chromium.org/21274004/74001
7 years, 4 months ago (2013-08-02 07:10:16 UTC) #20
commit-bot: I haz the power
7 years, 4 months ago (2013-08-02 09:44:41 UTC) #21
Message was sent while issue was closed.
Change committed as 155425

Powered by Google App Engine
This is Rietveld 408576698