From: chiba Date: Fri, 19 Oct 2012 07:17:44 +0000 (+0000) Subject: fixed JASSIST-160 X-Git-Tag: rel_3_17_1_ga~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=34a093c27a90fdcb8f463f2b3ee74e612dcc12f8;p=javassist.git fixed JASSIST-160 git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@674 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/javassist.jar b/javassist.jar index d0a93f28..dd1d5843 100644 Binary files a/javassist.jar and b/javassist.jar differ 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; * stack_map attribute. * *

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 Object_variable_info + * or Uninitialized_variable_info is visited. + * + * @param tag OBJECT or UNINIT. + * @param data the value of cpool_index or offset. + * @param pos the position of cpool_index or offset. + */ + 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");