[jboss-cvs] JBossAS SVN: r104251 - in projects/jboss-reflect/trunk: src/main/java/org/jboss/config/plugins/property and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 26 06:17:08 EDT 2010


Author: kabir.khan at jboss.com
Date: 2010-04-26 06:17:07 -0400 (Mon, 26 Apr 2010)
New Revision: 104251

Added:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistConstructor.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistField.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistMethod.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultMemberFactory.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/Metrics.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistConstructor.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistField.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistMethod.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsMBean.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/AccessorBenchmark2.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/ApplicationServerBenchmark.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/ApplicationServerBenchmarkMBean.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/IntrospectionAccessorBenchmark.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/IntrospectionAccessorBenchmark2.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/JavassistAccessorBenchmark.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/JavassistAccessorBenchmark2.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/Test.java
Modified:
   projects/jboss-reflect/trunk/.classpath
   projects/jboss-reflect/trunk/src/main/java/org/jboss/config/plugins/property/PropertyConfiguration.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistUtil.java
   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] Fix JavassistMemeberFactory to use the classloader of jboss-reflect when generating the JavassistMethod, -Constructor and -Field implementations if the class targetted lives in a parent classloader of jboss-reflect.

Add initial support for changing the implementation of how the accessors are created, i.e. normal reflection vs generated classes.

Add support for metrics of how often the accessors are called accessible via an MBean


Modified: projects/jboss-reflect/trunk/.classpath
===================================================================
--- projects/jboss-reflect/trunk/.classpath	2010-04-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/.classpath	2010-04-26 10:17:07 UTC (rev 104251)
@@ -1,7 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-  <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
-  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
-  <classpathentry kind="output" path="target/classes"/>
-  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-  <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
-</classpath>
\ No newline at end of file
+	<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="lib" path="/Users/kabir/Downloads/asm-3.2/lib/asm-3.2.jar" sourcepath="/Users/kabir/Downloads/asm-3.2/src.zip"/>
+	<classpathentry kind="lib" path="/Users/kabir/Downloads/asm-3.2/lib/asm-commons-3.2.jar" sourcepath="/Users/kabir/Downloads/asm-3.2/src.zip"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/config/plugins/property/PropertyConfiguration.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/config/plugins/property/PropertyConfiguration.java	2010-04-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/config/plugins/property/PropertyConfiguration.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -29,6 +29,7 @@
 import org.jboss.config.plugins.AbstractConfiguration;
 import org.jboss.joinpoint.spi.JoinpointFactoryBuilder;
 import org.jboss.logging.Logger;
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
 import org.jboss.reflect.spi.TypeInfoFactory;
 
 /**
@@ -92,7 +93,10 @@
    @Override
    protected TypeInfoFactory createDefaultTypeInfoFactory() throws Throwable
    {
-      return (TypeInfoFactory) loadFromProperties(PropertyConfigurationConstants.TYPE_INFO_FACTORY_NAME, PropertyConfigurationConstants.TYPE_INFO_FACTORY_DEFAULT, TypeInfoFactory.class);
+//      return (TypeInfoFactory) loadFromProperties(PropertyConfigurationConstants.TYPE_INFO_FACTORY_NAME, PropertyConfigurationConstants.TYPE_INFO_FACTORY_DEFAULT, TypeInfoFactory.class);
+      TypeInfoFactory factory = (TypeInfoFactory) loadFromProperties(PropertyConfigurationConstants.TYPE_INFO_FACTORY_NAME, JavassistTypeInfoFactory.class.getName(), TypeInfoFactory.class);
+      log.warn("Factory: " + factory);
+      return factory;
    }
 
    @Override

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java	2010-04-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -48,9 +48,6 @@
    /** The serialVersionUID */
    private static final long serialVersionUID = -2255405601790592604L;
 
-   /** The reflection factory */
-   private static final JavassistReflectionFactory reflectionFactory = new JavassistReflectionFactory(true);
- 
    /** The constructor implementation */
    private transient volatile JavassistConstructor constructor;
 
@@ -70,7 +67,7 @@
    {
       if (constructor == null)
       {
-         JavassistConstructor ctor = reflectionFactory.createConstructor((CtConstructor)ctBehavior);
+         JavassistConstructor ctor = JavassistReflectionFactory.INSTANCE.createConstructor(this);
          if (constructor == null)
             constructor = ctor; 
       }

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java	2010-04-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -56,9 +56,6 @@
    /** The serialVersionUID */
    private static final long serialVersionUID = -104555531831318930L;
 
-   /** The reflection factory */
-   private static final JavassistReflectionFactory reflectionFactory = new JavassistReflectionFactory(true);
-
    /** The field */
    private final CtField ctField;
    
@@ -143,7 +140,7 @@
    public Object get(Object target) throws Throwable
    {
       if (field == null)
-         field = reflectionFactory.createField(ctField);
+         field = JavassistReflectionFactory.INSTANCE.createField(this);
       
       JavassistAccessController.checkAccess(this);
       
@@ -153,7 +150,7 @@
    public Object set(Object target, Object value) throws Throwable
    {
       if (field == null)
-         field = reflectionFactory.createField(ctField);
+         field = JavassistReflectionFactory.INSTANCE.createField(this);
 
       JavassistAccessController.checkAccess(this);
 

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java	2010-04-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -56,9 +56,6 @@
    /** The serialVersionUID */
    private static final long serialVersionUID = 101183748227690112L;
 
-   /** The reflection factory */
-   private static final JavassistReflectionFactory reflectionFactory = new JavassistReflectionFactory(true);
-   
    /** The method implementation */
    private transient volatile JavassistMethod method;
    
@@ -114,7 +111,7 @@
    public Object invoke(Object target, Object[] args) throws Throwable
    {
       if (method == null)
-         method = reflectionFactory.createMethod((CtMethod)ctBehavior);
+         method = JavassistReflectionFactory.INSTANCE.createMethod(this);
       
       JavassistAccessController.checkAccess(this);
       

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java	2010-04-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistReflectionFactory.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -21,17 +21,45 @@
 */
 package org.jboss.reflect.plugins.javassist;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashSet;
+import java.util.Set;
+
 import javassist.CtConstructor;
 import javassist.CtField;
 import javassist.CtMethod;
 
 import org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory;
+import org.jboss.reflect.plugins.javassist.defaultmember.DefaultMemberFactory;
+import org.jboss.reflect.plugins.javassist.metrics.MetricsJavassistConstructor;
+import org.jboss.reflect.plugins.javassist.metrics.MetricsJavassistField;
+import org.jboss.reflect.plugins.javassist.metrics.MetricsJavassistMethod;
 
 /**
- * JavassistReflectionFactory.
+ * <p>JavassistReflectionFactory.
+ * </p><p>
  * Creates instances of {@link JavassistMethod}, {@link JavassistConstructor} and
  * {@link JavassistField} that invoke methods, constructors, and accesses fields without
- * the use of reflection.
+ * the use of reflection. Although a lot faster, there is an overhead associated with generating
+ * these classes, so they should only be used for frequently used members </p>
+ * <p>
+ * By default the generated classes class will not do any checking of the parameters. To turn this on,
+ * specify <code>-Dorg.jboss.reflect.plugins.javassist.JavassistReflectionFactory.check=true</code>.
+ * </p> 
+ * <p>
+ * To output the generated classes to disk, so the bytecode can be inspected, specify
+ * <code>-Dorg.jboss.reflect.plugins.javassist.JavassistReflectionFactory.debug=true</code>.
+ * </p>
+ * <p>
+ * To enable metrics, which can be useful in determining which members accessors should be generated, specify
+ * <code>-Dorg.jboss.reflect.plugins.javassist.JavassistReflectionFactory.enableMetrics=true</code>.
+ * </p>
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
@@ -40,15 +68,29 @@
  */
 public class JavassistReflectionFactory
 {
+   public static final JavassistReflectionFactory INSTANCE;
+   
    /** Whether to check arguments */
-   private final boolean check;
+   private static final boolean check;
    
    /** Whether to output generated classes to disk */
-   private final boolean debug;
+   private static final boolean debug;
    
+   /** Whether to enable metrics for the classes or not */
+   private static final boolean enableMetrics;
+   
+   /** A file containing the names of the members that should be generated */
+   private static final Set<String> forceGenerate;
+   
    protected static final Class<?> MAGIC_ACCESSOR_IMPL;
    static
    {
+      check = initBooleanProperty(JavassistReflectionFactory.class.getName() + ".check");
+      debug = initBooleanProperty(JavassistReflectionFactory.class.getName() + ".debug");
+      enableMetrics = initBooleanProperty(JavassistReflectionFactory.class.getName() + ".enableMetrics");
+      forceGenerate = initForceGenerate(JavassistReflectionFactory.class.getName() + ".file");
+      INSTANCE = new JavassistReflectionFactory();
+      
       try
       {
          MAGIC_ACCESSOR_IMPL = SecurityActions.classForName("sun.reflect.MagicAccessorImpl");
@@ -59,26 +101,86 @@
       }
    }
    
-   /**
-    * Create a new JavassistReflectionFactory.
-    * 
-    * @param check whether to check arguments
-    */
-   public JavassistReflectionFactory(boolean check)
+   private static boolean initBooleanProperty(final String name)
    {
-      this(check, false);
+      return AccessController.doPrivileged(new PrivilegedAction<Boolean>()
+      {
+         public Boolean run()
+         {
+            return Boolean.getBoolean(name);
+         }
+      });
+      
    }
 
+   public void addForceGenerate(String s)
+   {
+      forceGenerate.add(s);
+   }
+   
+   public void removeForceGenerate(String s)
+   {
+      forceGenerate.remove(s);
+   }
+   
+   private static Set<String> initForceGenerate(final String name)
+   {
+      try
+      {
+         return AccessController.doPrivileged(new PrivilegedExceptionAction<Set<String>>()
+         {
+            public Set<String> run() throws Exception
+            {
+               String generateFile = System.getProperty(JavassistReflectionFactory.class.getName() + ".file", null);
+               Set<String> forceGenerate = new HashSet<String>();
+               if (generateFile != null)
+               {
+                  File file = new File(generateFile);
+                  if (!file.exists())
+                     throw new IllegalArgumentException("No file called '" + generateFile + "' specified via -D" + JavassistReflectionFactory.class.getName() + ".file");
+                  
+                  BufferedReader in = null;
+                  try
+                  {
+                     in = new BufferedReader(new FileReader(file));
+                     String s = in.readLine();
+                     while (s != null)
+                     {
+                        s = s.trim();
+                        if (s.length() > 0)
+                           forceGenerate.add(s);
+                        s = in.readLine();
+                     }
+                  }
+                  finally
+                  {
+                     try
+                     {
+                        in.close();
+                     }
+                     catch(Exception ignore)
+                     {
+                     }
+                  }
+               }
+               return forceGenerate;
+            }
+         });
+      }
+      catch(PrivilegedActionException e)
+      {
+         if (e.getCause() instanceof RuntimeException)
+            throw (RuntimeException)e.getCause();
+         throw new RuntimeException(e.getCause());
+      }
+   }
+
    /**
     * Create a new JavassistReflectionFactory.
     * 
-    * @param check whether to check arguments
-    * @param debug whether to output generated classes to disk
     */
-   public JavassistReflectionFactory(boolean check, boolean debug)
+   private JavassistReflectionFactory()
    {
-      this.check = check;
-      this.debug = debug;
    }
 
    /**
@@ -91,9 +193,17 @@
     * @return the method
     * @throws Throwable for any error
     */
-   public JavassistMethod createMethod(CtMethod ctMethod) throws Throwable
+   public JavassistMethod createMethod(JavassistMethodInfo info) throws Throwable
    {
-      return JavassistMemberFactory.createJavassistMethod(MAGIC_ACCESSOR_IMPL, ctMethod, check, debug);      
+      String sig = JavassistUtil.getSignature(info.getCtMethod());
+      JavassistMethod method = generateAccessor(sig) ?
+            JavassistMemberFactory.createJavassistMethod(MAGIC_ACCESSOR_IMPL, info.getCtMethod(), check, debug) :
+               DefaultMemberFactory.createJavassistMethod(info);
+      
+      if (enableMetrics)
+         method = new MetricsJavassistMethod(method, sig);
+      
+      return method;
    }
    
    /**
@@ -103,9 +213,17 @@
     * @return the constructor
     * @throws Throwable for any error
     */
-   public JavassistConstructor createConstructor(CtConstructor ctConstructor) throws Throwable
+   public JavassistConstructor createConstructor(JavassistConstructorInfo info) throws Throwable
    {
-      return JavassistMemberFactory.createJavassistConstructor(MAGIC_ACCESSOR_IMPL, ctConstructor, check, debug);      
+      String sig = JavassistUtil.getSignature(info.getCtConstructor());
+      JavassistConstructor ctor = generateAccessor(sig) ?
+            JavassistMemberFactory.createJavassistConstructor(MAGIC_ACCESSOR_IMPL, info.getCtConstructor(), check, debug) :
+               DefaultMemberFactory.createJavassistConstructor(info);
+            
+      if (enableMetrics)
+         ctor = new MetricsJavassistConstructor(ctor, sig);
+      
+      return ctor;
    }
    
    /**
@@ -115,9 +233,22 @@
     * @return the field
     * @throws Throwable for any error
     */
-   public JavassistField createField(CtField ctField) throws Throwable
+   public JavassistField createField(JavassistFieldInfo info) throws Throwable
    {
-      return JavassistMemberFactory.createJavassistField(MAGIC_ACCESSOR_IMPL, ctField, check, debug);      
+      String sig = JavassistUtil.getSignature(info.getCtField());
+      JavassistField field = generateAccessor(sig) ?
+            JavassistMemberFactory.createJavassistField(MAGIC_ACCESSOR_IMPL, info.getCtField(), check, debug) :
+               DefaultMemberFactory.createJavassistField(info);
+            
+      if (enableMetrics)
+         field = new MetricsJavassistField(field, sig);
+      
+      return field;
    }
    
+   private boolean generateAccessor(String signature)
+   {
+      return true;
+//      return forceGenerate.contains(signature);
+   }
 }

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java	2010-04-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -232,7 +232,7 @@
       }
       catch (NotFoundException e)
       {
-         throw JavassistTypeInfoFactoryImpl.raiseClassNotFound(clazz.getSuperclass().getName(), e);
+         throw JavassistTypeInfoFactoryImpl.raiseClassNotFound(ctClass.getClassFile2().getSuperclass() + " from " + ctClass.getName() + " in pool " + ctClass.getClassPool(), e);
       }
    }
 

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2010-04-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -28,7 +28,10 @@
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.lang.reflect.WildcardType;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import javassist.ClassPool;
 import javassist.CtClass;
@@ -533,7 +536,9 @@
       try
       {
          if (ctClass == null)
+         {
             ctClass = poolFactory.getPoolForLoader(cl).get(name);
+         }
          result = instantiate(ctClass, clazz);
       }
       catch(NotFoundException e)
@@ -570,6 +575,45 @@
     */
    private TypeInfo delegateToIntrospectionImplementation(ClassLoader cl, String name) throws ClassNotFoundException
    {
+//      System.out.println("======> " + name + " " + cl);
+//      
+//      //Extra code just for debugging
+//      ClassPool pool = poolFactory.getPoolForLoader(cl);
+//      try
+//      {
+//         CtClass ct = pool.get(name); 
+//      }
+//      catch(Exception alreadyHandled)
+//      {
+//         System.out.println("---> Not found in " + pool);
+//      }
+//      
+//      Class<?> clazz = cl.loadClass(name);
+//      System.out.println("---> Loaded real class from " + clazz.getClassLoader());
+//      
+//      try
+//      {
+//         CtClass ct = pool.get(name); 
+//      }
+//      catch(Exception alreadyHandled)
+//      {
+//         System.out.println("---> Not found again in " + pool);
+//      }
+//      
+//      pool = poolFactory.getPoolForLoader(clazz.getClassLoader());
+//      try
+//      {
+//         CtClass ct = pool.get(name); 
+//         System.out.println("---> Found in actual pool " + pool);
+//      }
+//      catch(Exception alreadyHandled)
+//      {
+//         System.out.println("---> Not found in actual pool " + pool);
+//      }
+//      
+
+      //Extra code - END
+      
       IntrospectionTypeInfoFactory factory = new IntrospectionTypeInfoFactory();
       return factory.getTypeInfo(name, cl);
    }

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistUtil.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistUtil.java	2010-04-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistUtil.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -29,6 +29,9 @@
 import javassist.CannotCompileException;
 import javassist.ClassPool;
 import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.CtField;
+import javassist.CtMethod;
 import javassist.CtPrimitiveType;
 import javassist.NotFoundException;
 
@@ -171,7 +174,7 @@
       return clazzes;
    }
 
-   static ClassLoader getClassLoader(CtClass ctClass)
+   public static ClassLoader getClassLoader(CtClass ctClass)
    {
       ClassPool pool = ctClass.getClassPool();
       ClassLoader loader = null;
@@ -183,5 +186,20 @@
       
       return loader;
    }
+
+   public static String getSignature(CtConstructor ctor)
+   {
+      return ctor.getDeclaringClass().getName() + ctor.getSignature();
+   }
+
+   public static String getSignature(CtMethod method)
+   {
+      return method.getDeclaringClass().getName() + "." + method.getName() + method.getSignature();
+   }
+
+   public static String getSignature(CtField field)
+   {
+      return field.getDeclaringClass().getName() + "." + field.getName();
+   }
    
 }

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-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMemberFactory.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -26,8 +26,11 @@
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javassist.CannotCompileException;
@@ -150,7 +153,6 @@
 
    /** Descriptor for Short.valueOf */
    private final static String SHORT_VALUE_OF_DESCRIPTOR = RuntimeSupport.makeDescriptor(new Class[] {Short.TYPE}, Short.class);
-
    
    /** The method class counter */
    protected static final AtomicInteger counter = new AtomicInteger(0);
@@ -166,6 +168,35 @@
    
    /** Cached string representation of the signature of the accessed member */
    private String accessedMember;
+   
+   /**
+    * In AS the JavassistMethod, -Constructor and -Field classloaders are not deployed in 
+    * the system classpath. When generating an accessor for something from the system classpath
+    * we need to make sure it happens at the level that can see the implemented interfaces
+    * 
+    */
+   private static final ParentLoaderHandler PARENT_LOADER_HANDLER;
+   
+   static
+   {
+      PARENT_LOADER_HANDLER = AccessController.doPrivileged(new PrivilegedAction<ParentLoaderHandler>()
+      {
+         public ParentLoaderHandler run()
+         {
+            ClassLoader reflectLoader = JavassistMethod.class.getClassLoader();
+            if (reflectLoader == null)
+               reflectLoader = ClassLoader.getSystemClassLoader();
+            ClassLoader loader = reflectLoader.getParent();
+            Set<ClassLoader> parents = loader == null ? null : new HashSet<ClassLoader>(); 
+            while (loader != null)
+            {
+               parents.add(loader);
+               loader = loader.getParent();
+            }
+            return new ParentLoaderHandler(reflectLoader, parents);
+         }
+      });
+   }
 
    /**
     * Constructor
@@ -260,63 +291,63 @@
     */
    protected <T> Class<T> makeClass(Class<T> expected, CtClass target)
    {
+      //Create a new public class
+      final ClassFile cf = new ClassFile(false, getGeneratedClassName(), superClass.getName());
+      cf.setAccessFlags(AccessFlag.PUBLIC);
+      cf.setInterfaces(getInterfaceNames());
+
       try
       {
-         //Create a new public class
-         final ClassFile cf = new ClassFile(false, getGeneratedClassName(), superClass.getName());
-         cf.setAccessFlags(AccessFlag.PUBLIC);
-         cf.setInterfaces(getInterfaceNames());
-
          //Add the constructors from the super class 
          makeConstructors(cf);
-
+   
          //implement the methods from the interfaces
          implementMethods(cf);
-
+   
          if (debug)
             debugWriteFile(cf);
-
-
-         final ClassLoader cl = target.getClassPool().getClassLoader();
-         
-         return toClass(expected, cf, cl);
       }
-      catch(RuntimeException e)
+      catch(Exception e)
       {
-         throw e;
+         throw new RuntimeException("Error creating " + expected.getSimpleName() + " for " + target.getName(), e);
       }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
+
+
+      ClassLoader cl = target.getClassPool().getClassLoader();
+      if (cl == null)
+         cl = SecurityActions.getContextClassLoader();
+      
+      return toClass(expected, target, cf, cl);
    }
    
-   private <T> Class<T> toClass(final Class<T> expected, final ClassFile cf, final ClassLoader cl) throws CannotCompileException
+   private <T> Class<T> toClass(final Class<T> expected, final CtClass target, final ClassFile cf, final ClassLoader cl) 
    {
-      if (System.getSecurityManager() == null)
-         return FactoryHelper.toClass(cf, cl);
-
+      final ClassLoader actualLoader = PARENT_LOADER_HANDLER.getActualLoader(cl);
+      Throwable t = null;
       try
       {
-         return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<T>>()
-            {
-               public Class<T> run() throws Exception
-               {
-                  return FactoryHelper.toClass(cf, cl);
-               }
-            });
+         if (System.getSecurityManager() == null)
+            return FactoryHelper.toClass(cf, actualLoader);
+         else
+            return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<T>>()
+                  {
+                  public Class<T> run() throws Exception
+                  {
+                     return FactoryHelper.toClass(cf, actualLoader);
+                  }
+               });
       }
+      catch(CannotCompileException e)
+      {
+         t = e;
+      }
       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());
+         t = e.getCause();
       }
+      throw new RuntimeException("Error creating " + expected.getSimpleName() + " for " + target.getName() + " with classloader " + actualLoader + "(" + cl + ")", t);
    }
-
+   
    /**
     * Implements the methods of the interface
     * 
@@ -769,4 +800,25 @@
       }      
    }
    
+   private static class ParentLoaderHandler
+   {
+      final ClassLoader reflectLoader;
+      final Set<ClassLoader> parentLoaders;
+      
+      public ParentLoaderHandler(ClassLoader reflectLoader, Set<ClassLoader> parentLoaders)
+      {
+         if (reflectLoader == null)
+            throw new IllegalArgumentException("Null reflect loader");
+         this.reflectLoader = reflectLoader;
+         this.parentLoaders = parentLoaders;
+      }
+      
+      private ClassLoader getActualLoader(ClassLoader loader)
+      {
+         if (parentLoaders != null)
+            if (parentLoaders.contains(loader))
+               return reflectLoader;
+         return loader;
+      }
+   }
 }
\ No newline at end of file

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistConstructor.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistConstructor.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistConstructor.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,46 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins.javassist.defaultmember;
+
+import java.lang.reflect.Constructor;
+
+import org.jboss.reflect.plugins.javassist.JavassistConstructor;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class DefaultJavassistConstructor implements JavassistConstructor
+{
+   private final Constructor<?> ctor;
+
+   DefaultJavassistConstructor(Constructor<?> ctor)
+   {
+      this.ctor = ctor;
+   }
+
+   public Object newInstance(Object[] args) throws Throwable
+   {
+      return ctor.newInstance(args);
+   }
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistField.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistField.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistField.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins.javassist.defaultmember;
+
+import java.lang.reflect.Field;
+
+import org.jboss.reflect.plugins.javassist.JavassistField;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class DefaultJavassistField implements JavassistField
+{
+   final Field field;
+
+   DefaultJavassistField(Field field)
+   {
+      this.field = field;
+   }
+
+   public Object get(Object target) throws Throwable
+   {
+      return field.get(target);
+   }
+
+   public void set(Object target, Object value) throws Throwable
+   {
+      field.set(target, value);
+   }
+   
+   
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistMethod.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistMethod.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultJavassistMethod.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,46 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins.javassist.defaultmember;
+
+import java.lang.reflect.Method;
+
+import org.jboss.reflect.plugins.javassist.JavassistMethod;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class DefaultJavassistMethod implements JavassistMethod
+{
+   private final Method method;
+   
+   DefaultJavassistMethod(Method method)
+   {
+      this.method = method;
+   }
+
+   public Object invoke(Object target, Object[] args) throws Throwable
+   {
+      return method.invoke(target, args);
+   }
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultMemberFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultMemberFactory.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/defaultmember/DefaultMemberFactory.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,152 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins.javassist.defaultmember;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.jboss.reflect.plugins.javassist.JavassistConstructor;
+import org.jboss.reflect.plugins.javassist.JavassistConstructorInfo;
+import org.jboss.reflect.plugins.javassist.JavassistField;
+import org.jboss.reflect.plugins.javassist.JavassistFieldInfo;
+import org.jboss.reflect.plugins.javassist.JavassistMethod;
+import org.jboss.reflect.plugins.javassist.JavassistMethodInfo;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * <p>Class to create implementations of the {@link JavassistMethod}, {@link JavassistConstructor} 
+ * and {@link JavassistField} interfaces.</p>
+ * <p>This implementation simply creates implementations that use reflection</p>
+ * 
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultMemberFactory
+{
+   private static final Class<?>[] NO_PARAMS = new Class[0];
+   
+   /**
+    * Creates a new {@link JavassistMethod} implementation for a given method
+    * 
+    * @param methodInfo the CtMethod for which we want to create a JavassistMethod implementation
+    * @return the implementing class
+    * @throws RuntimeException if an error ocurred
+    */
+   public static JavassistMethod createJavassistMethod(JavassistMethodInfo methodInfo)
+   {
+      if (methodInfo == null)
+         throw new IllegalArgumentException("Null method");
+      
+      
+      try
+      {
+         //Ok to load the class here since this is only called by MethodInfo.invoke() in which
+         //case the class must be loaded
+         Class<?> clazz = methodInfo.getDeclaringClass().getType();
+         Class<?>[] params = getParams(methodInfo.getParameterTypes());
+         Method method = clazz.getDeclaredMethod(methodInfo.getName(), params); 
+         return new DefaultJavassistMethod(method);
+      }
+      catch(RuntimeException e)
+      {
+         throw e;
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   /**
+    * Creates a new {@link JavassistConstructor} implementation for a given constructor
+    * 
+    * @param constructorInfo the CtConstructor for which we want to create a JavassistConstructor implementation
+    * @return the implementing class
+    * @throws RuntimeException if an error ocurred
+    */
+   public static JavassistConstructor createJavassistConstructor(JavassistConstructorInfo constructorInfo)
+   {
+      if (constructorInfo == null)
+         throw new IllegalArgumentException("Null constructor");
+
+      try
+      {
+         //Ok to load the class here since this is only called by ConstructorInfo.newInstance() in which
+         //case the class must be loaded
+         Class<?> clazz = constructorInfo.getDeclaringClass().getType();
+         Class<?>[] params = getParams(constructorInfo.getParameterTypes());
+         Constructor<?> ctor = clazz.getDeclaredConstructor(params); 
+         return new DefaultJavassistConstructor(ctor);
+      }
+      catch(RuntimeException e)
+      {
+         throw e;
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   /**
+    * Creates a new {@link JavassistField} implementation for a given field
+    * 
+    * @param fieldInfo the CtField for which we want to create a JavassistField implementation
+    * @return the implementing class
+    * @throws RuntimeException if an error ocurred
+    */
+   public static JavassistField createJavassistField(JavassistFieldInfo fieldInfo)
+   {
+      if (fieldInfo == null)
+         throw new IllegalArgumentException("Null field");
+
+      try
+      {
+         //Ok to load the class here since this is only called by FieldInfo.get()/set() in which
+         //case the class must be loaded
+         Class<?> clazz = fieldInfo.getDeclaringClass().getType();
+         Field field = clazz.getDeclaredField(fieldInfo.getName()); 
+         return new DefaultJavassistField(field);
+      }
+      catch(RuntimeException e)
+      {
+         throw e;
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   private static Class<?>[] getParams(TypeInfo[] typeParams)
+   {
+      if (typeParams == null || typeParams.length == 0)
+         return NO_PARAMS;
+      Class<?>[] params = new Class[typeParams.length];
+      for (int i = 0 ; i < params.length ; i++)
+         params[i] = typeParams[i].getType();
+      return params;
+   }
+
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/Metrics.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/Metrics.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/Metrics.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,221 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins.javassist.metrics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Metrics implements MetricsMBean
+{
+   final static List<Entry> record = new ArrayList<Entry>();
+   
+   final Entry entry;
+
+   volatile boolean locked;
+   
+   public Metrics()
+   {
+      entry = null;
+   }
+   
+   protected Metrics(String name)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+      this.entry = new Entry(name);
+      synchronized (record)
+      {
+         record.add(entry);
+      }
+   }
+   
+   static String getDelegateType(Object delegate)
+   {
+      if (delegate.getClass().getSimpleName().startsWith("Default"))
+         return " - {R}"; 
+      
+      return " - {G}";
+   }
+
+   protected void recordTime(long nanosTaken)
+   {
+      if (locked)
+      {
+         //This is not perfect, but I don't want to synchronize all the time
+         synchronized (record)
+         {
+            doRecordTime(nanosTaken);
+         }
+      }
+      doRecordTime(nanosTaken);
+   }
+   
+   protected void doRecordTime(long nanosTaken)
+   {
+      entry.getInvocations().incrementAndGet();
+      entry.getNanos().addAndGet(nanosTaken);
+   }
+   
+   public List<Entry> sortByInvocations()
+   {
+      return sort(InvocationsComparator.INSTANCE);
+   }
+   
+   public String outputEntriesByInvocations(String lineSeparator)
+   {
+      if (lineSeparator == null)
+         lineSeparator = "\n";
+      
+      StringBuilder sb = new StringBuilder("Invocations (total time in ms) - Member name");
+      sb.append(lineSeparator);
+      sb.append("============================================");
+      sb.append(lineSeparator);
+      
+      long totalTime =0, invocations = 0;
+      for (Entry entry : sortByInvocations())
+      {
+         totalTime += entry.getNanos().get();
+         invocations += entry.getInvocations().get();
+         
+         sb.append(entry.getInvocations() + " (" + entry.getNanos().get()/*/1000000*/ + ") - " + entry.getName());
+         sb.append(lineSeparator);
+      }
+      sb.append("--------------------------------------------");
+      sb.append(lineSeparator);
+      sb.append("Total: " + invocations + " (" + totalTime + ")");
+      
+      return sb.toString();
+   }
+
+   public List<Entry> sortByTime()
+   {
+      return sort(TimeComparator.INSTANCE);
+   }
+   
+   public String outputEntriesByTime(String lineSeparator)
+   {
+      if (lineSeparator == null)
+         lineSeparator = "\n";
+      
+      StringBuilder sb = new StringBuilder("Total time in ms (Invocations) - Member name");
+      sb.append(lineSeparator);
+      sb.append("=============================================");
+      sb.append(lineSeparator);
+      
+      long totalTime =0, invocations = 0;
+      for (Entry entry : sortByTime())
+      {
+         totalTime += entry.getNanos().get();
+         invocations += entry.getInvocations().get();
+         
+         sb.append(entry.getNanos().get()/*/1000000*/ + " (" + entry.getInvocations() + ") - " + entry.getName());
+         sb.append(lineSeparator);
+      }
+      
+      sb.append("--------------------------------------------");
+      sb.append(lineSeparator);
+      sb.append("Total: " + totalTime  + " (" + invocations + ")");
+      return sb.toString();
+   }
+   
+   private List<Entry> sort(Comparator<Entry> comparator)
+   {
+      synchronized (record)
+      {
+         try
+         {
+            locked = true;
+            List<Entry> entries = new ArrayList<Entry>(record);
+            Collections.sort(entries, comparator);
+            return entries;
+         }
+         finally
+         {
+            locked = false;
+         }
+      }
+   }
+
+   private static class InvocationsComparator implements Comparator<Entry>
+   {
+      final static InvocationsComparator INSTANCE = new InvocationsComparator();
+      
+      public int compare(Entry o1, Entry o2)
+      {
+         if (o1.getInvocations().get() == o2.getInvocations().get())
+            return 0;
+         else if (o1.getInvocations().get() > o2.getInvocations().get())
+            return -1;
+         return 1;
+      }
+   }
+   
+   private static class TimeComparator implements Comparator<Entry>
+   {
+      final static TimeComparator INSTANCE = new TimeComparator();
+      
+      public int compare(Entry o1, Entry o2)
+      {
+         if (o1.getNanos().get() == o2.getNanos().get())
+            return 0;
+         else if (o1.getNanos().get() > o2.getNanos().get())
+            return -1;
+         return 1;
+      }
+   }
+   
+   public static class Entry
+   {
+      final String name;
+      final AtomicInteger invocations = new AtomicInteger();
+      final AtomicLong nanos = new AtomicLong();
+      
+      public Entry(String name)
+      {
+         this.name = name;
+      }
+      
+      public String getName()
+      {
+         return name;
+      }
+
+      public AtomicInteger getInvocations()
+      {
+         return invocations;
+      }
+
+      public AtomicLong getNanos()
+      {
+         return nanos;
+      }
+   }
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistConstructor.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistConstructor.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistConstructor.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins.javassist.metrics;
+
+import org.jboss.reflect.plugins.javassist.JavassistConstructor;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class MetricsJavassistConstructor extends Metrics implements JavassistConstructor
+{
+   private final JavassistConstructor delegate;
+   
+   public MetricsJavassistConstructor(JavassistConstructor delegate, String sig)
+   {
+      super(sig + getDelegateType(delegate));
+      if (delegate == null)
+         throw new IllegalArgumentException("Null delegate");
+      this.delegate = delegate;
+   }
+
+   public Object newInstance(Object[] args) throws Throwable
+   {
+      long start = System.currentTimeMillis();
+      try
+      {
+         return delegate.newInstance(args);
+      }
+      finally
+      {
+         recordTime(System.currentTimeMillis() - start);
+      }
+   }
+
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistField.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistField.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistField.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins.javassist.metrics;
+
+import org.jboss.reflect.plugins.javassist.JavassistField;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class MetricsJavassistField extends Metrics implements JavassistField
+{
+   private final JavassistField delegate;
+
+   public MetricsJavassistField(JavassistField delegate, String sig)
+   {
+      super(sig + getDelegateType(delegate));
+      if (delegate == null)
+         throw new IllegalArgumentException("Null delegate");
+      this.delegate = delegate;
+   }
+
+   public Object get(Object target) throws Throwable
+   {
+      long start = System.currentTimeMillis();
+      try
+      {
+         return delegate.get(target);
+      }
+      finally
+      {
+         recordTime(System.currentTimeMillis() - start);
+      }
+      
+   }
+
+   public void set(Object target, Object value) throws Throwable
+   {
+      long start = System.currentTimeMillis();
+      try
+      {
+         delegate.set(target, value);
+      }
+      finally
+      {
+         recordTime(System.currentTimeMillis() - start);
+      }
+   }
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistMethod.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistMethod.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsJavassistMethod.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins.javassist.metrics;
+
+import org.jboss.reflect.plugins.javassist.JavassistMethod;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class MetricsJavassistMethod extends Metrics implements JavassistMethod
+{
+   private final JavassistMethod delegate;
+   
+   public MetricsJavassistMethod(JavassistMethod delegate, String sig)
+   {
+      super(sig + getDelegateType(delegate));
+      if (delegate == null)
+         throw new IllegalArgumentException("Null delegate");
+      this.delegate = delegate;
+   }
+
+   public Object invoke(Object target, Object[] args) throws Throwable
+   {
+      long start = System.currentTimeMillis();
+      try
+      {
+         return delegate.invoke(target, args);
+      }
+      finally
+      {
+         recordTime(System.currentTimeMillis() - start);
+      }
+   }
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsMBean.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsMBean.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/metrics/MetricsMBean.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins.javassist.metrics;
+
+import java.util.List;
+
+import org.jboss.reflect.plugins.javassist.metrics.Metrics.Entry;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface MetricsMBean
+{
+   List<Entry> sortByInvocations();
+
+   String outputEntriesByInvocations(String lineSeparator);
+
+   List<Entry> sortByTime();
+
+   String outputEntriesByTime(String lineSeparator);
+}

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-26 10:15:26 UTC (rev 104250)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/AccessorBenchmark.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -42,16 +42,16 @@
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
-public class AccessorBenchmark extends TestCase
+public abstract class AccessorBenchmark extends TestCase
 {
-   TypeInfoFactory factory = new org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory();
-//   TypeInfoFactory factory = new org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory();
+   TypeInfoFactory factory = getTypeInfoFactory();
    
-   int numClasses = 10;
+   int numClasses = 100;
    int numFields = 50;
-   int numGetMembers = 1;
-   int numJoinpoint = 1;
+   int numGetMembers = 100;
+   int numJoinpoint = 300;
    
+   protected abstract TypeInfoFactory getTypeInfoFactory();
    
    public void testAccessors() throws Throwable
    {
@@ -67,45 +67,52 @@
       getFieldsAndMethods(classInfos);
       start = outputTime(start, "B - Getting " + numFields + " fields and methods for " + numClasses + " classes " + numGetMembers + " times");
     
-      useJoinpoint(classInfos, 1);
+      Object[] targets = instantiate(classInfos);
+      
+      long accessStart = start;
+      useJoinpoint(classInfos, targets, 1);
       start = outputTime(start, "C - First accessing " + numFields + " fields and methods for " + numClasses + " classes ");
 
-      useJoinpoint(classInfos, numJoinpoint);
+      useJoinpoint(classInfos, targets, numJoinpoint);
       start = outputTime(start, "D - Accessing " + numFields + " fields and methods for " + numClasses + " classes " + numJoinpoint + " times");
 
-      System.out.println("Done!");
+      System.out.println("Done! - All accesses took " + (System.currentTimeMillis() - accessStart));
    }
    
-   private void useJoinpoint(ClassInfo[] classInfos, int numJoinpoint) throws Throwable
+   private Object[] instantiate(ClassInfo[] classInfos) throws Throwable
    {
+      Object[] targets = new Object[classInfos.length];
+      for (int i = 0 ; i < classInfos.length ; i++)
+      {
+         ConstructorInfo ctor = classInfos[i].getDeclaredConstructor(null);
+         targets[i] = ctor.newInstance(null);
+      }
+      return targets;
+   }
+   
+   private void useJoinpoint(ClassInfo[] classInfos, Object[] targets, int numJoinpoint) throws Throwable
+   {
       TypeInfo[] params = new TypeInfo[] {PrimitiveInfo.INT};
       Object[] values = new Object[1];
       
-      for (int c = 0 ; c < classInfos.length ; c++)
+      for (int i = 0 ; i < numJoinpoint ; i ++)
       {
-         ConstructorInfo ctor = classInfos[c].getDeclaredConstructor(null);
-         Object o = ctor.newInstance(null);
+         Integer val = Integer.valueOf(i);
+         values[0] = val;
          
-         for (int f = 0 ; f < numFields ; f++)
+         for (int c = 0 ; c < classInfos.length ; c++)
          {
-            FieldInfo field = classInfos[c].getDeclaredField(fieldName(f));
-            Integer val = Integer.valueOf(f);
-            
-            for (int i = 0 ; i < numJoinpoint ; i ++)
+            for (int f = 0 ; f < numFields ; f++)
             {
-               field.set(o, val);
-               assertEquals(val, field.get(o));
+               FieldInfo field = classInfos[c].getDeclaredField(fieldName(f));
+               field.set(targets[c], val);
+               assertEquals(val, field.get(targets[c]));
             }
-         }
-         
-         for (int m = 0 ; m < numFields ; m++)
-         {
-            MethodInfo method = classInfos[c].getDeclaredMethod(methodName(m), params);
-            values[0] = Integer.valueOf(m);
-
-            for (int i = 0 ; i < numJoinpoint ; i ++)
+            
+            for (int m = 0 ; m < numFields ; m++)
             {
-               assertEquals(values[0], method.invoke(o, values));
+               MethodInfo method = classInfos[c].getDeclaredMethod(methodName(m), params);
+               assertEquals(values[0], method.invoke(targets[c], values));
             }
          }
       }

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/AccessorBenchmark2.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/AccessorBenchmark2.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/AccessorBenchmark2.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,178 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.benchmark;
+
+import java.util.Arrays;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMethod;
+import javassist.CtPrimitiveType;
+import javassist.Modifier;
+import junit.framework.TestCase;
+
+import org.jboss.reflect.plugins.javassist.JavassistMethodInfo;
+import org.jboss.reflect.plugins.javassist.JavassistReflectionFactory;
+import org.jboss.reflect.plugins.javassist.defaultmember.DefaultMemberFactory;
+import org.jboss.reflect.plugins.javassist.metrics.Metrics;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.ConstructorInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.PrimitiveInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AccessorBenchmark2 extends TestCase
+{
+   TypeInfoFactory factory = getTypeInfoFactory();
+   
+   int numClasses = 1;
+   int numFields = 1;
+   int numJoinpoint = 30;
+   
+   protected abstract TypeInfoFactory getTypeInfoFactory();
+
+   public void testArraySignatures(int[] i, String[] s)
+   {
+      
+   }
+      
+   public void testAccessors() throws Throwable
+   {
+      System.setProperty(JavassistReflectionFactory.class.getName() + ".enableMetrics", "true");
+      System.out.println("========== " + factory.getClass().getSimpleName());
+      
+      Class<?>[] classes = setupClasses();
+      
+      long start = System.currentTimeMillis();
+      
+      ClassInfo[] classInfos = setupClassInfos(classes);
+      start = outputTime(start, "A - Created " + numClasses + " ClassInfos");
+      
+      Object[] targets = instantiate(classInfos);
+      
+      long accessStart = start;
+      useJoinpoint(classInfos, targets, 1);
+      start = outputTime(start, "C - First accessing " + numFields + " fields and methods for " + numClasses + " classes ");
+
+      double[][] result = useJoinpoint(classInfos, targets, numJoinpoint);
+      start = outputTime(start, "D - Accessing " + numFields + " fields and methods for " + numClasses + " classes " + numJoinpoint + " times");
+
+      String s = Arrays.toString(result);
+
+      start = outputTime(accessStart, factory.getClass().getSimpleName() + " - All accesses " + numFields + "  methods for " + numClasses + " classes " + numJoinpoint + " times");
+      System.out.println(s.hashCode());
+      
+      Metrics metrics = new Metrics();
+      System.out.println(metrics.outputEntriesByInvocations(null));
+      System.out.println(metrics.outputEntriesByTime(null));
+   }
+   
+   private Object[] instantiate(ClassInfo[] classInfos) throws Throwable
+   {
+      Object[] targets = new Object[classInfos.length];
+      for (int i = 0 ; i < classInfos.length ; i++)
+      {
+         ConstructorInfo ctor = classInfos[i].getDeclaredConstructor(null);
+         targets[i] = ctor.newInstance(null);
+      }
+      return targets;
+   }
+   
+   private double[][] useJoinpoint(ClassInfo[] classInfos, Object[] targets, int numJoinpoint) throws Throwable
+   {
+      double[][] results = new double[][] {new double[numJoinpoint * targets.length * numFields], new double[numJoinpoint * targets.length * numFields]}; 
+      
+      TypeInfo[] params = new TypeInfo[] {PrimitiveInfo.INT};
+      Object[] values = new Object[1];
+      
+      int two = 0;
+      for (int i = 0 ; i < numJoinpoint ; i ++)
+      {
+         Integer val = Integer.valueOf(i);
+         double half = .5 * i;
+         values[0] = val;
+         for (int c = 0 ; c < classInfos.length ; c++)
+         {
+            for (int m = 0 ; m < numFields ; m++)
+            {
+               MethodInfo method = classInfos[c].getDeclaredMethod(methodName(m), params);
+               double r = ((Double)method.invoke(targets[c], values)).doubleValue();
+               int resultIndex = r > half ? 0 : 1;
+               results[resultIndex][two++] = r;
+            }
+         }
+      }
+      return results;
+   }
+
+   private ClassInfo[] setupClassInfos(Class<?>[] classes) throws Throwable
+   {
+      ClassInfo[] classInfos = new ClassInfo[classes.length];
+      
+      for (int i = 0 ; i < classInfos.length ; i++)
+         classInfos[i] = (ClassInfo)factory.getTypeInfo(classes[i]);
+      return classInfos;
+   }
+   
+   private Class<?>[] setupClasses() throws Exception
+   {
+      Class<?>[] createdClasses = new Class[numClasses];
+      for (int i = 0 ; i < numClasses ; i++)
+      {
+         createdClasses[i] = createClass(i);
+      }
+      return createdClasses;
+   }
+   
+   private Class<?> createClass(int num) throws Exception
+   {
+      CtClass clazz = ClassPool.getDefault().makeClass("org.jboss.test.benchmark.Test" + num);
+      
+      for (int i = 0 ; i < numFields ; i++)
+      {
+         CtMethod method = new CtMethod(CtPrimitiveType.doubleType, methodName(i), new CtClass[] {CtPrimitiveType.intType}, clazz);
+         method.setModifiers(Modifier.PUBLIC);
+         method.setBody("{return java.lang.Math.random() * $1;}");
+         clazz.addMethod(method);
+      }
+      
+      return clazz.toClass();
+   }
+   
+   private String methodName(int num)
+   {
+      return "method" + num;
+   }
+   
+   private long outputTime(long start, String msg)
+   {
+      long end = System.currentTimeMillis();
+      System.out.println(msg + " " + (end - start) + "ms");
+      return end;
+   }
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/ApplicationServerBenchmark.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/ApplicationServerBenchmark.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/ApplicationServerBenchmark.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,540 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.benchmark;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.ConstructorInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtField;
+import javassist.CtMethod;
+import javassist.CtPrimitiveType;
+import javassist.Modifier;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ApplicationServerBenchmark implements ApplicationServerBenchmarkMBean
+{
+   final static Object[] NO_ARGS = new Object[0];
+   
+   static int classes = 3;
+   
+   static final TypeInfoFactory factory = new PropertyConfiguration(System.getProperties()).getTypeInfoFactory();
+   
+   public void testClassInfo(int instances, int calls) throws Throwable
+   {
+      System.out.println("=================");
+      System.out.println("Instances: " + instances);
+      System.out.println("Calls:     " + calls);
+      
+      ClassInfo[] infos = getClassInfos();
+      ConstructorInfo[] constructors = getConstructors(infos); 
+      Object[][] targets = createTargets(instances, constructors);
+      MethodInfo[] methods = getMethods(infos);
+      long methodCalls = callMethodsFirst(targets, methods);
+      methodCalls += callMethods(calls, targets, methods);
+      System.out.println("Total Methods " + methodCalls + "ms");
+      
+//      long start = System.currentTimeMillis();
+//      for (int i = 0 ; i < 640 ; i++)
+//      {
+//         try
+//         {
+//            throw new Exception();
+//         }
+//         catch(Exception e)
+//         {
+//         }
+//      }
+//      System.out.println("Exceptions " + (System.currentTimeMillis() - start));
+   }
+   
+   
+   private ClassInfo[] getClassInfos() throws Throwable
+   {
+      long start = System.currentTimeMillis();
+      ClassInfo[] infos = new ClassInfo[classes];
+      for (int i = 0 ; i < classes ; i++)
+         infos[i] = (ClassInfo)factory.getTypeInfo(classname(i), this.getClass().getClassLoader());
+      long time = System.currentTimeMillis() - start;
+      System.out.println("Getting " + classes + " ClassInfos " + time + "ms");
+      return infos;
+   }
+   
+   private ConstructorInfo[] getConstructors(ClassInfo[] infos)
+   {
+      long start = System.currentTimeMillis();
+      ConstructorInfo[] constructors = new ConstructorInfo[classes]; 
+      for (int i = 0 ; i < classes ; i++)
+         constructors[i] = infos[i].getDeclaredConstructor(null);
+      long time = System.currentTimeMillis() - start;
+      System.out.println("Getting " + classes + " Constructors " + time + "ms");
+      return constructors;
+   }
+   
+   private MethodInfo[] getMethods(ClassInfo[] infos)
+   {
+      TypeInfo[] params = new TypeInfo[] {factory.getTypeInfo(String.class)};
+      
+      long start = System.currentTimeMillis();
+      MethodInfo[] methods = new MethodInfo[classes]; 
+      for (int i = 0 ; i < classes ; i++)
+         methods[i] = infos[i].getDeclaredMethod("setField", params);
+      long time = System.currentTimeMillis() - start;
+      System.out.println("Getting " + classes + " Methods " + time + "ms");
+      return methods;
+   }
+   
+   private long callMethodsFirst(Object[][] instances, MethodInfo[] methods) throws Throwable
+   {
+      if (instances.length != methods.length)
+         throw new IllegalArgumentException("Expected: " + instances.length + " was " + methods.length);
+      
+      Object[] arguments = new Object[methods.length];
+      for (int i = 0 ; i < arguments.length ; i++)
+      {
+         arguments[i] =  "Value" + i + 1;
+      }
+
+      Object[] args = new Object[1];
+      long start = System.currentTimeMillis();
+      for (int i = 0 ; i < methods.length ; i++)
+      {
+         args[0] = arguments[i];
+      }
+      long time = System.currentTimeMillis() - start;
+      System.out.println("Calling " + classes + " Methods first time " + time + "ms");
+      return time;
+   }
+   
+   private long callMethods(int calls, Object[][] instances, MethodInfo[] methods) throws Throwable
+   {
+      if (instances.length != methods.length)
+         throw new IllegalArgumentException("Expected: " + instances.length + " was " + methods.length);
+      
+      String[] strings = new String[100];
+      for (int i = 0 ; i < 100 ; i++)
+         strings[i] = "Value" + i;
+      
+      Object[] args = new Object[1];
+      long start = System.currentTimeMillis();
+      int total = 0;
+      for (int i = 0 ; i < calls ; i++)
+      {
+         for (int j = 0 ; j < methods.length ; j++)
+         {
+            for (int k = 0 ; k < instances[j].length ; k++)
+            {
+               args[0] = strings[total++ % 100];
+               methods[j].invoke(instances[j][k], args);
+            }
+         }
+      }
+      long time = System.currentTimeMillis() - start;
+      System.out.println("Calling " + classes * instances[0].length * calls + " Methods " + time + "ms");
+      return time;
+   }
+   
+   private Object[][] createTargets(int iterations, ConstructorInfo[] constructors) throws Throwable
+   {
+      Object[][] targets = new Object[classes][];
+      for (int i = 0 ; i < classes ; i++)
+         targets[i] = new Object[iterations];
+
+      long start = System.currentTimeMillis();
+      for (int i = 0 ; i < classes ; i++)
+      {
+         for (int j = 0 ; j < iterations ; j++)
+         {
+            targets[i][j] = constructors[i].newInstance(NO_ARGS);
+         }
+      }
+      long time = System.currentTimeMillis() - start;
+      System.out.println("Creating " + classes * iterations + " instances " + time + "ms");
+      return targets;
+   }
+   
+   public static void main(String[] args) throws Throwable
+   {
+      File temp = new File("temp");
+      recursiveDelete(temp);
+      temp.mkdir();
+      
+      File pkg = createPackageDirectories(temp);
+      createClasses(pkg);
+      copyBeanClasses(pkg);
+      createDD(temp);
+
+      File jarFile = new File("temp.jar");
+      if (jarFile.exists())
+         jarFile.delete();
+      compress(temp, jarFile);
+      
+      ApplicationServerBenchmark benchmark = new ApplicationServerBenchmark();
+      benchmark.testClassInfo(1000, 5);
+   }
+   
+   private static void copyBeanClasses(File packageDir) throws Exception
+   {
+      copyBeanClass(ApplicationServerBenchmark.class, packageDir);
+      copyBeanClass(ApplicationServerBenchmarkMBean.class, packageDir);
+   }
+   
+   private static void copyBeanClass(Class<?> clazz, File packageDir) throws Exception
+   {
+      String name = clazz.getName().replace('.', '/') + ".class";
+      InputStream in = null;
+      FileOutputStream out = null;
+      try
+      {
+         in = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
+         out = new FileOutputStream(new File(packageDir, clazz.getSimpleName() + ".class"));
+         int b = in.read();
+         while (b != -1)
+         {
+            out.write(b);
+            b = in.read();
+         }
+      }
+      finally
+      {
+         try
+         {
+            in.close();
+         }
+         catch (Exception ignore)
+         {
+         }
+         try
+         {
+            out.close();
+         }
+         catch (Exception ignore)
+         {
+         }
+      }
+   }
+   
+   /**
+    * Compress a directory in a JAR layout to a file
+    * @param directory The directory
+    * @param target The JAR file
+    * @exception IOException Thrown if an error occurs
+    */
+   public static void compress(File directory, File target) throws IOException
+   {
+      if (directory == null)
+         throw new IllegalArgumentException("Directory is null");
+
+      if (target == null)
+         throw new IllegalArgumentException("Target is null");
+
+      if (target.exists())
+         recursiveDelete(target);
+
+      Manifest manifest = null;
+
+      File manifestFile = new File(directory, "META-INF/MANIFEST.MF");
+      if (manifestFile.exists())
+      {
+         FileInputStream fis = null;
+         try
+         {
+            fis = new FileInputStream(manifestFile);
+            manifest = new Manifest(fis);
+         }
+         finally
+         {
+            try
+            {
+               if (fis != null)
+                  fis.close();
+            }
+            catch (IOException ignore)
+            {
+               // Ignore
+            }
+         }
+      }
+      else
+      {
+         //log.fine("No META-INF/MANIFEST.MF found; creating one");
+         manifest = new Manifest();
+      }
+
+      JarOutputStream jos = null;
+
+      try
+      {
+         FileOutputStream fos = new FileOutputStream(target);
+         jos = new JarOutputStream(fos, manifest);
+
+         int bytesRead;
+         byte[] buffer = new byte[4096];
+
+         List<File> entries = findEntries(directory);
+
+         if (entries != null)
+         {
+            entries.remove(new File("META-INF/MANIFEST.MF"));
+
+            for (File file : entries)
+            {
+               File f = new File(directory, file.getPath());
+               JarEntry entry = new JarEntry(file.getPath());
+               jos.putNextEntry(entry);
+
+               FileInputStream in = null;
+               try
+               {
+                  in = new FileInputStream(f);
+                  while ((bytesRead = in.read(buffer)) != -1)
+                     jos.write(buffer, 0, bytesRead);
+               }
+               finally
+               {
+                  if (in != null)
+                  {
+                     try
+                     {
+                        in.close();
+                     }
+                     catch (IOException ioe)
+                     {
+                        // Ignore
+                     }
+                  }
+               }
+            }
+         }
+
+         jos.flush();
+      }
+      finally
+      {
+         try
+         {
+            if (jos != null)
+               jos.close();
+         }
+         catch (IOException ignore)
+         {
+            // Ignore
+         }
+      }
+   }
+   
+   /**
+    * Recursive delete
+    * @param f The file handler
+    * @exception IOException Thrown if a file could not be deleted
+    */
+   public static void recursiveDelete(File f) throws IOException
+   {
+      if (f != null && f.exists())
+      {
+         File[] files = f.listFiles();
+         if (files != null)
+         {
+            for (File file : files)
+            {
+               if (file.isDirectory())
+               {
+                  recursiveDelete(file);
+               }
+               else
+               {
+                  if (!file.delete())
+                     throw new IOException("Could not delete " + file);
+               }
+            }
+         }
+         if (!f.delete())
+            throw new IOException("Could not delete " + f);
+      }
+   }
+
+   /**
+    * Find all file entries for a directory
+    * @param root The root directory
+    * @return The list of files
+    */
+   private static List<File> findEntries(File root)
+   {
+      try
+      {
+         return getListing(root, root);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   /**
+    * Recursively walk a directory tree and return a list of all files entries found
+    * @param root The root directory
+    * @param directory The current directory
+    * @return The list of files
+    * @exception Exception Thrown if an error occurs
+    */
+   private static List<File> getListing(File root, File directory) throws Exception
+   {
+      List<File> result = new ArrayList<File>();
+
+      File[] filesAndDirs = directory.listFiles();
+
+      if (filesAndDirs != null)
+      {
+         for (File file : filesAndDirs)
+         {
+            if (file.isDirectory())
+            {
+               List<File> deeperList = getListing(root, file);
+               result.addAll(deeperList);
+            }
+            else
+            {
+               String fileName = file.getPath().substring(root.getPath().length() + 1);
+               result.add(new File(fileName));
+            }
+         }
+      }
+
+      return result;
+   }
+
+   private static void createDD(File root)
+   {
+      File file = new File(root, "META-INF");
+      file.mkdir();
+      
+      BufferedWriter out = null;
+      try
+      {
+         out = new BufferedWriter(new FileWriter(new File(file, "benchmark-jboss-beans.xml")));
+         out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+         out.write("<deployment xmlns=\"urn:jboss:bean-deployer:2.0\">\n");
+         out.write("  <bean name=\"TestApplicationServerBenchmark\" class=\"org.jboss.test.benchmark.ApplicationServerBenchmark\">\n");
+         out.write("    <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(exposedInterface=org.jboss.test.benchmark.ApplicationServerBenchmarkMBean.class, name=\"org.jboss.reflect:service=Benchmark\")</annotation>\n");
+         out.write("  </bean>\n");
+         out.write("</deployment>");
+      }
+      catch (IOException e)
+      {
+         // AutoGenerated
+         throw new RuntimeException(e);
+      }
+      finally
+      {
+         try
+         {
+            out.close();
+         }
+         catch (Exception ignore)
+         {
+         }
+      }
+   }
+   
+   private static File createPackageDirectories(File root)
+   {
+      String[] split = ApplicationServerBenchmark.class.getPackage().getName().split("\\.");
+      for (String s : split)
+      {
+         root = new File(root, s);
+         root.mkdir();
+      }
+         
+      return root;
+   }
+   
+   private static void createClasses(File packageDir) throws Exception
+   {
+      CtClass string = ClassPool.getDefault().get(String.class.getName());
+      for (int i = 0 ; i < classes ; i++)
+      {
+         CtClass clazz = ClassPool.getDefault().makeClass(classname(i));
+         CtField field = new CtField(string, "field", clazz);
+         clazz.addField(field);
+         
+         CtMethod method = new CtMethod(CtPrimitiveType.voidType, "setField", new CtClass[] {string}, clazz);
+         method.setModifiers(Modifier.PUBLIC);
+         clazz.addMethod(method);
+         method.setBody("{field = $1;}");
+         
+         method = new CtMethod(string, "getField", new CtClass[] {}, clazz);
+         method.setModifiers(Modifier.PUBLIC);
+         clazz.addMethod(method);
+         method.setBody("{return field;}");
+         
+         byte[] bytes = clazz.toBytecode();
+         FileOutputStream out = null;
+         try
+         {
+            out = new FileOutputStream(new File(packageDir, clazz.getSimpleName() + ".class"));
+            out.write(bytes);
+         }
+         catch (Exception e)
+         {
+            throw e;
+         }
+         finally
+         {
+            try
+            {
+               out.close();
+            }
+            catch (Exception ignore)
+            {
+            }
+         }
+         clazz.toClass();
+      }
+   }
+   
+   private static String classname(int i)
+   {
+      return "org.jboss.test.benchmark.TestClass" + i;
+   }
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/ApplicationServerBenchmarkMBean.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/ApplicationServerBenchmarkMBean.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/ApplicationServerBenchmarkMBean.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.benchmark;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ApplicationServerBenchmarkMBean
+{
+   void testClassInfo(int instances, int calls) throws Throwable;
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/IntrospectionAccessorBenchmark.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/IntrospectionAccessorBenchmark.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/IntrospectionAccessorBenchmark.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.benchmark;
+
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class IntrospectionAccessorBenchmark extends AccessorBenchmark
+{
+   @Override
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new IntrospectionTypeInfoFactory();
+   }
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/IntrospectionAccessorBenchmark2.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/IntrospectionAccessorBenchmark2.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/IntrospectionAccessorBenchmark2.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.benchmark;
+
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class IntrospectionAccessorBenchmark2 extends AccessorBenchmark2
+{
+   @Override
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new IntrospectionTypeInfoFactory();
+   }
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/JavassistAccessorBenchmark.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/JavassistAccessorBenchmark.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/JavassistAccessorBenchmark.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.benchmark;
+
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavassistAccessorBenchmark extends AccessorBenchmark
+{
+   @Override
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new JavassistTypeInfoFactory();
+   }
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/JavassistAccessorBenchmark2.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/JavassistAccessorBenchmark2.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/JavassistAccessorBenchmark2.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.benchmark;
+
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavassistAccessorBenchmark2 extends AccessorBenchmark2
+{
+   @Override
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new JavassistTypeInfoFactory();
+   }
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/Test.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/Test.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/benchmark/Test.java	2010-04-26 10:17:07 UTC (rev 104251)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.benchmark;
+
+import javassist.Modifier;
+import javassist.bytecode.Bytecode;
+import javassist.bytecode.ClassFile;
+import javassist.bytecode.CodeAttribute;
+import javassist.bytecode.MethodInfo;
+import javassist.bytecode.Opcode;
+import javassist.bytecode.StackMapTable;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Test
+{
+   public int test(int i)
+   {
+      return i * 2;
+   }
+   
+   public void createTestMethod(ClassFile cf) throws Throwable 
+   {
+      //Create the MethodInfo
+      MethodInfo minfo = new javassist.bytecode.MethodInfo(cf.getConstPool(), "test", "(I)I");
+      minfo.setAccessFlags(Modifier.PUBLIC);
+      Bytecode code = new Bytecode(cf.getConstPool(), 0, 0);
+      
+      int pc = code.currentPc();
+      
+      code.addIload(1); 
+      code.addIconst(2); 
+      code.addOpcode(Opcode.IMUL);
+      code.addOpcode(Opcode.IRETURN); 
+    
+      //We need 2 local variable slots.
+      //One for 'this', one for the 'i' variable
+      //(If any variables are long or double they need to slots
+      code.setMaxLocals(2);
+      
+      CodeAttribute ca = code.toCodeAttribute();
+      minfo.setCodeAttribute(ca);
+
+      StackMapTable.Writer writer = new StackMapTable.Writer(32);
+      writer.sameFrame(pc);
+      ca.setAttribute(writer.toStackMapTable(cf.getConstPool()));
+      
+      cf.addMethod(minfo);
+   }
+}




More information about the jboss-cvs-commits mailing list