<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>168694</bug_id>
          
          <creation_ts>2017-02-21 17:00:03 -0800</creation_ts>
          <short_desc>WebAssembly: disable when --useJIT=0</short_desc>
          <delta_ts>2017-04-19 16:26:27 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>CONFIGURATION CHANGED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>159775</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="JF Bastien">jfbastien</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>fpizlo</cc>
    
    <cc>jfbastien</cc>
    
    <cc>keith_miller</cc>
    
    <cc>mark.lam</cc>
    
    <cc>msaboff</cc>
    
    <cc>saam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1279656</commentid>
    <comment_count>0</comment_count>
    <who name="JF Bastien">jfbastien</who>
    <bug_when>2017-02-21 17:00:03 -0800</bug_when>
    <thetext>We get an assertion in repatchNearCall because there&apos;s an immediate that doesn&apos;t fit. The problem is that without JIT the wasm code can&apos;t be linked to trampolines because they don&apos;t exist.

Simple repro:
  (cd ./JSTests/wasm/ &amp;&amp; lldb ../../current-debug/bin/jsc -- -m --useWebAssembly=1 ./js-api/wasm-to-wasm.js --useConcurrentJIT=0 --useJIT=0)

We probably want to JIT just those stubs when WebAssembly is used, even if the JIT is disabled.

Backtrace:

1   0x1013d3e9d WTFCrash
2   0x100300839 JSC::X86Assembler::setRel32(void*, void*)
3   0x1009cf43d JSC::X86Assembler::relinkCall(void*, void*)
4   0x100e37731 JSC::AbstractMacroAssembler&lt;JSC::X86Assembler, JSC::MacroAssemblerX86Common&gt;::repatchNearCall(JSC::CodeLocationNearCall, JSC::CodeLocationLabel)
5   0x100e3753f JSC::linkFor(JSC::ExecState*, JSC::CallLinkInfo&amp;, JSC::CodeBlock*, JSC::JSFunction*, JSC::MacroAssemblerCodePtr)
6   0x100e02ff6 operationLinkCall
...

frame #1: 0x0000000100300839 JavaScriptCore`JSC::X86Assembler::setRel32(from=0x000039c74ec011be, to=0x0000000100e58c6e) + 89 at X86Assembler.h:3123
   3120	    static void setRel32(void* from, void* to)
   3121	    {
   3122	        intptr_t offset = reinterpret_cast&lt;intptr_t&gt;(to) - reinterpret_cast&lt;intptr_t&gt;(from);
-&gt; 3123	        ASSERT(offset == static_cast&lt;int32_t&gt;(offset));
   3124	
   3125	        setInt32(from, offset);
   3126	    }
(lldb) p/x from
(void *) $0 = 0x000039c74ec011be
(lldb) p/x to
(void *) $1 = 0x0000000100e58c6e
(lldb) p/x offset
(intptr_t) $2 = 0xffffc639b2257ab0</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1279708</commentid>
    <comment_count>1</comment_count>
    <who name="Saam Barati">saam</who>
    <bug_when>2017-02-21 18:10:56 -0800</bug_when>
    <thetext>(In reply to comment #0)
&gt; We get an assertion in repatchNearCall because there&apos;s an immediate that
&gt; doesn&apos;t fit. The problem is that without JIT the wasm code can&apos;t be linked
&gt; to trampolines because they don&apos;t exist.
&gt; 
&gt; Simple repro:
&gt;   (cd ./JSTests/wasm/ &amp;&amp; lldb ../../current-debug/bin/jsc -- -m
&gt; --useWebAssembly=1 ./js-api/wasm-to-wasm.js --useConcurrentJIT=0 --useJIT=0)
&gt; 
&gt; We probably want to JIT just those stubs when WebAssembly is used, even if
&gt; the JIT is disabled.
&gt; 
&gt; Backtrace:
&gt; 
&gt; 1   0x1013d3e9d WTFCrash
&gt; 2   0x100300839 JSC::X86Assembler::setRel32(void*, void*)
&gt; 3   0x1009cf43d JSC::X86Assembler::relinkCall(void*, void*)
&gt; 4   0x100e37731 JSC::AbstractMacroAssembler&lt;JSC::X86Assembler,
&gt; JSC::MacroAssemblerX86Common&gt;::repatchNearCall(JSC::CodeLocationNearCall,
&gt; JSC::CodeLocationLabel)
&gt; 5   0x100e3753f JSC::linkFor(JSC::ExecState*, JSC::CallLinkInfo&amp;,
&gt; JSC::CodeBlock*, JSC::JSFunction*, JSC::MacroAssemblerCodePtr)
&gt; 6   0x100e02ff6 operationLinkCall
&gt; ...
&gt; 
&gt; frame #1: 0x0000000100300839
&gt; JavaScriptCore`JSC::X86Assembler::setRel32(from=0x000039c74ec011be,
&gt; to=0x0000000100e58c6e) + 89 at X86Assembler.h:3123
&gt;    3120	    static void setRel32(void* from, void* to)
&gt;    3121	    {
&gt;    3122	        intptr_t offset = reinterpret_cast&lt;intptr_t&gt;(to) -
&gt; reinterpret_cast&lt;intptr_t&gt;(from);
&gt; -&gt; 3123	        ASSERT(offset == static_cast&lt;int32_t&gt;(offset));
&gt;    3124	
&gt;    3125	        setInt32(from, offset);
&gt;    3126	    }
&gt; (lldb) p/x from
&gt; (void *) $0 = 0x000039c74ec011be
&gt; (lldb) p/x to
&gt; (void *) $1 = 0x0000000100e58c6e
&gt; (lldb) p/x offset
&gt; (intptr_t) $2 = 0xffffc639b2257ab0

Why would useJIT()=0 ever be valid with Wasm code? Seems like we should never allow running in that configuration since we&apos;re already relying on JITing for that call IC.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1279710</commentid>
    <comment_count>2</comment_count>
    <who name="JF Bastien">jfbastien</who>
    <bug_when>2017-02-21 18:16:00 -0800</bug_when>
    <thetext>&gt; Why would useJIT()=0 ever be valid with Wasm code? Seems like we should
&gt; never allow running in that configuration since we&apos;re already relying on
&gt; JITing for that call IC.

It would be nice to be able to say &quot;compile wasm, but don&apos;t JIT JS&quot;. I&apos;m not sure what we would call that option. Regardless of what we do, it would:

  - AOT wasm (as always)
  - Compile the wasm thunks at the same time
  - Compile the trampolines that are required for ICs when we compile wasm code (because usually baseline does this?)

I think we might have a super unlikely race in current wasm where it&apos;s possible to always be in the interpreter, compile some wasm, and then not have those trampolines either? I&apos;m not sure.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1279730</commentid>
    <comment_count>3</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2017-02-21 19:19:32 -0800</bug_when>
    <thetext>(In reply to comment #2)
&gt; &gt; Why would useJIT()=0 ever be valid with Wasm code? Seems like we should
&gt; &gt; never allow running in that configuration since we&apos;re already relying on
&gt; &gt; JITing for that call IC.
&gt; 
&gt; It would be nice to be able to say &quot;compile wasm, but don&apos;t JIT JS&quot;. I&apos;m not
&gt; sure what we would call that option. Regardless of what we do, it would:
&gt; 
&gt;   - AOT wasm (as always)
&gt;   - Compile the wasm thunks at the same time
&gt;   - Compile the trampolines that are required for ICs when we compile wasm
&gt; code (because usually baseline does this?)
&gt; 
&gt; I think we might have a super unlikely race in current wasm where it&apos;s
&gt; possible to always be in the interpreter, compile some wasm, and then not
&gt; have those trampolines either? I&apos;m not sure.

I don&apos;t think useJIT means what you want it to mean.  useJIT determines whether JSC is allowed to JIT.  If it&apos;s not allowed to JIT, then it&apos;s not allowed to wasm.  The only time we set it to false is to simulate environments where we don&apos;t have the JIT entitlement, and so cannot JIT at all.

So I think this is wontfix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1279931</commentid>
    <comment_count>4</comment_count>
    <who name="JF Bastien">jfbastien</who>
    <bug_when>2017-02-22 09:44:22 -0800</bug_when>
    <thetext>
&gt; I don&apos;t think useJIT means what you want it to mean.  useJIT determines
&gt; whether JSC is allowed to JIT.  If it&apos;s not allowed to JIT, then it&apos;s not
&gt; allowed to wasm.  The only time we set it to false is to simulate
&gt; environments where we don&apos;t have the JIT entitlement, and so cannot JIT at
&gt; all.
&gt; 
&gt; So I think this is wontfix.

That&apos;s fine. In that case we should throw when users try to use WebAssembly and useJIT is false. Uses of WebAssembly.Module / WebAssembly.compile / WebAssembly.instantiate should throw. Or maybe the WebAssembly object just shouldn&apos;t be there if useJIT == false. I think that&apos;s better.

I can get what I want by disabling baseline+DFG+FTL instead. I&apos;d also update the description of useJIT, which is currently &quot;allows the baseline JIT to be used if true&quot;.

So I&apos;ll reopen this bug, change its description, and implement it when I feel like doing something simple :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1298893</commentid>
    <comment_count>5</comment_count>
    <who name="JF Bastien">jfbastien</who>
    <bug_when>2017-04-19 16:26:27 -0700</bug_when>
    <thetext>Fixed separately.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>