< prev index next >

test/jdk/java/foreign/TestSpliterator.java

Print this page
*** 21,11 ***
   * questions.
   */
  
  /*
   * @test
-  * @enablePreview
   * @run testng TestSpliterator
   */
  
  import java.lang.foreign.*;
  
--- 21,10 ---

*** 42,23 ***
  
  import static org.testng.Assert.*;
  
  public class TestSpliterator {
  
-     static final VarHandle INT_HANDLE = ValueLayout.JAVA_INT.arrayElementVarHandle();
- 
      final static int CARRIER_SIZE = 4;
  
      @Test(dataProvider = "splits")
      public void testSum(int size, int threshold) {
          SequenceLayout layout = MemoryLayout.sequenceLayout(size, ValueLayout.JAVA_INT);
  
          //setup
          try (Arena arena = Arena.ofShared()) {
              MemorySegment segment = arena.allocate(layout);;
              for (int i = 0; i < layout.elementCount(); i++) {
!                 INT_HANDLE.set(segment, (long) i, i);
              }
              long expected = LongStream.range(0, layout.elementCount()).sum();
              //serial
              long serial = sum(0, segment);
              assertEquals(serial, expected);
--- 41,21 ---
  
  import static org.testng.Assert.*;
  
  public class TestSpliterator {
  
      final static int CARRIER_SIZE = 4;
  
      @Test(dataProvider = "splits")
      public void testSum(int size, int threshold) {
          SequenceLayout layout = MemoryLayout.sequenceLayout(size, ValueLayout.JAVA_INT);
  
          //setup
          try (Arena arena = Arena.ofShared()) {
              MemorySegment segment = arena.allocate(layout);;
              for (int i = 0; i < layout.elementCount(); i++) {
!                 segment.setAtIndex(ValueLayout.JAVA_INT, i, i);
              }
              long expected = LongStream.range(0, layout.elementCount()).sum();
              //serial
              long serial = sum(0, segment);
              assertEquals(serial, expected);

*** 81,11 ***
  
          //setup
          Arena scope = Arena.ofAuto();
          MemorySegment segment = scope.allocate(layout);
          for (int i = 0; i < layout.elementCount(); i++) {
!             INT_HANDLE.set(segment, (long) i, i);
          }
          long expected = LongStream.range(0, layout.elementCount()).sum();
  
          //check that a segment w/o ACQUIRE access mode can still be used from same thread
          AtomicLong spliteratorSum = new AtomicLong();
--- 78,11 ---
  
          //setup
          Arena scope = Arena.ofAuto();
          MemorySegment segment = scope.allocate(layout);
          for (int i = 0; i < layout.elementCount(); i++) {
!             segment.setAtIndex(ValueLayout.JAVA_INT, i, i);
          }
          long expected = LongStream.range(0, layout.elementCount()).sum();
  
          //check that a segment w/o ACQUIRE access mode can still be used from same thread
          AtomicLong spliteratorSum = new AtomicLong();

*** 158,18 ***
          long bigByteAlign = Long.lowestOneBit(segment.address()) << 1;
          segment.elements(MemoryLayout.sequenceLayout(2, ValueLayout.JAVA_INT.withByteAlignment(bigByteAlign)));
      }
  
      static long sumSingle(long acc, MemorySegment segment) {
!         return acc + (int)INT_HANDLE.get(segment, 0L);
      }
  
      static long sum(long start, MemorySegment segment) {
          long sum = start;
          int length = (int)segment.byteSize();
          for (int i = 0 ; i < length / CARRIER_SIZE ; i++) {
!             sum += (int)INT_HANDLE.get(segment, (long)i);
          }
          return sum;
      }
  
      static class SumSegmentCounted extends CountedCompleter<Long> {
--- 155,18 ---
          long bigByteAlign = Long.lowestOneBit(segment.address()) << 1;
          segment.elements(MemoryLayout.sequenceLayout(2, ValueLayout.JAVA_INT.withByteAlignment(bigByteAlign)));
      }
  
      static long sumSingle(long acc, MemorySegment segment) {
!         return acc + segment.getAtIndex(ValueLayout.JAVA_INT, 0);
      }
  
      static long sum(long start, MemorySegment segment) {
          long sum = start;
          int length = (int)segment.byteSize();
          for (int i = 0 ; i < length / CARRIER_SIZE ; i++) {
!             sum += segment.getAtIndex(ValueLayout.JAVA_INT, i);
          }
          return sum;
      }
  
      static class SumSegmentCounted extends CountedCompleter<Long> {
< prev index next >