Commit ebe0ae55 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Move {WasmModuleObject::GetFunctionOffset}.

This introduces {GetWasmFunctionOffset} to replace the above method,
since calculating offsets into the wire bytes is independent of the
concrete module object and hence only needs the shared decoded module.

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

Change-Id: I6818de4589e26dd8f69dfb71d15bbca127c7ee3e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1809368Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63862}
parent 26372107
...@@ -9237,8 +9237,9 @@ int debug::Script::GetSourceOffset(const debug::Location& location) const { ...@@ -9237,8 +9237,9 @@ int debug::Script::GetSourceOffset(const debug::Location& location) const {
i::Handle<i::Script> script = Utils::OpenHandle(this); i::Handle<i::Script> script = Utils::OpenHandle(this);
if (script->type() == i::Script::TYPE_WASM) { if (script->type() == i::Script::TYPE_WASM) {
if (this->SourceMappingURL().IsEmpty()) { if (this->SourceMappingURL().IsEmpty()) {
return i::WasmModuleObject::cast(script->wasm_module_object()) i::wasm::NativeModule* native_module = script->wasm_native_module();
.GetFunctionOffset(location.GetLineNumber()) + const i::wasm::WasmModule* module = native_module->module();
return i::wasm::GetWasmFunctionOffset(module, location.GetLineNumber()) +
location.GetColumnNumber(); location.GetColumnNumber();
} }
DCHECK_EQ(0, location.GetLineNumber()); DCHECK_EQ(0, location.GetLineNumber());
......
...@@ -603,7 +603,7 @@ int WasmStackFrame::GetColumnNumber() { return GetModuleOffset(); } ...@@ -603,7 +603,7 @@ int WasmStackFrame::GetColumnNumber() { return GetModuleOffset(); }
int WasmStackFrame::GetModuleOffset() const { int WasmStackFrame::GetModuleOffset() const {
const int function_offset = const int function_offset =
wasm_instance_->module_object().GetFunctionOffset(wasm_func_index_); GetWasmFunctionOffset(wasm_instance_->module(), wasm_func_index_);
return function_offset + GetPosition(); return function_offset + GetPosition();
} }
......
...@@ -491,8 +491,7 @@ int ScriptLinePosition(Handle<Script> script, int line) { ...@@ -491,8 +491,7 @@ int ScriptLinePosition(Handle<Script> script, int line) {
if (line < 0) return -1; if (line < 0) return -1;
if (script->type() == Script::TYPE_WASM) { if (script->type() == Script::TYPE_WASM) {
return WasmModuleObject::cast(script->wasm_module_object()) return GetWasmFunctionOffset(script->wasm_native_module()->module(), line);
.GetFunctionOffset(line);
} }
Script::InitLineEnds(script); Script::InitLineEnds(script);
......
...@@ -318,7 +318,8 @@ class InterpreterHandle { ...@@ -318,7 +318,8 @@ class InterpreterHandle {
DCHECK_LT(0, thread->GetFrameCount()); DCHECK_LT(0, thread->GetFrameCount());
auto frame = thread->GetFrame(thread->GetFrameCount() - 1); auto frame = thread->GetFrame(thread->GetFrameCount() - 1);
return module_object->GetFunctionOffset(frame->function()->func_index) + return GetWasmFunctionOffset(module_object->module(),
frame->function()->func_index) +
frame->pc(); frame->pc();
} }
......
...@@ -59,6 +59,14 @@ int GetExportWrapperIndex(const WasmModule* module, const FunctionSig* sig, ...@@ -59,6 +59,14 @@ int GetExportWrapperIndex(const WasmModule* module, const FunctionSig* sig,
return result; return result;
} }
// static
int GetWasmFunctionOffset(const WasmModule* module, uint32_t func_index) {
const std::vector<WasmFunction>& functions = module->functions;
if (static_cast<uint32_t>(func_index) >= functions.size()) return -1;
DCHECK_GE(kMaxInt, functions[func_index].code.offset());
return static_cast<int>(functions[func_index].code.offset());
}
// static // static
v8::debug::WasmDisassembly DisassembleWasmFunction( v8::debug::WasmDisassembly DisassembleWasmFunction(
const WasmModule* module, const ModuleWireBytes& wire_bytes, const WasmModule* module, const ModuleWireBytes& wire_bytes,
......
...@@ -245,6 +245,11 @@ V8_EXPORT_PRIVATE int MaxNumExportWrappers(const WasmModule* module); ...@@ -245,6 +245,11 @@ V8_EXPORT_PRIVATE int MaxNumExportWrappers(const WasmModule* module);
int GetExportWrapperIndex(const WasmModule* module, const FunctionSig* sig, int GetExportWrapperIndex(const WasmModule* module, const FunctionSig* sig,
bool is_import); bool is_import);
// Return the byte offset of the function identified by the given index.
// The offset will be relative to the start of the module bytes.
// Returns -1 if the function index is invalid.
int GetWasmFunctionOffset(const WasmModule* module, uint32_t func_index);
// Compute the disassembly of a wasm function. // Compute the disassembly of a wasm function.
// Returns the disassembly string and a list of <byte_offset, line, column> // Returns the disassembly string and a list of <byte_offset, line, column>
// entries, mapping wasm byte offsets to line and column in the disassembly. // entries, mapping wasm byte offsets to line and column in the disassembly.
......
...@@ -496,7 +496,7 @@ int WasmModuleObject::GetSourcePosition(Handle<WasmModuleObject> module_object, ...@@ -496,7 +496,7 @@ int WasmModuleObject::GetSourcePosition(Handle<WasmModuleObject> module_object,
if (module->origin == wasm::kWasmOrigin) { if (module->origin == wasm::kWasmOrigin) {
// for non-asm.js modules, we just add the function's start offset // for non-asm.js modules, we just add the function's start offset
// to make a module-relative position. // to make a module-relative position.
return byte_offset + module_object->GetFunctionOffset(func_index); return byte_offset + GetWasmFunctionOffset(module, func_index);
} }
// asm.js modules have an additional offset table that must be searched. // asm.js modules have an additional offset table that must be searched.
...@@ -689,13 +689,6 @@ Vector<const uint8_t> WasmModuleObject::GetRawFunctionName( ...@@ -689,13 +689,6 @@ Vector<const uint8_t> WasmModuleObject::GetRawFunctionName(
return Vector<const uint8_t>::cast(name); return Vector<const uint8_t>::cast(name);
} }
int WasmModuleObject::GetFunctionOffset(uint32_t func_index) {
const std::vector<WasmFunction>& functions = module()->functions;
if (static_cast<uint32_t>(func_index) >= functions.size()) return -1;
DCHECK_GE(kMaxInt, 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) {
const std::vector<WasmFunction>& functions = module()->functions; const std::vector<WasmFunction>& functions = module()->functions;
......
...@@ -198,11 +198,6 @@ class WasmModuleObject : public JSObject { ...@@ -198,11 +198,6 @@ class WasmModuleObject : public JSObject {
// Does not allocate, hence gc-safe. // Does not allocate, hence gc-safe.
Vector<const uint8_t> GetRawFunctionName(uint32_t func_index); Vector<const uint8_t> GetRawFunctionName(uint32_t func_index);
// Return the byte offset of the function identified by the given index.
// The offset will be relative to the start of the module bytes.
// Returns -1 if the function index is invalid.
int GetFunctionOffset(uint32_t func_index);
// Returns the function containing the given byte offset. // Returns the function containing the given byte offset.
// Returns -1 if the byte offset is not contained in any function of this // Returns -1 if the byte offset is not contained in any function of this
// module. // module.
......
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