Commit eb1eaf63 authored by Michael Achenbach's avatar Michael Achenbach Committed by Commit Bot

Revert "Use new arraybuffer deleter interface in d8"

This reverts commit 524215be.

Reason for revert: Breaks cfi:
https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Linux64%20-%20cfi/16422

Original change's description:
> Use new arraybuffer deleter interface in d8
> 
> With this cl we start using the custom deleter to free externalized
> array buffers. This also allows us to keep wasm memories registered
> with the wasm memory tracker and thereby to propagate that a memory
> is wasm allocated over postMessage calls.
> 
> Bug: v8:8073, chromium:836800
> Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
> Change-Id: I57e3ea44d9c6633ada7996677dd1de4da810ab64
> Reviewed-on: https://chromium-review.googlesource.com/1186681
> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
> Commit-Queue: Stephan Herhut <herhut@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#55361}

TBR=mstarzinger@chromium.org,herhut@chromium.org

Change-Id: I64c4e76d8d68bad8df4ba3297c099b9b44eabc7c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:8073, chromium:836800
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/1187241Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55366}
parent 6930df0f
...@@ -7472,7 +7472,17 @@ v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() { ...@@ -7472,7 +7472,17 @@ v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() {
"ArrayBuffer already externalized"); "ArrayBuffer already externalized");
self->set_is_external(true); self->set_is_external(true);
// We need to capture the contents before releasing the allocation from the
// Wasm tracker, because otherwise we will not correctly capture the
// allocation data.
const v8::ArrayBuffer::Contents contents = GetContents(); const v8::ArrayBuffer::Contents contents = GetContents();
if (self->is_wasm_memory()) {
// Since this is being externalized, the Wasm Allocation Tracker can no
// longer track it.
//
// TODO(eholk): Find a way to track this across externalization
self->StopTrackingWasmMemory(isolate);
}
isolate->heap()->UnregisterArrayBuffer(*self); isolate->heap()->UnregisterArrayBuffer(*self);
// A regular copy is good enough. No move semantics needed. // A regular copy is good enough. No move semantics needed.
...@@ -7723,7 +7733,17 @@ v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::Externalize() { ...@@ -7723,7 +7733,17 @@ v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::Externalize() {
"SharedArrayBuffer already externalized"); "SharedArrayBuffer already externalized");
self->set_is_external(true); self->set_is_external(true);
// We need to capture the contents before releasing the allocation from the
// Wasm tracker, because otherwise we will not correctly capture the
// allocation data.
const v8::SharedArrayBuffer::Contents contents = GetContents(); const v8::SharedArrayBuffer::Contents contents = GetContents();
if (self->is_wasm_memory()) {
// Since this is being externalized, the Wasm Allocation Tracker can no
// longer track it.
//
// TODO(eholk): Find a way to track this across externalization
self->StopTrackingWasmMemory(isolate);
}
isolate->heap()->UnregisterArrayBuffer(*self); isolate->heap()->UnregisterArrayBuffer(*self);
// A regular copy is good enough. No move semantics needed. // A regular copy is good enough. No move semantics needed.
...@@ -7797,11 +7817,9 @@ Local<SharedArrayBuffer> v8::SharedArrayBuffer::New( ...@@ -7797,11 +7817,9 @@ Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::Handle<i::JSArrayBuffer> obj = i::Handle<i::JSArrayBuffer> obj =
i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared); i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
bool is_wasm_memory =
i_isolate->wasm_engine()->memory_tracker()->IsWasmMemory(data);
i::JSArrayBuffer::Setup(obj, i_isolate, i::JSArrayBuffer::Setup(obj, i_isolate,
mode == ArrayBufferCreationMode::kExternalized, data, mode == ArrayBufferCreationMode::kExternalized, data,
byte_length, i::SharedFlag::kShared, is_wasm_memory); byte_length, i::SharedFlag::kShared);
return Utils::ToLocalShared(obj); return Utils::ToLocalShared(obj);
} }
......
...@@ -2567,8 +2567,12 @@ void SourceGroup::JoinThread() { ...@@ -2567,8 +2567,12 @@ void SourceGroup::JoinThread() {
} }
ExternalizedContents::~ExternalizedContents() { ExternalizedContents::~ExternalizedContents() {
if (data_ != nullptr) { if (base_ != nullptr) {
deleter_(data_, length_, deleter_data_); if (mode_ == ArrayBuffer::Allocator::AllocationMode::kReservation) {
CHECK(i::FreePages(base_, length_));
} else {
Shell::array_buffer_allocator->Free(base_, length_);
}
} }
} }
......
...@@ -132,45 +132,38 @@ class SourceGroup { ...@@ -132,45 +132,38 @@ class SourceGroup {
class ExternalizedContents { class ExternalizedContents {
public: public:
explicit ExternalizedContents(const ArrayBuffer::Contents& contents) explicit ExternalizedContents(const ArrayBuffer::Contents& contents)
: data_(contents.Data()), : base_(contents.AllocationBase()),
length_(contents.ByteLength()), length_(contents.AllocationLength()),
deleter_(contents.Deleter()), mode_(contents.AllocationMode()) {}
deleter_data_(contents.DeleterData()) {}
explicit ExternalizedContents(const SharedArrayBuffer::Contents& contents) explicit ExternalizedContents(const SharedArrayBuffer::Contents& contents)
: data_(contents.Data()), : base_(contents.AllocationBase()),
length_(contents.ByteLength()), length_(contents.AllocationLength()),
deleter_(contents.Deleter()), mode_(contents.AllocationMode()) {}
deleter_data_(contents.DeleterData()) {}
ExternalizedContents(ExternalizedContents&& other) V8_NOEXCEPT ExternalizedContents(ExternalizedContents&& other) V8_NOEXCEPT
: data_(other.data_), : base_(other.base_),
length_(other.length_), length_(other.length_),
deleter_(other.deleter_), mode_(other.mode_) {
deleter_data_(other.deleter_data_) { other.base_ = nullptr;
other.data_ = nullptr;
other.length_ = 0; other.length_ = 0;
other.deleter_ = nullptr; other.mode_ = ArrayBuffer::Allocator::AllocationMode::kNormal;
other.deleter_data_ = nullptr;
} }
ExternalizedContents& operator=(ExternalizedContents&& other) V8_NOEXCEPT { ExternalizedContents& operator=(ExternalizedContents&& other) V8_NOEXCEPT {
if (this != &other) { if (this != &other) {
data_ = other.data_; base_ = other.base_;
length_ = other.length_; length_ = other.length_;
deleter_ = other.deleter_; mode_ = other.mode_;
deleter_data_ = other.deleter_data_; other.base_ = nullptr;
other.data_ = nullptr;
other.length_ = 0; other.length_ = 0;
other.deleter_ = nullptr; other.mode_ = ArrayBuffer::Allocator::AllocationMode::kNormal;
other.deleter_data_ = nullptr;
} }
return *this; return *this;
} }
~ExternalizedContents(); ~ExternalizedContents();
private: private:
void* data_; void* base_;
size_t length_; size_t length_;
ArrayBuffer::Contents::DeleterCallback deleter_; ArrayBuffer::Allocator::AllocationMode mode_;
void* deleter_data_;
DISALLOW_COPY_AND_ASSIGN(ExternalizedContents); DISALLOW_COPY_AND_ASSIGN(ExternalizedContents);
}; };
......
...@@ -992,9 +992,13 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -992,9 +992,13 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
Handle<JSArrayBuffer> memory = memory_.ToHandleChecked(); Handle<JSArrayBuffer> memory = memory_.ToHandleChecked();
memory->set_is_neuterable(false); memory->set_is_neuterable(false);
DCHECK_IMPLIES(use_trap_handler(), module_->origin == kAsmJsOrigin || DCHECK_IMPLIES(use_trap_handler(),
memory->is_wasm_memory() || module_->origin == kAsmJsOrigin ||
memory->backing_store() == nullptr); memory->is_wasm_memory() ||
memory->backing_store() == nullptr ||
// TODO(836800) Remove once is_wasm_memory transfers over
// post-message.
(enabled_.threads && memory->is_shared()));
} else if (initial_pages > 0 || use_trap_handler()) { } else if (initial_pages > 0 || use_trap_handler()) {
// We need to unconditionally create a guard region if using trap handlers, // We need to unconditionally create a guard region if using trap handlers,
// even when the size is zero to prevent null-dereference issues // even when the size is zero to prevent null-dereference issues
......
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