Commit 78fa1453 authored by Andreas Haas's avatar Andreas Haas Committed by V8 LUCI CQ

[wasm] Change return type of WasmCode::index to int

WebAssembly.Function and functions of the C-API do not have a function
index. Their index is kAnonymousFuncIndex = -1. Therefore it is
necessary to change the return type of WasmCode::index() from uint to
int.

The changes in WasmFrame::Print produces output like the following:

[9]: CWasmEntryFrame [pc: 0x9d200084091]
[10]: Anonymous wasm wrapper [pc: 0x101c5975c972]
[11]: WASM [wasm://wasm/f4bee83a], function #1 ('fibonacci_wasm'), pc=0x101c5975c5dc (+0x7c), pos=123 (+32)

R=jkummerow@chromium.org

Bug: v8:11713
Change-Id: I1012e92713d64d24ed2a92729dd3c2e4a013b9c0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2871455Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74355}
parent fc377b05
......@@ -1862,8 +1862,13 @@ int BuiltinFrame::ComputeParametersCount() const {
#if V8_ENABLE_WEBASSEMBLY
void WasmFrame::Print(StringStream* accumulator, PrintMode mode,
int index) const {
wasm::WasmCodeRefScope code_ref_scope;
PrintIndex(accumulator, mode, index);
if (function_index() == wasm::kAnonymousFuncIndex) {
accumulator->Add("Anonymous wasm wrapper [pc: %p]\n",
reinterpret_cast<void*>(pc()));
return;
}
wasm::WasmCodeRefScope code_ref_scope;
accumulator->Add("WASM [");
accumulator->PrintName(script().name());
Address instruction_start = isolate()
......@@ -1907,7 +1912,7 @@ WasmModuleObject WasmFrame::module_object() const {
return wasm_instance().module_object();
}
uint32_t WasmFrame::function_index() const {
int WasmFrame::function_index() const {
wasm::WasmCodeRefScope code_ref_scope;
return wasm_code()->index();
}
......
......@@ -962,7 +962,7 @@ class WasmFrame : public TypedFrame {
V8_EXPORT_PRIVATE WasmInstanceObject wasm_instance() const;
V8_EXPORT_PRIVATE wasm::NativeModule* native_module() const;
wasm::WasmCode* wasm_code() const;
uint32_t function_index() const;
int function_index() const;
Script script() const;
// Byte position in the module, or asm.js source position.
int position() const override;
......
......@@ -3118,7 +3118,8 @@ void CompilationStateImpl::OnFinishedUnits(Vector<WasmCode*> code_vector) {
DCHECK_NOT_NULL(code);
DCHECK_LT(code->index(), native_module_->num_functions());
if (code->index() < native_module_->num_imported_functions()) {
if (code->index() <
static_cast<int>(native_module_->num_imported_functions())) {
// Import wrapper.
DCHECK_EQ(code->tier(), ExecutionTier::kTurbofan);
outstanding_baseline_units_--;
......
......@@ -1162,7 +1162,7 @@ WasmCode* NativeModule::PublishCodeLocked(
// guaranteed to be valid.
WasmCodeRefScope::AddRef(code);
if (code->IsAnonymous() || code->index() < module_->num_imported_functions) {
if (code->index() < static_cast<int>(module_->num_imported_functions)) {
return code;
}
......
......@@ -161,11 +161,7 @@ class V8_EXPORT_PRIVATE WasmCode final {
return {reloc_info().end(), static_cast<size_t>(source_positions_size_)};
}
// TODO(clemensb): Make this return int.
uint32_t index() const {
DCHECK_LE(0, index_);
return index_;
}
int index() const { return index_; }
// Anonymous functions are functions that don't carry an index.
bool IsAnonymous() const { return index_ == kAnonymousFuncIndex; }
Kind kind() const { return KindField::decode(flags_); }
......
......@@ -246,8 +246,10 @@ Handle<String> WasmModuleObject::GetFunctionName(
.ToHandleChecked();
}
Vector<const uint8_t> WasmModuleObject::GetRawFunctionName(
uint32_t func_index) {
Vector<const uint8_t> WasmModuleObject::GetRawFunctionName(int func_index) {
if (func_index == wasm::kAnonymousFuncIndex) {
return Vector<const uint8_t>({nullptr, 0});
}
DCHECK_GT(module()->functions.size(), func_index);
wasm::ModuleWireBytes wire_bytes(native_module()->wire_bytes());
wasm::WireBytesRef name_ref =
......
......@@ -176,7 +176,7 @@ class WasmModuleObject : public JSObject {
// given index.
// Meant to be used for debugging or frame printing.
// Does not allocate, hence gc-safe.
Vector<const uint8_t> GetRawFunctionName(uint32_t func_index);
Vector<const uint8_t> GetRawFunctionName(int func_index);
// Extract a portion of the wire bytes as UTF-8 string, optionally
// internalized. (Prefer to internalize early if the string will be used for a
......
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