Bug 170219 - WebAssembly: option to crash if no fast memory is available
Summary: WebAssembly: option to crash if no fast memory is available
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: JF Bastien
URL:
Keywords:
Depends on:
Blocks: 159775 170242
  Show dependency treegraph
 
Reported: 2017-03-28 17:22 PDT by JF Bastien
Modified: 2017-03-29 09:04 PDT (History)
7 users (show)

See Also:


Attachments
patch (4.92 KB, patch)
2017-03-28 17:24 PDT, JF Bastien
mark.lam: review+
Details | Formatted Diff | Diff
patch (4.97 KB, patch)
2017-03-28 20:20 PDT, JF Bastien
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description JF Bastien 2017-03-28 17:22:24 PDT
.
Comment 1 JF Bastien 2017-03-28 17:24:01 PDT
Created attachment 305680 [details]
patch
Comment 2 Mark Lam 2017-03-28 17:29:03 PDT
Comment on attachment 305680 [details]
patch

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

r=me

> Source/JavaScriptCore/wasm/WasmMemory.cpp:124
> +    if (!fastMemoryEnabled())

nit: if (UNLIKELY(...

> Source/JavaScriptCore/wasm/WasmMemory.cpp:128
> +    if (!vm.getCTIStub(throwExceptionFromWasmThunkGenerator).size())

nit: if (UNLIKELY(...

> Source/JavaScriptCore/wasm/WasmMemory.cpp:129
> +        goto fail;

"goto"!  One of my favorite coding constructs that gets so little use because peeps don't know how to use it right, and fear it.

> Source/JavaScriptCore/wasm/WasmMemory.cpp:139
> +        if (dequeFastMemory())

nit: if (LIKELY(...

> Source/JavaScriptCore/wasm/WasmMemory.cpp:153
> +    if (memory)

nit: if (LIKELY(memory))
Comment 3 JF Bastien 2017-03-28 20:20:19 PDT
Created attachment 305700 [details]
patch

> > Source/JavaScriptCore/wasm/WasmMemory.cpp:139
> > +        if (dequeFastMemory())
> 
> nit: if (LIKELY(...
> 
> > Source/JavaScriptCore/wasm/WasmMemory.cpp:153
> > +    if (memory)
> 
> nit: if (LIKELY(memory))

I don't know that these two are unlikely: they're not options or odd things. They're certainly undesirable, but I wouldn't call them unlikely.

The others you pointed out definitely are, so I marked them appropriately.

> > Source/JavaScriptCore/wasm/WasmMemory.cpp:129
> > +        goto fail;
> 
> "goto"!  One of my favorite coding constructs that gets so little use
> because peeps don't know how to use it right, and fear it.

Am I using it right? :-p
Comment 4 Mark Lam 2017-03-28 20:48:08 PDT
(In reply to JF Bastien from comment #3)
> Created attachment 305700 [details]
> patch
> 
> > > Source/JavaScriptCore/wasm/WasmMemory.cpp:139
> > > +        if (dequeFastMemory())
> > 
> > nit: if (LIKELY(...
> > 
> > > Source/JavaScriptCore/wasm/WasmMemory.cpp:153
> > > +    if (memory)
> > 
> > nit: if (LIKELY(memory))
> 
> I don't know that these two are unlikely: they're not options or odd things.
> They're certainly undesirable, but I wouldn't call them unlikely.

I said "LIKELY", not "UNLIKELY".  That's because the alternative is to fail and crash.  They better be LIKELY.


> The others you pointed out definitely are, so I marked them appropriately.
> 
> > > Source/JavaScriptCore/wasm/WasmMemory.cpp:129
> > > +        goto fail;
> > 
> > "goto"!  One of my favorite coding constructs that gets so little use
> > because peeps don't know how to use it right, and fear it.
> 
> Am I using it right? :-p

Totally. =)
Comment 5 JF Bastien 2017-03-28 20:55:19 PDT
> > I don't know that these two are unlikely: they're not options or odd things.
> > They're certainly undesirable, but I wouldn't call them unlikely.
> 
> I said "LIKELY", not "UNLIKELY".  That's because the alternative is to fail
> and crash.  They better be LIKELY.

It'll only crash if the option is set though. If unset, it'll just return false and generate a slow-mode memory. It's totally normal for this to fail, I just want an option to catch when it does so that I can benchmark knowing we used the fast version!


> > The others you pointed out definitely are, so I marked them appropriately.
> > 
> > > > Source/JavaScriptCore/wasm/WasmMemory.cpp:129
> > > > +        goto fail;
> > > 
> > > "goto"!  One of my favorite coding constructs that gets so little use
> > > because peeps don't know how to use it right, and fear it.
> > 
> > Am I using it right? :-p
> 
> Totally. =)

🎉
Comment 6 WebKit Commit Bot 2017-03-28 21:02:20 PDT
Comment on attachment 305700 [details]
patch

Clearing flags on attachment: 305700

Committed r214526: <http://trac.webkit.org/changeset/214526>
Comment 7 WebKit Commit Bot 2017-03-28 21:02:23 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Saam Barati 2017-03-29 01:24:38 PDT
(In reply to JF Bastien from comment #3)
> Created attachment 305700 [details]
> patch
> 
> > > Source/JavaScriptCore/wasm/WasmMemory.cpp:139
> > > +        if (dequeFastMemory())
> > 
> > nit: if (LIKELY(...
> > 
> > > Source/JavaScriptCore/wasm/WasmMemory.cpp:153
> > > +    if (memory)
> > 
> > nit: if (LIKELY(memory))
> 
> I don't know that these two are unlikely: they're not options or odd things.
> They're certainly undesirable, but I wouldn't call them unlikely.
> 
> The others you pointed out definitely are, so I marked them appropriately.
> 
> > > Source/JavaScriptCore/wasm/WasmMemory.cpp:129
> > > +        goto fail;
> > 
> > "goto"!  One of my favorite coding constructs that gets so little use
> > because peeps don't know how to use it right, and fear it.
> 
> Am I using it right? :-p
I think more idiomatic JSC style would be to name a lambda fail, and 'return fail()' everywhere you 'goto fail'
Comment 9 Saam Barati 2017-03-29 01:25:15 PDT
Comment on attachment 305680 [details]
patch

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

>> Source/JavaScriptCore/wasm/WasmMemory.cpp:129
>> +        goto fail;
> 
> "goto"!  One of my favorite coding constructs that gets so little use because peeps don't know how to use it right, and fear it.

I don't think this is why people don't use "goto"
Comment 10 Mark Lam 2017-03-29 07:08:37 PDT
(In reply to Saam Barati from comment #9)
> >> Source/JavaScriptCore/wasm/WasmMemory.cpp:129
> >> +        goto fail;
> > 
> > "goto"!  One of my favorite coding constructs that gets so little use because peeps don't know how to use it right, and fear it.
> 
> I don't think this is why people don't use "goto"

This was a semi-joke, and I was being over the top.  My point was that there are valid uses for it, and this was the main one IMHO.  Or at least, it was until ...

(In reply to Saam Barati from comment #8)
> I think more idiomatic JSC style would be to name a lambda fail, and 'return
> fail()' everywhere you 'goto fail'

I agree with this.  This is a much better solution.  I knew I should have scratch my head a little longer before saying yes to the gotos.
Comment 11 Saam Barati 2017-03-29 08:26:29 PDT
(In reply to Mark Lam from comment #10)
> (In reply to Saam Barati from comment #9)
> > >> Source/JavaScriptCore/wasm/WasmMemory.cpp:129
> > >> +        goto fail;
> > > 
> > > "goto"!  One of my favorite coding constructs that gets so little use because peeps don't know how to use it right, and fear it.
> > 
> > I don't think this is why people don't use "goto"
> 
> This was a semi-joke, and I was being over the top. 
Yeah I know :) My response is a bit of a tease as well.

> are valid uses for it, and this was the main one IMHO.  Or at least, it was
> until ...
> 
> (In reply to Saam Barati from comment #8)
> > I think more idiomatic JSC style would be to name a lambda fail, and 'return
> > fail()' everywhere you 'goto fail'
> 
> I agree with this.  This is a much better solution.  I knew I should have
> scratch my head a little longer before saying yes to the gotos.
Just to clarify, I'm not trying to argue that one is better than the other. (I could make the argument that LLVM probably produces better code for what we care about in  a function like this using the goto variant. It'll either produce smaller code, or code with one fewer function call.) I'm just arguing it's more in line with JSC style not to use goto.
Comment 12 JF Bastien 2017-03-29 09:04:56 PDT
(In reply to Saam Barati from comment #11)
> (In reply to Mark Lam from comment #10)
> > (In reply to Saam Barati from comment #9)
> > > >> Source/JavaScriptCore/wasm/WasmMemory.cpp:129
> > > >> +        goto fail;
> > > > 
> > > > "goto"!  One of my favorite coding constructs that gets so little use because peeps don't know how to use it right, and fear it.
> > > 
> > > I don't think this is why people don't use "goto"
> > 
> > This was a semi-joke, and I was being over the top. 
> Yeah I know :) My response is a bit of a tease as well.
> 
> > are valid uses for it, and this was the main one IMHO.  Or at least, it was
> > until ...
> > 
> > (In reply to Saam Barati from comment #8)
> > > I think more idiomatic JSC style would be to name a lambda fail, and 'return
> > > fail()' everywhere you 'goto fail'
> > 
> > I agree with this.  This is a much better solution.  I knew I should have
> > scratch my head a little longer before saying yes to the gotos.
> Just to clarify, I'm not trying to argue that one is better than the other.
> (I could make the argument that LLVM probably produces better code for what
> we care about in  a function like this using the goto variant. It'll either
> produce smaller code, or code with one fewer function call.) I'm just
> arguing it's more in line with JSC style not to use goto.

Lambda is indeed nicer. Will fix:
  https://bugs.webkit.org/show_bug.cgi?id=170242

goto is just a reflex for my 2000-era C++, and years of C programming :)
I can post-modernize my C++.