Bug 1496378 part 2 - Move data pointer accessors from DataViewObject/TypedArrayObject to ArrayBufferViewObject. r=jwalden

Note that DataViewObject had dataPointer* methods but TypedArrayObject used
viewData* for this. I used dataPointer* for consistency with ArrayBufferObject
(and I like it more).

Depends on D7721

Differential Revision: https://phabricator.services.mozilla.com/D7722

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan de Mooij 2018-10-15 11:51:46 +00:00
parent e3bba47ba5
commit b94bcfafb4
16 changed files with 95 additions and 134 deletions

View File

@ -206,7 +206,7 @@ js::atomics_compareExchange(JSContext* cx, unsigned argc, Value* vp)
bool badType = false;
int32_t result = CompareExchange(view->type(), oldCandidate, newCandidate,
view->viewDataShared(), offset, &badType);
view->dataPointerShared(), offset, &badType);
if (badType) {
return ReportBadArrayType(cx);
@ -237,7 +237,7 @@ js::atomics_load(JSContext* cx, unsigned argc, Value* vp)
return false;
}
SharedMem<void*> viewData = view->viewDataShared();
SharedMem<void*> viewData = view->dataPointerShared();
switch (view->type()) {
case Scalar::Uint8: {
uint8_t v = jit::AtomicOperations::loadSeqCst(viewData.cast<uint8_t*>() + offset);
@ -357,7 +357,7 @@ ExchangeOrStore(JSContext* cx, unsigned argc, Value* vp)
bool badType = false;
int32_t result = ExchangeOrStore<op>(view->type(), JS::ToInt32(integerValue),
view->viewDataShared(), offset, &badType);
view->dataPointerShared(), offset, &badType);
if (badType) {
return ReportBadArrayType(cx);
@ -403,7 +403,7 @@ AtomicsBinop(JSContext* cx, HandleValue objv, HandleValue idxv, HandleValue valv
return false;
}
SharedMem<void*> viewData = view->viewDataShared();
SharedMem<void*> viewData = view->dataPointerShared();
switch (view->type()) {
case Scalar::Int8: {
int8_t v = (int8_t)numberValue;
@ -700,7 +700,7 @@ js::atomics_wait(JSContext* cx, unsigned argc, Value* vp)
// The computation will not overflow because range checks have been
// performed.
uint32_t byteOffset = offset * sizeof(int32_t) +
(view->viewDataShared().cast<uint8_t*>().unwrap(/* arithmetic */) -
(view->dataPointerShared().cast<uint8_t*>().unwrap(/* arithmetic */) -
sab->dataPointerShared().unwrap(/* arithmetic */));
switch (atomics_wait_impl(cx, sab->rawBufferObject(), byteOffset, value, timeout)) {
@ -794,7 +794,7 @@ js::atomics_notify(JSContext* cx, unsigned argc, Value* vp)
// The computation will not overflow because range checks have been
// performed.
uint32_t byteOffset = offset * sizeof(int32_t) +
(view->viewDataShared().cast<uint8_t*>().unwrap(/* arithmetic */) -
(view->dataPointerShared().cast<uint8_t*>().unwrap(/* arithmetic */) -
sab->dataPointerShared().unwrap(/* arithmetic */));
r.setNumber(double(atomics_notify_impl(sab->rawBufferObject(), byteOffset, count)));

View File

@ -76,10 +76,7 @@ DataViewObject::create(JSContext* cx, uint32_t byteOffset, uint32_t byteLength,
obj->setFixedSlot(BUFFER_SLOT, ObjectValue(*arrayBuffer));
SharedMem<uint8_t*> ptr = arrayBuffer->dataPointerEither();
// A pointer to raw shared memory is exposed through the private slot. This
// is safe so long as getPrivate() is not used willy-nilly. It is wrapped in
// other accessors in TypedArrayObject.h.
obj->initPrivate(ptr.unwrap(/*safe - see above*/) + byteOffset);
obj->initDataPointer(ptr + byteOffset);
// Include a barrier if the data view's data pointer is in the nursery, as
// is done for typed arrays.

View File

@ -88,24 +88,6 @@ class DataViewObject : public ArrayBufferViewObject
return bufferValue(this).toObject().as<ArrayBufferObjectMaybeShared>();
}
SharedMem<void*> dataPointerEither() const {
void *p = getPrivate();
if (isSharedMemory()) {
return SharedMem<void*>::shared(p);
}
return SharedMem<void*>::unshared(p);
}
void* dataPointerUnshared() const {
MOZ_ASSERT(!isSharedMemory());
return getPrivate();
}
void* dataPointerShared() const {
MOZ_ASSERT(isSharedMemory());
return getPrivate();
}
static bool construct(JSContext* cx, unsigned argc, Value* vp);
static bool getInt8Impl(JSContext* cx, const CallArgs& args);

View File

@ -774,7 +774,7 @@ WasmTextToBinary(JSContext* cx, unsigned argc, Value* vp)
return false;
}
memcpy(binary->as<TypedArrayObject>().viewDataUnshared(), bytes.begin(), bytes.length());
memcpy(binary->as<TypedArrayObject>().dataPointerUnshared(), bytes.begin(), bytes.length());
if (!withOffsets) {
args.rval().setObject(*binary);

View File

@ -9175,7 +9175,7 @@ IonBuilder::addTypedArrayLengthAndData(MDefinition* obj,
}
if (tarr) {
SharedMem<void*> data = tarr->as<TypedArrayObject>().viewDataEither();
SharedMem<void*> data = tarr->as<TypedArrayObject>().dataPointerEither();
// Bug 979449 - Optimistically embed the elements and use TI to
// invalidate if we move them.
bool isTenured = !tarr->runtimeFromMainThread()->gc.nursery().isInside(data);

View File

@ -221,7 +221,7 @@ FileAsTypedArray(JSContext* cx, JS::HandleString pathnameStr)
JS_ReportErrorUTF8(cx, "can't read %s: shared memory buffer", pathname.get());
return nullptr;
}
char* buf = static_cast<char*>(ta.viewDataUnshared());
char* buf = static_cast<char*>(ta.dataPointerUnshared());
size_t cc = fread(buf, 1, len, file);
if (cc != len) {
if (ptrdiff_t(cc) < 0) {
@ -370,7 +370,7 @@ osfile_writeTypedArrayToFile(JSContext* cx, unsigned argc, Value* vp)
JS_ReportErrorUTF8(cx, "can't write %s: shared memory buffer", filename.get());
return false;
}
void* buf = obj->viewDataUnshared();
void* buf = obj->dataPointerUnshared();
if (fwrite(buf, obj->bytesPerElement(), obj->length(), file) != obj->length() ||
!autoClose.release())
{

View File

@ -1753,15 +1753,7 @@ ArrayBufferViewObject::notifyBufferDetached(JSContext* cx, void* newData)
uint8_t*
ArrayBufferViewObject::dataPointerUnshared(const JS::AutoRequireNoGC& nogc)
{
if (is<DataViewObject>()) {
MOZ_ASSERT(!as<DataViewObject>().isSharedMemory());
return static_cast<uint8_t*>(as<DataViewObject>().dataPointerUnshared());
}
if (is<TypedArrayObject>()) {
MOZ_ASSERT(!as<TypedArrayObject>().isSharedMemory());
return static_cast<uint8_t*>(as<TypedArrayObject>().viewDataUnshared());
}
MOZ_CRASH("Unknown ArrayBufferViewObject");
return static_cast<uint8_t*>(dataPointerUnshared());
}
void
@ -2057,14 +2049,10 @@ JS_GetArrayBufferViewData(JSObject* obj, bool* isSharedMemory, const JS::AutoReq
if (!obj) {
return nullptr;
}
if (obj->is<DataViewObject>()) {
DataViewObject& dv = obj->as<DataViewObject>();
*isSharedMemory = dv.isSharedMemory();
return dv.dataPointerEither().unwrap(/*safe - caller sees isSharedMemory flag*/);
}
TypedArrayObject& ta = obj->as<TypedArrayObject>();
*isSharedMemory = ta.isSharedMemory();
return ta.viewDataEither().unwrap(/*safe - caller sees isSharedMemory flag*/);
ArrayBufferViewObject& view = obj->as<ArrayBufferViewObject>();
*isSharedMemory = view.isSharedMemory();
return view.dataPointerEither().unwrap(/*safe - caller sees isSharedMemory flag*/);
}
JS_FRIEND_API(JSObject*)
@ -2134,18 +2122,10 @@ js::GetArrayBufferViewLengthAndData(JSObject* obj, uint32_t* length, bool* isSha
? obj->as<DataViewObject>().byteLength()
: obj->as<TypedArrayObject>().byteLength();
if (obj->is<DataViewObject>()) {
DataViewObject& dv = obj->as<DataViewObject>();
*isSharedMemory = dv.isSharedMemory();
*data = static_cast<uint8_t*>(
dv.dataPointerEither().unwrap(/*safe - caller sees isShared flag*/));
}
else {
TypedArrayObject& ta = obj->as<TypedArrayObject>();
*isSharedMemory = ta.isSharedMemory();
*data = static_cast<uint8_t*>(
ta.viewDataEither().unwrap(/*safe - caller sees isShared flag*/));
}
ArrayBufferViewObject& view = obj->as<ArrayBufferViewObject>();
*isSharedMemory = view.isSharedMemory();
*data = static_cast<uint8_t*>(
view.dataPointerEither().unwrap(/*safe - caller sees isShared flag*/));
}
JS_FRIEND_API(JSObject*)

View File

@ -492,6 +492,14 @@ class ArrayBufferViewObject : public NativeObject
// need not be looked up on accesses.
static constexpr size_t DATA_SLOT = 3;
private:
void* dataPointerEither_() const {
// Note, do not check whether shared or not
// Keep synced with js::Get<Type>ArrayLengthAndData in jsfriendapi.h!
return static_cast<void*>(getPrivate(DATA_SLOT));
}
public:
static ArrayBufferObjectMaybeShared* bufferObject(JSContext* cx, Handle<ArrayBufferViewObject*> obj);
void notifyBufferDetached(JSContext* cx, void* newData);
@ -501,6 +509,31 @@ class ArrayBufferViewObject : public NativeObject
uint8_t* dataPointerUnshared(const JS::AutoRequireNoGC&);
void setDataPointerUnshared(uint8_t* data);
void initDataPointer(SharedMem<uint8_t*> viewData) {
// Install a pointer to the buffer location that corresponds
// to offset zero within the typed array.
//
// The following unwrap is safe because the DATA_SLOT is
// accessed only from jitted code and from the
// dataPointerEither_() accessor above; in neither case does the
// raw pointer escape untagged into C++ code.
initPrivate(viewData.unwrap(/*safe - see above*/));
}
SharedMem<void*> dataPointerShared() const {
return SharedMem<void*>::shared(dataPointerEither_());
}
SharedMem<void*> dataPointerEither() const {
if (isSharedMemory()) {
return SharedMem<void*>::shared(dataPointerEither_());
}
return SharedMem<void*>::unshared(dataPointerEither_());
}
void* dataPointerUnshared() const {
MOZ_ASSERT(!isSharedMemory());
return dataPointerEither_();
}
static void trace(JSTracer* trc, JSObject* obj);
};

View File

@ -7898,7 +7898,7 @@ DebuggerSource_getBinary(JSContext* cx, unsigned argc, Value* vp)
return false;
}
memcpy(arr->as<TypedArrayObject>().viewDataUnshared(), bytecode.begin(), bytecode.length());
memcpy(arr->as<TypedArrayObject>().dataPointerUnshared(), bytecode.begin(), bytecode.length());
args.rval().setObject(*arr);
return true;

View File

@ -1237,7 +1237,7 @@ intrinsic_MoveTypedArrayElements(JSContext* cx, unsigned argc, Value* vp)
}
#endif
SharedMem<uint8_t*> data = tarray->viewDataEither().cast<uint8_t*>();
SharedMem<uint8_t*> data = tarray->dataPointerEither().cast<uint8_t*>();
jit::AtomicOperations::memmoveSafeWhenRacy(data + byteDest, data + byteSrc, byteSize);
args.rval().setUndefined();
@ -1340,10 +1340,10 @@ intrinsic_SetFromTypedArrayApproach(JSContext* cx, unsigned argc, Value* vp)
size_t targetElementSize = TypedArrayElemSize(targetType);
SharedMem<uint8_t*> targetData =
target->viewDataEither().cast<uint8_t*>() + targetOffset * targetElementSize;
target->dataPointerEither().cast<uint8_t*>() + targetOffset * targetElementSize;
SharedMem<uint8_t*> unsafeSrcDataCrossCompartment =
unsafeTypedArrayCrossCompartment->viewDataEither().cast<uint8_t*>();
unsafeTypedArrayCrossCompartment->dataPointerEither().cast<uint8_t*>();
uint32_t unsafeSrcElementSizeCrossCompartment =
TypedArrayElemSize(unsafeSrcTypeCrossCompartment);
@ -1374,7 +1374,7 @@ intrinsic_SetFromTypedArrayApproach(JSContext* cx, unsigned argc, Value* vp)
SharedMem<uint8_t*> unsafeSrcDataLimitCrossCompartment =
unsafeSrcDataCrossCompartment + unsafeSrcByteLengthCrossCompartment;
SharedMem<uint8_t*> targetDataLimit =
target->viewDataEither().cast<uint8_t*>() + targetLength * targetElementSize;
target->dataPointerEither().cast<uint8_t*>() + targetLength * targetElementSize;
// Step 24 test (but not steps 24a-d -- the caller handles those).
bool overlap =
@ -1463,7 +1463,7 @@ CopyToDisjointArray(TypedArrayObject* target, uint32_t targetOffset, SharedMem<v
Scalar::Type srcType, uint32_t count)
{
Scalar::Type destType = target->type();
SharedMem<uint8_t*> dest = target->viewDataEither().cast<uint8_t*>() + targetOffset * TypedArrayElemSize(destType);
SharedMem<uint8_t*> dest = target->dataPointerEither().cast<uint8_t*>() + targetOffset * TypedArrayElemSize(destType);
switch (destType) {
case Scalar::Int8: {
@ -1526,7 +1526,7 @@ js::SetDisjointTypedElements(TypedArrayObject* target, uint32_t targetOffset,
{
Scalar::Type unsafeSrcTypeCrossCompartment = unsafeSrcCrossCompartment->type();
SharedMem<void*> unsafeSrcDataCrossCompartment = unsafeSrcCrossCompartment->viewDataEither();
SharedMem<void*> unsafeSrcDataCrossCompartment = unsafeSrcCrossCompartment->dataPointerEither();
uint32_t count = unsafeSrcCrossCompartment->length();
CopyToDisjointArray(target, targetOffset,
@ -1597,7 +1597,7 @@ intrinsic_SetOverlappingTypedElements(JSContext* cx, unsigned argc, Value* vp)
}
jit::AtomicOperations::memcpySafeWhenRacy(SharedMem<uint8_t*>::unshared(copyOfSrcData.get()),
unsafeSrcCrossCompartment->viewDataEither().cast<uint8_t*>(),
unsafeSrcCrossCompartment->dataPointerEither().cast<uint8_t*>(),
sourceByteLen);
CopyToDisjointArray(target, targetOffset, SharedMem<void*>::unshared(copyOfSrcData.get()),
@ -1684,10 +1684,10 @@ intrinsic_TypedArrayBitwiseSlice(JSContext* cx, unsigned argc, Value* vp)
MOZ_ASSERT(elementSize == TypedArrayElemSize(unsafeTypedArrayCrossCompartment->type()));
SharedMem<uint8_t*> sourceData =
source->viewDataEither().cast<uint8_t*>() + sourceOffset * elementSize;
source->dataPointerEither().cast<uint8_t*>() + sourceOffset * elementSize;
SharedMem<uint8_t*> unsafeTargetDataCrossCompartment =
unsafeTypedArrayCrossCompartment->viewDataEither().cast<uint8_t*>();
unsafeTypedArrayCrossCompartment->dataPointerEither().cast<uint8_t*>();
uint32_t byteLength = count * elementSize;

View File

@ -2094,7 +2094,7 @@ class ConstraintDataFreezeObjectForTypedArrayData
public:
explicit ConstraintDataFreezeObjectForTypedArrayData(TypedArrayObject& tarray)
: obj(&tarray),
viewData(tarray.viewDataEither().unwrapValue()),
viewData(tarray.dataPointerEither().unwrapValue()),
length(tarray.length())
{
MOZ_ASSERT(tarray.isSingleton());
@ -2107,7 +2107,7 @@ class ConstraintDataFreezeObjectForTypedArrayData
bool invalidateOnNewObjectState(const AutoSweepObjectGroup& sweep, ObjectGroup* group) {
MOZ_ASSERT(obj->group() == group);
TypedArrayObject& tarr = obj->as<TypedArrayObject>();
return tarr.viewDataEither().unwrapValue() != viewData || tarr.length() != length;
return tarr.dataPointerEither().unwrapValue() != viewData || tarr.length() != length;
}
bool constraintHolds(const AutoSweepObjectGroup& sweep, JSContext* cx,

View File

@ -189,7 +189,7 @@ class SharedOps
}
static SharedMem<void*> extract(TypedArrayObject* obj) {
return obj->viewDataEither();
return obj->dataPointerEither();
}
};
@ -239,7 +239,7 @@ class UnsharedOps
}
static SharedMem<void*> extract(TypedArrayObject* obj) {
return SharedMem<void*>::unshared(obj->viewDataUnshared());
return SharedMem<void*>::unshared(obj->dataPointerUnshared());
}
};
@ -271,11 +271,11 @@ class ElementSpecific
return setFromOverlappingTypedArray(target, source, offset);
}
SharedMem<T*> dest = target->viewDataEither().template cast<T*>() + offset;
SharedMem<T*> dest = target->dataPointerEither().template cast<T*>() + offset;
uint32_t count = source->length();
if (source->type() == target->type()) {
Ops::podCopy(dest, source->viewDataEither().template cast<T*>(), count);
Ops::podCopy(dest, source->dataPointerEither().template cast<T*>(), count);
return true;
}
@ -375,7 +375,7 @@ class ElementSpecific
// the first potentially side-effectful lookup or conversion.
uint32_t bound = Min(source->as<NativeObject>().getDenseInitializedLength(), len);
SharedMem<T*> dest = target->viewDataEither().template cast<T*>() + offset;
SharedMem<T*> dest = target->dataPointerEither().template cast<T*>() + offset;
MOZ_ASSERT(!canConvertInfallibly(MagicValue(JS_ELEMENTS_HOLE)),
"the following loop must abort on holes");
@ -411,7 +411,7 @@ class ElementSpecific
// Compute every iteration in case getElement/valueToNative
// detaches the underlying array buffer or GC moves the data.
SharedMem<T*> dest = target->viewDataEither().template cast<T*>() + offset + i;
SharedMem<T*> dest = target->dataPointerEither().template cast<T*>() + offset + i;
Ops::store(dest, n);
}
@ -437,7 +437,7 @@ class ElementSpecific
// Attempt fast-path infallible conversion of dense elements up to the
// first potentially side-effectful conversion.
SharedMem<T*> dest = target->viewDataEither().template cast<T*>();
SharedMem<T*> dest = target->dataPointerEither().template cast<T*>();
const Value* srcValues = source->getDenseElements();
for (; i < len; i++) {
@ -472,7 +472,7 @@ class ElementSpecific
MOZ_ASSERT(i < target->length());
// Compute every iteration in case GC moves the data.
SharedMem<T*> newDest = target->viewDataEither().template cast<T*>();
SharedMem<T*> newDest = target->dataPointerEither().template cast<T*>();
Ops::store(newDest + i, n);
}
@ -499,11 +499,11 @@ class ElementSpecific
MOZ_ASSERT(offset <= target->length());
MOZ_ASSERT(source->length() <= target->length() - offset);
SharedMem<T*> dest = target->viewDataEither().template cast<T*>() + offset;
SharedMem<T*> dest = target->dataPointerEither().template cast<T*>() + offset;
uint32_t len = source->length();
if (source->type() == target->type()) {
SharedMem<T*> src = source->viewDataEither().template cast<T*>();
SharedMem<T*> src = source->dataPointerEither().template cast<T*>();
Ops::podMove(dest, src, len);
return true;
}
@ -515,7 +515,7 @@ class ElementSpecific
return false;
}
Ops::memcpy(SharedMem<void*>::unshared(data),
source->viewDataEither(),
source->dataPointerEither(),
sourceByteLen);
switch (source->type()) {

View File

@ -120,7 +120,7 @@ TypedArrayObject::ensureHasBuffer(JSContext* cx, Handle<TypedArrayObject*> tarra
}
// tarray is not shared, because if it were it would have a buffer.
memcpy(buffer->dataPointer(), tarray->viewDataUnshared(), tarray->byteLength());
memcpy(buffer->dataPointer(), tarray->dataPointerUnshared(), tarray->byteLength());
// If the object is in the nursery, the buffer will be freed by the next
// nursery GC. Free the data slot pointer if the object has no inline data.
@ -501,7 +501,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject
}
if (buffer) {
obj->initViewData(buffer->dataPointerEither() + byteOffset);
obj->initDataPointer(buffer->dataPointerEither() + byteOffset);
// If the buffer is for an inline typed object, the data pointer
// may be in the nursery, so include a barrier to make sure this
@ -543,7 +543,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject
// Unwraps are safe: both are for the pointer value.
if (IsArrayBuffer(buffer.get())) {
MOZ_ASSERT_IF(!AsArrayBuffer(buffer.get()).isDetached(),
buffer->dataPointerEither().unwrap(/*safe*/) <= obj->viewDataEither().unwrap(/*safe*/));
buffer->dataPointerEither().unwrap(/*safe*/) <= obj->dataPointerEither().unwrap(/*safe*/));
}
MOZ_ASSERT(bufferByteLength - arrayByteOffset >= arrayByteLength);
MOZ_ASSERT(arrayByteOffset <= bufferByteLength);
@ -1039,14 +1039,14 @@ class TypedArrayObjectTemplate : public TypedArrayObject
getIndex(TypedArrayObject* tarray, uint32_t index)
{
MOZ_ASSERT(index < tarray->length());
return jit::AtomicOperations::loadSafeWhenRacy(tarray->viewDataEither().cast<NativeType*>() + index);
return jit::AtomicOperations::loadSafeWhenRacy(tarray->dataPointerEither().cast<NativeType*>() + index);
}
static void
setIndex(TypedArrayObject& tarray, uint32_t index, NativeType val)
{
MOZ_ASSERT(index < tarray.length());
jit::AtomicOperations::storeSafeWhenRacy(tarray.viewDataEither().cast<NativeType*>() + index, val);
jit::AtomicOperations::storeSafeWhenRacy(tarray.dataPointerEither().cast<NativeType*>() + index, val);
}
static Value getIndexValue(TypedArrayObject* tarray, uint32_t index);
@ -2028,7 +2028,7 @@ IMPL_TYPED_ARRAY_JSAPI_CONSTRUCTORS(Float64, double)
TypedArrayObject* tarr = &obj->as<TypedArrayObject>(); \
*length = tarr->length(); \
*isShared = tarr->isSharedMemory(); \
*data = static_cast<ExternalType*>(tarr->viewDataEither().unwrap(/*safe - caller sees isShared flag*/)); \
*data = static_cast<ExternalType*>(tarr->dataPointerEither().unwrap(/*safe - caller sees isShared flag*/)); \
\
return obj; \
}
@ -2204,7 +2204,7 @@ js::IsBufferSource(JSObject* object, SharedMem<uint8_t*>* dataPointer, size_t* b
{
if (object->is<TypedArrayObject>()) {
TypedArrayObject& view = object->as<TypedArrayObject>();
*dataPointer = view.viewDataEither().cast<uint8_t*>();
*dataPointer = view.dataPointerEither().cast<uint8_t*>();
*byteLength = view.byteLength();
return true;
}
@ -2437,7 +2437,7 @@ JS_GetInt8ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoRequireNo
TypedArrayObject* tarr = &obj->as<TypedArrayObject>();
MOZ_ASSERT((int32_t) tarr->type() == Scalar::Int8);
*isSharedMemory = tarr->isSharedMemory();
return static_cast<int8_t*>(tarr->viewDataEither().unwrap(/*safe - caller sees isShared*/));
return static_cast<int8_t*>(tarr->dataPointerEither().unwrap(/*safe - caller sees isShared*/));
}
JS_FRIEND_API(uint8_t*)
@ -2450,7 +2450,7 @@ JS_GetUint8ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoRequireN
TypedArrayObject* tarr = &obj->as<TypedArrayObject>();
MOZ_ASSERT((int32_t) tarr->type() == Scalar::Uint8);
*isSharedMemory = tarr->isSharedMemory();
return static_cast<uint8_t*>(tarr->viewDataEither().unwrap(/*safe - caller sees isSharedMemory*/));
return static_cast<uint8_t*>(tarr->dataPointerEither().unwrap(/*safe - caller sees isSharedMemory*/));
}
JS_FRIEND_API(uint8_t*)
@ -2463,7 +2463,7 @@ JS_GetUint8ClampedArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoR
TypedArrayObject* tarr = &obj->as<TypedArrayObject>();
MOZ_ASSERT((int32_t) tarr->type() == Scalar::Uint8Clamped);
*isSharedMemory = tarr->isSharedMemory();
return static_cast<uint8_t*>(tarr->viewDataEither().unwrap(/*safe - caller sees isSharedMemory*/));
return static_cast<uint8_t*>(tarr->dataPointerEither().unwrap(/*safe - caller sees isSharedMemory*/));
}
JS_FRIEND_API(int16_t*)
@ -2476,7 +2476,7 @@ JS_GetInt16ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoRequireN
TypedArrayObject* tarr = &obj->as<TypedArrayObject>();
MOZ_ASSERT((int32_t) tarr->type() == Scalar::Int16);
*isSharedMemory = tarr->isSharedMemory();
return static_cast<int16_t*>(tarr->viewDataEither().unwrap(/*safe - caller sees isSharedMemory*/));
return static_cast<int16_t*>(tarr->dataPointerEither().unwrap(/*safe - caller sees isSharedMemory*/));
}
JS_FRIEND_API(uint16_t*)
@ -2489,7 +2489,7 @@ JS_GetUint16ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoRequire
TypedArrayObject* tarr = &obj->as<TypedArrayObject>();
MOZ_ASSERT((int32_t) tarr->type() == Scalar::Uint16);
*isSharedMemory = tarr->isSharedMemory();
return static_cast<uint16_t*>(tarr->viewDataEither().unwrap(/*safe - caller sees isSharedMemory*/));
return static_cast<uint16_t*>(tarr->dataPointerEither().unwrap(/*safe - caller sees isSharedMemory*/));
}
JS_FRIEND_API(int32_t*)
@ -2502,7 +2502,7 @@ JS_GetInt32ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoRequireN
TypedArrayObject* tarr = &obj->as<TypedArrayObject>();
MOZ_ASSERT((int32_t) tarr->type() == Scalar::Int32);
*isSharedMemory = tarr->isSharedMemory();
return static_cast<int32_t*>(tarr->viewDataEither().unwrap(/*safe - caller sees isSharedMemory*/));
return static_cast<int32_t*>(tarr->dataPointerEither().unwrap(/*safe - caller sees isSharedMemory*/));
}
JS_FRIEND_API(uint32_t*)
@ -2515,7 +2515,7 @@ JS_GetUint32ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoRequire
TypedArrayObject* tarr = &obj->as<TypedArrayObject>();
MOZ_ASSERT((int32_t) tarr->type() == Scalar::Uint32);
*isSharedMemory = tarr->isSharedMemory();
return static_cast<uint32_t*>(tarr->viewDataEither().unwrap(/*safe - caller sees isSharedMemory*/));
return static_cast<uint32_t*>(tarr->dataPointerEither().unwrap(/*safe - caller sees isSharedMemory*/));
}
JS_FRIEND_API(float*)
@ -2528,7 +2528,7 @@ JS_GetFloat32ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoRequir
TypedArrayObject* tarr = &obj->as<TypedArrayObject>();
MOZ_ASSERT((int32_t) tarr->type() == Scalar::Float32);
*isSharedMemory = tarr->isSharedMemory();
return static_cast<float*>(tarr->viewDataEither().unwrap(/*safe - caller sees isSharedMemory*/));
return static_cast<float*>(tarr->dataPointerEither().unwrap(/*safe - caller sees isSharedMemory*/));
}
JS_FRIEND_API(double*)
@ -2541,5 +2541,5 @@ JS_GetFloat64ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoRequir
TypedArrayObject* tarr = &obj->as<TypedArrayObject>();
MOZ_ASSERT((int32_t) tarr->type() == Scalar::Float64);
*isSharedMemory = tarr->isSharedMemory();
return static_cast<double*>(tarr->viewDataEither().unwrap(/*safe - caller sees isSharedMemory*/));
return static_cast<double*>(tarr->dataPointerEither().unwrap(/*safe - caller sees isSharedMemory*/));
}

View File

@ -188,30 +188,6 @@ class TypedArrayObject : public ArrayBufferViewObject
return &obj->as<ArrayBufferObject>();
}
SharedMem<void*> viewDataShared() const {
return SharedMem<void*>::shared(viewDataEither_());
}
SharedMem<void*> viewDataEither() const {
if (isSharedMemory()) {
return SharedMem<void*>::shared(viewDataEither_());
}
return SharedMem<void*>::unshared(viewDataEither_());
}
void initViewData(SharedMem<uint8_t*> viewData) {
// Install a pointer to the buffer location that corresponds
// to offset zero within the typed array.
//
// The following unwrap is safe because the DATA_SLOT is
// accessed only from jitted code and from the
// viewDataEither_() accessor below; in neither case does the
// raw pointer escape untagged into C++ code.
initPrivate(viewData.unwrap(/*safe - see above*/));
}
void* viewDataUnshared() const {
MOZ_ASSERT(!isSharedMemory());
return viewDataEither_();
}
bool hasDetachedBuffer() const {
// Shared buffers can't be detached.
if (isSharedMemory()) {
@ -228,14 +204,6 @@ class TypedArrayObject : public ArrayBufferViewObject
return buffer->isDetached();
}
private:
void* viewDataEither_() const {
// Note, do not check whether shared or not
// Keep synced with js::Get<Type>ArrayLengthAndData in jsfriendapi.h!
return static_cast<void*>(getPrivate(DATA_SLOT));
}
public:
static void trace(JSTracer* trc, JSObject* obj);
static void finalize(FreeOp* fop, JSObject* obj);
static size_t objectMoved(JSObject* obj, JSObject* old);

View File

@ -400,7 +400,7 @@ wasm::Eval(JSContext* cx, Handle<TypedArrayObject*> code, HandleObject importObj
return false;
}
if (!bytecode->append((uint8_t*)code->viewDataEither().unwrap(), code->byteLength())) {
if (!bytecode->append((uint8_t*)code->dataPointerEither().unwrap(), code->byteLength())) {
ReportOutOfMemory(cx);
return false;
}

View File

@ -500,7 +500,8 @@ Module::extractCode(JSContext* cx, Tier tier, MutableHandleValue vp) const
return false;
}
memcpy(code->as<TypedArrayObject>().viewDataUnshared(), moduleSegment.base(), moduleSegment.length());
memcpy(code->as<TypedArrayObject>().dataPointerUnshared(), moduleSegment.base(),
moduleSegment.length());
RootedValue value(cx, ObjectValue(*code));
if (!JS_DefineProperty(cx, result, "code", value, JSPROP_ENUMERATE)) {