< prev index next >

test/jdk/java/foreign/TestSharedAccess.java

Print this page
*** 41,15 ***
  
  import static org.testng.Assert.*;
  
  public class TestSharedAccess {
  
!     static final VarHandle intHandle = MemoryLayouts.JAVA_INT.varHandle(int.class);
  
      @Test
      public void testShared() throws Throwable {
!         SequenceLayout layout = MemoryLayout.sequenceLayout(1024, MemoryLayouts.JAVA_INT);
          try (ResourceScope scope = ResourceScope.newSharedScope()) {
              MemorySegment s = MemorySegment.allocateNative(layout, scope);
              for (int i = 0 ; i < layout.elementCount().getAsLong() ; i++) {
                  setInt(s.asSlice(i * 4), 42);
              }
--- 41,15 ---
  
  import static org.testng.Assert.*;
  
  public class TestSharedAccess {
  
!     static final VarHandle intHandle = ValueLayout.JAVA_INT.varHandle();
  
      @Test
      public void testShared() throws Throwable {
!         SequenceLayout layout = MemoryLayout.sequenceLayout(1024, ValueLayout.JAVA_INT);
          try (ResourceScope scope = ResourceScope.newSharedScope()) {
              MemorySegment s = MemorySegment.allocateNative(layout, scope);
              for (int i = 0 ; i < layout.elementCount().getAsLong() ; i++) {
                  setInt(s.asSlice(i * 4), 42);
              }

*** 96,11 ***
          try (ResourceScope scope = ResourceScope.newSharedScope()) {
              MemorySegment s = MemorySegment.allocateNative(4, 1, scope);
              setInt(s, 42);
              assertEquals(getInt(s), 42);
              List<Thread> threads = new ArrayList<>();
!             MemorySegment sharedSegment = s.address().asSegment(s.byteSize(), scope);
              for (int i = 0 ; i < 1000 ; i++) {
                  threads.add(new Thread(() -> {
                      assertEquals(getInt(sharedSegment), 42);
                  }));
              }
--- 96,11 ---
          try (ResourceScope scope = ResourceScope.newSharedScope()) {
              MemorySegment s = MemorySegment.allocateNative(4, 1, scope);
              setInt(s, 42);
              assertEquals(getInt(s), 42);
              List<Thread> threads = new ArrayList<>();
!             MemorySegment sharedSegment = MemorySegment.ofAddressNative(s.address(), s.byteSize(), scope);
              for (int i = 0 ; i < 1000 ; i++) {
                  threads.add(new Thread(() -> {
                      assertEquals(getInt(sharedSegment), 42);
                  }));
              }

*** 119,11 ***
      public void testOutsideConfinementThread() throws Throwable {
          CountDownLatch a = new CountDownLatch(1);
          CountDownLatch b = new CountDownLatch(1);
          CompletableFuture<?> r;
          try (ResourceScope scope = ResourceScope.newConfinedScope()) {
!             MemorySegment s1 = MemorySegment.allocateNative(MemoryLayout.sequenceLayout(2, MemoryLayouts.JAVA_INT), scope);
              r = CompletableFuture.runAsync(() -> {
                  try {
                      ByteBuffer bb = s1.asByteBuffer();
  
                      MemorySegment s2 = MemorySegment.ofByteBuffer(bb);
--- 119,11 ---
      public void testOutsideConfinementThread() throws Throwable {
          CountDownLatch a = new CountDownLatch(1);
          CountDownLatch b = new CountDownLatch(1);
          CompletableFuture<?> r;
          try (ResourceScope scope = ResourceScope.newConfinedScope()) {
!             MemorySegment s1 = MemorySegment.allocateNative(MemoryLayout.sequenceLayout(2, ValueLayout.JAVA_INT), scope);
              r = CompletableFuture.runAsync(() -> {
                  try {
                      ByteBuffer bb = s1.asByteBuffer();
  
                      MemorySegment s2 = MemorySegment.ofByteBuffer(bb);
< prev index next >