Commit 3c2d9527 authored by Stephan Herhut's avatar Stephan Herhut Committed by Commit Bot

Remove AllocationKind from array buffer handling

With the new v8 interface for externalizing array buffer contents, we
no longer need to store the kind or allocation_base/size on the blink
side. Hence, this change removes those fields completely.

Furthermore, gin now also uses the custom deleter based interface.

Change-Id: Ifa1a1900e83e7f9fab859672edc8fe54ad7e647e
Reviewed-on: https://chromium-review.googlesource.com/1235937Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Commit-Queue: Stephan Herhut <herhut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593613}
parent b2838220
......@@ -83,6 +83,7 @@ class ArrayBuffer::Private : public base::RefCounted<ArrayBuffer::Private> {
private:
friend class base::RefCounted<Private>;
using DataDeleter = void (*)(void* data, size_t length, void* info);
Private(v8::Isolate* isolate, v8::Local<v8::ArrayBuffer> array);
~Private();
......@@ -95,9 +96,8 @@ class ArrayBuffer::Private : public base::RefCounted<ArrayBuffer::Private> {
v8::Isolate* isolate_;
void* buffer_;
size_t length_;
void* allocation_base_;
size_t allocation_length_;
v8::ArrayBuffer::Allocator::AllocationMode allocation_mode_;
DataDeleter deleter_;
void* deleter_data_;
};
scoped_refptr<ArrayBuffer::Private> ArrayBuffer::Private::From(
......@@ -118,18 +118,10 @@ ArrayBuffer::Private::Private(v8::Isolate* isolate,
// Take ownership of the array buffer.
CHECK(!array->IsExternal());
v8::ArrayBuffer::Contents contents = array->Externalize();
// We shouldn't receive large page-allocated array buffers.
CHECK_NE(v8::ArrayBuffer::Allocator::AllocationMode::kReservation,
contents.AllocationMode());
buffer_ = contents.Data();
length_ = contents.ByteLength();
allocation_base_ = contents.AllocationBase();
allocation_length_ = contents.AllocationLength();
DCHECK(reinterpret_cast<uintptr_t>(allocation_base_) <=
reinterpret_cast<uintptr_t>(buffer_));
DCHECK(reinterpret_cast<uintptr_t>(buffer_) + length_ <=
reinterpret_cast<uintptr_t>(allocation_base_) + allocation_length_);
deleter_ = contents.Deleter();
deleter_data_ = contents.DeleterData();
array->SetAlignedPointerInInternalField(kWrapperInfoIndex,
&g_array_buffer_wrapper_info);
......@@ -141,8 +133,7 @@ ArrayBuffer::Private::Private(v8::Isolate* isolate,
}
ArrayBuffer::Private::~Private() {
PerIsolateData::From(isolate_)->allocator()->Free(allocation_base_,
allocation_length_);
deleter_(buffer_, length_, deleter_data_);
}
void ArrayBuffer::Private::FirstWeakCallback(
......
......@@ -1034,22 +1034,8 @@ v8::Local<v8::Object> {{v8_class}}::findInstanceInPrototypeChain(v8::Local<v8::V
// Transfer the ownership of the allocated memory to an {{interface_name}} without
// copying.
v8::{{interface_name}}::Contents v8Contents = v8buffer->Externalize();
WTF::ArrayBufferContents::AllocationKind kind = WTF::ArrayBufferContents::AllocationKind::kNormal;
switch (v8Contents.AllocationMode()) {
case v8::ArrayBuffer::Allocator::AllocationMode::kNormal:
kind = WTF::ArrayBufferContents::AllocationKind::kNormal;
break;
case v8::ArrayBuffer::Allocator::AllocationMode::kReservation:
kind = WTF::ArrayBufferContents::AllocationKind::kReservation;
break;
default:
NOTREACHED();
};
WTF::ArrayBufferContents::DataHandle data(v8Contents.AllocationBase(),
v8Contents.AllocationLength(),
v8Contents.Data(),
WTF::ArrayBufferContents::DataHandle data(v8Contents.Data(),
v8Contents.ByteLength(),
kind,
v8Contents.Deleter(),
v8Contents.DeleterData());
WTF::ArrayBufferContents contents(std::move(data), WTF::ArrayBufferContents::k{% if interface_name == 'ArrayBuffer' %}Not{% endif %}Shared);
......
......@@ -76,22 +76,8 @@ TestArrayBuffer* V8ArrayBuffer::ToImpl(v8::Local<v8::Object> object) {
// Transfer the ownership of the allocated memory to an ArrayBuffer without
// copying.
v8::ArrayBuffer::Contents v8Contents = v8buffer->Externalize();
WTF::ArrayBufferContents::AllocationKind kind = WTF::ArrayBufferContents::AllocationKind::kNormal;
switch (v8Contents.AllocationMode()) {
case v8::ArrayBuffer::Allocator::AllocationMode::kNormal:
kind = WTF::ArrayBufferContents::AllocationKind::kNormal;
break;
case v8::ArrayBuffer::Allocator::AllocationMode::kReservation:
kind = WTF::ArrayBufferContents::AllocationKind::kReservation;
break;
default:
NOTREACHED();
};
WTF::ArrayBufferContents::DataHandle data(v8Contents.AllocationBase(),
v8Contents.AllocationLength(),
v8Contents.Data(),
WTF::ArrayBufferContents::DataHandle data(v8Contents.Data(),
v8Contents.ByteLength(),
kind,
v8Contents.Deleter(),
v8Contents.DeleterData());
WTF::ArrayBufferContents contents(std::move(data), WTF::ArrayBufferContents::kNotShared);
......
......@@ -52,8 +52,6 @@ class WTF_EXPORT ArrayBufferContents {
// specifies the correct deleter.
using DataDeleter = void (*)(void* data, size_t length, void* info);
enum class AllocationKind { kNormal, kReservation };
class DataHandle {
DISALLOW_COPY_AND_ASSIGN(DataHandle);
......@@ -62,88 +60,37 @@ class WTF_EXPORT ArrayBufferContents {
size_t length,
DataDeleter deleter,
void* deleter_info)
: allocation_base_(data),
allocation_length_(length),
data_(data),
: data_(data),
data_length_(length),
kind_(AllocationKind::kNormal),
deleter_(deleter),
deleter_info_(deleter_info) {}
DataHandle(void* allocation_base,
size_t allocation_length,
void* data,
size_t data_length,
AllocationKind kind,
DataDeleter deleter,
void* deleter_info)
: allocation_base_(allocation_base),
allocation_length_(allocation_length),
data_(data),
data_length_(data_length),
kind_(kind),
deleter_(deleter),
deleter_info_(deleter_info) {
DCHECK(reinterpret_cast<uintptr_t>(allocation_base_) <=
reinterpret_cast<uintptr_t>(data_));
DCHECK(reinterpret_cast<uintptr_t>(data_) + data_length_ <=
reinterpret_cast<uintptr_t>(allocation_base_) +
allocation_length_);
}
// Move constructor
DataHandle(DataHandle&& other) { *this = std::move(other); }
~DataHandle() {
if (!allocation_base_)
if (!data_)
return;
DCHECK(reinterpret_cast<uintptr_t>(allocation_base_) <=
reinterpret_cast<uintptr_t>(data_));
DCHECK(reinterpret_cast<uintptr_t>(data_) + data_length_ <=
reinterpret_cast<uintptr_t>(allocation_base_) +
allocation_length_);
switch (kind_) {
case AllocationKind::kNormal:
DCHECK(deleter_);
deleter_(data_, data_length_, deleter_info_);
return;
case AllocationKind::kReservation:
DCHECK(deleter_);
deleter_(data_, data_length_, deleter_info_);
return;
}
deleter_(data_, data_length_, deleter_info_);
}
// Move operator
DataHandle& operator=(DataHandle&& other) {
allocation_base_ = other.allocation_base_;
allocation_length_ = other.allocation_length_;
data_ = other.data_;
data_length_ = other.data_length_;
kind_ = other.kind_;
deleter_ = other.deleter_;
deleter_info_ = other.deleter_info_;
other.allocation_base_ = nullptr;
other.data_ = nullptr;
return *this;
}
void* AllocationBase() const { return allocation_base_; }
size_t AllocationLength() const { return allocation_length_; }
void* Data() const { return data_; }
size_t DataLength() const { return data_length_; }
ArrayBufferContents::AllocationKind GetAllocationKind() const {
return kind_;
}
operator bool() const { return allocation_base_; }
operator bool() const { return data_; }
private:
void* allocation_base_;
size_t allocation_length_;
void* data_;
size_t data_length_;
ArrayBufferContents::AllocationKind kind_;
DataDeleter deleter_;
void* deleter_info_;
};
......
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