Ignore:
Timestamp:
Dec 16, 2016, 11:24:06 AM (8 years ago)
Author:
[email protected]
Message:

WebAssembly: WasmB3IRGenerator should throw exceptions instead of crash
https://bugs.webkit.org/show_bug.cgi?id=165834

Reviewed by Keith Miller.

JSTests:

  • wasm/function-tests/exceptions.js: Added.

(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.makeInstance):

  • wasm/function-tests/table-basic.js:

(i.i.42.throw.new.Error):

Source/JavaScriptCore:

This patch generalizes how we throw exceptions in the Wasm::B3IRGenerator.
There are still places where we need to throw exceptions and we don't, but
this patch removes most of those places inside the IR generator. There are
still a few places we need to throw exceptions inside the IR generator, like
div/mod by 0. Those will be done in a separate patch. Also, there are
still some stubs we need to throw exceptions from; those will also be
done in a separate patch.

All exceptions thrown from Wasm share a common stub. The ABI for the stub
is to move the Wasm::ExceptionType into argGPR1 and jump to the stub.
The stub will then throw an exception with an error message tailored
to the particular Wasm::ExceptionType failure.

This patch also refactors B3::Compilation. Before, B3::Compilation(VM, Procedure)
constructor would compile a B3 function. This patch makes B3::Compilation a simple
tuple that keeps the necessary bits of B3 function alive in order to be runnable.
There is a new function that actually does the compilation for you. It is:
Compilation B3::compile(VM&, Procedure&)
The reason for this change is that I'm now using B3::Compilation(CodeRef, OpaqueByproducts)
constructor in Wasm code. It is weird to have a class both have a
constructor that instantiates the tuple, and another that performs the
compilation and then instantiates the tuple. It's more straight
forward if Compilation's job wasn't to actually do the compilation
but just to hold the necessary bits to keep a compiled B3 alive.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • b3/B3Compilation.cpp:

(JSC::B3::Compilation::Compilation):

  • b3/B3Compilation.h:
  • b3/B3Compile.cpp: Added.

(JSC::B3::compile):

  • b3/B3Compile.h: Added.
  • b3/testb3.cpp:

(JSC::B3::compile):

  • jit/ThunkGenerators.cpp:

(JSC::throwExceptionFromWasmThunkGenerator):

  • jit/ThunkGenerators.h:
  • wasm/WasmB3IRGenerator.cpp:

(JSC::Wasm::B3IRGenerator::B3IRGenerator):
(JSC::Wasm::B3IRGenerator::emitExceptionCheck):
(JSC::Wasm::createJSToWasmWrapper):
(JSC::Wasm::parseAndCompile):

  • wasm/WasmExceptionType.h: Added.

(JSC::Wasm::errorMessageForExceptionType):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/b3/B3Compilation.h

    r206525 r209928  
    4141class Procedure;
    4242
    43 // This is a fool-proof API for compiling a Procedure to code and then running that code. You compile
    44 // a Procedure using this API by doing:
    45 //
    46 // std::unique_ptr<Compilation> compilation = std::make_unique<Compilation>(vm, proc);
    47 //
    48 // Then you keep the Compilation object alive for as long as you want to be able to run the code. If
    49 // this API feels too high-level, you can use B3::generate() directly.
     43// This class is a way to keep the result of a B3 compilation alive
     44// and runnable.
    5045
    5146class Compilation {
     
    5449
    5550public:
    56     JS_EXPORT_PRIVATE Compilation(VM&, Procedure&, unsigned optLevel = 1);
    57 
    58     // This constructor allows you to manually create a Compilation. It's currently only used by test
    59     // code. Probably best to keep it that way.
    6051    JS_EXPORT_PRIVATE Compilation(MacroAssemblerCodeRef, std::unique_ptr<OpaqueByproducts>);
    61    
     52    JS_EXPORT_PRIVATE Compilation(Compilation&&);
    6253    JS_EXPORT_PRIVATE ~Compilation();
    6354
Note: See TracChangeset for help on using the changeset viewer.