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

Add methd to restrict confinement of memory segments

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • repo-panama
    • core-libs

      As the confinement properties of a memory segment are now orthogonal from lifetime (e.g. a MemorySegment.Scope is not about confinement), we might add a method on MemorySegment to create a confined view of an existing shared segment:

      MemorySegment asThreadConfined(Thread);

      This creates a segment view that can only be accessed by the specified thread. Rules:

      * If the original segment can be accessed by any thread, then we can specify any thread as parameter;
      * If the original segment is already confined, we can only re-assert thread-confinement (e.g. we cannot change the confinement thread).

      This method would be very useful for divide-and-conquer algorithms:

      ```
      MemorySegment segment = sharedArena.allocate(...);
      Thread[] threads = ...
      for (int i = 0 ; i < threads.length ; i++) {
          process(segment.asSlice(0, CHUNK_SIZE)
                 .asThreadConfined(threads[i]));
      }
      ```

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: