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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Oct 6 10:47:31 EDT 2012


Author: chiba
Date: 2012-10-06 10:47:31 -0400 (Sat, 06 Oct 2012)
New Revision: 672

Modified:
   trunk/Readme.html
   trunk/javassist.jar
   trunk/src/main/javassist/bytecode/CodeIterator.java
   trunk/src/main/javassist/bytecode/stackmap/Tracer.java
   trunk/src/main/javassist/bytecode/stackmap/TypeData.java
   trunk/src/test/javassist/bytecode/StackMapTest.java
   trunk/src/test/test4/InvokeDyn.java
Log:
fixed JASSIST-160

Modified: trunk/Readme.html
===================================================================
--- trunk/Readme.html	2012-10-04 14:13:37 UTC (rev 671)
+++ trunk/Readme.html	2012-10-06 14:47:31 UTC (rev 672)
@@ -7,7 +7,7 @@
 
 <h1>Javassist version 3</h1>
 
-<h3>Copyright (C) 1999-2011 by Shigeru Chiba, All rights reserved.</h3>
+<h3>Copyright (C) 1999-2012 by Shigeru Chiba, All rights reserved.</h3>
 
 <p><br></p>
 

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

Modified: trunk/src/main/javassist/bytecode/CodeIterator.java
===================================================================
--- trunk/src/main/javassist/bytecode/CodeIterator.java	2012-10-04 14:13:37 UTC (rev 671)
+++ trunk/src/main/javassist/bytecode/CodeIterator.java	2012-10-06 14:47:31 UTC (rev 672)
@@ -27,10 +27,14 @@
  * the following code substitutes the <code>NOP</code> instruction for the first
  * instruction of the method:  
  *
- * <pre>CodeAttribute ca = method.getMethodInfo().getCodeAttribute();
+ * <pre>
+ * CodeAttribute ca = method.getMethodInfo().getCodeAttribute();
  * CodeIterator ci = ca.iterator();
  * ci.writeByte(Opcode.NOP, 0);</pre>
  *
+ * <p>To visit every instruction, call {@link #next()} on a <code>CodeIterator</code>.
+ * It returns the index of the first byte of the next instruction.
+ *
  * <p>If there are multiple <code>CodeIterator</code>s referring to the
  * same <code>Code_attribute</code>, then inserting a gap by one
  * <code>CodeIterator</code> will break the other

Modified: trunk/src/main/javassist/bytecode/stackmap/Tracer.java
===================================================================
--- trunk/src/main/javassist/bytecode/stackmap/Tracer.java	2012-10-04 14:13:37 UTC (rev 671)
+++ trunk/src/main/javassist/bytecode/stackmap/Tracer.java	2012-10-06 14:47:31 UTC (rev 672)
@@ -803,7 +803,9 @@
             String className = cpool.getMethodrefClassName(i);
             TypeData target = stackTypes[--stackTop];
             if (target instanceof TypeData.UninitTypeVar && target.isUninit())
-                constructorCalled((TypeData.UninitTypeVar)target);
+                constructorCalled(target, ((TypeData.UninitTypeVar)target).offset());
+            else if (target instanceof TypeData.UninitData)
+                constructorCalled(target, ((TypeData.UninitData)target).offset());
 
             target.setType(className, classPool);
         }
@@ -814,9 +816,10 @@
 
     /* This is a constructor call on an uninitialized object.
      * Sets flags of other references to that object.
+     *
+     * @param offset        the offset where the object has been created.
      */
-    private void constructorCalled(TypeData.UninitTypeVar target) {
-        int offset = target.offset();
+    private void constructorCalled(TypeData target, int offset) {
         target.constructorCalled(offset);
         for (int i = 0; i < stackTop; i++)
             stackTypes[i].constructorCalled(offset);

Modified: trunk/src/main/javassist/bytecode/stackmap/TypeData.java
===================================================================
--- trunk/src/main/javassist/bytecode/stackmap/TypeData.java	2012-10-04 14:13:37 UTC (rev 671)
+++ trunk/src/main/javassist/bytecode/stackmap/TypeData.java	2012-10-06 14:47:31 UTC (rev 672)
@@ -745,11 +745,13 @@
 
         public void setType(String typeName, ClassPool cp) throws BadBytecode {
             super.setType(typeName, cp);
-            initialized = true;
+            // initialized = true;
         }
 
         public String toString() { return "uninit:" + getName() + "@" + offset; }
 
+        public int offset() { return offset; }
+
         public void constructorCalled(int offset) {
             if (offset == this.offset)
                 initialized = true;

Modified: trunk/src/test/javassist/bytecode/StackMapTest.java
===================================================================
--- trunk/src/test/javassist/bytecode/StackMapTest.java	2012-10-04 14:13:37 UTC (rev 671)
+++ trunk/src/test/javassist/bytecode/StackMapTest.java	2012-10-06 14:47:31 UTC (rev 672)
@@ -529,6 +529,7 @@
     public static class T8dd {
         java.util.List foo(String s) { return new java.util.ArrayList(); }
     }
+
     public static class T8d {
         static T8dd helper() { return new T8dd(); }
         int integer() { return 9; }
@@ -588,6 +589,39 @@
         }
     }
 
+    public void testInnerClass() throws Exception {
+        CtClass cc = loader.get("javassist.bytecode.StackMapTest$T9");
+        CtClass par = loader.get("javassist.bytecode.StackMapTest$T9$Parent");
+        CtClass in = loader.get("javassist.bytecode.StackMapTest$T9$In");
+        rebuildStackMaps2(cc);
+        rebuildStackMaps2(par);
+        rebuildStackMaps2(in);
+        cc.writeFile();
+        in.writeFile();
+        par.writeFile();
+        Object t1 = make(cc.getName());
+        assertEquals(19, invoke(t1, "test"));
+    }
+
+    public static class T9 {
+        class Parent {
+            int f; 
+            Parent(int i) { f = i; } 
+        }
+        class In extends Parent {
+            int value;
+            public In(int i) {
+                super(i > 0 ? 10 : 20);
+                value = i;
+            }
+        }
+
+        public int test() {
+            In in = new In(9);
+            return in.value + in.f;
+        }
+    }
+
     public void tstCtClassType() throws Exception {
         ClassPool cp = ClassPool.getDefault();
         CtClass cc = cp.get("javassist.CtClassType");

Modified: trunk/src/test/test4/InvokeDyn.java
===================================================================
--- trunk/src/test/test4/InvokeDyn.java	2012-10-04 14:13:37 UTC (rev 671)
+++ trunk/src/test/test4/InvokeDyn.java	2012-10-06 14:47:31 UTC (rev 672)
@@ -4,11 +4,23 @@
 
 public class InvokeDyn {
     public static int test9(int i, String s) { return 9; }
+    public int test8(int i, String s) { return 8; } 
 
-    public static CallSite boot(MethodHandles.Lookup caller, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException {
+    public static CallSite boot(MethodHandles.Lookup caller, String name, MethodType type)
+        throws NoSuchMethodException, IllegalAccessException
+    {
         MethodHandles.Lookup lookup = MethodHandles.lookup();
         Class thisClass = lookup.lookupClass();
         MethodHandle method = lookup.findStatic(thisClass, "test9", MethodType.methodType(int.class, int.class, String.class));
         return new ConstantCallSite(method);
     }
+
+    public CallSite boot2(MethodHandles.Lookup caller, String name, MethodType type)
+        throws NoSuchMethodException, IllegalAccessException
+    {
+        MethodHandles.Lookup lookup = MethodHandles.lookup();
+        Class thisClass = lookup.lookupClass();
+        MethodHandle method = lookup.findVirtual(thisClass, "test8", MethodType.methodType(int.class, int.class, String.class));
+        return new ConstantCallSite(method.asType(MethodType.methodType(int.class, Object.class, int.class, String.class)));
+    }
 }



More information about the jboss-cvs-commits mailing list