Bug 107312

Summary: Weak GC maps should be easier to use
Product: WebKit Reporter: Geoffrey Garen <ggaren>
Component: New BugsAssignee: Geoffrey Garen <ggaren>
Status: RESOLVED FIXED    
Severity: Normal CC: jer.noble, naginenis, ossy, ostap73, rniwa, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
For some reason "using" doesn't work on linuxes. Replace it with "typedef".
none
Patch sam: review+

Description Geoffrey Garen 2013-01-18 12:30:34 PST
Weak GC maps should be easier to use
Comment 1 Geoffrey Garen 2013-01-18 12:38:28 PST
Created attachment 183530 [details]
Patch
Comment 2 Geoffrey Garen 2013-01-18 12:38:46 PST
Comment on attachment 183530 [details]
Patch

Sam Weinig reviewed this.
Comment 3 Geoffrey Garen 2013-01-18 12:39:30 PST
Committed r140194: <http://trac.webkit.org/changeset/140194>
Comment 4 Jer Noble 2013-01-18 13:30:52 PST
Build fixes:

Committed r140199: <http://trac.webkit.org/changeset/140199>
Committed r140200: <http://trac.webkit.org/changeset/140200>
Comment 5 Viatcheslav Ostapenko 2013-01-18 13:40:35 PST
Created attachment 183537 [details]
For some reason "using" doesn't  work on linuxes. Replace it with "typedef".
Comment 6 Viatcheslav Ostapenko 2013-01-18 13:41:36 PST
Reopened because of build break.
Comment 7 Ryosuke Niwa 2013-01-18 14:33:03 PST
Comment on attachment 183537 [details]
For some reason "using" doesn't  work on linuxes. Replace it with "typedef".

rs=me.
Comment 8 Ryosuke Niwa 2013-01-18 15:07:05 PST
Committed r140211: <http://trac.webkit.org/changeset/140211>
Comment 9 Csaba Osztrogonác 2013-01-18 15:34:29 PST
You could have avoided 2.5 hours and 20 commit long build breakage ,
if you waited more than 18 seconds for the EWS bots ...
Comment 10 Geoffrey Garen 2013-01-20 16:57:56 PST
Reopening to attach new patch.
Comment 11 Geoffrey Garen 2013-01-20 16:57:59 PST
Created attachment 183692 [details]
Patch
Comment 12 Geoffrey Garen 2013-01-20 17:01:04 PST
Committed r140284: <http://trac.webkit.org/changeset/140284>
Comment 13 Darin Adler 2013-01-21 10:11:01 PST
Comment on attachment 183692 [details]
Patch

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

> Source/JavaScriptCore/runtime/WeakGCMap.h:73
>      AddResult add(const KeyType& key, MappedPassInType value)
>      {
>          gcMapIfNeeded();
> -        AddResult addResult = Base::add(key, value);
> -        if (!addResult.isNewEntry && !addResult.iterator->value) { // Found a zombie value.
> +        AddResult addResult = Base::add(key, nullptr);
> +        if (!addResult.iterator->value) { // New value or found a zombie value.
>              addResult.isNewEntry = true;
>              addResult.iterator->value = value;
>          }

To me this function looks like HashMap::set. Three questions:

1) Why is it right to name the operation add rather than set?
2) Why doesn’t this call Base::set rather than Base::add?
3) Does HashMap::set have the same bug that you fixed here? If not, why not?
Comment 14 Geoffrey Garen 2013-01-30 12:11:09 PST
> 3) Does HashMap::set have the same bug that you fixed here? If not, why not?

I wouldn't call this a bug in HashMap -- it's just a unique feature of weak values.

The key new feature in WeakGCMap, which isn't appropriate for HashSet, is that values can magically become null, and a null value is treated "as if" there were no such entry in the table.

Perhaps HashMap could be extended to support this feature naturally through an additional value trait. Then we could remove WeakGCMap entirely. I'm not sure if that would be appropriate or not.

> 1) Why is it right to name the operation add rather than set?

If there is a non-null value in the table, this function will not overwrite the value.

> 2) Why doesn’t this call Base::set rather than Base::add?

Same reason.