< prev index next > src/java.base/share/classes/java/lang/foreign/Arena.java
Print this page
*/
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;
/**
* 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);
+ * 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 20
+ * @since 22
*/
- @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
*
* @return the global arena.
*/
static Arena global() {
class Holder {
- static final Arena GLOBAL = MemorySessionImpl.GLOBAL.asArena();
+ static final Arena GLOBAL = MemorySessionImpl.createGlobal().asArena();
}
return Holder.GLOBAL;
}
/**
* @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);
- }
+ MemorySegment allocate(long byteSize, long byteAlignment);
/**
* {@return the arena scope}
*/
Scope scope();
< prev index next >