[wasm] Remove StartDecoding method
Move it into the constructor instead, to simplify the API. R=ahaas@chromium.org Bug: v8:13447 Change-Id: I563a409c57c3cfdd91998c7c459f4e099211ccf7 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4062042 Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/main@{#84589}
This commit is contained in:
parent
ff5e83144e
commit
48a6193e67
@ -2147,7 +2147,6 @@ class AsyncStreamingProcessor final : public StreamingProcessor {
|
||||
bool prefix_cache_hit_ = false;
|
||||
bool before_code_section_ = true;
|
||||
std::shared_ptr<Counters> async_counters_;
|
||||
AccountingAllocator* allocator_;
|
||||
|
||||
// Running hash of the wire bytes up to code section size, but excluding the
|
||||
// code section itself. Used by the {NativeModuleCache} to detect potential
|
||||
@ -2729,11 +2728,10 @@ void AsyncCompileJob::FinishModule() {
|
||||
AsyncStreamingProcessor::AsyncStreamingProcessor(
|
||||
AsyncCompileJob* job, std::shared_ptr<Counters> async_counters,
|
||||
AccountingAllocator* allocator)
|
||||
: decoder_(job->enabled_features_),
|
||||
: decoder_(job->enabled_features_, allocator),
|
||||
job_(job),
|
||||
compilation_unit_builder_(nullptr),
|
||||
async_counters_(async_counters),
|
||||
allocator_(allocator) {}
|
||||
async_counters_(async_counters) {}
|
||||
|
||||
AsyncStreamingProcessor::~AsyncStreamingProcessor() {
|
||||
if (job_->native_module_ && job_->native_module_->wire_bytes().empty()) {
|
||||
@ -2786,7 +2784,6 @@ void AsyncStreamingProcessor::FinishAsyncCompileJobWithError(
|
||||
bool AsyncStreamingProcessor::ProcessModuleHeader(
|
||||
base::Vector<const uint8_t> bytes, uint32_t offset) {
|
||||
TRACE_STREAMING("Process module header...\n");
|
||||
decoder_.StartDecoding(GetWasmEngine()->allocator());
|
||||
decoder_.DecodeModuleHeader(bytes, offset);
|
||||
if (!decoder_.ok()) {
|
||||
FinishAsyncCompileJobWithError(decoder_.FinishDecoding().error());
|
||||
@ -2925,8 +2922,8 @@ void AsyncStreamingProcessor::ProcessFunctionBody(
|
||||
if (validate_lazily_compiled_function) {
|
||||
// The native module does not own the wire bytes until {SetWireBytes} is
|
||||
// called in {OnFinishedStream}. Validation must use {bytes} parameter.
|
||||
DecodeResult result = ValidateSingleFunction(module, func_index, bytes,
|
||||
allocator_, enabled_features);
|
||||
DecodeResult result = ValidateSingleFunction(
|
||||
module, func_index, bytes, module->allocator(), enabled_features);
|
||||
|
||||
if (result.failed()) {
|
||||
FinishAsyncCompileJobWithError(result.error(), kErrorInFunction);
|
||||
|
@ -307,13 +307,17 @@ class ModuleDecoderTemplate : public Decoder {
|
||||
public:
|
||||
ModuleDecoderTemplate(WasmFeatures enabled_features,
|
||||
base::Vector<const uint8_t> wire_bytes,
|
||||
ModuleOrigin origin, Tracer& tracer)
|
||||
ModuleOrigin origin, AccountingAllocator* allocator,
|
||||
Tracer& tracer)
|
||||
: Decoder(wire_bytes),
|
||||
enabled_features_(enabled_features),
|
||||
module_(std::make_shared<WasmModule>(
|
||||
std::make_unique<Zone>(allocator, "signatures"))),
|
||||
module_start_(wire_bytes.begin()),
|
||||
module_end_(wire_bytes.end()),
|
||||
tracer_(tracer),
|
||||
origin_(origin) {}
|
||||
tracer_(tracer) {
|
||||
module_->origin = origin;
|
||||
}
|
||||
|
||||
void onFirstError() override {
|
||||
pc_ = end_; // On error, terminate section decoding loop.
|
||||
@ -345,16 +349,6 @@ class ModuleDecoderTemplate : public Decoder {
|
||||
}
|
||||
}
|
||||
|
||||
void StartDecoding(AccountingAllocator* allocator) {
|
||||
CHECK_NULL(module_);
|
||||
module_.reset(
|
||||
new WasmModule(std::make_unique<Zone>(allocator, "signatures")));
|
||||
module_->initial_pages = 0;
|
||||
module_->maximum_pages = 0;
|
||||
module_->mem_export = false;
|
||||
module_->origin = origin_;
|
||||
}
|
||||
|
||||
void DecodeModuleHeader(base::Vector<const uint8_t> bytes, uint8_t offset) {
|
||||
if (failed()) return;
|
||||
Reset(bytes, offset);
|
||||
@ -1013,7 +1007,8 @@ class ModuleDecoderTemplate : public Decoder {
|
||||
tracer_.NextLine();
|
||||
}
|
||||
// Check for duplicate exports (except for asm.js).
|
||||
if (ok() && origin_ == kWasmOrigin && module_->export_table.size() > 1) {
|
||||
if (ok() && module_->origin == kWasmOrigin &&
|
||||
module_->export_table.size() > 1) {
|
||||
std::vector<WasmExport> sorted_exports(module_->export_table);
|
||||
|
||||
auto cmp_less = [this](const WasmExport& a, const WasmExport& b) {
|
||||
@ -1605,8 +1600,7 @@ class ModuleDecoderTemplate : public Decoder {
|
||||
}
|
||||
|
||||
// Decodes an entire module.
|
||||
ModuleResult DecodeModule(AccountingAllocator* allocator,
|
||||
bool validate_functions) {
|
||||
ModuleResult DecodeModule(bool validate_functions) {
|
||||
base::Vector<const byte> wire_bytes(start_, end_ - start_);
|
||||
size_t max_size = max_module_size();
|
||||
if (wire_bytes.size() > max_size) {
|
||||
@ -1614,7 +1608,6 @@ class ModuleDecoderTemplate : public Decoder {
|
||||
max_size, wire_bytes.size()}};
|
||||
}
|
||||
|
||||
StartDecoding(allocator);
|
||||
uint32_t offset = 0;
|
||||
DecodeModuleHeader(wire_bytes, offset);
|
||||
if (failed()) return toResult(nullptr);
|
||||
@ -1711,7 +1704,6 @@ class ModuleDecoderTemplate : public Decoder {
|
||||
kBitsPerByte * sizeof(ModuleDecoderTemplate::seen_unordered_sections_) >
|
||||
kLastKnownModuleSection,
|
||||
"not enough bits");
|
||||
ModuleOrigin origin_;
|
||||
AccountingAllocator allocator_;
|
||||
Zone init_expr_zone_{&allocator_, "constant expr. zone"};
|
||||
|
||||
@ -2076,7 +2068,8 @@ class ModuleDecoderTemplate : public Decoder {
|
||||
uint32_t type_length;
|
||||
ValueType result = value_type_reader::read_value_type<FullValidationTag>(
|
||||
this, pc_, &type_length,
|
||||
origin_ == kWasmOrigin ? enabled_features_ : WasmFeatures::None());
|
||||
module_->origin == kWasmOrigin ? enabled_features_
|
||||
: WasmFeatures::None());
|
||||
value_type_reader::ValidateValueType<FullValidationTag>(
|
||||
this, pc_, module_.get(), result);
|
||||
tracer_.Bytes(pc_, type_length);
|
||||
|
@ -75,9 +75,10 @@ const char* SectionName(SectionCode code) {
|
||||
class ModuleDecoderImpl : public ModuleDecoderTemplate<NoTracer> {
|
||||
public:
|
||||
ModuleDecoderImpl(WasmFeatures enabled_features,
|
||||
base::Vector<const uint8_t> wire_bytes, ModuleOrigin origin)
|
||||
base::Vector<const uint8_t> wire_bytes, ModuleOrigin origin,
|
||||
AccountingAllocator* allocator)
|
||||
: ModuleDecoderTemplate<NoTracer>(enabled_features, wire_bytes, origin,
|
||||
no_tracer_) {}
|
||||
allocator, no_tracer_) {}
|
||||
|
||||
private:
|
||||
NoTracer no_tracer_;
|
||||
@ -141,19 +142,23 @@ ModuleResult DecodeWasmModule(WasmFeatures enabled_features,
|
||||
base::Vector<const uint8_t> wire_bytes,
|
||||
bool validate_functions, ModuleOrigin origin,
|
||||
AccountingAllocator* allocator) {
|
||||
ModuleDecoderImpl decoder{enabled_features, wire_bytes, origin};
|
||||
return decoder.DecodeModule(allocator, validate_functions);
|
||||
ModuleDecoderImpl decoder{enabled_features, wire_bytes, origin, allocator};
|
||||
return decoder.DecodeModule(validate_functions);
|
||||
}
|
||||
|
||||
ModuleResult DecodeWasmModuleForDisassembler(
|
||||
base::Vector<const uint8_t> wire_bytes, AccountingAllocator* allocator) {
|
||||
constexpr bool kNoValidateFunctions = false;
|
||||
ModuleDecoderImpl decoder(WasmFeatures::All(), wire_bytes, kWasmOrigin);
|
||||
return decoder.DecodeModule(allocator, kNoValidateFunctions);
|
||||
ModuleDecoderImpl decoder{WasmFeatures::All(), wire_bytes, kWasmOrigin,
|
||||
allocator};
|
||||
return decoder.DecodeModule(kNoValidateFunctions);
|
||||
}
|
||||
|
||||
ModuleDecoder::ModuleDecoder(WasmFeatures enabled_features)
|
||||
: enabled_features_(enabled_features) {}
|
||||
ModuleDecoder::ModuleDecoder(WasmFeatures enabled_features,
|
||||
AccountingAllocator* allocator)
|
||||
: impl_(std::make_unique<ModuleDecoderImpl>(enabled_features,
|
||||
base::Vector<const uint8_t>{},
|
||||
kWasmOrigin, allocator)) {}
|
||||
|
||||
ModuleDecoder::~ModuleDecoder() = default;
|
||||
|
||||
@ -161,14 +166,6 @@ const std::shared_ptr<WasmModule>& ModuleDecoder::shared_module() const {
|
||||
return impl_->shared_module();
|
||||
}
|
||||
|
||||
void ModuleDecoder::StartDecoding(AccountingAllocator* allocator,
|
||||
ModuleOrigin origin) {
|
||||
DCHECK_NULL(impl_);
|
||||
static constexpr base::Vector<const uint8_t> kNoWireBytes{nullptr, 0};
|
||||
impl_.reset(new ModuleDecoderImpl(enabled_features_, kNoWireBytes, origin));
|
||||
impl_->StartDecoding(allocator);
|
||||
}
|
||||
|
||||
void ModuleDecoder::DecodeModuleHeader(base::Vector<const uint8_t> bytes,
|
||||
uint32_t offset) {
|
||||
impl_->DecodeModuleHeader(bytes, offset);
|
||||
@ -212,16 +209,16 @@ bool ModuleDecoder::ok() { return impl_->ok(); }
|
||||
Result<const FunctionSig*> DecodeWasmSignatureForTesting(
|
||||
WasmFeatures enabled_features, Zone* zone,
|
||||
base::Vector<const uint8_t> bytes) {
|
||||
ModuleDecoderImpl decoder(enabled_features, bytes, kWasmOrigin);
|
||||
ModuleDecoderImpl decoder{enabled_features, bytes, kWasmOrigin,
|
||||
zone->allocator()};
|
||||
return decoder.toResult(decoder.DecodeFunctionSignature(zone, bytes.begin()));
|
||||
}
|
||||
|
||||
ConstantExpression DecodeWasmInitExprForTesting(
|
||||
WasmFeatures enabled_features, base::Vector<const uint8_t> bytes,
|
||||
ValueType expected) {
|
||||
ModuleDecoderImpl decoder(enabled_features, bytes, kWasmOrigin);
|
||||
AccountingAllocator allocator;
|
||||
decoder.StartDecoding(&allocator);
|
||||
ModuleDecoderImpl decoder{enabled_features, bytes, kWasmOrigin, &allocator};
|
||||
return decoder.DecodeInitExprForTesting(expected);
|
||||
}
|
||||
|
||||
@ -233,7 +230,8 @@ FunctionResult DecodeWasmFunctionForTesting(
|
||||
WasmError{0, "size > maximum function size (%zu): %zu",
|
||||
kV8MaxWasmFunctionSize, function_bytes.size()}};
|
||||
}
|
||||
ModuleDecoderImpl decoder(enabled_features, function_bytes, kWasmOrigin);
|
||||
ModuleDecoderImpl decoder{enabled_features, function_bytes, kWasmOrigin,
|
||||
zone->allocator()};
|
||||
return decoder.DecodeSingleFunctionForTesting(zone, wire_bytes, module);
|
||||
}
|
||||
|
||||
|
@ -154,12 +154,10 @@ class ModuleDecoderImpl;
|
||||
|
||||
class ModuleDecoder {
|
||||
public:
|
||||
explicit ModuleDecoder(WasmFeatures enabled);
|
||||
explicit ModuleDecoder(WasmFeatures enabled_feature,
|
||||
AccountingAllocator* allocator);
|
||||
~ModuleDecoder();
|
||||
|
||||
void StartDecoding(AccountingAllocator* allocator,
|
||||
ModuleOrigin origin = ModuleOrigin::kWasmOrigin);
|
||||
|
||||
void DecodeModuleHeader(base::Vector<const uint8_t> bytes, uint32_t offset);
|
||||
|
||||
void DecodeSection(SectionCode section_code,
|
||||
@ -189,7 +187,6 @@ class ModuleDecoder {
|
||||
uint32_t offset, SectionCode* result);
|
||||
|
||||
private:
|
||||
const WasmFeatures enabled_features_;
|
||||
std::unique_ptr<ModuleDecoderImpl> impl_;
|
||||
};
|
||||
|
||||
|
@ -573,10 +573,10 @@ class OffsetsProvider {
|
||||
data_offsets_.reserve(module->data_segments.size());
|
||||
|
||||
using OffsetsCollectingDecoder = ModuleDecoderTemplate<OffsetsProvider>;
|
||||
OffsetsCollectingDecoder decoder(WasmFeatures::All(), wire_bytes,
|
||||
kWasmOrigin, *this);
|
||||
OffsetsCollectingDecoder decoder{WasmFeatures::All(), wire_bytes,
|
||||
kWasmOrigin, allocator, *this};
|
||||
constexpr bool kNoVerifyFunctions = false;
|
||||
decoder.DecodeModule(allocator, kNoVerifyFunctions);
|
||||
decoder.DecodeModule(kNoVerifyFunctions);
|
||||
|
||||
enabled_ = true;
|
||||
}
|
||||
|
@ -360,10 +360,12 @@ class ExtendedFunctionDis : public FunctionBodyDisassembler {
|
||||
class HexDumpModuleDis;
|
||||
class DumpingModuleDecoder : public ModuleDecoderTemplate<HexDumpModuleDis> {
|
||||
public:
|
||||
DumpingModuleDecoder(ModuleWireBytes wire_bytes, HexDumpModuleDis* module_dis)
|
||||
: ModuleDecoderTemplate<HexDumpModuleDis>(WasmFeatures::All(),
|
||||
wire_bytes.module_bytes(),
|
||||
kWasmOrigin, *module_dis) {}
|
||||
DumpingModuleDecoder(ModuleWireBytes wire_bytes,
|
||||
AccountingAllocator* allocator,
|
||||
HexDumpModuleDis* module_dis)
|
||||
: ModuleDecoderTemplate<HexDumpModuleDis>(
|
||||
WasmFeatures::All(), wire_bytes.module_bytes(), kWasmOrigin,
|
||||
allocator, *module_dis) {}
|
||||
|
||||
void onFirstError() override {
|
||||
// Pretend we've reached the end of the section, but contrary to the
|
||||
@ -386,7 +388,7 @@ class HexDumpModuleDis {
|
||||
|
||||
// Public entrypoint.
|
||||
void PrintModule() {
|
||||
DumpingModuleDecoder decoder(wire_bytes_, this);
|
||||
DumpingModuleDecoder decoder{wire_bytes_, allocator_, this};
|
||||
decoder_ = &decoder;
|
||||
|
||||
// If the module failed validation, create fakes to allow us to print
|
||||
@ -404,7 +406,7 @@ class HexDumpModuleDis {
|
||||
out_ << "[";
|
||||
out_.NextLine(0);
|
||||
constexpr bool kNoVerifyFunctions = false;
|
||||
decoder.DecodeModule(allocator_, kNoVerifyFunctions);
|
||||
decoder.DecodeModule(kNoVerifyFunctions);
|
||||
out_ << "]";
|
||||
|
||||
if (total_bytes_ != wire_bytes_.length()) {
|
||||
|
Loading…
Reference in New Issue
Block a user