diff --git a/src/wasm/module-compiler.cc b/src/wasm/module-compiler.cc index c2f00661b8..f960727bea 100644 --- a/src/wasm/module-compiler.cc +++ b/src/wasm/module-compiler.cc @@ -126,7 +126,7 @@ class CompilationStateImpl { // Set the number of compilations unit expected to be executed. Needs to be // set before {AddCompilationUnits} is run, which triggers background // compilation. - void SetNumberOfFunctionsToCompile(size_t num_functions); + void SetNumberOfFunctionsToCompile(int num_functions); // Add the callback function to be called on compilation events. Needs to be // set before {AddCompilationUnits} is run. @@ -236,8 +236,8 @@ class CompilationStateImpl { // compiling. std::shared_ptr wire_bytes_storage_; - size_t outstanding_baseline_units_ = 0; - size_t outstanding_tiering_units_ = 0; + int outstanding_baseline_units_ = 0; + int outstanding_tiering_units_ = 0; // End of fields protected by {mutex_}. ////////////////////////////////////////////////////////////////////////////// @@ -502,8 +502,9 @@ void CompileInParallel(Isolate* isolate, NativeModule* native_module) { CompilationStateImpl* compilation_state = Impl(native_module->compilation_state()); - uint32_t num_wasm_functions = - native_module->num_functions() - native_module->num_imported_functions(); + DCHECK_GE(kMaxInt, native_module->module()->num_declared_functions); + int num_wasm_functions = + static_cast(native_module->module()->num_declared_functions); compilation_state->SetNumberOfFunctionsToCompile(num_wasm_functions); // 1) The main thread allocates a compilation unit for each wasm function @@ -805,7 +806,7 @@ class AsyncStreamingProcessor final : public StreamingProcessor { bool ProcessSection(SectionCode section_code, Vector bytes, uint32_t offset) override; - bool ProcessCodeSectionHeader(size_t functions_count, uint32_t offset, + bool ProcessCodeSectionHeader(int functions_count, uint32_t offset, std::shared_ptr) override; bool ProcessFunctionBody(Vector bytes, @@ -831,7 +832,7 @@ class AsyncStreamingProcessor final : public StreamingProcessor { ModuleDecoder decoder_; AsyncCompileJob* job_; std::unique_ptr compilation_unit_builder_; - uint32_t next_function_ = 0; + int num_functions_ = 0; }; std::shared_ptr AsyncCompileJob::CreateStreamingDecoder() { @@ -1338,9 +1339,9 @@ bool AsyncStreamingProcessor::ProcessSection(SectionCode section_code, // Start the code section. bool AsyncStreamingProcessor::ProcessCodeSectionHeader( - size_t functions_count, uint32_t offset, + int functions_count, uint32_t offset, std::shared_ptr wire_bytes_storage) { - TRACE_STREAMING("Start the code section with %zu functions...\n", + TRACE_STREAMING("Start the code section with %d functions...\n", functions_count); if (!decoder_.CheckFunctionsCount(static_cast(functions_count), offset)) { @@ -1368,14 +1369,14 @@ bool AsyncStreamingProcessor::ProcessCodeSectionHeader( // Process a function body. bool AsyncStreamingProcessor::ProcessFunctionBody(Vector bytes, uint32_t offset) { - TRACE_STREAMING("Process function body %d ...\n", next_function_); + TRACE_STREAMING("Process function body %d ...\n", num_functions_); decoder_.DecodeFunctionBody( - next_function_, static_cast(bytes.length()), offset, false); + num_functions_, static_cast(bytes.length()), offset, false); - uint32_t index = next_function_ + decoder_.module()->num_imported_functions; + int index = num_functions_ + decoder_.module()->num_imported_functions; compilation_unit_builder_->AddUnit(index); - ++next_function_; + ++num_functions_; // This method always succeeds. The return value is necessary to comply with // the StreamingProcessor interface. return true; @@ -1476,7 +1477,7 @@ void CompilationStateImpl::AbortCompilation() { callbacks_.clear(); } -void CompilationStateImpl::SetNumberOfFunctionsToCompile(size_t num_functions) { +void CompilationStateImpl::SetNumberOfFunctionsToCompile(int num_functions) { DCHECK(!failed()); base::MutexGuard guard(&mutex_); outstanding_baseline_units_ = num_functions; diff --git a/src/wasm/streaming-decoder.cc b/src/wasm/streaming-decoder.cc index 20beaa459e..4472eb82e7 100644 --- a/src/wasm/streaming-decoder.cc +++ b/src/wasm/streaming-decoder.cc @@ -436,7 +436,9 @@ StreamingDecoder::DecodeNumberOfFunctions::NextWithValue( return base::make_unique(streaming->module_offset()); } - streaming->StartCodeSection(value_, streaming->section_buffers_.back()); + DCHECK_GE(kMaxInt, value_); + streaming->StartCodeSection(static_cast(value_), + streaming->section_buffers_.back()); if (!streaming->ok()) return nullptr; return base::make_unique( section_buffer_, section_buffer_->payload_offset() + bytes_consumed_, diff --git a/src/wasm/streaming-decoder.h b/src/wasm/streaming-decoder.h index b15a53d644..0d469a96b3 100644 --- a/src/wasm/streaming-decoder.h +++ b/src/wasm/streaming-decoder.h @@ -36,7 +36,7 @@ class V8_EXPORT_PRIVATE StreamingProcessor { // Process the start of the code section. Returns true if the processing // finished successfully and the decoding should continue. - virtual bool ProcessCodeSectionHeader(size_t num_functions, uint32_t offset, + virtual bool ProcessCodeSectionHeader(int num_functions, uint32_t offset, std::shared_ptr) = 0; // Process a function body. Returns true if the processing finished @@ -227,7 +227,7 @@ class V8_EXPORT_PRIVATE StreamingDecoder { } } - void StartCodeSection(size_t num_functions, + void StartCodeSection(int num_functions, std::shared_ptr wire_bytes_storage) { if (!ok()) return; // The offset passed to {ProcessCodeSectionHeader} is an error offset and diff --git a/test/unittests/wasm/streaming-decoder-unittest.cc b/test/unittests/wasm/streaming-decoder-unittest.cc index 013fc7b5a9..765e5a74ff 100644 --- a/test/unittests/wasm/streaming-decoder-unittest.cc +++ b/test/unittests/wasm/streaming-decoder-unittest.cc @@ -56,7 +56,7 @@ class MockStreamingProcessor : public StreamingProcessor { return true; } - bool ProcessCodeSectionHeader(size_t num_functions, uint32_t offset, + bool ProcessCodeSectionHeader(int num_functions, uint32_t offset, std::shared_ptr) override { return true; }