diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2012-09-28 17:07:43 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2012-09-28 17:07:43 +0000 |
commit | d58f611274b91ff23e521db513107189b0991ca0 (patch) | |
tree | ff943449d9304205adc863fd5c12d59e96f772c4 /src/test | |
parent | fc32a1d8493f30ee2e543d54797d36e822c8248a (diff) | |
download | javassist-d58f611274b91ff23e521db513107189b0991ca0.tar.gz javassist-d58f611274b91ff23e521db513107189b0991ca0.zip |
fixed JASSIST-160 by rewriting the whole javassist.bytecode.stackmap package.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@666 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/javassist/bytecode/StackMapTest.java | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/src/test/javassist/bytecode/StackMapTest.java b/src/test/javassist/bytecode/StackMapTest.java index 3dba27d3..c7a77cb8 100644 --- a/src/test/javassist/bytecode/StackMapTest.java +++ b/src/test/javassist/bytecode/StackMapTest.java @@ -10,6 +10,7 @@ import java.io.PrintStream; import java.lang.reflect.Method; import javassist.ClassPool; +import javassist.CodeConverter; import javassist.CtClass; import javassist.CtMethod; import javassist.CtNewMethod; @@ -299,7 +300,7 @@ public class StackMapTest extends TestCase { rebuildStackMaps2(cc); cc.writeFile(); Object t1 = make(cc.getName()); - assertEquals(122, invoke(t1, "test")); + assertEquals(123, invoke(t1, "test")); } public static class T5 { @@ -339,6 +340,89 @@ public class StackMapTest extends TestCase { } } + public void testSwitchCase() throws Exception { + CtClass cc = loader.get("javassist.bytecode.StackMapTest$T7"); + // CodeConverter conv = new CodeConverter(); + // conv.replaceNew(cc, cc, "make2"); + // cc.instrument(conv); + StringBuffer sbuf = new StringBuffer("String s;"); + for (int i = 0; i < 130; i++) + sbuf.append("s =\"" + i + "\";"); + + cc.getDeclaredMethod("foo").insertBefore(sbuf.toString()); + cc.getDeclaredMethod("test2").setBody(loader.get("javassist.bytecode.StackMapTest$T8").getDeclaredMethod("test2"), null); + //rebuildStackMaps2(cc); + cc.writeFile(); + Object t1 = make(cc.getName()); + assertEquals(110, invoke(t1, "test")); + } + + public static class T7 { + int value = 1; + T7 t7; + public static T7 make2() { return null; } + public int foo() { return 1; } + public int test() { return test2(10); } + public int test2(int k) { return k; } + } + + public static class T8 { + public int test2(int k) { + String s = "abc"; + T7 t = k > 0 ? new T7() : new T7(); + switch (k) { + case 0: + t = new T7(); + k += t.value; + break; + case 10: + k += 100; + break; + } + return k; + } + } + + public void testSwitchCase2() throws Exception { + CtClass cc = loader.get("javassist.bytecode.StackMapTest$T7b"); + StringBuffer sbuf = new StringBuffer("String s;"); + for (int i = 0; i < 130; i++) + sbuf.append("s =\"" + i + "\";"); + + cc.getDeclaredMethod("foo").insertBefore(sbuf.toString()); + cc.getDeclaredMethod("test2").setBody(loader.get("javassist.bytecode.StackMapTest$T8b").getDeclaredMethod("test2"), null); + rebuildStackMaps2(cc); + cc.writeFile(); + Object t1 = make(cc.getName()); + assertEquals(110, invoke(t1, "test")); + } + + public static class T7b { + int value = 1; + T7b t7; + public static T7b make2() { return null; } + public int foo() { return 1; } + public int test() { return test2(10); } + public int test2(int k) { return k; } + } + + public static class T8b { + public int test2(int k) { + String s = "abc"; + T7b t = k > 0 ? new T7b() : new T7b(); + switch (k) { + case 0: + t = new T7b(); + k += t.value; + break; + case 10: + k += 100; + break; + } + return k; + } + } + public void tstCtClassType() throws Exception { ClassPool cp = ClassPool.getDefault(); CtClass cc = cp.get("javassist.CtClassType"); |