Bug 27628

Summary: [v8] Simplify weak handlers callback
Product: WebKit Reporter: anton muhin <antonm>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, ager, christian.plesner.hansen, iposva
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Initial version
abarth: review-
Addressing Adam's comments
abarth: review-
Second round
abarth: review-
The right one
none
Fixing a minor type (should have used plural) abarth: review+

anton muhin
Reported 2009-07-23 15:52:22 PDT
As current wisdom is Nodes should be only managed from main thread, that simplifies management of near to death DOM nodes notably.
Attachments
Initial version (1.52 KB, patch)
2009-07-23 16:11 PDT, anton muhin
abarth: review-
Addressing Adam's comments (1.93 KB, patch)
2009-07-24 02:22 PDT, anton muhin
abarth: review-
Second round (1.93 KB, patch)
2009-07-24 04:14 PDT, anton muhin
abarth: review-
The right one (2.03 KB, patch)
2009-07-26 21:59 PDT, anton muhin
no flags
Fixing a minor type (should have used plural) (2.03 KB, patch)
2009-07-26 22:08 PDT, anton muhin
abarth: review+
anton muhin
Comment 1 2009-07-23 16:11:20 PDT
Created attachment 33390 [details] Initial version I'd say management of DOM node map should be simplidied, esp. fi Adam's patcj is in.
anton muhin
Comment 2 2009-07-23 19:34:54 PDT
Comment on attachment 33390 [details] Initial version Sorry, forgot to mark as a patch
anton muhin
Comment 3 2009-07-23 19:36:11 PDT
Comment on attachment 33390 [details] Initial version > Index: third_party/WebKit/WebCore/ChangeLog > =================================================================== > --- third_party/WebKit/WebCore/ChangeLog (revision 46295) > +++ third_party/WebKit/WebCore/ChangeLog (working copy) > @@ -1,3 +1,13 @@ > +2009-07-23 Anton Muhin <antonm@chromium.org> > + > + Reviewed by NOBODY (OOPS!). > + > + Simplify management of Nodes in weak handles callbacks. > + https://bugs.webkit.org/show_bug.cgi?id=27628 > + > + * bindings/v8/V8DOMMap.cpp: > + (WebCore::weakNodeCallback): > + > 2009-07-23 Dan Bernstein <mitz@apple.com> > > Reviewed by Dave Hyatt. > Index: third_party/WebKit/WebCore/bindings/v8/V8DOMMap.cpp > =================================================================== > --- third_party/WebKit/WebCore/bindings/v8/V8DOMMap.cpp (revision 46194) > +++ third_party/WebKit/WebCore/bindings/v8/V8DOMMap.cpp (working copy) > @@ -504,9 +504,12 @@ void weakActiveDOMObjectCallback(v8::Per > > static void weakNodeCallback(v8::Persistent<v8::Value> v8Object, void* domObject) > { > - v8::HandleScope scope; > - ASSERT(v8Object->IsObject()); > - DOMData::handleWeakObject<Node>(DOMDataStore::DOMNodeMap, v8::Handle<v8::Object>::Cast(v8Object), static_cast<Node*>(domObject)); > + DOMDataStore* store = DOMDataStore::allStores()[0]; > + DOMDataStore::InternalDOMWrapperMap<Node>& domMap = store->domNodeMap(); > + Node* node = static_cast<Node*>(domObject); > + v8Object.Dispose(); > + domMap.impl().remove(node); > + node->deref(); // Nobody overrides Node::deref so it's safe > } > > #if ENABLE(SVG) The code to retrieve DOM Node map should be merged with Adam's patch obviously.
Adam Barth
Comment 4 2009-07-23 23:47:26 PDT
Comment on attachment 33390 [details] Initial version + DOMDataStore* store = DOMDataStore::allStores()[0]; Why is it sufficient only to look in the zeroth DOMDataStore? What about the DOMDataStore for isolated worlds?
Christian Plesner Hansen
Comment 5 2009-07-24 01:03:27 PDT
I'm still a little unclear on how the dom node mappings work. This only works for nodes on the main thread right? So with Adam's changes you would use DOMData::getCurrentMainThread()->getStore().domNodeMap() instead?
Adam Barth
Comment 6 2009-07-24 01:12:12 PDT
(In reply to comment #5) > I'm still a little unclear on how the dom node mappings work. This only works > for nodes on the main thread right? So with Adam's changes you would use > DOMData::getCurrentMainThread()->getStore().domNodeMap() instead? You can try that, but it will crash because we're in the middle of a GC. :) That's why we iterate currently.
Christian Plesner Hansen
Comment 7 2009-07-24 01:25:40 PDT
Okay. Maybe not such a good idea then.
anton muhin
Comment 8 2009-07-24 02:22:32 PDT
Created attachment 33415 [details] Addressing Adam's comments Thanks a lot, Adam. May you have another look?
Adam Barth
Comment 9 2009-07-24 02:45:59 PDT
Comment on attachment 33415 [details] Addressing Adam's comments This patch is still incorrect. - v8::HandleScope scope; Don't we need a handle scope before talking to handles? - ASSERT(v8Object->IsObject()); Why drop this assert? + ASSERT(store->domData()->owningThread() == WTF::currentThread()); This assert is bogus. Some of DOMDataStores belong to worker threads. Here's what you should do: 1) Acquire the mutex before iterating through the list because items might be inserted or removed on another thread. 2) Move the ASSERT to after + if (it == domMapImpl.end() || it->second != *v8Object) At that point, you've found a DOMDataStore that holds a Node and it must be on the main thread.
anton muhin
Comment 10 2009-07-24 04:14:14 PDT
Created attachment 33424 [details] Second round Thanks a lot for another round, Adam. Answering in comments.
anton muhin
Comment 11 2009-07-24 04:16:10 PDT
(In reply to comment #9) > (From update of attachment 33415 [details]) > This patch is still incorrect. > > - v8::HandleScope scope; > > Don't we need a handle scope before talking to handles? We don't create any handles and thus I don't think we need it, but, please, double check. > > - ASSERT(v8Object->IsObject()); > > Why drop this assert? I can easily revive it. My thought was it was originally necessary due to the cast below (which would check the type anyway, btw). No I don't do that cast and hence why ASSERT? > > + ASSERT(store->domData()->owningThread() == WTF::currentThread()); > > This assert is bogus. Some of DOMDataStores belong to worker threads. > > Here's what you should do: > > 1) Acquire the mutex before iterating through the list because items might be > inserted or removed on another thread. > > 2) Move the ASSERT to after > > + if (it == domMapImpl.end() || it->second != *v8Object) > > At that point, you've found a DOMDataStore that holds a Node and it must be on > the main thread. You're absolutely right, I wasn't attentive enough.
Adam Barth
Comment 12 2009-07-24 10:41:21 PDT
Comment on attachment 33424 [details] Second round I think you mistakenly uploaded the old version of the patch.
anton muhin
Comment 13 2009-07-26 21:59:28 PDT
Created attachment 33518 [details] The right one
anton muhin
Comment 14 2009-07-26 22:08:37 PDT
Created attachment 33519 [details] Fixing a minor type (should have used plural)
anton muhin
Comment 15 2009-07-26 22:09:07 PDT
(In reply to comment #12) > (From update of attachment 33424 [details]) > I think you mistakenly uploaded the old version of the patch. I am very sorry, Adam, may you have a look now?
Adam Barth
Comment 16 2009-07-26 22:19:21 PDT
Comment on attachment 33519 [details] Fixing a minor type (should have used plural) This is great. Thanks for iterating on this.
anton muhin
Comment 17 2009-07-27 01:34:18 PDT
(In reply to comment #16) > (From update of attachment 33519 [details]) > This is great. Thanks for iterating on this. Thanks a lot for review, Adam!
Adam Barth
Comment 18 2009-07-27 02:12:45 PDT
I would land this, except the canary isn't compiling.
anton muhin
Comment 19 2009-07-27 02:36:48 PDT
(In reply to comment #18) > I would land this, except the canary isn't compiling. It used to compile. Let me sync to the most recent version and update the patch.
Adam Barth
Comment 21 2009-07-28 01:27:09 PDT
Committing to http://svn.webkit.org/repository/webkit/trunk ... M WebCore/ChangeLog M WebCore/bindings/v8/DOMDataStore.cpp Committed r46462 M WebCore/ChangeLog M WebCore/bindings/v8/DOMDataStore.cpp r46462 = f0f290bb233ca9ad7eef395908089c6c4f307085 (trunk) No changes between current HEAD and refs/remotes/trunk Resetting to the latest refs/remotes/trunk http://trac.webkit.org/changeset/46462
Note You need to log in before you can comment on or make changes to this bug.