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

[wasm] Clean up WasmInstanceNativeAllocations

This removes a dead method, makes constant fields constant, and avoids a
confusing macro (which just prevented me from finding the call to
{set_imported_mutable_globals}).

R=manoskouk@chromium.org

Bug: v8:12425
Change-Id: I76de744c273ed9e2e429647a2d26dc163e1f4525
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3406758Reviewed-by: 's avatarManos Koukoutos <manoskouk@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78733}
parent 402b9039
......@@ -50,47 +50,31 @@ namespace {
// an instance finalizer is not guaranteed to run upon isolate shutdown,
// we must use a Managed<WasmInstanceNativeAllocations> to guarantee
// it is freed.
// Native allocations are the signature ids and targets for indirect call
// targets, as well as the call targets for imported functions.
class WasmInstanceNativeAllocations {
public:
// Helper macro to set an internal field and the corresponding field
// on an instance.
#define SET(instance, field, value) \
instance->set_##field((this->field##_ = value).get());
// Allocates initial native storage for a given instance.
WasmInstanceNativeAllocations(Handle<WasmInstanceObject> instance,
size_t num_imported_functions,
size_t num_imported_mutable_globals,
size_t num_data_segments,
size_t num_elem_segments) {
SET(instance, imported_function_targets,
std::make_unique<Address[]>(num_imported_functions));
SET(instance, imported_mutable_globals,
std::make_unique<Address[]>(num_imported_mutable_globals));
SET(instance, data_segment_starts,
std::make_unique<Address[]>(num_data_segments));
SET(instance, data_segment_sizes,
std::make_unique<uint32_t[]>(num_data_segments));
SET(instance, dropped_elem_segments,
std::make_unique<uint8_t[]>(num_elem_segments));
size_t num_elem_segments)
: imported_function_targets_(new Address[num_imported_functions]),
imported_mutable_globals_(new Address[num_imported_mutable_globals]),
data_segment_starts_(new Address[num_data_segments]),
data_segment_sizes_(new uint32_t[num_data_segments]),
dropped_elem_segments_(new uint8_t[num_elem_segments]) {
instance->set_imported_function_targets(imported_function_targets_.get());
instance->set_imported_mutable_globals(imported_mutable_globals_.get());
instance->set_data_segment_starts(data_segment_starts_.get());
instance->set_data_segment_sizes(data_segment_sizes_.get());
instance->set_dropped_elem_segments(dropped_elem_segments_.get());
}
private:
template <typename T>
std::unique_ptr<T[]> grow(T* old_arr, size_t old_size, size_t new_size) {
std::unique_ptr<T[]> new_arr = std::make_unique<T[]>(new_size);
std::copy_n(old_arr, old_size, new_arr.get());
return new_arr;
}
std::unique_ptr<Address[]> imported_function_targets_;
std::unique_ptr<Address[]> imported_mutable_globals_;
std::unique_ptr<Address[]> data_segment_starts_;
std::unique_ptr<uint32_t[]> data_segment_sizes_;
std::unique_ptr<uint8_t[]> dropped_elem_segments_;
#undef SET
const std::unique_ptr<Address[]> imported_function_targets_;
const std::unique_ptr<Address[]> imported_mutable_globals_;
const std::unique_ptr<Address[]> data_segment_starts_;
const std::unique_ptr<uint32_t[]> data_segment_sizes_;
const std::unique_ptr<uint8_t[]> dropped_elem_segments_;
};
size_t EstimateNativeAllocationsSize(const WasmModule* module) {
......
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