Skip to content

Commit dede01e

Browse files
committedDec 4, 2020
8257622: MemoryAccess methods are missing @ForceInline annotations
Reviewed-by: jvernee, shade
1 parent 1d2d981 commit dede01e

File tree

3 files changed

+325
-0
lines changed

3 files changed

+325
-0
lines changed
 

‎src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAccess.java

+82
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ private static VarHandle unalignedHandle(ValueLayout elementLayout, Class<?> car
9595
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
9696
* @return a byte value read from {@code segment}.
9797
*/
98+
@ForceInline
9899
public static byte getByteAtOffset(MemorySegment segment, long offset) {
99100
Objects.requireNonNull(segment);
100101
return (byte)byte_handle.get(segment, offset);
@@ -107,6 +108,7 @@ public static byte getByteAtOffset(MemorySegment segment, long offset) {
107108
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
108109
* @param value the byte value to be written.
109110
*/
111+
@ForceInline
110112
public static void setByteAtOffset(MemorySegment segment, long offset, byte value) {
111113
Objects.requireNonNull(segment);
112114
byte_handle.set(segment, offset, value);
@@ -123,6 +125,7 @@ public static void setByteAtOffset(MemorySegment segment, long offset, byte valu
123125
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
124126
* @return a char value read from {@code segment}.
125127
*/
128+
@ForceInline
126129
public static char getCharAtOffset(MemorySegment segment, long offset) {
127130
return getCharAtOffset(segment, offset, ByteOrder.nativeOrder());
128131
}
@@ -138,6 +141,7 @@ public static char getCharAtOffset(MemorySegment segment, long offset) {
138141
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
139142
* @param value the char value to be written.
140143
*/
144+
@ForceInline
141145
public static void setCharAtOffset(MemorySegment segment, long offset, char value) {
142146
setCharAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
143147
}
@@ -153,6 +157,7 @@ public static void setCharAtOffset(MemorySegment segment, long offset, char valu
153157
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
154158
* @return a short value read from {@code segment}.
155159
*/
160+
@ForceInline
156161
public static short getShortAtOffset(MemorySegment segment, long offset) {
157162
return getShortAtOffset(segment, offset, ByteOrder.nativeOrder());
158163
}
@@ -168,6 +173,7 @@ public static short getShortAtOffset(MemorySegment segment, long offset) {
168173
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
169174
* @param value the short value to be written.
170175
*/
176+
@ForceInline
171177
public static void setShortAtOffset(MemorySegment segment, long offset, short value) {
172178
setShortAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
173179
}
@@ -183,6 +189,7 @@ public static void setShortAtOffset(MemorySegment segment, long offset, short va
183189
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
184190
* @return an int value read from {@code segment}.
185191
*/
192+
@ForceInline
186193
public static int getIntAtOffset(MemorySegment segment, long offset) {
187194
return getIntAtOffset(segment, offset, ByteOrder.nativeOrder());
188195
}
@@ -198,6 +205,7 @@ public static int getIntAtOffset(MemorySegment segment, long offset) {
198205
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
199206
* @param value the int value to be written.
200207
*/
208+
@ForceInline
201209
public static void setIntAtOffset(MemorySegment segment, long offset, int value) {
202210
setIntAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
203211
}
@@ -213,6 +221,7 @@ public static void setIntAtOffset(MemorySegment segment, long offset, int value)
213221
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
214222
* @return a float value read from {@code segment}.
215223
*/
224+
@ForceInline
216225
public static float getFloatAtOffset(MemorySegment segment, long offset) {
217226
return getFloatAtOffset(segment, offset, ByteOrder.nativeOrder());
218227
}
@@ -228,6 +237,7 @@ public static float getFloatAtOffset(MemorySegment segment, long offset) {
228237
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
229238
* @param value the float value to be written.
230239
*/
240+
@ForceInline
231241
public static void setFloatAtOffset(MemorySegment segment, long offset, float value) {
232242
setFloatAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
233243
}
@@ -243,6 +253,7 @@ public static void setFloatAtOffset(MemorySegment segment, long offset, float va
243253
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
244254
* @return a long value read from {@code segment}.
245255
*/
256+
@ForceInline
246257
public static long getLongAtOffset(MemorySegment segment, long offset) {
247258
return getLongAtOffset(segment, offset, ByteOrder.nativeOrder());
248259
}
@@ -258,6 +269,7 @@ public static long getLongAtOffset(MemorySegment segment, long offset) {
258269
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
259270
* @param value the long value to be written.
260271
*/
272+
@ForceInline
261273
public static void setLongAtOffset(MemorySegment segment, long offset, long value) {
262274
setLongAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
263275
}
@@ -273,6 +285,7 @@ public static void setLongAtOffset(MemorySegment segment, long offset, long valu
273285
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
274286
* @return a double value read from {@code segment}.
275287
*/
288+
@ForceInline
276289
public static double getDoubleAtOffset(MemorySegment segment, long offset) {
277290
return getDoubleAtOffset(segment, offset, ByteOrder.nativeOrder());
278291
}
@@ -288,6 +301,7 @@ public static double getDoubleAtOffset(MemorySegment segment, long offset) {
288301
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
289302
* @param value the double value to be written.
290303
*/
304+
@ForceInline
291305
public static void setDoubleAtOffset(MemorySegment segment, long offset, double value) {
292306
setDoubleAtOffset(segment, offset, ByteOrder.nativeOrder(), value);
293307
}
@@ -304,6 +318,7 @@ public static void setDoubleAtOffset(MemorySegment segment, long offset, double
304318
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
305319
* @return a memory address read from {@code segment}.
306320
*/
321+
@ForceInline
307322
public static MemoryAddress getAddressAtOffset(MemorySegment segment, long offset) {
308323
Objects.requireNonNull(segment);
309324
return (MemoryAddress)address_handle.get(segment, offset);
@@ -321,6 +336,7 @@ public static MemoryAddress getAddressAtOffset(MemorySegment segment, long offse
321336
* @param offset offset in bytes (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(offset)}.
322337
* @param value the memory address to be written (expressed as an {@link Addressable} instance).
323338
*/
339+
@ForceInline
324340
public static void setAddressAtOffset(MemorySegment segment, long offset, Addressable value) {
325341
Objects.requireNonNull(segment);
326342
Objects.requireNonNull(value);
@@ -340,6 +356,7 @@ public static void setAddressAtOffset(MemorySegment segment, long offset, Addres
340356
* @param order the specified byte order.
341357
* @return a char value read from {@code segment}.
342358
*/
359+
@ForceInline
343360
public static char getCharAtOffset(MemorySegment segment, long offset, ByteOrder order) {
344361
Objects.requireNonNull(segment);
345362
Objects.requireNonNull(order);
@@ -359,6 +376,7 @@ public static char getCharAtOffset(MemorySegment segment, long offset, ByteOrder
359376
* @param order the specified byte order.
360377
* @param value the char value to be written.
361378
*/
379+
@ForceInline
362380
public static void setCharAtOffset(MemorySegment segment, long offset, ByteOrder order, char value) {
363381
Objects.requireNonNull(segment);
364382
Objects.requireNonNull(order);
@@ -378,6 +396,7 @@ public static void setCharAtOffset(MemorySegment segment, long offset, ByteOrder
378396
* @param order the specified byte order.
379397
* @return a short value read from {@code segment}.
380398
*/
399+
@ForceInline
381400
public static short getShortAtOffset(MemorySegment segment, long offset, ByteOrder order) {
382401
Objects.requireNonNull(segment);
383402
Objects.requireNonNull(order);
@@ -397,6 +416,7 @@ public static short getShortAtOffset(MemorySegment segment, long offset, ByteOrd
397416
* @param order the specified byte order.
398417
* @param value the short value to be written.
399418
*/
419+
@ForceInline
400420
public static void setShortAtOffset(MemorySegment segment, long offset, ByteOrder order, short value) {
401421
Objects.requireNonNull(segment);
402422
Objects.requireNonNull(order);
@@ -416,6 +436,7 @@ public static void setShortAtOffset(MemorySegment segment, long offset, ByteOrde
416436
* @param order the specified byte order.
417437
* @return an int value read from {@code segment}.
418438
*/
439+
@ForceInline
419440
public static int getIntAtOffset(MemorySegment segment, long offset, ByteOrder order) {
420441
Objects.requireNonNull(segment);
421442
Objects.requireNonNull(order);
@@ -435,6 +456,7 @@ public static int getIntAtOffset(MemorySegment segment, long offset, ByteOrder o
435456
* @param order the specified byte order.
436457
* @param value the int value to be written.
437458
*/
459+
@ForceInline
438460
public static void setIntAtOffset(MemorySegment segment, long offset, ByteOrder order, int value) {
439461
Objects.requireNonNull(segment);
440462
Objects.requireNonNull(order);
@@ -454,6 +476,7 @@ public static void setIntAtOffset(MemorySegment segment, long offset, ByteOrder
454476
* @param order the specified byte order.
455477
* @return a float value read from {@code segment}.
456478
*/
479+
@ForceInline
457480
public static float getFloatAtOffset(MemorySegment segment, long offset, ByteOrder order) {
458481
Objects.requireNonNull(segment);
459482
Objects.requireNonNull(order);
@@ -473,6 +496,7 @@ public static float getFloatAtOffset(MemorySegment segment, long offset, ByteOrd
473496
* @param order the specified byte order.
474497
* @param value the float value to be written.
475498
*/
499+
@ForceInline
476500
public static void setFloatAtOffset(MemorySegment segment, long offset, ByteOrder order, float value) {
477501
Objects.requireNonNull(segment);
478502
Objects.requireNonNull(order);
@@ -492,6 +516,7 @@ public static void setFloatAtOffset(MemorySegment segment, long offset, ByteOrde
492516
* @param order the specified byte order.
493517
* @return a long value read from {@code segment}.
494518
*/
519+
@ForceInline
495520
public static long getLongAtOffset(MemorySegment segment, long offset, ByteOrder order) {
496521
Objects.requireNonNull(segment);
497522
Objects.requireNonNull(order);
@@ -511,6 +536,7 @@ public static long getLongAtOffset(MemorySegment segment, long offset, ByteOrder
511536
* @param order the specified byte order.
512537
* @param value the long value to be written.
513538
*/
539+
@ForceInline
514540
public static void setLongAtOffset(MemorySegment segment, long offset, ByteOrder order, long value) {
515541
Objects.requireNonNull(segment);
516542
Objects.requireNonNull(order);
@@ -530,6 +556,7 @@ public static void setLongAtOffset(MemorySegment segment, long offset, ByteOrder
530556
* @param order the specified byte order.
531557
* @return a double value read from {@code segment}.
532558
*/
559+
@ForceInline
533560
public static double getDoubleAtOffset(MemorySegment segment, long offset, ByteOrder order) {
534561
Objects.requireNonNull(segment);
535562
Objects.requireNonNull(order);
@@ -549,6 +576,7 @@ public static double getDoubleAtOffset(MemorySegment segment, long offset, ByteO
549576
* @param order the specified byte order.
550577
* @param value the double value to be written.
551578
*/
579+
@ForceInline
552580
public static void setDoubleAtOffset(MemorySegment segment, long offset, ByteOrder order, double value) {
553581
Objects.requireNonNull(segment);
554582
Objects.requireNonNull(order);
@@ -566,6 +594,7 @@ public static void setDoubleAtOffset(MemorySegment segment, long offset, ByteOrd
566594
* @param segment the segment to be dereferenced.
567595
* @return a byte value read from {@code segment}.
568596
*/
597+
@ForceInline
569598
public static byte getByte(MemorySegment segment) {
570599
return getByteAtOffset(segment, 0L);
571600
}
@@ -580,6 +609,7 @@ public static byte getByte(MemorySegment segment) {
580609
* @param segment the segment to be dereferenced.
581610
* @param value the byte value to be written.
582611
*/
612+
@ForceInline
583613
public static void setByte(MemorySegment segment, byte value) {
584614
setByteAtOffset(segment, 0L, value);
585615
}
@@ -594,6 +624,7 @@ public static void setByte(MemorySegment segment, byte value) {
594624
* @param segment the segment to be dereferenced.
595625
* @return a char value read from {@code segment}.
596626
*/
627+
@ForceInline
597628
public static char getChar(MemorySegment segment) {
598629
return getCharAtOffset(segment, 0L);
599630
}
@@ -608,6 +639,7 @@ public static char getChar(MemorySegment segment) {
608639
* @param segment the segment to be dereferenced.
609640
* @param value the char value to be written.
610641
*/
642+
@ForceInline
611643
public static void setChar(MemorySegment segment, char value) {
612644
setCharAtOffset(segment, 0L, value);
613645
}
@@ -622,6 +654,7 @@ public static void setChar(MemorySegment segment, char value) {
622654
* @param segment the segment to be dereferenced.
623655
* @return a short value read from {@code segment}.
624656
*/
657+
@ForceInline
625658
public static short getShort(MemorySegment segment) {
626659
return getShortAtOffset(segment, 0L);
627660
}
@@ -636,6 +669,7 @@ public static short getShort(MemorySegment segment) {
636669
* @param segment the segment to be dereferenced.
637670
* @param value the short value to be written.
638671
*/
672+
@ForceInline
639673
public static void setShort(MemorySegment segment, short value) {
640674
setShortAtOffset(segment, 0L, value);
641675
}
@@ -650,6 +684,7 @@ public static void setShort(MemorySegment segment, short value) {
650684
* @param segment the segment to be dereferenced.
651685
* @return an int value read from {@code segment}.
652686
*/
687+
@ForceInline
653688
public static int getInt(MemorySegment segment) {
654689
return getIntAtOffset(segment, 0L);
655690
}
@@ -664,6 +699,7 @@ public static int getInt(MemorySegment segment) {
664699
* @param segment the segment to be dereferenced.
665700
* @param value the int value to be written.
666701
*/
702+
@ForceInline
667703
public static void setInt(MemorySegment segment, int value) {
668704
setIntAtOffset(segment, 0L, value);
669705
}
@@ -678,6 +714,7 @@ public static void setInt(MemorySegment segment, int value) {
678714
* @param segment the segment to be dereferenced.
679715
* @return a float value read from {@code segment}.
680716
*/
717+
@ForceInline
681718
public static float getFloat(MemorySegment segment) {
682719
return getFloatAtOffset(segment, 0L);
683720
}
@@ -692,6 +729,7 @@ public static float getFloat(MemorySegment segment) {
692729
* @param segment the segment to be dereferenced.
693730
* @param value the float value to be written.
694731
*/
732+
@ForceInline
695733
public static void setFloat(MemorySegment segment, float value) {
696734
setFloatAtOffset(segment, 0L, value);
697735
}
@@ -706,6 +744,7 @@ public static void setFloat(MemorySegment segment, float value) {
706744
* @param segment the segment to be dereferenced.
707745
* @return a long value read from {@code segment}.
708746
*/
747+
@ForceInline
709748
public static long getLong(MemorySegment segment) {
710749
return getLongAtOffset(segment, 0L);
711750
}
@@ -720,6 +759,7 @@ public static long getLong(MemorySegment segment) {
720759
* @param segment the segment to be dereferenced.
721760
* @param value the long value to be written.
722761
*/
762+
@ForceInline
723763
public static void setLong(MemorySegment segment, long value) {
724764
setLongAtOffset(segment, 0L, value);
725765
}
@@ -734,6 +774,7 @@ public static void setLong(MemorySegment segment, long value) {
734774
* @param segment the segment to be dereferenced.
735775
* @return a double value read from {@code segment}.
736776
*/
777+
@ForceInline
737778
public static double getDouble(MemorySegment segment) {
738779
return getDoubleAtOffset(segment, 0L);
739780
}
@@ -748,6 +789,7 @@ public static double getDouble(MemorySegment segment) {
748789
* @param segment the segment to be dereferenced.
749790
* @param value the double value to be written.
750791
*/
792+
@ForceInline
751793
public static void setDouble(MemorySegment segment, double value) {
752794
setDoubleAtOffset(segment, 0L, value);
753795
}
@@ -762,6 +804,7 @@ public static void setDouble(MemorySegment segment, double value) {
762804
* @param segment the segment to be dereferenced.
763805
* @return a memory address read from {@code segment}.
764806
*/
807+
@ForceInline
765808
public static MemoryAddress getAddress(MemorySegment segment) {
766809
return getAddressAtOffset(segment, 0L);
767810
}
@@ -776,6 +819,7 @@ public static MemoryAddress getAddress(MemorySegment segment) {
776819
* @param segment the segment to be dereferenced.
777820
* @param value the memory address to be written (expressed as an {@link Addressable} instance).
778821
*/
822+
@ForceInline
779823
public static void setAddress(MemorySegment segment, Addressable value) {
780824
setAddressAtOffset(segment, 0L, value);
781825
}
@@ -791,6 +835,7 @@ public static void setAddress(MemorySegment segment, Addressable value) {
791835
* @param order the specified byte order.
792836
* @return a char value read from {@code segment}.
793837
*/
838+
@ForceInline
794839
public static char getChar(MemorySegment segment, ByteOrder order) {
795840
return getCharAtOffset(segment, 0L, order);
796841
}
@@ -806,6 +851,7 @@ public static char getChar(MemorySegment segment, ByteOrder order) {
806851
* @param order the specified byte order.
807852
* @param value the char value to be written.
808853
*/
854+
@ForceInline
809855
public static void setChar(MemorySegment segment, ByteOrder order, char value) {
810856
setCharAtOffset(segment, 0L, order, value);
811857
}
@@ -821,6 +867,7 @@ public static void setChar(MemorySegment segment, ByteOrder order, char value) {
821867
* @param order the specified byte order.
822868
* @return a short value read from {@code segment}.
823869
*/
870+
@ForceInline
824871
public static short getShort(MemorySegment segment, ByteOrder order) {
825872
return getShortAtOffset(segment, 0L, order);
826873
}
@@ -836,6 +883,7 @@ public static short getShort(MemorySegment segment, ByteOrder order) {
836883
* @param order the specified byte order.
837884
* @param value the short value to be written.
838885
*/
886+
@ForceInline
839887
public static void setShort(MemorySegment segment, ByteOrder order, short value) {
840888
setShortAtOffset(segment, 0L, order, value);
841889
}
@@ -851,6 +899,7 @@ public static void setShort(MemorySegment segment, ByteOrder order, short value)
851899
* @param order the specified byte order.
852900
* @return an int value read from {@code segment}.
853901
*/
902+
@ForceInline
854903
public static int getInt(MemorySegment segment, ByteOrder order) {
855904
return getIntAtOffset(segment, 0L, order);
856905
}
@@ -866,6 +915,7 @@ public static int getInt(MemorySegment segment, ByteOrder order) {
866915
* @param order the specified byte order.
867916
* @param value the int value to be written.
868917
*/
918+
@ForceInline
869919
public static void setInt(MemorySegment segment, ByteOrder order, int value) {
870920
setIntAtOffset(segment, 0L, order, value);
871921
}
@@ -881,6 +931,7 @@ public static void setInt(MemorySegment segment, ByteOrder order, int value) {
881931
* @param order the specified byte order.
882932
* @return a float value read from {@code segment}.
883933
*/
934+
@ForceInline
884935
public static float getFloat(MemorySegment segment, ByteOrder order) {
885936
return getFloatAtOffset(segment, 0L, order);
886937
}
@@ -896,6 +947,7 @@ public static float getFloat(MemorySegment segment, ByteOrder order) {
896947
* @param order the specified byte order.
897948
* @param value the float value to be written.
898949
*/
950+
@ForceInline
899951
public static void setFloat(MemorySegment segment, ByteOrder order, float value) {
900952
setFloatAtOffset(segment, 0L, order, value);
901953
}
@@ -911,6 +963,7 @@ public static void setFloat(MemorySegment segment, ByteOrder order, float value)
911963
* @param order the specified byte order.
912964
* @return a long value read from {@code segment}.
913965
*/
966+
@ForceInline
914967
public static long getLong(MemorySegment segment, ByteOrder order) {
915968
return getLongAtOffset(segment, 0L, order);
916969
}
@@ -926,6 +979,7 @@ public static long getLong(MemorySegment segment, ByteOrder order) {
926979
* @param order the specified byte order.
927980
* @param value the long value to be written.
928981
*/
982+
@ForceInline
929983
public static void setLong(MemorySegment segment, ByteOrder order, long value) {
930984
setLongAtOffset(segment, 0L, order, value);
931985
}
@@ -941,6 +995,7 @@ public static void setLong(MemorySegment segment, ByteOrder order, long value) {
941995
* @param order the specified byte order.
942996
* @return a double value read from {@code segment}.
943997
*/
998+
@ForceInline
944999
public static double getDouble(MemorySegment segment, ByteOrder order) {
9451000
return getDoubleAtOffset(segment, 0L, order);
9461001
}
@@ -956,6 +1011,7 @@ public static double getDouble(MemorySegment segment, ByteOrder order) {
9561011
* @param order the specified byte order.
9571012
* @param value the double value to be written.
9581013
*/
1014+
@ForceInline
9591015
public static void setDouble(MemorySegment segment, ByteOrder order, double value) {
9601016
setDoubleAtOffset(segment, 0L, order, value);
9611017
}
@@ -971,6 +1027,7 @@ public static void setDouble(MemorySegment segment, ByteOrder order, double valu
9711027
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 2)}.
9721028
* @return a char value read from {@code segment} at the element index specified by {@code index}.
9731029
*/
1030+
@ForceInline
9741031
public static char getCharAtIndex(MemorySegment segment, long index) {
9751032
return getCharAtOffset(segment, scale(segment, index, 2));
9761033
}
@@ -986,6 +1043,7 @@ public static char getCharAtIndex(MemorySegment segment, long index) {
9861043
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 2)}.
9871044
* @param value the char value to be written.
9881045
*/
1046+
@ForceInline
9891047
public static void setCharAtIndex(MemorySegment segment, long index, char value) {
9901048
setCharAtOffset(segment, scale(segment, index, 2), value);
9911049
}
@@ -1001,6 +1059,7 @@ public static void setCharAtIndex(MemorySegment segment, long index, char value)
10011059
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 2)}.
10021060
* @return a short value read from {@code segment} at the element index specified by {@code index}.
10031061
*/
1062+
@ForceInline
10041063
public static short getShortAtIndex(MemorySegment segment, long index) {
10051064
return getShortAtOffset(segment, scale(segment, index, 2));
10061065
}
@@ -1016,6 +1075,7 @@ public static short getShortAtIndex(MemorySegment segment, long index) {
10161075
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 2)}.
10171076
* @param value the short value to be written.
10181077
*/
1078+
@ForceInline
10191079
public static void setShortAtIndex(MemorySegment segment, long index, short value) {
10201080
setShortAtOffset(segment, scale(segment, index, 2), value);
10211081
}
@@ -1031,6 +1091,7 @@ public static void setShortAtIndex(MemorySegment segment, long index, short valu
10311091
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 4)}.
10321092
* @return an int value read from {@code segment} at the element index specified by {@code index}.
10331093
*/
1094+
@ForceInline
10341095
public static int getIntAtIndex(MemorySegment segment, long index) {
10351096
return getIntAtOffset(segment, scale(segment, index, 4));
10361097
}
@@ -1046,6 +1107,7 @@ public static int getIntAtIndex(MemorySegment segment, long index) {
10461107
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 4)}.
10471108
* @param value the int value to be written.
10481109
*/
1110+
@ForceInline
10491111
public static void setIntAtIndex(MemorySegment segment, long index, int value) {
10501112
setIntAtOffset(segment, scale(segment, index, 4), value);
10511113
}
@@ -1061,6 +1123,7 @@ public static void setIntAtIndex(MemorySegment segment, long index, int value) {
10611123
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 4)}.
10621124
* @return a float value read from {@code segment} at the element index specified by {@code index}.
10631125
*/
1126+
@ForceInline
10641127
public static float getFloatAtIndex(MemorySegment segment, long index) {
10651128
return getFloatAtOffset(segment, scale(segment, index, 4));
10661129
}
@@ -1076,6 +1139,7 @@ public static float getFloatAtIndex(MemorySegment segment, long index) {
10761139
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 4)}.
10771140
* @param value the float value to be written.
10781141
*/
1142+
@ForceInline
10791143
public static void setFloatAtIndex(MemorySegment segment, long index, float value) {
10801144
setFloatAtOffset(segment, scale(segment, index, 4), value);
10811145
}
@@ -1091,6 +1155,7 @@ public static void setFloatAtIndex(MemorySegment segment, long index, float valu
10911155
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 8)}.
10921156
* @return a long value read from {@code segment} at the element index specified by {@code index}.
10931157
*/
1158+
@ForceInline
10941159
public static long getLongAtIndex(MemorySegment segment, long index) {
10951160
return getLongAtOffset(segment, scale(segment, index, 8));
10961161
}
@@ -1106,6 +1171,7 @@ public static long getLongAtIndex(MemorySegment segment, long index) {
11061171
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 8)}.
11071172
* @param value the long value to be written.
11081173
*/
1174+
@ForceInline
11091175
public static void setLongAtIndex(MemorySegment segment, long index, long value) {
11101176
setLongAtOffset(segment, scale(segment, index, 8), value);
11111177
}
@@ -1121,6 +1187,7 @@ public static void setLongAtIndex(MemorySegment segment, long index, long value)
11211187
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 8)}.
11221188
* @return a double value read from {@code segment} at the element index specified by {@code index}.
11231189
*/
1190+
@ForceInline
11241191
public static double getDoubleAtIndex(MemorySegment segment, long index) {
11251192
return getDoubleAtOffset(segment, scale(segment, index, 8));
11261193
}
@@ -1136,6 +1203,7 @@ public static double getDoubleAtIndex(MemorySegment segment, long index) {
11361203
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 8)}.
11371204
* @param value the double value to be written.
11381205
*/
1206+
@ForceInline
11391207
public static void setDoubleAtIndex(MemorySegment segment, long index, double value) {
11401208
setDoubleAtOffset(segment, scale(segment, index, 8), value);
11411209
}
@@ -1151,6 +1219,7 @@ public static void setDoubleAtIndex(MemorySegment segment, long index, double va
11511219
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 8)}.
11521220
* @return a memory address read from {@code segment} at the element index specified by {@code index}.
11531221
*/
1222+
@ForceInline
11541223
public static MemoryAddress getAddressAtIndex(MemorySegment segment, long index) {
11551224
return getAddressAtOffset(segment, scale(segment, index, (int)MemoryLayouts.ADDRESS.byteSize()));
11561225
}
@@ -1166,6 +1235,7 @@ public static MemoryAddress getAddressAtIndex(MemorySegment segment, long index)
11661235
* @param index element index (relative to {@code segment}). The final address of this read operation can be expressed as {@code segment.address().addOffset(index * 8)}.
11671236
* @param value the memory address to be written (expressed as an {@link Addressable} instance).
11681237
*/
1238+
@ForceInline
11691239
public static void setAddressAtIndex(MemorySegment segment, long index, Addressable value) {
11701240
setAddressAtOffset(segment, scale(segment, index, (int)MemoryLayouts.ADDRESS.byteSize()), value);
11711241
}
@@ -1182,6 +1252,7 @@ public static void setAddressAtIndex(MemorySegment segment, long index, Addressa
11821252
* @param order the specified byte order.
11831253
* @return a char value read from {@code segment} at the element index specified by {@code index}.
11841254
*/
1255+
@ForceInline
11851256
public static char getCharAtIndex(MemorySegment segment, long index, ByteOrder order) {
11861257
return getCharAtOffset(segment, scale(segment, index, 2), order);
11871258
}
@@ -1198,6 +1269,7 @@ public static char getCharAtIndex(MemorySegment segment, long index, ByteOrder o
11981269
* @param order the specified byte order.
11991270
* @param value the char value to be written.
12001271
*/
1272+
@ForceInline
12011273
public static void setCharAtIndex(MemorySegment segment, long index, ByteOrder order, char value) {
12021274
setCharAtOffset(segment, scale(segment, index, 2), order, value);
12031275
}
@@ -1214,6 +1286,7 @@ public static void setCharAtIndex(MemorySegment segment, long index, ByteOrder o
12141286
* @param order the specified byte order.
12151287
* @return a short value read from {@code segment} at the element index specified by {@code index}.
12161288
*/
1289+
@ForceInline
12171290
public static short getShortAtIndex(MemorySegment segment, long index, ByteOrder order) {
12181291
return getShortAtOffset(segment, scale(segment, index, 2), order);
12191292
}
@@ -1230,6 +1303,7 @@ public static short getShortAtIndex(MemorySegment segment, long index, ByteOrder
12301303
* @param order the specified byte order.
12311304
* @param value the short value to be written.
12321305
*/
1306+
@ForceInline
12331307
public static void setShortAtIndex(MemorySegment segment, long index, ByteOrder order, short value) {
12341308
setShortAtOffset(segment, scale(segment, index, 2), order, value);
12351309
}
@@ -1246,6 +1320,7 @@ public static void setShortAtIndex(MemorySegment segment, long index, ByteOrder
12461320
* @param order the specified byte order.
12471321
* @return an int value read from {@code segment} at the element index specified by {@code index}.
12481322
*/
1323+
@ForceInline
12491324
public static int getIntAtIndex(MemorySegment segment, long index, ByteOrder order) {
12501325
return getIntAtOffset(segment, scale(segment, index, 4), order);
12511326
}
@@ -1262,6 +1337,7 @@ public static int getIntAtIndex(MemorySegment segment, long index, ByteOrder ord
12621337
* @param order the specified byte order.
12631338
* @param value the int value to be written.
12641339
*/
1340+
@ForceInline
12651341
public static void setIntAtIndex(MemorySegment segment, long index, ByteOrder order, int value) {
12661342
setIntAtOffset(segment, scale(segment, index, 4), order, value);
12671343
}
@@ -1278,6 +1354,7 @@ public static void setIntAtIndex(MemorySegment segment, long index, ByteOrder or
12781354
* @param order the specified byte order.
12791355
* @return a float value read from {@code segment} at the element index specified by {@code index}.
12801356
*/
1357+
@ForceInline
12811358
public static float getFloatAtIndex(MemorySegment segment, long index, ByteOrder order) {
12821359
return getFloatAtOffset(segment, scale(segment, index, 4), order);
12831360
}
@@ -1294,6 +1371,7 @@ public static float getFloatAtIndex(MemorySegment segment, long index, ByteOrder
12941371
* @param order the specified byte order.
12951372
* @param value the float value to be written.
12961373
*/
1374+
@ForceInline
12971375
public static void setFloatAtIndex(MemorySegment segment, long index, ByteOrder order, float value) {
12981376
setFloatAtOffset(segment, scale(segment, index, 4), order, value);
12991377
}
@@ -1310,6 +1388,7 @@ public static void setFloatAtIndex(MemorySegment segment, long index, ByteOrder
13101388
* @param order the specified byte order.
13111389
* @return a long value read from {@code segment} at the element index specified by {@code index}.
13121390
*/
1391+
@ForceInline
13131392
public static long getLongAtIndex(MemorySegment segment, long index, ByteOrder order) {
13141393
return getLongAtOffset(segment, scale(segment, index, 8), order);
13151394
}
@@ -1326,6 +1405,7 @@ public static long getLongAtIndex(MemorySegment segment, long index, ByteOrder o
13261405
* @param order the specified byte order.
13271406
* @param value the long value to be written.
13281407
*/
1408+
@ForceInline
13291409
public static void setLongAtIndex(MemorySegment segment, long index, ByteOrder order, long value) {
13301410
setLongAtOffset(segment, scale(segment, index, 8), order, value);
13311411
}
@@ -1342,6 +1422,7 @@ public static void setLongAtIndex(MemorySegment segment, long index, ByteOrder o
13421422
* @param order the specified byte order.
13431423
* @return a double value read from {@code segment} at the element index specified by {@code index}.
13441424
*/
1425+
@ForceInline
13451426
public static double getDoubleAtIndex(MemorySegment segment, long index, ByteOrder order) {
13461427
return getDoubleAtOffset(segment, scale(segment, index, 8), order);
13471428
}
@@ -1358,6 +1439,7 @@ public static double getDoubleAtIndex(MemorySegment segment, long index, ByteOrd
13581439
* @param order the specified byte order.
13591440
* @param value the double value to be written.
13601441
*/
1442+
@ForceInline
13611443
public static void setDoubleAtIndex(MemorySegment segment, long index, ByteOrder order, double value) {
13621444
setDoubleAtOffset(segment, scale(segment, index, 8), order, value);
13631445
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package org.openjdk.bench.jdk.incubator.foreign;
24+
25+
import jdk.incubator.foreign.MemoryAccess;
26+
import jdk.incubator.foreign.MemoryAddress;
27+
import jdk.incubator.foreign.MemoryLayout;
28+
import jdk.incubator.foreign.MemorySegment;
29+
import org.openjdk.jmh.annotations.Benchmark;
30+
import org.openjdk.jmh.annotations.BenchmarkMode;
31+
import org.openjdk.jmh.annotations.Fork;
32+
import org.openjdk.jmh.annotations.Measurement;
33+
import org.openjdk.jmh.annotations.Mode;
34+
import org.openjdk.jmh.annotations.OutputTimeUnit;
35+
import org.openjdk.jmh.annotations.Setup;
36+
import org.openjdk.jmh.annotations.State;
37+
import org.openjdk.jmh.annotations.TearDown;
38+
import org.openjdk.jmh.annotations.Warmup;
39+
import sun.misc.Unsafe;
40+
41+
import java.lang.invoke.VarHandle;
42+
import java.nio.ByteBuffer;
43+
import java.nio.ByteOrder;
44+
import java.util.concurrent.TimeUnit;
45+
46+
import static jdk.incubator.foreign.MemoryLayout.PathElement.sequenceElement;
47+
import static jdk.incubator.foreign.MemoryLayouts.JAVA_DOUBLE;
48+
49+
@BenchmarkMode(Mode.AverageTime)
50+
@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
51+
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
52+
@State(org.openjdk.jmh.annotations.Scope.Thread)
53+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
54+
@Fork(3)
55+
public class LoopOverNonConstantFP {
56+
57+
static final Unsafe unsafe = Utils.unsafe;
58+
59+
static final int ELEM_SIZE = 1_000_000;
60+
static final int CARRIER_SIZE = (int)JAVA_DOUBLE.byteSize();
61+
static final int ALLOC_SIZE = ELEM_SIZE * CARRIER_SIZE;
62+
63+
MemorySegment segmentIn, segmentOut;
64+
long unsafe_addrIn, unsafe_addrOut;
65+
ByteBuffer byteBufferIn, byteBufferOut;
66+
67+
@Setup
68+
public void setup() {
69+
unsafe_addrIn = unsafe.allocateMemory(ALLOC_SIZE);
70+
unsafe_addrOut = unsafe.allocateMemory(ALLOC_SIZE);
71+
for (int i = 0; i < ELEM_SIZE; i++) {
72+
unsafe.putDouble(unsafe_addrIn + (i * CARRIER_SIZE), i);
73+
}
74+
for (int i = 0; i < ELEM_SIZE; i++) {
75+
unsafe.putDouble(unsafe_addrOut + (i * CARRIER_SIZE), i);
76+
}
77+
segmentIn = MemorySegment.allocateNative(ALLOC_SIZE);
78+
segmentOut = MemorySegment.allocateNative(ALLOC_SIZE);
79+
for (int i = 0; i < ELEM_SIZE; i++) {
80+
MemoryAccess.setDoubleAtIndex(segmentIn, i, i);
81+
}
82+
for (int i = 0; i < ELEM_SIZE; i++) {
83+
MemoryAccess.setDoubleAtIndex(segmentOut, i, i);
84+
}
85+
byteBufferIn = ByteBuffer.allocateDirect(ALLOC_SIZE).order(ByteOrder.nativeOrder());
86+
byteBufferOut = ByteBuffer.allocateDirect(ALLOC_SIZE).order(ByteOrder.nativeOrder());
87+
for (int i = 0; i < ELEM_SIZE; i++) {
88+
byteBufferIn.putDouble(i * CARRIER_SIZE , i);
89+
}
90+
for (int i = 0; i < ELEM_SIZE; i++) {
91+
byteBufferOut.putDouble(i * CARRIER_SIZE , i);
92+
}
93+
}
94+
95+
@TearDown
96+
public void tearDown() {
97+
segmentIn.close();
98+
segmentOut.close();
99+
unsafe.invokeCleaner(byteBufferIn);
100+
unsafe.invokeCleaner(byteBufferOut);
101+
unsafe.freeMemory(unsafe_addrIn);
102+
unsafe.freeMemory(unsafe_addrOut);
103+
}
104+
105+
@Benchmark
106+
public void unsafe_loop() {
107+
for (int i = 0; i < ELEM_SIZE; i ++) {
108+
unsafe.putDouble(unsafe_addrOut + (i * CARRIER_SIZE),
109+
unsafe.getDouble(unsafe_addrIn + (i * CARRIER_SIZE)) +
110+
unsafe.getDouble(unsafe_addrOut + (i * CARRIER_SIZE)));
111+
}
112+
}
113+
114+
@Benchmark
115+
public void segment_loop() {
116+
for (int i = 0; i < ELEM_SIZE; i ++) {
117+
MemoryAccess.setDoubleAtIndex(segmentOut, i,
118+
MemoryAccess.getDoubleAtIndex(segmentIn, i) +
119+
MemoryAccess.getDoubleAtIndex(segmentOut, i));
120+
}
121+
}
122+
123+
@Benchmark
124+
public void BB_loop() {
125+
for (int i = 0; i < ELEM_SIZE; i++) {
126+
byteBufferOut.putDouble(i * CARRIER_SIZE,
127+
byteBufferIn.getDouble(i * CARRIER_SIZE) +
128+
byteBufferOut.getDouble(i * CARRIER_SIZE));
129+
}
130+
}
131+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package org.openjdk.bench.jdk.incubator.foreign;
25+
26+
import static jdk.incubator.foreign.MemoryAccess.*;
27+
import jdk.incubator.foreign.*;
28+
import org.openjdk.jmh.annotations.*;
29+
import org.openjdk.jmh.runner.Runner;
30+
import org.openjdk.jmh.runner.options.Options;
31+
import org.openjdk.jmh.runner.options.OptionsBuilder;
32+
import sun.misc.Unsafe;
33+
import java.util.concurrent.TimeUnit;
34+
35+
import java.lang.invoke.MethodHandles;
36+
import java.lang.invoke.VarHandle;
37+
import java.lang.reflect.Field;
38+
39+
@BenchmarkMode(Mode.AverageTime)
40+
@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
41+
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
42+
@State(org.openjdk.jmh.annotations.Scope.Thread)
43+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
44+
@Fork(3)
45+
public class UnrolledAccess {
46+
47+
static final Unsafe U = Utils.unsafe;
48+
49+
final static int SIZE = 1024;
50+
51+
static final VarHandle LONG_HANDLE = MemoryLayout.ofSequence(SIZE, MemoryLayouts.JAVA_LONG)
52+
.varHandle(long.class, MemoryLayout.PathElement.sequenceElement());
53+
54+
@State(Scope.Benchmark)
55+
public static class Data {
56+
57+
final double[] inputArray;
58+
final double[] outputArray;
59+
final long inputAddress;
60+
final long outputAddress;
61+
final MemorySegment inputSegment;
62+
final MemorySegment outputSegment;
63+
64+
65+
public Data() {
66+
this.inputArray = new double[SIZE];
67+
this.outputArray = new double[SIZE];
68+
this.inputAddress = U.allocateMemory(8 * SIZE);
69+
this.outputAddress = U.allocateMemory(8 * SIZE);
70+
this.inputSegment = MemoryAddress.ofLong(inputAddress).asSegmentRestricted(8*SIZE);
71+
this.outputSegment = MemoryAddress.ofLong(outputAddress).asSegmentRestricted(8*SIZE);
72+
}
73+
}
74+
75+
@Benchmark
76+
public void unsafe_loop(Data state) {
77+
final long ia = state.inputAddress;
78+
final long oa = state.outputAddress;
79+
for(int i = 0; i < SIZE; i+=4) {
80+
U.putLong(oa + 8*i, U.getLong(ia + 8*i) + U.getLong(oa + 8*i));
81+
U.putLong(oa + 8*(i+1), U.getLong(ia + 8*(i+1)) + U.getLong(oa + 8*(i+1)));
82+
U.putLong(oa + 8*(i+2), U.getLong(ia + 8*(i+2)) + U.getLong(oa + 8*(i+2)));
83+
U.putLong(oa + 8*(i+3), U.getLong(ia + 8*(i+3)) + U.getLong(oa + 8*(i+3)));
84+
}
85+
}
86+
87+
@Benchmark
88+
public void handle_loop(Data state) {
89+
final MemorySegment is = state.inputSegment;
90+
final MemorySegment os = state.outputSegment;
91+
92+
for(int i = 0; i < SIZE; i+=4) {
93+
LONG_HANDLE.set(os, (long) (i), (long) LONG_HANDLE.get(is, (long) (i)) + (long) LONG_HANDLE.get(os, (long) (i)));
94+
LONG_HANDLE.set(os, (long) (i+1), (long) LONG_HANDLE.get(is, (long) (i+1)) + (long) LONG_HANDLE.get(os, (long) (i+1)));
95+
LONG_HANDLE.set(os, (long) (i+2), (long) LONG_HANDLE.get(is, (long) (i+2)) + (long) LONG_HANDLE.get(os, (long) (i+2)));
96+
LONG_HANDLE.set(os, (long) (i+3), (long) LONG_HANDLE.get(is, (long) (i+3)) + (long) LONG_HANDLE.get(os, (long) (i+3)));
97+
}
98+
}
99+
100+
@Benchmark
101+
public void static_handle_loop(Data state) {
102+
final MemorySegment is = state.inputSegment;
103+
final MemorySegment os = state.outputSegment;
104+
105+
for(int i = 0; i < SIZE; i+=4) {
106+
setLongAtIndex(os, i,getLongAtIndex(is, i) + MemoryAccess.getLongAtIndex(os, i));
107+
setLongAtIndex(os, i+1,getLongAtIndex(is, i+1) + getLongAtIndex(os, i+1));
108+
setLongAtIndex(os, i+2,getLongAtIndex(is, i+2) + getLongAtIndex(os, i+2));
109+
setLongAtIndex(os, i+3,getLongAtIndex(is, i+3) + getLongAtIndex(os, i+3));
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)
Please sign in to comment.