Commit 2e161cfd authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Make WireBytesStorage keep wire bytes alive

The purpose of the {WireBytesStorage} (typically held in a shared_ptr
itself) is to keep the actual wire bytes alive. Thus implement it this
way for the {NativeModuleWireBytesStorage}.

R=mstarzinger@chromium.org

Bug: v8:8689
Change-Id: I8f171b4fa8b80b517badb1b1d3228503a32830dd
Reviewed-on: https://chromium-review.googlesource.com/c/1421362
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58966}
parent 0dc02e7c
......@@ -803,24 +803,27 @@ Vector<byte> NativeModule::AllocateForCode(size_t size) {
namespace {
class NativeModuleWireBytesStorage final : public WireBytesStorage {
public:
explicit NativeModuleWireBytesStorage(NativeModule* native_module)
: native_module_(native_module) {}
explicit NativeModuleWireBytesStorage(
std::shared_ptr<OwnedVector<const uint8_t>> wire_bytes)
: wire_bytes_(std::move(wire_bytes)) {}
Vector<const uint8_t> GetCode(WireBytesRef ref) const final {
return native_module_->wire_bytes().SubVector(ref.offset(),
ref.end_offset());
return wire_bytes_->as_vector().SubVector(ref.offset(), ref.end_offset());
}
private:
NativeModule* const native_module_;
const std::shared_ptr<OwnedVector<const uint8_t>> wire_bytes_;
};
} // namespace
void NativeModule::SetWireBytes(OwnedVector<const byte> wire_bytes) {
wire_bytes_ = std::move(wire_bytes);
if (!wire_bytes.is_empty()) {
void NativeModule::SetWireBytes(OwnedVector<const uint8_t> wire_bytes) {
auto shared_wire_bytes =
std::make_shared<OwnedVector<const uint8_t>>(std::move(wire_bytes));
wire_bytes_ = shared_wire_bytes;
if (!shared_wire_bytes->is_empty()) {
compilation_state_->SetWireBytesStorage(
std::make_shared<NativeModuleWireBytesStorage>(this));
std::make_shared<NativeModuleWireBytesStorage>(
std::move(shared_wire_bytes)));
}
}
......
......@@ -339,11 +339,11 @@ class V8_EXPORT_PRIVATE NativeModule final {
UseTrapHandler use_trap_handler() const { return use_trap_handler_; }
void set_lazy_compile_frozen(bool frozen) { lazy_compile_frozen_ = frozen; }
bool lazy_compile_frozen() const { return lazy_compile_frozen_; }
Vector<const byte> wire_bytes() const { return wire_bytes_.as_vector(); }
Vector<const uint8_t> wire_bytes() const { return wire_bytes_->as_vector(); }
const WasmModule* module() const { return module_.get(); }
size_t committed_code_space() const { return committed_code_space_.load(); }
void SetWireBytes(OwnedVector<const byte> wire_bytes);
void SetWireBytes(OwnedVector<const uint8_t> wire_bytes);
WasmCode* Lookup(Address) const;
......@@ -427,7 +427,9 @@ class V8_EXPORT_PRIVATE NativeModule final {
// AsyncCompileJob).
std::shared_ptr<const WasmModule> module_;
OwnedVector<const byte> wire_bytes_;
// Wire bytes, held in a shared_ptr so they can be kept alive by the
// {WireBytesStorage}, held by background compile tasks.
std::shared_ptr<OwnedVector<const uint8_t>> wire_bytes_;
WasmCode* runtime_stub_table_[WasmCode::kRuntimeStubCount] = {nullptr};
......
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