From 9d857ea3575ee263801741a95711d9214c156276 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 17 Jun 2014 01:16:51 +0200 Subject: ReflectionUtil.getConstructor: Add 'initializeClazz' argument, allowing to defer static class initialization --- src/java/com/jogamp/common/util/IOUtil.java | 2 +- src/java/com/jogamp/common/util/ReflectionUtil.java | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 60a0ee0..fe482d9 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -96,7 +96,7 @@ public class IOUtil { Constructor _fosCtor; Throwable _t; try { - _fosCtor = ReflectionUtil.getConstructor("java.io.FileOutputStream", new Class[] { File.class }, IOUtil.class.getClassLoader()); + _fosCtor = ReflectionUtil.getConstructor("java.io.FileOutputStream", new Class[] { File.class }, true, IOUtil.class.getClassLoader()); _t = null; } catch (Throwable t) { _fosCtor = null; diff --git a/src/java/com/jogamp/common/util/ReflectionUtil.java b/src/java/com/jogamp/common/util/ReflectionUtil.java index e3f6ad7..949df1d 100644 --- a/src/java/com/jogamp/common/util/ReflectionUtil.java +++ b/src/java/com/jogamp/common/util/ReflectionUtil.java @@ -120,10 +120,10 @@ public final class ReflectionUtil { return sb; } - private static Class getClassImpl(String clazzName, boolean initialize, ClassLoader cl) throws ClassNotFoundException { + private static Class getClassImpl(String clazzName, boolean initializeClazz, ClassLoader cl) throws ClassNotFoundException { if(DEBUG_STATS_FORNAME) { final long t0 = System.nanoTime(); - final Class res = Class.forName(clazzName, initialize, cl); + final Class res = Class.forName(clazzName, initializeClazz, cl); final long t1 = System.nanoTime(); final long nanoCosts = t1 - t0; synchronized(forNameLock) { @@ -137,14 +137,14 @@ public final class ReflectionUtil { cnl.count++; cnl.nanoCosts += nanoCosts; System.err.printf("ReflectionUtil.getClassImpl.%03d: %8.3f ms, init %b, [%s]@ Thread %s%n", - forNameCount, nanoCosts/1e6, initialize, cnl.toString(), Thread.currentThread().getName()); + forNameCount, nanoCosts/1e6, initializeClazz, cnl.toString(), Thread.currentThread().getName()); if(DEBUG) { Thread.dumpStack(); } } return res; } else { - return Class.forName(clazzName, initialize, cl); + return Class.forName(clazzName, initializeClazz, cl); } } @@ -163,22 +163,23 @@ public final class ReflectionUtil { * Loads and returns the class or null. * @see Class#forName(java.lang.String, boolean, java.lang.ClassLoader) */ - public static final Class getClass(String clazzName, boolean initialize, ClassLoader cl) + public static final Class getClass(String clazzName, boolean initializeClazz, ClassLoader cl) throws JogampRuntimeException { try { - return getClassImpl(clazzName, initialize, cl); + return getClassImpl(clazzName, initializeClazz, cl); } catch (ClassNotFoundException e) { throw new JogampRuntimeException(clazzName + " not available", e); } } /** + * @param initializeClazz TODO * @throws JogampRuntimeException if the constructor can not be delivered. */ - public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes, ClassLoader cl) + public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes, boolean initializeClazz, ClassLoader cl) throws JogampRuntimeException { try { - return getConstructor(getClassImpl(clazzName, true, cl), cstrArgTypes); + return getConstructor(getClassImpl(clazzName, initializeClazz, cl), cstrArgTypes); } catch (ClassNotFoundException ex) { throw new JogampRuntimeException(clazzName + " not available", ex); } @@ -249,7 +250,7 @@ public final class ReflectionUtil { public static final Constructor getConstructor(String clazzName, ClassLoader cl) throws JogampRuntimeException { - return getConstructor(clazzName, null, cl); + return getConstructor(clazzName, null, true, cl); } /** -- cgit v1.2.3