130
130
import com .oracle .graal .python .runtime .sequence .storage .SequenceStorage .StorageType ;
131
131
import com .oracle .graal .python .runtime .sequence .storage .SequenceStorageFactory ;
132
132
import com .oracle .graal .python .runtime .sequence .storage .SequenceStoreException ;
133
- import com .oracle .graal .python .runtime .sequence .storage .native2 .ArrowSequenceStorage ;
134
- import com .oracle .graal .python .runtime .sequence .storage .native2 .IntArrowSequenceStorage ;
135
- import com .oracle .graal .python .runtime .sequence .storage .native2 .NativeBuffer ;
133
+ import com .oracle .graal .python .runtime .sequence .storage .NativePrimitiveSequenceStorage ;
134
+ import com .oracle .graal .python .runtime .sequence .storage .NativeIntSequenceStorage ;
136
135
import com .oracle .graal .python .util .BiFunction ;
137
136
import com .oracle .graal .python .util .OverflowException ;
138
137
import com .oracle .graal .python .util .PythonUtils ;
@@ -616,7 +615,7 @@ protected static Object doObject(ObjectSequenceStorage storage, int idx) {
616
615
}
617
616
618
617
@ Specialization
619
- protected static int doArrowInt ( IntArrowSequenceStorage storage , int idx ) {
618
+ protected static int doNativeInt ( NativeIntSequenceStorage storage , int idx ) {
620
619
return storage .getIntItemNormalized (idx );
621
620
}
622
621
@@ -786,10 +785,11 @@ protected static SequenceStorage doMroSequenceStorage(MroSequenceStorage storage
786
785
}
787
786
788
787
@ Specialization
789
- protected static SequenceStorage doArrowInt ( IntArrowSequenceStorage storage , int start , int stop , int step , int length ,
788
+ protected static SequenceStorage doNativeInt ( NativeIntSequenceStorage storage , int start , int stop , int step , int length ,
790
789
@ Bind ("this" ) Node node ) {
791
- var newBuffer = doNativeSliceInBound (node , start , step , length , storage );
792
- return new IntArrowSequenceStorage (newBuffer , length );
790
+ var valueBufferAddr = doNativePrimitiveSliceInBound (node , start , step , length , storage );
791
+ long sizeInBytes = length * storage .getItemSize ();
792
+ return PythonContext .get (node ).nativeBufferContext .wrapToIntStorage (valueBufferAddr , sizeInBytes , length );
793
793
}
794
794
795
795
@ Specialization
@@ -814,26 +814,25 @@ protected static SequenceStorage doNativeObject(NativeObjectSequenceStorage stor
814
814
return new ObjectSequenceStorage (newArray );
815
815
}
816
816
817
- private static NativeBuffer doNativeSliceInBound (Node node , int start , int step , int sliceLength , ArrowSequenceStorage storage ) {
818
- long typeWidth = storage .getTypeWidth ();
819
- var context = PythonContext .get (node );
820
- var unsafe = context .getUnsafe ();
821
- long sizeInBytes = sliceLength * typeWidth ;
822
- var destNativeBuffer = context .nativeBufferContext .createNativeBuffer (sizeInBytes );
817
+ private static long doNativePrimitiveSliceInBound (Node node , int start , int step , int sliceLength , NativePrimitiveSequenceStorage storage ) {
818
+ long itemSize = storage .getItemSize ();
819
+ var nativeContext = PythonContext .get (node ).nativeBufferContext ;
820
+ long sizeInBytes = sliceLength * itemSize ;
821
+ long toAddr = nativeContext .allocateNativeMemory (sizeInBytes );
823
822
824
823
if (step == 1 ) {
825
- var startAddress = storage .getNativeBuffer (). getMemoryAddress () + (start * typeWidth );
826
- unsafe .copyMemory (startAddress , destNativeBuffer . getMemoryAddress () , sizeInBytes );
827
- return destNativeBuffer ;
824
+ var startAddress = storage .getValueBufferAddr () + (start * itemSize );
825
+ nativeContext .copyMemory (startAddress , toAddr , sizeInBytes );
826
+ return toAddr ;
828
827
}
829
828
830
- var stepInBytes = step * typeWidth ;
831
- for (long srcAddr = storage .getNativeBuffer (). getMemoryAddress () + (start * typeWidth ), destAddr = destNativeBuffer . getMemoryAddress () ,
832
- j = 0 ; j < sliceLength ; srcAddr += stepInBytes , destAddr += typeWidth , j ++) {
833
- unsafe .copyMemory (srcAddr , destAddr , typeWidth );
829
+ var stepInBytes = step * itemSize ;
830
+ for (long srcAddr = storage .getValueBufferAddr () + (start * itemSize ), destAddr = toAddr ,
831
+ j = 0 ; j < sliceLength ; srcAddr += stepInBytes , destAddr += itemSize , j ++) {
832
+ nativeContext .copyMemory (srcAddr , destAddr , itemSize );
834
833
}
835
834
836
- return destNativeBuffer ;
835
+ return toAddr ;
837
836
}
838
837
839
838
@ NeverDefault
@@ -1223,7 +1222,7 @@ protected static void doInt(@SuppressWarnings("unused") Node inliningTarget, Int
1223
1222
}
1224
1223
1225
1224
@ Specialization
1226
- protected static void doArrowInt (@ SuppressWarnings ("unused" ) Node inliningTarget , IntArrowSequenceStorage storage , int idx , int value ) {
1225
+ protected static void doNativeInt (@ SuppressWarnings ("unused" ) Node inliningTarget , NativeIntSequenceStorage storage , int idx , int value ) {
1227
1226
storage .setIntItemNormalized (idx , value );
1228
1227
}
1229
1228
@@ -1560,19 +1559,19 @@ static void doObjectStorage(ObjectSequenceStorage storage) {
1560
1559
}
1561
1560
1562
1561
@ Specialization
1563
- static void doArrow (Node inliningTarget , ArrowSequenceStorage storage ) {
1562
+ static void doNativePrimitive (Node inliningTarget , NativePrimitiveSequenceStorage storage ) {
1564
1563
var length = storage .length ();
1565
1564
var unsafe = PythonContext .get (inliningTarget ).getUnsafe ();
1566
- long typeWidth = storage .getTypeWidth ();
1567
- long startAddress = storage .getNativeBuffer (). getMemoryAddress ();
1568
- long endAddress = startAddress + ((length - 1 ) * typeWidth );
1569
- byte [] tempBuffer = new byte [(int ) typeWidth ];
1565
+ long itemSize = storage .getItemSize ();
1566
+ long startAddress = storage .getValueBufferAddr ();
1567
+ long endAddress = startAddress + ((length - 1 ) * itemSize );
1568
+ byte [] tempBuffer = new byte [(int ) itemSize ];
1570
1569
while (startAddress < endAddress ) {
1571
- unsafe .copyMemory (null , startAddress , tempBuffer , Unsafe .ARRAY_BYTE_BASE_OFFSET , typeWidth );
1572
- unsafe .copyMemory (endAddress , startAddress , typeWidth );
1573
- unsafe .copyMemory (tempBuffer , Unsafe .ARRAY_BYTE_BASE_OFFSET , null , endAddress , typeWidth );
1574
- startAddress += typeWidth ;
1575
- endAddress -= typeWidth ;
1570
+ unsafe .copyMemory (null , startAddress , tempBuffer , Unsafe .ARRAY_BYTE_BASE_OFFSET , itemSize );
1571
+ unsafe .copyMemory (endAddress , startAddress , itemSize );
1572
+ unsafe .copyMemory (tempBuffer , Unsafe .ARRAY_BYTE_BASE_OFFSET , null , endAddress , itemSize );
1573
+ startAddress += itemSize ;
1574
+ endAddress -= itemSize ;
1576
1575
}
1577
1576
}
1578
1577
@@ -3145,15 +3144,14 @@ static void doObject(ObjectSequenceStorage storage, int cap) {
3145
3144
}
3146
3145
3147
3146
@ Specialization
3148
- static void doArrow (Node inliningTarget , ArrowSequenceStorage storage , int cap ) {
3147
+ static void doNativePrimitive (Node inliningTarget , NativePrimitiveSequenceStorage storage , int cap ) {
3149
3148
if (CompilerDirectives .injectBranchProbability (CompilerDirectives .UNLIKELY_PROBABILITY , cap > storage .getCapacity ())) {
3150
- var context = getContext (inliningTarget );
3151
- long newCapacityInBytes = storage .getTypeWidth () * cap ;
3152
- var oldNativeBuffer = storage .getNativeBuffer ();
3153
- var newNativeBuffer = context .nativeBufferContext .createNativeBuffer (newCapacityInBytes );
3154
- context .getUnsafe ().copyMemory (oldNativeBuffer .getMemoryAddress (), newNativeBuffer .getMemoryAddress (), oldNativeBuffer .getCapacityInBytes ());
3155
- storage .setCapacity (cap );
3156
- storage .setNativeBuffer (newNativeBuffer );
3149
+ var nativeContext = getContext (inliningTarget ).nativeBufferContext ;
3150
+ long newCapacityInBytes = storage .getItemSize () * cap ;
3151
+ var oldAddr = storage .getValueBufferAddr ();
3152
+ var newAddr = nativeContext .allocateNativeMemory (newCapacityInBytes );
3153
+ nativeContext .copyMemory (oldAddr , newAddr , storage .getCapacityInBytes ());
3154
+ nativeContext .setNewValueAddrToStorage (storage , newAddr , newCapacityInBytes );
3157
3155
}
3158
3156
}
3159
3157
@@ -3298,9 +3296,13 @@ static SequenceStorage doMro(MroSequenceStorage storage) {
3298
3296
}
3299
3297
3300
3298
@ Specialization
3301
- static SequenceStorage doArrowInt (Node inliningTarget , IntArrowSequenceStorage storage ) {
3302
- var copiedBuffer = copyNativeBuffer (inliningTarget , storage .getNativeBuffer ());
3303
- return new IntArrowSequenceStorage (copiedBuffer , storage .length ());
3299
+ static SequenceStorage doNativeInt (Node inliningTarget , NativeIntSequenceStorage storage ) {
3300
+ var nativeContext = PythonContext .get (inliningTarget ).getContext ().nativeBufferContext ;
3301
+ var capacityInBytes = storage .getCapacityInBytes ();
3302
+ var toAddr = nativeContext .allocateNativeMemory (capacityInBytes );
3303
+ nativeContext .copyMemory (storage .getValueBufferAddr (), toAddr , capacityInBytes );
3304
+
3305
+ return nativeContext .wrapToIntStorage (toAddr , capacityInBytes , storage .length ());
3304
3306
}
3305
3307
3306
3308
@ Specialization
@@ -3322,16 +3324,6 @@ static SequenceStorage doNativeObjects(NativeObjectSequenceStorage s,
3322
3324
}
3323
3325
return new ObjectSequenceStorage (objects );
3324
3326
}
3325
-
3326
- private static NativeBuffer copyNativeBuffer (Node inliningTarget , NativeBuffer buffer ) {
3327
- var context = PythonContext .get (inliningTarget );
3328
- var unsafe = context .getUnsafe ();
3329
- var newBuffer = context .nativeBufferContext .createNativeBuffer (buffer .getCapacityInBytes ());
3330
-
3331
- unsafe .copyMemory (buffer .getMemoryAddress (), newBuffer .getMemoryAddress (), buffer .getCapacityInBytes ());
3332
-
3333
- return newBuffer ;
3334
- }
3335
3327
}
3336
3328
3337
3329
@ GenerateUncached
@@ -3422,7 +3414,7 @@ static void doNative(NativeSequenceStorage s, int len,
3422
3414
}
3423
3415
3424
3416
@ Specialization
3425
- static void doArrow ( ArrowSequenceStorage s , int len ) {
3417
+ static void doNativePrimitive ( NativePrimitiveSequenceStorage s , int len ) {
3426
3418
s .setNewLength (len );
3427
3419
}
3428
3420
}
@@ -3957,17 +3949,17 @@ static SequenceStorage doArrayBasedStorage(Node inliningTarget, ArrayBasedSequen
3957
3949
3958
3950
// TODO introduce something similar to InsertItemArrayBasedStorageNode
3959
3951
@ Specialization
3960
- static SequenceStorage doArrowInt (Node inliningTarget , IntArrowSequenceStorage storage , int index , int value ,
3952
+ static SequenceStorage doNativeInt (Node inliningTarget , NativeIntSequenceStorage storage , int index , int value ,
3961
3953
@ Exclusive @ Cached EnsureCapacityNode ensureCapacity ) {
3962
3954
int length = storage .length ();
3963
3955
var context = PythonContext .get (inliningTarget );
3964
3956
var unsafe = context .getUnsafe ();
3965
- long typeWidth = storage .getTypeWidth ();
3957
+ long itemSize = storage .getItemSize ();
3966
3958
ensureCapacity .execute (inliningTarget , storage , length + 1 );
3967
3959
// shifting tail to the right by one slot
3968
- long startAddr = storage .getNativeBuffer (). getMemoryAddress () + (index * typeWidth );
3969
- long endAddr = startAddr + typeWidth ;
3970
- long sizeInBytes = (length - index ) * typeWidth ;
3960
+ long startAddr = storage .getValueBufferAddr () + (index * itemSize );
3961
+ long endAddr = startAddr + itemSize ;
3962
+ long sizeInBytes = (length - index ) * itemSize ;
3971
3963
unsafe .copyMemory (startAddr , endAddr , sizeInBytes );
3972
3964
3973
3965
storage .setIntItemNormalized (index , value );
0 commit comments