Top Description Fields Constructors Methods
io.netty5.buffer.unsafe

public final Class UnsafeMemoryManager

extends Object
implements MemoryManager
Class Inheritance
All Implemented Interfaces
io.netty5.buffer.MemoryManager
Imports
io.netty5.buffer.AllocationType, .AllocatorControl, .BufferAllocator, .DefaultBufferAllocators, .Buffer, .Drop, .MemoryManager, .StandardAllocationTypes, io.netty5.buffer.internal.ArcDrop, .InternalBufferUtils, .WrappingAllocation, io.netty5.util.internal.PlatformDependent, .SystemPropertyUtil, java.lang.ref.Cleaner, java.util.function.Function

This memory manager produces and manages Buffer instances that are using Unsafe to allocate and access memory.

Memory managers are normally not used directly. Instead, you likely want to use the DefaultBufferAllocators, or the static methods on BufferAllocator.

Field Summary

Modifier and TypeField and Description
private static final boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Buffer
allocateConstChild(Buffer
The read-only parent buffer for which a const buffer should be created. The parent buffer is allocated in the usual way, with allocateShared(AllocatorControl, long, Function, AllocationType), initialised with contents, and then made read-only.
readOnlyConstParent
)

Implements io.netty5.buffer.MemoryManager.allocateConstChild.

Allocates a constant buffer based on the given parent.
public Buffer
allocateShared(AllocatorControl
Call-back interface for controlling the allocator that requested the allocation of this buffer.
control
,
long
The size of the buffer to allocate. This size is assumed to be valid for the implementation.
size
,
Function<Drop<Buffer>, Drop<Buffer>>
A function to decorate the memory managers Drop instance. The Drop instance returned by this function will be used when the buffer is closed.
dropDecorator
,
AllocationType
The type of allocation to perform. Typically, one of the StandardAllocationTypes.
allocationType
)

Implements io.netty5.buffer.MemoryManager.allocateShared.

Allocates a shared buffer.
public void
clearMemory(Object
The memory that should be overwritten.
memory
)

Implements io.netty5.buffer.MemoryManager.clearMemory.

Overwrite the given recoverable memory object with zeroes, erasing all data that it contains.
private static UnsafeBuffer
createBuffer(UnsafeMemory memory, int size, AllocatorControl allocatorControl, Drop<Buffer> drop)

public String
implementationName()

Implements io.netty5.buffer.MemoryManager.implementationName.

Get the name for this implementation, which can be used for finding this particular implementation via the lookupImplementation(String) method.
public Buffer
recoverMemory(AllocatorControl
The allocator control to attach to the buffer.
allocatorControl
,
Object
The opaque memory to use for the buffer.
recoverableMemory
,
Drop<Buffer>
The Drop instance to use when the buffer is closed.
drop
)

Implements io.netty5.buffer.MemoryManager.recoverMemory.

Recover the memory from a prior unwrapRecoverableMemory(Buffer) call, and wrap it in a Buffer instance.
public Object
sliceMemory(Object
The opaque memory to slice.
memory
,
int
The offset into the memory to slice from.
offset
,
int
The length of the slice.
length
)

Implements io.netty5.buffer.MemoryManager.sliceMemory.

Produces a slice of the given internal memory representation object.
public Object
unwrapRecoverableMemory(Buffer
The buffer to unwrap.
buf
)

Implements io.netty5.buffer.MemoryManager.unwrapRecoverableMemory.

Create an object that represents the internal memory of the given buffer.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FREE_IMMEDIATELYback to summary
private static final boolean FREE_IMMEDIATELY

Constructor Detail

UnsafeMemoryManagerback to summary
public UnsafeMemoryManager()

Method Detail

allocateConstChildback to summary
public Buffer allocateConstChild(Buffer readOnlyConstParent)

Implements io.netty5.buffer.MemoryManager.allocateConstChild.

Doc from io.netty5.buffer.MemoryManager.allocateConstChild.

Allocates a constant buffer based on the given parent. A "constant" buffer is conceptually similar to a read-only buffer, but the implementation may share the underlying memory across multiple buffer instance - something that is normally not allowed by the API. This allows efficient implementation of the BufferAllocator#constBufferSupplier(byte[]) method.

Note

The const-parent buffer must be allocated by this memory manager.

Parameters
readOnlyConstParent:Buffer

The read-only parent buffer for which a const buffer should be created. The parent buffer is allocated in the usual way, with allocateShared(AllocatorControl, long, Function, AllocationType), initialised with contents, and then made read-only.

Returns:Buffer

A const buffer with the same size, contents, and read-only state of the given parent buffer.

Annotations
@Override
allocateSharedback to summary
public Buffer allocateShared(AllocatorControl control, long size, Function<Drop<Buffer>, Drop<Buffer>> dropDecorator, AllocationType allocationType)

Implements io.netty5.buffer.MemoryManager.allocateShared.

Doc from io.netty5.buffer.MemoryManager.allocateShared.

Allocates a shared buffer. "Shared" is the normal type of buffer, and means the buffer permit concurrent access from multiple threads, within the limited thread-safety guarantees of the Buffer interface.

Parameters
control:AllocatorControl

Call-back interface for controlling the allocator that requested the allocation of this buffer.

size:long

The size of the buffer to allocate. This size is assumed to be valid for the implementation.

dropDecorator:Function<Drop<Buffer>, Drop<Buffer>>

A function to decorate the memory managers Drop instance. The Drop instance returned by this function will be used when the buffer is closed.

allocationType:AllocationType

The type of allocation to perform. Typically, one of the StandardAllocationTypes.

Returns:Buffer

A Buffer instance with the given configuration.

Annotations
@Override
clearMemoryback to summary
public void clearMemory(Object memory)

Implements io.netty5.buffer.MemoryManager.clearMemory.

Doc from io.netty5.buffer.MemoryManager.clearMemory.

Overwrite the given recoverable memory object with zeroes, erasing all data that it contains.

This is used by the SensitiveBufferAllocator to erase data on deallocation.

Parameters
memory:Object

The memory that should be overwritten.

Annotations
@Override
createBufferback to summary
private static UnsafeBuffer createBuffer(UnsafeMemory memory, int size, AllocatorControl allocatorControl, Drop<Buffer> drop)
implementationNameback to summary
public String implementationName()

Implements io.netty5.buffer.MemoryManager.implementationName.

Doc from io.netty5.buffer.MemoryManager.implementationName.

Get the name for this implementation, which can be used for finding this particular implementation via the lookupImplementation(String) method.

Returns:String

The name of this memory managers implementation.

Annotations
@Override
recoverMemoryback to summary
public Buffer recoverMemory(AllocatorControl allocatorControl, Object recoverableMemory, Drop<Buffer> drop)

Implements io.netty5.buffer.MemoryManager.recoverMemory.

Doc from io.netty5.buffer.MemoryManager.recoverMemory.

Recover the memory from a prior unwrapRecoverableMemory(Buffer) call, and wrap it in a Buffer instance.

Parameters
allocatorControl:AllocatorControl

The allocator control to attach to the buffer.

recoverableMemory:Object

The opaque memory to use for the buffer.

drop:Drop<Buffer>

The Drop instance to use when the buffer is closed.

Returns:Buffer

A Buffer instance backed by the given recovered memory.

Annotations
@Override
sliceMemoryback to summary
public Object sliceMemory(Object memory, int offset, int length)

Implements io.netty5.buffer.MemoryManager.sliceMemory.

Doc from io.netty5.buffer.MemoryManager.sliceMemory.

Produces a slice of the given internal memory representation object.

Parameters
memory:Object

The opaque memory to slice.

offset:int

The offset into the memory to slice from.

length:int

The length of the slice.

Returns:Object

A new opaque memory instance that represents the given slice of the original.

Annotations
@Override
unwrapRecoverableMemoryback to summary
public Object unwrapRecoverableMemory(Buffer buf)

Implements io.netty5.buffer.MemoryManager.unwrapRecoverableMemory.

Doc from io.netty5.buffer.MemoryManager.unwrapRecoverableMemory.

Create an object that represents the internal memory of the given buffer.

Parameters
buf:Buffer

The buffer to unwrap.

Returns:Object

The internal memory of the given buffer, as an opaque object.

Annotations
@Override