< prev index next >

src/java.base/share/classes/sun/nio/ch/Util.java

Print this page
rev 50306 : imported patch loom-fibers

*** 33,60 **** import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Collection; import java.util.Iterator; import java.util.Set; import jdk.internal.misc.Unsafe; import sun.security.action.GetPropertyAction; import java.io.IOException; public class Util { // -- Caches -- // The number of temp buffers in our pool private static final int TEMP_BUF_POOL_SIZE = IOUtil.IOV_MAX; // The max size allowed for a cached temp buffer, in bytes private static final long MAX_CACHED_BUFFER_SIZE = getMaxCachedBufferSize(); // Per-thread cache of temporary direct buffers ! private static ThreadLocal<BufferCache> bufferCache = ! new ThreadLocal<BufferCache>() ! { @Override protected BufferCache initialValue() { return new BufferCache(); } }; --- 33,62 ---- import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Collection; import java.util.Iterator; import java.util.Set; + + import jdk.internal.misc.JavaLangAccess; + import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.Unsafe; import sun.security.action.GetPropertyAction; import java.io.IOException; public class Util { + private static JavaLangAccess JLA = SharedSecrets.getJavaLangAccess(); // -- Caches -- // The number of temp buffers in our pool private static final int TEMP_BUF_POOL_SIZE = IOUtil.IOV_MAX; // The max size allowed for a cached temp buffer, in bytes private static final long MAX_CACHED_BUFFER_SIZE = getMaxCachedBufferSize(); // Per-thread cache of temporary direct buffers ! private static ThreadLocal<BufferCache> bufferCache = new ThreadLocal<>() { @Override protected BufferCache initialValue() { return new BufferCache(); } };
*** 218,228 **** // below) given that we won't put the new buffer in the cache. if (isBufferTooLarge(size)) { return ByteBuffer.allocateDirect(size); } ! BufferCache cache = bufferCache.get(); ByteBuffer buf = cache.get(size); if (buf != null) { return buf; } else { // No suitable buffer in the cache so we need to allocate a new --- 220,230 ---- // below) given that we won't put the new buffer in the cache. if (isBufferTooLarge(size)) { return ByteBuffer.allocateDirect(size); } ! BufferCache cache = JLA.getKernelThreadLocal(bufferCache); ByteBuffer buf = cache.get(size); if (buf != null) { return buf; } else { // No suitable buffer in the cache so we need to allocate a new
*** 245,255 **** if (isBufferTooLarge(size)) { return ByteBuffer.allocateDirect(size + alignment - 1) .alignedSlice(alignment); } ! BufferCache cache = bufferCache.get(); ByteBuffer buf = cache.get(size); if (buf != null) { if (buf.alignmentOffset(0, alignment) == 0) { return buf; } --- 247,257 ---- if (isBufferTooLarge(size)) { return ByteBuffer.allocateDirect(size + alignment - 1) .alignedSlice(alignment); } ! BufferCache cache = JLA.getKernelThreadLocal(bufferCache); ByteBuffer buf = cache.get(size); if (buf != null) { if (buf.alignmentOffset(0, alignment) == 0) { return buf; }
*** 282,292 **** free(buf); return; } assert buf != null; ! BufferCache cache = bufferCache.get(); if (!cache.offerFirst(buf)) { // cache is full free(buf); } } --- 284,294 ---- free(buf); return; } assert buf != null; ! BufferCache cache = JLA.getKernelThreadLocal(bufferCache); if (!cache.offerFirst(buf)) { // cache is full free(buf); } }
*** 304,314 **** free(buf); return; } assert buf != null; ! BufferCache cache = bufferCache.get(); if (!cache.offerLast(buf)) { // cache is full free(buf); } } --- 306,316 ---- free(buf); return; } assert buf != null; ! BufferCache cache = JLA.getKernelThreadLocal(bufferCache); if (!cache.offerLast(buf)) { // cache is full free(buf); } }
< prev index next >