Commit dd3b14b7 authored by gdeepti's avatar gdeepti Committed by Commit bot

[wasm] Fix test-run-wasm-module tests in debug mode.

test-run-wasm-module cctests broken in debug since recent refactoring changes for moving Compilation/Instantiation off the module object (https://codereview.chromium.org/2320723005). The problem here is that SetupIsolateForWasm tries to add the same property to a module_object multiple times and hits a DCHECK when this property is found on a lookup.
 - Fixed to use the setup method only once when CcTest::InitIsolateOnce is used.
 - Move setup method to test as this is only used for cctests/fuzzers. The install method should take care of this in the regular JS pipeline.

 R=mtrofin@chromium.org, ahaas@chromium.org

Review-Url: https://codereview.chromium.org/2342263002
Cr-Commit-Position: refs/heads/master@{#39484}
parent 7d008c0d
......@@ -316,45 +316,42 @@ static Handle<JSFunction> InstallFunc(Isolate* isolate, Handle<JSObject> object,
return function;
}
void WasmJs::SetupIsolateForWasm(Isolate* isolate) {
InstallWasmFunctionMap(isolate, isolate->native_context());
InstallWasmModuleSymbol(isolate, isolate->global_object(),
isolate->native_context());
}
void WasmJs::InstallWasmModuleSymbolIfNeeded(Isolate* isolate,
Handle<JSGlobalObject> global,
Handle<Context> context) {
if (!context->get(Context::WASM_MODULE_SYM_INDEX)->IsSymbol() ||
!context->get(Context::WASM_INSTANCE_SYM_INDEX)->IsSymbol()) {
Factory* factory = isolate->factory();
// Create private symbols.
Handle<Symbol> module_sym = factory->NewPrivateSymbol();
Handle<Symbol> instance_sym = factory->NewPrivateSymbol();
context->set_wasm_module_sym(*module_sym);
context->set_wasm_instance_sym(*instance_sym);
// Bind the WebAssembly object.
Handle<String> name = v8_str(isolate, "WebAssembly");
Handle<JSFunction> cons = factory->NewFunction(name);
JSFunction::SetInstancePrototype(
cons, Handle<Object>(context->initial_object_prototype(), isolate));
cons->shared()->set_instance_class_name(*name);
Handle<JSObject> wasm_object = factory->NewJSObject(cons, TENURED);
PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM);
JSObject::AddProperty(global, name, wasm_object, attributes);
void WasmJs::InstallWasmModuleSymbol(Isolate* isolate,
Handle<JSGlobalObject> global,
Handle<Context> context) {
Factory* factory = isolate->factory();
// Create private symbols.
Handle<Symbol> module_sym = factory->NewPrivateSymbol();
Handle<Symbol> instance_sym = factory->NewPrivateSymbol();
context->set_wasm_module_sym(*module_sym);
context->set_wasm_instance_sym(*instance_sym);
// Bind the WebAssembly object.
Handle<String> name = v8_str(isolate, "WebAssembly");
Handle<JSFunction> cons = factory->NewFunction(name);
JSFunction::SetInstancePrototype(
cons, Handle<Object>(context->initial_object_prototype(), isolate));
cons->shared()->set_instance_class_name(*name);
Handle<JSObject> wasm_object = factory->NewJSObject(cons, TENURED);
PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM);
JSObject::AddProperty(global, name, wasm_object, attributes);
// Install static methods on WebAssembly object.
InstallFunc(isolate, wasm_object, "compile", WebAssemblyCompile);
Handle<JSFunction> module_constructor =
InstallFunc(isolate, wasm_object, "Module", WebAssemblyModule);
Handle<JSFunction> instance_constructor =
InstallFunc(isolate, wasm_object, "Instance", WebAssemblyInstance);
i::Handle<i::Map> map = isolate->factory()->NewMap(
i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + i::kPointerSize);
module_constructor->set_prototype_or_initial_map(*map);
map->SetConstructor(*module_constructor);
context->set_wasm_module_constructor(*module_constructor);
context->set_wasm_instance_constructor(*instance_constructor);
// Install static methods on WebAssembly object.
InstallFunc(isolate, wasm_object, "compile", WebAssemblyCompile);
Handle<JSFunction> module_constructor =
InstallFunc(isolate, wasm_object, "Module", WebAssemblyModule);
Handle<JSFunction> instance_constructor =
InstallFunc(isolate, wasm_object, "Instance", WebAssemblyInstance);
i::Handle<i::Map> map = isolate->factory()->NewMap(
i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + i::kPointerSize);
module_constructor->set_prototype_or_initial_map(*map);
map->SetConstructor(*module_constructor);
context->set_wasm_module_constructor(*module_constructor);
context->set_wasm_instance_constructor(*instance_constructor);
}
}
void WasmJs::Install(Isolate* isolate, Handle<JSGlobalObject> global) {
......@@ -366,7 +363,7 @@ void WasmJs::Install(Isolate* isolate, Handle<JSGlobalObject> global) {
// Setup wasm function map.
Handle<Context> context(global->native_context(), isolate);
InstallWasmFunctionMap(isolate, context);
InstallWasmFunctionMapIfNeeded(isolate, context);
if (!FLAG_expose_wasm) {
return;
......@@ -399,10 +396,11 @@ void WasmJs::Install(Isolate* isolate, Handle<JSGlobalObject> global) {
JSObject::AddProperty(wasm_object, name, value, attributes);
}
}
InstallWasmModuleSymbol(isolate, global, context);
InstallWasmModuleSymbolIfNeeded(isolate, global, context);
}
void WasmJs::InstallWasmFunctionMap(Isolate* isolate, Handle<Context> context) {
void WasmJs::InstallWasmFunctionMapIfNeeded(Isolate* isolate,
Handle<Context> context) {
if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) {
// TODO(titzer): Move this to bootstrapper.cc??
// TODO(titzer): Also make one for strict mode functions?
......
......@@ -19,11 +19,11 @@ namespace internal {
class WasmJs {
public:
static void Install(Isolate* isolate, Handle<JSGlobalObject> global_object);
static void InstallWasmFunctionMap(Isolate* isolate, Handle<Context> context);
static void InstallWasmModuleSymbol(Isolate* isolate,
Handle<JSGlobalObject> global,
Handle<Context> context);
static void SetupIsolateForWasm(Isolate* isolate);
static void InstallWasmFunctionMapIfNeeded(Isolate* isolate,
Handle<Context> context);
static void InstallWasmModuleSymbolIfNeeded(Isolate* isolate,
Handle<JSGlobalObject> global,
Handle<Context> context);
};
} // namespace internal
......
......@@ -7,7 +7,6 @@
#include "src/wasm/encoder.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-macro-gen.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-opcodes.h"
......@@ -29,7 +28,7 @@ void TestModule(Zone* zone, WasmModuleBuilder* builder,
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
WasmJs::SetupIsolateForWasm(isolate);
testing::SetupIsolateForWasmModule(isolate);
int32_t result = testing::CompileAndRunWasmModule(
isolate, buffer.begin(), buffer.end(), ModuleOrigin::kWasmOrigin);
CHECK_EQ(expected_result, result);
......@@ -205,7 +204,7 @@ TEST(Run_WasmModule_Serialization) {
v8::WasmCompiledModule::SerializedModule data;
{
HandleScope scope(isolate);
WasmJs::SetupIsolateForWasm(isolate);
testing::SetupIsolateForWasmModule(isolate);
ModuleResult decoding_result = DecodeWasmModule(
isolate, &zone, buffer.begin(), buffer.end(), false, kWasmOrigin);
......@@ -236,7 +235,7 @@ TEST(Run_WasmModule_Serialization) {
v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate);
new_ctx->Enter();
isolate = reinterpret_cast<Isolate*>(v8_isolate);
WasmJs::SetupIsolateForWasm(isolate);
testing::SetupIsolateForWasmModule(isolate);
v8::MaybeLocal<v8::WasmCompiledModule> deserialized =
v8::WasmCompiledModule::Deserialize(v8_isolate, data);
......
......@@ -208,7 +208,8 @@ class TestingModule : public ModuleEnv {
Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main");
Handle<JSObject> module_object = Handle<JSObject>(0, isolate_);
Handle<Code> code = instance->function_code[index];
WasmJs::InstallWasmFunctionMap(isolate_, isolate_->native_context());
WasmJs::InstallWasmFunctionMapIfNeeded(isolate_,
isolate_->native_context());
Handle<Code> ret_code =
compiler::CompileJSToWasmWrapper(isolate_, this, code, index);
FunctionSig* funcSig = this->module->functions[index].sig;
......
......@@ -10,6 +10,7 @@
#include "src/property-descriptor.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-interpreter.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-result.h"
#include "src/zone.h"
......@@ -199,6 +200,12 @@ int32_t CallWasmFunctionForTesting(Isolate* isolate, Handle<JSObject> instance,
return -1;
}
void SetupIsolateForWasmModule(Isolate* isolate) {
WasmJs::InstallWasmFunctionMapIfNeeded(isolate, isolate->native_context());
WasmJs::InstallWasmModuleSymbolIfNeeded(isolate, isolate->global_object(),
isolate->native_context());
}
} // namespace testing
} // namespace wasm
} // namespace internal
......
......@@ -46,6 +46,9 @@ int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower* thrower,
const WasmModule* module, int function_index,
WasmVal* args);
// Install function map, module symbol for testing
void SetupIsolateForWasmModule(Isolate* isolate);
} // namespace testing
} // namespace wasm
} // namespace internal
......
......@@ -12,7 +12,6 @@
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/objects.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-module.h"
#include "test/common/wasm/wasm-module-runner.h"
#include "test/fuzzer/fuzzer-support.h"
......@@ -32,7 +31,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
v8::HandleScope handle_scope(isolate);
v8::Context::Scope context_scope(support->GetContext());
v8::TryCatch try_catch(isolate);
v8::internal::WasmJs::SetupIsolateForWasm(i_isolate);
v8::internal::wasm::testing::SetupIsolateForWasmModule(i_isolate);
v8::internal::wasm::testing::CompileAndRunWasmModule(
i_isolate, data, data + size,
v8::internal::wasm::ModuleOrigin::kAsmJsOrigin);
......
......@@ -9,7 +9,6 @@
#include "src/isolate.h"
#include "src/wasm/encoder.h"
#include "src/wasm/wasm-interpreter.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-module.h"
#include "test/cctest/wasm/test-signatures.h"
#include "test/common/wasm/wasm-module-runner.h"
......@@ -50,7 +49,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
ZoneBuffer buffer(&zone);
builder.WriteTo(buffer);
v8::internal::WasmJs::SetupIsolateForWasm(i_isolate);
v8::internal::wasm::testing::SetupIsolateForWasmModule(i_isolate);
v8::internal::HandleScope scope(i_isolate);
......
......@@ -12,7 +12,6 @@
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/objects.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-module.h"
#include "test/common/wasm/wasm-module-runner.h"
#include "test/fuzzer/fuzzer-support.h"
......@@ -32,7 +31,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
v8::HandleScope handle_scope(isolate);
v8::Context::Scope context_scope(support->GetContext());
v8::TryCatch try_catch(isolate);
v8::internal::WasmJs::SetupIsolateForWasm(i_isolate);
v8::internal::wasm::testing::SetupIsolateForWasmModule(i_isolate);
v8::internal::wasm::testing::CompileAndRunWasmModule(
i_isolate, data, data + size, v8::internal::wasm::kWasmOrigin);
return 0;
......
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