From d649505a6cf7f632319c51a0aa2518f10bcf21f1 Mon Sep 17 00:00:00 2001 From: "PSp..om" Date: Tue, 26 Jun 2012 06:58:59 +0000 Subject: [PATCH] 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 --- .../src/core/com/jme3/util/BufferUtils.java | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/engine/src/core/com/jme3/util/BufferUtils.java b/engine/src/core/com/jme3/util/BufferUtils.java index c96ee47f2..36bfb93ce 100644 --- a/engine/src/core/com/jme3/util/BufferUtils.java +++ b/engine/src/core/com/jme3/util/BufferUtils.java @@ -1145,7 +1145,6 @@ public final class BufferUtils { } } - private static final AtomicBoolean loadedMethods = new AtomicBoolean(false); private static Method cleanerMethod = null; private static Method cleanMethod = null; private static Method viewedBufferMethod = null; @@ -1165,31 +1164,23 @@ public final class BufferUtils { } } - private static void loadCleanerMethods() { - // If its already true, exit, if not, set it to true. - if (loadedMethods.getAndSet(true)) { - return; + static { + // 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"); } - // This could potentially be called many times if used from multiple - // threads - synchronized (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 - ByteBuffer bb = BufferUtils.createByteBuffer(1); - Class clazz = bb.getClass(); - try { - freeMethod = clazz.getMethod("free"); - } catch (NoSuchMethodException ex) { - } catch (SecurityException ex) { - } + // Apache Harmony + ByteBuffer bb = BufferUtils.createByteBuffer(1); + Class clazz = bb.getClass(); + try { + freeMethod = clazz.getMethod("free"); + } catch (NoSuchMethodException ex) { + } catch (SecurityException ex) { } } @@ -1210,8 +1201,6 @@ public final class BufferUtils { return; } - loadCleanerMethods(); - try { if (freeMethod != null) { freeMethod.invoke(toBeDestroyed);