Commit 3c8e1598 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] [test] Introduce enum for runtime exception support

We were using a boolean before, which makes the meaning non-obvious
when passed as a parameter. With the enum, you actually have to use
{kRuntimeExceptionSupport} or {kNoRuntimeExceptionSupport}.

R=mtrofin@chromium.org

Change-Id: Iaf5a7b6f1b446d4c3e16e044a6055d923d3b0b49
Reviewed-on: https://chromium-review.googlesource.com/660738
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47969}
parent d8864701
...@@ -194,7 +194,7 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position, ...@@ -194,7 +194,7 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position,
Node** effect, Node** control) { Node** effect, Node** control) {
// TODO(mtrofin): "!env_" happens when we generate a wrapper. // TODO(mtrofin): "!env_" happens when we generate a wrapper.
// We should factor wrappers separately from wasm codegen. // We should factor wrappers separately from wasm codegen.
if (FLAG_wasm_no_stack_checks || !env_ || !has_runtime_exception_support_) { if (FLAG_wasm_no_stack_checks || !env_ || !runtime_exception_support_) {
return; return;
} }
if (effect == nullptr) effect = effect_; if (effect == nullptr) effect = effect_;
...@@ -830,7 +830,7 @@ Node* WasmGraphBuilder::BranchExpectFalse(Node* cond, Node** true_node, ...@@ -830,7 +830,7 @@ Node* WasmGraphBuilder::BranchExpectFalse(Node* cond, Node** true_node,
} }
Builtins::Name WasmGraphBuilder::GetBuiltinIdForTrap(wasm::TrapReason reason) { Builtins::Name WasmGraphBuilder::GetBuiltinIdForTrap(wasm::TrapReason reason) {
if (!has_runtime_exception_support_) { if (runtime_exception_support_ == kNoRuntimeExceptionSupport) {
// We use Builtins::builtin_count as a marker to tell the code generator // We use Builtins::builtin_count as a marker to tell the code generator
// to generate a call to a testing c-function instead of a runtime // to generate a call to a testing c-function instead of a runtime
// function. This code should only be called from a cctest. // function. This code should only be called from a cctest.
......
...@@ -78,6 +78,11 @@ struct ModuleEnv { ...@@ -78,6 +78,11 @@ struct ModuleEnv {
const uintptr_t globals_start; const uintptr_t globals_start;
}; };
enum RuntimeExceptionSupport : bool {
kRuntimeExceptionSupport = true,
kNoRuntimeExceptionSupport = false
};
class WasmCompilationUnit final { class WasmCompilationUnit final {
public: public:
// If constructing from a background thread, pass in a Counters*, and ensure // If constructing from a background thread, pass in a Counters*, and ensure
...@@ -317,8 +322,8 @@ class WasmGraphBuilder { ...@@ -317,8 +322,8 @@ class WasmGraphBuilder {
bool has_simd() const { return has_simd_; } bool has_simd() const { return has_simd_; }
void SetRuntimeExceptionSupport(bool value) { void set_runtime_exception_support(RuntimeExceptionSupport value) {
has_runtime_exception_support_ = value; runtime_exception_support_ = value;
} }
const wasm::WasmModule* module() { return env_ ? env_->module : nullptr; } const wasm::WasmModule* module() { return env_ ? env_->module : nullptr; }
...@@ -345,7 +350,7 @@ class WasmGraphBuilder { ...@@ -345,7 +350,7 @@ class WasmGraphBuilder {
// If the runtime doesn't support exception propagation, // If the runtime doesn't support exception propagation,
// we won't generate stack checks, and trap handling will also // we won't generate stack checks, and trap handling will also
// be generated differently. // be generated differently.
bool has_runtime_exception_support_ = true; RuntimeExceptionSupport runtime_exception_support_ = kRuntimeExceptionSupport;
wasm::FunctionSig* sig_; wasm::FunctionSig* sig_;
SetOncePointer<const Operator> allocate_heap_number_operator_; SetOncePointer<const Operator> allocate_heap_number_operator_;
......
...@@ -1951,7 +1951,8 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { ...@@ -1951,7 +1951,8 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) {
byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, static_cast<byte>(opcode), byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, static_cast<byte>(opcode),
WASM_END}; WASM_END};
TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code, TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code,
code + arraysize(code)); code + arraysize(code),
compiler::kNoRuntimeExceptionSupport);
} else { } else {
CHECK_EQ(2, sig->parameter_count()); CHECK_EQ(2, sig->parameter_count());
byte code[] = {WASM_NO_LOCALS, byte code[] = {WASM_NO_LOCALS,
...@@ -1962,7 +1963,8 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { ...@@ -1962,7 +1963,8 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) {
static_cast<byte>(opcode), static_cast<byte>(opcode),
WASM_END}; WASM_END};
TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code, TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code,
code + arraysize(code)); code + arraysize(code),
compiler::kNoRuntimeExceptionSupport);
} }
} }
......
...@@ -155,7 +155,8 @@ TEST(CollectDetailedWasmStack_WasmError) { ...@@ -155,7 +155,8 @@ TEST(CollectDetailedWasmStack_WasmError) {
int unreachable_pos = 1 << (8 * pos_shift); int unreachable_pos = 1 << (8 * pos_shift);
TestSignatures sigs; TestSignatures sigs;
// Create a WasmRunner with stack checks and traps enabled. // Create a WasmRunner with stack checks and traps enabled.
WasmRunner<int> r(kExecuteCompiled, "main", true); WasmRunner<int> r(kExecuteCompiled, "main",
compiler::kRuntimeExceptionSupport);
std::vector<byte> code(unreachable_pos + 1, kExprNop); std::vector<byte> code(unreachable_pos + 1, kExprNop);
code[unreachable_pos] = kExprUnreachable; code[unreachable_pos] = kExprUnreachable;
......
...@@ -68,7 +68,8 @@ void CheckExceptionInfos(v8::internal::Isolate* i_isolate, Handle<Object> exc, ...@@ -68,7 +68,8 @@ void CheckExceptionInfos(v8::internal::Isolate* i_isolate, Handle<Object> exc,
// Trigger a trap for executing unreachable. // Trigger a trap for executing unreachable.
TEST(Unreachable) { TEST(Unreachable) {
// Create a WasmRunner with stack checks and traps enabled. // Create a WasmRunner with stack checks and traps enabled.
WasmRunner<void> r(kExecuteCompiled, "main", true); WasmRunner<void> r(kExecuteCompiled, "main",
compiler::kRuntimeExceptionSupport);
TestSignatures sigs; TestSignatures sigs;
BUILD(r, WASM_UNREACHABLE); BUILD(r, WASM_UNREACHABLE);
...@@ -102,7 +103,8 @@ TEST(Unreachable) { ...@@ -102,7 +103,8 @@ TEST(Unreachable) {
// Trigger a trap for loading from out-of-bounds. // Trigger a trap for loading from out-of-bounds.
TEST(IllegalLoad) { TEST(IllegalLoad) {
WasmRunner<void> r(kExecuteCompiled, "main", true); WasmRunner<void> r(kExecuteCompiled, "main",
compiler::kRuntimeExceptionSupport);
TestSignatures sigs; TestSignatures sigs;
r.builder().AddMemory(0L); r.builder().AddMemory(0L);
......
...@@ -239,15 +239,15 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() { ...@@ -239,15 +239,15 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
return WasmInstanceObject::New(isolate_, compiled_module); return WasmInstanceObject::New(isolate_, compiled_module);
} }
void TestBuildingGraph(Zone* zone, compiler::JSGraph* jsgraph, void TestBuildingGraph(
compiler::ModuleEnv* module, FunctionSig* sig, Zone* zone, compiler::JSGraph* jsgraph, compiler::ModuleEnv* module,
compiler::SourcePositionTable* source_position_table, FunctionSig* sig, compiler::SourcePositionTable* source_position_table,
const byte* start, const byte* end, const byte* start, const byte* end,
bool runtime_exception_support) { compiler::RuntimeExceptionSupport runtime_exception_support) {
compiler::WasmGraphBuilder builder( compiler::WasmGraphBuilder builder(
module, zone, jsgraph, CEntryStub(jsgraph->isolate(), 1).GetCode(), sig, module, zone, jsgraph, CEntryStub(jsgraph->isolate(), 1).GetCode(), sig,
source_position_table); source_position_table);
builder.SetRuntimeExceptionSupport(runtime_exception_support); builder.set_runtime_exception_support(runtime_exception_support);
DecodeResult result = DecodeResult result =
BuildTFGraph(zone->allocator(), &builder, sig, start, end); BuildTFGraph(zone->allocator(), &builder, sig, start, end);
...@@ -420,10 +420,10 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) { ...@@ -420,10 +420,10 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
} }
} }
WasmFunctionCompiler::WasmFunctionCompiler(Zone* zone, FunctionSig* sig, WasmFunctionCompiler::WasmFunctionCompiler(
TestingModuleBuilder* builder, Zone* zone, FunctionSig* sig, TestingModuleBuilder* builder,
const char* name, const char* name,
bool runtime_exception_support) compiler::RuntimeExceptionSupport runtime_exception_support)
: GraphAndBuilders(zone), : GraphAndBuilders(zone),
jsgraph(builder->isolate(), this->graph(), this->common(), nullptr, jsgraph(builder->isolate(), this->graph(), this->common(), nullptr,
nullptr, this->machine()), nullptr, this->machine()),
......
...@@ -210,11 +210,11 @@ class TestingModuleBuilder { ...@@ -210,11 +210,11 @@ class TestingModuleBuilder {
Handle<WasmInstanceObject> InitInstanceObject(); Handle<WasmInstanceObject> InitInstanceObject();
}; };
void TestBuildingGraph(Zone* zone, compiler::JSGraph* jsgraph, void TestBuildingGraph(
compiler::ModuleEnv* module, FunctionSig* sig, Zone* zone, compiler::JSGraph* jsgraph, compiler::ModuleEnv* module,
compiler::SourcePositionTable* source_position_table, FunctionSig* sig, compiler::SourcePositionTable* source_position_table,
const byte* start, const byte* end, const byte* start, const byte* end,
bool runtime_exception_support = false); compiler::RuntimeExceptionSupport runtime_exception_support);
class WasmFunctionWrapper : private compiler::GraphAndBuilders { class WasmFunctionWrapper : private compiler::GraphAndBuilders {
public: public:
...@@ -275,9 +275,8 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders { ...@@ -275,9 +275,8 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders {
private: private:
friend class WasmRunnerBase; friend class WasmRunnerBase;
WasmFunctionCompiler(Zone* zone, FunctionSig* sig, WasmFunctionCompiler(Zone*, FunctionSig*, TestingModuleBuilder*,
TestingModuleBuilder* builder, const char* name, const char* name, compiler::RuntimeExceptionSupport);
bool runtime_exception_support);
Handle<Code> Compile(); Handle<Code> Compile();
...@@ -290,7 +289,8 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders { ...@@ -290,7 +289,8 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders {
LocalDeclEncoder local_decls; LocalDeclEncoder local_decls;
compiler::SourcePositionTable source_position_table_; compiler::SourcePositionTable source_position_table_;
WasmInterpreter* interpreter_; WasmInterpreter* interpreter_;
bool runtime_exception_support_ = false; compiler::RuntimeExceptionSupport runtime_exception_support_ =
compiler::kNoRuntimeExceptionSupport;
}; };
// A helper class to build a module around Wasm bytecode, generate machine // A helper class to build a module around Wasm bytecode, generate machine
...@@ -298,7 +298,7 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders { ...@@ -298,7 +298,7 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders {
class WasmRunnerBase : public HandleAndZoneScope { class WasmRunnerBase : public HandleAndZoneScope {
public: public:
WasmRunnerBase(WasmExecutionMode execution_mode, int num_params, WasmRunnerBase(WasmExecutionMode execution_mode, int num_params,
bool runtime_exception_support) compiler::RuntimeExceptionSupport runtime_exception_support)
: zone_(&allocator_, ZONE_NAME), : zone_(&allocator_, ZONE_NAME),
builder_(&zone_, execution_mode), builder_(&zone_, execution_mode),
wrapper_(&zone_, num_params), wrapper_(&zone_, num_params),
...@@ -367,7 +367,8 @@ class WasmRunnerBase : public HandleAndZoneScope { ...@@ -367,7 +367,8 @@ class WasmRunnerBase : public HandleAndZoneScope {
WasmFunctionWrapper wrapper_; WasmFunctionWrapper wrapper_;
bool compiled_ = false; bool compiled_ = false;
bool possible_nondeterminism_ = false; bool possible_nondeterminism_ = false;
bool runtime_exception_support_ = false; compiler::RuntimeExceptionSupport runtime_exception_support_ =
compiler::kNoRuntimeExceptionSupport;
public: public:
// This field has to be static. Otherwise, gcc complains about the use in // This field has to be static. Otherwise, gcc complains about the use in
...@@ -380,7 +381,8 @@ class WasmRunner : public WasmRunnerBase { ...@@ -380,7 +381,8 @@ class WasmRunner : public WasmRunnerBase {
public: public:
WasmRunner(WasmExecutionMode execution_mode, WasmRunner(WasmExecutionMode execution_mode,
const char* main_fn_name = "main", const char* main_fn_name = "main",
bool runtime_exception_support = false) compiler::RuntimeExceptionSupport runtime_exception_support =
compiler::kNoRuntimeExceptionSupport)
: WasmRunnerBase(execution_mode, sizeof...(ParamTypes), : WasmRunnerBase(execution_mode, sizeof...(ParamTypes),
runtime_exception_support) { runtime_exception_support) {
NewFunction<ReturnType, ParamTypes...>(main_fn_name); NewFunction<ReturnType, ParamTypes...>(main_fn_name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment