APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.foreign

public final Class BufferStack

extends Object
Class Inheritance
Imports
jdk.internal.misc.CarrierThreadLocal, jdk.internal.vm.annotation.ForceInline, java.lang.foreign.Arena, .MemoryLayout, .MemorySegment, .SegmentAllocator, java.lang.ref.Reference, java.util.concurrent.locks.ReentrantLock, java.util.function.Consumer

A buffer stack that allows efficient reuse of memory segments. This is useful in cases where temporary memory is needed.

Use the factories BufferStack.of(...) to create new instances of this class.

Note

The reused segments are neither zeroed out before nor after re-use.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record

Field Summary

Modifier and TypeField and Description
private final long
private final long
private final CarrierThreadLocal<BufferStack.PerThread>

Constructor Summary

AccessConstructor and Description
private
BufferStack(long byteSize, long byteAlignment)

Method Summary

Modifier and TypeMethod and Description
public static BufferStack
of(long byteSize, long byteAlignment)

public static BufferStack
of(long byteSize)

public static BufferStack
of(MemoryLayout layout)

public Arena

Returns:

a new Arena that tries to provide byteSize and byteAlignment allocations by recycling the BufferStack's internal memory
pushFrame
(long
to be reserved from this BufferStack's internal memory
byteSize
,
long
to be used for reservation
byteAlignment
)

Returns a new Arena that tries to provide byteSize and byteAlignment allocations by recycling the BufferStack's internal memory.

public Arena

Returns:

a new Arena that tries to provide byteSize allocations by recycling the BufferStack's internal memory
pushFrame
(long
to be reserved from this BufferStack's internal memory
byteSize
)

Returns a new Arena that tries to provide byteSize allocations by recycling the BufferStack's internal memory.

public Arena

Returns:

a new Arena that tries to provide layout allocations by recycling the BufferStack's internal memory
pushFrame
(MemoryLayout
for which to reserve internal memory
layout
)

Returns a new Arena that tries to provide layout allocations by recycling the BufferStack's internal memory.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

byteAlignmentback to summary
private final long byteAlignment
byteSizeback to summary
private final long byteSize
tlback to summary
private final CarrierThreadLocal<BufferStack.PerThread> tl

Constructor Detail

BufferStackback to summary
private BufferStack(long byteSize, long byteAlignment)

Method Detail

ofback to summary
public static BufferStack of(long byteSize, long byteAlignment)
ofback to summary
public static BufferStack of(long byteSize)
ofback to summary
public static BufferStack of(MemoryLayout layout)
pushFrameback to summary
public Arena pushFrame(long byteSize, long byteAlignment)

Returns a new Arena that tries to provide byteSize and byteAlignment allocations by recycling the BufferStack's internal memory.

Parameters
byteSize:long

to be reserved from this BufferStack's internal memory

byteAlignment:long

to be used for reservation

Returns:Arena

a new Arena that tries to provide byteSize and byteAlignment allocations by recycling the BufferStack's internal memory

Annotations
@ForceInline
pushFrameback to summary
public Arena pushFrame(long byteSize)

Returns a new Arena that tries to provide byteSize allocations by recycling the BufferStack's internal memory.

Parameters
byteSize:long

to be reserved from this BufferStack's internal memory

Returns:Arena

a new Arena that tries to provide byteSize allocations by recycling the BufferStack's internal memory

Annotations
@ForceInline
pushFrameback to summary
public Arena pushFrame(MemoryLayout layout)

Returns a new Arena that tries to provide layout allocations by recycling the BufferStack's internal memory.

Parameters
layout:MemoryLayout

for which to reserve internal memory

Returns:Arena

a new Arena that tries to provide layout allocations by recycling the BufferStack's internal memory

Annotations
@ForceInline
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
jdk.internal.foreign back to summary

private final Record BufferStack.PerThread

extends Record
Class Inheritance
Record Components
lock:ReentrantLock 
arena:Arena 
stack:SlicingAllocator 
cleanupAction:BufferStack.PerThread.CleanupAction 

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
private class

Field Summary

Modifier and TypeField and Description
private final Arena
arena

Record Component accessed by arena().

private final BufferStack.PerThread.CleanupAction
cleanupAction

Record Component accessed by cleanupAction().

private final ReentrantLock
lock

Record Component accessed by lock().

private final SlicingAllocator
stack

Record Component accessed by stack().

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Arena
arena()

Record Component getter of arena.

public BufferStack.PerThread.CleanupAction
cleanupAction()

Record Component getter of cleanupAction.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public ReentrantLock
lock()

Record Component getter of lock.

pack-priv static BufferStack.PerThread
of(long byteSize, long byteAlignment)

public Arena
pushFrame(long size, long byteAlignment)

public SlicingAllocator
stack()

Record Component getter of stack.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

arenaback to summary
private final Arena arena

Record Component accessed by arena().

cleanupActionback to summary
private final BufferStack.PerThread.CleanupAction cleanupAction

Record Component accessed by cleanupAction().

lockback to summary
private final ReentrantLock lock

Record Component accessed by lock().

stackback to summary
private final SlicingAllocator stack

Record Component accessed by stack().

Constructor Detail

PerThreadback to summary
private PerThread(ReentrantLock lock, Arena arena, SlicingAllocator stack, BufferStack.PerThread.CleanupAction cleanupAction)

Method Detail

arenaback to summary
public Arena arena()

Record Component getter of arena.

cleanupActionback to summary
public BufferStack.PerThread.CleanupAction cleanupAction()

Record Component getter of cleanupAction.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

lockback to summary
public ReentrantLock lock()

Record Component getter of lock.

ofback to summary
pack-priv static BufferStack.PerThread of(long byteSize, long byteAlignment)
pushFrameback to summary
public Arena pushFrame(long size, long byteAlignment)
Annotations
@ForceInline
stackback to summary
public SlicingAllocator stack()

Record Component getter of stack.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

jdk.internal.foreign back to summary

private final Record BufferStack.PerThread.CleanupAction

extends Record
implements Consumer<MemorySegment>
Class Inheritance
All Implemented Interfaces
java.util.function.Consumer
Record Components
arena:Arena 

Field Summary

Modifier and TypeField and Description
private final Arena
arena

Record Component accessed by arena().

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
accept(MemorySegment memorySegment)

Implements java.util.function.Consumer.accept.

Performs this operation on the given argument.

public Arena
arena()

Record Component getter of arena.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

arenaback to summary
private final Arena arena

Record Component accessed by arena().

Constructor Detail

CleanupActionback to summary
private CleanupAction(Arena arena)

Method Detail

acceptback to summary
public void accept(MemorySegment memorySegment)

Implements java.util.function.Consumer.accept.

Doc from java.util.function.Consumer.accept.

Performs this operation on the given argument.

Annotations
@Override
arenaback to summary
public Arena arena()

Record Component getter of arena.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

jdk.internal.foreign back to summary

private final Class BufferStack.PerThread.Frame

extends Object
implements Arena
Class Inheritance
All Implemented Interfaces
java.lang.foreign.Arena, java.lang.AutoCloseable, java.lang.foreign.SegmentAllocator

Field Summary

Modifier and TypeField and Description
private final Arena
private final SegmentAllocator
private final boolean
private final long
private final long

Constructor Summary

AccessConstructor and Description
public
Frame(boolean locked, long byteSize, long byteAlignment)

Method Summary

Modifier and TypeMethod and Description
public MemorySegment
allocate(long byteSize, long byteAlignment)

Implements java.lang.foreign.Arena.allocate.

Returns a native memory segment with the given size (in bytes) and alignment constraint (in bytes).

private void
public void
close()

Implements java.lang.foreign.Arena.close.

Closes this arena.

public MemorySegment.Scope
scope()

Implements java.lang.foreign.Arena.scope.

Returns the arena scope.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

confinedArenaback to summary
private final Arena confinedArena
frameback to summary
private final SegmentAllocator frame
lockedback to summary
private final boolean locked
parentOffsetback to summary
private final long parentOffset
topOfStackback to summary
private final long topOfStack

Constructor Detail

Frameback to summary
public Frame(boolean locked, long byteSize, long byteAlignment)
Annotations
@SuppressWarnings:restricted
@ForceInline

Method Detail

allocateback to summary
public MemorySegment allocate(long byteSize, long byteAlignment)

Implements java.lang.foreign.Arena.allocate.

Doc from java.lang.foreign.Arena.allocate.

Returns a native memory segment with the given size (in bytes) and alignment constraint (in bytes). The returned segment is associated with this arena scope. The segment's address is the starting address of the allocated off-heap region of memory backing the segment, and the address is aligned according the provided alignment constraint.

Annotations
@ForceInline
@Override
@SuppressWarnings:restricted
assertOrderback to summary
private void assertOrder()
Annotations
@ForceInline
closeback to summary
public void close()

Implements java.lang.foreign.Arena.close.

Doc from java.lang.foreign.Arena.close.

Closes this arena. If this method completes normally, the arena scope is no longer alive, and all the memory segments associated with it can no longer be accessed. Furthermore, any off-heap region of memory backing the segments obtained from this arena are also released.

Annotations
@ForceInline
@Override
scopeback to summary
public MemorySegment.Scope scope()

Implements java.lang.foreign.Arena.scope.

Doc from java.lang.foreign.Arena.scope.

Returns the arena scope.

Annotations
@ForceInline
@Override