Bug 156472

Summary: Clean up IDBBindingUtilities
Product: WebKit Reporter: Brady Eidson <beidson>
Component: WebCore Misc.Assignee: Brady Eidson <beidson>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, alecflett, cdumez, cgarcia, commit-queue, darin, esprehn+autocc, jiewen_tan, jsbell, kangil.han, kondapallykalyan
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 156483    
Bug Blocks: 149117    
Attachments:
Description Flags
Patch v1
achristensen: review+
New patch v1
none
New patch v2
none
New patch v3 none

Description Brady Eidson 2016-04-11 11:53:32 PDT
Clean up IDBBindingUtilities massively
Comment 1 Brady Eidson 2016-04-11 13:16:25 PDT
Created attachment 276168 [details]
Patch v1
Comment 2 Alex Christensen 2016-04-11 13:32:53 PDT
Comment on attachment 276168 [details]
Patch v1

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

looks great!

> Source/WebCore/Modules/indexeddb/IDBCursorWithValue.idl:33
> +    [CallWith=ScriptState, ImplementationReturnType=JSValue] readonly attribute any value;

It would be nice if the default return value were JSValue and we had to add something to make it Deprecated::ScriptValue.
Comment 3 Brady Eidson 2016-04-11 13:39:21 PDT
(In reply to comment #2)
> Comment on attachment 276168 [details]
> Patch v1
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=276168&action=review
> 
> looks great!
> 
> > Source/WebCore/Modules/indexeddb/IDBCursorWithValue.idl:33
> > +    [CallWith=ScriptState, ImplementationReturnType=JSValue] readonly attribute any value;
> 
> It would be nice if the default return value were JSValue and we had to add
> something to make it Deprecated::ScriptValue.

I think this will be an awesome idea to implement in a patch dedicated to it.

One patch that touches the code generator and many many many IDLs all at once.
Comment 4 Brady Eidson 2016-04-11 14:34:22 PDT
http://trac.webkit.org/changeset/199310
Comment 5 WebKit Commit Bot 2016-04-11 16:46:45 PDT
Re-opened since this is blocked by bug 156483
Comment 6 Jiewen Tan 2016-04-11 16:57:07 PDT
Rolled out in r199323: <http://trac.webkit.org/changeset/199323>.

Potential tests, which this change turns into crashes:
https://build.webkit.org/results/Apple%20El%20Capitan%20Debug%20WK2%20(Tests)/r199312%20(4344)/results.html
storage/indexeddb/cursor-continue-validity.html
storage/indexeddb/cursor-request-cycle-private.html
storage/indexeddb/cursor-value.html

https://build.webkit.org/results/Apple%20Yosemite%20Debug%20WK2%20(Tests)/r199314%20(11347)/results.html
imported/w3c/web-platform-tests/IndexedDB/idbindex-multientry-big.htm
storage/indexeddb/cursor-request-cycle-private.html
storage/indexeddb/cursor-value.html
Comment 7 Darin Adler 2016-04-11 17:49:27 PDT
I am pretty sure the reason these tests were failing is that we had JSValue data members in IDBAny and IDBCursor objects that are not on the stack. We need to use smart pointers instead.
Comment 8 Brady Eidson 2016-04-13 22:45:46 PDT
Working on an updated version of this.

There will need to be some "smart pointer to JSValue" changes (namely JSC::Strong<JSC::Unknown>) as well as some addOpaqueRoot / containsOpaqueRoot dancing.
Comment 9 Brady Eidson 2016-04-14 10:08:01 PDT
(In reply to comment #8)
> Working on an updated version of this.
> 
> There will need to be some "smart pointer to JSValue" changes (namely
> JSC::Strong<JSC::Unknown>) as well as some addOpaqueRoot /
> containsOpaqueRoot dancing.

Actually for now I'm just going to use JSC::Strong<JSC::Unknown>s wherever we used to use Deprecated::ScriptValue, as that is literally a zero-change in behavior.

Anywhere use of D:SV might has caused a leak before, Strong<Unknown> will cause the same leak now.

Fixing those potential leaks is something we can do in a followup.
Comment 10 Brady Eidson 2016-04-14 11:23:20 PDT
Created attachment 276407 [details]
New patch v1

Not marking for review yet until I run all layout tests in a few different configs.
Comment 11 Darin Adler 2016-04-14 12:27:10 PDT
(In reply to comment #9)
> Actually for now I'm just going to use JSC::Strong<JSC::Unknown>s wherever
> we used to use Deprecated::ScriptValue, as that is literally a zero-change
> in behavior.

Sounds exactly right.

At some point, worth studying to find out whether there are any already-existing reference cycles.
Comment 12 Brady Eidson 2016-04-14 13:08:11 PDT
(In reply to comment #11)
> (In reply to comment #9)
> > Actually for now I'm just going to use JSC::Strong<JSC::Unknown>s wherever
> > we used to use Deprecated::ScriptValue, as that is literally a zero-change
> > in behavior.
> 
> Sounds exactly right.
> 
> At some point, worth studying to find out whether there are any
> already-existing reference cycles.

It's trivial to create one with the existing code.

e.g. - Iterate a cursor, and then set a property on the cursor's current value to be the cursor itself.

cursor.value.foo = cursor;

That's something that proper opaque roots will fix.
Comment 13 Brady Eidson 2016-04-14 13:08:51 PDT
Obviously the new patch missed at least one niggling little detail. I'll revisit it soon, but it's not critical ATM.
Comment 14 Darin Adler 2016-04-14 13:35:10 PDT
I think the reference cycle issue is more important than the refactoring and cleanup being done by this patch. I’d also be happy to help resolve it. I wonder what the best way to write a regression test for the cycles is?
Comment 15 Darin Adler 2016-04-14 14:15:29 PDT
(In reply to comment #13)
> Obviously the new patch missed at least one niggling little detail. I'll
> revisit it soon, but it's not critical ATM.

That one niggling detail is a missing include of "ScriptExecutionContext.h" in IDBBindingUtilities.cpp.
Comment 16 Brady Eidson 2016-04-14 15:39:23 PDT
(In reply to comment #15)
> (In reply to comment #13)
> > Obviously the new patch missed at least one niggling little detail. I'll
> > revisit it soon, but it's not critical ATM.
> 
> That one niggling detail is a missing include of "ScriptExecutionContext.h"
> in IDBBindingUtilities.cpp.

And this demonstrates you went through the trouble of looking at the EWS failures, instead of just noting "EWS failed" and resolving to revisit later  :)
Comment 17 Brady Eidson 2016-04-14 15:43:02 PDT
(In reply to comment #14)
> I think the reference cycle issue is more important than the refactoring and
> cleanup being done by this patch. I’d also be happy to help resolve it. 

No argument there. I just did this because I was touching the binding utilities for other reasons, and I'd been wanting to.

We have a bug for ref-cycles and leaks - https://bugs.webkit.org/show_bug.cgi?id=154015 - but no sub-task filed for this quite yet.

> I wonder what the best way to write a regression test for the cycles is?

That is, indeed, the challenge. There's a group of skipped IDB tests marked in TestExpectations with:
# Relies on internals.observeGC

That's how the chromium port + V8 detected these types of things back when they were part of the project. I don't think we have a replacement. 

Months ago when I discussed it with him, Geoff mentioned he thought having our own form of that would be both doable and desirable.
Comment 18 Darin Adler 2016-04-14 19:04:36 PDT
On a local branch I got rid of the IDBAny class entirely and replaced it with some custom bindings. I hope you land this soon; then I will merge and post that and try to whip it into shape.
Comment 19 Brady Eidson 2016-04-14 20:53:22 PDT
(In reply to comment #18)
> On a local branch I got rid of the IDBAny class entirely and replaced it
> with some custom bindings. I hope you land this soon; then I will merge and
> post that and try to whip it into shape.

That's crazy exciting.

I'll make sure I get this landed tomorrow before IDB'y things diverge much more.
Comment 20 Brady Eidson 2016-04-15 22:59:45 PDT
Created attachment 276548 [details]
New patch v2
Comment 21 Brady Eidson 2016-04-16 15:55:20 PDT
Created attachment 276566 [details]
New patch v3
Comment 22 Brady Eidson 2016-04-17 10:58:24 PDT
I think our understanding of what went wrong first time is obviously right. Ran lots of tests locally, EWS passed, etc etc

Let's land this.
Comment 23 WebKit Commit Bot 2016-04-17 11:49:40 PDT
Comment on attachment 276566 [details]
New patch v3

Clearing flags on attachment: 276566

Committed r199643: <http://trac.webkit.org/changeset/199643>
Comment 24 Brady Eidson 2016-04-17 12:45:33 PDT
Conrad has landed some "debug build" fix attempts in http://trac.webkit.org/changeset/199645 and http://trac.webkit.org/changeset/199646.

I built debug locally, as did mac-debug EWS...  =/
Comment 25 Darin Adler 2016-04-17 14:30:12 PDT
Those fixes are needed due to the combination of your patch and my patch. Separately each compiled. Together, they required these new includes.

Not really "debug build specific" as far as I can tell.
Comment 26 Brady Eidson 2016-04-17 14:35:26 PDT
(In reply to comment #25)
> Those fixes are needed due to the combination of your patch and my patch.
> Separately each compiled. Together, they required these new includes.
> 
> Not really "debug build specific" as far as I can tell.

I figured this out shortly after apologizing to Conrad for the breakage.

Our two patches revealed an interesting race condition in the CQ bot - My build started before yours landed, which is why CQ cleared it.

Annoying, but probably not all-too-common an occurrence.
Comment 27 Chris Dumez 2016-04-18 16:01:20 PDT
Comment on attachment 276566 [details]
New patch v3

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

> Source/WebCore/dom/ScriptExecutionContext.cpp:497
> +    WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(this);

Why isn't this using a downcast<>() ?