Skip to content

Commit

Permalink
Distinguish fixed and auto length TypedArrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamstolis committed Jun 13, 2024
1 parent 69ec8a2 commit 346f9be
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public abstract static class GetBufferElementNode extends JavaScriptBaseNode {
static Object doHeapArrayBuffer(JSArrayBufferObject.Heap buffer, int bufferIndex, boolean littleEndian, TypedArrayFactory factory) {
assert !JSArrayBuffer.isJSInteropArrayBuffer(buffer) && !JSArrayBuffer.isJSDirectOrSharedArrayBuffer(buffer) : buffer;
CompilerAsserts.partialEvaluationConstant(factory);
TypedArray strategy = factory.createArrayType(false, true, false);
TypedArray strategy = factory.createArrayType(false, true, false, false);
CompilerAsserts.partialEvaluationConstant(strategy);
return strategy.getBufferElement(buffer, bufferIndex, littleEndian, null);
}
Expand All @@ -280,7 +280,7 @@ static Object doHeapArrayBuffer(JSArrayBufferObject.Heap buffer, int bufferIndex
static Object doDirectOrSharedArrayBuffer(JSArrayBufferObject.DirectBase buffer, int bufferIndex, boolean littleEndian, TypedArrayFactory factory) {
assert !JSArrayBuffer.isJSInteropArrayBuffer(buffer) && JSArrayBuffer.isJSDirectOrSharedArrayBuffer(buffer) : buffer;
CompilerAsserts.partialEvaluationConstant(factory);
TypedArray strategy = factory.createArrayType(true, true, false);
TypedArray strategy = factory.createArrayType(true, true, false, false);
CompilerAsserts.partialEvaluationConstant(strategy);
return strategy.getBufferElement(buffer, bufferIndex, littleEndian, null);
}
Expand All @@ -290,7 +290,7 @@ static Object doInteropBuffer(JSArrayBufferObject.Interop buffer, int bufferInde
@CachedLibrary(limit = "InteropLibraryLimit") InteropLibrary interop) {
assert JSArrayBuffer.isJSInteropArrayBuffer(buffer) && !JSArrayBuffer.isJSDirectOrSharedArrayBuffer(buffer) : buffer;
CompilerAsserts.partialEvaluationConstant(factory);
TypedArray strategy = factory.createArrayType(false, true, true);
TypedArray strategy = factory.createArrayType(false, true, false, true);
CompilerAsserts.partialEvaluationConstant(strategy);
return strategy.getBufferElement(buffer, bufferIndex, littleEndian, interop);
}
Expand Down Expand Up @@ -352,7 +352,7 @@ public abstract static class SetBufferElementNode extends JavaScriptBaseNode {
static void doHeapArrayBuffer(JSArrayBufferObject.Heap buffer, int bufferIndex, boolean littleEndian, Object value, TypedArrayFactory factory) {
assert !JSArrayBuffer.isJSInteropArrayBuffer(buffer) && !JSArrayBuffer.isJSDirectOrSharedArrayBuffer(buffer) : buffer;
CompilerAsserts.partialEvaluationConstant(factory);
TypedArray strategy = factory.createArrayType(false, true, false);
TypedArray strategy = factory.createArrayType(false, true, false, false);
CompilerAsserts.partialEvaluationConstant(strategy);
strategy.setBufferElement(buffer, bufferIndex, littleEndian, value, null);
}
Expand All @@ -361,7 +361,7 @@ static void doHeapArrayBuffer(JSArrayBufferObject.Heap buffer, int bufferIndex,
static void doDirectOrSharedArrayBuffer(JSArrayBufferObject.DirectBase buffer, int bufferIndex, boolean littleEndian, Object value, TypedArrayFactory factory) {
assert !JSArrayBuffer.isJSInteropArrayBuffer(buffer) && JSArrayBuffer.isJSDirectOrSharedArrayBuffer(buffer) : buffer;
CompilerAsserts.partialEvaluationConstant(factory);
TypedArray strategy = factory.createArrayType(true, true, false);
TypedArray strategy = factory.createArrayType(true, true, false, false);
CompilerAsserts.partialEvaluationConstant(strategy);
strategy.setBufferElement(buffer, bufferIndex, littleEndian, value, null);
}
Expand All @@ -371,7 +371,7 @@ static void doInteropBuffer(JSArrayBufferObject.Interop buffer, int bufferIndex,
@CachedLibrary(limit = "InteropLibraryLimit") InteropLibrary interop) {
assert JSArrayBuffer.isJSInteropArrayBuffer(buffer) && !JSArrayBuffer.isJSDirectOrSharedArrayBuffer(buffer) : buffer;
CompilerAsserts.partialEvaluationConstant(factory);
TypedArray strategy = factory.createArrayType(false, true, true);
TypedArray strategy = factory.createArrayType(false, true, false, true);
CompilerAsserts.partialEvaluationConstant(strategy);
strategy.setBufferElement(buffer, bufferIndex, littleEndian, value, interop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private JSDynamicObject doArrayBufferImpl(JSArrayBufferObject arrayBuffer, Objec
}

assert byteOffset <= Integer.MAX_VALUE && length <= Integer.MAX_VALUE;
TypedArray typedArray = factory.createArrayType(direct, byteOffset != 0, isInteropBuffer);
TypedArray typedArray = factory.createArrayType(direct, byteOffset != 0, length != JSArrayBufferViewBase.AUTO_LENGTH, isInteropBuffer);
return createTypedArray(arrayBuffer, typedArray, (int) byteOffset, (int) length, newTarget);
}

Expand Down Expand Up @@ -282,7 +282,7 @@ protected JSDynamicObject doTypedArray(JSDynamicObject newTarget, JSTypedArrayOb
throw Errors.createTypeErrorCannotMixBigIntWithOtherTypes(this);
}

TypedArray typedArray = factory.createArrayType(getContext().isOptionDirectByteBuffer(), false);
TypedArray typedArray = factory.createArrayType(getContext().isOptionDirectByteBuffer(), false, true);
JSDynamicObject result = createTypedArray(arrayBuffer, typedArray, 0, (int) length, newTarget);

assert typedArray == JSArrayBufferView.typedArrayGetArrayType(result);
Expand Down Expand Up @@ -375,7 +375,7 @@ protected JSDynamicObject doObject(JSDynamicObject newTarget, JSObject object, @
SimpleArrayList<Object> values = iterableToListNode.execute(getIteratorFromMethodNode.execute(node, object, usingIterator));
int len = values.size();
JSArrayBufferObject arrayBuffer = createTypedArrayBuffer(len);
TypedArray typedArray = factory.createArrayType(getContext().isOptionDirectByteBuffer(), false);
TypedArray typedArray = factory.createArrayType(getContext().isOptionDirectByteBuffer(), false, true);
JSDynamicObject obj = integerIndexedObjectCreate(arrayBuffer, typedArray, 0, len, proto);
for (int k = 0; k < len; k++) {
Object kValue = values.get(k);
Expand All @@ -388,7 +388,7 @@ protected JSDynamicObject doObject(JSDynamicObject newTarget, JSObject object, @
long len = getLengthNode.executeLong(object);
JSArrayBufferObject arrayBuffer = createTypedArrayBuffer(len);
assert len <= Integer.MAX_VALUE;
TypedArray typedArray = factory.createArrayType(getContext().isOptionDirectByteBuffer(), false);
TypedArray typedArray = factory.createArrayType(getContext().isOptionDirectByteBuffer(), false, true);
JSDynamicObject obj = integerIndexedObjectCreate(arrayBuffer, typedArray, 0, (int) len, proto);
for (int k = 0; k < len; k++) {
Object kValue = readNode.executeWithTargetAndIndex(object, k);
Expand Down Expand Up @@ -482,7 +482,7 @@ private JSArrayBufferObject createTypedArrayBuffer(long length) {
*/
private JSDynamicObject createTypedArrayWithLength(long length, JSDynamicObject newTarget) {
JSArrayBufferObject arrayBuffer = createTypedArrayBuffer(length);
TypedArray typedArray = factory.createArrayType(getContext().isOptionDirectByteBuffer(), false);
TypedArray typedArray = factory.createArrayType(getContext().isOptionDirectByteBuffer(), false, true);
return createTypedArray(arrayBuffer, typedArray, 0, (int) length, newTarget);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ private void setArrayBufferView(JSTypedArrayObject targetView, JSTypedArrayObjec
sourceBuffer = cloneArrayBuffer(sourceBuffer, sourceArray, srcByteLength, srcByteOffset);
if (sourceArray.isInterop()) {
// cloned buffer is not an interop buffer anymore
sourceArray = sourceArray.getFactory().createArrayType(getContext().isOptionDirectByteBuffer(), false);
sourceArray = sourceArray.getFactory().createArrayType(getContext().isOptionDirectByteBuffer(), false, true);
}
srcByteIndex = 0;
}
Expand Down Expand Up @@ -693,8 +693,8 @@ private JSArrayBufferObject cloneArrayBuffer(JSArrayBufferObject sourceBuffer, T
private JSArrayBufferObject cloneInteropArrayBuffer(JSArrayBufferObject sourceBuffer, int srcByteLength, int srcByteOffset, InteropLibrary interop) {
assert JSArrayBuffer.isJSInteropArrayBuffer(sourceBuffer);
boolean direct = getContext().isOptionDirectByteBuffer();
TypedArray sourceType = TypedArrayFactory.Int8Array.createArrayType(false, false, true);
TypedArray clonedType = TypedArrayFactory.Int8Array.createArrayType(direct, false);
TypedArray sourceType = TypedArrayFactory.Int8Array.createArrayType(false, false, true, true);
TypedArray clonedType = TypedArrayFactory.Int8Array.createArrayType(direct, false, true);
JSArrayBufferObject clonedArrayBuffer = direct
? JSArrayBuffer.createDirectArrayBuffer(getContext(), getRealm(), srcByteLength)
: JSArrayBuffer.createArrayBuffer(getContext(), getRealm(), srcByteLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private Object exportBuffer(JSArrayBufferObject arrayBuffer, int offset, int len
// Wrap ArrayBuffer into Uint8Array - to allow reading its bytes on WASM side
boolean interop = JSArrayBuffer.isJSInteropArrayBuffer(arrayBuffer);
boolean direct = JSArrayBuffer.isJSDirectArrayBuffer(arrayBuffer);
TypedArray arrayType = TypedArrayFactory.Uint8Array.createArrayType(direct, (offset != 0), interop);
TypedArray arrayType = TypedArrayFactory.Uint8Array.createArrayType(direct, (offset != 0), true, interop);
return JSArrayBufferView.createArrayBufferView(context, realm, buffer, arrayType, offset, length);
}

Expand Down
Loading

0 comments on commit 346f9be

Please sign in to comment.