< prev index next >
src/java.base/share/classes/sun/nio/fs/NativeBuffers.java
Print this page
rev 50306 : imported patch loom-fibers
*** 23,47 ****
* questions.
*/
package sun.nio.fs;
import jdk.internal.misc.Unsafe;
/**
* Factory for native buffers.
*/
class NativeBuffers {
! private NativeBuffers() { }
private static final Unsafe unsafe = Unsafe.getUnsafe();
private static final int TEMP_BUF_POOL_SIZE = 3;
private static ThreadLocal<NativeBuffer[]> threadLocal =
new ThreadLocal<NativeBuffer[]>();
/**
* Allocates a native buffer, of at least the given size, from the heap.
*/
static NativeBuffer allocNativeBuffer(int size) {
// Make a new one of at least 2k
--- 23,51 ----
* questions.
*/
package sun.nio.fs;
+ import jdk.internal.misc.JavaLangAccess;
+ import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.Unsafe;
/**
* Factory for native buffers.
*/
class NativeBuffers {
! private static JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
private static final Unsafe unsafe = Unsafe.getUnsafe();
private static final int TEMP_BUF_POOL_SIZE = 3;
private static ThreadLocal<NativeBuffer[]> threadLocal =
new ThreadLocal<NativeBuffer[]>();
+ private NativeBuffers() { }
+
/**
* Allocates a native buffer, of at least the given size, from the heap.
*/
static NativeBuffer allocNativeBuffer(int size) {
// Make a new one of at least 2k
*** 53,63 ****
* Returns a native buffer, of at least the given size, from the thread
* local cache.
*/
static NativeBuffer getNativeBufferFromCache(int size) {
// return from cache if possible
! NativeBuffer[] buffers = threadLocal.get();
if (buffers != null) {
for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) {
NativeBuffer buffer = buffers[i];
if (buffer != null && buffer.size() >= size) {
buffers[i] = null;
--- 57,67 ----
* Returns a native buffer, of at least the given size, from the thread
* local cache.
*/
static NativeBuffer getNativeBufferFromCache(int size) {
// return from cache if possible
! NativeBuffer[] buffers = JLA.getKernelThreadLocal(threadLocal);
if (buffers != null) {
for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) {
NativeBuffer buffer = buffers[i];
if (buffer != null && buffer.size() >= size) {
buffers[i] = null;
*** 87,97 ****
* Releases the given buffer. If there is space in the thread local cache
* then the buffer goes into the cache; otherwise the memory is deallocated.
*/
static void releaseNativeBuffer(NativeBuffer buffer) {
// create cache if it doesn't exist
! NativeBuffer[] buffers = threadLocal.get();
if (buffers == null) {
buffers = new NativeBuffer[TEMP_BUF_POOL_SIZE];
buffers[0] = buffer;
threadLocal.set(buffers);
return;
--- 91,101 ----
* Releases the given buffer. If there is space in the thread local cache
* then the buffer goes into the cache; otherwise the memory is deallocated.
*/
static void releaseNativeBuffer(NativeBuffer buffer) {
// create cache if it doesn't exist
! NativeBuffer[] buffers = JLA.getKernelThreadLocal(threadLocal);
if (buffers == null) {
buffers = new NativeBuffer[TEMP_BUF_POOL_SIZE];
buffers[0] = buffer;
threadLocal.set(buffers);
return;
< prev index next >