Bug 120912 - Support WeakMap
Summary: Support WeakMap
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Oliver Hunt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-06 17:02 PDT by Oliver Hunt
Modified: 2013-09-10 14:15 PDT (History)
11 users (show)

See Also:


Attachments
Patch (76.90 KB, patch)
2013-09-06 17:02 PDT, Oliver Hunt
no flags Details | Formatted Diff | Diff
Patch (51.21 KB, patch)
2013-09-09 15:41 PDT, Oliver Hunt
no flags Details | Formatted Diff | Diff
Patch (51.24 KB, patch)
2013-09-09 16:16 PDT, Oliver Hunt
no flags Details | Formatted Diff | Diff
Patch (58.42 KB, patch)
2013-09-10 13:40 PDT, Oliver Hunt
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Hunt 2013-09-06 17:02:22 PDT
Support WeakMap
Comment 1 Oliver Hunt 2013-09-06 17:02:35 PDT
Created attachment 210818 [details]
Patch
Comment 2 WebKit Commit Bot 2013-09-06 17:05:20 PDT
Attachment 210818 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/JavaScriptCore/ChangeLog', u'Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj', u'Source/JavaScriptCore/heap/WeakImpl.h', u'Source/JavaScriptCore/heap/WeakInlines.h', u'Source/JavaScriptCore/runtime/CommonIdentifiers.h', u'Source/JavaScriptCore/runtime/JSGlobalObject.cpp', u'Source/JavaScriptCore/runtime/JSGlobalObject.h', u'Source/JavaScriptCore/runtime/JSWeakMap.cpp', u'Source/JavaScriptCore/runtime/JSWeakMap.h', u'Source/JavaScriptCore/runtime/WeakMapConstructor.cpp', u'Source/JavaScriptCore/runtime/WeakMapConstructor.h', u'Source/JavaScriptCore/runtime/WeakMapData.cpp', u'Source/JavaScriptCore/runtime/WeakMapData.h', u'Source/JavaScriptCore/runtime/WeakMapPrototype.cpp', u'Source/JavaScriptCore/runtime/WeakMapPrototype.h', u'Source/JavaScriptCore/tests/mozilla/actual.html']" exit_code: 1
Source/JavaScriptCore/runtime/WeakMapData.cpp:57:  Code inside a namespace should not be indented.  [whitespace/indent] [4]
Source/JavaScriptCore/runtime/WeakMapData.cpp:59:  Missing spaces around >>  [whitespace/operators] [3]
Source/JavaScriptCore/runtime/WeakMapData.cpp:69:  Missing spaces around >>  [whitespace/operators] [3]
Source/JavaScriptCore/runtime/WeakMapData.cpp:77:  Missing spaces around >>  [whitespace/operators] [3]
Source/JavaScriptCore/runtime/WeakMapData.cpp:87:  Missing spaces around >>  [whitespace/operators] [3]
Source/JavaScriptCore/runtime/WeakMapData.cpp:96:  Could not find a newline character at the end of the file.  [whitespace/ending_newline] [5]
Source/JavaScriptCore/runtime/WeakMapConstructor.cpp:64:  Could not find a newline character at the end of the file.  [whitespace/ending_newline] [5]
Total errors found: 7 in 16 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Early Warning System Bot 2013-09-06 17:09:50 PDT
Comment on attachment 210818 [details]
Patch

Attachment 210818 [details] did not pass qt-ews (qt):
Output: http://webkit-queues.appspot.com/results/1718207
Comment 4 Early Warning System Bot 2013-09-06 17:11:37 PDT
Comment on attachment 210818 [details]
Patch

Attachment 210818 [details] did not pass qt-wk2-ews (qt-wk2):
Output: http://webkit-queues.appspot.com/results/1705578
Comment 5 Build Bot 2013-09-06 18:37:15 PDT
Comment on attachment 210818 [details]
Patch

Attachment 210818 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/1704539
Comment 6 Build Bot 2013-09-06 19:17:44 PDT
Comment on attachment 210818 [details]
Patch

Attachment 210818 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/1708553
Comment 7 Build Bot 2013-09-06 19:38:49 PDT
Comment on attachment 210818 [details]
Patch

Attachment 210818 [details] did not pass win-ews (win):
Output: http://webkit-queues.appspot.com/results/1707594
Comment 8 EFL EWS Bot 2013-09-06 19:41:41 PDT
Comment on attachment 210818 [details]
Patch

Attachment 210818 [details] did not pass efl-wk2-ews (efl-wk2):
Output: http://webkit-queues.appspot.com/results/1709541
Comment 9 EFL EWS Bot 2013-09-06 19:50:42 PDT
Comment on attachment 210818 [details]
Patch

Attachment 210818 [details] did not pass efl-ews (efl):
Output: http://webkit-queues.appspot.com/results/1718242
Comment 10 kov's GTK+ EWS bot 2013-09-06 20:20:28 PDT
Comment on attachment 210818 [details]
Patch

Attachment 210818 [details] did not pass gtk-ews (gtk):
Output: http://webkit-queues.appspot.com/results/1704565
Comment 11 Sam Weinig 2013-09-07 08:38:44 PDT
Comment on attachment 210818 [details]
Patch

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

> Source/JavaScriptCore/runtime/JSGlobalObject.h:204
>      WriteBarrier<Structure> m_mapDataStructure;
> +    WriteBarrier<Structure> m_weakMapDataStructure;

Does the WeakMapData object's structure need to be per-global object if it is not expose (e.g. can it be per-vm)?  Same question for MapData's structure?
Comment 12 Oliver Hunt 2013-09-07 12:08:55 PDT
(In reply to comment #11)
> (From update of attachment 210818 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=210818&action=review
> 
> > Source/JavaScriptCore/runtime/JSGlobalObject.h:204
> >      WriteBarrier<Structure> m_mapDataStructure;
> > +    WriteBarrier<Structure> m_weakMapDataStructure;
> 
> Does the WeakMapData object's structure need to be per-global object if it is not expose (e.g. can it be per-vm)?  Same question for MapData's structure?

Not strictly but the destructible object is an Object and thus requires a global object :-/

I'm still working on WeakMap so was using this to move the patch around -- it's currently hideously ugly, leaks like a sieve, etc, etc :-/
Comment 13 Oliver Hunt 2013-09-09 15:41:17 PDT
Created attachment 211107 [details]
Patch
Comment 14 Build Bot 2013-09-09 15:59:34 PDT
Comment on attachment 211107 [details]
Patch

Attachment 211107 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/1736433
Comment 15 Early Warning System Bot 2013-09-09 16:02:06 PDT
Comment on attachment 211107 [details]
Patch

Attachment 211107 [details] did not pass qt-ews (qt):
Output: http://webkit-queues.appspot.com/results/1726714
Comment 16 Early Warning System Bot 2013-09-09 16:08:46 PDT
Comment on attachment 211107 [details]
Patch

Attachment 211107 [details] did not pass qt-wk2-ews (qt-wk2):
Output: http://webkit-queues.appspot.com/results/1734446
Comment 17 Oliver Hunt 2013-09-09 16:16:46 PDT
Created attachment 211112 [details]
Patch
Comment 18 Sam Weinig 2013-09-10 03:30:46 PDT
Comment on attachment 211112 [details]
Patch

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

> Source/JavaScriptCore/runtime/JSWeakMap.h:35
> +class JSWeakMap : public JSObject {

Most of these instance classes are derived from JSNonFinalObjects.
Comment 19 Oliver Hunt 2013-09-10 13:40:14 PDT
Created attachment 211234 [details]
Patch
Comment 20 Geoffrey Garen 2013-09-10 13:58:08 PDT
Comment on attachment 211234 [details]
Patch

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

r=me

> Source/JavaScriptCore/ChangeLog:25
> +        (JSC::JSGlobalObject::reset):
> +        (JSC::JSGlobalObject::visitChildren):

I don't like empty function lists like this :(.

> Source/JavaScriptCore/runtime/WeakMapConstructor.cpp:46
> +static EncodedJSValue JSC_HOST_CALL constructWeakMapConstructor(ExecState* exec)

Let's call this "constructWeakMap".

> Source/JavaScriptCore/runtime/WeakMapData.cpp:44
> +    , m_gcCleaner(this)

Let's call this "m_deadKeyCleaner".

> Source/JavaScriptCore/runtime/WeakMapData.cpp:66
> +    // This sin't exact, but it is close enough, and proportional to the actual

Should be "isn't".

> Source/JavaScriptCore/runtime/WeakMapData.cpp:79
> +    auto iter = m_map.find(key);
> +    if (iter != m_map.end()) {
> +        iter->value.set(callFrame->vm(), this, value);
> +        return;
> +    }
> +    // Here we force the write barrier on the key.
> +    m_map.add(WriteBarrier<JSObject>(callFrame->vm(), this, key).get(), WriteBarrier<Unknown>(callFrame->vm(), this, value));

I think it would be better to use the "add 0" idiom here:

auto result = m_map.add(WriteBarrier<JSObject>(callFrame->vm(), this, key).get(), WriteBarrier<Unknown>(callFrame->vm(), this, value));
if (!result.isNewEntry)
    result.iterator->value = value;

This avoids a second hash table lookup in the case where we add a new entry to the table.

> Source/JavaScriptCore/runtime/WeakMapData.cpp:113
> +    for (auto ptr = m_target->m_map.begin(), end = m_target->m_map.end(); ptr != end; ++ptr) {

I think we usually use "it" for iterators.

> Source/JavaScriptCore/runtime/WeakMapData.cpp:131
> +        for (auto ptr = m_target->m_map.begin(), end = m_target->m_map.end(); ptr != end; ++ptr) {

Ditto.

> Source/JavaScriptCore/runtime/WeakMapData.cpp:140
> +        for (auto ptr = m_target->m_map.begin(), end = m_target->m_map.end(); ptr != end; ++ptr) {

Ditto.
Comment 21 Geoffrey Garen 2013-09-10 14:00:10 PDT
> I think it would be better to use the "add 0" idiom here:
> 
> auto result = m_map.add(WriteBarrier<JSObject>(callFrame->vm(), this, key).get(), WriteBarrier<Unknown>(callFrame->vm(), this, value));
> if (!result.isNewEntry)
>     result.iterator->value = value;

I meant:

auto result = m_map.add(WriteBarrier<JSObject>(callFrame->vm(), this, key).get(), WriteBarrier<Unknown>());
Comment 22 Oliver Hunt 2013-09-10 14:15:47 PDT
Committed r155473: <http://trac.webkit.org/changeset/155473>