< prev index next >

src/java.base/share/classes/java/lang/foreign/Arena.java

Print this page
*** 24,11 ***
   */
  
  package java.lang.foreign;
  
  import jdk.internal.foreign.MemorySessionImpl;
- import jdk.internal.javac.PreviewFeature;
  import jdk.internal.ref.CleanerFactory;
  
  import java.lang.foreign.MemorySegment.Scope;
  
  /**
--- 24,10 ---

*** 182,24 ***
   * the timely deallocation guarantee provided by the underlying confined arena:
   *
   * {@snippet lang = java:
   * try (Arena slicingArena = new SlicingArena(1000)) {
   *     for (int i = 0; i < 10; i++) {
!  *         MemorySegment s = slicingArena.allocateArray(JAVA_INT, 1, 2, 3, 4, 5);
   *         ...
   *     }
   * } // all memory allocated is released here
   * }
   *
   * @implSpec
   * Implementations of this interface are thread-safe.
   *
   * @see MemorySegment
   *
!  * @since 20
   */
- @PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
  public interface Arena extends SegmentAllocator, AutoCloseable {
  
      /**
       * Creates a new arena that is managed, automatically, by the garbage collector.
       * Segments allocated with the returned arena can be
--- 181,23 ---
   * the timely deallocation guarantee provided by the underlying confined arena:
   *
   * {@snippet lang = java:
   * try (Arena slicingArena = new SlicingArena(1000)) {
   *     for (int i = 0; i < 10; i++) {
!  *         MemorySegment s = slicingArena.allocateFrom(JAVA_INT, 1, 2, 3, 4, 5);
   *         ...
   *     }
   * } // all memory allocated is released here
   * }
   *
   * @implSpec
   * Implementations of this interface are thread-safe.
   *
   * @see MemorySegment
   *
!  * @since 22
   */
  public interface Arena extends SegmentAllocator, AutoCloseable {
  
      /**
       * Creates a new arena that is managed, automatically, by the garbage collector.
       * Segments allocated with the returned arena can be

*** 219,11 ***
       *
       * @return the global arena.
       */
      static Arena global() {
          class Holder {
!             static final Arena GLOBAL = MemorySessionImpl.GLOBAL.asArena();
          }
          return Holder.GLOBAL;
      }
  
      /**
--- 217,11 ---
       *
       * @return the global arena.
       */
      static Arena global() {
          class Holder {
!             static final Arena GLOBAL = MemorySessionImpl.createGlobal().asArena();
          }
          return Holder.GLOBAL;
      }
  
      /**

*** 267,13 ***
       * @throws IllegalStateException if this arena has already been {@linkplain #close() closed}.
       * @throws WrongThreadException if this arena is confined, and this method is called from a thread
       * other than the arena's owner thread.
       */
      @Override
!     default MemorySegment allocate(long byteSize, long byteAlignment) {
-         return ((MemorySessionImpl)scope()).allocate(byteSize, byteAlignment);
-     }
  
      /**
       * {@return the arena scope}
       */
      Scope scope();
--- 265,11 ---
       * @throws IllegalStateException if this arena has already been {@linkplain #close() closed}.
       * @throws WrongThreadException if this arena is confined, and this method is called from a thread
       * other than the arena's owner thread.
       */
      @Override
!     MemorySegment allocate(long byteSize, long byteAlignment);
  
      /**
       * {@return the arena scope}
       */
      Scope scope();
< prev index next >