[jboss-cvs] JBossAS SVN: r102958 - projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 25 11:15:14 EDT 2010


Author: kabir.khan at jboss.com
Date: 2010-03-25 11:15:13 -0400 (Thu, 25 Mar 2010)
New Revision: 102958

Modified:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistConstructorFactory.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistFieldFactory.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMethodFactory.java
Log:
[JBREFLECT-6] Fix local variable sizes after Andrew Dinn explained them to me

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistConstructorFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistConstructorFactory.java	2010-03-25 14:36:35 UTC (rev 102957)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistConstructorFactory.java	2010-03-25 15:15:13 UTC (rev 102958)
@@ -113,8 +113,6 @@
       
       int pc = code.currentPc();
       
-      int s = countParameterStackSize(1, getParameterTypes());
-
       checkParameters(code, 1);
 
       code.addNew(ctConstructor.getDeclaringClass().getName());
@@ -125,7 +123,10 @@
       code.addInvokespecial(ctConstructor.getDeclaringClass(), "<init>", ctConstructor.getSignature());
       code.addOpcode(Opcode.ARETURN);
       
-      code.setMaxLocals(s + 1);
+      //We need 3 local variable slots.
+      //One for 'this', one for the target reference and one for the argument array.
+      //These are all object references and so take one slot each 
+      code.setMaxLocals(3);
       CodeAttribute ca = code.toCodeAttribute();
       minfo.setCodeAttribute(ca);
 

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistFieldFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistFieldFactory.java	2010-03-25 14:36:35 UTC (rev 102957)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistFieldFactory.java	2010-03-25 15:15:13 UTC (rev 102958)
@@ -145,17 +145,29 @@
       Bytecode code = new Bytecode(cp, 0, 0);
       
       int pc = code.currentPc();
-      int s = countParameterStackSize(1, getFieldType());
       boolean isStatic = Modifier.isStatic(ctField.getModifiers());
 
       checkTargetParameter(code, ctField.getDeclaringClass().getName(), isStatic);
-      
+
+      int maxLocals = 0;
       if (index == 0)
+      {
+         //We need 2 local variable slots.
+         //One for 'this' and one for the target reference
+         //These are all object references and so take one slot each 
+         maxLocals = 2;
          makeGetMethod(code, methods[index], cp, isStatic);
+      }
       else
+      {
+         //We need 3 local variable slots.
+         //One for 'this', one for the target reference and one for the argument array.
+         //These are all object references and so take one slot each 
+         maxLocals = 3;
          makeSetMethod(code, methods[index], cp, isStatic);
+      }
       
-      code.setMaxLocals(s + 1);
+      code.setMaxLocals(maxLocals);
       CodeAttribute ca = code.toCodeAttribute();
       minfo.setCodeAttribute(ca);
 

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMethodFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMethodFactory.java	2010-03-25 14:36:35 UTC (rev 102957)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMethodFactory.java	2010-03-25 15:15:13 UTC (rev 102958)
@@ -167,7 +167,10 @@
          code.addOpcode(Opcode.ARETURN);
       }
 
-      code.setMaxLocals(determineMaxStackSize());
+      //We need 3 local variable slots.
+      //One for 'this', one for the target reference and one for the argument array.
+      //These are all object references and so take one slot each 
+      code.setMaxLocals(3);
       
       CodeAttribute ca = code.toCodeAttribute();
       minfo.setCodeAttribute(ca);
@@ -177,20 +180,4 @@
       ca.setAttribute(writer.toStackMapTable(cp));
       return minfo;
    }
-   
-   private int determineMaxStackSize()
-   {
-      //Not 100% sure what is going on here :-)
-      
-      //This is the original code which yields a too small stack size if the target parameter size is 0
-      //int stackSize = countParameterStackSize(1, getParameterTypes());
-      //code.setMaxLocals(stackSize + 1);
-
-      //Try adding the parameters to the method being implemented AND the parameters for the target method
-      //This might be too big, but hopefully that won't hurt
-      int offset = 1; //TODO 0 if the target is static?
-      int stackSize = countParameterStackSize(offset, getParameterTypes());
-      stackSize += 2; //size of parameters to the invoke(Object target, Object[] args)
-      return stackSize + 1;
-   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list