diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2007-06-02 14:12:36 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2007-06-02 14:12:36 +0000 |
commit | b8445cabacd7ab2a9c04bc5936583060f35ef505 (patch) | |
tree | 0d3ed708d5c2ef0b2849e45b44d1ec3e250062a5 /src/main/javassist/compiler/CodeGen.java | |
parent | 8242ef42ef19f1f6a3f15e9b230f0317067f3863 (diff) | |
download | javassist-b8445cabacd7ab2a9c04bc5936583060f35ef505.tar.gz javassist-b8445cabacd7ab2a9c04bc5936583060f35ef505.zip |
fixed bugs related to stack map tables.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@378 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/compiler/CodeGen.java')
-rw-r--r-- | src/main/javassist/compiler/CodeGen.java | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/main/javassist/compiler/CodeGen.java b/src/main/javassist/compiler/CodeGen.java index dfcddc4e..0712d906 100644 --- a/src/main/javassist/compiler/CodeGen.java +++ b/src/main/javassist/compiler/CodeGen.java @@ -53,7 +53,13 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId { */ protected static abstract class ReturnHook { ReturnHook next; - protected abstract void doit(Bytecode b, int opcode); + + /** + * Returns true if the generated code ends with return, + * throw, or goto. + */ + protected abstract boolean doit(Bytecode b, int opcode); + protected ReturnHook(CodeGen gen) { next = gen.returnHooks; gen.returnHooks = this; @@ -607,7 +613,10 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId { } for (ReturnHook har = returnHooks; har != null; har = har.next) - har.doit(bytecode, op); + if (har.doit(bytecode, op)) { + hasReturned = true; + return; + } bytecode.addOpcode(op); hasReturned = true; @@ -645,9 +654,10 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId { bc.addOpcode(MONITORENTER); ReturnHook rh = new ReturnHook(this) { - protected void doit(Bytecode b, int opcode) { + protected boolean doit(Bytecode b, int opcode) { b.addAload(var); b.addOpcode(MONITOREXIT); + return false; } }; @@ -665,10 +675,13 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId { bc.addIndex(0); } - int pc4 = bc.currentPc(); - rh.doit(bc, 0); // the 2nd arg is ignored. - bc.addOpcode(ATHROW); - bc.addExceptionHandler(pc, pc2, pc4, 0); + if (pc < pc2) { // if the body is not empty + int pc4 = bc.currentPc(); + rh.doit(bc, 0); // the 2nd arg is ignored. + bc.addOpcode(ATHROW); + bc.addExceptionHandler(pc, pc2, pc4, 0); + } + if (!hasReturned) bc.write16bit(pc3, bc.currentPc() - pc3 + 1); |