/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
class Util {
// -- Caches --
// The number of temp buffers in our pool
// Per-thread cache of temporary direct buffers
new ThreadLocal<BufferCache>()
{
protected BufferCache initialValue() {
return new BufferCache();
}
};
/**
* A simple cache of direct buffers.
*/
private static class BufferCache {
// the array of buffers
// the number of buffers in the cache
private int count;
// the index of the first valid buffer (undefined if count == 0)
private int start;
private int next(int i) {
return (i + 1) % TEMP_BUF_POOL_SIZE;
}
BufferCache() {
}
/**
* Removes and returns a buffer from the cache of at least the given
* size (or null if no suitable buffer is found).
*/
if (count == 0)
return null; // cache is empty
// search for suitable buffer (often the first buffer will do)
int i = start;
break;
break;
}
}
return null;
// move first element to here to avoid re-packing
}
// remove first element
count--;
// prepare the buffer and return it
return buf;
}
if (count >= TEMP_BUF_POOL_SIZE) {
return false;
} else {
count++;
return true;
}
}
if (count >= TEMP_BUF_POOL_SIZE) {
return false;
} else {
count++;
return true;
}
}
boolean isEmpty() {
return count == 0;
}
assert count > 0;
count--;
return buf;
}
}
/**
* Returns a temporary buffer of at least the given size
*/
return buf;
} else {
// No suitable buffer in the cache so we need to allocate a new
// one. To avoid the cache growing then we remove the first
// buffer from the cache and free it.
}
}
}
/**
* Releases a temporary buffer by returning to the cache or freeing it.
*/
}
/**
* 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.
*/
// cache is full
}
}
/**
* 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
* cache in same order that they were obtained.
*/
// cache is full
}
}
/**
* Frees the memory for the given direct buffer
*/
}
private static class SelectorWrapper {
}
}
public void run () {
try {
}
}
}
}
// Per-thread cached selector
// Hold a reference to the selWrapper object to prevent it from
// being cleaned when the temporary selector wrapped is on lease.
= new ThreadLocal<SelectorWrapper>();
// When finished, invoker must ensure that selector is empty
// by cancelling any related keys and explicitly releasing
// the selector by invoking releaseTemporarySelector()
throws IOException
{
}
return sel;
}
throws IOException
{
// Selector should be empty
}
// -- Random stuff --
return bs;
int n = length;
for (int i = 0; i < n; i++)
return bs2;
}
return new Set<E>() {
return s.containsAll(coll);
}
}
}
public boolean add(E o){
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
};
}
// -- Unsafe access --
private static byte _get(long a) {
}
private static void _put(long a, byte b) {
}
}
return unsafe;
}
static int pageSize() {
if (pageSize == -1)
return pageSize;
}
private static void initDBBConstructor() {
try {
new Class[] { int.class,
long.class,
FileDescriptor.class,
Runnable.class });
ctor.setAccessible(true);
} catch (ClassNotFoundException x) {
throw new InternalError();
} catch (NoSuchMethodException x) {
throw new InternalError();
} catch (IllegalArgumentException x) {
throw new InternalError();
} catch (ClassCastException x) {
throw new InternalError();
}
return null;
}});
}
{
if (directByteBufferConstructor == null)
try {
fd,
unmapper });
} catch (InstantiationException e) {
throw new InternalError();
} catch (IllegalAccessException e) {
throw new InternalError();
} catch (InvocationTargetException e) {
throw new InternalError();
}
return dbb;
}
private static void initDBBRConstructor() {
try {
new Class[] { int.class,
long.class,
FileDescriptor.class,
Runnable.class });
ctor.setAccessible(true);
} catch (ClassNotFoundException x) {
throw new InternalError();
} catch (NoSuchMethodException x) {
throw new InternalError();
} catch (IllegalArgumentException x) {
throw new InternalError();
} catch (ClassCastException x) {
throw new InternalError();
}
return null;
}});
}
{
if (directByteBufferRConstructor == null)
try {
fd,
unmapper });
} catch (InstantiationException e) {
throw new InternalError();
} catch (IllegalAccessException e) {
throw new InternalError();
} catch (InvocationTargetException e) {
throw new InternalError();
}
return dbb;
}
// -- Bug compatibility --
return false;
new GetPropertyAction("sun.nio.ch.bugLevel"));
}
}
// -- Initialization --
private static boolean loaded = false;
static void load() {
synchronized (Util.class) {
if (loaded)
return;
loaded = true;
// IOUtil must be initialized; Its native methods are called from
// other places in native nio code so they must be set up.
}
}
}