Commit 9d8aa1a6 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Make {Script} object reference {NativeModule} directly.

This is a first step towards being able to share the same script for
multiple {WasmModuleObject} objects. In general it should be possible
for the inspector to debug (i.e. disassemble, set breakpoints) multiple
modules if they all have the same URL (and the same wire bytes). These
are the same conditions under which we can canonicalize the modules to
be based on the same underlying {NativeModule} as well. Hence it makes
sense to establish a link from {Script} to {NativeModule} in this CL.

Subsequent CLs will eventually deprecate the {wasm_module_object} field.

R=clemensh@chromium.org
BUG=v8:6847

Change-Id: I5cfb617e18d9b06682e6437b2a2146ea5665c1c6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1807371
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63859}
parent 0d6aa842
......@@ -9326,9 +9326,8 @@ int debug::WasmScript::NumFunctions() const {
i::DisallowHeapAllocation no_gc;
i::Handle<i::Script> script = Utils::OpenHandle(this);
DCHECK_EQ(i::Script::TYPE_WASM, script->type());
i::WasmModuleObject module_object =
i::WasmModuleObject::cast(script->wasm_module_object());
const i::wasm::WasmModule* module = module_object.module();
i::wasm::NativeModule* native_module = script->wasm_native_module();
const i::wasm::WasmModule* module = native_module->module();
DCHECK_GE(i::kMaxInt, module->functions.size());
return static_cast<int>(module->functions.size());
}
......@@ -9337,9 +9336,8 @@ int debug::WasmScript::NumImportedFunctions() const {
i::DisallowHeapAllocation no_gc;
i::Handle<i::Script> script = Utils::OpenHandle(this);
DCHECK_EQ(i::Script::TYPE_WASM, script->type());
i::WasmModuleObject module_object =
i::WasmModuleObject::cast(script->wasm_module_object());
const i::wasm::WasmModule* module = module_object.module();
i::wasm::NativeModule* native_module = script->wasm_native_module();
const i::wasm::WasmModule* module = native_module->module();
DCHECK_GE(i::kMaxInt, module->num_imported_functions);
return static_cast<int>(module->num_imported_functions);
}
......@@ -9349,9 +9347,8 @@ std::pair<int, int> debug::WasmScript::GetFunctionRange(
i::DisallowHeapAllocation no_gc;
i::Handle<i::Script> script = Utils::OpenHandle(this);
DCHECK_EQ(i::Script::TYPE_WASM, script->type());
i::WasmModuleObject module_object =
i::WasmModuleObject::cast(script->wasm_module_object());
const i::wasm::WasmModule* module = module_object.module();
i::wasm::NativeModule* native_module = script->wasm_native_module();
const i::wasm::WasmModule* module = native_module->module();
DCHECK_LE(0, function_index);
DCHECK_GT(module->functions.size(), function_index);
const i::wasm::WasmFunction& func = module->functions[function_index];
......@@ -9365,14 +9362,12 @@ uint32_t debug::WasmScript::GetFunctionHash(int function_index) {
i::DisallowHeapAllocation no_gc;
i::Handle<i::Script> script = Utils::OpenHandle(this);
DCHECK_EQ(i::Script::TYPE_WASM, script->type());
i::WasmModuleObject module_object =
i::WasmModuleObject::cast(script->wasm_module_object());
const i::wasm::WasmModule* module = module_object.module();
i::wasm::NativeModule* native_module = script->wasm_native_module();
const i::wasm::WasmModule* module = native_module->module();
DCHECK_LE(0, function_index);
DCHECK_GT(module->functions.size(), function_index);
const i::wasm::WasmFunction& func = module->functions[function_index];
i::wasm::ModuleWireBytes wire_bytes(
module_object.native_module()->wire_bytes());
i::wasm::ModuleWireBytes wire_bytes(native_module->wire_bytes());
i::Vector<const i::byte> function_bytes = wire_bytes.GetFunctionBytes(&func);
// TODO(herhut): Maybe also take module, name and signature into account.
return i::StringHasher::HashSequentialString(function_bytes.begin(),
......
......@@ -663,7 +663,7 @@ extern class Script extends Struct {
line_ends: Object;
id: Smi;
eval_from_shared_or_wrapped_arguments: Object;
eval_from_position: Smi;
eval_from_position: Smi | Foreign; // Smi or Managed<wasm::NativeModule>
shared_function_infos: Object;
flags: Smi;
source_url: Object;
......
......@@ -45,6 +45,8 @@ ACCESSORS(Script, host_defined_options, FixedArray, kHostDefinedOptionsOffset)
ACCESSORS_CHECKED(Script, wasm_module_object, Object,
kEvalFromSharedOrWrappedArgumentsOffset,
this->type() == TYPE_WASM)
ACCESSORS_CHECKED(Script, wasm_managed_native_module, Object,
kEvalFromPositionOffset, this->type() == TYPE_WASM)
bool Script::is_wrapped() const {
return eval_from_shared_or_wrapped_arguments().IsFixedArray();
......@@ -75,6 +77,10 @@ FixedArray Script::wrapped_arguments() const {
return FixedArray::cast(eval_from_shared_or_wrapped_arguments());
}
wasm::NativeModule* Script::wasm_native_module() const {
return Managed<wasm::NativeModule>::cast(wasm_managed_native_module()).raw();
}
Script::CompilationType Script::compilation_type() {
return BooleanBit::get(flags(), kCompilationTypeBit) ? COMPILATION_TYPE_EVAL
: COMPILATION_TYPE_HOST;
......
......@@ -107,6 +107,11 @@ class Script : public Struct {
// This must only be called if the type of this script is TYPE_WASM.
DECL_ACCESSORS(wasm_module_object, Object)
// [wasm_native_module]: the wasm {NativeModule} this script belongs to.
// This must only be called if the type of this script is TYPE_WASM.
DECL_ACCESSORS(wasm_managed_native_module, Object)
inline wasm::NativeModule* wasm_native_module() const;
// [host_defined_options]: Options defined by the embedder.
DECL_ACCESSORS(host_defined_options, FixedArray)
......
......@@ -244,6 +244,7 @@ Handle<WasmModuleObject> WasmModuleObject::New(
module_object->set_export_wrappers(*export_wrappers);
if (script->type() == Script::TYPE_WASM) {
script->set_wasm_module_object(*module_object);
script->set_wasm_managed_native_module(*managed_native_module);
}
module_object->set_script(*script);
module_object->set_weak_instance_list(
......
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