Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8357847

(ch) WindowsAsynchronousFileChannelImpl should support FFM Buffers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 22
    • core-libs
    • None
    • In Review

      The FFM API allows the creation of `MemorySegment` instances viewed as buffers. These buffers need to be guarded during use so they are not closed underneath. Also, it is better to use `dst.isDirect()` rather than instanceof testing.

      While an asynchronous event is taking place, the buffer needs to remain under guard. It is only when the event completes, the guard can be lifted.

      Guard: IOUtil.acquireScope(buf, true);

      We could also add a buffer variant in the test:

          // returns ByteBuffer with random bytes
          static ByteBuffer genBuffer() {
              int size = 1024 + rand.nextInt(16000);
              byte[] buf = new byte[size];
              return switch (rand.nextInt(4)) {
                  case 0 -> ByteBuffer.allocateDirect(buf.length)
                          .put(buf)
                          .flip();
                  case 1 -> ByteBuffer.wrap(buf);
                  case 2 -> Arena.ofAuto().allocate(buf.length).asByteBuffer()
                          .put(buf)
                          .flip();
                  case 3 -> Arena.ofShared().allocate(buf.length).asByteBuffer()
                          .put(buf)
                          .flip();
                  default -> throw new InternalError("Should not reach here");
              };
          }

            bpb Brian Burkhalter
            pminborg Per-Ake Minborg
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: