[wasm] Store function index in integer

We sometimes store function indexes and number of functions as {size_t}
and sometimes as {int}. Unify a few places to be {int}.

R=ahaas@chromium.org

Change-Id: I1d204cbd9388245f97f291a469b32743457ab2c0
Reviewed-on: https://chromium-review.googlesource.com/c/1491607
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59946}
This commit is contained in:
Clemens Hammacher 2019-02-28 11:57:35 +01:00 committed by Commit Bot
parent dd98ba3197
commit 500260027f
4 changed files with 21 additions and 18 deletions

View File

@ -126,7 +126,7 @@ class CompilationStateImpl {
// Set the number of compilations unit expected to be executed. Needs to be // Set the number of compilations unit expected to be executed. Needs to be
// set before {AddCompilationUnits} is run, which triggers background // set before {AddCompilationUnits} is run, which triggers background
// compilation. // 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 // Add the callback function to be called on compilation events. Needs to be
// set before {AddCompilationUnits} is run. // set before {AddCompilationUnits} is run.
@ -236,8 +236,8 @@ class CompilationStateImpl {
// compiling. // compiling.
std::shared_ptr<WireBytesStorage> wire_bytes_storage_; std::shared_ptr<WireBytesStorage> wire_bytes_storage_;
size_t outstanding_baseline_units_ = 0; int outstanding_baseline_units_ = 0;
size_t outstanding_tiering_units_ = 0; int outstanding_tiering_units_ = 0;
// End of fields protected by {mutex_}. // End of fields protected by {mutex_}.
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -502,8 +502,9 @@ void CompileInParallel(Isolate* isolate, NativeModule* native_module) {
CompilationStateImpl* compilation_state = CompilationStateImpl* compilation_state =
Impl(native_module->compilation_state()); Impl(native_module->compilation_state());
uint32_t num_wasm_functions = DCHECK_GE(kMaxInt, native_module->module()->num_declared_functions);
native_module->num_functions() - native_module->num_imported_functions(); int num_wasm_functions =
static_cast<int>(native_module->module()->num_declared_functions);
compilation_state->SetNumberOfFunctionsToCompile(num_wasm_functions); compilation_state->SetNumberOfFunctionsToCompile(num_wasm_functions);
// 1) The main thread allocates a compilation unit for each wasm function // 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<const uint8_t> bytes, bool ProcessSection(SectionCode section_code, Vector<const uint8_t> bytes,
uint32_t offset) override; uint32_t offset) override;
bool ProcessCodeSectionHeader(size_t functions_count, uint32_t offset, bool ProcessCodeSectionHeader(int functions_count, uint32_t offset,
std::shared_ptr<WireBytesStorage>) override; std::shared_ptr<WireBytesStorage>) override;
bool ProcessFunctionBody(Vector<const uint8_t> bytes, bool ProcessFunctionBody(Vector<const uint8_t> bytes,
@ -831,7 +832,7 @@ class AsyncStreamingProcessor final : public StreamingProcessor {
ModuleDecoder decoder_; ModuleDecoder decoder_;
AsyncCompileJob* job_; AsyncCompileJob* job_;
std::unique_ptr<CompilationUnitBuilder> compilation_unit_builder_; std::unique_ptr<CompilationUnitBuilder> compilation_unit_builder_;
uint32_t next_function_ = 0; int num_functions_ = 0;
}; };
std::shared_ptr<StreamingDecoder> AsyncCompileJob::CreateStreamingDecoder() { std::shared_ptr<StreamingDecoder> AsyncCompileJob::CreateStreamingDecoder() {
@ -1338,9 +1339,9 @@ bool AsyncStreamingProcessor::ProcessSection(SectionCode section_code,
// Start the code section. // Start the code section.
bool AsyncStreamingProcessor::ProcessCodeSectionHeader( bool AsyncStreamingProcessor::ProcessCodeSectionHeader(
size_t functions_count, uint32_t offset, int functions_count, uint32_t offset,
std::shared_ptr<WireBytesStorage> wire_bytes_storage) { std::shared_ptr<WireBytesStorage> 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); functions_count);
if (!decoder_.CheckFunctionsCount(static_cast<uint32_t>(functions_count), if (!decoder_.CheckFunctionsCount(static_cast<uint32_t>(functions_count),
offset)) { offset)) {
@ -1368,14 +1369,14 @@ bool AsyncStreamingProcessor::ProcessCodeSectionHeader(
// Process a function body. // Process a function body.
bool AsyncStreamingProcessor::ProcessFunctionBody(Vector<const uint8_t> bytes, bool AsyncStreamingProcessor::ProcessFunctionBody(Vector<const uint8_t> bytes,
uint32_t offset) { uint32_t offset) {
TRACE_STREAMING("Process function body %d ...\n", next_function_); TRACE_STREAMING("Process function body %d ...\n", num_functions_);
decoder_.DecodeFunctionBody( decoder_.DecodeFunctionBody(
next_function_, static_cast<uint32_t>(bytes.length()), offset, false); num_functions_, static_cast<uint32_t>(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); compilation_unit_builder_->AddUnit(index);
++next_function_; ++num_functions_;
// This method always succeeds. The return value is necessary to comply with // This method always succeeds. The return value is necessary to comply with
// the StreamingProcessor interface. // the StreamingProcessor interface.
return true; return true;
@ -1476,7 +1477,7 @@ void CompilationStateImpl::AbortCompilation() {
callbacks_.clear(); callbacks_.clear();
} }
void CompilationStateImpl::SetNumberOfFunctionsToCompile(size_t num_functions) { void CompilationStateImpl::SetNumberOfFunctionsToCompile(int num_functions) {
DCHECK(!failed()); DCHECK(!failed());
base::MutexGuard guard(&mutex_); base::MutexGuard guard(&mutex_);
outstanding_baseline_units_ = num_functions; outstanding_baseline_units_ = num_functions;

View File

@ -436,7 +436,9 @@ StreamingDecoder::DecodeNumberOfFunctions::NextWithValue(
return base::make_unique<DecodeSectionID>(streaming->module_offset()); return base::make_unique<DecodeSectionID>(streaming->module_offset());
} }
streaming->StartCodeSection(value_, streaming->section_buffers_.back()); DCHECK_GE(kMaxInt, value_);
streaming->StartCodeSection(static_cast<int>(value_),
streaming->section_buffers_.back());
if (!streaming->ok()) return nullptr; if (!streaming->ok()) return nullptr;
return base::make_unique<DecodeFunctionLength>( return base::make_unique<DecodeFunctionLength>(
section_buffer_, section_buffer_->payload_offset() + bytes_consumed_, section_buffer_, section_buffer_->payload_offset() + bytes_consumed_,

View File

@ -36,7 +36,7 @@ class V8_EXPORT_PRIVATE StreamingProcessor {
// Process the start of the code section. Returns true if the processing // Process the start of the code section. Returns true if the processing
// finished successfully and the decoding should continue. // 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<WireBytesStorage>) = 0; std::shared_ptr<WireBytesStorage>) = 0;
// Process a function body. Returns true if the processing finished // 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<WireBytesStorage> wire_bytes_storage) { std::shared_ptr<WireBytesStorage> wire_bytes_storage) {
if (!ok()) return; if (!ok()) return;
// The offset passed to {ProcessCodeSectionHeader} is an error offset and // The offset passed to {ProcessCodeSectionHeader} is an error offset and

View File

@ -56,7 +56,7 @@ class MockStreamingProcessor : public StreamingProcessor {
return true; return true;
} }
bool ProcessCodeSectionHeader(size_t num_functions, uint32_t offset, bool ProcessCodeSectionHeader(int num_functions, uint32_t offset,
std::shared_ptr<WireBytesStorage>) override { std::shared_ptr<WireBytesStorage>) override {
return true; return true;
} }