Commit e92e8871 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Make WasmInterpreterInternals a normal object

For unknown reasons, WasmInterpreterInternals was a zone object. However
WasmInterpreterInternals indirectly owns a global handle and a
unique_ptr, both for the interpreter stack. As a zone object,
WasmInterpreterInternals is never destructed, and therefore never frees
the unique_ptr. With this CL I make WasmInterpreterInternals a normal
object and allocate it into a unique_ptr, so that it gets destructed
properly.

R=mstarzinger@chromium.org

Bug: chromium:1000610
Change-Id: Ie08c5627393a434521f5c32702bf9945db2c7811
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1807361Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63835}
parent 1257f60e
......@@ -4017,20 +4017,19 @@ uint32_t WasmInterpreter::Thread::ActivationFrameBase(uint32_t id) {
//============================================================================
// The implementation details of the interpreter.
//============================================================================
class WasmInterpreterInternals : public ZoneObject {
class WasmInterpreterInternals {
public:
// Create a copy of the module bytes for the interpreter, since the passed
// pointer might be invalidated after constructing the interpreter.
const ZoneVector<uint8_t> module_bytes_;
CodeMap codemap_;
ZoneVector<ThreadImpl> threads_;
std::vector<ThreadImpl> threads_;
WasmInterpreterInternals(Zone* zone, const WasmModule* module,
const ModuleWireBytes& wire_bytes,
Handle<WasmInstanceObject> instance_object)
: module_bytes_(wire_bytes.start(), wire_bytes.end(), zone),
codemap_(module, module_bytes_.data(), zone),
threads_(zone) {
codemap_(module, module_bytes_.data(), zone) {
Isolate* isolate = instance_object->GetIsolate();
Handle<Cell> reference_stack = isolate->global_handles()->Create(
*isolate->factory()->NewCell(isolate->factory()->empty_fixed_array()));
......@@ -4068,10 +4067,12 @@ WasmInterpreter::WasmInterpreter(Isolate* isolate, const WasmModule* module,
const ModuleWireBytes& wire_bytes,
Handle<WasmInstanceObject> instance_object)
: zone_(isolate->allocator(), ZONE_NAME),
internals_(new (&zone_) WasmInterpreterInternals(
internals_(new WasmInterpreterInternals(
&zone_, module, wire_bytes, MakeWeak(isolate, instance_object))) {}
WasmInterpreter::~WasmInterpreter() { internals_->~WasmInterpreterInternals(); }
// The destructor is here so we can forward declare {WasmInterpreterInternals}
// used in the {unique_ptr} in the header.
WasmInterpreter::~WasmInterpreter() {}
void WasmInterpreter::Run() { internals_->threads_[0].Run(); }
......
......@@ -172,9 +172,12 @@ class V8_EXPORT_PRIVATE WasmInterpreter {
uint32_t ActivationFrameBase(uint32_t activation_id);
};
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(WasmInterpreter);
WasmInterpreter(Isolate* isolate, const WasmModule* module,
const ModuleWireBytes& wire_bytes,
Handle<WasmInstanceObject> instance);
~WasmInterpreter();
//==========================================================================
......@@ -216,7 +219,7 @@ class V8_EXPORT_PRIVATE WasmInterpreter {
private:
Zone zone_;
WasmInterpreterInternals* internals_;
std::unique_ptr<WasmInterpreterInternals> internals_;
};
} // namespace wasm
......
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