Commit 50117080 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[wasm][cleanup] Fix passing of WireBytesStorage

WireBytesStorage is the class used to access the wire bytes of a
function for compilation. It is stored and passed in a shared_ptr,
because it can be updated while compilation is running, and the
compilation threads will keep the old reference alive until the last
reference is dropped.
This CL fixes a few issues where we unnecessarily passed a reference
to the shared_ptr instead of just a raw pointer, and changes one
copy-assign into a move-assign to avoid an unneeded reference increase
and decrease.

R=thibaudm@chromium.org

Bug: v8:11879
Change-Id: I18b626a7b6cde09d5b29f091bd9f49d01d408206
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2953196Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75116}
parent 54692928
......@@ -122,8 +122,8 @@ ExecutionTier WasmCompilationUnit::GetBaselineExecutionTier(
WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
WasmEngine* engine, CompilationEnv* env,
const std::shared_ptr<WireBytesStorage>& wire_bytes_storage,
Counters* counters, WasmFeatures* detected) {
const WireBytesStorage* wire_bytes_storage, Counters* counters,
WasmFeatures* detected) {
WasmCompilationResult result;
if (func_index_ < static_cast<int>(env->module->num_imported_functions)) {
result = ExecuteImportWrapperCompilation(engine, env);
......@@ -159,8 +159,8 @@ WasmCompilationResult WasmCompilationUnit::ExecuteImportWrapperCompilation(
WasmCompilationResult WasmCompilationUnit::ExecuteFunctionCompilation(
WasmEngine* wasm_engine, CompilationEnv* env,
const std::shared_ptr<WireBytesStorage>& wire_bytes_storage,
Counters* counters, WasmFeatures* detected) {
const WireBytesStorage* wire_bytes_storage, Counters* counters,
WasmFeatures* detected) {
auto* func = &env->module->functions[func_index_];
Vector<const uint8_t> code = wire_bytes_storage->GetCode(func->code);
wasm::FunctionBody func_body{func->sig, func->code.offset(), code.begin(),
......@@ -267,7 +267,7 @@ void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate,
CompilationEnv env = native_module->CreateCompilationEnv();
WasmCompilationResult result = unit.ExecuteCompilation(
isolate->wasm_engine(), &env,
native_module->compilation_state()->GetWireBytesStorage(),
native_module->compilation_state()->GetWireBytesStorage().get(),
isolate->counters(), detected);
if (result.succeeded()) {
WasmCodeRefScope code_ref_scope;
......
......@@ -84,9 +84,9 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final {
WasmCompilationUnit(int index, ExecutionTier tier, ForDebugging for_debugging)
: func_index_(index), tier_(tier), for_debugging_(for_debugging) {}
WasmCompilationResult ExecuteCompilation(
WasmEngine*, CompilationEnv*, const std::shared_ptr<WireBytesStorage>&,
Counters*, WasmFeatures* detected);
WasmCompilationResult ExecuteCompilation(WasmEngine*, CompilationEnv*,
const WireBytesStorage*, Counters*,
WasmFeatures* detected);
ExecutionTier tier() const { return tier_; }
int func_index() const { return func_index_; }
......@@ -96,13 +96,13 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final {
ExecutionTier);
private:
WasmCompilationResult ExecuteFunctionCompilation(
WasmEngine* wasm_engine, CompilationEnv* env,
const std::shared_ptr<WireBytesStorage>& wire_bytes_storage,
Counters* counters, WasmFeatures* detected);
WasmCompilationResult ExecuteFunctionCompilation(WasmEngine*, CompilationEnv*,
const WireBytesStorage*,
Counters*,
WasmFeatures* detected);
WasmCompilationResult ExecuteImportWrapperCompilation(WasmEngine* engine,
CompilationEnv* env);
WasmCompilationResult ExecuteImportWrapperCompilation(WasmEngine*,
CompilationEnv*);
int func_index_;
ExecutionTier tier_;
......
......@@ -632,7 +632,7 @@ class CompilationStateImpl {
void SetWireBytesStorage(
std::shared_ptr<WireBytesStorage> wire_bytes_storage) {
base::MutexGuard guard(&mutex_);
wire_bytes_storage_ = wire_bytes_storage;
wire_bytes_storage_ = std::move(wire_bytes_storage);
}
std::shared_ptr<WireBytesStorage> GetWireBytesStorage() const {
......@@ -1127,8 +1127,9 @@ bool CompileLazy(Isolate* isolate, Handle<WasmModuleObject> module_object,
CompilationEnv env = native_module->CreateCompilationEnv();
WasmFeatures detected_features;
WasmCompilationResult result = baseline_unit.ExecuteCompilation(
isolate->wasm_engine(), &env, compilation_state->GetWireBytesStorage(),
counters, &detected_features);
isolate->wasm_engine(), &env,
compilation_state->GetWireBytesStorage().get(), counters,
&detected_features);
compilation_state->OnCompilationStopped(detected_features);
// During lazy compilation, we can only get compilation errors when
......@@ -1314,7 +1315,7 @@ CompilationExecutionResult ExecuteCompilationUnits(
while (unit->tier() == current_tier) {
// (asynchronous): Execute the compilation.
WasmCompilationResult result = unit->ExecuteCompilation(
engine, &env.value(), wire_bytes, counters, &detected_features);
engine, &env.value(), wire_bytes.get(), counters, &detected_features);
results_to_publish.emplace_back(std::move(result));
bool yield = delegate && delegate->ShouldYield();
......
......@@ -564,7 +564,7 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
for_debugging);
result.emplace(unit.ExecuteCompilation(
isolate()->wasm_engine(), &env,
native_module->compilation_state()->GetWireBytesStorage(),
native_module->compilation_state()->GetWireBytesStorage().get(),
isolate()->counters(), &unused_detected_features));
}
WasmCode* code = native_module->PublishCode(
......
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