Commit 615c215f authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Ensure constness of WasmModule after decoding

We pass the {WasmModule} by non-const pointer and by non-const
reference a lot. This violates the style guide, and adds the risk of
accidentally modifying it.
This CL makes the {WasmModule} const during compilation and
instantiation.

R=mstarzinger@chromium.org

Bug: v8:7754
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: Ie1878322828b63284b341d97da595e8e91dd4f51
Reviewed-on: https://chromium-review.googlesource.com/1117194Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54078}
parent cf66f737
...@@ -9450,7 +9450,7 @@ int debug::WasmScript::NumFunctions() const { ...@@ -9450,7 +9450,7 @@ int debug::WasmScript::NumFunctions() const {
DCHECK_EQ(i::Script::TYPE_WASM, script->type()); DCHECK_EQ(i::Script::TYPE_WASM, script->type());
i::WasmModuleObject* module_object = i::WasmModuleObject* module_object =
i::WasmModuleObject::cast(script->wasm_module_object()); i::WasmModuleObject::cast(script->wasm_module_object());
i::wasm::WasmModule* module = module_object->module(); const i::wasm::WasmModule* module = module_object->module();
DCHECK_GE(i::kMaxInt, module->functions.size()); DCHECK_GE(i::kMaxInt, module->functions.size());
return static_cast<int>(module->functions.size()); return static_cast<int>(module->functions.size());
} }
...@@ -9461,7 +9461,7 @@ int debug::WasmScript::NumImportedFunctions() const { ...@@ -9461,7 +9461,7 @@ int debug::WasmScript::NumImportedFunctions() const {
DCHECK_EQ(i::Script::TYPE_WASM, script->type()); DCHECK_EQ(i::Script::TYPE_WASM, script->type());
i::WasmModuleObject* module_object = i::WasmModuleObject* module_object =
i::WasmModuleObject::cast(script->wasm_module_object()); i::WasmModuleObject::cast(script->wasm_module_object());
i::wasm::WasmModule* module = module_object->module(); const i::wasm::WasmModule* module = module_object->module();
DCHECK_GE(i::kMaxInt, module->num_imported_functions); DCHECK_GE(i::kMaxInt, module->num_imported_functions);
return static_cast<int>(module->num_imported_functions); return static_cast<int>(module->num_imported_functions);
} }
...@@ -9473,10 +9473,10 @@ std::pair<int, int> debug::WasmScript::GetFunctionRange( ...@@ -9473,10 +9473,10 @@ std::pair<int, int> debug::WasmScript::GetFunctionRange(
DCHECK_EQ(i::Script::TYPE_WASM, script->type()); DCHECK_EQ(i::Script::TYPE_WASM, script->type());
i::WasmModuleObject* module_object = i::WasmModuleObject* module_object =
i::WasmModuleObject::cast(script->wasm_module_object()); i::WasmModuleObject::cast(script->wasm_module_object());
i::wasm::WasmModule* module = module_object->module(); const i::wasm::WasmModule* module = module_object->module();
DCHECK_LE(0, function_index); DCHECK_LE(0, function_index);
DCHECK_GT(module->functions.size(), function_index); DCHECK_GT(module->functions.size(), function_index);
i::wasm::WasmFunction& func = module->functions[function_index]; const i::wasm::WasmFunction& func = module->functions[function_index];
DCHECK_GE(i::kMaxInt, func.code.offset()); DCHECK_GE(i::kMaxInt, func.code.offset());
DCHECK_GE(i::kMaxInt, func.code.end_offset()); DCHECK_GE(i::kMaxInt, func.code.end_offset());
return std::make_pair(static_cast<int>(func.code.offset()), return std::make_pair(static_cast<int>(func.code.offset()),
...@@ -9489,10 +9489,10 @@ uint32_t debug::WasmScript::GetFunctionHash(int function_index) { ...@@ -9489,10 +9489,10 @@ uint32_t debug::WasmScript::GetFunctionHash(int function_index) {
DCHECK_EQ(i::Script::TYPE_WASM, script->type()); DCHECK_EQ(i::Script::TYPE_WASM, script->type());
i::WasmModuleObject* module_object = i::WasmModuleObject* module_object =
i::WasmModuleObject::cast(script->wasm_module_object()); i::WasmModuleObject::cast(script->wasm_module_object());
i::wasm::WasmModule* module = module_object->module(); const i::wasm::WasmModule* module = module_object->module();
DCHECK_LE(0, function_index); DCHECK_LE(0, function_index);
DCHECK_GT(module->functions.size(), function_index); DCHECK_GT(module->functions.size(), function_index);
i::wasm::WasmFunction& func = module->functions[function_index]; const i::wasm::WasmFunction& func = module->functions[function_index];
i::wasm::ModuleWireBytes wire_bytes( i::wasm::ModuleWireBytes wire_bytes(
module_object->native_module()->wire_bytes()); module_object->native_module()->wire_bytes());
i::Vector<const i::byte> function_bytes = wire_bytes.GetFunctionBytes(&func); i::Vector<const i::byte> function_bytes = wire_bytes.GetFunctionBytes(&func);
......
...@@ -4721,7 +4721,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -4721,7 +4721,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
} // namespace } // namespace
MaybeHandle<Code> CompileJSToWasmWrapper( MaybeHandle<Code> CompileJSToWasmWrapper(
Isolate* isolate, wasm::WasmModule* module, Address call_target, Isolate* isolate, const wasm::WasmModule* module, Address call_target,
uint32_t index, wasm::UseTrapHandler use_trap_handler) { uint32_t index, wasm::UseTrapHandler use_trap_handler) {
const wasm::WasmFunction* func = &module->functions[index]; const wasm::WasmFunction* func = &module->functions[index];
......
...@@ -116,7 +116,7 @@ MaybeHandle<Code> CompileWasmToJSWrapper(Isolate*, Handle<JSReceiver> target, ...@@ -116,7 +116,7 @@ MaybeHandle<Code> CompileWasmToJSWrapper(Isolate*, Handle<JSReceiver> target,
// Wraps a given wasm code object, producing a code object. // Wraps a given wasm code object, producing a code object.
V8_EXPORT_PRIVATE MaybeHandle<Code> CompileJSToWasmWrapper( V8_EXPORT_PRIVATE MaybeHandle<Code> CompileJSToWasmWrapper(
Isolate*, wasm::WasmModule*, Address call_target, uint32_t index, Isolate*, const wasm::WasmModule*, Address call_target, uint32_t index,
wasm::UseTrapHandler); wasm::UseTrapHandler);
// Compiles a stub that redirects a call to a wasm function to the wasm // Compiles a stub that redirects a call to a wasm function to the wasm
......
...@@ -188,7 +188,7 @@ namespace { ...@@ -188,7 +188,7 @@ namespace {
class JSToWasmWrapperCache { class JSToWasmWrapperCache {
public: public:
Handle<Code> CloneOrCompileJSToWasmWrapper( Handle<Code> CloneOrCompileJSToWasmWrapper(
Isolate* isolate, wasm::WasmModule* module, Address call_target, Isolate* isolate, const wasm::WasmModule* module, Address call_target,
uint32_t index, wasm::UseTrapHandler use_trap_handler) { uint32_t index, wasm::UseTrapHandler use_trap_handler) {
const bool is_import = index < module->num_imported_functions; const bool is_import = index < module->num_imported_functions;
DCHECK_EQ(is_import, call_target == kNullAddress); DCHECK_EQ(is_import, call_target == kNullAddress);
...@@ -259,7 +259,7 @@ class InstanceBuilder { ...@@ -259,7 +259,7 @@ class InstanceBuilder {
}; };
Isolate* isolate_; Isolate* isolate_;
WasmModule* const module_; const WasmModule* const module_;
const std::shared_ptr<Counters> async_counters_; const std::shared_ptr<Counters> async_counters_;
ErrorThrower* thrower_; ErrorThrower* thrower_;
Handle<WasmModuleObject> module_object_; Handle<WasmModuleObject> module_object_;
...@@ -320,8 +320,9 @@ class InstanceBuilder { ...@@ -320,8 +320,9 @@ class InstanceBuilder {
// Load data segments into the memory. // Load data segments into the memory.
void LoadDataSegments(Handle<WasmInstanceObject> instance); void LoadDataSegments(Handle<WasmInstanceObject> instance);
void WriteGlobalValue(WasmGlobal& global, double value); void WriteGlobalValue(const WasmGlobal& global, double value);
void WriteGlobalValue(WasmGlobal& global, Handle<WasmGlobalObject> value); void WriteGlobalValue(const WasmGlobal& global,
Handle<WasmGlobalObject> value);
void SanitizeImports(); void SanitizeImports();
...@@ -335,7 +336,7 @@ class InstanceBuilder { ...@@ -335,7 +336,7 @@ class InstanceBuilder {
int ProcessImports(Handle<WasmInstanceObject> instance); int ProcessImports(Handle<WasmInstanceObject> instance);
template <typename T> template <typename T>
T* GetRawGlobalPtr(WasmGlobal& global); T* GetRawGlobalPtr(const WasmGlobal& global);
// Process initialization of globals. // Process initialization of globals.
void InitGlobals(); void InitGlobals();
...@@ -934,10 +935,11 @@ class BackgroundCompileTask : public CancelableTask { ...@@ -934,10 +935,11 @@ class BackgroundCompileTask : public CancelableTask {
} // namespace } // namespace
MaybeHandle<WasmModuleObject> CompileToModuleObject( MaybeHandle<WasmModuleObject> CompileToModuleObject(
Isolate* isolate, ErrorThrower* thrower, std::shared_ptr<WasmModule> module, Isolate* isolate, ErrorThrower* thrower,
const ModuleWireBytes& wire_bytes, Handle<Script> asm_js_script, std::shared_ptr<const WasmModule> module, const ModuleWireBytes& wire_bytes,
Handle<Script> asm_js_script,
Vector<const byte> asm_js_offset_table_bytes) { Vector<const byte> asm_js_offset_table_bytes) {
WasmModule* wasm_module = module.get(); const WasmModule* wasm_module = module.get();
TimedHistogramScope wasm_compile_module_time_scope( TimedHistogramScope wasm_compile_module_time_scope(
SELECT_WASM_COUNTER(isolate->async_counters(), wasm_module->origin, SELECT_WASM_COUNTER(isolate->async_counters(), wasm_module->origin,
wasm_compile, module_time)); wasm_compile, module_time));
...@@ -1218,7 +1220,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -1218,7 +1220,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Check that indirect function table segments are within bounds. // Check that indirect function table segments are within bounds.
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
for (WasmTableInit& table_init : module_->table_inits) { for (const WasmTableInit& table_init : module_->table_inits) {
DCHECK(table_init.table_index < table_instances_.size()); DCHECK(table_init.table_index < table_instances_.size());
uint32_t base = EvalUint32InitExpr(table_init.offset); uint32_t base = EvalUint32InitExpr(table_init.offset);
size_t table_size = table_instances_[table_init.table_index].table_size; size_t table_size = table_instances_[table_init.table_index].table_size;
...@@ -1231,7 +1233,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -1231,7 +1233,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Check that memory segments are within bounds. // Check that memory segments are within bounds.
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
for (WasmDataSegment& seg : module_->data_segments) { for (const WasmDataSegment& seg : module_->data_segments) {
uint32_t base = EvalUint32InitExpr(seg.dest_addr); uint32_t base = EvalUint32InitExpr(seg.dest_addr);
if (!in_bounds(base, seg.source.length(), instance->memory_size())) { if (!in_bounds(base, seg.source.length(), instance->memory_size())) {
thrower_->LinkError("data segment is out of bounds"); thrower_->LinkError("data segment is out of bounds");
...@@ -1430,7 +1432,7 @@ void InstanceBuilder::LoadDataSegments(Handle<WasmInstanceObject> instance) { ...@@ -1430,7 +1432,7 @@ void InstanceBuilder::LoadDataSegments(Handle<WasmInstanceObject> instance) {
} }
} }
void InstanceBuilder::WriteGlobalValue(WasmGlobal& global, double num) { void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global, double num) {
TRACE("init [globals_start=%p + %u] = %lf, type = %s\n", TRACE("init [globals_start=%p + %u] = %lf, type = %s\n",
reinterpret_cast<void*>(raw_buffer_ptr(globals_, 0)), global.offset, reinterpret_cast<void*>(raw_buffer_ptr(globals_, 0)), global.offset,
num, ValueTypes::TypeName(global.type)); num, ValueTypes::TypeName(global.type));
...@@ -1453,7 +1455,7 @@ void InstanceBuilder::WriteGlobalValue(WasmGlobal& global, double num) { ...@@ -1453,7 +1455,7 @@ void InstanceBuilder::WriteGlobalValue(WasmGlobal& global, double num) {
} }
} }
void InstanceBuilder::WriteGlobalValue(WasmGlobal& global, void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global,
Handle<WasmGlobalObject> value) { Handle<WasmGlobalObject> value) {
TRACE("init [globals_start=%p + %u] = ", TRACE("init [globals_start=%p + %u] = ",
reinterpret_cast<void*>(raw_buffer_ptr(globals_, 0)), global.offset); reinterpret_cast<void*>(raw_buffer_ptr(globals_, 0)), global.offset);
...@@ -1493,7 +1495,7 @@ void InstanceBuilder::SanitizeImports() { ...@@ -1493,7 +1495,7 @@ void InstanceBuilder::SanitizeImports() {
Vector<const uint8_t> wire_bytes = Vector<const uint8_t> wire_bytes =
module_object_->native_module()->wire_bytes(); module_object_->native_module()->wire_bytes();
for (size_t index = 0; index < module_->import_table.size(); ++index) { for (size_t index = 0; index < module_->import_table.size(); ++index) {
WasmImport& import = module_->import_table[index]; const WasmImport& import = module_->import_table[index];
Handle<String> module_name; Handle<String> module_name;
MaybeHandle<String> maybe_module_name = MaybeHandle<String> maybe_module_name =
...@@ -1559,7 +1561,7 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) { ...@@ -1559,7 +1561,7 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) {
int num_imports = static_cast<int>(module_->import_table.size()); int num_imports = static_cast<int>(module_->import_table.size());
NativeModule* native_module = instance->module_object()->native_module(); NativeModule* native_module = instance->module_object()->native_module();
for (int index = 0; index < num_imports; ++index) { for (int index = 0; index < num_imports; ++index) {
WasmImport& import = module_->import_table[index]; const WasmImport& import = module_->import_table[index];
Handle<String> module_name = sanitized_imports_[index].module_name; Handle<String> module_name = sanitized_imports_[index].module_name;
Handle<String> import_name = sanitized_imports_[index].import_name; Handle<String> import_name = sanitized_imports_[index].import_name;
...@@ -1622,7 +1624,8 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) { ...@@ -1622,7 +1624,8 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) {
} }
uint32_t table_num = import.index; uint32_t table_num = import.index;
DCHECK_EQ(table_num, num_imported_tables); DCHECK_EQ(table_num, num_imported_tables);
WasmIndirectFunctionTable& table = module_->function_tables[table_num]; const WasmIndirectFunctionTable& table =
module_->function_tables[table_num];
TableInstance& table_instance = table_instances_[table_num]; TableInstance& table_instance = table_instances_[table_num];
table_instance.table_object = Handle<WasmTableObject>::cast(value); table_instance.table_object = Handle<WasmTableObject>::cast(value);
instance->set_table_object(*table_instance.table_object); instance->set_table_object(*table_instance.table_object);
...@@ -1746,7 +1749,7 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) { ...@@ -1746,7 +1749,7 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) {
// Mutable global imports instead have their backing array buffers // Mutable global imports instead have their backing array buffers
// referenced by this instance, and store the address of the imported // referenced by this instance, and store the address of the imported
// global in the {imported_mutable_globals_} array. // global in the {imported_mutable_globals_} array.
WasmGlobal& global = module_->globals[import.index]; const WasmGlobal& global = module_->globals[import.index];
// The mutable-global proposal allows importing i64 values, but only if // The mutable-global proposal allows importing i64 values, but only if
// they are passed as a WebAssembly.Global object. // they are passed as a WebAssembly.Global object.
...@@ -1839,7 +1842,7 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) { ...@@ -1839,7 +1842,7 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) {
} }
template <typename T> template <typename T>
T* InstanceBuilder::GetRawGlobalPtr(WasmGlobal& global) { T* InstanceBuilder::GetRawGlobalPtr(const WasmGlobal& global) {
return reinterpret_cast<T*>(raw_buffer_ptr(globals_, global.offset)); return reinterpret_cast<T*>(raw_buffer_ptr(globals_, global.offset));
} }
...@@ -1931,7 +1934,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) { ...@@ -1931,7 +1934,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
// imported WebAssembly functions into the js_wrappers_ list. // imported WebAssembly functions into the js_wrappers_ list.
for (int index = 0, end = static_cast<int>(module_->import_table.size()); for (int index = 0, end = static_cast<int>(module_->import_table.size());
index < end; ++index) { index < end; ++index) {
WasmImport& import = module_->import_table[index]; const WasmImport& import = module_->import_table[index];
if (import.kind == kExternalFunction) { if (import.kind == kExternalFunction) {
Handle<Object> value = sanitized_imports_[index].value; Handle<Object> value = sanitized_imports_[index].value;
if (WasmExportedFunction::IsWasmExportedFunction(*value)) { if (WasmExportedFunction::IsWasmExportedFunction(*value)) {
...@@ -1971,7 +1974,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) { ...@@ -1971,7 +1974,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
// Process each export in the export table. // Process each export in the export table.
int export_index = 0; // Index into {export_wrappers}. int export_index = 0; // Index into {export_wrappers}.
for (WasmExport& exp : module_->export_table) { for (const WasmExport& exp : module_->export_table) {
Handle<String> name = WasmModuleObject::ExtractUtf8StringFromModuleBytes( Handle<String> name = WasmModuleObject::ExtractUtf8StringFromModuleBytes(
isolate_, module_object_, exp.name) isolate_, module_object_, exp.name)
.ToHandleChecked(); .ToHandleChecked();
...@@ -1986,7 +1989,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) { ...@@ -1986,7 +1989,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
switch (exp.kind) { switch (exp.kind) {
case kExternalFunction: { case kExternalFunction: {
// Wrap and export the code as a JSFunction. // Wrap and export the code as a JSFunction.
WasmFunction& function = module_->functions[exp.index]; const WasmFunction& function = module_->functions[exp.index];
Handle<JSFunction> js_function = js_wrappers_[exp.index]; Handle<JSFunction> js_function = js_wrappers_[exp.index];
if (js_function.is_null()) { if (js_function.is_null()) {
// Wrap the exported code as a JSFunction. // Wrap the exported code as a JSFunction.
...@@ -2014,7 +2017,8 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) { ...@@ -2014,7 +2017,8 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
case kExternalTable: { case kExternalTable: {
// Export a table as a WebAssembly.Table object. // Export a table as a WebAssembly.Table object.
TableInstance& table_instance = table_instances_[exp.index]; TableInstance& table_instance = table_instances_[exp.index];
WasmIndirectFunctionTable& table = module_->function_tables[exp.index]; const WasmIndirectFunctionTable& table =
module_->function_tables[exp.index];
if (table_instance.table_object.is_null()) { if (table_instance.table_object.is_null()) {
uint32_t maximum = table.has_maximum_size ? table.maximum_size uint32_t maximum = table.has_maximum_size ? table.maximum_size
: FLAG_wasm_max_table_size; : FLAG_wasm_max_table_size;
...@@ -2035,7 +2039,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) { ...@@ -2035,7 +2039,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
break; break;
} }
case kExternalGlobal: { case kExternalGlobal: {
WasmGlobal& global = module_->globals[exp.index]; const WasmGlobal& global = module_->globals[exp.index];
if (FLAG_experimental_wasm_mut_global) { if (FLAG_experimental_wasm_mut_global) {
Handle<JSArrayBuffer> buffer; Handle<JSArrayBuffer> buffer;
uint32_t offset; uint32_t offset;
...@@ -2119,7 +2123,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) { ...@@ -2119,7 +2123,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
void InstanceBuilder::InitializeTables(Handle<WasmInstanceObject> instance) { void InstanceBuilder::InitializeTables(Handle<WasmInstanceObject> instance) {
size_t table_count = module_->function_tables.size(); size_t table_count = module_->function_tables.size();
for (size_t index = 0; index < table_count; ++index) { for (size_t index = 0; index < table_count; ++index) {
WasmIndirectFunctionTable& table = module_->function_tables[index]; const WasmIndirectFunctionTable& table = module_->function_tables[index];
TableInstance& table_instance = table_instances_[index]; TableInstance& table_instance = table_instances_[index];
if (!instance->has_indirect_function_table()) { if (!instance->has_indirect_function_table()) {
...@@ -2144,7 +2148,7 @@ void InstanceBuilder::LoadTableSegments(Handle<WasmInstanceObject> instance) { ...@@ -2144,7 +2148,7 @@ void InstanceBuilder::LoadTableSegments(Handle<WasmInstanceObject> instance) {
DCHECK(in_bounds(base, num_entries, table_instance.table_size)); DCHECK(in_bounds(base, num_entries, table_instance.table_size));
for (uint32_t i = 0; i < num_entries; ++i) { for (uint32_t i = 0; i < num_entries; ++i) {
uint32_t func_index = table_init.entries[i]; uint32_t func_index = table_init.entries[i];
WasmFunction* function = &module_->functions[func_index]; const WasmFunction* function = &module_->functions[func_index];
int table_index = static_cast<int>(i + base); int table_index = static_cast<int>(i + base);
// Update the local dispatch table first. // Update the local dispatch table first.
...@@ -2484,7 +2488,7 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep { ...@@ -2484,7 +2488,7 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
Handle<Script> script = CreateWasmScript(job_->isolate_, job_->wire_bytes_); Handle<Script> script = CreateWasmScript(job_->isolate_, job_->wire_bytes_);
Handle<ByteArray> asm_js_offset_table; Handle<ByteArray> asm_js_offset_table;
WasmModule* module = job_->module_.get(); const WasmModule* module = job_->module_.get();
ModuleEnv env = CreateDefaultModuleEnv(module); ModuleEnv env = CreateDefaultModuleEnv(module);
int export_wrapper_size = static_cast<int>(module->num_exported_functions); int export_wrapper_size = static_cast<int>(module->num_exported_functions);
Handle<FixedArray> export_wrappers = Handle<FixedArray> export_wrappers =
...@@ -3100,7 +3104,7 @@ void CompileJsToWasmWrappers(Isolate* isolate, ...@@ -3100,7 +3104,7 @@ void CompileJsToWasmWrappers(Isolate* isolate,
NativeModule* native_module = module_object->native_module(); NativeModule* native_module = module_object->native_module();
wasm::UseTrapHandler use_trap_handler = wasm::UseTrapHandler use_trap_handler =
native_module->use_trap_handler() ? kUseTrapHandler : kNoTrapHandler; native_module->use_trap_handler() ? kUseTrapHandler : kNoTrapHandler;
WasmModule* module = module_object->module(); const WasmModule* module = module_object->module();
for (auto exp : module->export_table) { for (auto exp : module->export_table) {
if (exp.kind != kExternalFunction) continue; if (exp.kind != kExternalFunction) continue;
Address call_target = Address call_target =
......
...@@ -48,9 +48,9 @@ std::unique_ptr<CompilationState, CompilationStateDeleter> NewCompilationState( ...@@ -48,9 +48,9 @@ std::unique_ptr<CompilationState, CompilationStateDeleter> NewCompilationState(
ModuleEnv* GetModuleEnv(CompilationState* compilation_state); ModuleEnv* GetModuleEnv(CompilationState* compilation_state);
MaybeHandle<WasmModuleObject> CompileToModuleObject( MaybeHandle<WasmModuleObject> CompileToModuleObject(
Isolate* isolate, ErrorThrower* thrower, std::shared_ptr<WasmModule> module, Isolate* isolate, ErrorThrower* thrower,
const ModuleWireBytes& wire_bytes, Handle<Script> asm_js_script, std::shared_ptr<const WasmModule> module, const ModuleWireBytes& wire_bytes,
Vector<const byte> asm_js_offset_table_bytes); Handle<Script> asm_js_script, Vector<const byte> asm_js_offset_table_bytes);
MaybeHandle<WasmInstanceObject> InstantiateToInstanceObject( MaybeHandle<WasmInstanceObject> InstantiateToInstanceObject(
Isolate* isolate, ErrorThrower* thrower, Isolate* isolate, ErrorThrower* thrower,
...@@ -148,7 +148,7 @@ class AsyncCompileJob { ...@@ -148,7 +148,7 @@ class AsyncCompileJob {
ModuleWireBytes wire_bytes_; ModuleWireBytes wire_bytes_;
Handle<Context> context_; Handle<Context> context_;
std::unique_ptr<CompilationResultResolver> resolver_; std::unique_ptr<CompilationResultResolver> resolver_;
std::shared_ptr<WasmModule> module_; std::shared_ptr<const WasmModule> module_;
std::vector<DeferredHandles*> deferred_handles_; std::vector<DeferredHandles*> deferred_handles_;
Handle<WasmModuleObject> module_object_; Handle<WasmModuleObject> module_object_;
......
...@@ -612,7 +612,7 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info, ...@@ -612,7 +612,7 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
Handle<WasmInstanceObject> instance(debug_info->wasm_instance(), isolate); Handle<WasmInstanceObject> instance(debug_info->wasm_instance(), isolate);
wasm::NativeModule* native_module = wasm::NativeModule* native_module =
instance->module_object()->native_module(); instance->module_object()->native_module();
wasm::WasmModule* module = instance->module(); const wasm::WasmModule* module = instance->module();
// We may modify js wrappers, as well as wasm functions. Hence the 2 // We may modify js wrappers, as well as wasm functions. Hence the 2
// modification scopes. // modification scopes.
......
...@@ -129,7 +129,7 @@ Handle<JSArray> GetImports(Isolate* isolate, ...@@ -129,7 +129,7 @@ Handle<JSArray> GetImports(Isolate* isolate,
Handle<String> global_string = factory->InternalizeUtf8String("global"); Handle<String> global_string = factory->InternalizeUtf8String("global");
// Create the result array. // Create the result array.
WasmModule* module = module_object->module(); const WasmModule* module = module_object->module();
int num_imports = static_cast<int>(module->import_table.size()); int num_imports = static_cast<int>(module->import_table.size());
Handle<JSArray> array_object = factory->NewJSArray(PACKED_ELEMENTS, 0, 0); Handle<JSArray> array_object = factory->NewJSArray(PACKED_ELEMENTS, 0, 0);
Handle<FixedArray> storage = factory->NewFixedArray(num_imports); Handle<FixedArray> storage = factory->NewFixedArray(num_imports);
...@@ -141,7 +141,7 @@ Handle<JSArray> GetImports(Isolate* isolate, ...@@ -141,7 +141,7 @@ Handle<JSArray> GetImports(Isolate* isolate,
// Populate the result array. // Populate the result array.
for (int index = 0; index < num_imports; ++index) { for (int index = 0; index < num_imports; ++index) {
WasmImport& import = module->import_table[index]; const WasmImport& import = module->import_table[index];
Handle<JSObject> entry = factory->NewJSObject(object_function); Handle<JSObject> entry = factory->NewJSObject(object_function);
...@@ -196,7 +196,7 @@ Handle<JSArray> GetExports(Isolate* isolate, ...@@ -196,7 +196,7 @@ Handle<JSArray> GetExports(Isolate* isolate,
Handle<String> global_string = factory->InternalizeUtf8String("global"); Handle<String> global_string = factory->InternalizeUtf8String("global");
// Create the result array. // Create the result array.
WasmModule* module = module_object->module(); const WasmModule* module = module_object->module();
int num_exports = static_cast<int>(module->export_table.size()); int num_exports = static_cast<int>(module->export_table.size());
Handle<JSArray> array_object = factory->NewJSArray(PACKED_ELEMENTS, 0, 0); Handle<JSArray> array_object = factory->NewJSArray(PACKED_ELEMENTS, 0, 0);
Handle<FixedArray> storage = factory->NewFixedArray(num_exports); Handle<FixedArray> storage = factory->NewFixedArray(num_exports);
...@@ -208,7 +208,7 @@ Handle<JSArray> GetExports(Isolate* isolate, ...@@ -208,7 +208,7 @@ Handle<JSArray> GetExports(Isolate* isolate,
// Populate the result array. // Populate the result array.
for (int index = 0; index < num_exports; ++index) { for (int index = 0; index < num_exports; ++index) {
WasmExport& exp = module->export_table[index]; const WasmExport& exp = module->export_table[index];
Handle<String> export_kind; Handle<String> export_kind;
switch (exp.kind) { switch (exp.kind) {
......
...@@ -52,7 +52,7 @@ CAST_ACCESSOR(WasmTableObject) ...@@ -52,7 +52,7 @@ CAST_ACCESSOR(WasmTableObject)
ACCESSORS(WasmModuleObject, managed_native_module, Managed<wasm::NativeModule>, ACCESSORS(WasmModuleObject, managed_native_module, Managed<wasm::NativeModule>,
kNativeModuleOffset) kNativeModuleOffset)
ACCESSORS(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset) ACCESSORS(WasmModuleObject, export_wrappers, FixedArray, kExportWrappersOffset)
ACCESSORS(WasmModuleObject, managed_module, Managed<wasm::WasmModule>, ACCESSORS(WasmModuleObject, managed_module, Managed<const wasm::WasmModule>,
kManagedModuleOffset) kManagedModuleOffset)
ACCESSORS(WasmModuleObject, script, Script, kScriptOffset) ACCESSORS(WasmModuleObject, script, Script, kScriptOffset)
ACCESSORS(WasmModuleObject, weak_instance_list, WeakArrayList, ACCESSORS(WasmModuleObject, weak_instance_list, WeakArrayList,
...@@ -61,7 +61,7 @@ OPTIONAL_ACCESSORS(WasmModuleObject, asm_js_offset_table, ByteArray, ...@@ -61,7 +61,7 @@ OPTIONAL_ACCESSORS(WasmModuleObject, asm_js_offset_table, ByteArray,
kAsmJsOffsetTableOffset) kAsmJsOffsetTableOffset)
OPTIONAL_ACCESSORS(WasmModuleObject, breakpoint_infos, FixedArray, OPTIONAL_ACCESSORS(WasmModuleObject, breakpoint_infos, FixedArray,
kBreakPointInfosOffset) kBreakPointInfosOffset)
wasm::WasmModule* WasmModuleObject::module() const { const wasm::WasmModule* WasmModuleObject::module() const {
return managed_module()->raw(); return managed_module()->raw();
} }
wasm::NativeModule* WasmModuleObject::native_module() { wasm::NativeModule* WasmModuleObject::native_module() {
......
...@@ -176,17 +176,17 @@ enum DispatchTableElements : int { ...@@ -176,17 +176,17 @@ enum DispatchTableElements : int {
Handle<WasmModuleObject> WasmModuleObject::New( Handle<WasmModuleObject> WasmModuleObject::New(
Isolate* isolate, Handle<FixedArray> export_wrappers, Isolate* isolate, Handle<FixedArray> export_wrappers,
std::shared_ptr<wasm::WasmModule> shared_module, wasm::ModuleEnv& env, std::shared_ptr<const wasm::WasmModule> shared_module, wasm::ModuleEnv& env,
std::unique_ptr<const uint8_t[]> wire_bytes, size_t wire_bytes_len, std::unique_ptr<const uint8_t[]> wire_bytes, size_t wire_bytes_len,
Handle<Script> script, Handle<ByteArray> asm_js_offset_table) { Handle<Script> script, Handle<ByteArray> asm_js_offset_table) {
WasmModule* module = shared_module.get(); const WasmModule* module = shared_module.get();
DCHECK_EQ(module, env.module); DCHECK_EQ(module, env.module);
size_t module_size = EstimateWasmModuleSize(module); size_t module_size = EstimateWasmModuleSize(module);
// The {managed_module} will take shared ownership of the {WasmModule} object, // The {managed_module} will take shared ownership of the {WasmModule} object,
// and release it when the GC reclaim the managed. // and release it when the GC reclaim the managed.
Handle<Managed<WasmModule>> managed_module = Handle<Managed<const WasmModule>> managed_module =
Managed<WasmModule>::FromSharedPtr(isolate, module_size, Managed<const WasmModule>::FromSharedPtr(isolate, module_size,
std::move(shared_module)); std::move(shared_module));
// Now create the {WasmModuleObject}. // Now create the {WasmModuleObject}.
Handle<JSFunction> module_cons( Handle<JSFunction> module_cons(
...@@ -228,7 +228,7 @@ bool WasmModuleObject::SetBreakPoint(Handle<WasmModuleObject> module_object, ...@@ -228,7 +228,7 @@ bool WasmModuleObject::SetBreakPoint(Handle<WasmModuleObject> module_object,
// Find the function for this breakpoint. // Find the function for this breakpoint.
int func_index = module_object->GetContainingFunction(*position); int func_index = module_object->GetContainingFunction(*position);
if (func_index < 0) return false; if (func_index < 0) return false;
WasmFunction& func = module_object->module()->functions[func_index]; const WasmFunction& func = module_object->module()->functions[func_index];
int offset_in_func = *position - func.code.offset(); int offset_in_func = *position - func.code.offset();
// According to the current design, we should only be called with valid // According to the current design, we should only be called with valid
...@@ -372,7 +372,7 @@ void WasmModuleObject::SetBreakpointsOnNewInstance( ...@@ -372,7 +372,7 @@ void WasmModuleObject::SetBreakpointsOnNewInstance(
// Find the function for this breakpoint, and set the breakpoint. // Find the function for this breakpoint, and set the breakpoint.
int func_index = module_object->GetContainingFunction(position); int func_index = module_object->GetContainingFunction(position);
DCHECK_LE(0, func_index); DCHECK_LE(0, func_index);
WasmFunction& func = module_object->module()->functions[func_index]; const WasmFunction& func = module_object->module()->functions[func_index];
int offset_in_func = position - func.code.offset(); int offset_in_func = position - func.code.offset();
WasmDebugInfo::SetBreakpoint(debug_info, func_index, offset_in_func); WasmDebugInfo::SetBreakpoint(debug_info, func_index, offset_in_func);
} }
...@@ -431,7 +431,8 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable( ...@@ -431,7 +431,8 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable(
module_object->set_asm_js_offset_table(*decoded_table); module_object->set_asm_js_offset_table(*decoded_table);
int idx = 0; int idx = 0;
std::vector<WasmFunction>& wasm_funs = module_object->module()->functions; const std::vector<WasmFunction>& wasm_funs =
module_object->module()->functions;
for (int func = 0; func < num_functions; ++func) { for (int func = 0; func < num_functions; ++func) {
std::vector<wasm::AsmJsOffsetEntry>& func_asm_offsets = std::vector<wasm::AsmJsOffsetEntry>& func_asm_offsets =
asm_offsets.val[func]; asm_offsets.val[func];
...@@ -520,7 +521,7 @@ bool WasmModuleObject::GetPossibleBreakpoints( ...@@ -520,7 +521,7 @@ bool WasmModuleObject::GetPossibleBreakpoints(
std::vector<v8::debug::BreakLocation>* locations) { std::vector<v8::debug::BreakLocation>* locations) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
std::vector<WasmFunction>& functions = module()->functions; const std::vector<WasmFunction>& functions = module()->functions;
if (start.GetLineNumber() < 0 || start.GetColumnNumber() < 0 || if (start.GetLineNumber() < 0 || start.GetColumnNumber() < 0 ||
(!end.IsEmpty() && (!end.IsEmpty() &&
(end.GetLineNumber() < 0 || end.GetColumnNumber() < 0))) (end.GetLineNumber() < 0 || end.GetColumnNumber() < 0)))
...@@ -566,7 +567,7 @@ bool WasmModuleObject::GetPossibleBreakpoints( ...@@ -566,7 +567,7 @@ bool WasmModuleObject::GetPossibleBreakpoints(
for (uint32_t func_idx = start_func_index; func_idx <= end_func_index; for (uint32_t func_idx = start_func_index; func_idx <= end_func_index;
++func_idx) { ++func_idx) {
WasmFunction& func = functions[func_idx]; const WasmFunction& func = functions[func_idx];
if (func.code.length() == 0) continue; if (func.code.length() == 0) continue;
wasm::BodyLocalDecls locals(&tmp); wasm::BodyLocalDecls locals(&tmp);
...@@ -637,7 +638,7 @@ MaybeHandle<String> WasmModuleObject::ExtractUtf8StringFromModuleBytes( ...@@ -637,7 +638,7 @@ MaybeHandle<String> WasmModuleObject::ExtractUtf8StringFromModuleBytes(
MaybeHandle<String> WasmModuleObject::GetModuleNameOrNull( MaybeHandle<String> WasmModuleObject::GetModuleNameOrNull(
Isolate* isolate, Handle<WasmModuleObject> module_object) { Isolate* isolate, Handle<WasmModuleObject> module_object) {
WasmModule* module = module_object->module(); const WasmModule* module = module_object->module();
if (!module->name.is_set()) return {}; if (!module->name.is_set()) return {};
return ExtractUtf8StringFromModuleBytes(isolate, module_object, module->name); return ExtractUtf8StringFromModuleBytes(isolate, module_object, module->name);
} }
...@@ -672,14 +673,14 @@ Vector<const uint8_t> WasmModuleObject::GetRawFunctionName( ...@@ -672,14 +673,14 @@ Vector<const uint8_t> WasmModuleObject::GetRawFunctionName(
} }
int WasmModuleObject::GetFunctionOffset(uint32_t func_index) { int WasmModuleObject::GetFunctionOffset(uint32_t func_index) {
std::vector<WasmFunction>& functions = module()->functions; const std::vector<WasmFunction>& functions = module()->functions;
if (static_cast<uint32_t>(func_index) >= functions.size()) return -1; if (static_cast<uint32_t>(func_index) >= functions.size()) return -1;
DCHECK_GE(kMaxInt, functions[func_index].code.offset()); DCHECK_GE(kMaxInt, functions[func_index].code.offset());
return static_cast<int>(functions[func_index].code.offset()); return static_cast<int>(functions[func_index].code.offset());
} }
int WasmModuleObject::GetContainingFunction(uint32_t byte_offset) { int WasmModuleObject::GetContainingFunction(uint32_t byte_offset) {
std::vector<WasmFunction>& functions = module()->functions; const std::vector<WasmFunction>& functions = module()->functions;
// Binary search for a function containing the given position. // Binary search for a function containing the given position.
int left = 0; // inclusive int left = 0; // inclusive
...@@ -694,7 +695,7 @@ int WasmModuleObject::GetContainingFunction(uint32_t byte_offset) { ...@@ -694,7 +695,7 @@ int WasmModuleObject::GetContainingFunction(uint32_t byte_offset) {
} }
} }
// If the found function does not contains the given position, return -1. // If the found function does not contains the given position, return -1.
WasmFunction& func = functions[left]; const WasmFunction& func = functions[left];
if (byte_offset < func.code.offset() || if (byte_offset < func.code.offset() ||
byte_offset >= func.code.end_offset()) { byte_offset >= func.code.end_offset()) {
return -1; return -1;
...@@ -708,7 +709,7 @@ bool WasmModuleObject::GetPositionInfo(uint32_t position, ...@@ -708,7 +709,7 @@ bool WasmModuleObject::GetPositionInfo(uint32_t position,
int func_index = GetContainingFunction(position); int func_index = GetContainingFunction(position);
if (func_index < 0) return false; if (func_index < 0) return false;
WasmFunction& function = module()->functions[func_index]; const WasmFunction& function = module()->functions[func_index];
info->line = func_index; info->line = func_index;
info->column = position - function.code.offset(); info->column = position - function.code.offset();
...@@ -1188,7 +1189,9 @@ void WasmInstanceObject::SetRawMemory(byte* mem_start, uint32_t mem_size) { ...@@ -1188,7 +1189,9 @@ void WasmInstanceObject::SetRawMemory(byte* mem_start, uint32_t mem_size) {
set_memory_mask(mem_mask64); set_memory_mask(mem_mask64);
} }
WasmModule* WasmInstanceObject::module() { return module_object()->module(); } const WasmModule* WasmInstanceObject::module() {
return module_object()->module();
}
Handle<WasmDebugInfo> WasmInstanceObject::GetOrCreateDebugInfo( Handle<WasmDebugInfo> WasmInstanceObject::GetOrCreateDebugInfo(
Handle<WasmInstanceObject> instance) { Handle<WasmInstanceObject> instance) {
......
...@@ -107,8 +107,8 @@ class WasmModuleObject : public JSObject { ...@@ -107,8 +107,8 @@ class WasmModuleObject : public JSObject {
DECL_ACCESSORS(managed_native_module, Managed<wasm::NativeModule>) DECL_ACCESSORS(managed_native_module, Managed<wasm::NativeModule>)
inline wasm::NativeModule* native_module(); inline wasm::NativeModule* native_module();
DECL_ACCESSORS(export_wrappers, FixedArray) DECL_ACCESSORS(export_wrappers, FixedArray)
DECL_ACCESSORS(managed_module, Managed<wasm::WasmModule>) DECL_ACCESSORS(managed_module, Managed<const wasm::WasmModule>)
inline wasm::WasmModule* module() const; inline const wasm::WasmModule* module() const;
DECL_ACCESSORS(script, Script) DECL_ACCESSORS(script, Script)
DECL_ACCESSORS(weak_instance_list, WeakArrayList) DECL_ACCESSORS(weak_instance_list, WeakArrayList)
DECL_OPTIONAL_ACCESSORS(asm_js_offset_table, ByteArray) DECL_OPTIONAL_ACCESSORS(asm_js_offset_table, ByteArray)
...@@ -136,7 +136,7 @@ class WasmModuleObject : public JSObject { ...@@ -136,7 +136,7 @@ class WasmModuleObject : public JSObject {
static Handle<WasmModuleObject> New( static Handle<WasmModuleObject> New(
Isolate* isolate, Handle<FixedArray> export_wrappers, Isolate* isolate, Handle<FixedArray> export_wrappers,
std::shared_ptr<wasm::WasmModule> module, wasm::ModuleEnv& env, std::shared_ptr<const wasm::WasmModule> module, wasm::ModuleEnv& env,
std::unique_ptr<const uint8_t[]> wire_bytes, size_t wire_bytes_len, std::unique_ptr<const uint8_t[]> wire_bytes, size_t wire_bytes_len,
Handle<Script> script, Handle<ByteArray> asm_js_offset_table); Handle<Script> script, Handle<ByteArray> asm_js_offset_table);
...@@ -437,7 +437,7 @@ class WasmInstanceObject : public JSObject { ...@@ -437,7 +437,7 @@ class WasmInstanceObject : public JSObject {
WASM_INSTANCE_OBJECT_FIELDS) WASM_INSTANCE_OBJECT_FIELDS)
#undef WASM_INSTANCE_OBJECT_FIELDS #undef WASM_INSTANCE_OBJECT_FIELDS
V8_EXPORT_PRIVATE wasm::WasmModule* module(); V8_EXPORT_PRIVATE const wasm::WasmModule* module();
static bool EnsureIndirectFunctionTableWithMinimumSize( static bool EnsureIndirectFunctionTableWithMinimumSize(
Handle<WasmInstanceObject> instance, uint32_t minimum_size); Handle<WasmInstanceObject> instance, uint32_t minimum_size);
......
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