diff options
author | chibash <chiba@javassist.org> | 2015-01-25 18:16:48 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2015-01-25 18:16:48 +0900 |
commit | e59339343a538699b632bd9fa0cf4f251ab6f3ee (patch) | |
tree | 3a0f9f1c3d8d9058a787057b519377f43d3e1775 | |
parent | e8c023af06f04877ccc83911c6f6900574486a6c (diff) | |
download | javassist-e59339343a538699b632bd9fa0cf4f251ab6f3ee.tar.gz javassist-e59339343a538699b632bd9fa0cf4f251ab6f3ee.zip |
fixed JIRA JASSIST-241
-rw-r--r-- | javassist.jar | bin | 723078 -> 723174 bytes | |||
-rw-r--r-- | src/main/javassist/CtBehavior.java | 10 | ||||
-rw-r--r-- | src/main/javassist/bytecode/stackmap/BasicBlock.java | 1 | ||||
-rw-r--r-- | src/test/javassist/JvstTest4.java | 4 | ||||
-rw-r--r-- | src/test/javassist/JvstTest5.java | 9 | ||||
-rw-r--r-- | src/test/test5/JIRA241.java | 33 |
6 files changed, 53 insertions, 4 deletions
diff --git a/javassist.jar b/javassist.jar Binary files differindex 43ca3750..45488622 100644 --- a/javassist.jar +++ b/javassist.jar diff --git a/src/main/javassist/CtBehavior.java b/src/main/javassist/CtBehavior.java index 92513159..ede73422 100644 --- a/src/main/javassist/CtBehavior.java +++ b/src/main/javassist/CtBehavior.java @@ -917,7 +917,9 @@ public abstract class CtBehavior extends CtMember { // the gap length might be a multiple of 4. iterator.writeByte(Opcode.NOP, pos); boolean wide = subr + 2 - pos > Short.MAX_VALUE; - pos = iterator.insertGapAt(pos, wide ? 4 : 2, false).position; + int len = wide ? 4 : 2; + CodeIterator.Gap gap = iterator.insertGapAt(pos, len, false); + pos = gap.position + gap.length - len; int offset = iterator.getMark() - pos; if (wide) { iterator.writeByte(Opcode.GOTO_W, pos); @@ -928,7 +930,11 @@ public abstract class CtBehavior extends CtMember { iterator.write16bit(offset, pos + 1); } else { - pos = iterator.insertGapAt(pos, 2, false).position; + if (gap.length < 4) { + CodeIterator.Gap gap2 = iterator.insertGapAt(gap.position, 2, false); + pos = gap2.position + gap2.length + gap.length - 4; + } + iterator.writeByte(Opcode.GOTO_W, pos); iterator.write32bit(iterator.getMark() - pos, pos + 1); } diff --git a/src/main/javassist/bytecode/stackmap/BasicBlock.java b/src/main/javassist/bytecode/stackmap/BasicBlock.java index 43367307..79ec5a77 100644 --- a/src/main/javassist/bytecode/stackmap/BasicBlock.java +++ b/src/main/javassist/bytecode/stackmap/BasicBlock.java @@ -360,6 +360,7 @@ public class BasicBlock { prev.length = m.position - prev.position; // the incoming flow from dead code is not counted // bb.incoming++; + prev.stop = true; // because the incoming flow is not counted. prev.exit = makeArray(bb); } } diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java index c39f6700..549102f0 100644 --- a/src/test/javassist/JvstTest4.java +++ b/src/test/javassist/JvstTest4.java @@ -661,9 +661,9 @@ public class JvstTest4 extends JvstTestRoot { long t2 = endTime2 - endTime; long t3 = endTime3 - endTime2; System.out.println("JIRA150: " + t1 + ", " + t2 + ", " + t3); - assertTrue("performance test (the next try may succeed): " + t1 + "/ 6 < " + t2, + assertTrue("performance test (the next try may succeed): " + t2 + " < 6 * " + t1, t2 < t1 * 6); - assertTrue("", t3 < t1 * 3); + assertTrue(t3 + " < 3 * " + t1, t3 < t1 * 3); } public void testJIRA150b() throws Exception { diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index becd5c59..124f585d 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -44,4 +44,13 @@ public class JvstTest5 extends JvstTestRoot { Annotation[] annos = t.getAnnotations(); assertEquals("@test5.TypeAnnoA()", annos[0].toString()); } + + public void testJIRA241() throws Exception { + CtClass cc = sloader.get("test5.JIRA241"); + CtMethod testMethod = cc.getDeclaredMethod("test"); + testMethod.insertAfter("System.out.println(\"inserted!\");"); + cc.writeFile(); + Object obj = make(cc.getName()); + assertEquals(10, invoke(obj, "run")); + } } diff --git a/src/test/test5/JIRA241.java b/src/test/test5/JIRA241.java new file mode 100644 index 00000000..e6f8e957 --- /dev/null +++ b/src/test/test5/JIRA241.java @@ -0,0 +1,33 @@ +package test5; + +import java.util.Random; +import javassist.*; + +public class JIRA241 { + public int run() { + test(this); + return 10; + } + + public static void test(Object o) { + //part 1 + if (o == null) { + return; + } + + //part 2 + int oper = new Random().nextInt(); + switch (oper) { + case 1: + break; + } + } + + public static void main(String[] args) throws Exception { + ClassPool pool = ClassPool.getDefault(); + CtClass cc = pool.get("test5.JIRA241"); + CtMethod testMethod = cc.getMethod("test", "(Ljava/lang/Object;)V"); + testMethod.insertAfter("System.out.println(\"inserted!\");"); + cc.writeFile(); + } +} |