Bug 225108 - Copy-on-write semantics should be an internal implementation detail of StorageMap
Summary: Copy-on-write semantics should be an internal implementation detail of Storag...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-04-27 09:04 PDT by Chris Dumez
Modified: 2021-04-27 13:56 PDT (History)
6 users (show)

See Also:


Attachments
Patch (29.94 KB, patch)
2021-04-27 09:39 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (29.82 KB, patch)
2021-04-27 12:28 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2021-04-27 09:04:41 PDT
Copy-on-write semantics should be an internal implementation details of StorageMap, instead of requiring the client to replace its storageMap explicitly.
Comment 1 Chris Dumez 2021-04-27 09:39:25 PDT
Created attachment 427157 [details]
Patch
Comment 2 Sihui Liu 2021-04-27 11:58:52 PDT
Comment on attachment 427157 [details]
Patch

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

> Source/WebKit/ChangeLog:17
> +        Instead of making the StorageMap RefCounted and requiring the client to potentially
> +        replace its StorageMap whenever it calls functions that modify the StorageMap, the
> +        copy-on-write semantics in now an internal implementation detail of StorageMap.
> +
> +        To achieve this, the following changes were made:
> +        - StorageMap is no longer RefCounted. Instead, it has an internal Impl data member 
> +          that is RefCounted.
> +        - The internal Impl data member is the one that gets copied on write.
> +        - Functions that modify the StorageMap no longer need to return a StorageMap.
> +        - Add a clear() function for convenience.

These seem to belong to WebCore/ChangeLog

> Source/WebKitLegacy/ChangeLog:17
> +        Instead of making the StorageMap RefCounted and requiring the client to potentially
> +        replace its StorageMap whenever it calls functions that modify the StorageMap, the
> +        copy-on-write semantics in now an internal implementation detail of StorageMap.
> +
> +        To achieve this, the following changes were made:
> +        - StorageMap is no longer RefCounted. Instead, it has an internal Impl data member 
> +          that is RefCounted.
> +        - The internal Impl data member is the one that gets copied on write.
> +        - Functions that modify the StorageMap no longer need to return a StorageMap.
> +        - Add a clear() function for convenience.

Ditto

> Source/WebCore/storage/StorageMap.h:57
> +    bool isShared() const { return !m_impl->hasOneRef(); }

(Maybe a silly question) Is this possible to return true with current implementation?
Comment 3 Chris Dumez 2021-04-27 12:02:17 PDT
(In reply to Sihui Liu from comment #2)
> Comment on attachment 427157 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=427157&action=review
> 
> > Source/WebKit/ChangeLog:17
> > +        Instead of making the StorageMap RefCounted and requiring the client to potentially
> > +        replace its StorageMap whenever it calls functions that modify the StorageMap, the
> > +        copy-on-write semantics in now an internal implementation detail of StorageMap.
> > +
> > +        To achieve this, the following changes were made:
> > +        - StorageMap is no longer RefCounted. Instead, it has an internal Impl data member 
> > +          that is RefCounted.
> > +        - The internal Impl data member is the one that gets copied on write.
> > +        - Functions that modify the StorageMap no longer need to return a StorageMap.
> > +        - Add a clear() function for convenience.
> 
> These seem to belong to WebCore/ChangeLog
> 
> > Source/WebKitLegacy/ChangeLog:17
> > +        Instead of making the StorageMap RefCounted and requiring the client to potentially
> > +        replace its StorageMap whenever it calls functions that modify the StorageMap, the
> > +        copy-on-write semantics in now an internal implementation detail of StorageMap.
> > +
> > +        To achieve this, the following changes were made:
> > +        - StorageMap is no longer RefCounted. Instead, it has an internal Impl data member 
> > +          that is RefCounted.
> > +        - The internal Impl data member is the one that gets copied on write.
> > +        - Functions that modify the StorageMap no longer need to return a StorageMap.
> > +        - Add a clear() function for convenience.
> 
> Ditto
> 
> > Source/WebCore/storage/StorageMap.h:57
> > +    bool isShared() const { return !m_impl->hasOneRef(); }
> 
> (Maybe a silly question) Is this possible to return true with current
> implementation?

Sure. See SessionStorageNamespace::cloneTo() and StorageArea::clone(). There are cases where we clone the session data (window.open() & link with target=_blank iirc). In such cases, we initially share the same HashMap to save memory. If one of the 2 pages start modifying the HashMap though, we copy-on-write.
Comment 4 Chris Dumez 2021-04-27 12:28:29 PDT
Created attachment 427182 [details]
Patch
Comment 5 Chris Dumez 2021-04-27 13:55:11 PDT
Comment on attachment 427182 [details]
Patch

Clearing flags on attachment: 427182

Committed r276659 (237086@main): <https://commits.webkit.org/237086@main>
Comment 6 Chris Dumez 2021-04-27 13:55:13 PDT
All reviewed patches have been landed.  Closing bug.
Comment 7 Radar WebKit Bug Importer 2021-04-27 13:56:22 PDT
<rdar://problem/77228667>