1// Copyright 2019 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5@abstract 6@generateCppClass 7extern class FixedArrayBase extends HeapObject { 8 // length of the array. 9 const length: Smi; 10} 11 12@generateBodyDescriptor 13@generateCppClass 14extern class FixedArray extends FixedArrayBase { 15 objects[length]: Object; 16} 17 18type EmptyFixedArray extends FixedArray; 19 20@generateCppClass 21extern class FixedDoubleArray extends FixedArrayBase { 22 floats[length]: float64_or_hole; 23} 24 25@generateBodyDescriptor 26@generateCppClass 27extern class WeakFixedArray extends HeapObject { 28 const length: Smi; 29 objects[length]: MaybeObject; 30} 31 32@generateCppClass 33extern class ByteArray extends FixedArrayBase { 34 bytes[length]: uint8; 35} 36 37@hasSameInstanceTypeAsParent 38@generateCppClass 39@doNotGenerateCast 40extern class ArrayList extends FixedArray { 41} 42 43@hasSameInstanceTypeAsParent 44@generateCppClass 45@doNotGenerateCast 46extern class TemplateList extends FixedArray { 47} 48 49@generateBodyDescriptor 50@generateCppClass 51extern class WeakArrayList extends HeapObject { 52 const capacity: Smi; 53 length: Smi; 54 objects[capacity]: MaybeObject; 55} 56 57extern operator '.length_intptr' macro LoadAndUntagFixedArrayBaseLength( 58 FixedArrayBase): intptr; 59 60extern operator '.objects[]' macro LoadFixedArrayElement( 61 FixedArray, intptr): Object; 62extern operator '.objects[]' macro LoadFixedArrayElement( 63 FixedArray, Smi): Object; 64extern operator '.objects[]' macro LoadFixedArrayElement( 65 FixedArray, constexpr int31): Object; 66extern operator '.objects[]=' macro StoreFixedArrayElement( 67 FixedArray, intptr, Smi): void; 68extern operator '.objects[]=' macro StoreFixedArrayElement( 69 FixedArray, Smi, Smi): void; 70extern operator '.objects[]=' macro StoreFixedArrayElement( 71 FixedArray, intptr, HeapObject): void; 72extern operator '.objects[]=' macro StoreFixedArrayElement( 73 FixedArray, intptr, Object): void; 74extern operator '.objects[]=' macro StoreFixedArrayElement( 75 FixedArray, constexpr int31, Smi): void; 76extern operator '.objects[]=' macro StoreFixedArrayElement( 77 FixedArray, constexpr int31, HeapObject): void; 78extern operator '.objects[]=' macro StoreFixedArrayElement( 79 FixedArray, Smi, Object): void; 80extern macro StoreFixedArrayElement( 81 FixedArray, Smi, Object, constexpr WriteBarrierMode): void; 82extern macro StoreFixedArrayElement( 83 FixedArray, Smi, Smi, constexpr WriteBarrierMode): void; 84extern macro StoreFixedArrayElement( 85 FixedArray, constexpr int31, Object, constexpr WriteBarrierMode): void; 86extern macro StoreFixedArrayElement( 87 FixedArray, constexpr int31, Smi, constexpr WriteBarrierMode): void; 88extern macro StoreFixedArrayElement( 89 FixedArray, intptr, Object, constexpr WriteBarrierMode): void; 90extern macro StoreFixedArrayElement( 91 FixedArray, intptr, Smi, constexpr WriteBarrierMode): void; 92extern operator '.floats[]=' macro StoreFixedDoubleArrayElement( 93 FixedDoubleArray, intptr, float64): void; 94extern operator '.floats[]=' macro StoreFixedDoubleArrayElement( 95 FixedDoubleArray, Smi, float64): void; 96extern operator '.floats[]' macro LoadFixedDoubleArrayElement( 97 FixedDoubleArray, intptr): float64; 98operator '[]=' macro StoreFixedDoubleArrayDirect( 99 a: FixedDoubleArray, i: Smi, v: Number) { 100 a.floats[i] = Convert<float64_or_hole>(Convert<float64>(v)); 101} 102operator '[]=' macro StoreFixedArrayDirect(a: FixedArray, i: Smi, v: Object) { 103 a.objects[i] = v; 104} 105 106extern macro AllocateFixedArray( 107 constexpr ElementsKind, intptr, constexpr AllocationFlag): FixedArrayBase; 108 109extern macro AllocateZeroedFixedArray(intptr): FixedArray; 110extern macro AllocateZeroedFixedDoubleArray(intptr): FixedDoubleArray; 111extern macro CalculateNewElementsCapacity(Smi): Smi; 112extern macro CalculateNewElementsCapacity(intptr): intptr; 113 114extern macro AllocateFixedArrayWithHoles( 115 intptr, constexpr AllocationFlag): FixedArray; 116extern macro AllocateFixedDoubleArrayWithHoles( 117 intptr, constexpr AllocationFlag): FixedDoubleArray; 118extern macro CopyFixedArrayElements( 119 constexpr ElementsKind, FixedArray, constexpr ElementsKind, FixedArray, 120 intptr, intptr): void; 121extern macro CopyFixedArrayElements( 122 constexpr ElementsKind, FixedArray, constexpr ElementsKind, FixedArray, 123 intptr, intptr, intptr): void; 124 125macro ExtractFixedArray( 126 source: FixedArray, first: intptr, count: intptr, 127 capacity: intptr): FixedArray { 128 // TODO(tebbi): This should be optimized to use memcpy for initialization. 129 return NewFixedArray( 130 capacity, 131 IteratorSequence<Object>( 132 (&source.objects).Iterator(first, first + count), 133 ConstantIterator(TheHole))); 134} 135macro ExtractFixedDoubleArray( 136 source: FixedDoubleArray, first: intptr, count: intptr, 137 capacity: intptr): FixedDoubleArray|EmptyFixedArray { 138 // TODO(tebbi): This should be optimized to use memcpy for initialization. 139 return NewFixedDoubleArray( 140 capacity, 141 IteratorSequence<float64_or_hole>( 142 (&source.floats).Iterator(first, first + count), 143 ConstantIterator(kDoubleHole))); 144} 145 146namespace runtime { 147extern runtime FatalProcessOutOfMemoryInvalidArrayLength(NoContext): never; 148} 149 150macro NewFixedArray<Iterator: type>(length: intptr, it: Iterator): FixedArray { 151 if (length == 0) return kEmptyFixedArray; 152 if (length > kFixedArrayMaxLength) deferred { 153 runtime::FatalProcessOutOfMemoryInvalidArrayLength(kNoContext); 154 } 155 return new 156 FixedArray{map: kFixedArrayMap, length: Convert<Smi>(length), objects: ...it}; 157} 158 159macro NewFixedDoubleArray<Iterator: type>( 160 length: intptr, it: Iterator): FixedDoubleArray|EmptyFixedArray { 161 if (length == 0) return kEmptyFixedArray; 162 if (length > kFixedDoubleArrayMaxLength) deferred { 163 runtime::FatalProcessOutOfMemoryInvalidArrayLength(kNoContext); 164 } 165 return new FixedDoubleArray{ 166 map: kFixedDoubleArrayMap, 167 length: Convert<Smi>(length), 168 floats: ...it 169 }; 170} 171