[jboss-cvs] JBossAS SVN: r103971 - in projects/jboss-reflect/trunk/src: test/java/org/jboss/test/benchmark and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 14 09:53:44 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-04-14 09:53:44 -0400 (Wed, 14 Apr 2010)
New Revision: 103971
Modified:
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMemberFactory.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/AccessorBenchmark.java
Log:
[JBREFLECT-6] Don't use privileged block unless security manager is used
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMemberFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMemberFactory.java 2010-04-14 13:49:27 UTC (rev 103970)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMemberFactory.java 2010-04-14 13:53:44 UTC (rev 103971)
@@ -279,31 +279,44 @@
final ClassLoader cl = target.getClassPool().getClassLoader();
- return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<T>>()
- {
- public Class<T> run() throws Exception
- {
- return FactoryHelper.toClass(cf, cl);
- }
- });
-
+ return toClass(expected, cf, cl);
}
catch(RuntimeException e)
{
throw e;
}
- catch (PrivilegedActionException e)
- {
- if (e.getCause() instanceof RuntimeException)
- throw (RuntimeException)e.getCause();
- throw new RuntimeException(e.getCause());
- }
catch (Exception e)
{
throw new RuntimeException(e);
}
}
+
+ private <T> Class<T> toClass(final Class<T> expected, final ClassFile cf, final ClassLoader cl) throws CannotCompileException
+ {
+ if (System.getSecurityManager() == null)
+ return FactoryHelper.toClass(cf, cl);
+ try
+ {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<T>>()
+ {
+ public Class<T> run() throws Exception
+ {
+ return FactoryHelper.toClass(cf, cl);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ if (e.getCause() instanceof CannotCompileException)
+ throw (CannotCompileException)e.getCause();
+ else if (e.getCause() instanceof RuntimeException)
+ throw (RuntimeException)e.getCause();
+ else
+ throw new RuntimeException(e.getCause());
+ }
+ }
+
/**
* Implements the methods of the interface
*
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/AccessorBenchmark.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/AccessorBenchmark.java 2010-04-14 13:49:27 UTC (rev 103970)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/AccessorBenchmark.java 2010-04-14 13:53:44 UTC (rev 103971)
@@ -47,10 +47,10 @@
TypeInfoFactory factory = new org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory();
// TypeInfoFactory factory = new org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory();
- int numClasses = 100;
- int numFields = 100;
- int numGetMembers = 50;
- int numJoinpoint = 50;
+ int numClasses = 10;
+ int numFields = 50;
+ int numGetMembers = 1;
+ int numJoinpoint = 1;
public void testAccessors() throws Throwable
@@ -62,7 +62,7 @@
long start = System.currentTimeMillis();
ClassInfo[] classInfos = setupClassInfos(classes);
- start = outputTime(start, "A - Created " + numClasses + " Class Infos");
+ start = outputTime(start, "A - Created " + numClasses + " ClassInfos");
getFieldsAndMethods(classInfos);
start = outputTime(start, "B - Getting " + numFields + " fields and methods for " + numClasses + " classes " + numGetMembers + " times");
More information about the jboss-cvs-commits
mailing list