Skip to content

Commit ce1a9ab

Browse files
marjakhV8 LUCI CQ
authored and
V8 LUCI CQ
committed
[rab/gsab] Enable code paths needed for BigInt TypedArrays
Bug: v8:11111 Change-Id: Ib3ae55349024ebeab9ceaf9472a6de2b4d86ce55 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3056975 Reviewed-by: Jakob Kummerow <[email protected]> Commit-Queue: Marja Hölttä <[email protected]> Cr-Commit-Position: refs/heads/master@{#75993}
1 parent 2442ea5 commit ce1a9ab

6 files changed

+46
-80
lines changed

src/objects/js-objects-inl.h

+5
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,11 @@ DEF_GETTER(JSObject, HasTypedArrayElements, bool) {
622622
return map(cage_base).has_typed_array_elements();
623623
}
624624

625+
DEF_GETTER(JSObject, HasTypedArrayOrRabGsabTypedArrayElements, bool) {
626+
DCHECK(!elements(cage_base).is_null());
627+
return map(cage_base).has_typed_array_or_rab_gsab_typed_array_elements();
628+
}
629+
625630
#define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype) \
626631
DEF_GETTER(JSObject, HasFixed##Type##Elements, bool) { \
627632
return map(cage_base).elements_kind() == TYPE##_ELEMENTS; \

src/objects/js-objects.h

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ class JSObject : public TorqueGeneratedJSObject<JSObject, JSReceiver> {
364364
DECL_GETTER(HasNonextensibleElements, bool)
365365

366366
DECL_GETTER(HasTypedArrayElements, bool)
367+
DECL_GETTER(HasTypedArrayOrRabGsabTypedArrayElements, bool)
367368

368369
DECL_GETTER(HasFixedUint8ClampedElements, bool)
369370
DECL_GETTER(HasFixedArrayElements, bool)

src/objects/objects.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -2770,12 +2770,11 @@ Maybe<bool> Object::SetDataProperty(LookupIterator* it, Handle<Object> value) {
27702770

27712771
Handle<Object> to_assign = value;
27722772
// Convert the incoming value to a number for storing into typed arrays.
2773-
// TODO(v8:11111): Support RAB / GSAB.
27742773
if (it->IsElement() && receiver->IsJSObject(isolate) &&
2775-
JSObject::cast(*receiver).HasTypedArrayElements(isolate)) {
2774+
JSObject::cast(*receiver).HasTypedArrayOrRabGsabTypedArrayElements(
2775+
isolate)) {
27762776
ElementsKind elements_kind = JSObject::cast(*receiver).GetElementsKind();
2777-
if (elements_kind == BIGINT64_ELEMENTS ||
2778-
elements_kind == BIGUINT64_ELEMENTS) {
2777+
if (IsBigIntTypedArrayElementsKind(elements_kind)) {
27792778
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, to_assign,
27802779
BigInt::FromObject(isolate, value),
27812780
Nothing<bool>());

test/mjsunit/typedarray-growablesharedarraybuffer.js

+5-34
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88

99
d8.file.execute('test/mjsunit/typedarray-helpers.js');
1010

11-
class MyUint8Array extends Uint8Array {};
12-
13-
const ctors = [
14-
Uint8Array,
15-
Int8Array,
16-
Uint16Array,
17-
Int16Array,
18-
Int32Array,
19-
Float32Array,
20-
Float64Array,
21-
Uint8ClampedArray,
22-
BigUint64Array,
23-
BigInt64Array,
24-
MyUint8Array
25-
];
26-
2711
function CreateGrowableSharedArrayBuffer(byteLength, maxByteLength) {
2812
return new SharedArrayBuffer(byteLength, {maxByteLength: maxByteLength});
2913
}
@@ -404,17 +388,12 @@ function CreateGrowableSharedArrayBuffer(byteLength, maxByteLength) {
404388
function TestIteration(ta, expected) {
405389
let values = [];
406390
for (const value of ta) {
407-
values.push(value);
391+
values.push(Number(value));
408392
}
409393
assertEquals(expected, values);
410394
}
411395

412396
for (let ctor of ctors) {
413-
if (ctor == BigInt64Array || ctor == BigUint64Array) {
414-
// This test doesn't work for BigInts.
415-
continue;
416-
}
417-
418397
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
419398
// We can use the same GSAB for all the TAs below, since we won't modify it
420399
// after writing the initial values.
@@ -425,7 +404,7 @@ function CreateGrowableSharedArrayBuffer(byteLength, maxByteLength) {
425404
// Write some data into the array.
426405
let ta_write = new ctor(gsab);
427406
for (let i = 0; i < no_elements; ++i) {
428-
ta_write[i] = i % 128;
407+
WriteToTypedArray(ta_write, i, i % 128);
429408
}
430409

431410
// Create various different styles of TypedArrays with the GSAB as the
@@ -468,11 +447,11 @@ function CreateGrowableSharedArrayBuffer(byteLength, maxByteLength) {
468447
// Helpers for iteration tests.
469448
function CreateGsab(buffer_byte_length, ctor) {
470449
const gsab = CreateGrowableSharedArrayBuffer(buffer_byte_length,
471-
2 * buffer_byte_length);
450+
2 * buffer_byte_length);
472451
// Write some data into the array.
473452
let ta_write = new ctor(gsab);
474453
for (let i = 0; i < buffer_byte_length / ctor.BYTES_PER_ELEMENT; ++i) {
475-
ta_write[i] = i % 128;
454+
WriteToTypedArray(ta_write, i, i % 128);
476455
}
477456
return gsab;
478457
}
@@ -482,7 +461,7 @@ function TestIterationAndGrow(ta, expected, gsab, grow_after,
482461
let values = [];
483462
let grown = false;
484463
for (const value of ta) {
485-
values.push(value);
464+
values.push(Number(value));
486465
if (!grown && values.length == grow_after) {
487466
gsab.grow(new_byte_length);
488467
grown = true;
@@ -497,10 +476,6 @@ function TestIterationAndGrow(ta, expected, gsab, grow_after,
497476
const offset = 2;
498477

499478
for (let ctor of ctors) {
500-
if (ctor == BigInt64Array || ctor == BigUint64Array) {
501-
// This test doesn't work for BigInts.
502-
continue;
503-
}
504479
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
505480
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
506481

@@ -555,10 +530,6 @@ function TestIterationAndGrow(ta, expected, gsab, grow_after,
555530

556531
// We need to recreate the gsab between all TA tests, since we grow it.
557532
for (let ctor of ctors) {
558-
if (ctor == BigInt64Array || ctor == BigUint64Array) {
559-
// This test doesn't work for BigInts.
560-
continue;
561-
}
562533
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
563534
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
564535

test/mjsunit/typedarray-helpers.js

+27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
class MyUint8Array extends Uint8Array {};
6+
class MyBigInt64Array extends BigInt64Array {};
7+
8+
const ctors = [
9+
Uint8Array,
10+
Int8Array,
11+
Uint16Array,
12+
Int16Array,
13+
Int32Array,
14+
Float32Array,
15+
Float64Array,
16+
Uint8ClampedArray,
17+
BigUint64Array,
18+
BigInt64Array,
19+
MyUint8Array,
20+
MyBigInt64Array,
21+
];
22+
523
function ReadDataFromBuffer(ab, ctor) {
624
let result = [];
725
const ta = new ctor(ab, 0, ab.byteLength / ctor.BYTES_PER_ELEMENT);
@@ -11,6 +29,15 @@ function ReadDataFromBuffer(ab, ctor) {
1129
return result;
1230
}
1331

32+
function WriteToTypedArray(array, index, value) {
33+
if (array instanceof BigInt64Array ||
34+
array instanceof BigUint64Array) {
35+
array[index] = BigInt(value);
36+
} else {
37+
array[index] = value;
38+
}
39+
}
40+
1441
function FillHelper(ta, n, start, end) {
1542
if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) {
1643
ta.fill(BigInt(n), start, end);

test/mjsunit/typedarray-resizablearraybuffer.js

+5-42
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88

99
d8.file.execute('test/mjsunit/typedarray-helpers.js');
1010

11-
class MyUint8Array extends Uint8Array {};
12-
13-
const ctors = [
14-
Uint8Array,
15-
Int8Array,
16-
Uint16Array,
17-
Int16Array,
18-
Int32Array,
19-
Float32Array,
20-
Float64Array,
21-
Uint8ClampedArray,
22-
BigUint64Array,
23-
BigInt64Array,
24-
MyUint8Array
25-
];
26-
2711
function CreateResizableArrayBuffer(byteLength, maxByteLength) {
2812
return new ArrayBuffer(byteLength, {maxByteLength: maxByteLength});
2913
}
@@ -677,17 +661,12 @@ function CreateResizableArrayBuffer(byteLength, maxByteLength) {
677661
function TestIteration(ta, expected) {
678662
let values = [];
679663
for (const value of ta) {
680-
values.push(value);
664+
values.push(Number(value));
681665
}
682666
assertEquals(expected, values);
683667
}
684668

685669
for (let ctor of ctors) {
686-
if (ctor == BigInt64Array || ctor == BigUint64Array) {
687-
// This test doesn't work for BigInts.
688-
continue;
689-
}
690-
691670
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
692671
// We can use the same RAB for all the TAs below, since we won't modify it
693672
// after writing the initial values.
@@ -698,7 +677,7 @@ function CreateResizableArrayBuffer(byteLength, maxByteLength) {
698677
// Write some data into the array.
699678
let ta_write = new ctor(rab);
700679
for (let i = 0; i < no_elements; ++i) {
701-
ta_write[i] = i % 128;
680+
WriteToTypedArray(ta_write, i, i % 128);
702681
}
703682

704683
// Create various different styles of TypedArrays with the RAB as the
@@ -741,11 +720,11 @@ function CreateResizableArrayBuffer(byteLength, maxByteLength) {
741720
// Helpers for iteration tests.
742721
function CreateRab(buffer_byte_length, ctor) {
743722
const rab = CreateResizableArrayBuffer(buffer_byte_length,
744-
2 * buffer_byte_length);
723+
2 * buffer_byte_length);
745724
// Write some data into the array.
746725
let ta_write = new ctor(rab);
747726
for (let i = 0; i < buffer_byte_length / ctor.BYTES_PER_ELEMENT; ++i) {
748-
ta_write[i] = i % 128;
727+
WriteToTypedArray(ta_write, i, i % 128);
749728
}
750729
return rab;
751730
}
@@ -755,7 +734,7 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
755734
let values = [];
756735
let resized = false;
757736
for (const value of ta) {
758-
values.push(value);
737+
values.push(Number(value));
759738
if (!resized && values.length == resize_after) {
760739
rab.resize(new_byte_length);
761740
resized = true;
@@ -770,10 +749,6 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
770749
const offset = 2;
771750

772751
for (let ctor of ctors) {
773-
if (ctor == BigInt64Array || ctor == BigUint64Array) {
774-
// This test doesn't work for BigInts.
775-
continue;
776-
}
777752
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
778753
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
779754

@@ -828,10 +803,6 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
828803

829804
// We need to recreate the RAB between all TA tests, since we grow it.
830805
for (let ctor of ctors) {
831-
if (ctor == BigInt64Array || ctor == BigUint64Array) {
832-
// This test doesn't work for BigInts.
833-
continue;
834-
}
835806
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
836807
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
837808

@@ -875,10 +846,6 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
875846
const offset = 2;
876847

877848
for (let ctor of ctors) {
878-
if (ctor == BigInt64Array || ctor == BigUint64Array) {
879-
// This test doesn't work for BigInts.
880-
continue;
881-
}
882849
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
883850
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
884851

@@ -935,10 +902,6 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
935902
const offset = 2;
936903

937904
for (let ctor of ctors) {
938-
if (ctor == BigInt64Array || ctor == BigUint64Array) {
939-
// This test doesn't work for BigInts.
940-
continue;
941-
}
942905
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
943906
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
944907

0 commit comments

Comments
 (0)