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