[jboss-cvs] javassist SVN: r674 - in trunk: src/main/javassist/bytecode and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 19 03:17:44 EDT 2012


Author: chiba
Date: 2012-10-19 03:17:44 -0400 (Fri, 19 Oct 2012)
New Revision: 674

Modified:
   trunk/javassist.jar
   trunk/src/main/javassist/bytecode/MethodInfo.java
   trunk/src/main/javassist/bytecode/StackMap.java
   trunk/src/main/javassist/bytecode/StackMapTable.java
   trunk/src/test/javassist/bytecode/StackMapTest.java
Log:
fixed JASSIST-160

Modified: trunk/javassist.jar
===================================================================
(Binary files differ)

Modified: trunk/src/main/javassist/bytecode/MethodInfo.java
===================================================================
--- trunk/src/main/javassist/bytecode/MethodInfo.java	2012-10-06 14:53:31 UTC (rev 673)
+++ trunk/src/main/javassist/bytecode/MethodInfo.java	2012-10-19 07:17:44 UTC (rev 674)
@@ -431,7 +431,7 @@
      * include a code attribute, nothing happens.
      *
      * @param pool          used for making type hierarchy.
-     * @see StackMapTable
+     * @see StackMap
      * @since 3.12
      */
     public void rebuildStackMapForME(ClassPool pool) throws BadBytecode {

Modified: trunk/src/main/javassist/bytecode/StackMap.java
===================================================================
--- trunk/src/main/javassist/bytecode/StackMap.java	2012-10-06 14:53:31 UTC (rev 673)
+++ trunk/src/main/javassist/bytecode/StackMap.java	2012-10-19 07:17:44 UTC (rev 674)
@@ -396,6 +396,11 @@
 
             return super.locals(pos, offset, num);
         }
+
+        public void uninitialized(int pos, int offset) {
+            if (where <= offset)
+                ByteArray.write16bit(offset + gap, info, pos + 1);
+        }
     }
 
     /**

Modified: trunk/src/main/javassist/bytecode/StackMapTable.java
===================================================================
--- trunk/src/main/javassist/bytecode/StackMapTable.java	2012-10-06 14:53:31 UTC (rev 673)
+++ trunk/src/main/javassist/bytecode/StackMapTable.java	2012-10-19 07:17:44 UTC (rev 674)
@@ -28,7 +28,7 @@
  * <code>stack_map</code> attribute.
  *
  * <p>This is an entry in the attributes table of a Code attribute.
- * It was introduced by J2SE 6 for the process of verification by
+ * It was introduced by J2SE 6 for the verification by
  * typechecking.
  *
  * @see StackMap
@@ -244,6 +244,7 @@
             int data = 0;
             if (tag == OBJECT || tag == UNINIT) {
                 data = ByteArray.readU16bit(info, pos + 2);
+                objectOrUninitialized(tag, data, pos + 2);
                 pos += 2;
             }
 
@@ -286,6 +287,7 @@
                 tags[i] = tag;
                 if (tag == OBJECT || tag == UNINIT) {
                     data[i] = ByteArray.readU16bit(info, p + 1);
+                    objectOrUninitialized(tag, data[i], p + 1);
                     p += 3;
                 }
                 else {
@@ -346,12 +348,23 @@
                 tags[i] = tag;
                 if (tag == OBJECT || tag == UNINIT) {
                     data[i] = ByteArray.readU16bit(info, pos);
+                    objectOrUninitialized(tag, data[i], pos);
                     pos += 2;
                 }
             }
 
             return pos;
         }
+
+        /**
+         * Invoked if <code>Object_variable_info</code>
+         * or <code>Uninitialized_variable_info</code> is visited.
+         *
+         * @param tag		<code>OBJECT</code> or <code>UNINIT</code>.
+         * @param data		the value of <code>cpool_index</code> or <code>offset</code>.
+         * @param pos		the position of <code>cpool_index</code> or <code>offset</code>.
+         */
+        public void objectOrUninitialized(int tag, int data, int pos) {}
     }
 
     static class SimpleCopy extends Walker {
@@ -791,9 +804,26 @@
     void shiftPc(int where, int gapSize, boolean exclusive)
         throws BadBytecode
     {
+    	new OffsetShifter(this, where, gapSize).parse();
         new Shifter(this, where, gapSize, exclusive).doit();
     }
 
+    static class OffsetShifter extends Walker {
+    	int where, gap;
+
+    	public OffsetShifter(StackMapTable smt, int where, int gap) {
+    		super(smt);
+    		this.where = where;
+    		this.gap = gap;
+    	}
+
+    	public void objectOrUninitialized(int tag, int data, int pos) {
+    		if (tag == UNINIT)
+    			if (where <= data)
+    				ByteArray.write16bit(data + gap, info, pos);
+    	}
+    }
+
     static class Shifter extends Walker {
         private StackMapTable stackMap;
         int where, gap;

Modified: trunk/src/test/javassist/bytecode/StackMapTest.java
===================================================================
--- trunk/src/test/javassist/bytecode/StackMapTest.java	2012-10-06 14:53:31 UTC (rev 673)
+++ trunk/src/test/javassist/bytecode/StackMapTest.java	2012-10-19 07:17:44 UTC (rev 674)
@@ -622,6 +622,31 @@
         }
     }
 
+    public void testConstructor3() throws Exception {
+        CtClass cc = loader.get("javassist.bytecode.StackMapTest$C4");
+        MethodInfo mi = cc.getDeclaredMethod("foo").getMethodInfo();
+        mi.rebuildStackMapForME(loader);
+        CodeIterator ci = mi.getCodeAttribute().iterator();
+        ci.insertGap(0, 7);
+        cc.writeFile();
+        Object t1 = make(cc.getName());
+        assertEquals(6, invoke(t1, "test"));
+    }
+
+    public static class C4 {
+        public int test() { return foo(3); }
+        public int foo(int i) {
+            String s = new String(i > 0 ? "pos" : "negative");
+            System.out.println("2nd stage");
+            int len = 0;
+            if (i > 0) {
+                String t =  new String(i > 0 ? "pos" : "negative");
+                len = t.length();
+            }
+            return s.length() + len;
+        }
+    }
+
     public void tstCtClassType() throws Exception {
         ClassPool cp = ClassPool.getDefault();
         CtClass cc = cp.get("javassist.CtClassType");



More information about the jboss-cvs-commits mailing list