From: chibash Date: Fri, 16 Oct 2020 10:23:07 +0000 (+0900) Subject: fixes Issue #339 X-Git-Tag: rel_3_28_0_ga~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1c4e31b9677d020a1e89aeebc6686396f9e6c68a;p=javassist.git fixes Issue #339 --- diff --git a/Readme.html b/Readme.html index 914e912e..247962a5 100644 --- a/Readme.html +++ b/Readme.html @@ -293,7 +293,7 @@ see javassist.Dump.

-version 3.28

-version 3.27 on March 19, 2020 diff --git a/javassist.jar b/javassist.jar index b1f107b7..26c40469 100644 Binary files a/javassist.jar and b/javassist.jar differ diff --git a/src/main/javassist/bytecode/StackMapTable.java b/src/main/javassist/bytecode/StackMapTable.java index 9b8e5fae..81622200 100644 --- a/src/main/javassist/bytecode/StackMapTable.java +++ b/src/main/javassist/bytecode/StackMapTable.java @@ -881,7 +881,11 @@ public class StackMapTable extends AttributeInfo { position = oldPos + offsetDelta + (oldPos == 0 ? 0 : 1); boolean match; if (exclusive) - match = oldPos < where && where <= position; + // We optimize this expression by hand: + // match = (oldPos == 0 && where == 0 && (0 < position || 0 == position)) + // || oldPos < where && where <= position; + match = (oldPos == 0 && where == 0) + || oldPos < where && where <= position; else match = oldPos <= where && where < position; @@ -931,7 +935,8 @@ public class StackMapTable extends AttributeInfo { position = oldPos + offsetDelta + (oldPos == 0 ? 0 : 1); boolean match; if (exclusive) - match = oldPos < where && where <= position; + match = (oldPos == 0 && where == 0) + || oldPos < where && where <= position; else match = oldPos <= where && where < position; diff --git a/src/test/javassist/bytecode/StackMapTest.java b/src/test/javassist/bytecode/StackMapTest.java index 07ee50be..7ea415a9 100644 --- a/src/test/javassist/bytecode/StackMapTest.java +++ b/src/test/javassist/bytecode/StackMapTest.java @@ -848,4 +848,79 @@ public class StackMapTest extends TestCase { cc.writeFile(); Object t1 = make(cc.getName()); } + + public static class C8 { + int value = 0; + int loop = 0; + int loop2 = 1; + public void foo(int i) { value += i; } + public void bar(int i) { value += i; } + public void foo2(int i) { value += i; } + public void bar2(int i) { value += i; } + } + + public static class C9 extends C8 { + public void foo(int i) { + while(true) { + loop--; + if (loop < 0) + break; + } + value += i; + } + public void bar(int i) { + value += i; + for (int k = 0; i < 10; k++) + loop += k; + } + public void foo2(int i) { + while(true) { + loop2--; + if (loop2 < 0) + break; + } + value += i; + for (int k = 0; k < 3; k++) + loop2--; + } + public void bar2(int i) { + value += i; + for (int k = 0; i < 10; k++) + loop += k; + } + public int run() { + foo(1); + bar(10); + foo2(100); + bar2(1000); + return value; + } + } + + public void testIssue339() throws Exception { + CtClass cc0 = loader.get("javassist.bytecode.StackMapTest$C8"); + CtClass cc = loader.get("javassist.bytecode.StackMapTest$C9"); + + testIssue339b(cc, cc0, "foo", true); + testIssue339b(cc, cc0, "bar", true); + testIssue339b(cc, cc0, "foo2", false); + testIssue339b(cc, cc0, "bar2", false); + + cc.writeFile(); + Object t1 = make(cc.getName()); + assertEquals(2322, invoke(t1, "run")); + } + + public void testIssue339b(CtClass cc, CtClass cc0, String name, boolean exclusive) throws Exception { + Bytecode newCode = new Bytecode(cc.getClassFile().constPool); + newCode.addAload(0); // Loads 'this' + newCode.addIload(1); // Loads method param 1 (int) + newCode.addInvokespecial(cc0.getName(), name, "(I)V"); + CodeAttribute ca = cc.getDeclaredMethod(name).getMethodInfo().getCodeAttribute(); + CodeIterator ci = ca.iterator(); + if (exclusive) + ci.insertEx(newCode.get()); + else + ci.insert(newCode.get()); + } }