Modified to do the method lookups on first class
access and removed the (now) unnecessary threading synchronization stuff. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9528 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
1d6fc2f9d6
commit
d649505a6c
@ -1145,7 +1145,6 @@ public final class BufferUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -1165,14 +1164,7 @@ public final class BufferUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadCleanerMethods() {
|
static {
|
||||||
// If its already true, exit, if not, set it to true.
|
|
||||||
if (loadedMethods.getAndSet(true)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// This could potentially be called many times if used from multiple
|
|
||||||
// threads
|
|
||||||
synchronized (loadedMethods) {
|
|
||||||
// Oracle JRE / OpenJDK
|
// Oracle JRE / OpenJDK
|
||||||
cleanerMethod = loadMethod("sun.nio.ch.DirectBuffer", "cleaner");
|
cleanerMethod = loadMethod("sun.nio.ch.DirectBuffer", "cleaner");
|
||||||
cleanMethod = loadMethod("sun.misc.Cleaner", "clean");
|
cleanMethod = loadMethod("sun.misc.Cleaner", "clean");
|
||||||
@ -1191,7 +1183,6 @@ public final class BufferUtils {
|
|||||||
} catch (SecurityException ex) {
|
} catch (SecurityException ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct buffers are garbage collected by using a phantom reference and a
|
* Direct buffers are garbage collected by using a phantom reference and a
|
||||||
@ -1210,8 +1201,6 @@ public final class BufferUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadCleanerMethods();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (freeMethod != null) {
|
if (freeMethod != null) {
|
||||||
freeMethod.invoke(toBeDestroyed);
|
freeMethod.invoke(toBeDestroyed);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user