diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2012-10-20 10:57:51 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2012-10-20 10:57:51 +0000 |
commit | 705c3c66218afb4d914a00323d5acad6c062683e (patch) | |
tree | 4fcaa70634d20167d7f7983e8dfae8dbc06c94b7 /src/main | |
parent | 34a093c27a90fdcb8f463f2b3ee74e612dcc12f8 (diff) | |
download | javassist-705c3c66218afb4d914a00323d5acad6c062683e.tar.gz javassist-705c3c66218afb4d914a00323d5acad6c062683e.zip |
fixed JASSIST-175
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@675 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/javassist/bytecode/BadBytecode.java | 6 | ||||
-rw-r--r-- | src/main/javassist/bytecode/stackmap/MapMaker.java | 55 |
2 files changed, 51 insertions, 10 deletions
diff --git a/src/main/javassist/bytecode/BadBytecode.java b/src/main/javassist/bytecode/BadBytecode.java index 71e5bb9d..9959ae6c 100644 --- a/src/main/javassist/bytecode/BadBytecode.java +++ b/src/main/javassist/bytecode/BadBytecode.java @@ -31,4 +31,10 @@ public class BadBytecode extends Exception { public BadBytecode(String msg, Throwable cause) { super(msg, cause); } + + public BadBytecode(MethodInfo minfo, Throwable cause) { + super(minfo.toString() + " in " + + minfo.getConstPool().getClassName() + + ": " + cause.getMessage(), cause); + } } diff --git a/src/main/javassist/bytecode/stackmap/MapMaker.java b/src/main/javassist/bytecode/stackmap/MapMaker.java index b846661b..3c96a36a 100644 --- a/src/main/javassist/bytecode/stackmap/MapMaker.java +++ b/src/main/javassist/bytecode/stackmap/MapMaker.java @@ -96,7 +96,13 @@ public class MapMaker extends Tracer { return null; MapMaker mm = new MapMaker(classes, minfo, ca); - mm.make(blocks, ca.getCode()); + try { + mm.make(blocks, ca.getCode()); + } + catch (BadBytecode bb) { + throw new BadBytecode(minfo, bb); + } + return mm.toStackMap(blocks); } @@ -117,7 +123,12 @@ public class MapMaker extends Tracer { return null; MapMaker mm = new MapMaker(classes, minfo, ca); - mm.make(blocks, ca.getCode()); + try { + mm.make(blocks, ca.getCode()); + } + catch (BadBytecode bb) { + throw new BadBytecode(minfo, bb); + } return mm.toStackMap2(minfo.getConstPool(), blocks); } @@ -137,7 +148,7 @@ public class MapMaker extends Tracer { { make(code, blocks[0]); try { - fixTypes(blocks); + fixTypes(code, blocks); } catch (NotFoundException e) { throw new BadBytecode("failed to resolve types", e); } @@ -276,22 +287,40 @@ public class MapMaker extends Tracer { * Since SCCs are found in the topologically sorted order, * their types are also fixed when they are found. */ - private void fixTypes(TypedBlock[] blocks) throws NotFoundException { + private void fixTypes(byte[] code, TypedBlock[] blocks) throws NotFoundException, BadBytecode { ArrayList preOrder = new ArrayList(); int len = blocks.length; int index = 0; for (int i = 0; i < len; i++) { TypedBlock block = blocks[i]; - int n = block.localsTypes.length; - for (int j = 0; j < n; j++) - index = block.localsTypes[j].dfs(preOrder, index, classPool); + if (block.localsTypes == null) // if block is dead code + fixDeadcode(code, block); + else { + int n = block.localsTypes.length; + for (int j = 0; j < n; j++) + index = block.localsTypes[j].dfs(preOrder, index, classPool); - n = block.stackTop; - for (int j = 0; j < n; j++) - index = block.stackTypes[j].dfs(preOrder, index, classPool); + n = block.stackTop; + for (int j = 0; j < n; j++) + index = block.stackTypes[j].dfs(preOrder, index, classPool); + } } } + private void fixDeadcode(byte[] code, TypedBlock block) throws BadBytecode { + int pos = block.position; + int len = block.length - 3; + if (len < 0) + throw new BadBytecode("dead code detected at " + pos + + ". No stackmap table generated."); + + for (int k = 0; k < len; k++) + code[pos + k] = Bytecode.NOP; + + code[pos + len] = (byte)Bytecode.GOTO; + ByteArray.write16bit(-len, code, pos + len + 1); + } + // Phase 3 public StackMapTable toStackMap(TypedBlock[] blocks) { @@ -314,6 +343,12 @@ public class MapMaker extends Tracer { offsetDelta = bb.length - 1; prev = bb; } + else if (bb.incoming == 0) { + // dead code. + writer.sameFrame(offsetDelta); + offsetDelta = bb.length - 1; + prev = bb; + } else offsetDelta += bb.length; } |