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 { ...@@ -50,47 +50,31 @@ namespace {
// an instance finalizer is not guaranteed to run upon isolate shutdown, // an instance finalizer is not guaranteed to run upon isolate shutdown,
// we must use a Managed<WasmInstanceNativeAllocations> to guarantee // we must use a Managed<WasmInstanceNativeAllocations> to guarantee
// it is freed. // 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 { class WasmInstanceNativeAllocations {
public: 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, WasmInstanceNativeAllocations(Handle<WasmInstanceObject> instance,
size_t num_imported_functions, size_t num_imported_functions,
size_t num_imported_mutable_globals, size_t num_imported_mutable_globals,
size_t num_data_segments, size_t num_data_segments,
size_t num_elem_segments) { size_t num_elem_segments)
SET(instance, imported_function_targets, : imported_function_targets_(new Address[num_imported_functions]),
std::make_unique<Address[]>(num_imported_functions)); imported_mutable_globals_(new Address[num_imported_mutable_globals]),
SET(instance, imported_mutable_globals, data_segment_starts_(new Address[num_data_segments]),
std::make_unique<Address[]>(num_imported_mutable_globals)); data_segment_sizes_(new uint32_t[num_data_segments]),
SET(instance, data_segment_starts, dropped_elem_segments_(new uint8_t[num_elem_segments]) {
std::make_unique<Address[]>(num_data_segments)); instance->set_imported_function_targets(imported_function_targets_.get());
SET(instance, data_segment_sizes, instance->set_imported_mutable_globals(imported_mutable_globals_.get());
std::make_unique<uint32_t[]>(num_data_segments)); instance->set_data_segment_starts(data_segment_starts_.get());
SET(instance, dropped_elem_segments, instance->set_data_segment_sizes(data_segment_sizes_.get());
std::make_unique<uint8_t[]>(num_elem_segments)); instance->set_dropped_elem_segments(dropped_elem_segments_.get());
} }
private: private:
template <typename T> const std::unique_ptr<Address[]> imported_function_targets_;
std::unique_ptr<T[]> grow(T* old_arr, size_t old_size, size_t new_size) { const std::unique_ptr<Address[]> imported_mutable_globals_;
std::unique_ptr<T[]> new_arr = std::make_unique<T[]>(new_size); const std::unique_ptr<Address[]> data_segment_starts_;
std::copy_n(old_arr, old_size, new_arr.get()); const std::unique_ptr<uint32_t[]> data_segment_sizes_;
return new_arr; const std::unique_ptr<uint8_t[]> dropped_elem_segments_;
}
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
}; };
size_t EstimateNativeAllocationsSize(const WasmModule* module) { 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