Bug 154273 - Reduce uses of PassRefPtr in indexeddb
Summary: Reduce uses of PassRefPtr in indexeddb
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Gyuyoung Kim
URL:
Keywords:
Depends on: 150854
Blocks: 144092
  Show dependency treegraph
 
Reported: 2016-02-15 18:48 PST by Gyuyoung Kim
Modified: 2016-02-28 17:57 PST (History)
8 users (show)

See Also:


Attachments
Patch (44.42 KB, patch)
2016-02-15 18:50 PST, Gyuyoung Kim
no flags Details | Formatted Diff | Diff
Patch (44.41 KB, patch)
2016-02-16 05:45 PST, Gyuyoung Kim
no flags Details | Formatted Diff | Diff
Patch (17.53 KB, patch)
2016-02-26 06:44 PST, Gyuyoung Kim
no flags Details | Formatted Diff | Diff
Patch (17.69 KB, patch)
2016-02-26 21:16 PST, Gyuyoung Kim
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews100 for mac-yosemite (810.16 KB, application/zip)
2016-02-26 21:54 PST, Build Bot
no flags Details
Archive of layout-test-results from ews105 for mac-yosemite-wk2 (922.62 KB, application/zip)
2016-02-26 21:57 PST, Build Bot
no flags Details
Archive of layout-test-results from ews116 for mac-yosemite (883.39 KB, application/zip)
2016-02-26 22:07 PST, Build Bot
no flags Details
Patch (17.80 KB, patch)
2016-02-27 22:53 PST, Gyuyoung Kim
no flags Details | Formatted Diff | Diff
Patch (17.74 KB, patch)
2016-02-27 23:44 PST, Gyuyoung Kim
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gyuyoung Kim 2016-02-15 18:48:05 PST
SSIA
Comment 1 Gyuyoung Kim 2016-02-15 18:50:55 PST
Created attachment 271403 [details]
Patch
Comment 2 Gyuyoung Kim 2016-02-16 05:45:33 PST
Created attachment 271426 [details]
Patch
Comment 3 Brady Eidson 2016-02-17 20:53:05 PST
Comment on attachment 271426 [details]
Patch

Please hold off on this.

This will interfere with at least one feature patch I have in progress, and also touches "Dead-code-walking" (https://bugs.webkit.org/show_bug.cgi?id=150854)

After 150584 is resolved (Soon!), this would be a great task to revisit.
Comment 4 Gyuyoung Kim 2016-02-17 23:31:01 PST
(In reply to comment #3)
> Comment on attachment 271426 [details]
> Patch
> 
> Please hold off on this.
> 
> This will interfere with at least one feature patch I have in progress, and
> also touches "Dead-code-walking"
> (https://bugs.webkit.org/show_bug.cgi?id=150854)
> 
> After 150584 is resolved (Soon!), this would be a great task to revisit.

I see. Let me update this clean up after landing it.
Comment 5 Gyuyoung Kim 2016-02-26 06:44:06 PST
Created attachment 272324 [details]
Patch
Comment 6 Darin Adler 2016-02-26 07:47:15 PST
Comment on attachment 272324 [details]
Patch

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

Thanks for tackling this.

> Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:94
> +    return IDBKeyRange::create(bound.get(), 0, open ? LowerBoundOpen : LowerBoundClosed, UpperBoundOpen);

This is a case where we’d like to hand over ownership, which shows that we could get better efficiency if IDBKeyRange::create took RefPtr&& arguments rather than pointers; we would use WTFMove here instead of .get(). Also, when touching this line of code, the 0 should be changed to nullptr.

> Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:106
> +    return IDBKeyRange::create(0, bound.get(), LowerBoundOpen, open ? UpperBoundOpen : UpperBoundClosed);

Ditto.

> Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:128
> +    return IDBKeyRange::create(lower.get(), upper.get(), lowerOpen ? LowerBoundOpen : LowerBoundClosed, upperOpen ? UpperBoundOpen : UpperBoundClosed);

Same thing again.

> Source/WebCore/Modules/indexeddb/IDBKeyRange.h:51
> +    static Ref<IDBKeyRange> create(IDBKey* lower, IDBKey* upper, LowerBoundType lowerType, UpperBoundType upperType)

The argument type here should be RefPtr&&, not raw pointers.

> Source/WebCore/Modules/indexeddb/IDBKeyRange.h:55
> +    static Ref<IDBKeyRange> create(IDBKey* prpKey);

The argument type here should be RefPtr&&, not a raw pointer.

> Source/WebCore/Modules/indexeddb/IDBKeyRange.h:56
>      ~IDBKeyRange() { }

This line of code should be removed; does no good.

> Source/WebCore/Modules/indexeddb/IDBKeyRange.h:59
> +    RefPtr<IDBKey> lower() const { return m_lower; }
> +    RefPtr<IDBKey> upper() const { return m_upper; }

The return types here should be raw pointers, not RefPtr.

> Source/WebCore/Modules/indexeddb/IDBKeyRange.h:82
> +    IDBKeyRange(IDBKey* lower, IDBKey* upper, LowerBoundType lowerType, UpperBoundType upperType);

These arguments should be RefPtr&&, not *.

> Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp:71
> -    return IDBKeyRange::create(lowerKey.maybeCreateIDBKey(), upperKey.maybeCreateIDBKey(), lowerOpen ? IDBKeyRange::LowerBoundOpen : IDBKeyRange::LowerBoundClosed, upperOpen ? IDBKeyRange::UpperBoundOpen : IDBKeyRange::UpperBoundClosed);
> +    return IDBKeyRange::create(lowerKey.maybeCreateIDBKey().get(), upperKey.maybeCreateIDBKey().get(), lowerOpen ? IDBKeyRange::LowerBoundOpen : IDBKeyRange::LowerBoundClosed, upperOpen ? IDBKeyRange::UpperBoundOpen : IDBKeyRange::UpperBoundClosed);

This change adds reference count churn. We should not make this change.

> Source/WebCore/inspector/InspectorIndexedDBAgent.cpp:314
> +    return IDBKeyRange::create(idbLower.get(), idbUpper.get(), lowerBoundType, upperBoundType);

This should be using WTFMove, not get().
Comment 7 Gyuyoung Kim 2016-02-26 21:16:54 PST
Created attachment 272398 [details]
Patch
Comment 8 Build Bot 2016-02-26 21:53:57 PST
Comment on attachment 272398 [details]
Patch

Attachment 272398 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/889060

Number of test failures exceeded the failure limit.
Comment 9 Build Bot 2016-02-26 21:54:01 PST
Created attachment 272401 [details]
Archive of layout-test-results from ews100 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews100  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 10 Build Bot 2016-02-26 21:57:35 PST
Comment on attachment 272398 [details]
Patch

Attachment 272398 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/889061

Number of test failures exceeded the failure limit.
Comment 11 Build Bot 2016-02-26 21:57:38 PST
Created attachment 272403 [details]
Archive of layout-test-results from ews105 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews105  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 12 Build Bot 2016-02-26 22:07:11 PST
Comment on attachment 272398 [details]
Patch

Attachment 272398 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/889078

Number of test failures exceeded the failure limit.
Comment 13 Build Bot 2016-02-26 22:07:15 PST
Created attachment 272404 [details]
Archive of layout-test-results from ews116 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews116  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 14 Darin Adler 2016-02-27 16:04:20 PST
Comment on attachment 272398 [details]
Patch

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

review+ assuming you fix the "double move" mistake in the IDBKeyRange::create and IDBKeyRange::only functions that is causing tests to fail

> Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:38
> +Ref<IDBKeyRange> IDBKeyRange::create(RefPtr<IDBKey>&& key)

I don’t think it’s legal to call this function with null. Might be worth coming back here later and changing this to take Ref instead of RefPtr.

> Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:40
> -    RefPtr<IDBKey> key = prpKey;
> -    return adoptRef(*new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed));
> +    return adoptRef(*new IDBKeyRange(WTFMove(key), WTFMove(key), LowerBoundClosed, UpperBoundClosed));

This is wrong. Can’t modify something in two different arguments because the order is undefined. One of the two will probably show up as null. I think that’s why the tests are failing on EWS. Need something like this:

    RefPtr<IDBKey> upperBound = key;
    return adoptRef(*new IDBKeyRange(WTFMove(key), WTFMove(upperBound), LowerBoundClosed, UpperBoundClosed));

> Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:70
>      return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed);

Better to write:

    return create(key);

Unless we are going to delete the create function above that takes only a single argument, we should use it.

> Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:82
> +    return IDBKeyRange::create(WTFMove(key), WTFMove(key), LowerBoundClosed, UpperBoundClosed);

Same problem as above, but since we have an overloaded create function, I think the right way to deal with it is to just write this:

    return create(WTFMove(key));

Unless we are going to delete the create function above that takes only a single argument, we should use it.

I also noticed that many call sites throughout this file call IDBKeyRange::create, but could just call create, since the call sites are inside IDBKeyRange member functions.
Comment 15 Gyuyoung Kim 2016-02-27 22:53:25 PST
Created attachment 272441 [details]
Patch
Comment 16 Gyuyoung Kim 2016-02-27 23:44:46 PST
Created attachment 272446 [details]
Patch
Comment 17 Gyuyoung Kim 2016-02-27 23:48:50 PST
(In reply to comment #14)
> Comment on attachment 272398 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=272398&action=review
> 
> review+ assuming you fix the "double move" mistake in the
> IDBKeyRange::create and IDBKeyRange::only functions that is causing tests to
> fail
> 
> > Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:38
> > +Ref<IDBKeyRange> IDBKeyRange::create(RefPtr<IDBKey>&& key)
> 
> I don’t think it’s legal to call this function with null. Might be worth
> coming back here later and changing this to take Ref instead of RefPtr.
> 
> > Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:40
> > -    RefPtr<IDBKey> key = prpKey;
> > -    return adoptRef(*new IDBKeyRange(key, key, LowerBoundClosed, UpperBoundClosed));
> > +    return adoptRef(*new IDBKeyRange(WTFMove(key), WTFMove(key), LowerBoundClosed, UpperBoundClosed));
> 
> This is wrong. Can’t modify something in two different arguments because the
> order is undefined. One of the two will probably show up as null. I think
> that’s why the tests are failing on EWS. Need something like this:
> 
>     RefPtr<IDBKey> upperBound = key;
>     return adoptRef(*new IDBKeyRange(WTFMove(key), WTFMove(upperBound),
> LowerBoundClosed, UpperBoundClosed));
> 
> > Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:70
> >      return IDBKeyRange::create(key, key, LowerBoundClosed, UpperBoundClosed);
> 
> Better to write:
> 
>     return create(key);
> 
> Unless we are going to delete the create function above that takes only a
> single argument, we should use it.
> 
> > Source/WebCore/Modules/indexeddb/IDBKeyRange.cpp:82
> > +    return IDBKeyRange::create(WTFMove(key), WTFMove(key), LowerBoundClosed, UpperBoundClosed);
> 
> Same problem as above, but since we have an overloaded create function, I
> think the right way to deal with it is to just write this:
> 
>     return create(WTFMove(key));
> 
> Unless we are going to delete the create function above that takes only a
> single argument, we should use it.
> 
> I also noticed that many call sites throughout this file call
> IDBKeyRange::create, but could just call create, since the call sites are
> inside IDBKeyRange member functions.

Yes, I noticed to miss that *key* was already passed to the create() through first WTFMove(). Fixed all. Thanks.
Comment 18 WebKit Commit Bot 2016-02-28 17:57:34 PST
Comment on attachment 272446 [details]
Patch

Clearing flags on attachment: 272446

Committed r197306: <http://trac.webkit.org/changeset/197306>
Comment 19 WebKit Commit Bot 2016-02-28 17:57:39 PST
All reviewed patches have been landed.  Closing bug.