diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2012-10-19 07:17:44 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2012-10-19 07:17:44 +0000 |
commit | 34a093c27a90fdcb8f463f2b3ee74e612dcc12f8 (patch) | |
tree | d8f33c9c7289b8649ec8bb9ecdbf02ba7e1ef269 | |
parent | b897d2cf59f2bfb9b526991b696ec1ae7db5e597 (diff) | |
download | javassist-34a093c27a90fdcb8f463f2b3ee74e612dcc12f8.tar.gz javassist-34a093c27a90fdcb8f463f2b3ee74e612dcc12f8.zip |
fixed JASSIST-160
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@674 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r-- | javassist.jar | bin | 698237 -> 699131 bytes | |||
-rw-r--r-- | src/main/javassist/bytecode/MethodInfo.java | 2 | ||||
-rw-r--r-- | src/main/javassist/bytecode/StackMap.java | 5 | ||||
-rw-r--r-- | src/main/javassist/bytecode/StackMapTable.java | 32 | ||||
-rw-r--r-- | src/test/javassist/bytecode/StackMapTest.java | 25 |
5 files changed, 62 insertions, 2 deletions
diff --git a/javassist.jar b/javassist.jar Binary files differindex d0a93f28..dd1d5843 100644 --- a/javassist.jar +++ b/javassist.jar diff --git a/src/main/javassist/bytecode/MethodInfo.java b/src/main/javassist/bytecode/MethodInfo.java index 4ca4e90d..1db524ce 100644 --- a/src/main/javassist/bytecode/MethodInfo.java +++ b/src/main/javassist/bytecode/MethodInfo.java @@ -431,7 +431,7 @@ public class MethodInfo { * 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 { diff --git a/src/main/javassist/bytecode/StackMap.java b/src/main/javassist/bytecode/StackMap.java index fe3655fd..1abdc40f 100644 --- a/src/main/javassist/bytecode/StackMap.java +++ b/src/main/javassist/bytecode/StackMap.java @@ -396,6 +396,11 @@ public class StackMap extends AttributeInfo { return super.locals(pos, offset, num); } + + public void uninitialized(int pos, int offset) { + if (where <= offset) + ByteArray.write16bit(offset + gap, info, pos + 1); + } } /** diff --git a/src/main/javassist/bytecode/StackMapTable.java b/src/main/javassist/bytecode/StackMapTable.java index 4518ef36..08770afc 100644 --- a/src/main/javassist/bytecode/StackMapTable.java +++ b/src/main/javassist/bytecode/StackMapTable.java @@ -28,7 +28,7 @@ import javassist.CannotCompileException; * <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 @@ public class StackMapTable extends AttributeInfo { 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 @@ public class StackMapTable extends AttributeInfo { 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 @@ public class StackMapTable extends AttributeInfo { 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 @@ public class StackMapTable extends AttributeInfo { 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; diff --git a/src/test/javassist/bytecode/StackMapTest.java b/src/test/javassist/bytecode/StackMapTest.java index 4714f7aa..876b335e 100644 --- a/src/test/javassist/bytecode/StackMapTest.java +++ b/src/test/javassist/bytecode/StackMapTest.java @@ -622,6 +622,31 @@ public class StackMapTest extends TestCase { } } + 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"); |