commit
a416eafec5
@ -51,7 +51,6 @@ import java.nio.IntBuffer;
|
|||||||
import java.nio.LongBuffer;
|
import java.nio.LongBuffer;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -1268,7 +1267,6 @@ public final class BufferUtils {
|
|||||||
System.out.println(store.toString());
|
System.out.println(store.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static final AtomicBoolean loadedMethods = new AtomicBoolean(false);
|
|
||||||
private static Method cleanerMethod = null;
|
private static Method cleanerMethod = null;
|
||||||
private static Method cleanMethod = null;
|
private static Method cleanMethod = null;
|
||||||
private static Method viewedBufferMethod = null;
|
private static Method viewedBufferMethod = null;
|
||||||
@ -1288,31 +1286,23 @@ public final class BufferUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadCleanerMethods() {
|
static {
|
||||||
// If its already true, exit, if not, set it to true.
|
// Oracle JRE / OpenJDK
|
||||||
if (BufferUtils.loadedMethods.getAndSet(true)) {
|
cleanerMethod = loadMethod("sun.nio.ch.DirectBuffer", "cleaner");
|
||||||
return;
|
cleanMethod = loadMethod("sun.misc.Cleaner", "clean");
|
||||||
|
viewedBufferMethod = loadMethod("sun.nio.ch.DirectBuffer", "viewedBuffer");
|
||||||
|
if (viewedBufferMethod == null) {
|
||||||
|
// They changed the name in Java 7 (???)
|
||||||
|
viewedBufferMethod = loadMethod("sun.nio.ch.DirectBuffer", "attachment");
|
||||||
}
|
}
|
||||||
// This could potentially be called many times if used from multiple
|
|
||||||
// threads
|
|
||||||
synchronized (BufferUtils.loadedMethods) {
|
|
||||||
// Oracle JRE / OpenJDK
|
|
||||||
cleanerMethod = loadMethod("sun.nio.ch.DirectBuffer", "cleaner");
|
|
||||||
cleanMethod = loadMethod("sun.misc.Cleaner", "clean");
|
|
||||||
viewedBufferMethod = loadMethod("sun.nio.ch.DirectBuffer", "viewedBuffer");
|
|
||||||
if (viewedBufferMethod == null) {
|
|
||||||
// They changed the name in Java 7 (???)
|
|
||||||
viewedBufferMethod = loadMethod("sun.nio.ch.DirectBuffer", "attachment");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apache Harmony
|
// Apache Harmony
|
||||||
ByteBuffer bb = BufferUtils.createByteBuffer(1);
|
ByteBuffer bb = BufferUtils.createByteBuffer(1);
|
||||||
Class<?> clazz = bb.getClass();
|
Class<?> clazz = bb.getClass();
|
||||||
try {
|
try {
|
||||||
freeMethod = clazz.getMethod("free");
|
freeMethod = clazz.getMethod("free");
|
||||||
} catch (NoSuchMethodException ex) {
|
} catch (NoSuchMethodException ex) {
|
||||||
} catch (SecurityException ex) {
|
} catch (SecurityException ex) {
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1333,8 +1323,6 @@ public final class BufferUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferUtils.loadCleanerMethods();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (freeMethod != null) {
|
if (freeMethod != null) {
|
||||||
freeMethod.invoke(toBeDestroyed);
|
freeMethod.invoke(toBeDestroyed);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user