[wasm][cleanup] Use OwnedVector instead of unique_ptr + size
Passing a {unique_ptr} plus the size of the array separately makes it easier to pass non-matching values. Using {base::OwnedVector} instead makes all call sites cleaner. R=ahaas@chromium.org Change-Id: I66cf8e756d098837aac71e410b18e08646e512b8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4061893 Commit-Queue: Clemens Backes <clemensb@chromium.org> Reviewed-by: Andreas Haas <ahaas@chromium.org> Cr-Commit-Position: refs/heads/main@{#84549}
This commit is contained in:
parent
4f2d5b3b77
commit
11275172bd
@ -2059,7 +2059,7 @@ void RecompileNativeModule(NativeModule* native_module,
|
||||
|
||||
AsyncCompileJob::AsyncCompileJob(
|
||||
Isolate* isolate, WasmFeatures enabled_features,
|
||||
std::unique_ptr<byte[]> bytes_copy, size_t length, Handle<Context> context,
|
||||
base::OwnedVector<const uint8_t> bytes, Handle<Context> context,
|
||||
Handle<Context> incumbent_context, const char* api_method_name,
|
||||
std::shared_ptr<CompilationResultResolver> resolver, int compilation_id)
|
||||
: isolate_(isolate),
|
||||
@ -2067,8 +2067,8 @@ AsyncCompileJob::AsyncCompileJob(
|
||||
enabled_features_(enabled_features),
|
||||
dynamic_tiering_(DynamicTiering{v8_flags.wasm_dynamic_tiering.value()}),
|
||||
start_time_(base::TimeTicks::Now()),
|
||||
bytes_copy_(std::move(bytes_copy)),
|
||||
wire_bytes_(bytes_copy_.get(), bytes_copy_.get() + length),
|
||||
bytes_copy_(std::move(bytes)),
|
||||
wire_bytes_(bytes_copy_.as_vector()),
|
||||
resolver_(std::move(resolver)),
|
||||
compilation_id_(compilation_id) {
|
||||
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
|
||||
@ -2199,7 +2199,7 @@ void AsyncCompileJob::CreateNativeModule(
|
||||
|
||||
native_module_ = GetWasmEngine()->NewNativeModule(
|
||||
isolate_, enabled_features_, std::move(module), code_size_estimate);
|
||||
native_module_->SetWireBytes({std::move(bytes_copy_), wire_bytes_.length()});
|
||||
native_module_->SetWireBytes(std::move(bytes_copy_));
|
||||
native_module_->compilation_state()->set_compilation_id(compilation_id_);
|
||||
}
|
||||
|
||||
@ -2961,7 +2961,7 @@ void AsyncStreamingProcessor::OnFinishedStream(
|
||||
}
|
||||
|
||||
job_->wire_bytes_ = ModuleWireBytes(bytes.as_vector());
|
||||
job_->bytes_copy_ = bytes.ReleaseData();
|
||||
job_->bytes_copy_ = std::move(bytes);
|
||||
|
||||
// Record event metrics.
|
||||
auto duration = base::TimeTicks::Now() - job_->start_time_;
|
||||
@ -3006,8 +3006,7 @@ void AsyncStreamingProcessor::OnFinishedStream(
|
||||
cache_hit = job_->GetOrCreateNativeModule(std::move(result).value(),
|
||||
kCodeSizeEstimate);
|
||||
} else {
|
||||
job_->native_module_->SetWireBytes(
|
||||
{std::move(job_->bytes_copy_), job_->wire_bytes_.length()});
|
||||
job_->native_module_->SetWireBytes(std::move(job_->bytes_copy_));
|
||||
}
|
||||
const bool needs_finish =
|
||||
job_->DecrementAndCheckFinisherCount(AsyncCompileJob::kStreamingDecoder);
|
||||
|
@ -139,7 +139,7 @@ class WrapperQueue {
|
||||
class AsyncCompileJob {
|
||||
public:
|
||||
AsyncCompileJob(Isolate* isolate, WasmFeatures enabled_features,
|
||||
std::unique_ptr<byte[]> bytes_copy, size_t length,
|
||||
base::OwnedVector<const uint8_t> bytes,
|
||||
Handle<Context> context, Handle<Context> incumbent_context,
|
||||
const char* api_method_name,
|
||||
std::shared_ptr<CompilationResultResolver> resolver,
|
||||
@ -263,7 +263,7 @@ class AsyncCompileJob {
|
||||
base::TimeTicks start_time_;
|
||||
// Copy of the module wire bytes, moved into the {native_module_} on its
|
||||
// creation.
|
||||
std::unique_ptr<byte[]> bytes_copy_;
|
||||
base::OwnedVector<const uint8_t> bytes_copy_;
|
||||
// Reference to the wire bytes (held in {bytes_copy_} or as part of
|
||||
// {native_module_}).
|
||||
ModuleWireBytes wire_bytes_;
|
||||
|
@ -680,13 +680,12 @@ void WasmEngine::AsyncCompile(
|
||||
}
|
||||
// Make a copy of the wire bytes in case the user program changes them
|
||||
// during asynchronous compilation.
|
||||
std::unique_ptr<byte[]> copy(new byte[bytes.length()]);
|
||||
memcpy(copy.get(), bytes.start(), bytes.length());
|
||||
base::OwnedVector<const uint8_t> copy =
|
||||
base::OwnedVector<const uint8_t>::Of(bytes.module_bytes());
|
||||
|
||||
AsyncCompileJob* job = CreateAsyncCompileJob(
|
||||
isolate, enabled, std::move(copy), bytes.length(),
|
||||
handle(isolate->context(), isolate), api_method_name_for_errors,
|
||||
std::move(resolver), compilation_id);
|
||||
isolate, enabled, std::move(copy), handle(isolate->context(), isolate),
|
||||
api_method_name_for_errors, std::move(resolver), compilation_id);
|
||||
job->Start();
|
||||
}
|
||||
|
||||
@ -698,9 +697,9 @@ std::shared_ptr<StreamingDecoder> WasmEngine::StartStreamingCompilation(
|
||||
TRACE_EVENT1("v8.wasm", "wasm.StartStreamingCompilation", "id",
|
||||
compilation_id);
|
||||
if (v8_flags.wasm_async_compilation) {
|
||||
AsyncCompileJob* job = CreateAsyncCompileJob(
|
||||
isolate, enabled, std::unique_ptr<byte[]>(nullptr), 0, context,
|
||||
api_method_name, std::move(resolver), compilation_id);
|
||||
AsyncCompileJob* job =
|
||||
CreateAsyncCompileJob(isolate, enabled, {}, context, api_method_name,
|
||||
std::move(resolver), compilation_id);
|
||||
return job->CreateStreamingDecoder();
|
||||
}
|
||||
return StreamingDecoder::CreateSyncStreamingDecoder(
|
||||
@ -921,13 +920,13 @@ CodeTracer* WasmEngine::GetCodeTracer() {
|
||||
|
||||
AsyncCompileJob* WasmEngine::CreateAsyncCompileJob(
|
||||
Isolate* isolate, const WasmFeatures& enabled,
|
||||
std::unique_ptr<byte[]> bytes_copy, size_t length, Handle<Context> context,
|
||||
base::OwnedVector<const uint8_t> bytes, Handle<Context> context,
|
||||
const char* api_method_name,
|
||||
std::shared_ptr<CompilationResultResolver> resolver, int compilation_id) {
|
||||
Handle<Context> incumbent_context = isolate->GetIncumbentContext();
|
||||
AsyncCompileJob* job = new AsyncCompileJob(
|
||||
isolate, enabled, std::move(bytes_copy), length, context,
|
||||
incumbent_context, api_method_name, std::move(resolver), compilation_id);
|
||||
isolate, enabled, std::move(bytes), context, incumbent_context,
|
||||
api_method_name, std::move(resolver), compilation_id);
|
||||
// Pass ownership to the unique_ptr in {async_compile_jobs_}.
|
||||
base::MutexGuard guard(&mutex_);
|
||||
async_compile_jobs_[job] = std::unique_ptr<AsyncCompileJob>(job);
|
||||
|
@ -379,8 +379,8 @@ class V8_EXPORT_PRIVATE WasmEngine {
|
||||
|
||||
AsyncCompileJob* CreateAsyncCompileJob(
|
||||
Isolate* isolate, const WasmFeatures& enabled,
|
||||
std::unique_ptr<byte[]> bytes_copy, size_t length,
|
||||
Handle<Context> context, const char* api_method_name,
|
||||
base::OwnedVector<const uint8_t> bytes, Handle<Context> context,
|
||||
const char* api_method_name,
|
||||
std::shared_ptr<CompilationResultResolver> resolver, int compilation_id);
|
||||
|
||||
void TriggerGC(int8_t gc_sequence_index);
|
||||
|
Loading…
Reference in New Issue
Block a user