APIdia Launch Partner
Top Inners Fields Constructors Methods
sun.nio.ch

public Class Util

extends Object
Class Inheritance
Imports
java.io.FileDescriptor, .IOException, java.lang.foreign.MemorySegment, java.lang.reflect.Constructor, .InvocationTargetException, java.nio.ByteBuffer, .MappedByteBuffer, java.util.Collection, .Iterator, .Set, jdk.internal.access.JavaNioAccess, .SharedSecrets, jdk.internal.misc.TerminatingThreadLocal, .Unsafe

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Util.BufferCache

A simple cache of direct buffers.

Field Summary

Modifier and TypeField and Description
private static final TerminatingThreadLocal<Util.BufferCache>
private static volatile Constructor<?>
private static volatile Constructor<?>
private static final long
private static final JavaNioAccess
private static int
private static final int
private static final Unsafe

Constructor Summary

AccessConstructor and Description
public
Util()

Method Summary

Modifier and TypeMethod and Description
private static byte
_get(long a)

private static void
_put(long a, byte b)

pack-priv static void
checkBufferPositionAligned(ByteBuffer bb, int pos, int alignment)

pack-priv static void
checkChannelPositionAligned(long position, int alignment)

pack-priv static void
checkRemainingBufferSizeAligned(int rem, int alignment)

pack-priv static void
private static void
free(ByteBuffer buf)

Frees the memory for the given direct buffer

private static long
getMaxCachedBufferSize()

Returns the max size allowed for a cached temp buffers, in bytes.

public static ByteBuffer
getTemporaryAlignedDirectBuffer(int size, int alignment)

Returns a temporary buffer of at least the given size and aligned to the alignment

public static ByteBuffer
getTemporaryDirectBuffer(int size)

Returns a temporary buffer of at least the given size

private static void
private static void
private static boolean
isBufferTooLarge(int size)

Returns true if a buffer of this size is too large to be added to the buffer cache, false otherwise.

private static boolean
isBufferTooLarge(ByteBuffer buf)

Returns true if the buffer is too large to be added to the buffer cache, false otherwise.

pack-priv static MappedByteBuffer
newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync)

pack-priv static MappedByteBuffer
newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync)

pack-priv static void
offerFirstTemporaryDirectBuffer(ByteBuffer buf)

Releases a temporary buffer by returning to the cache or freeing it.

pack-priv static void
offerLastTemporaryDirectBuffer(ByteBuffer buf)

Releases a temporary buffer by returning to the cache or freeing it.

pack-priv static int
public static void
releaseTemporaryDirectBuffer(ByteBuffer buf)

Releases a temporary buffer by returning to the cache or freeing it.

pack-priv static ByteBuffer[]
subsequence(ByteBuffer[] bs, int offset, int length)

pack-priv static <E> Set<E>
ungrowableSet(final Set<E> s)

pack-priv static Unsafe
private static ByteBuffer
unwrapIfAlignedSlice(ByteBuffer buf)

Return the underling byte buffer if the given byte buffer is an aligned slice.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferCacheback to summary
private static final TerminatingThreadLocal<Util.BufferCache> bufferCache
directByteBufferConstructorback to summary
private static volatile Constructor<?> directByteBufferConstructor
directByteBufferRConstructorback to summary
private static volatile Constructor<?> directByteBufferRConstructor
MAX_CACHED_BUFFER_SIZEback to summary
private static final long MAX_CACHED_BUFFER_SIZE
NIO_ACCESSback to summary
private static final JavaNioAccess NIO_ACCESS
pageSizeback to summary
private static int pageSize
TEMP_BUF_POOL_SIZEback to summary
private static final int TEMP_BUF_POOL_SIZE
unsafeback to summary
private static final Unsafe unsafe

Constructor Detail

Utilback to summary
public Util()

Method Detail

_getback to summary
private static byte _get(long a)
_putback to summary
private static void _put(long a, byte b)
checkBufferPositionAlignedback to summary
pack-priv static void checkBufferPositionAligned(ByteBuffer bb, int pos, int alignment) throws IOException
checkChannelPositionAlignedback to summary
pack-priv static void checkChannelPositionAligned(long position, int alignment) throws IOException
checkRemainingBufferSizeAlignedback to summary
pack-priv static void checkRemainingBufferSizeAligned(int rem, int alignment) throws IOException
eraseback to summary
pack-priv static void erase(ByteBuffer bb)
freeback to summary
private static void free(ByteBuffer buf)

Frees the memory for the given direct buffer

getMaxCachedBufferSizeback to summary
private static long getMaxCachedBufferSize()

Returns the max size allowed for a cached temp buffers, in bytes. It defaults to Long.MAX_VALUE. It can be set with the jdk.nio.maxCachedBufferSize property. Even though ByteBuffer.capacity() returns an int, we're using a long here for potential future-proofing.

getTemporaryAlignedDirectBufferback to summary
public static ByteBuffer getTemporaryAlignedDirectBuffer(int size, int alignment)

Returns a temporary buffer of at least the given size and aligned to the alignment

getTemporaryDirectBufferback to summary
public static ByteBuffer getTemporaryDirectBuffer(int size)

Returns a temporary buffer of at least the given size

initDBBConstructorback to summary
private static void initDBBConstructor()
initDBBRConstructorback to summary
private static void initDBBRConstructor()
isBufferTooLargeback to summary
private static boolean isBufferTooLarge(int size)

Returns true if a buffer of this size is too large to be added to the buffer cache, false otherwise.

isBufferTooLargeback to summary
private static boolean isBufferTooLarge(ByteBuffer buf)

Returns true if the buffer is too large to be added to the buffer cache, false otherwise.

newMappedByteBufferback to summary
pack-priv static MappedByteBuffer newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync)
newMappedByteBufferRback to summary
pack-priv static MappedByteBuffer newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync)
offerFirstTemporaryDirectBufferback to summary
pack-priv static void offerFirstTemporaryDirectBuffer(ByteBuffer buf)

Releases a temporary buffer by returning to the cache or freeing it. If returning to the cache then insert it at the start so that it is likely to be returned by a subsequent call to getTemporaryDirectBuffer.

offerLastTemporaryDirectBufferback to summary
pack-priv static void offerLastTemporaryDirectBuffer(ByteBuffer buf)

Releases a temporary buffer by returning to the cache or freeing it. If returning to the cache then insert it at the end. This makes it suitable for scatter/gather operations where the buffers are returned to cache in same order that they were obtained.

pageSizeback to summary
pack-priv static int pageSize()
releaseTemporaryDirectBufferback to summary
public static void releaseTemporaryDirectBuffer(ByteBuffer buf)

Releases a temporary buffer by returning to the cache or freeing it.

subsequenceback to summary
pack-priv static ByteBuffer[] subsequence(ByteBuffer[] bs, int offset, int length)
ungrowableSetback to summary
pack-priv static <E> Set<E> ungrowableSet(final Set<E> s)
unsafeback to summary
pack-priv static Unsafe unsafe()
unwrapIfAlignedSliceback to summary
private static ByteBuffer unwrapIfAlignedSlice(ByteBuffer buf)

Return the underling byte buffer if the given byte buffer is an aligned slice.

sun.nio.ch back to summary

private Class Util.BufferCache

extends Object
Class Inheritance

A simple cache of direct buffers.

Field Summary

Modifier and TypeField and Description
private final ByteBuffer[]
private int
private int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv ByteBuffer
get(int size)

Removes and returns a buffer from the cache of at least the given size (or null if no suitable buffer is found).

pack-priv boolean
private int
next(int i)

pack-priv boolean
pack-priv boolean
pack-priv ByteBuffer
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

buffersback to summary
private final ByteBuffer[] buffers
countback to summary
private int count
startback to summary
private int start

Constructor Detail

BufferCacheback to summary
pack-priv BufferCache()

Method Detail

getback to summary
pack-priv ByteBuffer get(int size)

Removes and returns a buffer from the cache of at least the given size (or null if no suitable buffer is found).

isEmptyback to summary
pack-priv boolean isEmpty()
nextback to summary
private int next(int i)
offerFirstback to summary
pack-priv boolean offerFirst(ByteBuffer buf)
offerLastback to summary
pack-priv boolean offerLast(ByteBuffer buf)
removeFirstback to summary
pack-priv ByteBuffer removeFirst()